@powerhousedao/ph-cli 6.0.2-staging.2 → 6.0.2-staging.3

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 (129) hide show
  1. package/dist/assign-env-vars-B-oPplBd.mjs +15 -0
  2. package/dist/assign-env-vars-B-oPplBd.mjs.map +1 -0
  3. package/dist/auth-mwX4ugZt.mjs +15 -0
  4. package/dist/auth-mwX4ugZt.mjs.map +1 -0
  5. package/dist/build-Fq1pNRsl.mjs +33 -0
  6. package/dist/build-Fq1pNRsl.mjs.map +1 -0
  7. package/dist/cli-CYgcGGKv.mjs +140 -0
  8. package/dist/cli-CYgcGGKv.mjs.map +1 -0
  9. package/dist/cli.d.mts +1 -0
  10. package/dist/cli.mjs +860 -0
  11. package/dist/cli.mjs.map +1 -0
  12. package/dist/connect-build-DUiJQGfx.mjs +35 -0
  13. package/dist/connect-build-DUiJQGfx.mjs.map +1 -0
  14. package/dist/connect-preview-hSphy1QP.mjs +27 -0
  15. package/dist/connect-preview-hSphy1QP.mjs.map +1 -0
  16. package/dist/connect-studio-CFH0kGW1.mjs +28 -0
  17. package/dist/connect-studio-CFH0kGW1.mjs.map +1 -0
  18. package/dist/connect-studio-CV-T5IfA.mjs +3 -0
  19. package/dist/generate-all-yTycRkd3.mjs +10 -0
  20. package/dist/generate-all-yTycRkd3.mjs.map +1 -0
  21. package/dist/generate-app-hSK1SlOn.mjs +31 -0
  22. package/dist/generate-app-hSK1SlOn.mjs.map +1 -0
  23. package/dist/generate-document-model-ZowVACXL.mjs +17 -0
  24. package/dist/generate-document-model-ZowVACXL.mjs.map +1 -0
  25. package/dist/generate-editor-C53z-03Q.mjs +31 -0
  26. package/dist/generate-editor-C53z-03Q.mjs.map +1 -0
  27. package/dist/generate-processor-BS4F98d6.mjs +22 -0
  28. package/dist/generate-processor-BS4F98d6.mjs.map +1 -0
  29. package/dist/generate-subgraph-D1cYT9GQ.mjs +20 -0
  30. package/dist/generate-subgraph-D1cYT9GQ.mjs.map +1 -0
  31. package/dist/init-BgEVXxOR.mjs +124 -0
  32. package/dist/init-BgEVXxOR.mjs.map +1 -0
  33. package/dist/inspect-DRvimHBb.mjs +45 -0
  34. package/dist/inspect-DRvimHBb.mjs.map +1 -0
  35. package/dist/logout-BpJEO2Ij.mjs +230 -0
  36. package/dist/logout-BpJEO2Ij.mjs.map +1 -0
  37. package/dist/migrate-CSaC4bDh.mjs +11 -0
  38. package/dist/migrate-CSaC4bDh.mjs.map +1 -0
  39. package/dist/scripts/generate-commands-docs.ts +14 -0
  40. package/dist/switchboard-Bl2llp5U.mjs +72 -0
  41. package/dist/switchboard-Bl2llp5U.mjs.map +1 -0
  42. package/dist/switchboard-DUlj8v2F.mjs +2 -0
  43. package/dist/switchboard-migrate-BiQJfIrc.mjs +50 -0
  44. package/dist/switchboard-migrate-BiQJfIrc.mjs.map +1 -0
  45. package/dist/utils-C6_gv4nB.mjs +162 -0
  46. package/dist/utils-C6_gv4nB.mjs.map +1 -0
  47. package/dist/vetra-D2zbrNY1.mjs +420 -0
  48. package/dist/vetra-D2zbrNY1.mjs.map +1 -0
  49. package/package.json +35 -26
  50. package/dist/bundle.d.ts +0 -2
  51. package/dist/bundle.d.ts.map +0 -1
  52. package/dist/scripts/generate-commands-docs.d.ts +0 -2
  53. package/dist/scripts/generate-commands-docs.d.ts.map +0 -1
  54. package/dist/src/cli.d.ts +0 -3
  55. package/dist/src/cli.d.ts.map +0 -1
  56. package/dist/src/cli.js +0 -395510
  57. package/dist/src/commands/access-token.d.ts +0 -14
  58. package/dist/src/commands/access-token.d.ts.map +0 -1
  59. package/dist/src/commands/connect.d.ts +0 -249
  60. package/dist/src/commands/connect.d.ts.map +0 -1
  61. package/dist/src/commands/generate.d.ts +0 -62
  62. package/dist/src/commands/generate.d.ts.map +0 -1
  63. package/dist/src/commands/index.d.ts +0 -13
  64. package/dist/src/commands/index.d.ts.map +0 -1
  65. package/dist/src/commands/inspect.d.ts +0 -12
  66. package/dist/src/commands/inspect.d.ts.map +0 -1
  67. package/dist/src/commands/install.d.ts +0 -22
  68. package/dist/src/commands/install.d.ts.map +0 -1
  69. package/dist/src/commands/list.d.ts +0 -10
  70. package/dist/src/commands/list.d.ts.map +0 -1
  71. package/dist/src/commands/login.d.ts +0 -24
  72. package/dist/src/commands/login.d.ts.map +0 -1
  73. package/dist/src/commands/logout.d.ts +0 -6
  74. package/dist/src/commands/logout.d.ts.map +0 -1
  75. package/dist/src/commands/migrate.d.ts +0 -12
  76. package/dist/src/commands/migrate.d.ts.map +0 -1
  77. package/dist/src/commands/ph-cli-commands.d.ts +0 -419
  78. package/dist/src/commands/ph-cli-commands.d.ts.map +0 -1
  79. package/dist/src/commands/ph-cli-help.d.ts +0 -400
  80. package/dist/src/commands/ph-cli-help.d.ts.map +0 -1
  81. package/dist/src/commands/ph-cli.d.ts +0 -506
  82. package/dist/src/commands/ph-cli.d.ts.map +0 -1
  83. package/dist/src/commands/service.d.ts +0 -12
  84. package/dist/src/commands/service.d.ts.map +0 -1
  85. package/dist/src/commands/switchboard.d.ts +0 -46
  86. package/dist/src/commands/switchboard.d.ts.map +0 -1
  87. package/dist/src/commands/uninstall.d.ts +0 -22
  88. package/dist/src/commands/uninstall.d.ts.map +0 -1
  89. package/dist/src/commands/vetra.d.ts +0 -64
  90. package/dist/src/commands/vetra.d.ts.map +0 -1
  91. package/dist/src/get-version.d.ts +0 -2
  92. package/dist/src/get-version.d.ts.map +0 -1
  93. package/dist/src/help.d.ts +0 -65
  94. package/dist/src/help.d.ts.map +0 -1
  95. package/dist/src/services/auth.d.ts +0 -21
  96. package/dist/src/services/auth.d.ts.map +0 -1
  97. package/dist/src/services/connect-build.d.ts +0 -3
  98. package/dist/src/services/connect-build.d.ts.map +0 -1
  99. package/dist/src/services/connect-preview.d.ts +0 -3
  100. package/dist/src/services/connect-preview.d.ts.map +0 -1
  101. package/dist/src/services/connect-studio.d.ts +0 -4
  102. package/dist/src/services/connect-studio.d.ts.map +0 -1
  103. package/dist/src/services/generate.d.ts +0 -3
  104. package/dist/src/services/generate.d.ts.map +0 -1
  105. package/dist/src/services/inspect.d.ts +0 -3
  106. package/dist/src/services/inspect.d.ts.map +0 -1
  107. package/dist/src/services/migrate.d.ts +0 -3
  108. package/dist/src/services/migrate.d.ts.map +0 -1
  109. package/dist/src/services/switchboard-migrate.d.ts +0 -7
  110. package/dist/src/services/switchboard-migrate.d.ts.map +0 -1
  111. package/dist/src/services/switchboard.d.ts +0 -23
  112. package/dist/src/services/switchboard.d.ts.map +0 -1
  113. package/dist/src/services/vetra.d.ts +0 -3
  114. package/dist/src/services/vetra.d.ts.map +0 -1
  115. package/dist/src/types.d.ts +0 -28
  116. package/dist/src/types.d.ts.map +0 -1
  117. package/dist/src/utils/assign-env-vars.d.ts +0 -3
  118. package/dist/src/utils/assign-env-vars.d.ts.map +0 -1
  119. package/dist/src/utils/configure-vetra-github-url.d.ts +0 -12
  120. package/dist/src/utils/configure-vetra-github-url.d.ts.map +0 -1
  121. package/dist/src/utils/constants.d.ts +0 -2
  122. package/dist/src/utils/constants.d.ts.map +0 -1
  123. package/dist/src/utils/resolve-connect-dirs.d.ts +0 -5
  124. package/dist/src/utils/resolve-connect-dirs.d.ts.map +0 -1
  125. package/dist/src/utils.d.ts +0 -112
  126. package/dist/src/utils.d.ts.map +0 -1
  127. package/dist/tsconfig.tsbuildinfo +0 -1
  128. package/dist/vitest.config.d.ts +0 -3
  129. package/dist/vitest.config.d.ts.map +0 -1
