Skip to content

Commit 026f9ef

Browse files
committed
version 1.0.1
1 parent 5e0619b commit 026f9ef

10 files changed

Lines changed: 765 additions & 807 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
dist.zip

.vscode/getNet.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const { networkInterfaces } = require('os');
22

33
module.exports = async (mode = 'dev') => {
4-
const { WiFi } = getIp();
5-
const ip = WiFi ? WiFi[0] : undefined;
4+
const { WiFi, Ethernet } = getIp();
5+
const [ip] = WiFi || Ethernet;
66
const port = '5500';
77
const src = `https://${ip || '10.0.0'}:${port}`;
88
console.log('Server starting at: ', src);

.vscode/pack-zip.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
const jszip = require('jszip');
4+
5+
const iconFile = path.join(__dirname, '../icon.png');
6+
const pluginJSON = path.join(__dirname, '../plugin.json');
7+
const distFolder = path.join(__dirname, '../dist');
8+
let readmeDotMd = path.join(__dirname, '../readme.md');
9+
10+
if (!fs.existsSync(readmeDotMd)) {
11+
readmeDotMd = path.join(__dirname, '../README.md');
12+
}
13+
14+
// create zip file of dist folder
15+
16+
const zip = new jszip();
17+
18+
zip.file('icon.png', fs.readFileSync(iconFile));
19+
zip.file('plugin.json', fs.readFileSync(pluginJSON));
20+
zip.file('readme.md', fs.readFileSync(readmeDotMd));
21+
22+
loadFile('', distFolder);
23+
24+
zip
25+
.generateNodeStream({ type: 'nodebuffer', streamFiles: true })
26+
.pipe(fs.createWriteStream(path.join(__dirname, '../dist.zip')))
27+
.on('finish', () => {
28+
console.log('dist.zip written.');
29+
});
30+
31+
function loadFile(root, folder) {
32+
const distFiles = fs.readdirSync(folder);
33+
distFiles.forEach((file) => {
34+
35+
const stat = fs.statSync(path.join(folder, file));
36+
37+
if (stat.isDirectory()) {
38+
zip.folder(file);
39+
loadFile(path.join(root, file), path.join(folder, file));
40+
return;
41+
}
42+
43+
if (!/LICENSE.txt/.test(file)) {
44+
zip.file(path.join(root, file), fs.readFileSync(path.join(folder, file)));
45+
}
46+
});
47+
}

dist/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
{
22
"name": "acode-plugin",
3-
"version": "1.0.2",
3+
"version": "1.0.1",
44
"description": "Template for Acode plugin",
55
"main": "dist/main.js",
66
"repository": "https://github.com/deadlyjack/acode-plugin.git",
77
"author": "Ajit <me@ajitkumar.dev>",
88
"license": "MIT",
99
"dependencies": {
10-
"html-tag-js": "^1.1.6"
10+
"html-tag-js": "^1.1.6",
11+
"terser": ">=5.14.2 "
1112
},
1213
"devDependencies": {
1314
"@babel/cli": "^7.18.10",
1415
"@babel/core": "^7.18.13",
1516
"@babel/preset-env": "^7.18.10",
16-
"babel-loader": "^8.2.5",
17+
"babel-loader": "^9.1.2",
18+
"jszip": "^3.10.1",
1719
"live-server": "^1.2.2",
1820
"webpack": "^5.74.0",
19-
"webpack-cli": "^4.10.0"
21+
"webpack-cli": "^5.0.1"
2022
},
2123
"scripts": {
2224
"build": "webpack",

plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "Volumn cursor",
44
"type": "free",
55
"main": "dist/main.js",
6-
"version": "1.0.0",
6+
"version": "1.0.1",
77
"readme": "readme.md",
88
"icon": "icon.png",
99
"files": [],
@@ -12,4 +12,4 @@
1212
"email": "me@ajitkumar.dev",
1313
"github": "https://github.com/deadlyjack"
1414
}
15-
}
15+
}

readme.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22

33
Control editor cursor.
44

5-
- Volumn up > left
6-
- Volumn down > right
5+
## Updates
6+
7+
### 0.0.1
8+
9+
- Added settings to change direction of cursor movement.

src/main.js

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import tag from 'html-tag-js';
22
import plugin from '../plugin.json';
33

