@spekn/cli 1.0.0 → 1.0.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.
Files changed (154) hide show
  1. package/README.md +58 -0
  2. package/dist/main.js +40540 -32176
  3. package/dist/prompts/governance-analysis.prompt.md +109 -0
  4. package/dist/resources/prompts/repo-analysis.prompt.md +28 -136
  5. package/dist/resources/prompts/repo-sync-analysis.prompt.md +31 -68
  6. package/dist/tui/chunk-4WEASLXY.mjs +3444 -0
  7. package/dist/tui/chunk-755CADEG.mjs +3401 -0
  8. package/dist/tui/chunk-BUJQVTY5.mjs +3409 -0
  9. package/dist/tui/chunk-BZKKMGFB.mjs +1959 -0
  10. package/dist/tui/chunk-DJYOBCNM.mjs +3159 -0
  11. package/dist/tui/chunk-GTFTFDY4.mjs +3417 -0
  12. package/dist/tui/chunk-IMEBD2KA.mjs +3444 -0
  13. package/dist/tui/chunk-IX6DR5SW.mjs +3433 -0
  14. package/dist/tui/chunk-JKFOY4IF.mjs +2003 -0
  15. package/dist/tui/chunk-OXXZ3O5L.mjs +3378 -0
  16. package/dist/tui/chunk-SHJNIAAJ.mjs +1697 -0
  17. package/dist/tui/chunk-V4SNDRUS.mjs +1666 -0
  18. package/dist/tui/chunk-VXVHNZST.mjs +1666 -0
  19. package/dist/tui/chunk-WCTSFKTA.mjs +3459 -0
  20. package/dist/tui/chunk-X2XP5ACW.mjs +3443 -0
  21. package/dist/tui/chunk-YUYJ7VBG.mjs +2029 -0
  22. package/dist/tui/chunk-ZM3EI5IA.mjs +3384 -0
  23. package/dist/tui/chunk-ZYOX64HP.mjs +1653 -0
  24. package/dist/tui/index.mjs +6999 -6938
  25. package/dist/tui/prompts/spec-creation-system.prompt.md +47 -0
  26. package/dist/tui/prompts/spec-refinement-system.prompt.md +72 -0
  27. package/dist/tui/use-session-store-63YUGUFA.mjs +8 -0
  28. package/dist/tui/use-session-store-ACO2SMJC.mjs +8 -0
  29. package/dist/tui/use-session-store-BVFDAWOB.mjs +8 -0
  30. package/dist/tui/use-session-store-DJIZ3FQZ.mjs +9 -0
  31. package/dist/tui/use-session-store-EAIQA4UG.mjs +9 -0
  32. package/dist/tui/use-session-store-EFBAXC3G.mjs +8 -0
  33. package/dist/tui/use-session-store-FJOR4KTG.mjs +8 -0
  34. package/dist/tui/use-session-store-IJE5KVOC.mjs +8 -0
  35. package/dist/tui/use-session-store-KGAFXCKI.mjs +8 -0
  36. package/dist/tui/use-session-store-KS4DPNDY.mjs +8 -0
  37. package/dist/tui/use-session-store-MMHJENNL.mjs +8 -0
  38. package/dist/tui/use-session-store-OZ6HC4I2.mjs +9 -0
  39. package/dist/tui/use-session-store-PTMWISNJ.mjs +8 -0
  40. package/dist/tui/use-session-store-VCDECQMW.mjs +8 -0
  41. package/dist/tui/use-session-store-VOK5ML5J.mjs +9 -0
  42. package/package.json +33 -13
  43. package/dist/__tests__/export-cli.test.d.ts +0 -1
  44. package/dist/__tests__/export-cli.test.js +0 -70
  45. package/dist/__tests__/tui-args-policy.test.d.ts +0 -1
  46. package/dist/__tests__/tui-args-policy.test.js +0 -50
  47. package/dist/acp-S2MHZOAD.mjs +0 -23
  48. package/dist/acp-UCCI44JY.mjs +0 -25
  49. package/dist/auth/credentials-store.d.ts +0 -2
  50. package/dist/auth/credentials-store.js +0 -5
  51. package/dist/auth/device-flow.d.ts +0 -36
  52. package/dist/auth/device-flow.js +0 -189
  53. package/dist/auth/jwt.d.ts +0 -1
  54. package/dist/auth/jwt.js +0 -6
  55. package/dist/auth/session.d.ts +0 -67
  56. package/dist/auth/session.js +0 -86
  57. package/dist/auth-login.d.ts +0 -34
  58. package/dist/auth-login.js +0 -202
  59. package/dist/auth-logout.d.ts +0 -25
  60. package/dist/auth-logout.js +0 -115
  61. package/dist/auth-status.d.ts +0 -24
  62. package/dist/auth-status.js +0 -109
  63. package/dist/backlog-generate.d.ts +0 -11
  64. package/dist/backlog-generate.js +0 -308
  65. package/dist/backlog-health.d.ts +0 -11
  66. package/dist/backlog-health.js +0 -287
  67. package/dist/bridge-login.d.ts +0 -40
  68. package/dist/bridge-login.js +0 -277
  69. package/dist/chunk-3PAYRI4G.mjs +0 -2428
  70. package/dist/chunk-M4CS3A25.mjs +0 -2426
  71. package/dist/commands/auth/login.d.ts +0 -30
  72. package/dist/commands/auth/login.js +0 -164
  73. package/dist/commands/auth/logout.d.ts +0 -25
  74. package/dist/commands/auth/logout.js +0 -115
  75. package/dist/commands/auth/status.d.ts +0 -24
  76. package/dist/commands/auth/status.js +0 -109
  77. package/dist/commands/backlog/generate.d.ts +0 -11
  78. package/dist/commands/backlog/generate.js +0 -308
  79. package/dist/commands/backlog/health.d.ts +0 -11
  80. package/dist/commands/backlog/health.js +0 -287
  81. package/dist/commands/bridge/login.d.ts +0 -36
  82. package/dist/commands/bridge/login.js +0 -258
  83. package/dist/commands/export.d.ts +0 -35
  84. package/dist/commands/export.js +0 -485
  85. package/dist/commands/marketplace-export.d.ts +0 -21
  86. package/dist/commands/marketplace-export.js +0 -214
  87. package/dist/commands/project-clean.d.ts +0 -1
  88. package/dist/commands/project-clean.js +0 -126
  89. package/dist/commands/repo/common.d.ts +0 -105
  90. package/dist/commands/repo/common.js +0 -775
  91. package/dist/commands/repo/detach.d.ts +0 -2
  92. package/dist/commands/repo/detach.js +0 -120
  93. package/dist/commands/repo/register.d.ts +0 -21
  94. package/dist/commands/repo/register.js +0 -175
  95. package/dist/commands/repo/sync.d.ts +0 -22
  96. package/dist/commands/repo/sync.js +0 -873
  97. package/dist/commands/skills-import-local.d.ts +0 -16
  98. package/dist/commands/skills-import-local.js +0 -352
  99. package/dist/commands/spec/drift-check.d.ts +0 -3
  100. package/dist/commands/spec/drift-check.js +0 -186
  101. package/dist/commands/spec/frontmatter.d.ts +0 -11
  102. package/dist/commands/spec/frontmatter.js +0 -219
  103. package/dist/commands/spec/lint.d.ts +0 -11
  104. package/dist/commands/spec/lint.js +0 -499
  105. package/dist/commands/spec/parse.d.ts +0 -11
  106. package/dist/commands/spec/parse.js +0 -162
  107. package/dist/export.d.ts +0 -35
  108. package/dist/export.js +0 -485
  109. package/dist/main.d.ts +0 -1
  110. package/dist/marketplace-export.d.ts +0 -21
  111. package/dist/marketplace-export.js +0 -214
  112. package/dist/project-clean.d.ts +0 -1
  113. package/dist/project-clean.js +0 -126
  114. package/dist/project-context.d.ts +0 -99
  115. package/dist/project-context.js +0 -376
  116. package/dist/repo-common.d.ts +0 -101
  117. package/dist/repo-common.js +0 -671
  118. package/dist/repo-detach.d.ts +0 -2
  119. package/dist/repo-detach.js +0 -102
  120. package/dist/repo-ingest.d.ts +0 -29
  121. package/dist/repo-ingest.js +0 -305
  122. package/dist/repo-register.d.ts +0 -21
  123. package/dist/repo-register.js +0 -175
  124. package/dist/repo-sync.d.ts +0 -16
  125. package/dist/repo-sync.js +0 -152
  126. package/dist/resources/prompt-loader.d.ts +0 -1
  127. package/dist/resources/prompt-loader.js +0 -62
  128. package/dist/skills-import-local.d.ts +0 -16
  129. package/dist/skills-import-local.js +0 -352
  130. package/dist/spec-drift-check.d.ts +0 -3
  131. package/dist/spec-drift-check.js +0 -186
  132. package/dist/spec-frontmatter.d.ts +0 -11
  133. package/dist/spec-frontmatter.js +0 -219
  134. package/dist/spec-lint.d.ts +0 -11
  135. package/dist/spec-lint.js +0 -499
  136. package/dist/spec-parse.d.ts +0 -11
  137. package/dist/spec-parse.js +0 -162
  138. package/dist/stubs/dotenv.d.ts +0 -5
  139. package/dist/stubs/dotenv.js +0 -6
  140. package/dist/stubs/typeorm.d.ts +0 -22
  141. package/dist/stubs/typeorm.js +0 -28
  142. package/dist/tui-bundle.d.ts +0 -1
  143. package/dist/tui-bundle.js +0 -5
  144. package/dist/tui-entry.mjs +0 -1407
  145. package/dist/utils/cli-runtime.d.ts +0 -5
  146. package/dist/utils/cli-runtime.js +0 -22
  147. package/dist/utils/help-error.d.ts +0 -7
  148. package/dist/utils/help-error.js +0 -14
  149. package/dist/utils/interaction.d.ts +0 -19
  150. package/dist/utils/interaction.js +0 -93
  151. package/dist/utils/structured-log.d.ts +0 -7
  152. package/dist/utils/structured-log.js +0 -112
  153. package/dist/utils/trpc-url.d.ts +0 -4
  154. package/dist/utils/trpc-url.js +0 -15
