my_wins 1.2.3 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +96 -24
- package/package.json +4 -2
- package/readme.md +14 -0
package/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { spawn, execFile, exec } = require("child_process");
|
|
2
2
|
const fs = require("fs");
|
|
3
3
|
const JSON5 = require("json5");
|
|
4
|
+
const inquirer = require("inquirer");
|
|
4
5
|
const keysender = require("@sumbat/keysender");
|
|
5
6
|
const defaultSettings = {
|
|
6
7
|
x: 0,
|
|
@@ -13,7 +14,7 @@ const defaultSettings = {
|
|
|
13
14
|
wy_total : 12,
|
|
14
15
|
};
|
|
15
16
|
|
|
16
|
-
function makeWinsArray(settings
|
|
17
|
+
function makeWinsArray(settings) {
|
|
17
18
|
let winsArray = settings.winsArray || [];
|
|
18
19
|
let {x,y,width, height, screenWidth, screenHeight, wy_total, wx_total} = settings;
|
|
19
20
|
const scr_sz = keysender.getScreenSize();
|
|
@@ -41,17 +42,24 @@ function awaitDelay(delay) {
|
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
function parseArgs(argv) {
|
|
46
|
+
const raw = argv.slice(2);
|
|
47
|
+
const menu = raw.includes("-m") || raw.includes("--menu");
|
|
48
|
+
const positional = raw.filter((arg)=>arg !== "-m" && arg !== "--menu");
|
|
49
|
+
return {
|
|
50
|
+
menu,
|
|
51
|
+
single: positional[0],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
47
54
|
|
|
55
|
+
function loadSettings() {
|
|
48
56
|
let settings;
|
|
49
57
|
try {
|
|
50
58
|
settings = Object.assign({}, defaultSettings, JSON5.parse(fs.readFileSync("my_wins.json")));
|
|
51
59
|
} catch (e) {
|
|
52
60
|
if(!e.message.startsWith("ENOENT")) {
|
|
53
61
|
console.error(`Error reading 'my_wins.json' ${e.message}`);
|
|
54
|
-
return;
|
|
62
|
+
return null;
|
|
55
63
|
} else
|
|
56
64
|
console.log(`Usage:
|
|
57
65
|
create 'my_wins.json' with optional contents
|
|
@@ -76,10 +84,36 @@ module.exports.run = async ()=>{
|
|
|
76
84
|
|
|
77
85
|
if (!settings.wins) settings.wins = {};
|
|
78
86
|
|
|
79
|
-
|
|
80
|
-
|
|
87
|
+
try {
|
|
88
|
+
let personal_settings ;
|
|
89
|
+
try {
|
|
90
|
+
personal_settings = JSON5.parse(fs.readFileSync("my_wins_personal.json"));
|
|
91
|
+
} catch (e) {
|
|
92
|
+
if (!e.message.startsWith("ENOENT")) {
|
|
93
|
+
console.error(`Error reading 'my_wins_personal.json' ${e.message}`);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (personal_settings) {
|
|
98
|
+
for (let k in personal_settings) if (k !== "wins") settings[k] = personal_settings[k];
|
|
99
|
+
|
|
100
|
+
if (personal_settings.wins) {
|
|
101
|
+
for (let name in personal_settings.wins)
|
|
102
|
+
if (!settings.wins[name]) settings.wins[name] = personal_settings.wins[name];
|
|
103
|
+
else Object.assign(settings.wins[name], personal_settings.wins[name]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch (e) {}
|
|
107
|
+
|
|
108
|
+
return settings;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function buildRunSettings(baseSettings, filterNames) {
|
|
112
|
+
const settings = JSON.parse(JSON.stringify(baseSettings));
|
|
113
|
+
const hasFilter = Array.isArray(filterNames) && filterNames.length > 0;
|
|
114
|
+
if (hasFilter) {
|
|
81
115
|
for(let k in settings.wins) {
|
|
82
|
-
if(k
|
|
116
|
+
if(!filterNames.includes(k)) {
|
|
83
117
|
delete settings.wins[k];
|
|
84
118
|
}
|
|
85
119
|
}
|
|
@@ -95,22 +129,12 @@ module.exports.run = async ()=>{
|
|
|
95
129
|
w.title = w.name+randSuffix()
|
|
96
130
|
}
|
|
97
131
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
try {
|
|
101
|
-
personal_settings = JSON5.parse(fs.readFileSync("my_wins_personal.json"));
|
|
102
|
-
} catch (e) {
|
|
103
|
-
if (!e.message.startsWith("ENOENT")) {
|
|
104
|
-
console.error(`Error reading 'my_wins_personal.json' ${e.message}`);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
for (let k in personal_settings) if (k !== "wins") settings[k] = personal_settings[k];
|
|
132
|
+
return settings;
|
|
133
|
+
}
|
|
109
134
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
} catch (e) {}
|
|
135
|
+
async function runOnce(baseSettings, filterNames) {
|
|
136
|
+
const settings = buildRunSettings(baseSettings, filterNames);
|
|
137
|
+
if (!Object.keys(settings.wins).length) return;
|
|
114
138
|
|
|
115
139
|
let wins = keysender.getAllWindows();
|
|
116
140
|
|
|
@@ -192,6 +216,54 @@ module.exports.run = async ()=>{
|
|
|
192
216
|
|
|
193
217
|
await awaitDelay(700);
|
|
194
218
|
console.log(`my_wins finished successfully!`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function promptMenu(winNames) {
|
|
222
|
+
const choices = winNames.map((name)=>({ name, value: name }));
|
|
223
|
+
choices.push({ name: "exit", value: "__exit__", checked: true });
|
|
224
|
+
const { selections } = await inquirer.prompt([
|
|
225
|
+
{
|
|
226
|
+
type: "checkbox",
|
|
227
|
+
name: "selections",
|
|
228
|
+
message: "Select commands to run",
|
|
229
|
+
choices,
|
|
230
|
+
},
|
|
231
|
+
]);
|
|
232
|
+
return selections;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
module.exports.defaultSettings = defaultSettings;
|
|
236
|
+
module.exports.run = async ()=>{
|
|
237
|
+
console.log("Screen size:", keysender.getScreenSize());
|
|
238
|
+
|
|
239
|
+
const settings = loadSettings();
|
|
240
|
+
if (!settings) return;
|
|
241
|
+
|
|
242
|
+
const args = parseArgs(process.argv);
|
|
243
|
+
const winNames = Object.keys(settings.wins || {});
|
|
244
|
+
|
|
245
|
+
if (args.menu) {
|
|
246
|
+
if (!winNames.length) {
|
|
247
|
+
console.log("No wins configured.");
|
|
248
|
+
process.exit(0);
|
|
249
|
+
}
|
|
250
|
+
while (true) {
|
|
251
|
+
const selections = await promptMenu(winNames);
|
|
252
|
+
const exitSelected = selections.includes("__exit__");
|
|
253
|
+
const selectedNames = selections.filter((item)=>item !== "__exit__");
|
|
254
|
+
if (selectedNames.length) {
|
|
255
|
+
await runOnce(settings, selectedNames);
|
|
256
|
+
}
|
|
257
|
+
if (exitSelected) break;
|
|
258
|
+
}
|
|
259
|
+
process.exit(0);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (args.single && settings.wins[args.single]) {
|
|
263
|
+
await runOnce(settings, [args.single]);
|
|
264
|
+
} else {
|
|
265
|
+
await runOnce(settings);
|
|
266
|
+
}
|
|
267
|
+
|
|
195
268
|
process.exit(0);
|
|
196
269
|
};
|
|
197
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "my_wins",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Automates starting and laying out your console windows for tsc, babel, tests, verdaccio, etc...",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -15,11 +15,13 @@
|
|
|
15
15
|
"my_wins": "bin/index.js"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
|
-
"start": "node index.js"
|
|
18
|
+
"start": "node index.js",
|
|
19
|
+
"startm": "node index.js -m"
|
|
19
20
|
},
|
|
20
21
|
"author": "Yuri Yaryshev",
|
|
21
22
|
"license": "Unlicense",
|
|
22
23
|
"dependencies": {
|
|
24
|
+
"inquirer": "^8.2.6",
|
|
23
25
|
"json5": "^2.1.3",
|
|
24
26
|
"@sumbat/keysender": "^2.3.0"
|
|
25
27
|
},
|
package/readme.md
CHANGED
|
@@ -65,6 +65,20 @@ Now if you need to restart or pause/resume any of your cmd just do
|
|
|
65
65
|
|
|
66
66
|
***my_wins*** uses json5 to parse it's settings, so you can leave trailing commas or remove quotes around json-keys (see json5 package for details).
|
|
67
67
|
|
|
68
|
+
### Menu mode
|
|
69
|
+
|
|
70
|
+
Use menu mode to pick multiple commands interactively:
|
|
71
|
+
|
|
72
|
+
```shell
|
|
73
|
+
my_wins -m
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
or
|
|
77
|
+
|
|
78
|
+
```shell
|
|
79
|
+
my_wins --menu
|
|
80
|
+
```
|
|
81
|
+
|
|
68
82
|
### All options
|
|
69
83
|
|
|
70
84
|
You can also create "my_wins_personal.json" which can partially or fully overrides my_wins.
|