4+
const appSettings = acode.require('settings');
5+
46
const keyMapping = {
57
37: 'ArrowLeft',
68
38: 'ArrowUp',
@@ -9,7 +11,22 @@ const keyMapping = {
911
};
1012

1113
class AcodePlugin {
14+
TO_LEFT = 'to left';
15+
TO_RIGHT = 'to right';
16+
TO_UP = 'to up';
17+
TO_DOWN = 'to down';
18+
19+
KEY_LEFT = 37;
20+
KEY_UP = 38;
21+
KEY_RIGHT = 39;
22+
KEY_DOWN = 40;
23+
1224
constructor() {
25+
if (!appSettings[plugin.id]) {
26+
appSettings[plugin.id] = {
27+
direction: this.TO_RIGHT,
28+
};
29+
}
1330
this.removeListeners = this.removeListeners.bind(this);
1431
this.addListners = this.addListners.bind(this);
1532
this.onvolumndown = this.onvolumndown.bind(this);
@@ -41,11 +58,45 @@ class AcodePlugin {
4158
}
4259

4360
onvolumndown() {
44-
this.dispatchKey(37);
61+
let key = this.KEY_RIGHT;
62+
63+
switch (this.direction) {
64+
case this.TO_LEFT:
65+
key = this.KEY_LEFT;
66+
break;
67+
case this.TO_RIGHT:
68+
key = this.KEY_RIGHT;
69+
break;
70+
case this.TO_UP:
71+
key = this.KEY_UP;
72+
break;
73+
case this.TO_DOWN:
74+
key = this.KEY_DOWN;
75+
break;
76+
}
77+
78+
this.dispatchKey(key);
4579
}
4680

4781
onvolumnup() {
48-
this.dispatchKey(39)
82+
let key = this.KEY_LEFT;
83+
84+
switch (this.direction) {
85+
case this.TO_LEFT:
86+
key = this.KEY_RIGHT;
87+
break;
88+
case this.TO_RIGHT:
89+
key = this.KEY_LEFT;
90+
break;
91+
case this.TO_UP:
92+
key = this.KEY_DOWN;
93+
break;
94+
case this.TO_DOWN:
95+
key = this.KEY_UP;
96+
break;
97+
}
98+
99+
this.dispatchKey(key);
49100
}
50101

51102
dispatchKey(which) {
@@ -60,6 +111,36 @@ class AcodePlugin {
60111

61112
$textarea.dispatchEvent(keyevent);
62113
}
114+
115+
get settingsObj() {
116+
return {
117+
list: [
118+
{
119+
key: 'direction',
120+
text: 'Direction',
121+
value: this.settings.direction,
122+
select: [
123+
this.TO_LEFT,
124+
this.TO_RIGHT,
125+
this.TO_UP,
126+
this.TO_DOWN,
127+
]
128+
}
129+
],
130+
cb: (key, value) => {
131+
this.settings[key] = value;
132+
appSettings.update();
133+
},
134+
}
135+
}
136+
137+
get settings() {
138+
return appSettings[plugin.id];
139+
}
140+
141+
get direction() {
142+
return this.settings.direction || this.TO_RIGHT;
143+
}
63144
}
64145

65146
if (window.acode) {
@@ -70,7 +151,7 @@ if (window.acode) {
70151
}
71152
acodePlugin.baseUrl = baseUrl;
72153
acodePlugin.init($page, cacheFile, cacheFileUrl);
73-
});
154+
}, acodePlugin.settingsObj);
74155
acode.setPluginUnmount(plugin.id, () => {
75156
acodePlugin.destroy();
76157
});

webpack.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { exec } = require('child_process');
12
const path = require('path');
23

34
module.exports = (env, options) => {
@@ -27,6 +28,22 @@ module.exports = (env, options) => {
2728
module: {
2829
rules,
2930
},
31+
plugins: [
32+
{
33+
apply: (compiler) => {
34+
compiler.hooks.afterDone.tap('pack-zip', () => {
35+
// run pack-zip.js
36+
exec('node .vscode/pack-zip.js', (err, stdout, stderr) => {
37+
if (err) {
38+
console.error(err);
39+
return;
40+
}
41+
console.log(stdout);
42+
});
43+
});
44+
}
45+
}
46+
],
3047
};
3148

3249
return [main];

0 commit comments

Comments
 (0)