my_wins 1.3.1 → 1.3.3

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 CHANGED
@@ -44,11 +44,35 @@ function awaitDelay(delay) {
44
44
 
45
45
  function parseArgs(argv) {
46
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");
47
+ let menu = false;
48
+ let version = false;
49
+ let runName;
50
+ const positional = [];
51
+ for (let i = 0; i < raw.length; i++) {
52
+ const arg = raw[i];
53
+ if (arg === "-m" || arg === "--menu") {
54
+ menu = true;
55
+ continue;
56
+ }
57
+ if (arg === "-r" || arg === "--run") {
58
+ runName = raw[i + 1];
59
+ i += 1;
60
+ continue;
61
+ }
62
+ if (arg.startsWith("--run=")) {
63
+ runName = arg.slice("--run=".length);
64
+ continue;
65
+ }
66
+ if (arg === "-v" || arg === "--version") {
67
+ version = true;
68
+ continue;
69
+ }
70
+ positional.push(arg);
71
+ }
49
72
  return {
50
73
  menu,
51
- single: positional[0],
74
+ version,
75
+ single: runName || positional[0],
52
76
  };
53
77
  }
54
78
 
@@ -221,7 +245,11 @@ async function runOnce(baseSettings, filterNames) {
221
245
  async function promptMenu(winNames) {
222
246
  const choices = winNames.map((name)=>({ name, value: name }));
223
247
  choices.push({ name: "exit", value: "__exit__", checked: true });
224
- const { selections } = await inquirer.prompt([
248
+ const prompt = inquirer.prompt || (inquirer.default && inquirer.default.prompt);
249
+ if (!prompt) {
250
+ throw new Error("Inquirer prompt API is unavailable. Please use a compatible inquirer version.");
251
+ }
252
+ const { selections } = await prompt([
225
253
  {
226
254
  type: "checkbox",
227
255
  name: "selections",
@@ -234,12 +262,18 @@ async function promptMenu(winNames) {
234
262
 
235
263
  module.exports.defaultSettings = defaultSettings;
236
264
  module.exports.run = async ()=>{
237
- console.log("Screen size:", keysender.getScreenSize());
265
+ const args = parseArgs(process.argv);
266
+ if (args.version) {
267
+ const pkgPath = require("path").join(__dirname, "..", "package.json");
268
+ const pkg = JSON.parse(fs.readFileSync(pkgPath));
269
+ console.log(pkg.version || "0.0.0");
270
+ process.exit(0);
271
+ }
238
272
 
239
273
  const settings = loadSettings();
240
274
  if (!settings) return;
241
275
 
242
- const args = parseArgs(process.argv);
276
+ console.log("Screen size:", keysender.getScreenSize());
243
277
  const winNames = Object.keys(settings.wins || {});
244
278
 
245
279
  if (args.menu) {
package/my_wins.json CHANGED
@@ -3,6 +3,7 @@
3
3
  "wins": {
4
4
  // "cmd1": "echo cm1",
5
5
  // "cmd2": "echo cmd2",
6
- webstorm: {app:true, cmd:"notepad"}
7
- },
8
- }
6
+ webstorm: {app:true, cmd:"notepad"},
7
+ test_file: "powershell -NoProfile -Command \"Set-Content -Path 'D:/b/Mine/GIT_Work/my_wins/temp/my_wins_test.txt' -Value 'my_wins test'\" && exit"
8
+ },
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "my_wins",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Automates starting and laying out your console windows for tsc, babel, tests, verdaccio, etc...",
5
5
  "keywords": [
6
6
  "automation",
@@ -16,17 +16,18 @@
16
16
  },
17
17
  "scripts": {
18
18
  "start": "node index.js",
19
- "startm": "node index.js -m"
19
+ "startm": "node index.js -m",
20
+ "test": "node test/run-test.js"
20
21
  },
21
22
  "author": "Yuri Yaryshev",
22
23
  "license": "Unlicense",
23
24
  "dependencies": {
24
- "inquirer": "^8.2.6",
25
- "json5": "^2.1.3",
26
- "@sumbat/keysender": "^2.3.0"
25
+ "@sumbat/keysender": "^2.3.0",
26
+ "inquirer": "^13.2.1",
27
+ "json5": "^2.2.3"
27
28
  },
28
29
  "devDependencies": {
29
- "prettier": "^3.6.2"
30
+ "prettier": "^3.8.1"
30
31
  },
31
32
  "homepage": "https://github.com/yuyaryshev/my_wins",
32
33
  "repository": {
package/readme.md CHANGED
@@ -79,6 +79,22 @@ or
79
79
  my_wins --menu
80
80
  ```
81
81
 
82
+ ### Run a single command
83
+
84
+ Run a single win by name:
85
+
86
+ ```shell
87
+ my_wins --run cmd1
88
+ ```
89
+
90
+ ### Version
91
+
92
+ Print current version:
93
+
94
+ ```shell
95
+ my_wins --version
96
+ ```
97
+
82
98
  ### All options
83
99
 
84
100
  You can also create "my_wins_personal.json" which can partially or fully overrides my_wins.
@@ -0,0 +1,52 @@
1
+ const { spawn } = require("child_process");
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+
5
+ const repoRoot = path.resolve(__dirname, "..");
6
+ const tempDir = path.join(repoRoot, "temp");
7
+ const testFile = path.join(tempDir, "my_wins_test.txt");
8
+
9
+ function sleep(ms) {
10
+ return new Promise((resolve) => setTimeout(resolve, ms));
11
+ }
12
+
13
+ async function waitForFile(filePath, timeoutMs) {
14
+ const started = Date.now();
15
+ while (Date.now() - started < timeoutMs) {
16
+ if (fs.existsSync(filePath)) return true;
17
+ await sleep(250);
18
+ }
19
+ return false;
20
+ }
21
+
22
+ async function run() {
23
+ fs.mkdirSync(tempDir, { recursive: true });
24
+ if (fs.existsSync(testFile)) fs.unlinkSync(testFile);
25
+ if (fs.existsSync(testFile)) {
26
+ throw new Error(`Expected test file to be deleted: ${testFile}`);
27
+ }
28
+
29
+ const child = spawn("node", ["index.js", "--run", "test_file"], {
30
+ cwd: repoRoot,
31
+ stdio: "inherit",
32
+ });
33
+
34
+ const exitCode = await new Promise((resolve, reject) => {
35
+ child.on("error", reject);
36
+ child.on("close", resolve);
37
+ });
38
+
39
+ if (exitCode !== 0) {
40
+ throw new Error(`my_wins exited with code ${exitCode}`);
41
+ }
42
+
43
+ const created = await waitForFile(testFile, 8000);
44
+ if (!created) {
45
+ throw new Error(`Expected test file to exist: ${testFile}`);
46
+ }
47
+ }
48
+
49
+ run().catch((err) => {
50
+ console.error(err);
51
+ process.exit(1);
52
+ });