sdtk-code-kit 0.2.0 → 0.2.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/README.md +201 -201
- package/assets/manifest/toolkit-bundle.manifest.json +147 -147
- package/assets/manifest/toolkit-bundle.sha256.txt +28 -28
- package/assets/toolkit/toolkit/AGENTS.md +219 -219
- package/assets/toolkit/toolkit/install.ps1 +156 -156
- package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +78 -78
- package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +150 -150
- package/assets/toolkit/toolkit/scripts/uninstall-claude-skills.ps1 +62 -62
- package/assets/toolkit/toolkit/scripts/uninstall-codex-skills.ps1 +82 -82
- package/assets/toolkit/toolkit/sdtk-spec.config.json +6 -6
- package/assets/toolkit/toolkit/sdtk-spec.config.profiles.example.json +12 -12
- package/assets/toolkit/toolkit/skills/code-brainstorm/SKILL.md +55 -55
- package/assets/toolkit/toolkit/skills/code-debug/SKILL.md +296 -296
- package/assets/toolkit/toolkit/skills/code-debug/references/root-cause-tracing.md +68 -68
- package/assets/toolkit/toolkit/skills/code-discover/SKILL.md +54 -54
- package/assets/toolkit/toolkit/skills/code-execute/SKILL.md +74 -74
- package/assets/toolkit/toolkit/skills/code-finish/SKILL.md +205 -205
- package/assets/toolkit/toolkit/skills/code-parallel/SKILL.md +64 -64
- package/assets/toolkit/toolkit/skills/code-parallel/references/code-quality-reviewer-prompt.md +26 -26
- package/assets/toolkit/toolkit/skills/code-parallel/references/implementer-prompt.md +113 -113
- package/assets/toolkit/toolkit/skills/code-parallel/references/spec-reviewer-prompt.md +61 -61
- package/assets/toolkit/toolkit/skills/code-plan/SKILL.md +85 -85
- package/assets/toolkit/toolkit/skills/code-review/SKILL.md +79 -79
- package/assets/toolkit/toolkit/skills/code-review/references/checklist.md +125 -125
- package/assets/toolkit/toolkit/skills/code-review/references/code-reviewer.md +146 -146
- package/assets/toolkit/toolkit/skills/code-ship/SKILL.md +52 -52
- package/assets/toolkit/toolkit/skills/code-tdd/SKILL.md +378 -378
- package/assets/toolkit/toolkit/skills/code-tdd/references/testing-anti-patterns.md +299 -299
- package/assets/toolkit/toolkit/skills/code-verify/SKILL.md +144 -144
- package/assets/toolkit/toolkit/skills/code-worktree/SKILL.md +228 -228
- package/assets/toolkit/toolkit/templates/CODE_WORKFLOW_TEMPLATE.md +140 -140
- package/bin/sdtk-code.js +14 -14
- package/package.json +44 -44
- package/src/commands/build.js +53 -53
- package/src/commands/doctor.js +51 -51
- package/src/commands/generate.js +11 -11
- package/src/commands/guardrails.js +215 -123
- package/src/commands/help.js +244 -244
- package/src/commands/init.js +98 -98
- package/src/commands/plan.js +53 -53
- package/src/commands/readiness.js +77 -77
- package/src/commands/resume.js +61 -61
- package/src/commands/runtime.js +224 -224
- package/src/commands/ship.js +59 -59
- package/src/commands/sleep.js +132 -0
- package/src/commands/start.js +89 -89
- package/src/commands/status.js +77 -77
- package/src/commands/update.js +11 -11
- package/src/commands/verify.js +71 -71
- package/src/index.js +108 -104
- package/src/lib/args.js +107 -107
- package/src/lib/errors.js +41 -41
- package/src/lib/powershell.js +65 -65
- package/src/lib/project-target-guard.js +53 -53
- package/src/lib/scope.js +72 -72
- package/src/lib/ship-readiness.js +281 -281
- package/src/lib/sleep-plan.js +175 -0
- package/src/lib/sleep-report.js +229 -0
- package/src/lib/toolkit-payload.js +72 -72
- package/src/lib/trust-events.js +166 -166
- package/src/lib/trust-file-scope.js +154 -154
- package/src/lib/trust-policy.js +212 -212
- package/src/lib/trust-redact.js +35 -35
- package/src/lib/trust-trace.js +179 -179
- package/src/lib/update.js +344 -344
- package/src/lib/workflow-artifact.js +503 -503
- package/src/lib/workflow-build.js +127 -127
- package/src/lib/workflow-doctor.js +83 -83
- package/src/lib/workflow-handoff.js +1029 -1029
- package/src/lib/workflow-intake.js +101 -101
- package/src/lib/workflow-plan.js +193 -193
- package/src/lib/workflow-review-packet.js +650 -650
- package/src/lib/workflow-ship.js +213 -213
- package/src/lib/workflow-state.js +438 -438
- package/src/lib/workflow-verify.js +393 -393
package/src/index.js
CHANGED
|
@@ -1,104 +1,108 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { cmdBuild } = require("./commands/build");
|
|
4
|
-
const { cmdDoctor } = require("./commands/doctor");
|
|
5
|
-
const { cmdGuardrails } = require("./commands/guardrails");
|
|
6
|
-
const { cmdHelp } = require("./commands/help");
|
|
7
|
-
const { cmdReadiness } = require("./commands/readiness");
|
|
8
|
-
const { cmdInit } = require("./commands/init");
|
|
9
|
-
const { cmdPlan } = require("./commands/plan");
|
|
10
|
-
const { cmdResume } = require("./commands/resume");
|
|
11
|
-
const { cmdRuntime } = require("./commands/runtime");
|
|
12
|
-
const { cmdShip } = require("./commands/ship");
|
|
13
|
-
const { cmdStart } = require("./commands/start");
|
|
14
|
-
const { cmdStatus } = require("./commands/status");
|
|
15
|
-
const {
|
|
16
|
-
const {
|
|
17
|
-
const {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
case "
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return
|
|
75
|
-
case "
|
|
76
|
-
return
|
|
77
|
-
case "
|
|
78
|
-
return
|
|
79
|
-
case "
|
|
80
|
-
return
|
|
81
|
-
case "
|
|
82
|
-
return
|
|
83
|
-
case "
|
|
84
|
-
return
|
|
85
|
-
case "
|
|
86
|
-
return
|
|
87
|
-
case "
|
|
88
|
-
return
|
|
89
|
-
case "
|
|
90
|
-
return
|
|
91
|
-
case "
|
|
92
|
-
return
|
|
93
|
-
case "
|
|
94
|
-
return
|
|
95
|
-
case "
|
|
96
|
-
return
|
|
97
|
-
case "
|
|
98
|
-
return
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { cmdBuild } = require("./commands/build");
|
|
4
|
+
const { cmdDoctor } = require("./commands/doctor");
|
|
5
|
+
const { cmdGuardrails } = require("./commands/guardrails");
|
|
6
|
+
const { cmdHelp } = require("./commands/help");
|
|
7
|
+
const { cmdReadiness } = require("./commands/readiness");
|
|
8
|
+
const { cmdInit } = require("./commands/init");
|
|
9
|
+
const { cmdPlan } = require("./commands/plan");
|
|
10
|
+
const { cmdResume } = require("./commands/resume");
|
|
11
|
+
const { cmdRuntime } = require("./commands/runtime");
|
|
12
|
+
const { cmdShip } = require("./commands/ship");
|
|
13
|
+
const { cmdStart } = require("./commands/start");
|
|
14
|
+
const { cmdStatus } = require("./commands/status");
|
|
15
|
+
const { cmdSleep } = require("./commands/sleep");
|
|
16
|
+
const { cmdUpdate } = require("./commands/update");
|
|
17
|
+
const { cmdVerify } = require("./commands/verify");
|
|
18
|
+
const { ValidationError } = require("./lib/errors");
|
|
19
|
+
|
|
20
|
+
function getVersion() {
|
|
21
|
+
const pkg = require("../package.json");
|
|
22
|
+
return pkg.version;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function parseCommand(argv) {
|
|
26
|
+
if (!argv || argv.length === 0) {
|
|
27
|
+
return { command: "help", args: [] };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const [first, ...rest] = argv;
|
|
31
|
+
if (first === "-h" || first === "--help") {
|
|
32
|
+
return { command: "help", args: [] };
|
|
33
|
+
}
|
|
34
|
+
if (first === "-v" || first === "--version") {
|
|
35
|
+
return { command: "version", args: [] };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { command: first, args: rest };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const COMMANDS = new Set([
|
|
42
|
+
"help",
|
|
43
|
+
"version",
|
|
44
|
+
"init",
|
|
45
|
+
"runtime",
|
|
46
|
+
"start",
|
|
47
|
+
"plan",
|
|
48
|
+
"build",
|
|
49
|
+
"verify",
|
|
50
|
+
"ship",
|
|
51
|
+
"status",
|
|
52
|
+
"doctor",
|
|
53
|
+
"guardrails",
|
|
54
|
+
"readiness",
|
|
55
|
+
"resume",
|
|
56
|
+
"sleep",
|
|
57
|
+
"update",
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
async function run(argv) {
|
|
61
|
+
const { command, args } = parseCommand(argv);
|
|
62
|
+
|
|
63
|
+
if (!COMMANDS.has(command)) {
|
|
64
|
+
throw new ValidationError(
|
|
65
|
+
`Unknown command: "${command}". Run "sdtk-code --help" for available commands.`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
switch (command) {
|
|
70
|
+
case "help":
|
|
71
|
+
return cmdHelp();
|
|
72
|
+
case "version":
|
|
73
|
+
console.log(`sdtk-code-kit ${getVersion()}`);
|
|
74
|
+
return 0;
|
|
75
|
+
case "init":
|
|
76
|
+
return cmdInit(args);
|
|
77
|
+
case "runtime":
|
|
78
|
+
return cmdRuntime(args);
|
|
79
|
+
case "start":
|
|
80
|
+
return cmdStart(args);
|
|
81
|
+
case "plan":
|
|
82
|
+
return cmdPlan(args);
|
|
83
|
+
case "build":
|
|
84
|
+
return cmdBuild(args);
|
|
85
|
+
case "verify":
|
|
86
|
+
return cmdVerify(args);
|
|
87
|
+
case "ship":
|
|
88
|
+
return cmdShip(args);
|
|
89
|
+
case "status":
|
|
90
|
+
return cmdStatus(args);
|
|
91
|
+
case "doctor":
|
|
92
|
+
return cmdDoctor(args);
|
|
93
|
+
case "guardrails":
|
|
94
|
+
return cmdGuardrails(args);
|
|
95
|
+
case "readiness":
|
|
96
|
+
return cmdReadiness(args);
|
|
97
|
+
case "resume":
|
|
98
|
+
return cmdResume(args);
|
|
99
|
+
case "sleep":
|
|
100
|
+
return cmdSleep(args);
|
|
101
|
+
case "update":
|
|
102
|
+
return cmdUpdate(args);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = {
|
|
107
|
+
run,
|
|
108
|
+
};
|
package/src/lib/args.js
CHANGED
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { ValidationError } = require("./errors");
|
|
4
|
-
|
|
5
|
-
function parseFlags(argv, defs) {
|
|
6
|
-
const flags = {};
|
|
7
|
-
const positional = [];
|
|
8
|
-
const aliasMap = {};
|
|
9
|
-
|
|
10
|
-
for (const [name, def] of Object.entries(defs)) {
|
|
11
|
-
if (def.alias) {
|
|
12
|
-
aliasMap[def.alias] = name;
|
|
13
|
-
}
|
|
14
|
-
if (def.type === "boolean") {
|
|
15
|
-
flags[name] = false;
|
|
16
|
-
} else if (def.multiple) {
|
|
17
|
-
flags[name] = [];
|
|
18
|
-
} else {
|
|
19
|
-
flags[name] = undefined;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let i = 0;
|
|
24
|
-
while (i < argv.length) {
|
|
25
|
-
const arg = argv[i];
|
|
26
|
-
|
|
27
|
-
if (!arg.startsWith("-")) {
|
|
28
|
-
positional.push(arg);
|
|
29
|
-
i++;
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let key;
|
|
34
|
-
let inlineValue;
|
|
35
|
-
if (arg.includes("=")) {
|
|
36
|
-
const eqIdx = arg.indexOf("=");
|
|
37
|
-
key = arg.slice(0, eqIdx);
|
|
38
|
-
inlineValue = arg.slice(eqIdx + 1);
|
|
39
|
-
} else {
|
|
40
|
-
key = arg;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const stripped = key.replace(/^-{1,2}/, "");
|
|
44
|
-
const resolved = aliasMap[stripped] || stripped;
|
|
45
|
-
if (!(resolved in defs)) {
|
|
46
|
-
throw new ValidationError(`Unknown flag: ${key}`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const def = defs[resolved];
|
|
50
|
-
if (def.type === "boolean") {
|
|
51
|
-
flags[resolved] = true;
|
|
52
|
-
i++;
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let value = inlineValue;
|
|
57
|
-
if (value === undefined) {
|
|
58
|
-
i++;
|
|
59
|
-
if (i >= argv.length) {
|
|
60
|
-
throw new ValidationError(`Flag ${key} requires a value.`);
|
|
61
|
-
}
|
|
62
|
-
value = argv[i];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (def.multiple) {
|
|
66
|
-
flags[resolved].push(value);
|
|
67
|
-
} else {
|
|
68
|
-
flags[resolved] = value;
|
|
69
|
-
}
|
|
70
|
-
i++;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return { flags, positional };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function requireFlag(flags, name, label) {
|
|
77
|
-
const value = flags[name];
|
|
78
|
-
if (value === undefined || value === null || value === "") {
|
|
79
|
-
throw new ValidationError(`Missing required flag: --${label || name}`);
|
|
80
|
-
}
|
|
81
|
-
return value;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function validateChoice(value, choices, label) {
|
|
85
|
-
if (!choices.includes(value)) {
|
|
86
|
-
throw new ValidationError(
|
|
87
|
-
`Invalid value for --${label}: "${value}". Must be one of: ${choices.join(", ")}`
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
return value;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function validatePattern(value, regex, label, hint) {
|
|
94
|
-
if (!regex.test(value)) {
|
|
95
|
-
throw new ValidationError(
|
|
96
|
-
`Invalid value for --${label}: "${value}". ${hint || `Must match ${regex}`}`
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
return value;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
module.exports = {
|
|
103
|
-
parseFlags,
|
|
104
|
-
requireFlag,
|
|
105
|
-
validateChoice,
|
|
106
|
-
validatePattern,
|
|
107
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { ValidationError } = require("./errors");
|
|
4
|
+
|
|
5
|
+
function parseFlags(argv, defs) {
|
|
6
|
+
const flags = {};
|
|
7
|
+
const positional = [];
|
|
8
|
+
const aliasMap = {};
|
|
9
|
+
|
|
10
|
+
for (const [name, def] of Object.entries(defs)) {
|
|
11
|
+
if (def.alias) {
|
|
12
|
+
aliasMap[def.alias] = name;
|
|
13
|
+
}
|
|
14
|
+
if (def.type === "boolean") {
|
|
15
|
+
flags[name] = false;
|
|
16
|
+
} else if (def.multiple) {
|
|
17
|
+
flags[name] = [];
|
|
18
|
+
} else {
|
|
19
|
+
flags[name] = undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let i = 0;
|
|
24
|
+
while (i < argv.length) {
|
|
25
|
+
const arg = argv[i];
|
|
26
|
+
|
|
27
|
+
if (!arg.startsWith("-")) {
|
|
28
|
+
positional.push(arg);
|
|
29
|
+
i++;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let key;
|
|
34
|
+
let inlineValue;
|
|
35
|
+
if (arg.includes("=")) {
|
|
36
|
+
const eqIdx = arg.indexOf("=");
|
|
37
|
+
key = arg.slice(0, eqIdx);
|
|
38
|
+
inlineValue = arg.slice(eqIdx + 1);
|
|
39
|
+
} else {
|
|
40
|
+
key = arg;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const stripped = key.replace(/^-{1,2}/, "");
|
|
44
|
+
const resolved = aliasMap[stripped] || stripped;
|
|
45
|
+
if (!(resolved in defs)) {
|
|
46
|
+
throw new ValidationError(`Unknown flag: ${key}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const def = defs[resolved];
|
|
50
|
+
if (def.type === "boolean") {
|
|
51
|
+
flags[resolved] = true;
|
|
52
|
+
i++;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let value = inlineValue;
|
|
57
|
+
if (value === undefined) {
|
|
58
|
+
i++;
|
|
59
|
+
if (i >= argv.length) {
|
|
60
|
+
throw new ValidationError(`Flag ${key} requires a value.`);
|
|
61
|
+
}
|
|
62
|
+
value = argv[i];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (def.multiple) {
|
|
66
|
+
flags[resolved].push(value);
|
|
67
|
+
} else {
|
|
68
|
+
flags[resolved] = value;
|
|
69
|
+
}
|
|
70
|
+
i++;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return { flags, positional };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function requireFlag(flags, name, label) {
|
|
77
|
+
const value = flags[name];
|
|
78
|
+
if (value === undefined || value === null || value === "") {
|
|
79
|
+
throw new ValidationError(`Missing required flag: --${label || name}`);
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function validateChoice(value, choices, label) {
|
|
85
|
+
if (!choices.includes(value)) {
|
|
86
|
+
throw new ValidationError(
|
|
87
|
+
`Invalid value for --${label}: "${value}". Must be one of: ${choices.join(", ")}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function validatePattern(value, regex, label, hint) {
|
|
94
|
+
if (!regex.test(value)) {
|
|
95
|
+
throw new ValidationError(
|
|
96
|
+
`Invalid value for --${label}: "${value}". ${hint || `Must match ${regex}`}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = {
|
|
103
|
+
parseFlags,
|
|
104
|
+
requireFlag,
|
|
105
|
+
validateChoice,
|
|
106
|
+
validatePattern,
|
|
107
|
+
};
|
package/src/lib/errors.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
class CliError extends Error {
|
|
4
|
-
constructor(message, exitCode = 4) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.name = this.constructor.name;
|
|
7
|
-
this.exitCode = exitCode;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
class ValidationError extends CliError {
|
|
12
|
-
constructor(message) {
|
|
13
|
-
super(message, 1);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class DependencyError extends CliError {
|
|
18
|
-
constructor(message) {
|
|
19
|
-
super(message, 2);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
class IntegrityError extends CliError {
|
|
24
|
-
constructor(message) {
|
|
25
|
-
super(message, 3);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
class InternalError extends CliError {
|
|
30
|
-
constructor(message) {
|
|
31
|
-
super(message, 4);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
module.exports = {
|
|
36
|
-
CliError,
|
|
37
|
-
ValidationError,
|
|
38
|
-
DependencyError,
|
|
39
|
-
IntegrityError,
|
|
40
|
-
InternalError,
|
|
41
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
class CliError extends Error {
|
|
4
|
+
constructor(message, exitCode = 4) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = this.constructor.name;
|
|
7
|
+
this.exitCode = exitCode;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class ValidationError extends CliError {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message, 1);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class DependencyError extends CliError {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message, 2);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class IntegrityError extends CliError {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message, 3);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class InternalError extends CliError {
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super(message, 4);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
CliError,
|
|
37
|
+
ValidationError,
|
|
38
|
+
DependencyError,
|
|
39
|
+
IntegrityError,
|
|
40
|
+
InternalError,
|
|
41
|
+
};
|
package/src/lib/powershell.js
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { execFile } = require("child_process");
|
|
4
|
-
const { DependencyError } = require("./errors");
|
|
5
|
-
|
|
6
|
-
function findPowerShell() {
|
|
7
|
-
if (process.platform === "win32") {
|
|
8
|
-
return "powershell.exe";
|
|
9
|
-
}
|
|
10
|
-
return "pwsh";
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function runScript(scriptPath, params = {}, options = {}) {
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
const psExe = findPowerShell();
|
|
16
|
-
const args = [
|
|
17
|
-
"-ExecutionPolicy",
|
|
18
|
-
"Bypass",
|
|
19
|
-
"-NoProfile",
|
|
20
|
-
"-NonInteractive",
|
|
21
|
-
"-File",
|
|
22
|
-
scriptPath,
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
for (const [key, value] of Object.entries(params)) {
|
|
26
|
-
if (value === true) {
|
|
27
|
-
args.push(`-${key}`);
|
|
28
|
-
} else if (value === false || value === undefined || value === null) {
|
|
29
|
-
continue;
|
|
30
|
-
} else {
|
|
31
|
-
args.push(`-${key}`);
|
|
32
|
-
args.push(String(value));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
execFile(psExe, args, { maxBuffer: 10 * 1024 * 1024 }, (error, stdout, stderr) => {
|
|
37
|
-
if (error && error.code === "ENOENT") {
|
|
38
|
-
reject(
|
|
39
|
-
new DependencyError(
|
|
40
|
-
`PowerShell not found. Ensure PowerShell is installed and available in PATH.\nTried: ${psExe}`
|
|
41
|
-
)
|
|
42
|
-
);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const exitCode = error ? error.code || 1 : 0;
|
|
47
|
-
const result = {
|
|
48
|
-
exitCode: typeof exitCode === "number" ? exitCode : 1,
|
|
49
|
-
stdout: stdout || "",
|
|
50
|
-
stderr: stderr || "",
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
if (!options.silent && result.stdout) {
|
|
54
|
-
process.stdout.write(result.stdout);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
resolve(result);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
module.exports = {
|
|
63
|
-
findPowerShell,
|
|
64
|
-
runScript,
|
|
65
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { execFile } = require("child_process");
|
|
4
|
+
const { DependencyError } = require("./errors");
|
|
5
|
+
|
|
6
|
+
function findPowerShell() {
|
|
7
|
+
if (process.platform === "win32") {
|
|
8
|
+
return "powershell.exe";
|
|
9
|
+
}
|
|
10
|
+
return "pwsh";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function runScript(scriptPath, params = {}, options = {}) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const psExe = findPowerShell();
|
|
16
|
+
const args = [
|
|
17
|
+
"-ExecutionPolicy",
|
|
18
|
+
"Bypass",
|
|
19
|
+
"-NoProfile",
|
|
20
|
+
"-NonInteractive",
|
|
21
|
+
"-File",
|
|
22
|
+
scriptPath,
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
for (const [key, value] of Object.entries(params)) {
|
|
26
|
+
if (value === true) {
|
|
27
|
+
args.push(`-${key}`);
|
|
28
|
+
} else if (value === false || value === undefined || value === null) {
|
|
29
|
+
continue;
|
|
30
|
+
} else {
|
|
31
|
+
args.push(`-${key}`);
|
|
32
|
+
args.push(String(value));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
execFile(psExe, args, { maxBuffer: 10 * 1024 * 1024 }, (error, stdout, stderr) => {
|
|
37
|
+
if (error && error.code === "ENOENT") {
|
|
38
|
+
reject(
|
|
39
|
+
new DependencyError(
|
|
40
|
+
`PowerShell not found. Ensure PowerShell is installed and available in PATH.\nTried: ${psExe}`
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const exitCode = error ? error.code || 1 : 0;
|
|
47
|
+
const result = {
|
|
48
|
+
exitCode: typeof exitCode === "number" ? exitCode : 1,
|
|
49
|
+
stdout: stdout || "",
|
|
50
|
+
stderr: stderr || "",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
if (!options.silent && result.stdout) {
|
|
54
|
+
process.stdout.write(result.stdout);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
resolve(result);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = {
|
|
63
|
+
findPowerShell,
|
|
64
|
+
runScript,
|
|
65
|
+
};
|