@take-out/cli 0.4.3 → 0.4.5

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.
Files changed (69) hide show
  1. package/dist/cjs/cli.cjs +53 -35
  2. package/dist/cjs/commands/changed.cjs +133 -95
  3. package/dist/cjs/commands/docs.cjs +276 -203
  4. package/dist/cjs/commands/env-setup.cjs +45 -33
  5. package/dist/cjs/commands/onboard.cjs +668 -224
  6. package/dist/cjs/commands/run-all.cjs +54 -45
  7. package/dist/cjs/commands/run.cjs +80 -65
  8. package/dist/cjs/commands/script.cjs +263 -187
  9. package/dist/cjs/commands/skills.cjs +174 -118
  10. package/dist/cjs/commands/sync.cjs +193 -93
  11. package/dist/cjs/constants/ascii.cjs +14 -12
  12. package/dist/cjs/index.cjs +12 -10
  13. package/dist/cjs/types.cjs +7 -5
  14. package/dist/cjs/utils/env-categories.cjs +53 -48
  15. package/dist/cjs/utils/env-setup.cjs +214 -106
  16. package/dist/cjs/utils/env.cjs +65 -44
  17. package/dist/cjs/utils/files.cjs +186 -113
  18. package/dist/cjs/utils/parallel-runner.cjs +125 -75
  19. package/dist/cjs/utils/ports.cjs +21 -21
  20. package/dist/cjs/utils/prerequisites.cjs +42 -34
  21. package/dist/cjs/utils/prompts.cjs +66 -41
  22. package/dist/cjs/utils/script-listing.cjs +130 -60
  23. package/dist/cjs/utils/script-utils.cjs +29 -19
  24. package/dist/cjs/utils/sync.cjs +67 -45
  25. package/dist/esm/cli.mjs +40 -24
  26. package/dist/esm/cli.mjs.map +1 -1
  27. package/dist/esm/commands/changed.mjs +104 -68
  28. package/dist/esm/commands/changed.mjs.map +1 -1
  29. package/dist/esm/commands/docs.mjs +245 -174
  30. package/dist/esm/commands/docs.mjs.map +1 -1
  31. package/dist/esm/commands/env-setup.mjs +18 -8
  32. package/dist/esm/commands/env-setup.mjs.map +1 -1
  33. package/dist/esm/commands/onboard.mjs +631 -189
  34. package/dist/esm/commands/onboard.mjs.map +1 -1
  35. package/dist/esm/commands/run-all.mjs +26 -19
  36. package/dist/esm/commands/run-all.mjs.map +1 -1
  37. package/dist/esm/commands/run.mjs +52 -39
  38. package/dist/esm/commands/run.mjs.map +1 -1
  39. package/dist/esm/commands/script.mjs +230 -156
  40. package/dist/esm/commands/script.mjs.map +1 -1
  41. package/dist/esm/commands/skills.mjs +143 -89
  42. package/dist/esm/commands/skills.mjs.map +1 -1
  43. package/dist/esm/commands/sync.mjs +160 -62
  44. package/dist/esm/commands/sync.mjs.map +1 -1
  45. package/dist/esm/constants/ascii.mjs +2 -2
  46. package/dist/esm/constants/ascii.mjs.map +1 -1
  47. package/dist/esm/utils/env-categories.mjs +29 -26
  48. package/dist/esm/utils/env-categories.mjs.map +1 -1
  49. package/dist/esm/utils/env-setup.mjs +184 -78
  50. package/dist/esm/utils/env-setup.mjs.map +1 -1
  51. package/dist/esm/utils/env.mjs +50 -31
  52. package/dist/esm/utils/env.mjs.map +1 -1
  53. package/dist/esm/utils/files.mjs +171 -100
  54. package/dist/esm/utils/files.mjs.map +1 -1
  55. package/dist/esm/utils/parallel-runner.mjs +111 -63
  56. package/dist/esm/utils/parallel-runner.mjs.map +1 -1
  57. package/dist/esm/utils/ports.mjs +9 -11
  58. package/dist/esm/utils/ports.mjs.map +1 -1
  59. package/dist/esm/utils/prerequisites.mjs +30 -24
  60. package/dist/esm/utils/prerequisites.mjs.map +1 -1
  61. package/dist/esm/utils/prompts.mjs +40 -17
  62. package/dist/esm/utils/prompts.mjs.map +1 -1
  63. package/dist/esm/utils/script-listing.mjs +101 -33
  64. package/dist/esm/utils/script-listing.mjs.map +1 -1
  65. package/dist/esm/utils/script-utils.mjs +14 -6
  66. package/dist/esm/utils/script-utils.mjs.map +1 -1
  67. package/dist/esm/utils/sync.mjs +38 -18
  68. package/dist/esm/utils/sync.mjs.map +1 -1
  69. package/package.json +5 -5
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: !0
9
- });
10
- },
11
- __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
14
  get: () => from[key],
