my_wins 1.3.0 → 1.3.2

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,29 @@ 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 runName;
49
+ const positional = [];
50
+ for (let i = 0; i < raw.length; i++) {
51
+ const arg = raw[i];
52
+ if (arg === "-m" || arg === "--menu") {
53
+ menu = true;
54
+ continue;
55
+ }
56
+ if (arg === "-r" || arg === "--run") {
57
+ runName = raw[i + 1];
58
+ i += 1;
59
+ continue;
60
+ }
61
+ if (arg.startsWith("--run=")) {
62
+ runName = arg.slice("--run=".length);
63
+ continue;
64
+ }
65
+ positional.push(arg);
66
+ }
49
67
  return {
50
68
  menu,
51
- single: positional[0],
69
+ single: runName || positional[0],
52
70
  };
53
71
  }
54
72
 
@@ -251,7 +269,9 @@ module.exports.run = async ()=>{
251
269
  const selections = await promptMenu(winNames);
252
270
  const exitSelected = selections.includes("__exit__");
253
271
  const selectedNames = selections.filter((item)=>item !== "__exit__");
254
- await runOnce(settings, selectedNames);
272
+ if (selectedNames.length) {
273
+ await runOnce(settings, selectedNames);
274
+ }
255
275
  if (exitSelected) break;
256
276
  }
257
277
  process.exit(0);
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.0",
3
+ "version": "1.3.2",
4
4
  "description": "Automates starting and laying out your console windows for tsc, babel, tests, verdaccio, etc...",
5
5
  "keywords": [
6
6
  "automation",
@@ -15,17 +15,19 @@
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",
20
+ "test": "node test/run-test.js"
19
21
  },
20
22
  "author": "Yuri Yaryshev",
21
23
  "license": "Unlicense",
22
24
  "dependencies": {
23
- "inquirer": "^8.2.6",
24
- "json5": "^2.1.3",
25
- "@sumbat/keysender": "^2.3.0"
25
+ "@sumbat/keysender": "^2.3.0",
26
+ "inquirer": "^13.2.1",
27
+ "json5": "^2.2.3"
26
28
  },
27
29
  "devDependencies": {
28
- "prettier": "^3.6.2"
30
+ "prettier": "^3.8.1"
29
31
  },
30
32
  "homepage": "https://github.com/yuyaryshev/my_wins",
31
33
  "repository": {
package/readme.md CHANGED
@@ -79,6 +79,14 @@ 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
+
82
90
  ### All options
83
91
 
84
92
  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
+ });