@@ -1,485 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.runExportCli = runExportCli;
38
- exports.main = main;
39
- exports.parseArgs = parseArgs;
40
- exports.normalizeTrpcUrl = normalizeTrpcUrl;
41
- const client_1 = require("@trpc/client");
42
- const fs = __importStar(require("node:fs"));
43
- const path = __importStar(require("node:path"));
44
- const credentials_store_1 = require("../auth/credentials-store");
45
- const project_context_1 = require("../project-context");
46
- const structured_log_1 = require("../utils/structured-log");
47
- const defaultDeps = {
48
- createClient: (apiUrl, organizationId, authToken) => (0, client_1.createTRPCProxyClient)({
49
- links: [
50
- (0, client_1.httpBatchLink)({
51
- url: normalizeTrpcUrl(apiUrl),
52
- headers: {
53
- 'x-organization-id': organizationId,
54
- authorization: authToken ? `Bearer ${authToken}` : '',
55
- },
56
- }),
57
- ],
58
- }),
59
- writeFile: (filePath, content) => {
60
- const dir = path.dirname(filePath);
61
- fs.mkdirSync(dir, { recursive: true });
62
- fs.writeFileSync(filePath, content, 'utf-8');
63
- },
64
- stdout: (content) => process.stdout.write(content),
65
- stderr: (content) => process.stderr.write(content),
66
- credentialsStore: new credentials_store_1.CredentialsStore(),
67
- };
68
- function normalizeTrpcUrl(apiUrl) {
69
- if (apiUrl.endsWith('/trpc')) {
70
- return apiUrl;
71
- }
72
- if (apiUrl.endsWith('/')) {
73
- return `${apiUrl}trpc`;
74
- }
75
- return `${apiUrl}/trpc`;
76
- }
77
- function printHelp(stderr) {
78
- stderr(`
79
- export - Generate and deliver agent context exports
80
-
81
- USAGE:
82
- spekn export discover --project <uuid> [options]
83
- spekn export preview --project <uuid> --format <agents-md|claude-md|cursorrules|gemini-md> [options]
84
- spekn export --project <uuid> --format <agents-md|claude-md|cursorrules|gemini-md> [options]
85
- spekn export status --project <uuid> --format <agents-md|claude-md|cursorrules|gemini-md> [options]
86
-
87
- OPTIONS:
88
- --project <uuid> Project ID (optional if .spekn/context is present)
89
- --format <format> Export format: agents-md | claude-md | cursorrules | gemini-md (required)
90
- --output <path> Write output to file (generate-only backward-compat mode)
91
- --anchors <a,b,c> Comma-separated anchor list
92
- --mode <mode> Export mode: global | scoped (default: global)
93
- --scope <path> Scope folder path when mode=scoped
94
- --delivery <mode> Delivery: download | copy | commit | pr (default: download)
95
- --branch <name> Target branch for commit/pr delivery
96
- --base-branch <name> Base branch for branch creation
97
- --commit-message <m> Commit message override
98
- --pr-title <title> PR title (delivery=pr)
99
- --pr-body <body> PR body (delivery=pr)
100
- --json Output machine-readable JSON
101
- --api-url <url> API base URL (default: SPEKN_API_URL or https://app.spekn.com)
102
- --help Show help
103
- `);
104
- }
105
- function parseArgs(args) {
106
- const command = args[0] === 'status' ? 'status' : args[0] === 'discover' ? 'discover' : args[0] === 'preview' ? 'preview' : 'generate';
107
- const parseArgs = command === 'generate' ? args : args.slice(1);
108
- let projectId = '';
109
- let format = '';
110
- let output;
111
- let anchors;
112
- let mode = 'global';
113
- let scope;
114
- let delivery = 'download';
115
- let json = false;
116
- let branch;
117
- let baseBranch;
118
- let commitMessage;
119
- let prTitle;
120
- let prBody;
121
- let apiUrl = process.env.SPEKN_API_URL || 'https://app.spekn.com';
122
- for (let index = 0; index < parseArgs.length; index++) {
123
- const arg = parseArgs[index];
124
- if (arg === '--help' || arg === '-h') {
125
- throw new Error('__HELP__');
126
- }
127
- if (arg === '--json') {
128
- json = true;
129
- continue;
130
- }
131
- if (arg === '--project' && parseArgs[index + 1]) {
132
- projectId = parseArgs[++index];
133
- continue;
134
- }
135
- if (arg.startsWith('--project=')) {
136
- projectId = arg.slice('--project='.length);
137
- continue;
138
- }
139
- if (arg === '--format' && parseArgs[index + 1]) {
140
- format = parseArgs[++index];
141
- continue;
142
- }
143
- if (arg.startsWith('--format=')) {
144
- format = arg.slice('--format='.length);
145
- continue;
146
- }
147
- if (arg === '--output' && parseArgs[index + 1]) {
148
- output = parseArgs[++index];
149
- continue;
150
- }
151
- if (arg.startsWith('--output=')) {
152
- output = arg.slice('--output='.length);
153
- continue;
154
- }
155
- if (arg === '--anchors' && parseArgs[index + 1]) {
156
- anchors = parseArgs[++index]
157
- .split(',')
158
- .map((entry) => entry.trim())
159
- .filter(Boolean);
160
- continue;
161
- }
162
- if (arg.startsWith('--anchors=')) {
163
- anchors = arg
164
- .slice('--anchors='.length)
165
- .split(',')
166
- .map((entry) => entry.trim())
167
- .filter(Boolean);
168
- continue;
169
- }
170
- if (arg === '--mode' && parseArgs[index + 1]) {
171
- mode = parseArgs[++index];
172
- continue;
173
- }
174
- if (arg.startsWith('--mode=')) {
175
- mode = arg.slice('--mode='.length);
176
- continue;
177
- }
178
- if (arg === '--scope' && parseArgs[index + 1]) {
179
- scope = parseArgs[++index];
180
- continue;
181
- }
182
- if (arg.startsWith('--scope=')) {
183
- scope = arg.slice('--scope='.length);
184
- continue;
185
- }
186
- if (arg === '--delivery' && parseArgs[index + 1]) {
187
- delivery = parseArgs[++index];
188
- continue;
189
- }
190
- if (arg.startsWith('--delivery=')) {
191
- delivery = arg.slice('--delivery='.length);
192
- continue;
193
- }
194
- if (arg === '--branch' && parseArgs[index + 1]) {
195
- branch = parseArgs[++index];
196
- continue;
197
- }
198
- if (arg.startsWith('--branch=')) {
199
- branch = arg.slice('--branch='.length);
200
- continue;
201
- }
202
- if (arg === '--base-branch' && parseArgs[index + 1]) {
203
- baseBranch = parseArgs[++index];
204
- continue;
205
- }
206
- if (arg.startsWith('--base-branch=')) {
207
- baseBranch = arg.slice('--base-branch='.length);
208
- continue;
209
- }
210
- if (arg === '--commit-message' && parseArgs[index + 1]) {
211
- commitMessage = parseArgs[++index];
212
- continue;
213
- }
214
- if (arg.startsWith('--commit-message=')) {
215
- commitMessage = arg.slice('--commit-message='.length);
216
- continue;
217
- }
218
- if (arg === '--pr-title' && parseArgs[index + 1]) {
219
- prTitle = parseArgs[++index];
220
- continue;
221
- }
222
- if (arg.startsWith('--pr-title=')) {
223
- prTitle = arg.slice('--pr-title='.length);
224
- continue;
225
- }
226
- if (arg === '--pr-body' && parseArgs[index + 1]) {
227
- prBody = parseArgs[++index];
228
- continue;
229
- }
230
- if (arg.startsWith('--pr-body=')) {
231
- prBody = arg.slice('--pr-body='.length);
232
- continue;
233
- }
234
- if (arg === '--api-url' && parseArgs[index + 1]) {
235
- apiUrl = parseArgs[++index];
236
- continue;
237
- }
238
- if (arg.startsWith('--api-url=')) {
239
- apiUrl = arg.slice('--api-url='.length);
240
- continue;
241
- }
242
- }
243
- if (command !== 'discover' && !['agents-md', 'claude-md', 'cursorrules', 'gemini-md'].includes(format)) {
244
- throw new Error('Missing or invalid --format. Allowed values: agents-md, claude-md, cursorrules, gemini-md');
245
- }
246
- if (!['global', 'scoped'].includes(mode)) {
247
- throw new Error('Invalid --mode. Allowed values: global, scoped');
248
- }
249
- if (mode === 'scoped' && !scope) {
250
- throw new Error('Missing --scope when --mode=scoped');
251
- }
252
- if (!['download', 'copy', 'commit', 'pr'].includes(delivery)) {
253
- throw new Error('Invalid --delivery. Allowed values: download, copy, commit, pr');
254
- }
255
- return {
256
- command,
257
- projectId,
258
- format: format,
259
- output,
260
- anchors,
261
- mode,
262
- scope,
263
- delivery,
264
- json,
265
- branch,
266
- baseBranch,
267
- commitMessage,
268
- prTitle,
269
- prBody,
270
- apiUrl,
271
- };
272
- }
273
- async function runExportCli(args, deps = defaultDeps) {
274
- try {
275
- const options = parseArgs(args);
276
- const emit = (payload) => {
277
- deps.stdout(`${JSON.stringify(payload, null, 2)}\n`);
278
- };
279
- (0, structured_log_1.appendCliStructuredLog)({
280
- source: 'cli.export',
281
- level: 'info',
282
- message: `Starting export ${options.command}`,
283
- details: {
284
- format: options.format,
285
- mode: options.mode,
286
- delivery: options.delivery,
287
- output: options.output,
288
- apiUrl: options.apiUrl,
289
- },
290
- });
291
- const storedToken = await deps.credentialsStore.getValidToken();
292
- const authToken = storedToken ?? process.env.SPEKN_AUTH_TOKEN;
293
- const storedCreds = deps.credentialsStore.load();
294
- const context = (0, project_context_1.resolveProjectContext)({
295
- explicitProjectId: options.projectId,
296
- repoPath: process.cwd(),
297
- credentialsOrganizationId: storedCreds?.organizationId,
298
- envOrganizationId: process.env.SPEKN_ORGANIZATION_ID,
299
- });
300
- const client = deps.createClient(options.apiUrl, context.organizationId, authToken ?? undefined);
301
- if (options.command === 'discover') {
302
- const result = await client.export.discover.query({
303
- projectId: context.projectId,
304
- });
305
- if (options.json) {
306
- emit(result);
307
- }
308
- else {
309
- deps.stdout(`Plan: ${result.plan}\n`);
310
- deps.stdout(`Modes: ${result.modes.join(', ')}\n`);
311
- deps.stdout('Formats:\n');
312
- for (const format of result.formats) {
313
- deps.stdout(`- ${format.id} (${format.filename})\n`);
314
- }
315
- deps.stdout('Delivery:\n');
316
- for (const delivery of result.delivery) {
317
- deps.stdout(`- ${delivery.mode}: ${delivery.available ? 'available' : `unavailable (${delivery.reason})`}\n`);
318
- }
319
- }
320
- return 0;
321
- }
322
- if (options.command === 'preview') {
323
- const result = await client.export.preview.query({
324
- projectId: context.projectId,
325
- formatId: options.format,
326
- anchorFilter: options.anchors,
327
- mode: options.mode,
328
- scopePath: options.scope,
329
- });
330
- if (options.json) {
331
- emit(result);
332
- }
333
- else {
334
- deps.stdout(result.content);
335
- deps.stdout('\n');
336
- }
337
- return 0;
338
- }
339
- if (options.command === 'status') {
340
- const result = await client.export.delivery.status.query({
341
- projectId: context.projectId,
342
- formatId: options.format,
343
- mode: options.mode,
344
- scopePath: options.scope,
345
- anchorFilter: options.anchors,
346
- });
347
- if (options.json) {
348
- emit(result);
349
- }
350
- else {
351
- deps.stdout(`Status: ${result.overall}\n`);
352
- for (const target of result.targets) {
353
- deps.stdout(`- ${target.path} [${target.kind}] -> ${target.status}\n`);
354
- }
355
- }
356
- return 0;
357
- }
358
- // Backward-compatible single output mode.
359
- if (options.output && options.delivery === 'download') {
360
- const result = await client.export.generate.mutate({
361
- projectId: context.projectId,
362
- formatId: options.format,
363
- anchorFilter: options.anchors,
364
- mode: options.mode,
365
- scopePath: options.scope,
366
- });
367
- const resolvedPath = path.resolve(process.cwd(), options.output);
368
- deps.writeFile(resolvedPath, result.content);
369
- if (options.json) {
370
- emit({
371
- delivery: 'download',
372
- targets: [{ path: resolvedPath, kind: 'entrypoint' }],
373
- anchorCount: result.anchorCount,
374
- specVersion: result.specVersion,
375
- warnings: result.warnings ?? [],
376
- });
377
- }
378
- else {
379
- deps.stdout(`Exported ${result.anchorCount} anchors to ${resolvedPath}\n`);
380
- }
381
- return 0;
382
- }
383
- if (options.delivery === 'commit') {
384
- const result = await client.export.delivery.commit.mutate({
385
- projectId: context.projectId,
386
- formatId: options.format,
387
- mode: options.mode,
388
- scopePath: options.scope,
389
- branch: options.branch,
390
- baseBranch: options.baseBranch,
391
- commitMessage: options.commitMessage,
392
- anchorFilter: options.anchors,
393
- });
394
- if (options.json) {
395
- emit(result);
396
- }
397
- else {
398
- deps.stdout(`Committed to ${result.branch}: ${result.commitSha}\n`);
399
- for (const fileUrl of result.fileUrls || [])
400
- deps.stdout(`- ${fileUrl}\n`);
401
- }
402
- return 0;
403
- }
404
- if (options.delivery === 'pr') {
405
- const result = await client.export.delivery.createPr.mutate({
406
- projectId: context.projectId,
407
- formatId: options.format,
408
- mode: options.mode,
409
- scopePath: options.scope,
410
- branch: options.branch,
411
- baseBranch: options.baseBranch,
412
- commitMessage: options.commitMessage,
413
- prTitle: options.prTitle,
414
- prBody: options.prBody,
415
- anchorFilter: options.anchors,
416
- });
417
- if (options.json) {
418
- emit(result);
419
- }
420
- else {
421
- deps.stdout(`PR #${result.prNumber}: ${result.prUrl}\n`);
422
- deps.stdout(`Commit: ${result.commitSha} on ${result.branch}\n`);
423
- }
424
- return 0;
425
- }
426
- const plan = await client.export.delivery.previewTarget.query({
427
- projectId: context.projectId,
428
- formatId: options.format,
429
- mode: options.mode,
430
- scopePath: options.scope,
431
- anchorFilter: options.anchors,
432
- });
433
- if (options.delivery === 'copy') {
434
- if (options.json) {
435
- emit(plan);
436
- }
437
- else {
438
- for (const target of plan.targets) {
439
- deps.stdout(`\n### ${target.path}\n\n`);
440
- deps.stdout(target.content);
441
- deps.stdout('\n');
442
- }
443
- }
444
- return 0;
445
- }
446
- const writtenTargets = [];
447
- for (const target of plan.targets) {
448
- const resolvedPath = path.resolve(process.cwd(), target.path);
449
- deps.writeFile(resolvedPath, target.content);
450
- writtenTargets.push({ path: resolvedPath, kind: target.kind });
451
- if (!options.json) {
452
- deps.stdout(`Wrote ${target.kind} -> ${resolvedPath}\n`);
453
- }
454
- }
455
- if (options.json) {
456
- emit({ delivery: 'download', targets: writtenTargets, warnings: plan.warnings ?? [] });
457
- }
458
- else if (plan.warnings?.length) {
459
- for (const warning of plan.warnings)
460
- deps.stdout(`Warning: ${warning}\n`);
461
- }
462
- return 0;
463
- }
464
- catch (error) {
465
- if (error instanceof Error && error.message === '__HELP__') {
466
- printHelp(deps.stderr);
467
- return 0;
468
- }
469
- const message = error instanceof Error ? error.message : String(error);
470
- deps.stderr(`Error: ${message}\n`);
471
- (0, structured_log_1.appendCliStructuredLog)({
472
- source: 'cli.export',
473
- level: 'error',
474
- message,
475
- });
476
- return 1;
477
- }
478
- }
479
- async function main() {
480
- const exitCode = await runExportCli(process.argv.slice(2));
481
- process.exit(exitCode);
482
- }
483
- if (require.main === module) {
484
- void main();
485
- }
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env node
2
- import { CredentialsStore } from '../auth/credentials-store';
3
- interface CLIOptions {
4
- projectId?: string;
5
- output: string;
6
- apiUrl: string;
7
- marketplaceName: string;
8
- ownerName: string;
9
- }
10
- interface Deps {
11
- createClient: (apiUrl: string, organizationId: string, authToken?: string) => any;
12
- writeFile: (filePath: string, content: string) => void;
13
- mkdirSync: (dirPath: string) => void;
14
- stdout: (content: string) => void;
15
- stderr: (content: string) => void;
16
- credentialsStore: CredentialsStore;
17
- }
18
- declare function parseArgs(args: string[]): CLIOptions;
19
- export declare function runMarketplaceExportCli(args: string[], deps?: Deps): Promise<number>;
20
- declare function main(): Promise<void>;
21
- export { main, parseArgs };