14
15
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
16
  });
16
- return to;
17
- };
17
+ }
18
+ return to;
19
+ };
18
20
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: !0
21
+ value: true
20
22
  }), mod);
21
23
  var files_exports = {};
22
24
  __export(files_exports, {
@@ -28,166 +30,237 @@ __export(files_exports, {
28
30
  updatePackageJsonEnv: () => updatePackageJsonEnv
29
31
  });
30
32
  module.exports = __toCommonJS(files_exports);
31
- var import_node_child_process = require("node:child_process"),
32
- import_node_fs = require("node:fs"),
33
- import_node_path = require("node:path");
33
+ var import_node_child_process = require("node:child_process");
34
+ var import_node_fs = require("node:fs");
35
+ var import_node_path = require("node:path");
34
36
  function updatePackageJson(cwd, updates) {
35
37
  const packagePath = (0, import_node_path.join)(cwd, "package.json");
36
- if (!(0, import_node_fs.existsSync)(packagePath)) return {
37
- success: !1,
38
- error: "package.json not found"
39
- };
38
+ if (!(0, import_node_fs.existsSync)(packagePath)) {
39
+ return {
40
+ success: false,
41
+ error: "package.json not found"
42
+ };
43
+ }
40
44
  try {
41
- const content = (0, import_node_fs.readFileSync)(packagePath, "utf-8"),
42
- pkg = JSON.parse(content);
43
- return updates.name && (pkg.name = updates.name), updates.description && (pkg.description = updates.description), (0, import_node_fs.writeFileSync)(packagePath, JSON.stringify(pkg, null, 2) + `
44
- `, "utf-8"), {
45
- success: !0
45
+ const content = (0, import_node_fs.readFileSync)(packagePath, "utf-8");
46
+ const pkg = JSON.parse(content);
47
+ if (updates.name) pkg.name = updates.name;
48
+ if (updates.description) pkg.description = updates.description;
49
+ (0, import_node_fs.writeFileSync)(packagePath, JSON.stringify(pkg, null, 2) + "\n", "utf-8");
50
+ return {
51
+ success: true
46
52
  };
47
53
  } catch (error) {
48
54
  return {
49
- success: !1,
55
+ success: false,
50
56
  error: error instanceof Error ? error.message : "Unknown error"
51
57
  };
52
58
  }
53
59
  }
54
60
  function updateAppConfig(cwd, updates) {
55
61
  const configPath = (0, import_node_path.join)(cwd, "app.config.ts");
56
- if (!(0, import_node_fs.existsSync)(configPath)) return {
57
- success: !1,
58
- error: "app.config.ts not found"
59
- };
62
+ if (!(0, import_node_fs.existsSync)(configPath)) {
63
+ return {
64
+ success: false,
65
+ error: "app.config.ts not found"
66
+ };
67
+ }
60
68
  try {
61
69
  let content = (0, import_node_fs.readFileSync)(configPath, "utf-8");
62
- return updates.name && (content = content.replace(/(name:\s*['"])([^'"]+)(['"])/, `$1${updates.name}$3`)), updates.slug && (content = content.replace(/(slug:\s*['"])([^'"]+)(['"])/, `$1${updates.slug}$3`)), updates.bundleId && (content = content.replace(/(bundleIdentifier:\s*['"])([^'"]+)(['"])/, `$1${updates.bundleId}$3`), content = content.replace(/(package:\s*['"])([^'"]+)(['"])/, `$1${updates.bundleId}$3`)), (0, import_node_fs.writeFileSync)(configPath, content, "utf-8"), {
63
- success: !0
70
+ if (updates.name) {
71
+ content = content.replace(/(name:\s*['"])([^'"]+)(['"])/, `$1${updates.name}$3`);
72
+ }
73
+ if (updates.slug) {
74
+ content = content.replace(/(slug:\s*['"])([^'"]+)(['"])/, `$1${updates.slug}$3`);
75
+ }
76
+ if (updates.bundleId) {
77
+ content = content.replace(/(bundleIdentifier:\s*['"])([^'"]+)(['"])/, `$1${updates.bundleId}$3`);
78
+ content = content.replace(/(package:\s*['"])([^'"]+)(['"])/, `$1${updates.bundleId}$3`);
79
+ }
80
+ (0, import_node_fs.writeFileSync)(configPath, content, "utf-8");
81
+ return {
82
+ success: true
64
83
  };
65
84
  } catch (error) {
66
85
  return {
67
- success: !1,
86
+ success: false,
68
87
  error: error instanceof Error ? error.message : "Unknown error"
69
88
  };
70
89
  }
71
90
  }
72
91
  function checkOnboarded(cwd) {
73
92
  const packagePath = (0, import_node_path.join)(cwd, "package.json");
74
- if (!(0, import_node_fs.existsSync)(packagePath)) return !1;
93
+ if (!(0, import_node_fs.existsSync)(packagePath)) return false;
75
94
  try {
76
- return JSON.parse((0, import_node_fs.readFileSync)(packagePath, "utf-8")).takeout?.onboarded === !0;
95
+ const pkg = JSON.parse((0, import_node_fs.readFileSync)(packagePath, "utf-8"));
96
+ return pkg.takeout?.onboarded === true;
77
97
  } catch {
78
- return !1;
98
+ return false;
79
99
  }
80
100
  }
81
101
  function markOnboarded(cwd) {
82
102
  const packagePath = (0, import_node_path.join)(cwd, "package.json");
83
- if (!(0, import_node_fs.existsSync)(packagePath)) return {
84
- success: !1,
85
- error: "package.json not found"
86
- };
103
+ if (!(0, import_node_fs.existsSync)(packagePath)) {
104
+ return {
105
+ success: false,
106
+ error: "package.json not found"
107
+ };
108
+ }
87
109
  try {
88
- const content = (0, import_node_fs.readFileSync)(packagePath, "utf-8"),
89
- pkg = JSON.parse(content);
90
- return pkg.takeout || (pkg.takeout = {}), pkg.takeout.onboarded = !0, (0, import_node_fs.writeFileSync)(packagePath, JSON.stringify(pkg, null, 2) + `
91
- `, "utf-8"), {
92
- success: !0
110
+ const content = (0, import_node_fs.readFileSync)(packagePath, "utf-8");
111
+ const pkg = JSON.parse(content);
112
+ if (!pkg.takeout) {
113
+ pkg.takeout = {};
114
+ }
115
+ pkg.takeout.onboarded = true;
116
+ (0, import_node_fs.writeFileSync)(packagePath, JSON.stringify(pkg, null, 2) + "\n", "utf-8");
117
+ return {
118
+ success: true
93
119
  };
94
120
  } catch (error) {
95
121
  return {
96
- success: !1,
122
+ success: false,
97
123
  error: error instanceof Error ? error.message : "Unknown error"
98
124
  };
99
125
  }
100
126
  }
101
127
  function updatePackageJsonEnv(cwd, platform) {
102
128
  const packagePath = (0, import_node_path.join)(cwd, "package.json");
103
- if (!(0, import_node_fs.existsSync)(packagePath)) return {
104
- success: !1,
105
- error: "package.json not found"
106
- };
129
+ if (!(0, import_node_fs.existsSync)(packagePath)) {
130
+ return {
131
+ success: false,
132
+ error: "package.json not found"
133
+ };
134
+ }
107
135
  try {
108
- const content = (0, import_node_fs.readFileSync)(packagePath, "utf-8"),
109
- pkg = JSON.parse(content);
110
- return pkg.env ? (platform === "sst" ? (delete pkg.env.DEPLOY_HOST, delete pkg.env.DEPLOY_USER, delete pkg.env.DEPLOY_SSH_KEY) : platform === "uncloud" && (delete pkg.env.CLOUDFLARE_API_TOKEN, delete pkg.env.AWS_ACCESS_KEY_ID, delete pkg.env.AWS_SECRET_ACCESS_KEY), (0, import_node_fs.writeFileSync)(packagePath, JSON.stringify(pkg, null, 2) + `
111
- `, "utf-8"), {
112
- success: !0
113
- }) : {
114
- success: !1,
115
- error: "env section not found in package.json"
136
+ const content = (0, import_node_fs.readFileSync)(packagePath, "utf-8");
137
+ const pkg = JSON.parse(content);
138
+ if (!pkg.env) {
139
+ return {
140
+ success: false,
141
+ error: "env section not found in package.json"
142
+ };
143
+ }
144
+ if (platform === "sst") {
145
+ delete pkg.env.DEPLOY_HOST;
146
+ delete pkg.env.DEPLOY_USER;
147
+ delete pkg.env.DEPLOY_SSH_KEY;
148
+ } else if (platform === "uncloud") {
149
+ delete pkg.env.CLOUDFLARE_API_TOKEN;
150
+ delete pkg.env.AWS_ACCESS_KEY_ID;
151
+ delete pkg.env.AWS_SECRET_ACCESS_KEY;
152
+ }
153
+ (0, import_node_fs.writeFileSync)(packagePath, JSON.stringify(pkg, null, 2) + "\n", "utf-8");
154
+ return {
155
+ success: true
116
156
  };
117
157
  } catch (error) {
118
158
  return {
119
- success: !1,
159
+ success: false,
120
160
  error: error instanceof Error ? error.message : "Unknown error"
121
161
  };
122
162
  }
123
163
  }
124
164
  async function ejectFromMonorepo(cwd, options = {}) {
125
165
  const {
126
- dryRun = !1
127
- } = options,
128
- packagePath = (0, import_node_path.join)(cwd, "package.json"),
129
- packagesDir = (0, import_node_path.join)(cwd, "packages"),
130
- warnings = [];
131
- if (!(0, import_node_fs.existsSync)(packagePath)) return {
132
- success: !1,
133
- error: "package.json not found"
134
- };
166
+ dryRun = false
167
+ } = options;
168
+ const packagePath = (0, import_node_path.join)(cwd, "package.json");
169
+ const packagesDir = (0, import_node_path.join)(cwd, "packages");
170
+ const warnings = [];
171
+ if (!(0, import_node_fs.existsSync)(packagePath)) {
172
+ return {
173
+ success: false,
174
+ error: "package.json not found"
175
+ };
176
+ }
135
177
  try {
136
- const content = (0, import_node_fs.readFileSync)(packagePath, "utf-8"),
137
- pkg = JSON.parse(content);
138
- if (!(0, import_node_fs.existsSync)(packagesDir)) return {
139
- success: !1,
140
- error: "packages directory not found - already ejected?"
141
- };
142
- if (!pkg.workspaces) return {
143
- success: !1,
144
- error: "no workspaces field found - already ejected?"
145
- };
146
- const workspacePackages = [],
147
- entries = (0, import_node_fs.readdirSync)(packagesDir, {
148
- withFileTypes: !0
149
- });
178
+ const content = (0, import_node_fs.readFileSync)(packagePath, "utf-8");
179
+ const pkg = JSON.parse(content);
180
+ if (!(0, import_node_fs.existsSync)(packagesDir)) {
181
+ return {
182
+ success: false,
183
+ error: "packages directory not found - already ejected?"
184
+ };
185
+ }
186
+ if (!pkg.workspaces) {
187
+ return {
188
+ success: false,
189
+ error: "no workspaces field found - already ejected?"
190
+ };
191
+ }
192
+ const workspacePackages = [];
193
+ const entries = (0, import_node_fs.readdirSync)(packagesDir, {
194
+ withFileTypes: true
195
+ });
150
196
  for (const entry of entries) {
151
197
  if (!entry.isDirectory()) continue;
152
198
  const pkgJsonPath = (0, import_node_path.join)(packagesDir, entry.name, "package.json");
153
- if ((0, import_node_fs.existsSync)(pkgJsonPath)) try {
154
- const pkgJson = JSON.parse((0, import_node_fs.readFileSync)(pkgJsonPath, "utf-8"));
155
- pkgJson.name && pkgJson.version ? workspacePackages.push({
156
- name: pkgJson.name,
157
- version: pkgJson.version
158
- }) : warnings.push(`skipped ${entry.name}: missing name or version`);
159
- } catch {
160
- warnings.push(`skipped ${entry.name}: invalid package.json`);
199
+ if ((0, import_node_fs.existsSync)(pkgJsonPath)) {
200
+ try {
201
+ const pkgJson = JSON.parse((0, import_node_fs.readFileSync)(pkgJsonPath, "utf-8"));
202
+ if (pkgJson.name && pkgJson.version) {
203
+ workspacePackages.push({
204
+ name: pkgJson.name,
205
+ version: pkgJson.version
206
+ });
207
+ } else {
208
+ warnings.push(`skipped ${entry.name}: missing name or version`);
209
+ }
210
+ } catch (e) {
211
+ warnings.push(`skipped ${entry.name}: invalid package.json`);
212
+ }
161
213
  }
162
214
  }
163
- if (workspacePackages.length === 0) return {
164
- success: !1,
165
- error: "no valid workspace packages found"
166
- };
167
- const unresolvedDeps = [],
168
- allDeps = {
169
- ...pkg.dependencies,
170
- ...pkg.devDependencies
215
+ if (workspacePackages.length === 0) {
216
+ return {
217
+ success: false,
218
+ error: "no valid workspace packages found"
171
219
  };
172
- for (const [name, version] of Object.entries(allDeps)) version === "workspace:*" && (workspacePackages.find(p => p.name === name) || unresolvedDeps.push(name));
173
- if (unresolvedDeps.length > 0) return {
174
- success: !1,
175
- error: `unresolved workspace dependencies: ${unresolvedDeps.join(", ")}`,
176
- packages: workspacePackages
177
- };
178
- if (dryRun) return {
179
- success: !0,
180
- packages: workspacePackages,
181
- warnings: warnings.length > 0 ? warnings : void 0
220
+ }
221
+ const unresolvedDeps = [];
222
+ const allDeps = {
223
+ ...pkg.dependencies,
224
+ ...pkg.devDependencies
182
225
  };
226
+ for (const [name, version] of Object.entries(allDeps)) {
227
+ if (version === "workspace:*") {
228
+ const found = workspacePackages.find(p => p.name === name);
229
+ if (!found) {
230
+ unresolvedDeps.push(name);
231
+ }
232
+ }
233
+ }
234
+ if (unresolvedDeps.length > 0) {
235
+ return {
236
+ success: false,
237
+ error: `unresolved workspace dependencies: ${unresolvedDeps.join(", ")}`,
238
+ packages: workspacePackages
239
+ };
240
+ }
241
+ if (dryRun) {
242
+ return {
243
+ success: true,
244
+ packages: workspacePackages,
245
+ warnings: warnings.length > 0 ? warnings : void 0
246
+ };
247
+ }
183
248
  for (const {
184
249
  name,
185
250
  version
186
- } of workspacePackages) pkg.dependencies?.[name] === "workspace:*" && (pkg.dependencies[name] = `^${version}`), pkg.devDependencies?.[name] === "workspace:*" && (pkg.devDependencies[name] = `^${version}`);
187
- delete pkg.workspaces, (0, import_node_fs.writeFileSync)(packagePath, JSON.stringify(pkg, null, 2) + `
188
- `, "utf-8"), (0, import_node_fs.rmSync)(packagesDir, {
189
- recursive: !0,
190
- force: !0
251
+ } of workspacePackages) {
252
+ if (pkg.dependencies?.[name] === "workspace:*") {
253
+ pkg.dependencies[name] = `^${version}`;
254
+ }
255
+ if (pkg.devDependencies?.[name] === "workspace:*") {
256
+ pkg.devDependencies[name] = `^${version}`;
257
+ }
258
+ }
259
+ delete pkg.workspaces;
260
+ (0, import_node_fs.writeFileSync)(packagePath, JSON.stringify(pkg, null, 2) + "\n", "utf-8");
261
+ (0, import_node_fs.rmSync)(packagesDir, {
262
+ recursive: true,
263
+ force: true
191
264
  });
192
265
  try {
193
266
  (0, import_node_child_process.execSync)("bun install", {
@@ -196,19 +269,19 @@ async function ejectFromMonorepo(cwd, options = {}) {
196
269
  });
197
270
  } catch {
198
271
  return {
199
- success: !1,
272
+ success: false,
200
273
  error: 'failed to install published packages. package.json was modified but install failed. try running "bun install" manually, or restore from git.',
201
274
  packages: workspacePackages
202
275
  };
203
276
  }
204
277
  return {
205
- success: !0,
278
+ success: true,
206
279
  packages: workspacePackages,
207
280
  warnings: warnings.length > 0 ? warnings : void 0
208
281
  };
209
282
  } catch (error) {
210
283
  return {
211
- success: !1,
284
+ success: false,
212
285
  error: error instanceof Error ? error.message : "Unknown error"
213
286
  };
214
287
  }
@@ -3,44 +3,46 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: !0
9
- });
10
- },
11
- __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
14
  get: () => from[key],
14
15
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
16
  });
16
- return to;
17
- };
17
+ }
18
+ return to;
19
+ };
18
20
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: !0
21
+ value: true
20
22
  }), mod);