package/dist/cli.mjs ADDED
@@ -0,0 +1,860 @@
1
+ #!/usr/bin/env node
2
+ import { a as getVersion, i as accessToken, n as login, r as list, t as logout } from "./logout-BpJEO2Ij.mjs";
3
+ import { t as runBuild } from "./build-Fq1pNRsl.mjs";
4
+ import { a as updateStylesFile, i as updateConfigFile, r as removeStylesImports } from "./utils-C6_gv4nB.mjs";
5
+ import { assertNodeVersion, buildArgs, captureCliError, codeArgs, connectBuildArgs, connectPreviewArgs, connectStudioArgs, debugArgs, getPowerhouseProjectInfo, getPowerhouseProjectUninstallCommand, initArgs, initCliTelemetry, inspectArgs, installArgs, makeDependenciesWithVersions, migrateArgs, phCliHelpCommands, publishArgs, switchboardArgs, uninstallArgs, unpublishArgs, vetraArgs } from "@powerhousedao/shared/clis";
6
+ import { array, boolean, command, flag, multioption, oneOf, option, optional, run, string, subcommands } from "cmd-ts";
7
+ import { AGENTS, resolveCommand } from "package-manager-detector";
8
+ import { Directory, File } from "cmd-ts/dist/cjs/batteries/fs.js";
9
+ import { generateDBSchema } from "@powerhousedao/codegen";
10
+ import path from "path";
11
+ import { PROCESSOR_APPS } from "@powerhousedao/shared/processors";
12
+ import { checkNpmAuth, npmPublish, npmUnpublish, resolveRegistryUrl } from "@powerhousedao/shared/registry";
13
+ import { execSync } from "child_process";
14
+ import { readPackageSync } from "read-pkg";
15
+ import { prerelease } from "semver";
16
+ import { createInterface } from "node:readline/promises";
17
+ //#region src/utils/constants.ts
18
+ const PH_CLI_DESCRIPTION = "The Powerhouse CLI (ph-cli) is a command-line interface tool that provides essential commands for managing Powerhouse projects. The tool and it's commands are fundamental for creating, building, and running Document Models as a builder in studio mode.";
19
+ const phCliHelp = subcommands({
20
+ name: "ph-cli",
21
+ description: PH_CLI_DESCRIPTION,
22
+ version: getVersion(),
23
+ cmds: phCliHelpCommands
24
+ });
25
+ //#endregion
26
+ //#region src/commands/build.ts
27
+ const build$1 = command({
28
+ name: "build",
29
+ args: buildArgs,
30
+ handler: async (args) => {
31
+ if (args.debug) console.log(args);
32
+ try {
33
+ await runBuild(args);
34
+ } catch (error) {
35
+ console.error(error);
36
+ process.exit(1);
37
+ }
38
+ }
39
+ });
40
+ //#endregion
41
+ //#region src/commands/code.ts
42
+ const code = command({
43
+ name: "code",
44
+ description: `
45
+ Open the Powerhouse coding agent — a REPL backed by Mastra that has every
46
+ installed Powerhouse tool available as an agent tool.
47
+
48
+ Examples:
49
+ ph code Start the interactive REPL.
50
+ ph code "list my installed packs" One-shot agent prompt.
51
+ `,
52
+ args: codeArgs,
53
+ handler: async (args) => {
54
+ const { buildPhCodeCli } = await import("./cli-CYgcGGKv.mjs");
55
+ const cli = buildPhCodeCli();
56
+ const argv = [
57
+ "node",
58
+ "ph-code",
59
+ ...args.rest.length === 0 ? ["-i"] : args.rest
60
+ ];
61
+ await cli.run(argv);
62
+ }
63
+ });
64
+ const connect = subcommands({
65
+ name: "connect",
66
+ description: `Powerhouse Connect commands. Use with \`studio\`, \`build\` or \`preview\`. Defaults to \`studio\` if not specified.`,
67
+ cmds: {
68
+ studio: command({
69
+ name: "studio",
70
+ description: `The studio command starts the Connect Studio, a development environment for building
71
+ and testing Powerhouse applications. It provides a visual interface for working with
72
+ your project.
73
+
74
+ This command:
75
+ 1. Starts a local Connect Studio server
76
+ 2. Provides a web interface for development
77
+ 3. Allows you to interact with your project components
78
+ 4. Supports various configuration options for customization
79
+ `,
80
+ args: connectStudioArgs,
81
+ handler: async (args) => {
82
+ if (args.debug) console.log(args);
83
+ const { runConnectStudio } = await import("./connect-studio-CV-T5IfA.mjs");
84
+ await runConnectStudio(args);
85
+ }
86
+ }),
87
+ build: command({
88
+ name: "build",
89
+ description: `The Connect build command creates a production build with the project's local and
90
+ external packages included
91
+ `,
92
+ args: connectBuildArgs,
93
+ handler: async (args) => {
94
+ if (args.debug) console.log(args);
95
+ const { runConnectBuild } = await import("./connect-build-DUiJQGfx.mjs");
96
+ await runConnectBuild(args);
97
+ process.exit(0);
98
+ }
99
+ }),
100
+ preview: command({
101
+ name: "preview",
102
+ description: `The Connect preview command previews a built Connect project.
103
+ NOTE: You must run \`ph connect build\` first
104
+ `,
105
+ args: connectPreviewArgs,
106
+ handler: async (args) => {
107
+ if (args.debug) console.log(args);
108
+ const { runConnectPreview } = await import("./connect-preview-hSphy1QP.mjs");
109
+ await runConnectPreview(args);
110
+ }
111
+ })
112
+ }
113
+ });
114
+ //#endregion
115
+ //#region src/commands/generate-all.ts
116
+ const generateAllCmd = command({
117
+ name: "all",
118
+ description: "Re-generate all modules in the current project",
119
+ args: {},
120
+ handler: async () => {
121
+ const { startGenerateAll } = await import("./generate-all-yTycRkd3.mjs");
122
+ await startGenerateAll(process.cwd());
123
+ process.exit(0);
124
+ }
125
+ });
126
+ //#endregion
127
+ //#region src/commands/generate-app.ts
128
+ const generateAppCmd = command({
129
+ name: "app",
130
+ description: "Generate a drive app",
131
+ args: {
132
+ name: option({
133
+ type: optional(string),
134
+ long: "name",
135
+ short: "n",
136
+ description: "The name of the drive app to generate"
137
+ }),
138
+ allowedDocumentTypes: multioption({
139
+ type: optional(array(string)),
140
+ long: "document-types",
141
+ short: "t",
142
+ description: "The document types allowed by the new app"
143
+ }),
144
+ dir: option({
145
+ type: optional(Directory),
146
+ long: "dir",
147
+ short: "d",
148
+ description: "Name of the directory of an existing app to re-generate"
149
+ }),
150
+ disableDragAndDrop: flag({
151
+ type: boolean,
152
+ long: "disable-drag-and-drop",
153
+ description: "Do not allow drag and drop in this drive app.",
154
+ defaultValue: () => false,
155
+ defaultValueIsSerializable: true
156
+ }),
157
+ all: flag({
158
+ long: "all",
159
+ short: "a",
160
+ description: "Re-generate all existing apps in the current project"
161
+ }),
162
+ ...debugArgs
163
+ },
164
+ handler: async (args) => {
165
+ const { startGenerateApp } = await import("./generate-app-hSK1SlOn.mjs");
166
+ await startGenerateApp(args, process.cwd());
167
+ process.exit(0);
168
+ }
169
+ });
170
+ //#endregion
171
+ //#region src/commands/generate-document-model.ts
172
+ const generateDocumentModelCmd = command({
173
+ name: "document-model",
174
+ aliases: ["doc"],
175
+ description: "Generate a document model",
176
+ args: {
177
+ file: option({
178
+ type: optional(File),
179
+ long: "file",
180
+ short: "f",
181
+ description: "Path to the file to generate the document model from"
182
+ }),
183
+ dir: option({
184
+ type: optional(Directory),
185
+ long: "dir",
186
+ short: "d",
187
+ description: "Name of the directory of an existing document model to re-generate"
188
+ }),
189
+ all: flag({
190
+ long: "all",
191
+ short: "a",
192
+ description: "Re-generate all existing document models in the current project"
193
+ }),
194
+ ...debugArgs
195
+ },
196
+ handler: async (args) => {
197
+ const { startGenerateDocumentModel } = await import("./generate-document-model-ZowVACXL.mjs");
198
+ await startGenerateDocumentModel(args, process.cwd());
199
+ process.exit(0);
200
+ }
201
+ });
202
+ //#endregion
203
+ //#region src/commands/generate-editor.ts
204
+ const generateEditorCmd = command({
205
+ name: "editor",
206
+ description: "Generate a document editor",
207
+ args: {
208
+ name: option({
209
+ type: optional(string),
210
+ long: "name",
211
+ short: "n",
212
+ description: "The name of the document editor to generate"
213
+ }),
214
+ documentType: option({
215
+ type: optional(string),
216
+ long: "document-type",
217
+ short: "t",
218
+ description: "The document type for the new editor"
219
+ }),
220
+ dir: option({
221
+ type: optional(Directory),
222
+ long: "dir",
223
+ short: "d",
224
+ description: "Name of the directory of an existing editor to re-generate"
225
+ }),
226
+ all: flag({
227
+ long: "all",
228
+ short: "a",
229
+ description: "Re-generate all existing editors in the current project"
230
+ }),
231
+ ...debugArgs
232
+ },
233
+ handler: async (args) => {
234
+ const { startGenerateEditor } = await import("./generate-editor-C53z-03Q.mjs");
235
+ await startGenerateEditor(args, process.cwd());
236
+ process.exit(0);
237
+ }
238
+ });
239
+ //#endregion
240
+ //#region src/commands/generate-migration-file.ts
241
+ const generateMigrationFileCmd = command({
242
+ name: "migration-file",
243
+ description: "Generate a migration file",
244
+ args: {
245
+ migrationFile: option({
246
+ type: string,
247
+ long: "path",
248
+ short: "p",
249
+ description: "Path to the migration file"
250
+ }),
251
+ schemaFile: option({
252
+ type: optional(string),
253
+ long: "schema-file",
254
+ description: "Path to the output file. Defaults to './schema.ts'"
255
+ }),
256
+ ...debugArgs
257
+ },
258
+ handler: async ({ migrationFile, schemaFile }) => {
259
+ await generateDBSchema({
260
+ migrationFile: path.join(process.cwd(), migrationFile),
261
+ schemaFile: schemaFile ? path.join(process.cwd(), schemaFile) : void 0
262
+ });
263
+ process.exit(0);
264
+ }
265
+ });
266
+ const generateProcessorCmd = command({
267
+ name: "processor",
268
+ description: "Generate a processor",
269
+ args: {
270
+ name: option({
271
+ type: optional(string),
272
+ long: "name",
273
+ short: "n",
274
+ description: "The name of the processor to generate"
275
+ }),
276
+ type: option({
277
+ type: oneOf(["analytics", "relationalDb"]),
278
+ long: "type",
279
+ description: "The type of processor to generate",
280
+ defaultValue: () => "analytics",
281
+ defaultValueIsSerializable: true
282
+ }),
283
+ documentTypes: multioption({
284
+ type: array(string),
285
+ long: "document-types",
286
+ short: "t",
287
+ description: "The document types the processor will run on",
288
+ defaultValue: () => [],
289
+ defaultValueIsSerializable: true
290
+ }),
291
+ apps: multioption({
292
+ long: "apps",
293
+ type: { from(processorApps) {
294
+ if (processorApps.length === 0) throw new Error(`No arguments provided for processor apps. Must be "connect" and/or "switchboard"`);
295
+ if (processorApps.length > 2) throw new Error(`Too many arguments provided for processor apps. Must be "connect" and/or "switchboard"`);
296
+ const allowed = new Set(PROCESSOR_APPS);
297
+ if (!processorApps.every((p) => allowed.has(p))) throw new Error(`Processor apps can only be "connect" and/or "switchboard".`);
298
+ return Promise.resolve(processorApps);
299
+ } },
300
+ description: "Whether the processor will run in switchboard (nodejs), connect (browser), or both",
301
+ defaultValue: () => ["switchboard", "connect"],
302
+ defaultValueIsSerializable: true
303
+ }),
304
+ dir: option({
305
+ type: optional(Directory),
306
+ long: "dir",
307
+ short: "d",
308
+ description: "Name of the directory of an existing processor to re-generate"
309
+ }),
310
+ all: flag({
311
+ long: "all",
312
+ short: "a",
313
+ description: "Re-generate all existing processors in the current project"
314
+ }),
315
+ ...debugArgs
316
+ },
317
+ handler: async (args) => {
318
+ const { startGenerateProcessor } = await import("./generate-processor-BS4F98d6.mjs");
319
+ await startGenerateProcessor(args, process.cwd());
320
+ process.exit(0);
321
+ }
322
+ });
323
+ //#endregion
324
+ //#region src/commands/generate-subgraph.ts
325
+ const generateSubgraphCmd = command({
326
+ name: "subgraph",
327
+ description: "Generate a subgraph",
328
+ args: {
329
+ name: option({
330
+ type: optional(string),
331
+ long: "name",
332
+ short: "n",
333
+ description: "The name of the subgraph to generate"
334
+ }),
335
+ dir: option({
336
+ type: optional(Directory),
337
+ long: "dir",
338
+ short: "d",
339
+ description: "Name of the directory of an existing subgraph to re-generate"
340
+ }),
341
+ all: flag({
342
+ long: "all",
343
+ short: "a",
344
+ description: "Re-generate all existing subgraphs in the current project"
345
+ }),
346
+ ...debugArgs
347
+ },
348
+ handler: async (args) => {
349
+ const { startGenerateSubgraph } = await import("./generate-subgraph-D1cYT9GQ.mjs");
350
+ await startGenerateSubgraph(args, process.cwd());
351
+ process.exit(0);
352
+ }
353
+ });
354
+ //#endregion
355
+ //#region src/commands/generate.ts
356
+ const generate = subcommands({
357
+ name: "generate",
358
+ description: `The generate command creates code for Powerhouse modules. It helps you create new code from scratch, or to re-generate existing code in your project.`,
359
+ cmds: {
360
+ all: generateAllCmd,
361
+ "document-model": generateDocumentModelCmd,
362
+ editor: generateEditorCmd,
363
+ app: generateAppCmd,
364
+ processor: generateProcessorCmd,
365
+ subgraph: generateSubgraphCmd,
366
+ "migration-file": generateMigrationFileCmd
367
+ }
368
+ });
369
+ //#endregion
370
+ //#region src/commands/init.ts
371
+ const init = command({
372
+ name: "init",
373
+ description: "Initialize a new project",
374
+ args: initArgs,
375
+ handler: async (args) => {
376
+ if (args.debug) console.log({ args });
377
+ const { startInit } = await import("./init-BgEVXxOR.mjs");
378
+ await startInit(args);
379
+ process.exit(0);
380
+ }
381
+ });
382
+ //#endregion
383
+ //#region src/commands/inspect.ts
384
+ const inspect = command({
385
+ name: "inspect",
386
+ description: `
387
+ The inspect command examines and provides detailed information about a Powerhouse package.
388
+ It helps you understand the structure, dependencies, and configuration of packages in
389
+ your project.
390
+
391
+ This command:
392
+ 1. Analyzes the specified package
393
+ 2. Retrieves detailed information about its structure and configuration
394
+ 3. Displays package metadata, dependencies, and other relevant information
395
+ 4. Helps troubleshoot package-related issues`,
396
+ aliases: ["is"],
397
+ args: inspectArgs,
398
+ handler: async (args) => {
399
+ if (args.debug) console.log(args);
400
+ const { startInspect } = await import("./inspect-DRvimHBb.mjs");
401
+ startInspect(args);
402
+ process.exit(0);
403
+ }
404
+ });
405
+ //#endregion
406
+ //#region src/commands/install.ts
407
+ const install = command({
408
+ name: "install",
409
+ aliases: ["add", "i"],
410
+ description: `
411
+ The install command adds Powerhouse dependencies to your project.
412
+
413
+ By default it only registers the package in powerhouse.config.json with
414
+ provider "registry" — Connect will load it from the registry CDN at runtime.
415
+
416
+ With --local, the package is also installed into node_modules and marked
417
+ as provider "local" — it will be bundled into ph connect build so the
418
+ preview works without the registry being reachable.
419
+
420
+ Resolution order for the registry URL:
421
+ --registry flag > PH_REGISTRY_URL env > powerhouse.config.json > default
422
+ `,
423
+ args: installArgs,
424
+ handler: async (args) => {
425
+ if (args.debug) console.log(args);
426
+ const { projectPath, localProjectPath, globalProjectPath, packageManager, isGlobal } = await getPowerhouseProjectInfo(args);
427
+ if (!projectPath) throw new Error(`Could not find project path to install from.`);
428
+ const registryUrl = resolveRegistryUrl({
429
+ registry: args.registry,
430
+ projectPath
431
+ });
432
+ if (args.debug) console.log(">>> registryUrl", registryUrl);
433
+ const dependenciesWithVersions = await makeDependenciesWithVersions(args.dependencies, registryUrl);
434
+ if (args.debug) {
435
+ console.log(">>> parsedDependencies", dependenciesWithVersions);
436
+ console.log("\n>>> projectInfo", {
437
+ localProjectPath,
438
+ globalProjectPath,
439
+ packageManager,
440
+ isGlobal
441
+ });
442
+ }
443
+ if (args.local) {
444
+ if (dependenciesWithVersions.length === 0) throw new Error("--local requires at least one package name (e.g. ph install --local @scope/pkg)");
445
+ try {
446
+ const specs = dependenciesWithVersions.map((d) => d.version ? `${d.name}@${d.version}` : d.name);
447
+ const scopes = /* @__PURE__ */ new Set();
448
+ for (const dep of dependenciesWithVersions) if (dep.name.startsWith("@")) {
449
+ const scope = dep.name.split("/")[0];
450
+ scopes.add(scope);
451
+ }
452
+ const scopeRegistryArgs = Array.from(scopes).map((scope) => `--${scope}:registry=${registryUrl}`);
453
+ const resolved = resolveCommand(packageManager, "add", [...specs, ...scopeRegistryArgs]);
454
+ if (!resolved) throw new Error(`Failed to resolve install command for package manager "${packageManager}".`);
455
+ const installCommand = `${resolved.command} ${resolved.args.join(" ")}`;
456
+ if (scopeRegistryArgs.length > 0) console.log(`Installing dependencies 📦 (routing ${Array.from(scopes).join(", ")} → ${registryUrl})...`);
457
+ else console.log("Installing dependencies 📦...");
458
+ console.log(`> ${installCommand}`);
459
+ execSync(installCommand, {
460
+ stdio: "inherit",
461
+ cwd: projectPath
462
+ });
463
+ console.log("Dependency installed successfully 🎉");
464
+ } catch (error) {
465
+ console.error("❌ Failed to install dependencies");
466
+ throw error;
467
+ }
468
+ }
469
+ try {
470
+ console.log("⚙️ Updating powerhouse config file...");
471
+ updateConfigFile(dependenciesWithVersions, projectPath, "install", args.local ? "local" : "registry", registryUrl);
472
+ console.log("Config file updated successfully 🎉");
473
+ } catch (error) {
474
+ console.error("❌ Failed to update config file");
475
+ throw error;
476
+ }
477
+ if (args.local) try {
478
+ console.log("⚙️ Updating styles.css file...");
479
+ updateStylesFile(dependenciesWithVersions, projectPath);
480
+ console.log("Styles file updated successfully 🎉");
481
+ } catch (error) {
482
+ console.error("❌ Failed to update styles file");
483
+ throw error;
484
+ }
485
+ process.exit(0);
486
+ }
487
+ });
488
+ //#endregion
489
+ //#region src/commands/migrate.ts
490
+ const migrate$1 = command({
491
+ name: "migrate",
492
+ args: migrateArgs,
493
+ description: "Run migrations",
494
+ handler: async (args) => {
495
+ if (args.debug) console.log(args);
496
+ const { startMigrate } = await import("./migrate-CSaC4bDh.mjs");
497
+ await startMigrate(args);
498
+ process.exit(0);
499
+ }
500
+ });
501
+ //#endregion
502
+ //#region src/commands/publish.ts
503
+ function hasTagFlag(args) {
504
+ return args.some((a) => a === "--tag" || a.startsWith("--tag="));
505
+ }
506
+ function isInteractive() {
507
+ return Boolean(process.stdin.isTTY) && !process.env.CI;
508
+ }
509
+ function readPrereleaseTag(projectPath) {
510
+ try {
511
+ const pkg = readPackageSync({ cwd: projectPath });
512
+ if (!pkg.version) return null;
513
+ const parts = prerelease(pkg.version);
514
+ if (!parts || parts.length === 0) return null;
515
+ const label = String(parts[0]);
516
+ if (!/^[a-z][a-z0-9-]*$/i.test(label)) return null;
517
+ return {
518
+ version: pkg.version,
519
+ tag: label
520
+ };
521
+ } catch {
522
+ return null;
523
+ }
524
+ }
525
+ const publish = command({
526
+ name: "publish",
527
+ description: `
528
+ Publish a package to the Powerhouse registry. This is a thin wrapper around npm publish
529
+ that automatically sets the registry URL.
530
+
531
+ This command:
532
+ 1. Resolves the registry URL (--registry flag > PH_REGISTRY_URL env > powerhouse.config.json > default)
533
+ 2. Checks authentication with the registry via npm whoami
534
+ 3. Forwards all additional arguments to npm publish
535
+ `,
536
+ args: publishArgs,
537
+ handler: async (args) => {
538
+ if (args.debug) console.log(args);
539
+ const { projectPath } = await getPowerhouseProjectInfo();
540
+ if (!projectPath) throw new Error("Could not find project path.");
541
+ const registryUrl = resolveRegistryUrl({
542
+ registry: args.registry,
543
+ projectPath
544
+ });
545
+ if (args.debug) console.log(">>> registryUrl", registryUrl);
546
+ try {
547
+ await checkNpmAuth(registryUrl);
548
+ } catch {
549
+ console.error(`Not authenticated with registry: ${registryUrl}`);
550
+ console.error(`Run: npm adduser --registry ${registryUrl}`);
551
+ process.exit(1);
552
+ }
553
+ let forwardedArgs = args.forwardedArgs;
554
+ if (!hasTagFlag(forwardedArgs)) {
555
+ const prereleaseInfo = readPrereleaseTag(projectPath);
556
+ if (prereleaseInfo) {
557
+ const { version, tag } = prereleaseInfo;
558
+ if (!isInteractive()) {
559
+ console.error(`Detected prerelease version ${version}. npm requires an explicit dist-tag for prerelease publishes.`);
560
+ console.error(`Re-run with --tag <label> (e.g. --tag ${tag}) to proceed.`);
561
+ process.exit(1);
562
+ }
563
+ const enquirer = await import("enquirer");
564
+ let confirmed = false;
565
+ try {
566
+ confirmed = (await enquirer.default.prompt({
567
+ type: "confirm",
568
+ name: "confirmed",
569
+ message: `Detected prerelease version ${version}. Publish with --tag ${tag}?`,
570
+ initial: true
571
+ })).confirmed;
572
+ } catch {
573
+ confirmed = false;
574
+ }
575
+ if (!confirmed) {
576
+ console.error(`Aborted. To publish manually: npm publish --registry ${registryUrl} --tag <label>`);
577
+ process.exit(1);
578
+ }
579
+ forwardedArgs = [
580
+ "--tag",
581
+ tag,
582
+ ...forwardedArgs
583
+ ];
584
+ }
585
+ }
586
+ if (args.debug) console.log(">>> command", `npm publish --registry ${registryUrl} ${forwardedArgs.join(" ")}`);
587
+ console.log(`Publishing to ${registryUrl}...`);
588
+ const result = await npmPublish({
589
+ registryUrl,
590
+ cwd: projectPath,
591
+ args: forwardedArgs
592
+ });
593
+ if (result.stdout) console.log(result.stdout);
594
+ process.exit(0);
595
+ }
596
+ });
597
+ //#endregion
598
+ //#region src/commands/switchboard.ts
599
+ const switchboard = command({
600
+ name: "switchboard",
601
+ aliases: ["reactor"],
602
+ description: `
603
+ The switchboard command starts a local Switchboard instance, which acts as the document
604
+ processing engine for Powerhouse projects. It provides the infrastructure for document
605
+ models, processors, and real-time updates.
606
+
607
+ This command:
608
+ 1. Starts a local switchboard server
609
+ 2. Loads document models and processors
610
+ 3. Provides an API for document operations
611
+ 4. Enables real-time document processing
612
+ 5. Can authenticate with remote services using your identity from 'ph login'`,
613
+ args: switchboardArgs,
614
+ handler: async (args) => {
615
+ if (args.debug) console.log(args);
616
+ const { basePath, dbPath, migrate, migrateStatus } = args;
617
+ if (basePath) process.env.BASE_PATH = basePath;
618
+ if (migrate || migrateStatus) {
619
+ const { runSwitchboardMigrations } = await import("./switchboard-migrate-BiQJfIrc.mjs");
620
+ await runSwitchboardMigrations({
621
+ dbPath,
622
+ statusOnly: migrateStatus
623
+ });
624
+ process.exit(0);
625
+ }
626
+ const { startSwitchboard } = await import("./switchboard-DUlj8v2F.mjs");
627
+ const { defaultDriveUrl, renown } = await startSwitchboard(args);
628
+ console.log(" ➜ Switchboard:", defaultDriveUrl);
629
+ if (renown) console.log(" ➜ Identity:", renown.did);
630
+ }
631
+ });
632
+ //#endregion
633
+ //#region src/commands/uninstall.ts
634
+ const uninstall = command({
635
+ name: "uninstall",
636
+ aliases: ["remove"],
637
+ description: `
638
+ The uninstall command removes Powerhouse dependencies from your project. It handles the
639
+ removal of packages, updates configuration files, and ensures proper cleanup.
640
+
641
+ This command:
642
+ 1. Uninstalls specified Powerhouse dependencies using your package manager
643
+ 2. Updates powerhouse.config.json to remove the dependencies
644
+ 3. Supports various uninstallation options and configurations
645
+ 4. Works with ${AGENTS.join(", ")} package managers
646
+ `,
647
+ args: uninstallArgs,
648
+ handler: async (args) => {
649
+ if (args.debug) console.log(args);
650
+ const { projectPath, localProjectPath, globalProjectPath, packageManager, isGlobal } = await getPowerhouseProjectInfo(args);
651
+ if (!projectPath) throw new Error(`Could not find project path to uninstall from`);
652
+ const dependenciesWithVersions = await makeDependenciesWithVersions(args.dependencies);
653
+ if (args.debug) console.log(">>> parsedDependencies", dependenciesWithVersions);
654
+ if (args.debug) console.log("\n>>> projectInfo", {
655
+ localProjectPath,
656
+ globalProjectPath,
657
+ packageManager,
658
+ isGlobal
659
+ });
660
+ try {
661
+ console.log("Uninstalling dependencies 📦 ...");
662
+ execSync(await getPowerhouseProjectUninstallCommand(packageManager), {
663
+ stdio: "inherit",
664
+ cwd: projectPath
665
+ });
666
+ console.log("Dependency uninstalled successfully 🎉");
667
+ } catch (error) {
668
+ console.error("❌ Failed to uninstall dependencies");
669
+ throw error;
670
+ }
671
+ try {
672
+ console.log("⚙️ Updating powerhouse config file...");
673
+ updateConfigFile(dependenciesWithVersions, projectPath, "uninstall");
674
+ console.log("Config file updated successfully 🎉");
675
+ } catch (error) {
676
+ console.error("❌ Failed to update config file");
677
+ throw error;
678
+ }
679
+ try {
680
+ console.log("⚙️ Updating styles.css file...");
681
+ removeStylesImports(dependenciesWithVersions, projectPath);
682
+ console.log("Styles file updated successfully 🎉");
683
+ } catch (error) {
684
+ console.error("❌ Failed to update styles file");
685
+ throw error;
686
+ }
687
+ process.exit(0);
688
+ }
689
+ });
690
+ //#endregion
691
+ //#region src/commands/unpublish.ts
692
+ const unpublish = command({
693
+ name: "unpublish",
694
+ description: `
695
+ Unpublish a package from the Powerhouse registry. This is a thin wrapper around
696
+ npm unpublish that automatically targets the Powerhouse registry and never
697
+ reaches npmjs.org.
698
+
699
+ Forms:
700
+ ph unpublish # unpublish <name>@<version> from cwd's package.json
701
+ ph unpublish <name> # unpublish the whole package (all versions)
702
+ ph unpublish <name>@<version> # unpublish a single version
703
+
704
+ Flags:
705
+ --registry <url> # override registry URL
706
+ --yes, -y # skip the confirmation prompt
707
+ `,
708
+ args: unpublishArgs,
709
+ handler: async (args) => {
710
+ if (args.debug) console.log(args);
711
+ const { projectPath } = await getPowerhouseProjectInfo();
712
+ if (!projectPath) throw new Error("Could not find project path.");
713
+ const registryUrl = resolveRegistryUrl({
714
+ registry: args.registry,
715
+ projectPath
716
+ });
717
+ const spec = resolveSpec(args.spec, projectPath);
718
+ if (!spec) {
719
+ console.error("No package spec provided and could not read name/version from package.json.");
720
+ process.exit(1);
721
+ }
722
+ if (args.debug) {
723
+ console.log(">>> registryUrl", registryUrl);
724
+ console.log(">>> spec", spec);
725
+ }
726
+ try {
727
+ await checkNpmAuth(registryUrl);
728
+ } catch {
729
+ console.error(`Not authenticated with registry: ${registryUrl}`);
730
+ console.error(`Run: npm adduser --registry ${registryUrl}`);
731
+ process.exit(1);
732
+ }
733
+ if (!args.yes) {
734
+ if (!await confirm(`Unpublish ${spec} from ${registryUrl}? [y/N] `)) {
735
+ console.log("Aborted.");
736
+ process.exit(0);
737
+ }
738
+ }
739
+ if (args.debug) console.log(">>> command", `npm unpublish ${spec} --registry ${registryUrl} --force ${args.forwardedArgs.join(" ")}`);
740
+ console.log(`Unpublishing ${spec} from ${registryUrl}...`);
741
+ try {
742
+ const result = await npmUnpublish({
743
+ registryUrl,
744
+ cwd: projectPath,
745
+ spec,
746
+ args: args.forwardedArgs
747
+ });
748
+ if (result.stdout) console.log(result.stdout);
749
+ process.exit(0);
750
+ } catch (err) {
751
+ console.error(err instanceof Error ? err.message : String(err));
752
+ process.exit(1);
753
+ }
754
+ }
755
+ });
756
+ function resolveSpec(explicit, projectPath) {
757
+ if (explicit) return explicit;
758
+ try {
759
+ const pkg = readPackageSync({ cwd: projectPath });
760
+ if (!pkg.name) return null;
761
+ return pkg.version ? `${pkg.name}@${pkg.version}` : pkg.name;
762
+ } catch {
763
+ return null;
764
+ }
765
+ }
766
+ async function confirm(prompt) {
767
+ const rl = createInterface({
768
+ input: process.stdin,
769
+ output: process.stdout
770
+ });
771
+ try {
772
+ const answer = await rl.question(prompt);
773
+ return /^y(es)?$/i.test(answer.trim());
774
+ } finally {
775
+ rl.close();
776
+ }
777
+ }
778
+ //#endregion
779
+ //#region src/commands/ph-cli-commands.ts
780
+ const phCliCommands = {
781
+ init,
782
+ code,
783
+ generate,
784
+ vetra: command({
785
+ name: "vetra",
786
+ description: `
787
+ The vetra command sets up a Vetra development environment for working with Vetra projects.
788
+ It starts a Vetra Switchboard and optionally Connect Studio, enabling document collaboration
789
+ and real-time processing with a "Vetra" drive or connection to remote drives.
790
+
791
+ This command:
792
+ 1. Starts a Vetra Switchboard with a "Vetra" drive for document storage
793
+ 2. Optionally connects to remote drives instead of creating a local drive
794
+ 3. Starts Connect Studio pointing to the Switchboard for user interaction (unless disabled)
795
+ 4. Enables real-time updates, collaboration, and code generation`,
796
+ args: vetraArgs,
797
+ handler: async (args) => {
798
+ if (args.debug) console.log(args);
799
+ const { startVetra } = await import("./vetra-D2zbrNY1.mjs");
800
+ await startVetra(args);
801
+ }
802
+ }),
803
+ connect,
804
+ build: build$1,
805
+ publish,
806
+ unpublish,
807
+ "access-token": accessToken,
808
+ inspect,
809
+ list,
810
+ migrate: migrate$1,
811
+ switchboard,
812
+ login,
813
+ logout,
814
+ install,
815
+ uninstall
816
+ };
817
+ const phCli = subcommands({
818
+ name: "ph-cli",
819
+ description: PH_CLI_DESCRIPTION,
820
+ version: getVersion(),
821
+ cmds: phCliCommands
822
+ });
823
+ //#endregion
824
+ //#region src/cli.ts
825
+ async function main() {
826
+ assertNodeVersion();
827
+ await initCliTelemetry({
828
+ cliName: "ph-cli",
829
+ release: getVersion()
830
+ });
831
+ const args = process.argv.slice(2);
832
+ const hasNoArgs = args.length === 0;
833
+ const isHelp = args.some((arg) => arg === "--help" || arg === "-h");
834
+ const isTopLevelHelp = isHelp && args.length === 1;
835
+ const cli = hasNoArgs || isTopLevelHelp ? phCliHelp : phCli;
836
+ const [command, ...restArgs] = args;
837
+ if (command === "connect" && ![
838
+ "studio",
839
+ "build",
840
+ "preview"
841
+ ].includes(args[1]) && !isHelp) await run(cli, [
842
+ "connect",
843
+ "studio",
844
+ ...restArgs
845
+ ]);
846
+ else await run(cli, args);
847
+ }
848
+ await main().catch(async (error) => {
849
+ const isDebug = process.argv.slice(2).includes("--debug");
850
+ await captureCliError(error);
851
+ if (isDebug) throw error;
852
+ if (error instanceof Error) {
853
+ console.error(error.message);
854
+ process.exit(1);
855
+ } else throw error;
856
+ });
857
+ //#endregion
858
+ export {};
859
+
860
+ //# sourceMappingURL=cli.mjs.map