Skip to content

Commit ff23765

Browse files
committed
version 1.0.3
1 parent 5f70c5a commit ff23765

4 files changed

Lines changed: 208 additions & 92 deletions

File tree

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
{
22
"name": "acode-plugin-github",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Github plugin for acode editor",
55
"main": "dist/main.js",
66
"repository": "https://github.com/deadlyjack/acode-plugin-github.git",
77
"author": "Ajit <me@ajitkumar.dev>",
88
"license": "MIT",
99
"dependencies": {
1010
"github-api": "^3.4.0",
11-
"html-tag-js": "^1.1.22",
11+
"html-tag-js": "^1.1.37",
1212
"mime-types": "^2.1.35"
1313
},
1414
"devDependencies": {
15-
"@babel/cli": "^7.18.10",
16-
"@babel/core": "^7.18.13",
17-
"@babel/plugin-transform-runtime": "^7.19.6",
15+
"@babel/cli": "^7.21.0",
16+
"@babel/core": "^7.21.0",
17+
"@babel/plugin-transform-runtime": "^7.21.0",
1818
"@babel/preset-env": "^7.18.10",
19-
"babel-loader": "^9.1.0",
19+
"babel-loader": "^9.1.2",
2020
"jszip": "^3.10.1",
2121
"live-server": "^1.2.2",
2222
"path-browserify": "^1.0.1",
23-
"webpack": "^5.74.0",
24-
"webpack-cli": "^5.0.0"
23+
"webpack": "^5.76.0",
24+
"webpack-cli": "^5.0.1"
2525
},
2626
"scripts": {
2727
"build": "webpack",
@@ -32,7 +32,7 @@
3232
"> 0.25%, not dead"
3333
],
3434
"resolutions": {
35-
"terser": ">=5.14.2 ",
35+
"terser": ">=5.16.6",
3636
"glob-parent": ">=5.1.2"
3737
}
3838
}

src/githubFs.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { lookup } from 'mime-types';
44
const fsOperation = acode.require('fsoperation');
55
const Url = acode.require('url');
66
const helpers = acode.require('helpers');
7+
const prompt = acode.require('prompt');
78
const test = (url) => /^gh:/.test(url);
89

910
githubFs.remove = () => {
@@ -35,7 +36,7 @@ githubFs.constructUrl = (type, user, repo, path, branch) => {
3536
return url;
3637
};
3738

38-
export default function githubFs(token) {
39+
export default function githubFs(token, settings) {
3940
fsOperation.extend(test, (url) => {
4041
const { user, type, repo, path, gist } = parseUrl(url);
4142
if (type === 'repo') {
@@ -145,7 +146,13 @@ export default function githubFs(token) {
145146
},
146147
async writeFile(data) {
147148
await init();
148-
await repo.writeFile(branch, path, data, `update ${path}`);
149+
let commitMessage = `update ${path}`;
150+
151+
if (settings.askCommitMessage) {
152+
commitMessage = await prompt('Commit message', commitMessage, 'text');
153+
}
154+
155+
await repo.writeFile(branch, path, data, commitMessage);
149156
},
150157
async createFile(name, data = '') {
151158
const newPath = path === '' ? name : Url.join(path, name);

src/main.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const helpers = acode.require('helpers');
99
const multiPrompt = acode.require('multiPrompt');
1010
const openFolder = acode.require('openFolder');
1111
const EditorFile = acode.require('EditorFile');
12+
const appSettings = acode.require('settings');
1213

1314
if (!Blob.prototype.arrayBuffer) {
1415
Blob.prototype.arrayBuffer = function () {
@@ -24,25 +25,33 @@ if (!Blob.prototype.arrayBuffer) {
2425
class AcodePlugin {
2526
token = '';
2627
NEW = `${helpers.uuid()}_NEW`;
27-
#cacheFile;
2828
#fsInitialized = false;
2929
#repos = [];
3030
#gists = [];
3131

32-
async init($page, cacheFile) {
33-
this.#cacheFile = cacheFile;
32+
async init() {
33+
this.settings = appSettings.value[plugin.id];
34+
35+
if (!this.settings) {
36+
this.settings = {
37+
askCommitMessage: false,
38+
};
39+
appSettings.value[plugin.id] = this.settings;
40+
appSettings.update();
41+
}
42+
3443
this.commands.forEach(command => {
3544
editorManager.editor.commands.addCommand(command);
3645
});
3746

38-
this.token = await this.#cacheFile.readFile('utf8');
47+
this.token = localStorage.getItem('github-token');
3948
await this.initFs();
4049
}
4150

4251
async initFs() {
4352
if (this.#fsInitialized) return;
4453
githubFs.remove();
45-
githubFs(this.getToken.bind(this));
54+
githubFs(this.getToken.bind(this), this.settings);
4655
this.#fsInitialized = true;
4756
}
4857

@@ -165,6 +174,7 @@ class AcodePlugin {
165174
const url = githubFs.constructUrl('repo', user, repoName, '/', branch);
166175
openFolder(url, {
167176
name: `${user}/${repoName}/${branch}`,
177+
saveState: false,
168178
});
169179
}
170180

@@ -292,7 +302,7 @@ class AcodePlugin {
292302
if (result) {
293303
this.token = result;
294304
this.#fsInitialized = false;
295-
await this.#cacheFile.writeFile(result);
305+
localStorage.setItem('github-token', result);
296306
await this.initFs();
297307
}
298308
}

0 commit comments

Comments
 (0)