21
23
  var parallel_runner_exports = {};
22
24
  __export(parallel_runner_exports, {
23
25
  runScriptsInParallel: () => runScriptsInParallel
24
26
  });
25
27
  module.exports = __toCommonJS(parallel_runner_exports);
26
- var import_node_child_process = require("node:child_process"),
27
- import_node_os = require("node:os");
28
+ var import_node_child_process = require("node:child_process");
29
+ var import_node_os = require("node:os");
28
30
  const colors = ["\x1B[36m",
29
- // Cyan
30
- "\x1B[35m",
31
- // Magenta
32
- "\x1B[33m",
33
- // Yellow
34
- "\x1B[32m",
35
- // Green
36
- "\x1B[34m",
37
- // Blue
38
- "\x1B[31m",
39
- // Red
40
- "\x1B[90m"
41
- // Gray
42
- ],
43
- reset = "\x1B[0m";
31
+ // Cyan
32
+ "\x1B[35m",
33
+ // Magenta
34
+ "\x1B[33m",
35
+ // Yellow
36
+ "\x1B[32m",
37
+ // Green
38
+ "\x1B[34m",
39
+ // Blue
40
+ "\x1B[31m",
41
+ // Red
42
+ "\x1B[90m"
43
+ // Gray
44
+ ];
45
+ const reset = "\x1B[0m";
44
46
  function isBunShellNoise(line) {
45
47
  const stripped = line.replace(/\x1b\[[0-9;]*m/g, "").trim();
46
48
  return stripped.startsWith("ShellError:") || stripped.startsWith("exitCode:") || stripped.startsWith("stdout:") || stripped.startsWith("stderr:") || stripped.startsWith("at ShellPromise") || stripped.startsWith("at BunShell") || stripped.startsWith("Bun v") || /^\d+\s*\|/.test(stripped) ||
@@ -48,21 +50,29 @@ function isBunShellNoise(line) {
48
50
  /^\s*\^$/.test(stripped);
49
51
  }
50
52
  const spawnedProcesses = [];
51
- let cleaning = !1;
53
+ let cleaning = false;
52
54
  function killAllProcessGroups(signal = "SIGTERM") {
53
- for (const proc of spawnedProcesses) if (proc.pid) try {
54
- process.kill(-proc.pid, signal);
55
- } catch {
56
- try {
57
- process.kill(proc.pid, signal);
58
- } catch {}
55
+ for (const proc of spawnedProcesses) {
56
+ if (proc.pid) {
57
+ try {
58
+ process.kill(-proc.pid, signal);
59
+ } catch (_) {
60
+ try {
61
+ process.kill(proc.pid, signal);
62
+ } catch (_2) {}
63
+ }
64
+ }
59
65
  }
60
66
  }
61
67
  function cleanupAndExit() {
62
- cleaning || (cleaning = !0, process.stdout.write(`
63
- \x1B[0m`), killAllProcessGroups("SIGTERM"), setTimeout(() => {
64
- killAllProcessGroups("SIGKILL"), process.exit(0);
65
- }, 150));
68
+ if (cleaning) return;
69
+ cleaning = true;
70
+ process.stdout.write("\n\x1B[0m");
71
+ killAllProcessGroups("SIGTERM");
72
+ setTimeout(() => {
73
+ killAllProcessGroups("SIGKILL");
74
+ process.exit(0);
75
+ }, 150);
66
76
  }
67
77
  process.on("SIGINT", cleanupAndExit);
68
78
  process.on("SIGTERM", cleanupAndExit);
@@ -72,56 +82,96 @@ async function runScriptsInParallel(scripts, options = {}) {
72
82
  onError = "exit",
73
83
  maxParallelism = (0, import_node_os.cpus)().length
74
84
  } = options;
75
- title && (console.info(), console.info(title), console.info());
76
- const allPromises = [],
77
- executing = /* @__PURE__ */new Set();
85
+ if (title) {
86
+ console.info();
87
+ console.info(title);
88
+ console.info();
89
+ }
90
+ const allPromises = [];
91
+ const executing = /* @__PURE__ */new Set();
78
92
  for (let i = 0; i < scripts.length; i++) {
79
- const script = scripts[i],
80
- scriptPromise = runSingleScript(script, i).finally(() => {
81
- executing.delete(scriptPromise);
82
- });
83
- allPromises.push(scriptPromise), executing.add(scriptPromise), executing.size >= maxParallelism && (await Promise.race(executing));
93
+ const script = scripts[i];
94
+ const scriptPromise = runSingleScript(script, i).finally(() => {
95
+ executing.delete(scriptPromise);
96
+ });
97
+ allPromises.push(scriptPromise);
98
+ executing.add(scriptPromise);
99
+ if (executing.size >= maxParallelism) {
100
+ await Promise.race(executing);
101
+ }
84
102
  }
85
- const failures = (await Promise.allSettled(allPromises)).filter(r => r.status === "rejected");
86
- failures.length > 0 ? (console.error(`
103
+ const settledResults = await Promise.allSettled(allPromises);
104
+ const failures = settledResults.filter(r => r.status === "rejected");
105
+ if (failures.length > 0) {
106
+ console.error(`
87
107
  ${reset}\x1B[31m\u2717 ${failures.length} script(s) failed${reset}
88
- `), onError === "exit" && process.exit(1)) : console.info(`
108
+ `);
109
+ if (onError === "exit") {
110
+ process.exit(1);
111
+ }
112
+ } else {
113
+ console.info(`
89
114
  ${reset}\x1B[32m\u2713 All scripts completed successfully${reset}
90
115
  `);
116
+ }
91
117
  }
92
118
  function runSingleScript(script, colorIndex) {
93
119
  return new Promise((resolve, reject) => {
94
- const color = colors[colorIndex % colors.length],
95
- prefixLabel = script.name,
96
- proc = (0, import_node_child_process.spawn)("bun", [script.path, ...(script.args || [])], {
97
- stdio: ["pipe", "pipe", "pipe"],
98
- shell: !1,
99
- env: {
100
- ...process.env,
101
- FORCE_COLOR: "3",
102
- TKO_IS_RUNNING_ALL: "1"
103
- },
104
- detached: !0
105
- });
120
+ const color = colors[colorIndex % colors.length];
121
+ const prefixLabel = script.name;
122
+ const proc = (0, import_node_child_process.spawn)("bun", [script.path, ...(script.args || [])], {
123
+ stdio: ["pipe", "pipe", "pipe"],
124
+ shell: false,
125
+ env: {
126
+ ...process.env,
127
+ FORCE_COLOR: "3",
128
+ TKO_IS_RUNNING_ALL: "1"
129
+ },
130
+ detached: true
131
+ });
106
132
  spawnedProcesses.push(proc);
107
133
  let stderrBuffer = "";
108
134
  proc.stdout.on("data", data => {
109
135
  if (cleaning) return;
110
- const lines = data.toString().split(`
111
- `);
112
- for (const line of lines) line && console.info(`${color}${prefixLabel}${reset} ${line}`);
113
- }), proc.stderr.on("data", data => {
136
+ const lines = data.toString().split("\n");
137
+ for (const line of lines) {
138
+ if (line) console.info(`${color}${prefixLabel}${reset} ${line}`);
139
+ }
140
+ });
141
+ proc.stderr.on("data", data => {
114
142
  const dataStr = data.toString();
115
- if (stderrBuffer += dataStr, cleaning) return;
116
- const lines = dataStr.split(`
117
- `);
118
- for (const line of lines) line && !isBunShellNoise(line) && console.error(`${color}${prefixLabel}${reset} ${line}`);
119
- }), proc.on("error", error => {
120
- console.error(`${color}${prefixLabel}${reset} Failed to start: ${error.message}`), reject(error);
121
- }), proc.on("close", code => {
122
- cleaning || (code && code !== 0 ? (stderrBuffer.includes("ShellError") || stderrBuffer.includes("at BunShell") || (console.error(`${color}${prefixLabel}${reset} Process exited with code ${code}`), stderrBuffer.trim() && (console.error(`
123
- ${color}${prefixLabel}${reset} Error output:`), console.error("\x1B[90m" + "\u2500".repeat(80) + "\x1B[0m"), console.error(stderrBuffer), console.error("\x1B[90m" + "\u2500".repeat(80) + `\x1B[0m
124
- `))), reject(new Error(`Script ${prefixLabel} failed with code ${code}`))) : (console.info(`${color}${prefixLabel}${reset} \x1B[32m\u2713 completed${reset}`), resolve()));
143
+ stderrBuffer += dataStr;
144
+ if (cleaning) return;
145
+ const lines = dataStr.split("\n");
146
+ for (const line of lines) {
147
+ if (line && !isBunShellNoise(line)) {
148
+ console.error(`${color}${prefixLabel}${reset} ${line}`);
149
+ }
150
+ }
151
+ });
152
+ proc.on("error", error => {
153
+ console.error(`${color}${prefixLabel}${reset} Failed to start: ${error.message}`);
154
+ reject(error);
155
+ });
156
+ proc.on("close", code => {
157
+ if (cleaning) return;
158
+ if (code && code !== 0) {
159
+ const isBunShellError = stderrBuffer.includes("ShellError") || stderrBuffer.includes("at BunShell");
160
+ if (!isBunShellError) {
161
+ console.error(`${color}${prefixLabel}${reset} Process exited with code ${code}`);
162
+ if (stderrBuffer.trim()) {
163
+ console.error(`
164
+ ${color}${prefixLabel}${reset} Error output:`);
165
+ console.error("\x1B[90m" + "\u2500".repeat(80) + "\x1B[0m");
166
+ console.error(stderrBuffer);
167
+ console.error("\x1B[90m" + "\u2500".repeat(80) + "\x1B[0m\n");
168
+ }
169
+ }
170
+ reject(new Error(`Script ${prefixLabel} failed with code ${code}`));
171
+ } else {
172
+ console.info(`${color}${prefixLabel}${reset} \x1B[32m\u2713 completed${reset}`);
173
+ resolve();
174
+ }
125
175
  });
126
176
  });
127
177
  }