sdtk-ops-kit 0.2.4 → 0.2.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.
package/src/lib/update.js CHANGED
@@ -1,344 +1,344 @@
1
- "use strict";
2
-
3
- const path = require("path");
4
- const { spawn } = require("child_process");
5
- const { parseFlags, validateChoice } = require("./args");
6
- const { CliError, DependencyError, ValidationError } = require("./errors");
7
- const { VALID_SCOPES, defaultScope, isProjectScopeSupported } = require("./scope");
8
- const { assertProjectRefreshTargetAllowed } = require("./project-target-guard");
9
-
10
- const PACKAGE_NAME = "sdtk-ops-kit";
11
- const CLI_NAME = "sdtk-ops";
12
- const CLI_BIN = path.resolve(__dirname, "..", "..", "bin", "sdtk-ops.js");
13
- const NPM_BIN = process.platform === "win32" ? "npm.cmd" : "npm";
14
- const NPM_DISPLAY = "npm";
15
- const NPM_VIEW_ARGS = ["view", PACKAGE_NAME, "version"];
16
- const VALID_RUNTIMES = ["codex", "claude"];
17
- const VERSION_PATTERN = /^\d+\.\d+\.\d+$/;
18
- const FLAG_DEFS = {
19
- version: { type: "string" },
20
- runtime: { type: "string" },
21
- scope: { type: "string" },
22
- "project-path": { type: "string" },
23
- "check-only": { type: "boolean" },
24
- "skip-project-files": { type: "boolean" },
25
- "skip-runtime-assets": { type: "boolean" },
26
- verbose: { type: "boolean" },
27
- };
28
- const pkg = require("../../package.json");
29
-
30
- let commandExecutor = defaultCommandExecutor;
31
-
32
- function defaultCommandExecutor(command, args, options = {}) {
33
- return new Promise((resolve, reject) => {
34
- const child = spawn(command, args, {
35
- cwd: options.cwd || process.cwd(),
36
- env: options.env || process.env,
37
- shell: options.shell || false,
38
- windowsHide: true,
39
- });
40
- let stdout = "";
41
- let stderr = "";
42
-
43
- child.stdout.on("data", (chunk) => {
44
- const text = chunk.toString();
45
- stdout += text;
46
- if (options.verbose) {
47
- process.stdout.write(text);
48
- }
49
- });
50
- child.stderr.on("data", (chunk) => {
51
- const text = chunk.toString();
52
- stderr += text;
53
- if (options.verbose) {
54
- process.stderr.write(text);
55
- }
56
- });
57
- child.on("error", (error) => {
58
- if (error && error.code === "ENOENT") {
59
- reject(new DependencyError(`Required command not found in PATH: ${command}`));
60
- return;
61
- }
62
- reject(error);
63
- });
64
- child.on("close", (exitCode) => {
65
- resolve({
66
- exitCode: typeof exitCode === "number" ? exitCode : 1,
67
- stdout,
68
- stderr,
69
- });
70
- });
71
- });
72
- }
73
-
74
- function setCommandExecutorForTests(executor) {
75
- commandExecutor = executor || defaultCommandExecutor;
76
- }
77
-
78
- function resetCommandExecutorForTests() {
79
- commandExecutor = defaultCommandExecutor;
80
- }
81
-
82
- function quote(value) {
83
- const text = String(value);
84
- return /[\s"]/u.test(text) ? JSON.stringify(text) : text;
85
- }
86
-
87
- function formatCommand(command, args) {
88
- return [command, ...args].map((value) => quote(value)).join(" ");
89
- }
90
-
91
- function validateVersion(targetVersion) {
92
- if (targetVersion !== "latest" && !VERSION_PATTERN.test(targetVersion)) {
93
- throw new ValidationError(
94
- `Invalid value for --version: "${targetVersion}". Must be "latest" or x.y.z.`
95
- );
96
- }
97
- }
98
-
99
- function extractResolvedVersion(stdout) {
100
- const lines = String(stdout || "")
101
- .split(/\r?\n/u)
102
- .map((line) => line.trim())
103
- .filter(Boolean);
104
- const candidate = (lines[lines.length - 1] || "").replace(/^['"]|['"]$/gu, "");
105
- if (!VERSION_PATTERN.test(candidate)) {
106
- throw new CliError(
107
- `npm registry lookup returned an invalid version for ${PACKAGE_NAME}: "${candidate || "<empty>"}"`
108
- );
109
- }
110
- return candidate;
111
- }
112
-
113
- async function resolveTargetVersion(options) {
114
- if (options.requestedVersion !== "latest") {
115
- return options.requestedVersion;
116
- }
117
-
118
- let result;
119
- try {
120
- result = await commandExecutor(NPM_BIN, NPM_VIEW_ARGS, {
121
- verbose: options.verbose,
122
- shell: process.platform === "win32",
123
- });
124
- } catch (error) {
125
- throw new CliError(
126
- `npm registry lookup failed for ${PACKAGE_NAME} while resolving --version latest.\n${error.message}`,
127
- error.exitCode || 4
128
- );
129
- }
130
-
131
- if (result.exitCode !== 0) {
132
- const detail = (result.stderr || result.stdout || "").trim();
133
- throw new CliError(
134
- `npm registry lookup failed for ${PACKAGE_NAME} while resolving --version latest (exit code ${result.exitCode}).${detail ? `\n${detail}` : ""}`
135
- );
136
- }
137
-
138
- try {
139
- return extractResolvedVersion(result.stdout);
140
- } catch (error) {
141
- throw new CliError(
142
- `npm registry lookup failed for ${PACKAGE_NAME} while resolving --version latest.\n${error.message}`,
143
- error.exitCode || 4
144
- );
145
- }
146
- }
147
-
148
- function buildPlan(options) {
149
- const npmArgs = ["install", "-g", `${PACKAGE_NAME}@${options.targetVersion}`];
150
- const plan = {
151
- installedVersion: pkg.version,
152
- requestedVersion: options.requestedVersion,
153
- targetVersion: options.targetVersion,
154
- updateNeeded: pkg.version !== options.targetVersion,
155
- npmArgs,
156
- npmCommand: formatCommand(NPM_DISPLAY, npmArgs),
157
- runtime: options.runtime,
158
- scope: options.scope,
159
- projectPath: options.projectPath,
160
- checkOnly: options.checkOnly,
161
- projectRefreshArgs: null,
162
- runtimeRefreshArgs: null,
163
- projectRefreshCommand: "skipped (no --runtime provided)",
164
- runtimeRefreshCommand: "skipped (no --runtime provided)",
165
- };
166
-
167
- if (!options.runtime) {
168
- return plan;
169
- }
170
-
171
- if (options.skipProjectFiles) {
172
- plan.projectRefreshCommand = "skipped (--skip-project-files)";
173
- } else {
174
- const initArgs = [
175
- "init",
176
- "--runtime",
177
- options.runtime,
178
- "--runtime-scope",
179
- options.scope,
180
- "--project-path",
181
- options.projectPath,
182
- "--force",
183
- "--skip-runtime-assets",
184
- ];
185
- if (options.verbose) {
186
- initArgs.push("--verbose");
187
- }
188
- plan.projectRefreshArgs = initArgs;
189
- plan.projectRefreshCommand = formatCommand(CLI_NAME, initArgs);
190
- }
191
-
192
- if (options.skipRuntimeAssets) {
193
- plan.runtimeRefreshCommand = "skipped (--skip-runtime-assets)";
194
- } else {
195
- const runtimeArgs = ["runtime", "install", "--runtime", options.runtime, "--scope", options.scope, "--force"];
196
- if (options.scope === "project") {
197
- runtimeArgs.push("--project-path", options.projectPath);
198
- }
199
- if (options.verbose) {
200
- runtimeArgs.push("--verbose");
201
- }
202
- plan.runtimeRefreshArgs = runtimeArgs;
203
- plan.runtimeRefreshCommand = formatCommand(CLI_NAME, runtimeArgs);
204
- }
205
-
206
- return plan;
207
- }
208
-
209
- function parseUpdateOptions(args) {
210
- const { flags, positional } = parseFlags(args, FLAG_DEFS);
211
-
212
- if (positional.length > 0) {
213
- throw new ValidationError(`Unexpected arguments: ${positional.join(" ")}`);
214
- }
215
-
216
- const requestedVersion = flags.version || "latest";
217
- validateVersion(requestedVersion);
218
-
219
- const runtime = flags.runtime;
220
- if (runtime) {
221
- validateChoice(runtime, VALID_RUNTIMES, "runtime");
222
- }
223
- if (flags.scope && !runtime) {
224
- throw new ValidationError("--scope requires --runtime.");
225
- }
226
-
227
- const scope = runtime ? (flags.scope || defaultScope(runtime)) : undefined;
228
- if (scope) {
229
- validateChoice(scope, VALID_SCOPES, "scope");
230
- if (scope === "project" && !isProjectScopeSupported(runtime)) {
231
- throw new ValidationError(
232
- `${runtime} does not support project-local runtime assets. Use --scope user instead.`
233
- );
234
- }
235
- }
236
-
237
- const projectPath = path.resolve(flags["project-path"] || process.cwd());
238
-
239
- if (runtime && !flags["skip-project-files"]) {
240
- assertProjectRefreshTargetAllowed("sdtk-ops", "update", projectPath);
241
- }
242
-
243
- return {
244
- requestedVersion,
245
- runtime,
246
- scope,
247
- projectPath,
248
- checkOnly: flags["check-only"],
249
- skipProjectFiles: flags["skip-project-files"],
250
- skipRuntimeAssets: flags["skip-runtime-assets"],
251
- verbose: flags.verbose,
252
- };
253
- }
254
-
255
- function printPlan(plan) {
256
- console.log("SDTK-OPS update plan");
257
- console.log(` Installed package version: ${plan.installedVersion}`);
258
- console.log(` Requested package version: ${plan.requestedVersion}`);
259
- console.log(` Target package version: ${plan.targetVersion}`);
260
- console.log(
261
- ` Package update needed: ${plan.updateNeeded ? "yes" : `no (already installed: ${plan.installedVersion})`}`
262
- );
263
- console.log(` Package refresh command: ${plan.npmCommand}`);
264
- if (plan.runtime) {
265
- console.log(` Runtime: ${plan.runtime}`);
266
- console.log(` Scope: ${plan.scope}`);
267
- console.log(` Project path: ${plan.projectPath}`);
268
- }
269
- console.log(` Project file refresh: ${plan.projectRefreshCommand}`);
270
- console.log(` Runtime asset refresh: ${plan.runtimeRefreshCommand}`);
271
- console.log(
272
- ` Mode: ${plan.checkOnly ? "check-only (no changes applied)" : "apply"}`
273
- );
274
- }
275
-
276
- async function runCommand(label, command, args, options) {
277
- const result = await commandExecutor(command, args, options);
278
- if (result.exitCode !== 0) {
279
- const detail = (result.stderr || result.stdout || "").trim();
280
- throw new CliError(
281
- `${label} failed (exit code ${result.exitCode}).${detail ? `\n${detail}` : ""}`
282
- );
283
- }
284
- return result;
285
- }
286
-
287
- async function applyPlan(plan, options) {
288
- console.log("");
289
- console.log("Applying SDTK-OPS update...");
290
- if (plan.updateNeeded) {
291
- console.log(` npm refresh: ${plan.npmCommand}`);
292
- await runCommand("npm package refresh", NPM_BIN, plan.npmArgs, {
293
- verbose: options.verbose,
294
- shell: process.platform === "win32",
295
- });
296
- } else {
297
- console.log(` npm refresh: skipped (installed package already matches ${plan.targetVersion})`);
298
- }
299
-
300
- if (plan.projectRefreshArgs) {
301
- console.log(` project refresh: ${plan.projectRefreshCommand}`);
302
- await runCommand("project file refresh", process.execPath, [CLI_BIN, ...plan.projectRefreshArgs], {
303
- verbose: options.verbose,
304
- });
305
- } else {
306
- console.log(` project refresh: ${plan.projectRefreshCommand}`);
307
- }
308
-
309
- if (plan.runtimeRefreshArgs) {
310
- console.log(` runtime refresh: ${plan.runtimeRefreshCommand}`);
311
- await runCommand("runtime asset refresh", process.execPath, [CLI_BIN, ...plan.runtimeRefreshArgs], {
312
- verbose: options.verbose,
313
- });
314
- } else {
315
- console.log(` runtime refresh: ${plan.runtimeRefreshCommand}`);
316
- }
317
-
318
- console.log("");
319
- console.log("SDTK-OPS update completed successfully.");
320
- }
321
-
322
- async function executeUpdate(args) {
323
- const options = parseUpdateOptions(args);
324
- const targetVersion = await resolveTargetVersion(options);
325
- const plan = buildPlan({ ...options, targetVersion });
326
- printPlan(plan);
327
-
328
- if (options.checkOnly) {
329
- return 0;
330
- }
331
-
332
- await applyPlan(plan, options);
333
- return 0;
334
- }
335
-
336
- module.exports = {
337
- buildPlan,
338
- executeUpdate,
339
- formatCommand,
340
- parseUpdateOptions,
341
- resetCommandExecutorForTests,
342
- resolveTargetVersion,
343
- setCommandExecutorForTests,
344
- };
1
+ "use strict";
2
+
3
+ const path = require("path");
4
+ const { spawn } = require("child_process");
5
+ const { parseFlags, validateChoice } = require("./args");
6
+ const { CliError, DependencyError, ValidationError } = require("./errors");
7
+ const { VALID_SCOPES, defaultScope, isProjectScopeSupported } = require("./scope");
8
+ const { assertProjectRefreshTargetAllowed } = require("./project-target-guard");
9
+
10
+ const PACKAGE_NAME = "sdtk-ops-kit";
11
+ const CLI_NAME = "sdtk-ops";
12
+ const CLI_BIN = path.resolve(__dirname, "..", "..", "bin", "sdtk-ops.js");
13
+ const NPM_BIN = process.platform === "win32" ? "npm.cmd" : "npm";
14
+ const NPM_DISPLAY = "npm";
15
+ const NPM_VIEW_ARGS = ["view", PACKAGE_NAME, "version"];
16
+ const VALID_RUNTIMES = ["codex", "claude"];
17
+ const VERSION_PATTERN = /^\d+\.\d+\.\d+$/;
18
+ const FLAG_DEFS = {
19
+ version: { type: "string" },
20
+ runtime: { type: "string" },
21
+ scope: { type: "string" },
22
+ "project-path": { type: "string" },
23
+ "check-only": { type: "boolean" },
24
+ "skip-project-files": { type: "boolean" },
25
+ "skip-runtime-assets": { type: "boolean" },
26
+ verbose: { type: "boolean" },
27
+ };
28
+ const pkg = require("../../package.json");
29
+
30
+ let commandExecutor = defaultCommandExecutor;
31
+
32
+ function defaultCommandExecutor(command, args, options = {}) {
33
+ return new Promise((resolve, reject) => {
34
+ const child = spawn(command, args, {
35
+ cwd: options.cwd || process.cwd(),
36
+ env: options.env || process.env,
37
+ shell: options.shell || false,
38
+ windowsHide: true,
39
+ });
40
+ let stdout = "";
41
+ let stderr = "";
42
+
43
+ child.stdout.on("data", (chunk) => {
44
+ const text = chunk.toString();
45
+ stdout += text;
46
+ if (options.verbose) {
47
+ process.stdout.write(text);
48
+ }
49
+ });
50
+ child.stderr.on("data", (chunk) => {
51
+ const text = chunk.toString();
52
+ stderr += text;
53
+ if (options.verbose) {
54
+ process.stderr.write(text);
55
+ }
56
+ });
57
+ child.on("error", (error) => {
58
+ if (error && error.code === "ENOENT") {
59
+ reject(new DependencyError(`Required command not found in PATH: ${command}`));
60
+ return;
61
+ }
62
+ reject(error);
63
+ });
64
+ child.on("close", (exitCode) => {
65
+ resolve({
66
+ exitCode: typeof exitCode === "number" ? exitCode : 1,
67
+ stdout,
68
+ stderr,
69
+ });
70
+ });
71
+ });
72
+ }
73
+
74
+ function setCommandExecutorForTests(executor) {
75
+ commandExecutor = executor || defaultCommandExecutor;
76
+ }
77
+
78
+ function resetCommandExecutorForTests() {
79
+ commandExecutor = defaultCommandExecutor;
80
+ }
81
+
82
+ function quote(value) {
83
+ const text = String(value);
84
+ return /[\s"]/u.test(text) ? JSON.stringify(text) : text;
85
+ }
86
+
87
+ function formatCommand(command, args) {
88
+ return [command, ...args].map((value) => quote(value)).join(" ");
89
+ }
90
+
91
+ function validateVersion(targetVersion) {
92
+ if (targetVersion !== "latest" && !VERSION_PATTERN.test(targetVersion)) {
93
+ throw new ValidationError(
94
+ `Invalid value for --version: "${targetVersion}". Must be "latest" or x.y.z.`
95
+ );
96
+ }
97
+ }
98
+
99
+ function extractResolvedVersion(stdout) {
100
+ const lines = String(stdout || "")
101
+ .split(/\r?\n/u)
102
+ .map((line) => line.trim())
103
+ .filter(Boolean);
104
+ const candidate = (lines[lines.length - 1] || "").replace(/^['"]|['"]$/gu, "");
105
+ if (!VERSION_PATTERN.test(candidate)) {
106
+ throw new CliError(
107
+ `npm registry lookup returned an invalid version for ${PACKAGE_NAME}: "${candidate || "<empty>"}"`
108
+ );
109
+ }
110
+ return candidate;
111
+ }
112
+
113
+ async function resolveTargetVersion(options) {
114
+ if (options.requestedVersion !== "latest") {
115
+ return options.requestedVersion;
116
+ }
117
+
118
+ let result;
119
+ try {
120
+ result = await commandExecutor(NPM_BIN, NPM_VIEW_ARGS, {
121
+ verbose: options.verbose,
122
+ shell: process.platform === "win32",
123
+ });
124
+ } catch (error) {
125
+ throw new CliError(
126
+ `npm registry lookup failed for ${PACKAGE_NAME} while resolving --version latest.\n${error.message}`,
127
+ error.exitCode || 4
128
+ );
129
+ }
130
+
131
+ if (result.exitCode !== 0) {
132
+ const detail = (result.stderr || result.stdout || "").trim();
133
+ throw new CliError(
134
+ `npm registry lookup failed for ${PACKAGE_NAME} while resolving --version latest (exit code ${result.exitCode}).${detail ? `\n${detail}` : ""}`
135
+ );
136
+ }
137
+
138
+ try {
139
+ return extractResolvedVersion(result.stdout);
140
+ } catch (error) {
141
+ throw new CliError(
142
+ `npm registry lookup failed for ${PACKAGE_NAME} while resolving --version latest.\n${error.message}`,
143
+ error.exitCode || 4
144
+ );
145
+ }
146
+ }
147
+
148
+ function buildPlan(options) {
149
+ const npmArgs = ["install", "-g", `${PACKAGE_NAME}@${options.targetVersion}`];
150
+ const plan = {
151
+ installedVersion: pkg.version,
152
+ requestedVersion: options.requestedVersion,
153
+ targetVersion: options.targetVersion,
154
+ updateNeeded: pkg.version !== options.targetVersion,
155
+ npmArgs,
156
+ npmCommand: formatCommand(NPM_DISPLAY, npmArgs),
157
+ runtime: options.runtime,
158
+ scope: options.scope,
159
+ projectPath: options.projectPath,
160
+ checkOnly: options.checkOnly,
161
+ projectRefreshArgs: null,
162
+ runtimeRefreshArgs: null,
163
+ projectRefreshCommand: "skipped (no --runtime provided)",
164
+ runtimeRefreshCommand: "skipped (no --runtime provided)",
165
+ };
166
+
167
+ if (!options.runtime) {
168
+ return plan;
169
+ }
170
+
171
+ if (options.skipProjectFiles) {
172
+ plan.projectRefreshCommand = "skipped (--skip-project-files)";
173
+ } else {
174
+ const initArgs = [
175
+ "init",
176
+ "--runtime",
177
+ options.runtime,
178
+ "--runtime-scope",
179
+ options.scope,
180
+ "--project-path",
181
+ options.projectPath,
182
+ "--force",
183
+ "--skip-runtime-assets",
184
+ ];
185
+ if (options.verbose) {
186
+ initArgs.push("--verbose");
187
+ }
188
+ plan.projectRefreshArgs = initArgs;
189
+ plan.projectRefreshCommand = formatCommand(CLI_NAME, initArgs);
190
+ }
191
+
192
+ if (options.skipRuntimeAssets) {
193
+ plan.runtimeRefreshCommand = "skipped (--skip-runtime-assets)";
194
+ } else {
195
+ const runtimeArgs = ["runtime", "install", "--runtime", options.runtime, "--scope", options.scope, "--force"];
196
+ if (options.scope === "project") {
197
+ runtimeArgs.push("--project-path", options.projectPath);
198
+ }
199
+ if (options.verbose) {
200
+ runtimeArgs.push("--verbose");
201
+ }
202
+ plan.runtimeRefreshArgs = runtimeArgs;
203
+ plan.runtimeRefreshCommand = formatCommand(CLI_NAME, runtimeArgs);
204
+ }
205
+
206
+ return plan;
207
+ }
208
+
209
+ function parseUpdateOptions(args) {
210
+ const { flags, positional } = parseFlags(args, FLAG_DEFS);
211
+
212
+ if (positional.length > 0) {
213
+ throw new ValidationError(`Unexpected arguments: ${positional.join(" ")}`);
214
+ }
215
+
216
+ const requestedVersion = flags.version || "latest";
217
+ validateVersion(requestedVersion);
218
+
219
+ const runtime = flags.runtime;
220
+ if (runtime) {
221
+ validateChoice(runtime, VALID_RUNTIMES, "runtime");
222
+ }
223
+ if (flags.scope && !runtime) {
224
+ throw new ValidationError("--scope requires --runtime.");
225
+ }
226
+
227
+ const scope = runtime ? (flags.scope || defaultScope(runtime)) : undefined;
228
+ if (scope) {
229
+ validateChoice(scope, VALID_SCOPES, "scope");
230
+ if (scope === "project" && !isProjectScopeSupported(runtime)) {
231
+ throw new ValidationError(
232
+ `${runtime} does not support project-local runtime assets. Use --scope user instead.`
233
+ );
234
+ }
235
+ }
236
+
237
+ const projectPath = path.resolve(flags["project-path"] || process.cwd());
238
+
239
+ if (runtime && !flags["skip-project-files"]) {
240
+ assertProjectRefreshTargetAllowed("sdtk-ops", "update", projectPath);
241
+ }
242
+
243
+ return {
244
+ requestedVersion,
245
+ runtime,
246
+ scope,
247
+ projectPath,
248
+ checkOnly: flags["check-only"],
249
+ skipProjectFiles: flags["skip-project-files"],
250
+ skipRuntimeAssets: flags["skip-runtime-assets"],
251
+ verbose: flags.verbose,
252
+ };
253
+ }
254
+
255
+ function printPlan(plan) {
256
+ console.log("SDTK-OPS update plan");
257
+ console.log(` Installed package version: ${plan.installedVersion}`);
258
+ console.log(` Requested package version: ${plan.requestedVersion}`);
259
+ console.log(` Target package version: ${plan.targetVersion}`);
260
+ console.log(
261
+ ` Package update needed: ${plan.updateNeeded ? "yes" : `no (already installed: ${plan.installedVersion})`}`
262
+ );
263
+ console.log(` Package refresh command: ${plan.npmCommand}`);
264
+ if (plan.runtime) {
265
+ console.log(` Runtime: ${plan.runtime}`);
266
+ console.log(` Scope: ${plan.scope}`);
267
+ console.log(` Project path: ${plan.projectPath}`);
268
+ }
269
+ console.log(` Project file refresh: ${plan.projectRefreshCommand}`);
270
+ console.log(` Runtime asset refresh: ${plan.runtimeRefreshCommand}`);
271
+ console.log(
272
+ ` Mode: ${plan.checkOnly ? "check-only (no changes applied)" : "apply"}`
273
+ );
274
+ }
275
+
276
+ async function runCommand(label, command, args, options) {
277
+ const result = await commandExecutor(command, args, options);
278
+ if (result.exitCode !== 0) {
279
+ const detail = (result.stderr || result.stdout || "").trim();
280
+ throw new CliError(
281
+ `${label} failed (exit code ${result.exitCode}).${detail ? `\n${detail}` : ""}`
282
+ );
283
+ }
284
+ return result;
285
+ }
286
+
287
+ async function applyPlan(plan, options) {
288
+ console.log("");
289
+ console.log("Applying SDTK-OPS update...");
290
+ if (plan.updateNeeded) {
291
+ console.log(` npm refresh: ${plan.npmCommand}`);
292
+ await runCommand("npm package refresh", NPM_BIN, plan.npmArgs, {
293
+ verbose: options.verbose,
294
+ shell: process.platform === "win32",
295
+ });
296
+ } else {
297
+ console.log(` npm refresh: skipped (installed package already matches ${plan.targetVersion})`);
298
+ }
299
+
300
+ if (plan.projectRefreshArgs) {
301
+ console.log(` project refresh: ${plan.projectRefreshCommand}`);
302
+ await runCommand("project file refresh", process.execPath, [CLI_BIN, ...plan.projectRefreshArgs], {
303
+ verbose: options.verbose,
304
+ });
305
+ } else {
306
+ console.log(` project refresh: ${plan.projectRefreshCommand}`);
307
+ }
308
+
309
+ if (plan.runtimeRefreshArgs) {
310
+ console.log(` runtime refresh: ${plan.runtimeRefreshCommand}`);
311
+ await runCommand("runtime asset refresh", process.execPath, [CLI_BIN, ...plan.runtimeRefreshArgs], {
312
+ verbose: options.verbose,
313
+ });
314
+ } else {
315
+ console.log(` runtime refresh: ${plan.runtimeRefreshCommand}`);
316
+ }
317
+
318
+ console.log("");
319
+ console.log("SDTK-OPS update completed successfully.");
320
+ }
321
+
322
+ async function executeUpdate(args) {
323
+ const options = parseUpdateOptions(args);
324
+ const targetVersion = await resolveTargetVersion(options);
325
+ const plan = buildPlan({ ...options, targetVersion });
326
+ printPlan(plan);
327
+
328
+ if (options.checkOnly) {
329
+ return 0;
330
+ }
331
+
332
+ await applyPlan(plan, options);
333
+ return 0;
334
+ }
335
+
336
+ module.exports = {
337
+ buildPlan,
338
+ executeUpdate,
339
+ formatCommand,
340
+ parseUpdateOptions,
341
+ resetCommandExecutorForTests,
342
+ resolveTargetVersion,
343
+ setCommandExecutorForTests,
344
+ };