@powerhousedao/ph-cli 6.0.0-dev.106 → 6.0.0-dev.108

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/dist/cli.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as runBuild } from "./build-0mNzbS4y.mjs";
3
- import { a as updateStylesFile, i as updateConfigFile, r as removeStylesImports } from "./utils-5r3OKhGj.mjs";
4
- import { DEFAULT_EXPIRY_SECONDS, SECONDS_IN_DAY, accessTokenArgs, assertNodeVersion, buildArgs, connectBuildArgs, connectPreviewArgs, connectStudioArgs, generateArgs, getPowerhouseProjectInfo, getPowerhouseProjectInstallCommand, getPowerhouseProjectUninstallCommand, inspectArgs, installArgs, listArgs, loginArgs, makeDependenciesWithVersions, migrateArgs, phCliHelpCommands, publishArgs, switchboardArgs, uninstallArgs, vetraArgs } from "@powerhousedao/shared/clis";
3
+ import { a as updateStylesFile, i as updateConfigFile, r as removeStylesImports } from "./utils-CjKhqXvK.mjs";
4
+ import { DEFAULT_EXPIRY_SECONDS, SECONDS_IN_DAY, accessTokenArgs, assertNodeVersion, buildArgs, connectBuildArgs, connectPreviewArgs, connectStudioArgs, generateArgs, getConfig, getPowerhouseProjectInfo, getPowerhouseProjectInstallCommand, getPowerhouseProjectUninstallCommand, inspectArgs, installArgs, listArgs, loginArgs, makeDependenciesWithVersions, migrateArgs, phCliHelpCommands, publishArgs, switchboardArgs, uninstallArgs, vetraArgs } from "@powerhousedao/shared/clis";
5
5
  import { command, run, subcommands } from "cmd-ts";
6
6
  import { AGENTS } from "package-manager-detector";
7
- import { execSync } from "child_process";
8
- import { getConfig } from "@powerhousedao/config/node";
9
7
  import { DEFAULT_REGISTRY_URL } from "@powerhousedao/config";
8
+ import { execSync } from "child_process";
10
9
  import { join } from "path";
10
+ import { getConfig as getConfig$1 } from "@powerhousedao/config/node";
11
11
  //#region src/get-version.ts
12
12
  function getVersion() {
13
13
  return process.env.WORKSPACE_VERSION || process.env.npm_package_version || "unknown";
@@ -204,7 +204,7 @@ This command:
204
204
  args: generateArgs,
205
205
  handler: async (args) => {
206
206
  if (args.debug) console.log(args);
207
- const { startGenerate } = await import("./generate-AwuAjrOM.mjs");
207
+ const { startGenerate } = await import("./generate-D7rJ2-Y6.mjs");
208
208
  await startGenerate(args);
209
209
  process.exit(0);
210
210
  }
@@ -227,7 +227,7 @@ This command:
227
227
  args: inspectArgs,
228
228
  handler: async (args) => {
229
229
  if (args.debug) console.log(args);
230
- const { startInspect } = await import("./inspect-CeMFGkND.mjs");
230
+ const { startInspect } = await import("./inspect--c82Qog6.mjs");
231
231
  startInspect(args);
232
232
  process.exit(0);
233
233
  }
@@ -238,21 +238,24 @@ const install = command({
238
238
  name: "install",
239
239
  aliases: ["add", "i"],
240
240
  description: `
241
- The install command adds Powerhouse dependencies to your project. It handles installation
242
- of packages, updates configuration files, and ensures proper setup of dependencies.
241
+ The install command adds Powerhouse dependencies to your project. It installs packages
242
+ from the Powerhouse registry by default and updates configuration files.
243
243
 
244
244
  This command:
245
- 1. Installs specified Powerhouse dependencies using your package manager
246
- 2. Updates powerhouse.config.json to include the new dependencies
247
- 3. Supports various installation options and configurations
248
- 4. Works with npm, yarn, pnpm, and bun package managers
245
+ 1. Resolves the registry URL (--registry flag > powerhouse.config.json > PH_REGISTRY_URL env > default)
246
+ 2. Installs the package using your package manager with the resolved registry
247
+ 3. Updates powerhouse.config.json to include the new dependencies
248
+ 4. Updates style.css with CSS imports if applicable
249
249
  `,
250
250
  args: installArgs,
251
251
  handler: async (args) => {
252
252
  if (args.debug) console.log(args);
253
253
  const { projectPath, localProjectPath, globalProjectPath, packageManager, isGlobal } = await getPowerhouseProjectInfo(args);
254
254
  if (!projectPath) throw new Error(`Could not find project path to install from.`);
255
- const dependenciesWithVersions = await makeDependenciesWithVersions(args.dependencies);
255
+ const config = getConfig(join(projectPath, "powerhouse.config.json"));
256
+ const registryUrl = args.registry ?? config.packageRegistryUrl ?? process.env.PH_REGISTRY_URL ?? DEFAULT_REGISTRY_URL;
257
+ if (args.debug) console.log(">>> registryUrl", registryUrl);
258
+ const dependenciesWithVersions = await makeDependenciesWithVersions(args.dependencies, registryUrl);
256
259
  if (args.debug) console.log(">>> parsedDependencies", dependenciesWithVersions);
257
260
  if (args.debug) console.log("\n>>> projectInfo", {
258
261
  localProjectPath,
@@ -261,8 +264,8 @@ This command:
261
264
  isGlobal
262
265
  });
263
266
  try {
264
- console.log("installing dependencies 📦 ...");
265
- execSync(getPowerhouseProjectInstallCommand(packageManager), {
267
+ console.log(`installing dependencies 📦 from ${registryUrl}...`);
268
+ execSync(getPowerhouseProjectInstallCommand(packageManager, ["--registry", registryUrl]), {
266
269
  stdio: "inherit",
267
270
  cwd: projectPath
268
271
  });
@@ -316,7 +319,7 @@ This command:
316
319
  try {
317
320
  const projectInfo = await getPowerhouseProjectInfo();
318
321
  console.log("\n>>> projectInfo", projectInfo);
319
- const phConfig = getConfig(projectInfo.projectPath + "/powerhouse.config.json");
322
+ const phConfig = getConfig$1(projectInfo.projectPath + "/powerhouse.config.json");
320
323
  if (!phConfig.packages || phConfig.packages.length === 0) {
321
324
  console.log("No packages found in the project");
322
325
  return;
@@ -516,7 +519,7 @@ const migrate = command({
516
519
  description: "Run migrations",
517
520
  handler: async (args) => {
518
521
  if (args.debug) console.log(args);
519
- const { startMigrate } = await import("./migrate-BxG1NdR_.mjs");
522
+ const { startMigrate } = await import("./migrate-DErTQPCC.mjs");
520
523
  await startMigrate(args);
521
524
  process.exit(0);
522
525
  }
@@ -539,8 +542,8 @@ This command:
539
542
  if (args.debug) console.log(args);
540
543
  const { projectPath } = await getPowerhouseProjectInfo();
541
544
  if (!projectPath) throw new Error("Could not find project path.");
542
- const config = getConfig(join(projectPath, "powerhouse.config.json"));
543
- const registryUrl = args.registry ?? config.packageRegistryUrl ?? process.env.PH_REGISTRY_URL ?? DEFAULT_REGISTRY_URL;
545
+ const config = getConfig$1(join(projectPath, "powerhouse.config.json"));
546
+ const registryUrl = args.registry ?? process.env.PH_REGISTRY_URL ?? config.packageRegistryUrl ?? DEFAULT_REGISTRY_URL;
544
547
  if (args.debug) console.log(">>> registryUrl", registryUrl);
545
548
  try {
546
549
  execSync(`npm whoami --registry ${registryUrl}`, { stdio: "pipe" });
@@ -549,7 +552,7 @@ This command:
549
552
  console.error(`Run: npm adduser --registry ${registryUrl}`);
550
553
  process.exit(1);
551
554
  }
552
- const cmd = `npm publish --registry ${registryUrl} ${getForwardedArgs().join(" ")}`.trim();
555
+ const cmd = `npm publish --registry ${registryUrl} ${args.forwardedArgs.join(" ")}`.trim();
553
556
  if (args.debug) console.log(">>> command", cmd);
554
557
  console.log(`Publishing to ${registryUrl}...`);
555
558
  execSync(cmd, {
@@ -559,22 +562,6 @@ This command:
559
562
  process.exit(0);
560
563
  }
561
564
  });
562
- function getForwardedArgs() {
563
- const argv = process.argv;
564
- const publishIndex = argv.indexOf("publish");
565
- if (publishIndex === -1) return [];
566
- const rawArgs = argv.slice(publishIndex + 1);
567
- const filtered = [];
568
- for (let i = 0; i < rawArgs.length; i++) {
569
- if (rawArgs[i] === "--debug") continue;
570
- if (rawArgs[i] === "--registry") {
571
- i++;
572
- continue;
573
- }
574
- filtered.push(rawArgs[i]);
575
- }
576
- return filtered;
577
- }
578
565
  //#endregion
579
566
  //#region src/commands/switchboard.ts
580
567
  const switchboard = command({
@@ -687,7 +674,7 @@ This command:
687
674
  args: vetraArgs,
688
675
  handler: async (args) => {
689
676
  if (args.debug) console.log(args);
690
- const { startVetra } = await import("./vetra-DDjhg4w5.mjs");
677
+ const { startVetra } = await import("./vetra-Bii4o1sa.mjs");
691
678
  await startVetra(args);
692
679
  }
693
680
  }),
package/dist/cli.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.mjs","names":["version","build"],"sources":["../src/get-version.ts","../src/utils/constants.ts","../src/commands/ph-cli-help.ts","../src/commands/access-token.ts","../src/commands/build.ts","../src/commands/connect.ts","../src/commands/generate.ts","../src/commands/inspect.ts","../src/commands/install.ts","../src/commands/list.ts","../src/commands/login.ts","../src/commands/logout.ts","../src/commands/migrate.ts","../src/commands/publish.ts","../src/commands/switchboard.ts","../src/commands/uninstall.ts","../src/commands/vetra.ts","../src/commands/ph-cli-commands.ts","../src/commands/ph-cli.ts","../src/cli.ts"],"sourcesContent":["export function getVersion() {\n return (\n process.env.WORKSPACE_VERSION ||\n process.env.npm_package_version ||\n \"unknown\"\n );\n}\n","export const PH_CLI_DESCRIPTION =\n \"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.\" as const;\n","import { phCliHelpCommands } from \"@powerhousedao/shared/clis\";\nimport { subcommands } from \"cmd-ts\";\nimport { getVersion } from \"../get-version.js\";\nimport { PH_CLI_DESCRIPTION } from \"../utils/constants.js\";\n\nconst version = getVersion();\nexport const phCliHelp = subcommands({\n name: \"ph-cli\",\n description: PH_CLI_DESCRIPTION,\n version,\n cmds: phCliHelpCommands,\n});\n","import {\n accessTokenArgs,\n DEFAULT_EXPIRY_SECONDS,\n SECONDS_IN_DAY,\n} from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const accessToken = command({\n name: \"access-token\",\n description: `\nThe access-token command generates a bearer token for API authentication. This token\ncan be used to authenticate requests to Powerhouse APIs like reactor-api (Switchboard).\n\nThis command:\n1. Uses your CLI's cryptographic identity (DID) to sign a verifiable credential\n2. Creates a JWT bearer token with configurable expiration\n3. Outputs the token to stdout (info to stderr) for easy piping\n\nPrerequisites:\n You must have a cryptographic identity. Run 'ph login' first to:\n - Generate a keypair (stored in .ph/.keypair.json)\n - Optionally link your Ethereum address (stored in .ph/.renown.json)\n\nToken Details:\n The generated token is a JWT (JSON Web Token) containing:\n - Issuer (iss): Your CLI's DID (did:key:...)\n - Subject (sub): Your CLI's DID\n - Credential Subject: Chain ID, network ID, and address (if authenticated)\n - Expiration (exp): Based on --expiry option\n - Audience (aud): If --audience is specified\n\nOutput:\n- Token information (DID, address, expiry) is printed to stderr\n- The token itself is printed to stdout for easy piping/copying\n\nThis allows you to use the command in scripts:\n TOKEN=$(ph access-token)\n curl -H \"Authorization: Bearer $TOKEN\" http://localhost:4001/graphql\n\nUsage with APIs:\n Generate token and use with curl\n TOKEN=$(ph access-token --expiry 1d)\n curl -X POST http://localhost:4001/graphql \\\\\n -H \"Content-Type: application/json\" \\\\\n -H \"Authorization: Bearer $TOKEN\" \\\\\n -d '{\"query\": \"{ drives { id name } }\"}'\n\n Export as environment variable\n export PH_ACCESS_TOKEN=$(ph access-token)\n\nNotes:\n - Tokens are self-signed using your CLI's private key\n - No network request is made; tokens are generated locally\n - The recipient API must trust your CLI's DID to accept the token\n - For reactor-api, ensure AUTH_ENABLED=true to require authentication\n`,\n args: accessTokenArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n const { getRenown } = await import(\"../services/auth.js\");\n const renown = await getRenown();\n const did = renown.did;\n const user = renown.user;\n\n // Require Renown authentication - user must have done 'ph login'\n if (!user || !user.credential) {\n throw new Error(\n \"Not authenticated. Run 'ph login' first to authenticate with Renown. A Renown credential is required to generate valid bearer tokens.\",\n );\n }\n\n const address = user.address;\n\n // Parse expiry\n let expiresIn = DEFAULT_EXPIRY_SECONDS;\n if (args.expiry) expiresIn = parseExpiry(args.expiry);\n\n // Generate the bearer token;\n const token = await renown.getBearerToken(\n {\n expiresIn,\n aud: args.audience,\n },\n true,\n );\n\n // Calculate human-readable expiry\n const expiryDays = Math.floor(expiresIn / SECONDS_IN_DAY);\n const expiryHours = Math.floor((expiresIn % SECONDS_IN_DAY) / 3600);\n let expiryStr: string;\n if (expiryDays > 0) {\n expiryStr =\n expiryHours > 0\n ? `${expiryDays} day${expiryDays > 1 ? \"s\" : \"\"} and ${expiryHours} hour${expiryHours > 1 ? \"s\" : \"\"}`\n : `${expiryDays} day${expiryDays > 1 ? \"s\" : \"\"}`;\n } else if (expiryHours > 0) {\n expiryStr = `${expiryHours} hour${expiryHours > 1 ? \"s\" : \"\"}`;\n } else {\n expiryStr = `${expiresIn} seconds`;\n }\n\n // Output token info to stderr, token itself to stdout for piping\n console.error(`CLI DID: ${did}`);\n console.error(`ETH Address: ${address}`);\n console.error(`Token expires in: ${expiryStr}`);\n console.error(\"\");\n\n // Output just the token to stdout (for easy piping/copying)\n console.log(token);\n process.exit(0);\n },\n});\n\n/**\n * Parse expiry string to seconds\n * Supports formats: \"7d\" (days), \"24h\" (hours), \"3600\" (seconds), \"3600s\" (seconds)\n */\nfunction parseExpiry(expiry: string): number {\n const trimmed = expiry.trim().toLowerCase();\n\n // Check for day format (e.g., \"7d\")\n if (trimmed.endsWith(\"d\")) {\n const days = parseInt(trimmed.slice(0, -1), 10);\n if (isNaN(days) || days <= 0) {\n throw new Error(\n `Invalid expiry format: ${expiry}. Days must be a positive number.`,\n );\n }\n return days * SECONDS_IN_DAY;\n }\n\n // Check for hour format (e.g., \"24h\")\n if (trimmed.endsWith(\"h\")) {\n const hours = parseInt(trimmed.slice(0, -1), 10);\n if (isNaN(hours) || hours <= 0) {\n throw new Error(\n `Invalid expiry format: ${expiry}. Hours must be a positive number.`,\n );\n }\n return hours * 60 * 60;\n }\n\n // Check for seconds format (e.g., \"3600s\" or just \"3600\")\n const numericValue = trimmed.endsWith(\"s\") ? trimmed.slice(0, -1) : trimmed;\n\n const seconds = parseInt(numericValue, 10);\n if (isNaN(seconds) || seconds <= 0) {\n throw new Error(\n `Invalid expiry format: ${expiry}. Expected a positive number or format like \"7d\", \"24h\", \"3600s\".`,\n );\n }\n\n return seconds;\n}\n","import { buildArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\nimport { runBuild } from \"../services/build.js\";\n\nexport const build = command({\n name: \"build\",\n args: buildArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n try {\n await runBuild(args);\n } catch (error) {\n console.error(error);\n process.exit(1);\n }\n },\n});\n","import {\n connectBuildArgs,\n connectPreviewArgs,\n connectStudioArgs,\n} from \"@powerhousedao/shared/clis\";\nimport { command, subcommands } from \"cmd-ts\";\nexport const studio = command({\n name: \"studio\",\n description: `The studio command starts the Connect Studio, a development environment for building\nand testing Powerhouse applications. It provides a visual interface for working with\nyour project.\n\nThis command:\n1. Starts a local Connect Studio server\n2. Provides a web interface for development\n3. Allows you to interact with your project components\n4. Supports various configuration options for customization\n`,\n args: connectStudioArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { runConnectStudio } = await import(\"../services/connect-studio.js\");\n await runConnectStudio(args);\n },\n});\n\nexport const build = command({\n name: \"build\",\n description: `The Connect build command creates a production build with the project's local and\nexternal packages included\n`,\n args: connectBuildArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n const { runConnectBuild } = await import(\"../services/connect-build.js\");\n await runConnectBuild(args);\n process.exit(0);\n },\n});\n\nexport const preview = command({\n name: \"preview\",\n description: `The Connect preview command previews a built Connect project.\nNOTE: You must run \\`ph connect build\\` first\n`,\n args: connectPreviewArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { runConnectPreview } =\n await import(\"../services/connect-preview.js\");\n await runConnectPreview(args);\n },\n});\n\nexport const connect = subcommands({\n name: \"connect\",\n description: `Powerhouse Connect commands. Use with \\`studio\\`, \\`build\\` or \\`preview\\`. Defaults to \\`studio\\` if not specified.`,\n cmds: {\n studio,\n build,\n preview,\n },\n});\n","import { generateArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const generate = command({\n name: \"generate\",\n description: `\nThe generate command creates code from document models. It helps you build editors, \nprocessors, and other components based on your document model files.\n\nThis command:\n1. Reads document model definitions\n2. Generates code for specified components (editors, processors, etc.)\n3. Supports customization of output and generation options\n4. Can watch files for changes and regenerate code automatically\n`,\n args: generateArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { startGenerate } = await import(\"../services/generate.js\");\n await startGenerate(args);\n process.exit(0);\n },\n});\n","import { inspectArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const inspect = command({\n name: \"inspect\",\n description: `\nThe inspect command examines and provides detailed information about a Powerhouse package.\nIt helps you understand the structure, dependencies, and configuration of packages in\nyour project.\n\nThis command:\n1. Analyzes the specified package\n2. Retrieves detailed information about its structure and configuration\n3. Displays package metadata, dependencies, and other relevant information\n4. Helps troubleshoot package-related issues`,\n aliases: [\"is\"],\n args: inspectArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { startInspect } = await import(\"../services/inspect.js\");\n startInspect(args);\n process.exit(0);\n },\n});\n","import {\n getPowerhouseProjectInfo,\n getPowerhouseProjectInstallCommand,\n installArgs,\n makeDependenciesWithVersions,\n} from \"@powerhousedao/shared/clis\";\nimport { execSync } from \"child_process\";\nimport { command } from \"cmd-ts\";\nimport { updateConfigFile, updateStylesFile } from \"../utils.js\";\n\nexport const install = command({\n name: \"install\",\n aliases: [\"add\", \"i\"],\n description: `\nThe install command adds Powerhouse dependencies to your project. It handles installation\nof packages, updates configuration files, and ensures proper setup of dependencies.\n\nThis command:\n1. Installs specified Powerhouse dependencies using your package manager\n2. Updates powerhouse.config.json to include the new dependencies\n3. Supports various installation options and configurations\n4. Works with npm, yarn, pnpm, and bun package managers\n `,\n args: installArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n const {\n projectPath,\n localProjectPath,\n globalProjectPath,\n packageManager,\n isGlobal,\n } = await getPowerhouseProjectInfo(args);\n\n if (!projectPath) {\n throw new Error(`Could not find project path to install from.`);\n }\n\n const dependenciesWithVersions = await makeDependenciesWithVersions(\n args.dependencies,\n );\n\n if (args.debug) {\n console.log(\">>> parsedDependencies\", dependenciesWithVersions);\n }\n\n if (args.debug) {\n console.log(\"\\n>>> projectInfo\", {\n localProjectPath,\n globalProjectPath,\n packageManager,\n isGlobal,\n });\n }\n\n try {\n console.log(\"installing dependencies 📦 ...\");\n const installCommand = getPowerhouseProjectInstallCommand(packageManager);\n execSync(installCommand, {\n stdio: \"inherit\",\n cwd: projectPath,\n });\n console.log(\"Dependency installed successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to install dependencies\");\n throw error;\n }\n\n if (args.debug) {\n console.log(\"\\n>>> updateConfigFile arguments:\");\n console.log(\">>> dependencies\", args.dependencies);\n console.log(\">>> projectPath\", projectPath);\n }\n\n try {\n console.log(\"⚙️ Updating powerhouse config file...\");\n updateConfigFile(dependenciesWithVersions, projectPath, \"install\");\n console.log(\"Config file updated successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to update config file\");\n throw error;\n }\n\n try {\n console.log(\"⚙️ Updating styles.css file...\");\n updateStylesFile(dependenciesWithVersions, projectPath);\n console.log(\"Styles file updated successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to update styles file\");\n throw error;\n }\n\n process.exit(0);\n },\n});\n","import { getConfig } from \"@powerhousedao/config/node\";\nimport { getPowerhouseProjectInfo, listArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const list = command({\n name: \"list\",\n description: `\nThe list command displays information about installed Powerhouse packages in your project.\nIt reads the powerhouse.config.json file and shows the packages that are currently installed.\n\nThis command:\n1. Examines your project configuration\n2. Lists all installed Powerhouse packages\n3. Provides a clear overview of your project's dependencies\n4. Helps you manage and track your Powerhouse components\n`,\n aliases: [\"l\"],\n args: listArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n try {\n const projectInfo = await getPowerhouseProjectInfo();\n console.log(\"\\n>>> projectInfo\", projectInfo);\n\n const phConfig = getConfig(\n projectInfo.projectPath + \"/powerhouse.config.json\",\n );\n\n if (!phConfig.packages || phConfig.packages.length === 0) {\n console.log(\"No packages found in the project\");\n return;\n }\n\n console.log(\"Installed Packages:\\n\");\n phConfig.packages.forEach((pkg) => {\n console.log(pkg.packageName);\n });\n } catch (e) {\n console.log(\"No packages found in the project\");\n }\n process.exit(0);\n },\n});\n","import { loginArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const login = command({\n name: \"login\",\n description: `\nThe login command authenticates you with Renown using your Ethereum wallet. This enables\nthe CLI to act on behalf of your Ethereum identity for authenticated operations.\n\nThis command:\n1. Generates or loads a cryptographic identity (DID) for the CLI\n2. Opens your browser to the Renown authentication page\n3. You authorize the CLI's DID to act on behalf of your Ethereum address\n4. Stores the credentials locally in .ph/.renown.json\n `,\n args: loginArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n if (args.showDid) {\n await showDid();\n process.exit(0);\n }\n\n // Handle status check\n if (args.status) {\n await showStatus();\n process.exit(0);\n }\n\n // Handle logout\n if (args.logout) {\n await handleLogout();\n process.exit(0);\n }\n\n const renownUrl = args.renownUrl;\n const timeoutMs = args.timeout ? args.timeout * 1000 : DEFAULT_TIMEOUT_MS;\n\n console.debug(\"Initializing cryptographic identity...\");\n\n const { generateSessionId, getRenown } =\n await import(\"../services/auth.js\");\n const renown = await getRenown();\n\n // Check if already authenticated\n if (renown.user) {\n console.error(\n `Already authenticated as ${renown.user.address}\\nUse \"ph logout\" to sign out first.`,\n );\n process.exit(1);\n }\n\n // Get the CLI's DID from Renown\n console.log(`CLI DID: ${renown.did}`);\n\n // Generate session ID\n const sessionId = generateSessionId();\n\n // Build the login URL with connect DID\n const loginUrl = new URL(`${renownUrl}/console`);\n loginUrl.searchParams.set(\"session\", sessionId);\n loginUrl.searchParams.set(\"connect\", renown.did);\n loginUrl.searchParams.set(\"app\", renown.did);\n\n console.log(\"Opening browser for authentication...\");\n console.log(`Session ID: ${sessionId.slice(0, 8)}...`);\n console.log();\n\n // Open browser\n await openBrowser(loginUrl.toString());\n\n console.log(\"Waiting for authentication in browser\");\n console.log(`(timeout in ${timeoutMs / 1000} seconds)`);\n console.log();\n console.log(\n \"Please connect your wallet and authorize this CLI to act on your behalf.\",\n );\n console.log();\n process.stdout.write(\"Waiting\");\n\n // Poll for session completion\n const result = await pollSession(renownUrl, sessionId, timeoutMs);\n\n console.log(); // New line after dots\n\n if (!result) {\n throw new Error(\n \"\\nAuthentication timed out. \\nPlease try again with: ph login\",\n );\n }\n\n const user = await renown.login(result.did);\n\n console.log();\n console.log(\"Successfully authenticated!\");\n console.log(` ETH Address: ${user.address}`);\n console.log(` User DID: ${user.did}`);\n console.log(` CLI DID: ${renown.did}`);\n console.log();\n console.log(\"The CLI can now act on behalf of your Ethereum identity.\");\n process.exit(0);\n },\n});\n\ninterface PendingSessionResponse {\n sessionId: string;\n status: \"pending\";\n}\n\ninterface ReadySessionResponse {\n sessionId: string;\n status: \"ready\";\n address: string;\n chainId: number;\n did: string;\n credentialId: string;\n userDocumentId: string;\n}\n\ntype SessionResponse = PendingSessionResponse | ReadySessionResponse;\n\nconst DEFAULT_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes\nconst POLL_INTERVAL_MS = 2000; // 2 seconds\n\n/**\n * Open a URL in the default browser\n */\nasync function openBrowser(url: string): Promise<void> {\n const { exec } = await import(\"node:child_process\");\n const { promisify } = await import(\"node:util\");\n const execAsync = promisify(exec);\n\n const platform = process.platform;\n\n try {\n if (platform === \"darwin\") {\n await execAsync(`open \"${url}\"`);\n } else if (platform === \"win32\") {\n await execAsync(`start \"\" \"${url}\"`);\n } else {\n // Linux and others\n await execAsync(`xdg-open \"${url}\"`);\n }\n } catch (error) {\n console.error(\"Failed to open browser automatically.\");\n console.log(`Please open this URL manually: ${url}`);\n }\n}\n\n/**\n * Poll the session endpoint until ready or timeout\n */\nasync function pollSession(\n renownUrl: string,\n sessionId: string,\n timeoutMs: number,\n): Promise<ReadySessionResponse | null> {\n const startTime = Date.now();\n const sessionUrl = `${renownUrl}/api/console/session/${sessionId}`;\n\n while (Date.now() - startTime < timeoutMs) {\n try {\n const response = await fetch(sessionUrl);\n\n if (!response.ok) {\n console.error(`Session check failed: ${response.status}`);\n await sleep(POLL_INTERVAL_MS);\n continue;\n }\n\n const data = (await response.json()) as SessionResponse;\n\n if (data.status === \"ready\") {\n return data;\n }\n\n // Still pending, wait and try again\n process.stdout.write(\".\");\n await sleep(POLL_INTERVAL_MS);\n } catch (error) {\n // Network error, wait and retry\n await sleep(POLL_INTERVAL_MS);\n }\n }\n\n return null; // Timeout reached\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Show current authentication status\n */\nasync function showStatus(): Promise<void> {\n const { getRenown } = await import(\"../services/auth.js\");\n const renown = await getRenown();\n const user = renown.user;\n if (!user || !user.credential) {\n console.log(\"Not authenticated with an Ethereum address.\");\n console.log('Run \"ph login\" to authenticate.');\n return;\n }\n\n const issuanceDate = new Date(user.credential.issuanceDate);\n console.log(\"Authenticated\");\n console.log(` ETH Address: ${user.address}`);\n console.log(` User DID: ${user.did}`);\n console.log(` Chain ID: ${user.chainId}`);\n console.log(` CLI DID: ${renown.did}`);\n console.log(` Authenticated at: ${issuanceDate.toLocaleString()}`);\n console.log(` Renown URL: ${renown.baseUrl}`);\n\n process.exit(0);\n}\n\n/**\n * Show just the CLI DID\n */\nasync function showDid(): Promise<void> {\n try {\n const { generateSessionId, getRenown } =\n await import(\"../services/auth.js\");\n const renown = await getRenown();\n console.log(renown.did);\n } catch (e) {\n console.error(\"Failed to get DID:\");\n throw e;\n }\n}\n\n/**\n * Logout and clear credentials\n */\nexport async function handleLogout() {\n const { getRenown } = await import(\"../services/auth.js\");\n const renown = await getRenown();\n if (!renown.user) {\n console.log(\"Not currently authenticated.\");\n return;\n }\n\n try {\n await renown.logout();\n console.log(\"Successfully logged out.\");\n } catch (error) {\n console.error(\"Failed to clear credentials.\");\n console.debug(error);\n }\n}\n","import { command } from \"cmd-ts\";\nimport { handleLogout } from \"./login.js\";\n\nexport const logout = command({\n name: \"logout\",\n description: `\nThe logout command removes an existing session created with 'ph login'`,\n args: {},\n handler: async () => {\n await handleLogout();\n process.exit(0);\n },\n});\n","import { migrateArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const migrate = command({\n name: \"migrate\",\n args: migrateArgs,\n description: \"Run migrations\",\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { startMigrate } = await import(\"../services/migrate.js\");\n await startMigrate(args);\n process.exit(0);\n },\n});\n","import { DEFAULT_REGISTRY_URL } from \"@powerhousedao/config\";\nimport { getConfig } from \"@powerhousedao/config/node\";\nimport {\n getPowerhouseProjectInfo,\n publishArgs,\n} from \"@powerhousedao/shared/clis\";\nimport { execSync } from \"child_process\";\nimport { command } from \"cmd-ts\";\nimport { join } from \"path\";\n\nexport const publish = command({\n name: \"publish\",\n description: `\nPublish a package to the Powerhouse registry. This is a thin wrapper around npm publish\nthat automatically sets the registry URL.\n\nThis command:\n1. Resolves the registry URL (--registry flag > powerhouse.config.json > PH_REGISTRY_URL env > default)\n2. Checks authentication with the registry via npm whoami\n3. Forwards all additional arguments to npm publish\n `,\n args: publishArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n const { projectPath } = await getPowerhouseProjectInfo();\n\n if (!projectPath) {\n throw new Error(\"Could not find project path.\");\n }\n\n // Resolve registry URL: flag > config > env > default\n const configPath = join(projectPath, \"powerhouse.config.json\");\n const config = getConfig(configPath);\n const registryUrl =\n args.registry ??\n config.packageRegistryUrl ??\n process.env.PH_REGISTRY_URL ??\n DEFAULT_REGISTRY_URL;\n\n if (args.debug) {\n console.log(\">>> registryUrl\", registryUrl);\n }\n\n // Check authentication\n try {\n execSync(`npm whoami --registry ${registryUrl}`, { stdio: \"pipe\" });\n } catch {\n console.error(`Not authenticated with registry: ${registryUrl}`);\n console.error(`Run: npm adduser --registry ${registryUrl}`);\n process.exit(1);\n }\n\n // Forward remaining args to npm publish\n const forwardedArgs = getForwardedArgs();\n const cmd =\n `npm publish --registry ${registryUrl} ${forwardedArgs.join(\" \")}`.trim();\n\n if (args.debug) {\n console.log(\">>> command\", cmd);\n }\n\n console.log(`Publishing to ${registryUrl}...`);\n execSync(cmd, { stdio: \"inherit\", cwd: projectPath });\n\n process.exit(0);\n },\n});\n\nexport function getForwardedArgs(): string[] {\n const argv = process.argv;\n const publishIndex = argv.indexOf(\"publish\");\n if (publishIndex === -1) return [];\n\n const rawArgs = argv.slice(publishIndex + 1);\n const filtered: string[] = [];\n\n for (let i = 0; i < rawArgs.length; i++) {\n if (rawArgs[i] === \"--debug\") continue;\n if (rawArgs[i] === \"--registry\") {\n i++; // skip flag + value\n continue;\n }\n filtered.push(rawArgs[i]!);\n }\n\n return filtered;\n}\n","import { switchboardArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const switchboard = command({\n name: \"switchboard\",\n aliases: [\"reactor\"],\n description: `\nThe switchboard command starts a local Switchboard instance, which acts as the document\nprocessing engine for Powerhouse projects. It provides the infrastructure for document\nmodels, processors, and real-time updates.\n\nThis command:\n1. Starts a local switchboard server\n2. Loads document models and processors\n3. Provides an API for document operations\n4. Enables real-time document processing\n5. Can authenticate with remote services using your identity from 'ph login'`,\n args: switchboardArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { basePath, dbPath, migrate, migrateStatus } = args;\n if (basePath) {\n process.env.BASE_PATH = basePath;\n }\n\n if (migrate || migrateStatus) {\n const { runSwitchboardMigrations } =\n await import(\"../services/switchboard-migrate.js\");\n await runSwitchboardMigrations({\n dbPath,\n statusOnly: migrateStatus,\n });\n process.exit(0);\n }\n\n const { startSwitchboard } = await import(\"../services/switchboard.js\");\n const { defaultDriveUrl, renown } = await startSwitchboard(args);\n console.log(\" ➜ Switchboard:\", defaultDriveUrl);\n if (renown) {\n console.log(\" ➜ Identity:\", renown.did);\n }\n },\n});\n","import {\n getPowerhouseProjectInfo,\n getPowerhouseProjectUninstallCommand,\n makeDependenciesWithVersions,\n uninstallArgs,\n} from \"@powerhousedao/shared/clis\";\nimport { execSync } from \"child_process\";\nimport { command } from \"cmd-ts\";\nimport { AGENTS } from \"package-manager-detector\";\nimport { removeStylesImports, updateConfigFile } from \"../utils.js\";\n\nexport const uninstall = command({\n name: \"uninstall\",\n aliases: [\"remove\"],\n description: `\nThe uninstall command removes Powerhouse dependencies from your project. It handles the\nremoval of packages, updates configuration files, and ensures proper cleanup.\n\nThis command:\n1. Uninstalls specified Powerhouse dependencies using your package manager\n2. Updates powerhouse.config.json to remove the dependencies\n3. Supports various uninstallation options and configurations\n4. Works with ${AGENTS.join(\", \")} package managers\n`,\n args: uninstallArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n const {\n projectPath,\n localProjectPath,\n globalProjectPath,\n packageManager,\n isGlobal,\n } = await getPowerhouseProjectInfo(args);\n\n if (!projectPath) {\n throw new Error(`Could not find project path to uninstall from`);\n }\n\n const dependenciesWithVersions = await makeDependenciesWithVersions(\n args.dependencies,\n );\n\n if (args.debug) {\n console.log(\">>> parsedDependencies\", dependenciesWithVersions);\n }\n\n if (args.debug) {\n console.log(\"\\n>>> projectInfo\", {\n localProjectPath,\n globalProjectPath,\n packageManager,\n isGlobal,\n });\n }\n\n try {\n console.log(\"Uninstalling dependencies 📦 ...\");\n const uninstallCommand =\n await getPowerhouseProjectUninstallCommand(packageManager);\n execSync(uninstallCommand, {\n stdio: \"inherit\",\n cwd: projectPath,\n });\n console.log(\"Dependency uninstalled successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to uninstall dependencies\");\n throw error;\n }\n\n try {\n console.log(\"⚙️ Updating powerhouse config file...\");\n updateConfigFile(dependenciesWithVersions, projectPath, \"uninstall\");\n console.log(\"Config file updated successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to update config file\");\n throw error;\n }\n\n try {\n console.log(\"⚙️ Updating styles.css file...\");\n removeStylesImports(dependenciesWithVersions, projectPath);\n console.log(\"Styles file updated successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to update styles file\");\n throw error;\n }\n\n process.exit(0);\n },\n});\n","import { vetraArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const vetra = command({\n name: \"vetra\",\n description: `\nThe vetra command sets up a Vetra development environment for working with Vetra projects.\nIt starts a Vetra Switchboard and optionally Connect Studio, enabling document collaboration \nand real-time processing with a \"Vetra\" drive or connection to remote drives.\n\nThis command:\n1. Starts a Vetra Switchboard with a \"Vetra\" drive for document storage\n2. Optionally connects to remote drives instead of creating a local drive\n3. Starts Connect Studio pointing to the Switchboard for user interaction (unless disabled)\n4. Enables real-time updates, collaboration, and code generation`,\n args: vetraArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { startVetra } = await import(\"../services/vetra.js\");\n await startVetra(args);\n },\n});\n","import { accessToken } from \"./access-token.js\";\nimport { build } from \"./build.js\";\nimport { connect } from \"./connect.js\";\nimport { generate } from \"./generate.js\";\nimport { inspect } from \"./inspect.js\";\nimport { install } from \"./install.js\";\nimport { list } from \"./list.js\";\nimport { login } from \"./login.js\";\nimport { logout } from \"./logout.js\";\nimport { migrate } from \"./migrate.js\";\nimport { publish } from \"./publish.js\";\nimport { switchboard } from \"./switchboard.js\";\nimport { uninstall } from \"./uninstall.js\";\nimport { vetra } from \"./vetra.js\";\n\nexport const phCliCommands = {\n generate,\n vetra,\n connect,\n build,\n publish,\n \"access-token\": accessToken,\n inspect,\n list,\n migrate,\n switchboard,\n login,\n logout,\n install,\n uninstall,\n} as const;\n","import { subcommands } from \"cmd-ts\";\nimport { getVersion } from \"../get-version.js\";\nimport { PH_CLI_DESCRIPTION } from \"../utils/constants.js\";\nimport { phCliCommands } from \"./ph-cli-commands.js\";\n\nconst version = getVersion();\nexport const phCli = subcommands({\n name: \"ph-cli\",\n description: PH_CLI_DESCRIPTION,\n version,\n cmds: phCliCommands,\n});\n","#!/usr/bin/env node\nimport { assertNodeVersion } from \"@powerhousedao/shared/clis\";\nimport { run } from \"cmd-ts\";\nimport { phCliHelp } from \"./commands/ph-cli-help.js\";\nimport { phCli } from \"./commands/ph-cli.js\";\n\nasync function main() {\n assertNodeVersion();\n const args = process.argv.slice(2);\n const hasNoArgs = args.length === 0;\n const isHelp = args.some((arg) => arg === \"--help\" || arg === \"-h\");\n const isTopLevelHelp = isHelp && args.length === 1;\n const showTopLevelHelp = hasNoArgs || isTopLevelHelp;\n const cli = showTopLevelHelp ? phCliHelp : phCli;\n const [command, ...restArgs] = args;\n if (\n command === \"connect\" &&\n ![\"studio\", \"build\", \"preview\"].includes(args[1]) &&\n !isHelp\n ) {\n const argsWithDefaultConnectSubCommand = [\"connect\", \"studio\", ...restArgs];\n await run(cli, argsWithDefaultConnectSubCommand);\n } else {\n await run(cli, args);\n }\n}\n\nawait main().catch((error) => {\n const isDebug = process.argv.slice(2).includes(\"--debug\");\n if (isDebug) {\n throw error;\n }\n if (error instanceof Error) {\n console.error(error.message);\n process.exit(1);\n } else {\n throw error;\n }\n});\n"],"mappings":";;;;;;;;;;;AAAA,SAAgB,aAAa;AAC3B,QACE,QAAQ,IAAI,qBACZ,QAAQ,IAAI,uBACZ;;;;ACJJ,MAAa,qBACX;ACKF,MAAa,YAAY,YAAY;CACnC,MAAM;CACN,aAAa;CACb,SAJc,YAAY;CAK1B,MAAM;CACP,CAAC;;;ACJF,MAAa,cAAc,QAAQ;CACjC,MAAM;CACN,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Cb,MAAM;CACN,SAAS,OAAO,SAAS;AACvB,MAAI,KAAK,MACP,SAAQ,IAAI,KAAK;EAGnB,MAAM,EAAE,cAAc,MAAM,OAAO;EACnC,MAAM,SAAS,MAAM,WAAW;EAChC,MAAM,MAAM,OAAO;EACnB,MAAM,OAAO,OAAO;AAGpB,MAAI,CAAC,QAAQ,CAAC,KAAK,WACjB,OAAM,IAAI,MACR,wIACD;EAGH,MAAM,UAAU,KAAK;EAGrB,IAAI,YAAY;AAChB,MAAI,KAAK,OAAQ,aAAY,YAAY,KAAK,OAAO;EAGrD,MAAM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M;EAER"}
1
+ {"version":3,"file":"cli.mjs","names":["version","build","getConfig","getConfig"],"sources":["../src/get-version.ts","../src/utils/constants.ts","../src/commands/ph-cli-help.ts","../src/commands/access-token.ts","../src/commands/build.ts","../src/commands/connect.ts","../src/commands/generate.ts","../src/commands/inspect.ts","../src/commands/install.ts","../src/commands/list.ts","../src/commands/login.ts","../src/commands/logout.ts","../src/commands/migrate.ts","../src/commands/publish.ts","../src/commands/switchboard.ts","../src/commands/uninstall.ts","../src/commands/vetra.ts","../src/commands/ph-cli-commands.ts","../src/commands/ph-cli.ts","../src/cli.ts"],"sourcesContent":["export function getVersion() {\n return (\n process.env.WORKSPACE_VERSION ||\n process.env.npm_package_version ||\n \"unknown\"\n );\n}\n","export const PH_CLI_DESCRIPTION =\n \"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.\" as const;\n","import { phCliHelpCommands } from \"@powerhousedao/shared/clis\";\nimport { subcommands } from \"cmd-ts\";\nimport { getVersion } from \"../get-version.js\";\nimport { PH_CLI_DESCRIPTION } from \"../utils/constants.js\";\n\nconst version = getVersion();\nexport const phCliHelp = subcommands({\n name: \"ph-cli\",\n description: PH_CLI_DESCRIPTION,\n version,\n cmds: phCliHelpCommands,\n});\n","import {\n accessTokenArgs,\n DEFAULT_EXPIRY_SECONDS,\n SECONDS_IN_DAY,\n} from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const accessToken = command({\n name: \"access-token\",\n description: `\nThe access-token command generates a bearer token for API authentication. This token\ncan be used to authenticate requests to Powerhouse APIs like reactor-api (Switchboard).\n\nThis command:\n1. Uses your CLI's cryptographic identity (DID) to sign a verifiable credential\n2. Creates a JWT bearer token with configurable expiration\n3. Outputs the token to stdout (info to stderr) for easy piping\n\nPrerequisites:\n You must have a cryptographic identity. Run 'ph login' first to:\n - Generate a keypair (stored in .ph/.keypair.json)\n - Optionally link your Ethereum address (stored in .ph/.renown.json)\n\nToken Details:\n The generated token is a JWT (JSON Web Token) containing:\n - Issuer (iss): Your CLI's DID (did:key:...)\n - Subject (sub): Your CLI's DID\n - Credential Subject: Chain ID, network ID, and address (if authenticated)\n - Expiration (exp): Based on --expiry option\n - Audience (aud): If --audience is specified\n\nOutput:\n- Token information (DID, address, expiry) is printed to stderr\n- The token itself is printed to stdout for easy piping/copying\n\nThis allows you to use the command in scripts:\n TOKEN=$(ph access-token)\n curl -H \"Authorization: Bearer $TOKEN\" http://localhost:4001/graphql\n\nUsage with APIs:\n Generate token and use with curl\n TOKEN=$(ph access-token --expiry 1d)\n curl -X POST http://localhost:4001/graphql \\\\\n -H \"Content-Type: application/json\" \\\\\n -H \"Authorization: Bearer $TOKEN\" \\\\\n -d '{\"query\": \"{ drives { id name } }\"}'\n\n Export as environment variable\n export PH_ACCESS_TOKEN=$(ph access-token)\n\nNotes:\n - Tokens are self-signed using your CLI's private key\n - No network request is made; tokens are generated locally\n - The recipient API must trust your CLI's DID to accept the token\n - For reactor-api, ensure AUTH_ENABLED=true to require authentication\n`,\n args: accessTokenArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n const { getRenown } = await import(\"../services/auth.js\");\n const renown = await getRenown();\n const did = renown.did;\n const user = renown.user;\n\n // Require Renown authentication - user must have done 'ph login'\n if (!user || !user.credential) {\n throw new Error(\n \"Not authenticated. Run 'ph login' first to authenticate with Renown. A Renown credential is required to generate valid bearer tokens.\",\n );\n }\n\n const address = user.address;\n\n // Parse expiry\n let expiresIn = DEFAULT_EXPIRY_SECONDS;\n if (args.expiry) expiresIn = parseExpiry(args.expiry);\n\n // Generate the bearer token;\n const token = await renown.getBearerToken(\n {\n expiresIn,\n aud: args.audience,\n },\n true,\n );\n\n // Calculate human-readable expiry\n const expiryDays = Math.floor(expiresIn / SECONDS_IN_DAY);\n const expiryHours = Math.floor((expiresIn % SECONDS_IN_DAY) / 3600);\n let expiryStr: string;\n if (expiryDays > 0) {\n expiryStr =\n expiryHours > 0\n ? `${expiryDays} day${expiryDays > 1 ? \"s\" : \"\"} and ${expiryHours} hour${expiryHours > 1 ? \"s\" : \"\"}`\n : `${expiryDays} day${expiryDays > 1 ? \"s\" : \"\"}`;\n } else if (expiryHours > 0) {\n expiryStr = `${expiryHours} hour${expiryHours > 1 ? \"s\" : \"\"}`;\n } else {\n expiryStr = `${expiresIn} seconds`;\n }\n\n // Output token info to stderr, token itself to stdout for piping\n console.error(`CLI DID: ${did}`);\n console.error(`ETH Address: ${address}`);\n console.error(`Token expires in: ${expiryStr}`);\n console.error(\"\");\n\n // Output just the token to stdout (for easy piping/copying)\n console.log(token);\n process.exit(0);\n },\n});\n\n/**\n * Parse expiry string to seconds\n * Supports formats: \"7d\" (days), \"24h\" (hours), \"3600\" (seconds), \"3600s\" (seconds)\n */\nfunction parseExpiry(expiry: string): number {\n const trimmed = expiry.trim().toLowerCase();\n\n // Check for day format (e.g., \"7d\")\n if (trimmed.endsWith(\"d\")) {\n const days = parseInt(trimmed.slice(0, -1), 10);\n if (isNaN(days) || days <= 0) {\n throw new Error(\n `Invalid expiry format: ${expiry}. Days must be a positive number.`,\n );\n }\n return days * SECONDS_IN_DAY;\n }\n\n // Check for hour format (e.g., \"24h\")\n if (trimmed.endsWith(\"h\")) {\n const hours = parseInt(trimmed.slice(0, -1), 10);\n if (isNaN(hours) || hours <= 0) {\n throw new Error(\n `Invalid expiry format: ${expiry}. Hours must be a positive number.`,\n );\n }\n return hours * 60 * 60;\n }\n\n // Check for seconds format (e.g., \"3600s\" or just \"3600\")\n const numericValue = trimmed.endsWith(\"s\") ? trimmed.slice(0, -1) : trimmed;\n\n const seconds = parseInt(numericValue, 10);\n if (isNaN(seconds) || seconds <= 0) {\n throw new Error(\n `Invalid expiry format: ${expiry}. Expected a positive number or format like \"7d\", \"24h\", \"3600s\".`,\n );\n }\n\n return seconds;\n}\n","import { buildArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\nimport { runBuild } from \"../services/build.js\";\n\nexport const build = command({\n name: \"build\",\n args: buildArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n try {\n await runBuild(args);\n } catch (error) {\n console.error(error);\n process.exit(1);\n }\n },\n});\n","import {\n connectBuildArgs,\n connectPreviewArgs,\n connectStudioArgs,\n} from \"@powerhousedao/shared/clis\";\nimport { command, subcommands } from \"cmd-ts\";\nexport const studio = command({\n name: \"studio\",\n description: `The studio command starts the Connect Studio, a development environment for building\nand testing Powerhouse applications. It provides a visual interface for working with\nyour project.\n\nThis command:\n1. Starts a local Connect Studio server\n2. Provides a web interface for development\n3. Allows you to interact with your project components\n4. Supports various configuration options for customization\n`,\n args: connectStudioArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { runConnectStudio } = await import(\"../services/connect-studio.js\");\n await runConnectStudio(args);\n },\n});\n\nexport const build = command({\n name: \"build\",\n description: `The Connect build command creates a production build with the project's local and\nexternal packages included\n`,\n args: connectBuildArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n const { runConnectBuild } = await import(\"../services/connect-build.js\");\n await runConnectBuild(args);\n process.exit(0);\n },\n});\n\nexport const preview = command({\n name: \"preview\",\n description: `The Connect preview command previews a built Connect project.\nNOTE: You must run \\`ph connect build\\` first\n`,\n args: connectPreviewArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { runConnectPreview } =\n await import(\"../services/connect-preview.js\");\n await runConnectPreview(args);\n },\n});\n\nexport const connect = subcommands({\n name: \"connect\",\n description: `Powerhouse Connect commands. Use with \\`studio\\`, \\`build\\` or \\`preview\\`. Defaults to \\`studio\\` if not specified.`,\n cmds: {\n studio,\n build,\n preview,\n },\n});\n","import { generateArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const generate = command({\n name: \"generate\",\n description: `\nThe generate command creates code from document models. It helps you build editors, \nprocessors, and other components based on your document model files.\n\nThis command:\n1. Reads document model definitions\n2. Generates code for specified components (editors, processors, etc.)\n3. Supports customization of output and generation options\n4. Can watch files for changes and regenerate code automatically\n`,\n args: generateArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { startGenerate } = await import(\"../services/generate.js\");\n await startGenerate(args);\n process.exit(0);\n },\n});\n","import { inspectArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const inspect = command({\n name: \"inspect\",\n description: `\nThe inspect command examines and provides detailed information about a Powerhouse package.\nIt helps you understand the structure, dependencies, and configuration of packages in\nyour project.\n\nThis command:\n1. Analyzes the specified package\n2. Retrieves detailed information about its structure and configuration\n3. Displays package metadata, dependencies, and other relevant information\n4. Helps troubleshoot package-related issues`,\n aliases: [\"is\"],\n args: inspectArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { startInspect } = await import(\"../services/inspect.js\");\n startInspect(args);\n process.exit(0);\n },\n});\n","import { DEFAULT_REGISTRY_URL } from \"@powerhousedao/config\";\nimport {\n getConfig,\n getPowerhouseProjectInfo,\n getPowerhouseProjectInstallCommand,\n installArgs,\n makeDependenciesWithVersions,\n} from \"@powerhousedao/shared/clis\";\nimport { execSync } from \"child_process\";\nimport { command } from \"cmd-ts\";\nimport { join } from \"path\";\nimport { updateConfigFile, updateStylesFile } from \"../utils.js\";\n\nexport const install = command({\n name: \"install\",\n aliases: [\"add\", \"i\"],\n description: `\nThe install command adds Powerhouse dependencies to your project. It installs packages\nfrom the Powerhouse registry by default and updates configuration files.\n\nThis command:\n1. Resolves the registry URL (--registry flag > powerhouse.config.json > PH_REGISTRY_URL env > default)\n2. Installs the package using your package manager with the resolved registry\n3. Updates powerhouse.config.json to include the new dependencies\n4. Updates style.css with CSS imports if applicable\n `,\n args: installArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n const {\n projectPath,\n localProjectPath,\n globalProjectPath,\n packageManager,\n isGlobal,\n } = await getPowerhouseProjectInfo(args);\n\n if (!projectPath) {\n throw new Error(`Could not find project path to install from.`);\n }\n\n // Resolve registry URL: flag > config > env > default\n const configPath = join(projectPath, \"powerhouse.config.json\");\n const config = getConfig(configPath);\n const registryUrl =\n args.registry ??\n config.packageRegistryUrl ??\n process.env.PH_REGISTRY_URL ??\n DEFAULT_REGISTRY_URL;\n\n if (args.debug) {\n console.log(\">>> registryUrl\", registryUrl);\n }\n\n const dependenciesWithVersions = await makeDependenciesWithVersions(\n args.dependencies,\n registryUrl,\n );\n\n if (args.debug) {\n console.log(\">>> parsedDependencies\", dependenciesWithVersions);\n }\n\n if (args.debug) {\n console.log(\"\\n>>> projectInfo\", {\n localProjectPath,\n globalProjectPath,\n packageManager,\n isGlobal,\n });\n }\n\n try {\n console.log(`installing dependencies 📦 from ${registryUrl}...`);\n const installCommand = getPowerhouseProjectInstallCommand(\n packageManager,\n [\"--registry\", registryUrl],\n );\n execSync(installCommand, {\n stdio: \"inherit\",\n cwd: projectPath,\n });\n console.log(\"Dependency installed successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to install dependencies\");\n throw error;\n }\n\n if (args.debug) {\n console.log(\"\\n>>> updateConfigFile arguments:\");\n console.log(\">>> dependencies\", args.dependencies);\n console.log(\">>> projectPath\", projectPath);\n }\n\n try {\n console.log(\"⚙️ Updating powerhouse config file...\");\n updateConfigFile(dependenciesWithVersions, projectPath, \"install\");\n console.log(\"Config file updated successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to update config file\");\n throw error;\n }\n\n try {\n console.log(\"⚙️ Updating styles.css file...\");\n updateStylesFile(dependenciesWithVersions, projectPath);\n console.log(\"Styles file updated successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to update styles file\");\n throw error;\n }\n\n process.exit(0);\n },\n});\n","import { getConfig } from \"@powerhousedao/config/node\";\nimport { getPowerhouseProjectInfo, listArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const list = command({\n name: \"list\",\n description: `\nThe list command displays information about installed Powerhouse packages in your project.\nIt reads the powerhouse.config.json file and shows the packages that are currently installed.\n\nThis command:\n1. Examines your project configuration\n2. Lists all installed Powerhouse packages\n3. Provides a clear overview of your project's dependencies\n4. Helps you manage and track your Powerhouse components\n`,\n aliases: [\"l\"],\n args: listArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n try {\n const projectInfo = await getPowerhouseProjectInfo();\n console.log(\"\\n>>> projectInfo\", projectInfo);\n\n const phConfig = getConfig(\n projectInfo.projectPath + \"/powerhouse.config.json\",\n );\n\n if (!phConfig.packages || phConfig.packages.length === 0) {\n console.log(\"No packages found in the project\");\n return;\n }\n\n console.log(\"Installed Packages:\\n\");\n phConfig.packages.forEach((pkg) => {\n console.log(pkg.packageName);\n });\n } catch (e) {\n console.log(\"No packages found in the project\");\n }\n process.exit(0);\n },\n});\n","import { loginArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const login = command({\n name: \"login\",\n description: `\nThe login command authenticates you with Renown using your Ethereum wallet. This enables\nthe CLI to act on behalf of your Ethereum identity for authenticated operations.\n\nThis command:\n1. Generates or loads a cryptographic identity (DID) for the CLI\n2. Opens your browser to the Renown authentication page\n3. You authorize the CLI's DID to act on behalf of your Ethereum address\n4. Stores the credentials locally in .ph/.renown.json\n `,\n args: loginArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n if (args.showDid) {\n await showDid();\n process.exit(0);\n }\n\n // Handle status check\n if (args.status) {\n await showStatus();\n process.exit(0);\n }\n\n // Handle logout\n if (args.logout) {\n await handleLogout();\n process.exit(0);\n }\n\n const renownUrl = args.renownUrl;\n const timeoutMs = args.timeout ? args.timeout * 1000 : DEFAULT_TIMEOUT_MS;\n\n console.debug(\"Initializing cryptographic identity...\");\n\n const { generateSessionId, getRenown } =\n await import(\"../services/auth.js\");\n const renown = await getRenown();\n\n // Check if already authenticated\n if (renown.user) {\n console.error(\n `Already authenticated as ${renown.user.address}\\nUse \"ph logout\" to sign out first.`,\n );\n process.exit(1);\n }\n\n // Get the CLI's DID from Renown\n console.log(`CLI DID: ${renown.did}`);\n\n // Generate session ID\n const sessionId = generateSessionId();\n\n // Build the login URL with connect DID\n const loginUrl = new URL(`${renownUrl}/console`);\n loginUrl.searchParams.set(\"session\", sessionId);\n loginUrl.searchParams.set(\"connect\", renown.did);\n loginUrl.searchParams.set(\"app\", renown.did);\n\n console.log(\"Opening browser for authentication...\");\n console.log(`Session ID: ${sessionId.slice(0, 8)}...`);\n console.log();\n\n // Open browser\n await openBrowser(loginUrl.toString());\n\n console.log(\"Waiting for authentication in browser\");\n console.log(`(timeout in ${timeoutMs / 1000} seconds)`);\n console.log();\n console.log(\n \"Please connect your wallet and authorize this CLI to act on your behalf.\",\n );\n console.log();\n process.stdout.write(\"Waiting\");\n\n // Poll for session completion\n const result = await pollSession(renownUrl, sessionId, timeoutMs);\n\n console.log(); // New line after dots\n\n if (!result) {\n throw new Error(\n \"\\nAuthentication timed out. \\nPlease try again with: ph login\",\n );\n }\n\n const user = await renown.login(result.did);\n\n console.log();\n console.log(\"Successfully authenticated!\");\n console.log(` ETH Address: ${user.address}`);\n console.log(` User DID: ${user.did}`);\n console.log(` CLI DID: ${renown.did}`);\n console.log();\n console.log(\"The CLI can now act on behalf of your Ethereum identity.\");\n process.exit(0);\n },\n});\n\ninterface PendingSessionResponse {\n sessionId: string;\n status: \"pending\";\n}\n\ninterface ReadySessionResponse {\n sessionId: string;\n status: \"ready\";\n address: string;\n chainId: number;\n did: string;\n credentialId: string;\n userDocumentId: string;\n}\n\ntype SessionResponse = PendingSessionResponse | ReadySessionResponse;\n\nconst DEFAULT_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes\nconst POLL_INTERVAL_MS = 2000; // 2 seconds\n\n/**\n * Open a URL in the default browser\n */\nasync function openBrowser(url: string): Promise<void> {\n const { exec } = await import(\"node:child_process\");\n const { promisify } = await import(\"node:util\");\n const execAsync = promisify(exec);\n\n const platform = process.platform;\n\n try {\n if (platform === \"darwin\") {\n await execAsync(`open \"${url}\"`);\n } else if (platform === \"win32\") {\n await execAsync(`start \"\" \"${url}\"`);\n } else {\n // Linux and others\n await execAsync(`xdg-open \"${url}\"`);\n }\n } catch (error) {\n console.error(\"Failed to open browser automatically.\");\n console.log(`Please open this URL manually: ${url}`);\n }\n}\n\n/**\n * Poll the session endpoint until ready or timeout\n */\nasync function pollSession(\n renownUrl: string,\n sessionId: string,\n timeoutMs: number,\n): Promise<ReadySessionResponse | null> {\n const startTime = Date.now();\n const sessionUrl = `${renownUrl}/api/console/session/${sessionId}`;\n\n while (Date.now() - startTime < timeoutMs) {\n try {\n const response = await fetch(sessionUrl);\n\n if (!response.ok) {\n console.error(`Session check failed: ${response.status}`);\n await sleep(POLL_INTERVAL_MS);\n continue;\n }\n\n const data = (await response.json()) as SessionResponse;\n\n if (data.status === \"ready\") {\n return data;\n }\n\n // Still pending, wait and try again\n process.stdout.write(\".\");\n await sleep(POLL_INTERVAL_MS);\n } catch (error) {\n // Network error, wait and retry\n await sleep(POLL_INTERVAL_MS);\n }\n }\n\n return null; // Timeout reached\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Show current authentication status\n */\nasync function showStatus(): Promise<void> {\n const { getRenown } = await import(\"../services/auth.js\");\n const renown = await getRenown();\n const user = renown.user;\n if (!user || !user.credential) {\n console.log(\"Not authenticated with an Ethereum address.\");\n console.log('Run \"ph login\" to authenticate.');\n return;\n }\n\n const issuanceDate = new Date(user.credential.issuanceDate);\n console.log(\"Authenticated\");\n console.log(` ETH Address: ${user.address}`);\n console.log(` User DID: ${user.did}`);\n console.log(` Chain ID: ${user.chainId}`);\n console.log(` CLI DID: ${renown.did}`);\n console.log(` Authenticated at: ${issuanceDate.toLocaleString()}`);\n console.log(` Renown URL: ${renown.baseUrl}`);\n\n process.exit(0);\n}\n\n/**\n * Show just the CLI DID\n */\nasync function showDid(): Promise<void> {\n try {\n const { generateSessionId, getRenown } =\n await import(\"../services/auth.js\");\n const renown = await getRenown();\n console.log(renown.did);\n } catch (e) {\n console.error(\"Failed to get DID:\");\n throw e;\n }\n}\n\n/**\n * Logout and clear credentials\n */\nexport async function handleLogout() {\n const { getRenown } = await import(\"../services/auth.js\");\n const renown = await getRenown();\n if (!renown.user) {\n console.log(\"Not currently authenticated.\");\n return;\n }\n\n try {\n await renown.logout();\n console.log(\"Successfully logged out.\");\n } catch (error) {\n console.error(\"Failed to clear credentials.\");\n console.debug(error);\n }\n}\n","import { command } from \"cmd-ts\";\nimport { handleLogout } from \"./login.js\";\n\nexport const logout = command({\n name: \"logout\",\n description: `\nThe logout command removes an existing session created with 'ph login'`,\n args: {},\n handler: async () => {\n await handleLogout();\n process.exit(0);\n },\n});\n","import { migrateArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const migrate = command({\n name: \"migrate\",\n args: migrateArgs,\n description: \"Run migrations\",\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { startMigrate } = await import(\"../services/migrate.js\");\n await startMigrate(args);\n process.exit(0);\n },\n});\n","import { DEFAULT_REGISTRY_URL } from \"@powerhousedao/config\";\nimport { getConfig } from \"@powerhousedao/config/node\";\nimport {\n getPowerhouseProjectInfo,\n publishArgs,\n} from \"@powerhousedao/shared/clis\";\nimport { execSync } from \"child_process\";\nimport { command } from \"cmd-ts\";\nimport { join } from \"path\";\n\nexport const publish = command({\n name: \"publish\",\n description: `\nPublish a package to the Powerhouse registry. This is a thin wrapper around npm publish\nthat automatically sets the registry URL.\n\nThis command:\n1. Resolves the registry URL (--registry flag > powerhouse.config.json > PH_REGISTRY_URL env > default)\n2. Checks authentication with the registry via npm whoami\n3. Forwards all additional arguments to npm publish\n `,\n args: publishArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n const { projectPath } = await getPowerhouseProjectInfo();\n\n if (!projectPath) {\n throw new Error(\"Could not find project path.\");\n }\n\n // Resolve registry URL: flag > config > env > default\n const configPath = join(projectPath, \"powerhouse.config.json\");\n const config = getConfig(configPath);\n const registryUrl =\n args.registry ??\n process.env.PH_REGISTRY_URL ??\n config.packageRegistryUrl ??\n DEFAULT_REGISTRY_URL;\n\n if (args.debug) {\n console.log(\">>> registryUrl\", registryUrl);\n }\n\n // Check authentication\n try {\n execSync(`npm whoami --registry ${registryUrl}`, { stdio: \"pipe\" });\n } catch {\n console.error(`Not authenticated with registry: ${registryUrl}`);\n console.error(`Run: npm adduser --registry ${registryUrl}`);\n process.exit(1);\n }\n\n // Forward remaining args to npm publish\n const forwardedArgs = args.forwardedArgs;\n const cmd =\n `npm publish --registry ${registryUrl} ${forwardedArgs.join(\" \")}`.trim();\n\n if (args.debug) {\n console.log(\">>> command\", cmd);\n }\n\n console.log(`Publishing to ${registryUrl}...`);\n execSync(cmd, { stdio: \"inherit\", cwd: projectPath });\n\n process.exit(0);\n },\n});\n","import { switchboardArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const switchboard = command({\n name: \"switchboard\",\n aliases: [\"reactor\"],\n description: `\nThe switchboard command starts a local Switchboard instance, which acts as the document\nprocessing engine for Powerhouse projects. It provides the infrastructure for document\nmodels, processors, and real-time updates.\n\nThis command:\n1. Starts a local switchboard server\n2. Loads document models and processors\n3. Provides an API for document operations\n4. Enables real-time document processing\n5. Can authenticate with remote services using your identity from 'ph login'`,\n args: switchboardArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { basePath, dbPath, migrate, migrateStatus } = args;\n if (basePath) {\n process.env.BASE_PATH = basePath;\n }\n\n if (migrate || migrateStatus) {\n const { runSwitchboardMigrations } =\n await import(\"../services/switchboard-migrate.js\");\n await runSwitchboardMigrations({\n dbPath,\n statusOnly: migrateStatus,\n });\n process.exit(0);\n }\n\n const { startSwitchboard } = await import(\"../services/switchboard.js\");\n const { defaultDriveUrl, renown } = await startSwitchboard(args);\n console.log(\" ➜ Switchboard:\", defaultDriveUrl);\n if (renown) {\n console.log(\" ➜ Identity:\", renown.did);\n }\n },\n});\n","import {\n getPowerhouseProjectInfo,\n getPowerhouseProjectUninstallCommand,\n makeDependenciesWithVersions,\n uninstallArgs,\n} from \"@powerhousedao/shared/clis\";\nimport { execSync } from \"child_process\";\nimport { command } from \"cmd-ts\";\nimport { AGENTS } from \"package-manager-detector\";\nimport { removeStylesImports, updateConfigFile } from \"../utils.js\";\n\nexport const uninstall = command({\n name: \"uninstall\",\n aliases: [\"remove\"],\n description: `\nThe uninstall command removes Powerhouse dependencies from your project. It handles the\nremoval of packages, updates configuration files, and ensures proper cleanup.\n\nThis command:\n1. Uninstalls specified Powerhouse dependencies using your package manager\n2. Updates powerhouse.config.json to remove the dependencies\n3. Supports various uninstallation options and configurations\n4. Works with ${AGENTS.join(\", \")} package managers\n`,\n args: uninstallArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n\n const {\n projectPath,\n localProjectPath,\n globalProjectPath,\n packageManager,\n isGlobal,\n } = await getPowerhouseProjectInfo(args);\n\n if (!projectPath) {\n throw new Error(`Could not find project path to uninstall from`);\n }\n\n const dependenciesWithVersions = await makeDependenciesWithVersions(\n args.dependencies,\n );\n\n if (args.debug) {\n console.log(\">>> parsedDependencies\", dependenciesWithVersions);\n }\n\n if (args.debug) {\n console.log(\"\\n>>> projectInfo\", {\n localProjectPath,\n globalProjectPath,\n packageManager,\n isGlobal,\n });\n }\n\n try {\n console.log(\"Uninstalling dependencies 📦 ...\");\n const uninstallCommand =\n await getPowerhouseProjectUninstallCommand(packageManager);\n execSync(uninstallCommand, {\n stdio: \"inherit\",\n cwd: projectPath,\n });\n console.log(\"Dependency uninstalled successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to uninstall dependencies\");\n throw error;\n }\n\n try {\n console.log(\"⚙️ Updating powerhouse config file...\");\n updateConfigFile(dependenciesWithVersions, projectPath, \"uninstall\");\n console.log(\"Config file updated successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to update config file\");\n throw error;\n }\n\n try {\n console.log(\"⚙️ Updating styles.css file...\");\n removeStylesImports(dependenciesWithVersions, projectPath);\n console.log(\"Styles file updated successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to update styles file\");\n throw error;\n }\n\n process.exit(0);\n },\n});\n","import { vetraArgs } from \"@powerhousedao/shared/clis\";\nimport { command } from \"cmd-ts\";\n\nexport const vetra = command({\n name: \"vetra\",\n description: `\nThe vetra command sets up a Vetra development environment for working with Vetra projects.\nIt starts a Vetra Switchboard and optionally Connect Studio, enabling document collaboration \nand real-time processing with a \"Vetra\" drive or connection to remote drives.\n\nThis command:\n1. Starts a Vetra Switchboard with a \"Vetra\" drive for document storage\n2. Optionally connects to remote drives instead of creating a local drive\n3. Starts Connect Studio pointing to the Switchboard for user interaction (unless disabled)\n4. Enables real-time updates, collaboration, and code generation`,\n args: vetraArgs,\n handler: async (args) => {\n if (args.debug) {\n console.log(args);\n }\n const { startVetra } = await import(\"../services/vetra.js\");\n await startVetra(args);\n },\n});\n","import { accessToken } from \"./access-token.js\";\nimport { build } from \"./build.js\";\nimport { connect } from \"./connect.js\";\nimport { generate } from \"./generate.js\";\nimport { inspect } from \"./inspect.js\";\nimport { install } from \"./install.js\";\nimport { list } from \"./list.js\";\nimport { login } from \"./login.js\";\nimport { logout } from \"./logout.js\";\nimport { migrate } from \"./migrate.js\";\nimport { publish } from \"./publish.js\";\nimport { switchboard } from \"./switchboard.js\";\nimport { uninstall } from \"./uninstall.js\";\nimport { vetra } from \"./vetra.js\";\n\nexport const phCliCommands = {\n generate,\n vetra,\n connect,\n build,\n publish,\n \"access-token\": accessToken,\n inspect,\n list,\n migrate,\n switchboard,\n login,\n logout,\n install,\n uninstall,\n} as const;\n","import { subcommands } from \"cmd-ts\";\nimport { getVersion } from \"../get-version.js\";\nimport { PH_CLI_DESCRIPTION } from \"../utils/constants.js\";\nimport { phCliCommands } from \"./ph-cli-commands.js\";\n\nconst version = getVersion();\nexport const phCli = subcommands({\n name: \"ph-cli\",\n description: PH_CLI_DESCRIPTION,\n version,\n cmds: phCliCommands,\n});\n","#!/usr/bin/env node\nimport { assertNodeVersion } from \"@powerhousedao/shared/clis\";\nimport { run } from \"cmd-ts\";\nimport { phCliHelp } from \"./commands/ph-cli-help.js\";\nimport { phCli } from \"./commands/ph-cli.js\";\n\nasync function main() {\n assertNodeVersion();\n const args = process.argv.slice(2);\n const hasNoArgs = args.length === 0;\n const isHelp = args.some((arg) => arg === \"--help\" || arg === \"-h\");\n const isTopLevelHelp = isHelp && args.length === 1;\n const showTopLevelHelp = hasNoArgs || isTopLevelHelp;\n const cli = showTopLevelHelp ? phCliHelp : phCli;\n const [command, ...restArgs] = args;\n if (\n command === \"connect\" &&\n ![\"studio\", \"build\", \"preview\"].includes(args[1]) &&\n !isHelp\n ) {\n const argsWithDefaultConnectSubCommand = [\"connect\", \"studio\", ...restArgs];\n await run(cli, argsWithDefaultConnectSubCommand);\n } else {\n await run(cli, args);\n }\n}\n\nawait main().catch((error) => {\n const isDebug = process.argv.slice(2).includes(\"--debug\");\n if (isDebug) {\n throw error;\n }\n if (error instanceof Error) {\n console.error(error.message);\n process.exit(1);\n } else {\n throw error;\n }\n});\n"],"mappings":";;;;;;;;;;;AAAA,SAAgB,aAAa;AAC3B,QACE,QAAQ,IAAI,qBACZ,QAAQ,IAAI,uBACZ;;;;ACJJ,MAAa,qBACX;ACKF,MAAa,YAAY,YAAY;CACnC,MAAM;CACN,aAAa;CACb,SAJc,YAAY;CAK1B,MAAM;CACP,CAAC;;;ACJF,MAAa,cAAc,QAAQ;CACjC,MAAM;CACN,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Cb,MAAM;CACN,SAAS,OAAO,SAAS;AACvB,MAAI,KAAK,MACP,SAAQ,IAAI,KAAK;EAGnB,MAAM,EAAE,cAAc,MAAM,OAAO;EACnC,MAAM,SAAS,MAAM,WAAW;EAChC,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AAQ;AAC5B,UAAQ,KAAK,EAAE;OAEf,OAAM;EAER"}
@@ -0,0 +1,2 @@
1
+ import { t as startGenerate } from "./generate-howgVbAT.mjs";
2
+ export { startGenerate };
@@ -1,5 +1,5 @@
1
- import { getConfig } from "@powerhousedao/config/node";
2
1
  import path from "path";
2
+ import { getConfig } from "@powerhousedao/config/node";
3
3
  import { generate, generateDBSchema, generateDriveEditor, generateEditor, generateFromFile, generateImportScript, generateProcessor, generateSubgraph } from "@powerhousedao/codegen";
4
4
  //#region src/services/generate.ts
5
5
  async function startGenerate(options) {
@@ -66,4 +66,4 @@ async function startGenerate(options) {
66
66
  //#endregion
67
67
  export { startGenerate as t };
68
68
 
69
- //# sourceMappingURL=generate-BfeI7CLg.mjs.map
69
+ //# sourceMappingURL=generate-howgVbAT.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate-BfeI7CLg.mjs","names":["generateCode"],"sources":["../src/services/generate.ts"],"sourcesContent":["import {\n generate as generateCode,\n generateDBSchema,\n generateDriveEditor,\n generateEditor,\n generateFromFile,\n generateImportScript,\n generateProcessor,\n generateSubgraph,\n} from \"@powerhousedao/codegen\";\nimport { getConfig } from \"@powerhousedao/config/node\";\nimport path from \"path\";\nimport type { GenerateArgs } from \"../types.js\";\n\nexport async function startGenerate(options: GenerateArgs) {\n const config = getConfig();\n const { skipFormat } = config;\n const {\n documentModelFilePositional,\n documentModelFileOption,\n editorName,\n editorId,\n documentType,\n // [DEPRECATED] - should be removed asap\n documentTypes,\n editorDirName,\n driveEditorName,\n driveEditorId,\n driveEditorDirName,\n allowedDocumentTypes,\n disableDragAndDrop,\n processorName,\n processorType,\n processorApps,\n importScriptName,\n migrationFile,\n schemaFile,\n verbose,\n force,\n useVersioning: useVersioningFlag,\n useHygen,\n subgraphName,\n migrateLegacy,\n } = options;\n\n const documentModelFile =\n documentModelFilePositional ?? documentModelFileOption;\n\n const useVersioning = useVersioningFlag || migrateLegacy;\n const useTsMorph = useVersioning || !useHygen;\n const isDragAndDropEnabled = disableDragAndDrop !== true;\n const specifiedPackageName = undefined;\n const filePath = Array.isArray(documentModelFile)\n ? documentModelFile.join(\" \")\n : documentModelFile;\n\n const documentTypeFromDocumentTypes = documentTypes?.split(\",\")[0];\n if (documentTypes) {\n console.warn(\n `[WARNING] --document-types is deprecated. Generated editor code is not set up to use multiple document types. Using the first document type in the list you specified (${documentTypeFromDocumentTypes})`,\n );\n }\n const documentTypeToUse = documentType ?? documentTypeFromDocumentTypes;\n\n if (editorName !== undefined) {\n if (!documentTypeToUse) {\n throw new Error(\n \"Please specify a document type for the generated editor.\",\n );\n }\n await generateEditor({\n editorName,\n editorId,\n editorDirName,\n documentTypes: [documentTypeToUse],\n useTsMorph,\n skipFormat,\n specifiedPackageName,\n });\n } else if (driveEditorName !== undefined) {\n await generateDriveEditor({\n driveEditorName,\n driveEditorId,\n driveEditorDirName,\n allowedDocumentTypes,\n isDragAndDropEnabled,\n useTsMorph,\n skipFormat,\n specifiedPackageName,\n });\n } else if (processorName !== undefined) {\n await generateProcessor({\n processorName,\n processorType,\n skipFormat,\n useTsMorph,\n processorApps,\n documentTypes: [documentTypeToUse].filter((t) => t !== undefined),\n });\n } else if (subgraphName !== undefined) {\n await generateSubgraph(subgraphName, filePath || null, config, {\n verbose,\n force,\n });\n } else if (importScriptName !== undefined) {\n await generateImportScript(importScriptName, config);\n } else if (migrationFile !== undefined) {\n await generateDBSchema({\n migrationFile: path.join(process.cwd(), migrationFile),\n schemaFile: schemaFile ? path.join(process.cwd(), schemaFile) : undefined,\n });\n } else if (filePath !== undefined) {\n await generateFromFile({\n path: filePath,\n config,\n useTsMorph,\n options,\n useVersioning,\n migrateLegacy,\n });\n } else {\n await generateCode(config, useTsMorph, useVersioning, migrateLegacy);\n }\n}\n"],"mappings":";;;;AAcA,eAAsB,cAAc,SAAuB;CACzD,MAAM,SAAS,WAAW;CAC1B,MAAM,EAAE,eAAe;CACvB,MAAM,EACJ,6BACA,yBACA,YACA,UACA,cAEA,eACA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A;EACA;EACD,CAAC;KAEF,OAAMA,SAAa,QAAQ,YAAY,eAAe,cAAc"}
1
+ {"version":3,"file":"generate-howgVbAT.mjs","names":["generateCode"],"sources":["../src/services/generate.ts"],"sourcesContent":["import {\n generate as generateCode,\n generateDBSchema,\n generateDriveEditor,\n generateEditor,\n generateFromFile,\n generateImportScript,\n generateProcessor,\n generateSubgraph,\n} from \"@powerhousedao/codegen\";\nimport { getConfig } from \"@powerhousedao/config/node\";\nimport path from \"path\";\nimport type { GenerateArgs } from \"../types.js\";\n\nexport async function startGenerate(options: GenerateArgs) {\n const config = getConfig();\n const { skipFormat } = config;\n const {\n documentModelFilePositional,\n documentModelFileOption,\n editorName,\n editorId,\n documentType,\n // [DEPRECATED] - should be removed asap\n documentTypes,\n editorDirName,\n driveEditorName,\n driveEditorId,\n driveEditorDirName,\n allowedDocumentTypes,\n disableDragAndDrop,\n processorName,\n processorType,\n processorApps,\n importScriptName,\n migrationFile,\n schemaFile,\n verbose,\n force,\n useVersioning: useVersioningFlag,\n useHygen,\n subgraphName,\n migrateLegacy,\n } = options;\n\n const documentModelFile =\n documentModelFilePositional ?? documentModelFileOption;\n\n const useVersioning = useVersioningFlag || migrateLegacy;\n const useTsMorph = useVersioning || !useHygen;\n const isDragAndDropEnabled = disableDragAndDrop !== true;\n const specifiedPackageName = undefined;\n const filePath = Array.isArray(documentModelFile)\n ? documentModelFile.join(\" \")\n : documentModelFile;\n\n const documentTypeFromDocumentTypes = documentTypes?.split(\",\")[0];\n if (documentTypes) {\n console.warn(\n `[WARNING] --document-types is deprecated. Generated editor code is not set up to use multiple document types. Using the first document type in the list you specified (${documentTypeFromDocumentTypes})`,\n );\n }\n const documentTypeToUse = documentType ?? documentTypeFromDocumentTypes;\n\n if (editorName !== undefined) {\n if (!documentTypeToUse) {\n throw new Error(\n \"Please specify a document type for the generated editor.\",\n );\n }\n await generateEditor({\n editorName,\n editorId,\n editorDirName,\n documentTypes: [documentTypeToUse],\n useTsMorph,\n skipFormat,\n specifiedPackageName,\n });\n } else if (driveEditorName !== undefined) {\n await generateDriveEditor({\n driveEditorName,\n driveEditorId,\n driveEditorDirName,\n allowedDocumentTypes,\n isDragAndDropEnabled,\n useTsMorph,\n skipFormat,\n specifiedPackageName,\n });\n } else if (processorName !== undefined) {\n await generateProcessor({\n processorName,\n processorType,\n skipFormat,\n useTsMorph,\n processorApps,\n documentTypes: [documentTypeToUse].filter((t) => t !== undefined),\n });\n } else if (subgraphName !== undefined) {\n await generateSubgraph(subgraphName, filePath || null, config, {\n verbose,\n force,\n });\n } else if (importScriptName !== undefined) {\n await generateImportScript(importScriptName, config);\n } else if (migrationFile !== undefined) {\n await generateDBSchema({\n migrationFile: path.join(process.cwd(), migrationFile),\n schemaFile: schemaFile ? path.join(process.cwd(), schemaFile) : undefined,\n });\n } else if (filePath !== undefined) {\n await generateFromFile({\n path: filePath,\n config,\n useTsMorph,\n options,\n useVersioning,\n migrateLegacy,\n });\n } else {\n await generateCode(config, useTsMorph, useVersioning, migrateLegacy);\n }\n}\n"],"mappings":";;;;AAcA,eAAsB,cAAc,SAAuB;CACzD,MAAM,SAAS,WAAW;CAC1B,MAAM,EAAE,eAAe;CACvB,MAAM,EACJ,6BACA,yBACA,YACA,UACA,cAEA,eACA,eACA,iBACA,eACA,oBACA,sBACA,oBACA,eACA,eACA,eACA,kBACA,eACA,YACA,SACA,OACA,eAAe,mBACf,UACA,cACA,kBACE;CAEJ,MAAM,oBACJ,+BAA+B;CAEjC,MAAM,gBAAgB,qBAAqB;CAC3C,MAAM,aAAa,iBAAiB,CAAC;CACrC,MAAM,uBAAuB,uBAAuB;CACpD,MAAM,uBAAuB,KAAA;CAC7B,MAAM,WAAW,MAAM,QAAQ,kBAAkB,GAC7C,kBAAkB,KAAK,IAAI,GAC3B;CAEJ,MAAM,gCAAgC,eAAe,MAAM,IAAI,CAAC;AAChE,KAAI,cACF,SAAQ,KACN,0KAA0K,8BAA8B,GACzM;CAEH,MAAM,oBAAoB,gBAAgB;AAE1C,KAAI,eAAe,KAAA,GAAW;AAC5B,MAAI,CAAC,kBACH,OAAM,IAAI,MACR,2DACD;AAEH,QAAM,eAAe;GACnB;GACA;GACA;GACA,eAAe,CAAC,kBAAkB;GAClC;GACA;GACA;GACD,CAAC;YACO,oBAAoB,KAAA,EAC7B,OAAM,oBAAoB;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;UACO,kBAAkB,KAAA,EAC3B,OAAM,kBAAkB;EACtB;EACA;EACA;EACA;EACA;EACA,eAAe,CAAC,kBAAkB,CAAC,QAAQ,MAAM,MAAM,KAAA,EAAU;EAClE,CAAC;UACO,iBAAiB,KAAA,EAC1B,OAAM,iBAAiB,cAAc,YAAY,MAAM,QAAQ;EAC7D;EACA;EACD,CAAC;UACO,qBAAqB,KAAA,EAC9B,OAAM,qBAAqB,kBAAkB,OAAO;UAC3C,kBAAkB,KAAA,EAC3B,OAAM,iBAAiB;EACrB,eAAe,KAAK,KAAK,QAAQ,KAAK,EAAE,cAAc;EACtD,YAAY,aAAa,KAAK,KAAK,QAAQ,KAAK,EAAE,WAAW,GAAG,KAAA;EACjE,CAAC;UACO,aAAa,KAAA,EACtB,OAAM,iBAAiB;EACrB,MAAM;EACN;EACA;EACA;EACA;EACA;EACD,CAAC;KAEF,OAAMA,SAAa,QAAQ,YAAY,eAAe,cAAc"}
@@ -1,4 +1,4 @@
1
- import { n as getProjectInfo } from "./utils-5r3OKhGj.mjs";
1
+ import { n as getProjectInfo } from "./utils-CjKhqXvK.mjs";
2
2
  import fs from "node:fs";
3
3
  //#region src/services/inspect.ts
4
4
  function startInspect(args) {
@@ -42,4 +42,4 @@ function startInspect(args) {
42
42
  //#endregion
43
43
  export { startInspect };
44
44
 
45
- //# sourceMappingURL=inspect-CeMFGkND.mjs.map
45
+ //# sourceMappingURL=inspect--c82Qog6.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"inspect-CeMFGkND.mjs","names":[],"sources":["../src/services/inspect.ts"],"sourcesContent":["import type { Manifest } from \"@powerhousedao/shared/document-model\";\nimport fs from \"node:fs\";\nimport type { InspectArgs } from \"../types.js\";\nimport { getProjectInfo } from \"../utils.js\";\nexport function startInspect(args: InspectArgs) {\n if (args.debug) {\n console.log(\">>> command arguments\", args);\n }\n\n const projectInfo = getProjectInfo(args.debug);\n const { packageName } = args;\n\n if (args.debug) {\n console.log(\"\\n>>> projectInfo\", projectInfo);\n }\n\n try {\n const loadManifest = (path: string) =>\n JSON.parse(fs.readFileSync(path, \"utf-8\")) as Manifest;\n const manifest = loadManifest(\n `${process.cwd()}/node_modules/${packageName}/dist/powerhouse.manifest.json`,\n );\n\n console.log(manifest.name);\n if (manifest.documentModels) {\n console.log(\"\\nDocument Models:\");\n manifest.documentModels.forEach((model) => {\n console.log(`- ${model.name} (${model.id})`);\n });\n }\n\n if (manifest.editors) {\n console.log(\"\\nEditors:\");\n manifest.editors.forEach((editor) => {\n console.log(`- ${editor.name} (${editor.id})`);\n });\n }\n\n if (manifest.processors) {\n console.log(\"\\nProcessors:\");\n manifest.processors.forEach((processor) => {\n console.log(`- ${processor.name} (${processor.id})`);\n });\n }\n\n if (manifest.subgraphs) {\n console.log(\"\\nSubgraphs:\");\n manifest.subgraphs.forEach((subgraph) => {\n console.log(`- ${subgraph.name} (${subgraph.id})`);\n });\n }\n } catch (e) {\n if (args.debug) {\n console.error(e);\n } else {\n console.log(\"No manifest found in the package\");\n }\n }\n}\n"],"mappings":";;;AAIA,SAAgB,aAAa,MAAmB;AAC9C,KAAI,KAAK,MACP,SAAQ,IAAI,yBAAyB,KAAK;CAG5C,MAAM,cAAc,eAAe,KAAK,MAAM;CAC9C,MAAM,EAAE,gBAAgB;AAExB,KAAI,KAAK,MACP,SAAQ,IAAI,qBAAqB,YAAY;AAG/C,KAAI;EACF,MAAM,gBAAgB,SACpB,KAAK,MAAM,GAAG,aAAa,MAAM,QAAQ,CAAC;EAC5C,MAAM,WAAW,aACf,GAAG,QAAQ,KAAK,CAAC,gBAAgB,YAAY,gCAC9C;AAED,UAAQ,IAAI,SAAS,KAAK;AAC1B,MAAI,SAAS,gBAAgB;AAC3B,WAAQ,IAAI,qBAAqB;AACjC,YAAS,eAAe,SAAS,UAAU;AACzC,YAAQ,IAAI,KAAK,MAAM,KAAK,IAAI,MAAM,GAAG,GAAG;KAC5C;;AAGJ,MAAI,SAAS,SAAS;AACpB,WAAQ,IAAI,aAAa;AACzB,YAAS,QAAQ,SAAS,WAAW;AACnC,YAAQ,IAAI,KAAK,OAAO,KAAK,IAAI,OAAO,GAAG,GAAG;KAC9C;;AAGJ,MAAI,SAAS,YAAY;AACvB,WAAQ,IAAI,gBAAgB;AAC5B,YAAS,WAAW,SAAS,cAAc;AACzC,YAAQ,IAAI,KAAK,UAAU,KAAK,IAAI,UAAU,GAAG,GAAG;KACpD;;AAGJ,MAAI,SAAS,WAAW;AACtB,WAAQ,IAAI,eAAe;AAC3B,YAAS,UAAU,SAAS,aAAa;AACvC,YAAQ,IAAI,KAAK,SAAS,KAAK,IAAI,SAAS,GAAG,GAAG;KAClD;;UAEG,GAAG;AACV,MAAI,KAAK,MACP,SAAQ,MAAM,EAAE;MAEhB,SAAQ,IAAI,mCAAmC"}
1
+ {"version":3,"file":"inspect--c82Qog6.mjs","names":[],"sources":["../src/services/inspect.ts"],"sourcesContent":["import type { Manifest } from \"@powerhousedao/shared/document-model\";\nimport fs from \"node:fs\";\nimport type { InspectArgs } from \"../types.js\";\nimport { getProjectInfo } from \"../utils.js\";\nexport function startInspect(args: InspectArgs) {\n if (args.debug) {\n console.log(\">>> command arguments\", args);\n }\n\n const projectInfo = getProjectInfo(args.debug);\n const { packageName } = args;\n\n if (args.debug) {\n console.log(\"\\n>>> projectInfo\", projectInfo);\n }\n\n try {\n const loadManifest = (path: string) =>\n JSON.parse(fs.readFileSync(path, \"utf-8\")) as Manifest;\n const manifest = loadManifest(\n `${process.cwd()}/node_modules/${packageName}/dist/powerhouse.manifest.json`,\n );\n\n console.log(manifest.name);\n if (manifest.documentModels) {\n console.log(\"\\nDocument Models:\");\n manifest.documentModels.forEach((model) => {\n console.log(`- ${model.name} (${model.id})`);\n });\n }\n\n if (manifest.editors) {\n console.log(\"\\nEditors:\");\n manifest.editors.forEach((editor) => {\n console.log(`- ${editor.name} (${editor.id})`);\n });\n }\n\n if (manifest.processors) {\n console.log(\"\\nProcessors:\");\n manifest.processors.forEach((processor) => {\n console.log(`- ${processor.name} (${processor.id})`);\n });\n }\n\n if (manifest.subgraphs) {\n console.log(\"\\nSubgraphs:\");\n manifest.subgraphs.forEach((subgraph) => {\n console.log(`- ${subgraph.name} (${subgraph.id})`);\n });\n }\n } catch (e) {\n if (args.debug) {\n console.error(e);\n } else {\n console.log(\"No manifest found in the package\");\n }\n }\n}\n"],"mappings":";;;AAIA,SAAgB,aAAa,MAAmB;AAC9C,KAAI,KAAK,MACP,SAAQ,IAAI,yBAAyB,KAAK;CAG5C,MAAM,cAAc,eAAe,KAAK,MAAM;CAC9C,MAAM,EAAE,gBAAgB;AAExB,KAAI,KAAK,MACP,SAAQ,IAAI,qBAAqB,YAAY;AAG/C,KAAI;EACF,MAAM,gBAAgB,SACpB,KAAK,MAAM,GAAG,aAAa,MAAM,QAAQ,CAAC;EAC5C,MAAM,WAAW,aACf,GAAG,QAAQ,KAAK,CAAC,gBAAgB,YAAY,gCAC9C;AAED,UAAQ,IAAI,SAAS,KAAK;AAC1B,MAAI,SAAS,gBAAgB;AAC3B,WAAQ,IAAI,qBAAqB;AACjC,YAAS,eAAe,SAAS,UAAU;AACzC,YAAQ,IAAI,KAAK,MAAM,KAAK,IAAI,MAAM,GAAG,GAAG;KAC5C;;AAGJ,MAAI,SAAS,SAAS;AACpB,WAAQ,IAAI,aAAa;AACzB,YAAS,QAAQ,SAAS,WAAW;AACnC,YAAQ,IAAI,KAAK,OAAO,KAAK,IAAI,OAAO,GAAG,GAAG;KAC9C;;AAGJ,MAAI,SAAS,YAAY;AACvB,WAAQ,IAAI,gBAAgB;AAC5B,YAAS,WAAW,SAAS,cAAc;AACzC,YAAQ,IAAI,KAAK,UAAU,KAAK,IAAI,UAAU,GAAG,GAAG;KACpD;;AAGJ,MAAI,SAAS,WAAW;AACtB,WAAQ,IAAI,eAAe;AAC3B,YAAS,UAAU,SAAS,aAAa;AACvC,YAAQ,IAAI,KAAK,SAAS,KAAK,IAAI,SAAS,GAAG,GAAG;KAClD;;UAEG,GAAG;AACV,MAAI,KAAK,MACP,SAAQ,MAAM,EAAE;MAEhB,SAAQ,IAAI,mCAAmC"}
@@ -1,6 +1,6 @@
1
- import { t as startGenerate } from "./generate-BfeI7CLg.mjs";
2
- import { existsSync, readdirSync } from "node:fs";
1
+ import { t as startGenerate } from "./generate-howgVbAT.mjs";
3
2
  import path from "path";
3
+ import { existsSync, readdirSync } from "node:fs";
4
4
  import { connectEntrypointTemplate, dockerfileTemplate, indexHtmlTemplate, indexTsTemplate, nginxConfTemplate, packageJsonExportsTemplate, packageJsonScriptsTemplate, switchboardEntrypointTemplate, syncAndPublishWorkflowTemplate, tsConfigTemplate } from "@powerhousedao/codegen/templates";
5
5
  import { mkdir, readdir, stat, writeFile } from "node:fs/promises";
6
6
  import { readPackage } from "read-pkg";
@@ -244,4 +244,4 @@ function getArrayLiteralExpressionElementsText(arrayLiteralExpression) {
244
244
  //#endregion
245
245
  export { startMigrate };
246
246
 
247
- //# sourceMappingURL=migrate-BxG1NdR_.mjs.map
247
+ //# sourceMappingURL=migrate-DErTQPCC.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"migrate-BxG1NdR_.mjs","names":[],"sources":["../src/services/migrate.ts"],"sourcesContent":["import {\n connectEntrypointTemplate,\n dockerfileTemplate,\n indexHtmlTemplate,\n indexTsTemplate,\n nginxConfTemplate,\n packageJsonExportsTemplate,\n packageJsonScriptsTemplate,\n switchboardEntrypointTemplate,\n syncAndPublishWorkflowTemplate,\n tsConfigTemplate,\n} from \"@powerhousedao/codegen/templates\";\nimport { existsSync, readdirSync } from \"node:fs\";\nimport { mkdir, readdir, stat, writeFile } from \"node:fs/promises\";\nimport path from \"path\";\nimport { readPackage } from \"read-pkg\";\nimport type {\n ArrayLiteralExpression,\n ObjectLiteralExpression,\n SourceFile,\n StringLiteral,\n} from \"ts-morph\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport { writePackage } from \"write-package\";\nimport type { GenerateArgs, MigrateArgs } from \"../types.js\";\nimport { startGenerate } from \"./generate.js\";\n\nexport async function startMigrate({ useHygen = false }: MigrateArgs) {\n await migratePackageJson();\n await migrateTsConfig();\n await migrateIndexHtml();\n await migrateCIFiles();\n await runGenerateOnAllDocumentModels(useHygen);\n await runGenerateOnAllEditors(useHygen);\n const project = new Project({\n tsConfigFilePath: path.resolve(\"tsconfig.json\"),\n compilerOptions: {\n verbatimModuleSyntax: false,\n },\n });\n deleteLegacyEditorDirIndexFiles(project);\n migrateEditorFiles(project);\n migrateRootIndex(project);\n removeZDotSchemaUsage(project);\n removeCreatorsUsage(project);\n removeUtilsDefaultExportUsage(project);\n fixImports(project);\n}\n\n/** Ensure that the project package.json has the correct scripts and exports. */\nasync function migratePackageJson() {\n const packageJson = await readPackage();\n const existingScripts = packageJson.scripts;\n const existingExports =\n !!packageJson.exports &&\n !Array.isArray(packageJson.exports) &&\n typeof packageJson.exports !== \"string\"\n ? packageJson.exports\n : {};\n const newScripts = {\n ...existingScripts,\n ...packageJsonScriptsTemplate,\n };\n const newExports = {\n ...existingExports,\n ...packageJsonExportsTemplate,\n };\n packageJson.scripts = newScripts;\n packageJson.exports = newExports;\n await writePackage(packageJson);\n}\n\n/** Ensure that the project index.html matches the boilerplate index.html. */\nasync function migrateIndexHtml() {\n const indexHtmlPath = path.join(process.cwd(), \"index.html\");\n await writeFile(indexHtmlPath, indexHtmlTemplate);\n}\n\n/** Ensure that the project tsconfig.json matches the boilerplate tsconfig.json. */\nasync function migrateTsConfig() {\n const tsConfigPath = path.join(process.cwd(), \"tsconfig.json\");\n await writeFile(tsConfigPath, tsConfigTemplate);\n}\n\n/** Check if a file exists */\nasync function fileExists(filePath: string): Promise<boolean> {\n try {\n await stat(filePath);\n return true;\n } catch {\n return false;\n }\n}\n\n/** Write a file with optional warning if it already exists */\nasync function writeFileWithWarning(\n filePath: string,\n content: string,\n): Promise<void> {\n const exists = await fileExists(filePath);\n if (exists) {\n console.warn(`Warning: Overwriting existing file: ${filePath}`);\n }\n await writeFile(filePath, content);\n}\n\n/** Add CI/CD workflow and Docker files to the project. */\nasync function migrateCIFiles() {\n const cwd = process.cwd();\n\n try {\n // Create directories if they don't exist\n await mkdir(path.join(cwd, \".github/workflows\"), { recursive: true });\n await mkdir(path.join(cwd, \"docker\"), { recursive: true });\n\n // Write CI/CD workflow\n await writeFileWithWarning(\n path.join(cwd, \".github/workflows/sync-and-publish.yml\"),\n syncAndPublishWorkflowTemplate,\n );\n\n // Write Docker files\n await writeFileWithWarning(\n path.join(cwd, \"Dockerfile\"),\n dockerfileTemplate,\n );\n await writeFileWithWarning(\n path.join(cwd, \"docker/nginx.conf\"),\n nginxConfTemplate,\n );\n await writeFileWithWarning(\n path.join(cwd, \"docker/connect-entrypoint.sh\"),\n connectEntrypointTemplate,\n );\n await writeFileWithWarning(\n path.join(cwd, \"docker/switchboard-entrypoint.sh\"),\n switchboardEntrypointTemplate,\n );\n } catch (error) {\n console.error(\"Error migrating CI files:\", error);\n throw error;\n }\n}\n\n/** Ensure that the project index.ts file uses the new exports for editors and document models */\nfunction migrateRootIndex(project: Project) {\n const indexPath = path.join(process.cwd(), \"index.ts\");\n let source = project.getSourceFile(indexPath);\n if (!source) {\n source = project.createSourceFile(indexPath);\n }\n source.replaceWithText(indexTsTemplate);\n project.saveSync();\n}\n\n/** Ensure that the project's editor.tsx files use default exports for lazy loading */\nfunction migrateEditorFiles(project: Project) {\n const editorsPath = path.join(process.cwd(), \"editors\");\n const dirs = readdirSync(editorsPath, { withFileTypes: true })\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name);\n for (const dir of dirs) {\n const editorFilePath = path.join(editorsPath, dir, \"editor.tsx\");\n const source = project.getSourceFile(editorFilePath);\n if (!source) continue;\n const text = source.getFullText();\n const replaceNamedExportWithDefaultExport = text.replace(\n \"export function Editor\",\n \"export default function Editor\",\n );\n source.replaceWithText(replaceNamedExportWithDefaultExport);\n project.saveSync();\n }\n}\n\n/** Delete the legacy index files in editor directories which are now replaced by module.ts files */\nfunction deleteLegacyEditorDirIndexFiles(project: Project) {\n const editorsPath = path.join(process.cwd(), \"editors\");\n const dirs = readdirSync(editorsPath, { withFileTypes: true })\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name);\n for (const dir of dirs) {\n const indexFilePath = path.join(editorsPath, dir, \"index.ts\");\n const source = project.getSourceFile(indexFilePath);\n if (!source) continue;\n source.delete();\n project.saveSync();\n }\n}\n\n/** Remove usage of the `z` re-export of document model schemas which caused naming conflicts */\nfunction removeZDotSchemaUsage(project: Project) {\n const sourceFiles = project.getSourceFiles();\n for (const sourceFile of sourceFiles) {\n const path = sourceFile.getFilePath();\n if (!path.includes(process.cwd())) continue;\n if (path.includes(\"zod.ts\")) continue;\n const text = sourceFile.getFullText();\n if (/import\\s+(?:\\{\\s*z\\s*\\}|z)\\s+from\\s+['\"]zod['\"]/.test(text)) continue;\n const withoutZDot = text.replace(/z\\./g, \"\");\n sourceFile.replaceWithText(withoutZDot);\n project.saveSync();\n }\n}\n\n/** Remove usage of the `creators` as an aliased full module export which is no longer needed */\nfunction removeCreatorsUsage(project: Project) {\n const sourceFiles = project.getSourceFiles();\n for (const sourceFile of sourceFiles) {\n const path = sourceFile.getFilePath();\n if (!path.includes(process.cwd())) continue;\n const creatorsInvocations = sourceFile\n .getStatements()\n .filter(\n (statement) =>\n statement.getKind() === SyntaxKind.PropertyAccessExpression,\n )\n .filter((statement) => statement.getText().includes(\"creators.\"));\n for (const creatorInvocation of creatorsInvocations) {\n const withoutCreators = creatorInvocation\n .getText()\n .replace(/creators\\./g, \"\");\n creatorInvocation.replaceWithText(withoutCreators);\n project.saveSync();\n }\n }\n}\n\n/** Remove usage of the `utils` import which is no longer exported as a default import */\nfunction removeUtilsDefaultExportUsage(project: Project) {\n const sourceFiles = project.getSourceFiles();\n for (const sourceFile of sourceFiles) {\n const path = sourceFile.getFilePath();\n if (!path.includes(process.cwd())) continue;\n const statement = sourceFile\n .getImportDeclarations()\n .find((importDeclaration) =>\n importDeclaration.getText().includes(\"import utils\"),\n );\n if (statement) {\n statement.remove();\n project.saveSync();\n }\n }\n}\n\n/** Fix missing imports in the project */\nfunction fixImports(project: Project) {\n const sourceFiles = project.getSourceFiles();\n for (const sourceFile of sourceFiles) {\n const path = sourceFile.getFilePath();\n if (!path.includes(process.cwd())) continue;\n sourceFile.fixMissingImports(undefined, {\n importModuleSpecifierPreference: \"project-relative\",\n autoImportSpecifierExcludeRegexes: [\"document-model\", \"document-drive\"],\n importModuleSpecifierEnding: \"js\",\n preferTypeOnlyAutoImports: false,\n });\n sourceFile.fixUnusedIdentifiers();\n\n project.saveSync();\n }\n}\n\n/** Run the generate command on all document models */\nasync function runGenerateOnAllDocumentModels(useHygen: boolean) {\n await startGenerate({\n useHygen,\n } as GenerateArgs);\n}\n\n/** Run the generate command on all editors */\nasync function runGenerateOnAllEditors(useHygen: boolean) {\n const editorsPath = path.join(process.cwd(), \"editors\");\n const dirs = (await readdir(editorsPath, { withFileTypes: true }))\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name);\n for (const dir of dirs) {\n const moduleFilePath = path.join(editorsPath, dir, \"module.ts\");\n const indexFilePath = path.join(editorsPath, dir, \"index.ts\");\n const hasModuleFile = existsSync(moduleFilePath);\n const hasIndexFile = existsSync(indexFilePath);\n if (!hasModuleFile && !hasIndexFile) {\n continue;\n }\n const filePathToUse = hasModuleFile ? moduleFilePath : indexFilePath;\n const { id, name, documentTypes, isDriveEditor } =\n extractEditorModuleInfo(filePathToUse);\n\n if (!name) {\n throw new Error(`Editor ${dir} is missing name`);\n }\n if (!id) {\n throw new Error(`Editor ${dir} is missing id`);\n }\n if (isDriveEditor) {\n const configFilePath = path.join(editorsPath, dir, \"config.ts\");\n const hasConfigFile = existsSync(configFilePath);\n const allowedDocumentTypes = hasConfigFile\n ? extractAllowedDocumentTypes(configFilePath)\n : undefined;\n const args = {\n driveEditorName: name,\n driveEditorId: id,\n driveEditorDirName: dir,\n allowedDocumentTypes,\n useHygen,\n } as GenerateArgs;\n await startGenerate(args);\n } else {\n const args = {\n editorName: name,\n editorId: id,\n editorDirName: dir,\n documentType: documentTypes?.[0],\n useHygen,\n } as GenerateArgs;\n await startGenerate(args);\n }\n }\n}\n\n/** Extract the name, id, document types, and whether the editor is a drive editor from the editor module */\nfunction extractEditorModuleInfo(filePath: string) {\n const project = new Project({\n tsConfigFilePath: path.resolve(\"tsconfig.json\"),\n compilerOptions: {\n verbatimModuleSyntax: false,\n },\n });\n const sourceFile = project.getSourceFileOrThrow(filePath);\n const moduleDeclaration = getVariableDeclarationByTypeName(\n sourceFile,\n \"EditorModule\",\n );\n\n const variable = moduleDeclaration?.getInitializerIfKind(\n SyntaxKind.ObjectLiteralExpression,\n );\n const documentTypes = getObjectProperty(\n variable,\n \"documentTypes\",\n SyntaxKind.ArrayLiteralExpression,\n )\n ?.getElements()\n .map((element) => element.getText())\n .map((text) => text.replace(/[\"']/g, \"\"));\n\n const configProperty = getObjectProperty(\n variable,\n \"config\",\n SyntaxKind.ObjectLiteralExpression,\n );\n\n const id = getStringLiteralValue(\n getObjectProperty(configProperty, \"id\", SyntaxKind.StringLiteral),\n );\n\n const name = getStringLiteralValue(\n getObjectProperty(configProperty, \"name\", SyntaxKind.StringLiteral),\n );\n const isDriveEditor = documentTypes?.includes(\"powerhouse/document-drive\");\n return { id, name, documentTypes, isDriveEditor };\n}\n\n/** Extract the allowed document types from the drive editor config */\nfunction extractAllowedDocumentTypes(filePath: string) {\n const project = new Project({\n tsConfigFilePath: path.resolve(\"tsconfig.json\"),\n compilerOptions: {\n verbatimModuleSyntax: false,\n },\n });\n const sourceFile = project.getSourceFile(filePath);\n if (!sourceFile) return;\n const configVariableDeclaration = getVariableDeclarationByTypeName(\n sourceFile,\n \"PHDriveEditorConfig\",\n );\n const configVariable = configVariableDeclaration?.getInitializerIfKind(\n SyntaxKind.ObjectLiteralExpression,\n );\n if (!configVariable) return;\n const allowedDocumentTypes = getArrayLiteralExpressionElementsText(\n getObjectProperty(\n configVariable,\n \"allowedDocumentTypes\",\n SyntaxKind.ArrayLiteralExpression,\n ),\n );\n return allowedDocumentTypes;\n}\n\nfunction getVariableDeclarationByTypeName(\n sourceFile: SourceFile,\n typeName: string,\n) {\n const variableDeclarations = sourceFile.getVariableDeclarations();\n return variableDeclarations.find((declaration) =>\n declaration.getType().getText().includes(typeName),\n );\n}\n\nfunction getStringLiteralValue(stringLiteral: StringLiteral | undefined) {\n return stringLiteral?.getText().replace(/[\"']/g, \"\");\n}\n\nfunction getObjectProperty<T extends SyntaxKind>(\n object: ObjectLiteralExpression | undefined,\n propertyName: string,\n propertyType: T,\n) {\n return object\n ?.getProperty(propertyName)\n ?.asKind(SyntaxKind.PropertyAssignment)\n ?.getChildren()\n .find((child) => child.getKind() === propertyType)\n ?.asKind(propertyType);\n}\n\nfunction getArrayLiteralExpressionElementsText(\n arrayLiteralExpression: ArrayLiteralExpression | undefined,\n) {\n return arrayLiteralExpression\n ?.getElements()\n .map((element) => element.getText())\n .map((text) => text.replace(/[\"']/g, \"\"));\n}\n"],"mappings":";;;;;;;;;AA2BA,eAAsB,aAAa,EAAE,WAAW,SAAsB;AACpE,OAAM,oBAAoB;AAC1B,OAAM,iBAAiB;AACvB,OAAM,kBAAkB;AACxB,OAAM,gBAAgB;AACtB,OAAM,+BAA+B,SAAS;AAC9C,OAAM,wBAAwB,SAAS;CACvC,MAAM,UAAU,IAAI,QAAQ;EAC1B,kBAAkB,KAAK,QAAQ,gBAAgB;EAC/C,iBAAiB,EACf,sBAAsB,OACvB;EACF,CAAC;AACF,iCAAgC,QAAQ;AACxC,oBAAmB,QAAQ;AAC3B,kBAAi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AAY,aAAa,EACzB,OAAO,WAAW,mBAAmB,EACrC,aAAa,CACd,MAAM,UAAU,MAAM,SAAS,KAAK,aAAa,EAChD,OAAO,aAAa;;AAG1B,SAAS,sCACP,wBACA;AACA,QAAO,wBACH,aAAa,CACd,KAAK,YAAY,QAAQ,SAAS,CAAC,CACnC,KAAK,SAAS,KAAK,QAAQ,SAAS,GAAG,CAAC"}
1
+ {"version":3,"file":"migrate-DErTQPCC.mjs","names":[],"sources":["../src/services/migrate.ts"],"sourcesContent":["import {\n connectEntrypointTemplate,\n dockerfileTemplate,\n indexHtmlTemplate,\n indexTsTemplate,\n nginxConfTemplate,\n packageJsonExportsTemplate,\n packageJsonScriptsTemplate,\n switchboardEntrypointTemplate,\n syncAndPublishWorkflowTemplate,\n tsConfigTemplate,\n} from \"@powerhousedao/codegen/templates\";\nimport { existsSync, readdirSync } from \"node:fs\";\nimport { mkdir, readdir, stat, writeFile } from \"node:fs/promises\";\nimport path from \"path\";\nimport { readPackage } from \"read-pkg\";\nimport type {\n ArrayLiteralExpression,\n ObjectLiteralExpression,\n SourceFile,\n StringLiteral,\n} from \"ts-morph\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport { writePackage } from \"write-package\";\nimport type { GenerateArgs, MigrateArgs } from \"../types.js\";\nimport { startGenerate } from \"./generate.js\";\n\nexport async function startMigrate({ useHygen = false }: MigrateArgs) {\n await migratePackageJson();\n await migrateTsConfig();\n await migrateIndexHtml();\n await migrateCIFiles();\n await runGenerateOnAllDocumentModels(useHygen);\n await runGenerateOnAllEditors(useHygen);\n const project = new Project({\n tsConfigFilePath: path.resolve(\"tsconfig.json\"),\n compilerOptions: {\n verbatimModuleSyntax: false,\n },\n });\n deleteLegacyEditorDirIndexFiles(project);\n migrateEditorFiles(project);\n migrateRootIndex(project);\n removeZDotSchemaUsage(project);\n removeCreatorsUsage(project);\n removeUtilsDefaultExportUsage(project);\n fixImports(project);\n}\n\n/** Ensure that the project package.json has the correct scripts and exports. */\nasync function migratePackageJson() {\n const packageJson = await readPackage();\n const existingScripts = packageJson.scripts;\n const existingExports =\n !!packageJson.exports &&\n !Array.isArray(packageJson.exports) &&\n typeof packageJson.exports !== \"string\"\n ? packageJson.exports\n : {};\n const newScripts = {\n ...existingScripts,\n ...packageJsonScriptsTemplate,\n };\n const newExports = {\n ...existingExports,\n ...packageJsonExportsTemplate,\n };\n packageJson.scripts = newScripts;\n packageJson.exports = newExports;\n await writePackage(packageJson);\n}\n\n/** Ensure that the project index.html matches the boilerplate index.html. */\nasync function migrateIndexHtml() {\n const indexHtmlPath = path.join(process.cwd(), \"index.html\");\n await writeFile(indexHtmlPath, indexHtmlTemplate);\n}\n\n/** Ensure that the project tsconfig.json matches the boilerplate tsconfig.json. */\nasync function migrateTsConfig() {\n const tsConfigPath = path.join(process.cwd(), \"tsconfig.json\");\n await writeFile(tsConfigPath, tsConfigTemplate);\n}\n\n/** Check if a file exists */\nasync function fileExists(filePath: string): Promise<boolean> {\n try {\n await stat(filePath);\n return true;\n } catch {\n return false;\n }\n}\n\n/** Write a file with optional warning if it already exists */\nasync function writeFileWithWarning(\n filePath: string,\n content: string,\n): Promise<void> {\n const exists = await fileExists(filePath);\n if (exists) {\n console.warn(`Warning: Overwriting existing file: ${filePath}`);\n }\n await writeFile(filePath, content);\n}\n\n/** Add CI/CD workflow and Docker files to the project. */\nasync function migrateCIFiles() {\n const cwd = process.cwd();\n\n try {\n // Create directories if they don't exist\n await mkdir(path.join(cwd, \".github/workflows\"), { recursive: true });\n await mkdir(path.join(cwd, \"docker\"), { recursive: true });\n\n // Write CI/CD workflow\n await writeFileWithWarning(\n path.join(cwd, \".github/workflows/sync-and-publish.yml\"),\n syncAndPublishWorkflowTemplate,\n );\n\n // Write Docker files\n await writeFileWithWarning(\n path.join(cwd, \"Dockerfile\"),\n dockerfileTemplate,\n );\n await writeFileWithWarning(\n path.join(cwd, \"docker/nginx.conf\"),\n nginxConfTemplate,\n );\n await writeFileWithWarning(\n path.join(cwd, \"docker/connect-entrypoint.sh\"),\n connectEntrypointTemplate,\n );\n await writeFileWithWarning(\n path.join(cwd, \"docker/switchboard-entrypoint.sh\"),\n switchboardEntrypointTemplate,\n );\n } catch (error) {\n console.error(\"Error migrating CI files:\", error);\n throw error;\n }\n}\n\n/** Ensure that the project index.ts file uses the new exports for editors and document models */\nfunction migrateRootIndex(project: Project) {\n const indexPath = path.join(process.cwd(), \"index.ts\");\n let source = project.getSourceFile(indexPath);\n if (!source) {\n source = project.createSourceFile(indexPath);\n }\n source.replaceWithText(indexTsTemplate);\n project.saveSync();\n}\n\n/** Ensure that the project's editor.tsx files use default exports for lazy loading */\nfunction migrateEditorFiles(project: Project) {\n const editorsPath = path.join(process.cwd(), \"editors\");\n const dirs = readdirSync(editorsPath, { withFileTypes: true })\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name);\n for (const dir of dirs) {\n const editorFilePath = path.join(editorsPath, dir, \"editor.tsx\");\n const source = project.getSourceFile(editorFilePath);\n if (!source) continue;\n const text = source.getFullText();\n const replaceNamedExportWithDefaultExport = text.replace(\n \"export function Editor\",\n \"export default function Editor\",\n );\n source.replaceWithText(replaceNamedExportWithDefaultExport);\n project.saveSync();\n }\n}\n\n/** Delete the legacy index files in editor directories which are now replaced by module.ts files */\nfunction deleteLegacyEditorDirIndexFiles(project: Project) {\n const editorsPath = path.join(process.cwd(), \"editors\");\n const dirs = readdirSync(editorsPath, { withFileTypes: true })\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name);\n for (const dir of dirs) {\n const indexFilePath = path.join(editorsPath, dir, \"index.ts\");\n const source = project.getSourceFile(indexFilePath);\n if (!source) continue;\n source.delete();\n project.saveSync();\n }\n}\n\n/** Remove usage of the `z` re-export of document model schemas which caused naming conflicts */\nfunction removeZDotSchemaUsage(project: Project) {\n const sourceFiles = project.getSourceFiles();\n for (const sourceFile of sourceFiles) {\n const path = sourceFile.getFilePath();\n if (!path.includes(process.cwd())) continue;\n if (path.includes(\"zod.ts\")) continue;\n const text = sourceFile.getFullText();\n if (/import\\s+(?:\\{\\s*z\\s*\\}|z)\\s+from\\s+['\"]zod['\"]/.test(text)) continue;\n const withoutZDot = text.replace(/z\\./g, \"\");\n sourceFile.replaceWithText(withoutZDot);\n project.saveSync();\n }\n}\n\n/** Remove usage of the `creators` as an aliased full module export which is no longer needed */\nfunction removeCreatorsUsage(project: Project) {\n const sourceFiles = project.getSourceFiles();\n for (const sourceFile of sourceFiles) {\n const path = sourceFile.getFilePath();\n if (!path.includes(process.cwd())) continue;\n const creatorsInvocations = sourceFile\n .getStatements()\n .filter(\n (statement) =>\n statement.getKind() === SyntaxKind.PropertyAccessExpression,\n )\n .filter((statement) => statement.getText().includes(\"creators.\"));\n for (const creatorInvocation of creatorsInvocations) {\n const withoutCreators = creatorInvocation\n .getText()\n .replace(/creators\\./g, \"\");\n creatorInvocation.replaceWithText(withoutCreators);\n project.saveSync();\n }\n }\n}\n\n/** Remove usage of the `utils` import which is no longer exported as a default import */\nfunction removeUtilsDefaultExportUsage(project: Project) {\n const sourceFiles = project.getSourceFiles();\n for (const sourceFile of sourceFiles) {\n const path = sourceFile.getFilePath();\n if (!path.includes(process.cwd())) continue;\n const statement = sourceFile\n .getImportDeclarations()\n .find((importDeclaration) =>\n importDeclaration.getText().includes(\"import utils\"),\n );\n if (statement) {\n statement.remove();\n project.saveSync();\n }\n }\n}\n\n/** Fix missing imports in the project */\nfunction fixImports(project: Project) {\n const sourceFiles = project.getSourceFiles();\n for (const sourceFile of sourceFiles) {\n const path = sourceFile.getFilePath();\n if (!path.includes(process.cwd())) continue;\n sourceFile.fixMissingImports(undefined, {\n importModuleSpecifierPreference: \"project-relative\",\n autoImportSpecifierExcludeRegexes: [\"document-model\", \"document-drive\"],\n importModuleSpecifierEnding: \"js\",\n preferTypeOnlyAutoImports: false,\n });\n sourceFile.fixUnusedIdentifiers();\n\n project.saveSync();\n }\n}\n\n/** Run the generate command on all document models */\nasync function runGenerateOnAllDocumentModels(useHygen: boolean) {\n await startGenerate({\n useHygen,\n } as GenerateArgs);\n}\n\n/** Run the generate command on all editors */\nasync function runGenerateOnAllEditors(useHygen: boolean) {\n const editorsPath = path.join(process.cwd(), \"editors\");\n const dirs = (await readdir(editorsPath, { withFileTypes: true }))\n .filter((entry) => entry.isDirectory())\n .map((entry) => entry.name);\n for (const dir of dirs) {\n const moduleFilePath = path.join(editorsPath, dir, \"module.ts\");\n const indexFilePath = path.join(editorsPath, dir, \"index.ts\");\n const hasModuleFile = existsSync(moduleFilePath);\n const hasIndexFile = existsSync(indexFilePath);\n if (!hasModuleFile && !hasIndexFile) {\n continue;\n }\n const filePathToUse = hasModuleFile ? moduleFilePath : indexFilePath;\n const { id, name, documentTypes, isDriveEditor } =\n extractEditorModuleInfo(filePathToUse);\n\n if (!name) {\n throw new Error(`Editor ${dir} is missing name`);\n }\n if (!id) {\n throw new Error(`Editor ${dir} is missing id`);\n }\n if (isDriveEditor) {\n const configFilePath = path.join(editorsPath, dir, \"config.ts\");\n const hasConfigFile = existsSync(configFilePath);\n const allowedDocumentTypes = hasConfigFile\n ? extractAllowedDocumentTypes(configFilePath)\n : undefined;\n const args = {\n driveEditorName: name,\n driveEditorId: id,\n driveEditorDirName: dir,\n allowedDocumentTypes,\n useHygen,\n } as GenerateArgs;\n await startGenerate(args);\n } else {\n const args = {\n editorName: name,\n editorId: id,\n editorDirName: dir,\n documentType: documentTypes?.[0],\n useHygen,\n } as GenerateArgs;\n await startGenerate(args);\n }\n }\n}\n\n/** Extract the name, id, document types, and whether the editor is a drive editor from the editor module */\nfunction extractEditorModuleInfo(filePath: string) {\n const project = new Project({\n tsConfigFilePath: path.resolve(\"tsconfig.json\"),\n compilerOptions: {\n verbatimModuleSyntax: false,\n },\n });\n const sourceFile = project.getSourceFileOrThrow(filePath);\n const moduleDeclaration = getVariableDeclarationByTypeName(\n sourceFile,\n \"EditorModule\",\n );\n\n const variable = moduleDeclaration?.getInitializerIfKind(\n SyntaxKind.ObjectLiteralExpression,\n );\n const documentTypes = getObjectProperty(\n variable,\n \"documentTypes\",\n SyntaxKind.ArrayLiteralExpression,\n )\n ?.getElements()\n .map((element) => element.getText())\n .map((text) => text.replace(/[\"']/g, \"\"));\n\n const configProperty = getObjectProperty(\n variable,\n \"config\",\n SyntaxKind.ObjectLiteralExpression,\n );\n\n const id = getStringLiteralValue(\n getObjectProperty(configProperty, \"id\", SyntaxKind.StringLiteral),\n );\n\n const name = getStringLiteralValue(\n getObjectProperty(configProperty, \"name\", SyntaxKind.StringLiteral),\n );\n const isDriveEditor = documentTypes?.includes(\"powerhouse/document-drive\");\n return { id, name, documentTypes, isDriveEditor };\n}\n\n/** Extract the allowed document types from the drive editor config */\nfunction extractAllowedDocumentTypes(filePath: string) {\n const project = new Project({\n tsConfigFilePath: path.resolve(\"tsconfig.json\"),\n compilerOptions: {\n verbatimModuleSyntax: false,\n },\n });\n const sourceFile = project.getSourceFile(filePath);\n if (!sourceFile) return;\n const configVariableDeclaration = getVariableDeclarationByTypeName(\n sourceFile,\n \"PHDriveEditorConfig\",\n );\n const configVariable = configVariableDeclaration?.getInitializerIfKind(\n SyntaxKind.ObjectLiteralExpression,\n );\n if (!configVariable) return;\n const allowedDocumentTypes = getArrayLiteralExpressionElementsText(\n getObjectProperty(\n configVariable,\n \"allowedDocumentTypes\",\n SyntaxKind.ArrayLiteralExpression,\n ),\n );\n return allowedDocumentTypes;\n}\n\nfunction getVariableDeclarationByTypeName(\n sourceFile: SourceFile,\n typeName: string,\n) {\n const variableDeclarations = sourceFile.getVariableDeclarations();\n return variableDeclarations.find((declaration) =>\n declaration.getType().getText().includes(typeName),\n );\n}\n\nfunction getStringLiteralValue(stringLiteral: StringLiteral | undefined) {\n return stringLiteral?.getText().replace(/[\"']/g, \"\");\n}\n\nfunction getObjectProperty<T extends SyntaxKind>(\n object: ObjectLiteralExpression | undefined,\n propertyName: string,\n propertyType: T,\n) {\n return object\n ?.getProperty(propertyName)\n ?.asKind(SyntaxKind.PropertyAssignment)\n ?.getChildren()\n .find((child) => child.getKind() === propertyType)\n ?.asKind(propertyType);\n}\n\nfunction getArrayLiteralExpressionElementsText(\n arrayLiteralExpression: ArrayLiteralExpression | undefined,\n) {\n return arrayLiteralExpression\n ?.getElements()\n .map((element) => element.getText())\n .map((text) => text.replace(/[\"']/g, \"\"));\n}\n"],"mappings":";;;;;;;;;AA2BA,eAAsB,aAAa,EAAE,WAAW,SAAsB;AACpE,OAAM,oBAAoB;AAC1B,OAAM,iBAAiB;AACvB,OAAM,kBAAkB;AACxB,OAAM,gBAAgB;AACtB,OAAM,+BAA+B,SAAS;AAC9C,OAAM,wBAAwB,SAAS;CACvC,MAAM,UAAU,IAAI,QAAQ;EAC1B,kBAAkB,KAAK,QAAQ,gBAAgB;EAC/C,iBAAiB,EACf,sBAAsB,OACvB;EACF,CAAC;AACF,iCAAgC,QAAQ;AACxC,oBAAmB,QAAQ;AAC3B,kBAAiB,QAAQ;AACzB,uBAAsB,QAAQ;AAC9B,qBAAoB,QAAQ;AAC5B,+BAA8B,QAAQ;AACtC,YAAW,QAAQ;;;AAIrB,eAAe,qBAAqB;CAClC,MAAM,cAAc,MAAM,aAAa;CACvC,MAAM,kBAAkB,YAAY;CACpC,MAAM,kBACJ,CAAC,CAAC,YAAY,WACd,CAAC,MAAM,QAAQ,YAAY,QAAQ,IACnC,OAAO,YAAY,YAAY,WAC3B,YAAY,UACZ,EAAE;CACR,MAAM,aAAa;EACjB,GAAG;EACH,GAAG;EACJ;CACD,MAAM,aAAa;EACjB,GAAG;EACH,GAAG;EACJ;AACD,aAAY,UAAU;AACtB,aAAY,UAAU;AACtB,OAAM,aAAa,YAAY;;;AAIjC,eAAe,mBAAmB;AAEhC,OAAM,UADgB,KAAK,KAAK,QAAQ,KAAK,EAAE,aAAa,EAC7B,kBAAkB;;;AAInD,eAAe,kBAAkB;AAE/B,OAAM,UADe,KAAK,KAAK,QAAQ,KAAK,EAAE,gBAAgB,EAChC,iBAAiB;;;AAIjD,eAAe,WAAW,UAAoC;AAC5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D,MAAM,aANU,IAAI,QAAQ;EAC1B,kBAAkB,KAAK,QAAQ,gBAAgB;EAC/C,iBAAiB,EACf,sBAAsB,OACvB;EACF,CAAC,CACyB,cAAc,SAAS;AAClD,KAAI,CAAC,WAAY;CAKjB,MAAM,iBAJ4B,iCAChC,YACA,sBACD,EACiD,qBAChD,WAAW,wBACZ;AACD,KAAI,CAAC,eAAgB;AAQrB,QAP6B,sCAC3B,kBACE,gBACA,wBACA,WAAW,uBACZ,CACF;;AAIH,SAAS,iCACP,YACA,UACA;AAEA,QAD6B,WAAW,yBAAyB,CACrC,MAAM,gBAChC,YAAY,SAAS,CAAC,SAAS,CAAC,SAAS,SAAS,CACnD;;AAGH,SAAS,sBAAsB,eAA0C;AACvE,QAAO,eAAe,SAAS,CAAC,QAAQ,SAAS,GAAG;;AAGtD,SAAS,kBACP,QACA,cACA,cACA;AACA,QAAO,QACH,YAAY,aAAa,EACzB,OAAO,WAAW,mBAAmB,EACrC,aAAa,CACd,MAAM,UAAU,MAAM,SAAS,KAAK,aAAa,EAChD,OAAO,aAAa;;AAG1B,SAAS,sCACP,wBACA;AACA,QAAO,wBACH,aAAa,CACd,KAAK,YAAY,QAAQ,SAAS,CAAC,CACnC,KAAK,SAAS,KAAK,QAAQ,SAAS,GAAG,CAAC"}
@@ -92,7 +92,7 @@ function updatePackagesArray(currentPackages = [], dependencies, task = "install
92
92
  const mappedPackages = dependencies.map((dep) => ({
93
93
  packageName: dep.name,
94
94
  version: dep.version,
95
- provider: "npm"
95
+ provider: "registry"
96
96
  }));
97
97
  if (isInstall) return [...currentPackages.filter((pkg) => !dependencies.find((dep) => dep.name === pkg.packageName)), ...mappedPackages];
98
98
  return currentPackages.filter((pkg) => !dependencies.map((dep) => dep.name).includes(pkg.packageName));
@@ -158,4 +158,4 @@ function removeStylesImports(dependencies, projectPath) {
158
158
  //#endregion
159
159
  export { updateStylesFile as a, updateConfigFile as i, getProjectInfo as n, removeStylesImports as r, generateProjectDriveId as t };
160
160
 
161
- //# sourceMappingURL=utils-5r3OKhGj.mjs.map
161
+ //# sourceMappingURL=utils-CjKhqXvK.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-CjKhqXvK.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import type { PowerhouseConfig } from \"@powerhousedao/config\";\nimport crypto from \"node:crypto\";\nimport fs from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport path, { dirname } from \"node:path\";\nexport const POWERHOUSE_CONFIG_FILE = \"powerhouse.config.json\";\nexport const POWERHOUSE_GLOBAL_DIR = path.join(homedir(), \".ph\");\nexport const SUPPORTED_PACKAGE_MANAGERS = [\"npm\", \"yarn\", \"pnpm\", \"bun\"];\n\nexport const packageManagers = {\n bun: {\n globalPathRegexp: /[\\\\/].bun[\\\\/]/,\n installCommand: \"bun add {{dependency}}\",\n uninstallCommand: \"bun remove {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"bun.lock\",\n updateCommand: \"bun update {{dependency}}\",\n buildAffected: \"bun run build:affected\",\n },\n pnpm: {\n globalPathRegexp: /[\\\\/]pnpm[\\\\/]/,\n installCommand: \"pnpm add {{dependency}}\",\n uninstallCommand: \"pnpm remove {{dependency}}\",\n workspaceOption: \"--workspace-root\",\n lockfile: \"pnpm-lock.yaml\",\n updateCommand: \"pnpm update {{dependency}}\",\n buildAffected: \"pnpm run build:affected\",\n },\n yarn: {\n globalPathRegexp: /[\\\\/]yarn[\\\\/]/,\n installCommand: \"yarn add {{dependency}}\",\n uninstallCommand: \"yarn remove {{dependency}}\",\n workspaceOption: \"-W\",\n lockfile: \"yarn.lock\",\n updateCommand: \"yarn upgrade {{dependency}}\",\n buildAffected: \"yarn run build:affected\",\n },\n npm: {\n installCommand: \"npm install {{dependency}}\",\n uninstallCommand: \"npm uninstall {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"package-lock.json\",\n updateCommand: \"npm update {{dependency}} --save\",\n buildAffected: \"npm run build:affected\",\n },\n};\n\ntype PathValidation = (dir: string) => boolean;\n\nexport type PackageManager = \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\nexport type ProjectInfo = {\n isGlobal: boolean;\n path: string;\n packageManager: PackageManager;\n};\n\nexport function defaultPathValidation() {\n return true;\n}\n\nexport function isPowerhouseProject(dir: string) {\n const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);\n\n return fs.existsSync(powerhouseConfigPath);\n}\n\nexport function findNodeProjectRoot(\n dir: string,\n pathValidation: PathValidation = defaultPathValidation,\n) {\n const packageJsonPath = path.join(dir, \"package.json\");\n\n if (fs.existsSync(packageJsonPath) && pathValidation(dir)) {\n return dir;\n }\n\n const parentDir = dirname(dir);\n\n if (parentDir === dir) {\n return null;\n }\n\n return findNodeProjectRoot(parentDir, pathValidation);\n}\n\nexport function getProjectInfo(debug?: boolean): ProjectInfo {\n const currentPath = process.cwd();\n\n if (debug) {\n console.log(\">>> currentPath\", currentPath);\n }\n\n const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);\n\n if (!projectPath) {\n return {\n isGlobal: true,\n path: POWERHOUSE_GLOBAL_DIR,\n packageManager: getPackageManagerFromLockfile(POWERHOUSE_GLOBAL_DIR),\n };\n }\n\n return {\n isGlobal: false,\n path: projectPath,\n packageManager: getPackageManagerFromLockfile(projectPath),\n };\n}\n\n/**\n * Generates a unique drive ID based on the project path.\n * The same project path will always generate the same ID.\n * @param name - The name prefix for the drive ID (e.g., \"vetra\", \"powerhouse\")\n * @returns A unique drive ID in the format \"{name}-{hash}\"\n */\nexport function generateProjectDriveId(name: string): string {\n const projectInfo = getProjectInfo();\n const hash = crypto\n .createHash(\"sha256\")\n .update(projectInfo.path)\n .digest(\"hex\");\n const shortHash = hash.substring(0, 8);\n return `${name}-${shortHash}`;\n}\n\nexport function getPackageManagerFromLockfile(dir: string): PackageManager {\n if (fs.existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {\n return \"pnpm\";\n } else if (fs.existsSync(path.join(dir, packageManagers.yarn.lockfile))) {\n return \"yarn\";\n } else if (fs.existsSync(path.join(dir, packageManagers.bun.lockfile))) {\n return \"bun\";\n }\n\n return \"npm\";\n}\n\nexport function updatePackagesArray(\n currentPackages: PowerhouseConfig[\"packages\"] = [],\n dependencies: { name: string; version: string | undefined }[],\n task: \"install\" | \"uninstall\" = \"install\",\n): PowerhouseConfig[\"packages\"] {\n const isInstall = task === \"install\";\n const mappedPackages = dependencies.map((dep) => ({\n packageName: dep.name,\n version: dep.version,\n provider: \"registry\" as const,\n }));\n\n if (isInstall) {\n // Overwrite existing package if version is different\n const filteredPackages = currentPackages.filter(\n (pkg) => !dependencies.find((dep) => dep.name === pkg.packageName),\n );\n return [...filteredPackages, ...mappedPackages];\n }\n\n return currentPackages.filter(\n (pkg) => !dependencies.map((dep) => dep.name).includes(pkg.packageName),\n );\n}\n\n// Modify updateConfigFile to use the new function\nexport function updateConfigFile(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n task: \"install\" | \"uninstall\" = \"install\",\n) {\n const configPath = path.join(projectPath, POWERHOUSE_CONFIG_FILE);\n\n if (!fs.existsSync(configPath)) {\n throw new Error(\n `powerhouse.config.json file not found. projectPath: ${projectPath}`,\n );\n }\n\n const config = JSON.parse(\n fs.readFileSync(configPath, \"utf-8\"),\n ) as PowerhouseConfig;\n\n const updatedConfig: PowerhouseConfig = {\n ...config,\n packages: updatePackagesArray(config.packages, dependencies, task),\n };\n\n fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));\n}\n\n/**\n * Recursively searches for a specific file by traversing up the directory tree.\n * Starting from the given path, it checks each parent directory until it finds\n * the target file or reaches the root directory.\n *\n * @param startPath - The absolute path of the directory to start searching from\n * @param targetFile - The name of the file to search for (e.g., 'package.json', 'pnpm-workspace.yaml')\n * @returns The absolute path of the directory containing the target file, or null if not found\n *\n * @example\n * // Find the workspace root directory\n * const workspaceRoot = findContainerDirectory('/path/to/project/src', 'pnpm-workspace.yaml');\n *\n * // Find the nearest package.json\n * const packageDir = findContainerDirectory('/path/to/project/src/components', 'package.json');\n */\nexport const findContainerDirectory = (\n startPath: string,\n targetFile: string,\n): string | null => {\n const filePath = path.join(startPath, targetFile);\n\n if (fs.existsSync(filePath)) {\n return startPath;\n }\n\n const parentDir = path.dirname(startPath);\n\n //reached the root directory and haven't found the file\n if (parentDir === startPath) {\n return null;\n }\n\n return findContainerDirectory(parentDir, targetFile);\n};\n\n/**\n * Updates the styles.css file to include imports for newly installed packages\n * @param dependencies - Array of dependencies that were installed\n * @param projectPath - Path to the project root\n */\nexport function updateStylesFile(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n) {\n const stylesPath = path.join(projectPath, \"style.css\");\n\n // Check if styles.css exists\n if (!fs.existsSync(stylesPath)) {\n console.warn(\"⚠️ Warning: style.css file not found in project root\");\n return;\n }\n\n const currentStyles = fs.readFileSync(stylesPath, \"utf-8\");\n let updatedStyles = currentStyles;\n\n for (const dep of dependencies) {\n const cssPath = `./node_modules/${dep.name}/dist/style.css`;\n const fullCssPath = path.join(projectPath, cssPath);\n const importStatement = `@import '${cssPath}';`;\n\n // Check if the CSS file exists\n if (!fs.existsSync(fullCssPath)) {\n console.warn(`⚠️ Warning: CSS file not found at ${cssPath}`);\n continue;\n }\n\n // Check if import already exists\n if (currentStyles.includes(importStatement)) {\n continue;\n }\n\n // Find the last @import statement\n const importLines = currentStyles\n .split(\"\\n\")\n .filter((line) => line.trim().startsWith(\"@import\"));\n const lastImport = importLines[importLines.length - 1];\n\n if (lastImport) {\n // Insert new import after the last existing import\n updatedStyles = currentStyles.replace(\n lastImport,\n `${lastImport}\\n${importStatement}`,\n );\n } else {\n // If no imports exist, add at the top of the file\n updatedStyles = `${importStatement}\\n${currentStyles}`;\n }\n }\n\n // Only write if changes were made\n if (updatedStyles !== currentStyles) {\n fs.writeFileSync(stylesPath, updatedStyles);\n }\n}\n\n/**\n * Removes CSS imports for uninstalled packages from styles.css\n */\nexport function removeStylesImports(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n) {\n const stylesPath = path.join(projectPath, \"style.css\");\n\n // Check if styles.css exists\n if (!fs.existsSync(stylesPath)) {\n console.warn(\"⚠️ Warning: style.css file not found in project root\");\n return;\n }\n\n const currentStyles = fs.readFileSync(stylesPath, \"utf-8\");\n let updatedStyles = currentStyles;\n\n for (const dep of dependencies) {\n const cssPath = `./node_modules/${dep.name}/dist/style.css`;\n const importStatement = `@import '${cssPath}';`;\n\n // Remove the import line if it exists\n const lines = updatedStyles.split(\"\\n\");\n const filteredLines = lines.filter(\n (line) => !line.trim().includes(importStatement),\n );\n\n if (filteredLines.length !== lines.length) {\n updatedStyles = filteredLines.join(\"\\n\");\n }\n }\n\n // Only write if changes were made\n if (updatedStyles !== currentStyles) {\n fs.writeFileSync(stylesPath, updatedStyles);\n }\n}\n"],"mappings":";;;;;AAKA,MAAa,yBAAyB;AACtC,MAAa,wBAAwB,KAAK,KAAK,SAAS,EAAE,MAAM;AAGhE,MAAa,kBAAkB;CAC7B,KAAK;EACH,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;EAChB;CACD,MAAM;EACJ,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;EAChB;CACD,MAAM;EACJ,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;EAChB;CACD,KAAK;EACH,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;EAChB;CACF;AAYD,SAAgB,wBAAwB;AACtC,QAAO;;AAGT,SAAgB,oBAAoB,KAAa;CAC/C,MAAM,uBAAuB,KAAK,KAAK,KAAK,uBAAuB;AAEnE,QAAO,GAAG,WAAW,qBAAqB;;AAG5C,SAAgB,oBACd,KACA,iBAAiC,uBACjC;CACA,M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AK3C,KAAI,kBAAkB,cACpB,IAAG,cAAc,YAAY,cAAc;;;;;AAO/C,SAAgB,oBACd,cACA,aACA;CACA,MAAM,aAAa,KAAK,KAAK,aAAa,YAAY;AAGtD,KAAI,CAAC,GAAG,WAAW,WAAW,EAAE;AAC9B,UAAQ,KAAK,uDAAuD;AACpE;;CAGF,MAAM,gBAAgB,GAAG,aAAa,YAAY,QAAQ;CAC1D,IAAI,gBAAgB;AAEpB,MAAK,MAAM,OAAO,cAAc;EAE9B,MAAM,kBAAkB,YADR,kBAAkB,IAAI,KAAK,iBACC;EAG5C,MAAM,QAAQ,cAAc,MAAM,KAAK;EACvC,MAAM,gBAAgB,MAAM,QACzB,SAAS,CAAC,KAAK,MAAM,CAAC,SAAS,gBAAgB,CACjD;AAED,MAAI,cAAc,WAAW,MAAM,OACjC,iBAAgB,cAAc,KAAK,KAAK;;AAK5C,KAAI,kBAAkB,cACpB,IAAG,cAAc,YAAY,cAAc"}
@@ -1,4 +1,4 @@
1
- import { t as generateProjectDriveId } from "./utils-5r3OKhGj.mjs";
1
+ import { t as generateProjectDriveId } from "./utils-CjKhqXvK.mjs";
2
2
  import "./assign-env-vars-CzHgn5ax.mjs";
3
3
  import { t as runConnectStudio } from "./connect-studio-38_NrT_a.mjs";
4
4
  import { n as startSwitchboard } from "./switchboard-BclxuF4j.mjs";
@@ -357,4 +357,4 @@ async function startVetra(args) {
357
357
  //#endregion
358
358
  export { startVetra };
359
359
 
360
- //# sourceMappingURL=vetra-DDjhg4w5.mjs.map
360
+ //# sourceMappingURL=vetra-Bii4o1sa.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"vetra-DDjhg4w5.mjs","names":[],"sources":["../src/utils/configure-vetra-github-url.ts","../src/services/vetra.ts"],"sourcesContent":["import {\n createVetraDocument,\n getVetraDocuments,\n setPackageGithubUrl,\n} from \"@powerhousedao/common/utils\";\nimport { red } from \"colorette\";\nimport { execSync } from \"node:child_process\";\nimport { createInterface } from \"node:readline\";\n\n/**\n * Get git remote URL (origin)\n * @returns Git remote URL or null if not configured\n */\nfunction getGitRemoteUrl(): string | null {\n try {\n const url = execSync(\"git remote get-url origin\", {\n encoding: \"utf-8\",\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n }).trim();\n return url || null;\n } catch {\n return null;\n }\n}\n\n/**\n * Prompt user to enter a custom GitHub URL\n */\nasync function promptForCustomUrl(): Promise<string | null> {\n return new Promise((resolve) => {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n process.stdout.write(\"\\nEnter GitHub URL (or press Enter to skip): \");\n\n rl.on(\"line\", (answer: string) => {\n rl.close();\n const url = answer.trim();\n resolve(url || null);\n });\n });\n}\n\n/**\n * Prompt yes/no question\n */\nasync function promptYesNo(question: string): Promise<boolean> {\n return new Promise((resolve) => {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n process.stdout.write(`\\n${question} (y/n): `);\n\n rl.on(\"line\", (answer: string) => {\n rl.close();\n const response = answer.trim().toLowerCase();\n resolve(response === \"y\" || response === \"yes\");\n });\n });\n}\n\n/**\n * Prompt user to select or enter GitHub URL\n * @param gitRemoteUrl - Git remote URL if available\n * @returns Selected URL or null if skipped\n */\nasync function promptForGithubUrl(\n gitRemoteUrl: string | null,\n): Promise<string | null> {\n return new Promise((resolve) => {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n console.log(\"\\n\" + \"=\".repeat(50));\n console.log(\"🔍 Vetra Package Configuration\");\n console.log(\"=\".repeat(50));\n console.log(\n \"\\nWe detected a Vetra package document in your remote drive without a GitHub URL configured.\",\n );\n console.log(\"\\nWould you like to configure the GitHub URL now?\");\n\n if (gitRemoteUrl) {\n console.log(`\\nGit remote URL detected: ${gitRemoteUrl}`);\n console.log(\"\\nOptions:\");\n console.log(\"1. Use detected URL\");\n console.log(\"2. Enter a different URL\");\n console.log(\"3. Skip configuration\");\n\n process.stdout.write(\"\\nSelect an option (1-3): \");\n\n const handleAnswer = (answer: string) => {\n const choice = answer.trim();\n\n if (choice === \"1\") {\n rl.close();\n resolve(gitRemoteUrl);\n } else if (choice === \"2\") {\n rl.close();\n promptForCustomUrl()\n .then(resolve)\n .catch(() => resolve(null));\n } else if (choice === \"3\") {\n rl.close();\n resolve(null);\n } else {\n process.stdout.write(\"Invalid choice. Select an option (1-3): \");\n }\n };\n\n rl.on(\"line\", handleAnswer);\n } else {\n console.log(\"\\nNo git remote URL detected.\");\n console.log(\"\\nOptions:\");\n console.log(\"1. Enter GitHub URL manually\");\n console.log(\"2. Skip configuration\");\n\n process.stdout.write(\"\\nSelect an option (1-2): \");\n\n const handleAnswer = (answer: string) => {\n const choice = answer.trim();\n\n if (choice === \"1\") {\n rl.close();\n promptForCustomUrl()\n .then(resolve)\n .catch(() => resolve(null));\n } else if (choice === \"2\") {\n rl.close();\n resolve(null);\n } else {\n process.stdout.write(\"Invalid choice. Select an option (1-2): \");\n }\n };\n\n rl.on(\"line\", handleAnswer);\n }\n });\n}\n\n/**\n * Set git remote URL (origin)\n */\nfunction setGitRemoteUrl(url: string): void {\n try {\n execSync(`git remote add origin ${url}`, {\n stdio: \"inherit\",\n });\n console.log(`✅ Git remote origin set to: ${url}`);\n } catch {\n try {\n execSync(`git remote set-url origin ${url}`, {\n stdio: \"inherit\",\n });\n console.log(`✅ Git remote origin updated to: ${url}`);\n } catch {\n console.error(red(`❌ Failed to set git remote URL`));\n }\n }\n}\n\n/**\n * Validates documents and returns the target document to use\n * Warns if multiple documents found\n */\nfunction validateAndSelectDocument<T>(documents: T[]): T | null {\n if (documents.length === 0) {\n return null;\n }\n\n if (documents.length > 1) {\n console.warn(\n `⚠️ Warning: Multiple Vetra documents found (${documents.length}). Using first document.`,\n );\n }\n\n return documents[0];\n}\n\nasync function applyGithubUrlConfiguration(\n graphqlEndpoint: string,\n vetraDriveId: string,\n documentId: string,\n selectedUrl: string,\n shouldSetRemote: boolean,\n): Promise<void> {\n // Set package GitHub URL\n await setPackageGithubUrl(\n graphqlEndpoint,\n vetraDriveId,\n documentId,\n selectedUrl,\n );\n\n console.log(`✅ GitHub URL configured: ${selectedUrl}`);\n\n // Set git remote URL if requested\n if (shouldSetRemote) {\n setGitRemoteUrl(selectedUrl);\n }\n}\n\nfunction logVerbose(message: string, verbose?: boolean): void {\n if (verbose) {\n console.log(message);\n }\n}\n\n/**\n * Sleep for a specified number of milliseconds\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Configure GitHub URL for Vetra documents\n * @param switchboardPort - Port where switchboard is running\n * @param vetraDriveUrl - Remote drive URL\n * @param verbose - Enable verbose logging\n */\nexport async function configureVetraGithubUrl(\n switchboardPort: number,\n vetraDriveUrl: string,\n verbose?: boolean,\n): Promise<void> {\n logVerbose(\"Checking GitHub URL configuration...\", verbose);\n\n try {\n const graphqlEndpoint = `http://localhost:${switchboardPort}/graphql`;\n const vetraDriveId = vetraDriveUrl.split(\"/\").pop();\n if (!vetraDriveId) {\n throw new Error(\"Invalid vetraDriveUrl: unable to extract drive ID\");\n }\n\n const documents = await getVetraDocuments(graphqlEndpoint, vetraDriveId);\n\n // Skip if already configured\n if (documents.some((doc) => doc.githubUrl)) {\n logVerbose(\"GitHub URL already configured, skipping setup\", verbose);\n return;\n }\n\n // Get or create target document\n let targetDocumentId: string;\n const targetDocument = validateAndSelectDocument(documents);\n\n // Collect user input\n const gitRemoteUrl = getGitRemoteUrl();\n const selectedUrl = await promptForGithubUrl(gitRemoteUrl);\n\n if (!selectedUrl) {\n logVerbose(\"GitHub URL configuration skipped\", verbose);\n return;\n }\n\n let shouldSetRemote = false;\n if (selectedUrl !== gitRemoteUrl && !gitRemoteUrl) {\n shouldSetRemote = await promptYesNo(\"Set this as your git remote URL?\");\n }\n\n if (!targetDocument) {\n logVerbose(\"No Vetra documents found, creating new document...\", verbose);\n\n targetDocumentId = await createVetraDocument(\n graphqlEndpoint,\n vetraDriveId,\n \"vetra-package\",\n );\n\n logVerbose(`Created new document: ${targetDocumentId}`, verbose);\n } else {\n targetDocumentId = targetDocument.id;\n }\n\n await applyGithubUrlConfiguration(\n graphqlEndpoint,\n vetraDriveId,\n targetDocumentId,\n selectedUrl,\n shouldSetRemote,\n );\n } catch (error) {\n console.error(\n red(\n `⚠️ GitHub URL configuration failed: ${error instanceof Error ? error.message : String(error)}`,\n ),\n );\n logVerbose(String(error), verbose);\n }\n}\n","import type { VetraProcessorConfigType } from \"@powerhousedao/config\";\nimport { VETRA_PROCESSOR_CONFIG_KEY } from \"@powerhousedao/config\";\nimport type {\n IDocumentDriveServer,\n IReactorClient,\n} from \"@powerhousedao/reactor\";\nimport { addDefaultDrive } from \"@powerhousedao/switchboard/utils\";\nimport type { ILogger } from \"document-model\";\nimport { blue, green, red, yellow, type Color } from \"colorette\";\nimport { createLogger } from \"vite\";\nimport { childLogger, setLogLevel } from \"document-model\";\nimport type { VetraArgs } from \"../types.js\";\nimport { generateProjectDriveId } from \"../utils.js\";\nimport {\n configureVetraGithubUrl,\n sleep,\n} from \"../utils/configure-vetra-github-url.js\";\nimport { runConnectStudio } from \"./connect-studio.js\";\nimport { startSwitchboard } from \"./switchboard.js\";\n\nconst VETRA_DRIVE_NAME = \"vetra\";\n\nconst getDefaultVetraUrl = (port: number) =>\n `http://localhost:${port}/d/${generateProjectDriveId(VETRA_DRIVE_NAME)}`;\n\nconst getDriveId = (driveUrl: string | undefined): string =>\n driveUrl?.split(\"/\").pop() ?? generateProjectDriveId(VETRA_DRIVE_NAME);\n\nfunction createViteLogger(color: Color) {\n const customLogger = createLogger(\"info\");\n const loggerInfo = customLogger.info.bind(customLogger);\n customLogger.info = (msg, options) => {\n loggerInfo(color(msg), options);\n };\n const loggerWarn = customLogger.warn.bind(customLogger);\n customLogger.warn = (msg, options) => {\n loggerWarn(yellow(msg), options);\n };\n const loggerError = customLogger.error.bind(customLogger);\n customLogger.error = (msg, options) => {\n loggerError(red(msg), options);\n };\n\n const loggerWarnOnce = customLogger.warnOnce.bind(customLogger);\n customLogger.warnOnce = (msg, options) => {\n loggerWarnOnce(yellow(msg), options);\n };\n return customLogger;\n}\n\nasync function startVetraPreviewDrive(\n reactor: IReactorClient,\n port: number,\n verbose?: boolean,\n): Promise<string> {\n const previewDriveId = generateProjectDriveId(\"preview\");\n\n const previewDrive = {\n id: previewDriveId,\n slug: previewDriveId,\n global: {\n name: \"Vetra Preview\",\n icon: \"https://azure-elderly-tortoise-212.mypinata.cloud/ipfs/bafkreifddkbopiyvcirf7vaqar74th424r5phlxkdxniirdyg3qgu2ajha\",\n nodes: [],\n },\n local: {\n availableOffline: true,\n listeners: [],\n sharingType: \"public\" as const,\n triggers: [],\n },\n };\n\n const driveUrl = await addDefaultDrive(reactor, previewDrive, port);\n\n if (verbose) {\n console.log(blue(`Vetra Switchboard: Preview drive: ${driveUrl}`));\n }\n return driveUrl;\n}\nasync function startLocalVetraSwitchboard(args: VetraArgs, logger?: ILogger) {\n const {\n connectPort,\n switchboardPort,\n dev,\n packages,\n disableLocalPackages,\n debug,\n httpsKeyFile,\n httpsCertFile,\n remoteDrive,\n interactive,\n watch,\n verbose,\n } = args;\n\n // Convert single remote drive to array if provided\n const remoteDrives = remoteDrive ? [remoteDrive] : [];\n\n const vetraProcessorConfig: VetraProcessorConfigType = {\n interactive,\n driveUrl: remoteDrive ?? getDefaultVetraUrl(connectPort),\n driveId: getDriveId(remoteDrive),\n };\n\n const processorConfig = new Map<string, unknown>();\n processorConfig.set(VETRA_PROCESSOR_CONFIG_KEY, vetraProcessorConfig);\n\n const vetraDriveId = generateProjectDriveId(VETRA_DRIVE_NAME);\n\n try {\n const switchboard = await startSwitchboard(\n {\n ...args,\n useVetraDrive: true, // Use Vetra drive instead of Powerhouse drive\n mcp: true,\n port: switchboardPort,\n dev,\n packages,\n remoteDrives,\n vetraDriveId,\n disableLocalPackages,\n debug,\n httpsKeyFile,\n httpsCertFile,\n basePath: undefined,\n keypairPath: undefined,\n dbPath: undefined,\n useIdentity: undefined,\n migrate: undefined,\n migrateStatus: undefined,\n requireIdentity: undefined,\n },\n logger,\n );\n\n // Add preview drive (only in watch mode)\n let previewDriveUrl: string | null = null;\n if (watch) {\n try {\n previewDriveUrl = await startVetraPreviewDrive(\n switchboard.reactor,\n switchboardPort,\n verbose,\n );\n } catch (error) {\n console.error(error);\n }\n }\n\n if (verbose) {\n console.log(blue(`Vetra Switchboard: Started successfully`));\n if (remoteDrive) {\n console.log(\n blue(`Vetra Switchboard: Syncing with remote drive: ${remoteDrive}`),\n );\n }\n } else {\n console.log();\n console.log(\n blue(`Vetra Switchboard: http://localhost:${switchboardPort}/graphql`),\n );\n console.log(blue(` ➜ Drive URL: ${switchboard.defaultDriveUrl}`));\n if (previewDriveUrl) {\n console.log(blue(` ➜ Preview Drive URL: ${previewDriveUrl}`));\n }\n }\n return {\n driveUrl: switchboard.defaultDriveUrl || \"\",\n previewDriveUrl: previewDriveUrl,\n };\n } catch (error) {\n console.error(\n red(\n `Vetra Switchboard: ${error instanceof Error ? error.message : String(error)}`,\n ),\n );\n throw error instanceof Error ? error : new Error(String(error));\n }\n}\n\nexport async function startVetra(args: VetraArgs) {\n const {\n switchboardPort,\n connectPort,\n verbose,\n remoteDrive,\n disableConnect,\n debug,\n httpsCertFile,\n httpsKeyFile,\n disableLocalPackages,\n host,\n open,\n cors,\n strictPort,\n printUrls,\n bindCLIShortcuts,\n watchTimeout,\n } = args;\n\n const switchboardLogger = childLogger([\"vetra\", \"switchboard\"]);\n\n try {\n // Set default log level to info if not already specified\n if (!process.env.LOG_LEVEL) {\n setLogLevel(\"info\");\n }\n\n if (verbose) {\n switchboardLogger.info(\"Starting Vetra Switchboard...\");\n if (remoteDrive) {\n const source = remoteDrive\n ? \"command line argument\"\n : \"powerhouse.config.json\";\n switchboardLogger.info(`Using vetraUrl from ${source}: ${remoteDrive}`);\n }\n }\n const switchboardResult = await startLocalVetraSwitchboard(\n {\n ...args,\n dev: true, // Vetra always runs in dev mode to load local packages\n httpsKeyFile,\n httpsCertFile,\n disableLocalPackages,\n debug,\n },\n switchboardLogger,\n );\n const driveUrl: string = switchboardResult.driveUrl || remoteDrive || \"\";\n const previewDriveUrl = switchboardResult.previewDriveUrl;\n\n // Configure GitHub URL if remote drive is set\n if (remoteDrive) {\n // give some time for the drive to process initial strands\n await sleep(3000);\n\n await configureVetraGithubUrl(switchboardPort, remoteDrive, verbose);\n\n // give some time for the user to read log messages\n await sleep(2000);\n }\n\n if (verbose) {\n console.log(\"Starting Codegen Reactor...\");\n }\n\n // Start Connect pointing to the drive (unless disabled)\n if (!disableConnect) {\n if (verbose) {\n console.log(\"Starting Connect...\");\n const drives = previewDriveUrl\n ? `${driveUrl}, ${previewDriveUrl}`\n : driveUrl;\n console.log(` ➜ Connect will use drives: ${drives}`);\n }\n console.log();\n console.log(green(`Vetra Connect: http://localhost:${connectPort}`));\n\n const customViteLogger = createViteLogger(green);\n\n await runConnectStudio(\n {\n ...args,\n defaultDrivesUrl: previewDriveUrl\n ? [driveUrl, previewDriveUrl].join(\",\")\n : driveUrl,\n drivesPreserveStrategy: \"preserve-all\",\n port: connectPort,\n disableLocalPackages,\n debug,\n host: host,\n open: open,\n cors: cors,\n strictPort: strictPort,\n printUrls: printUrls,\n bindCLIShortcuts: bindCLIShortcuts,\n watchTimeout: watchTimeout,\n },\n customViteLogger,\n );\n }\n } catch (error) {\n console.error(error);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAaA,SAAS,kBAAiC;AACxC,KAAI;AAKF,SAJY,SAAS,6BAA6B;GAChD,UAAU;GACV,OAAO;IAAC;IAAQ;IAAQ;IAAO;GAChC,CAAC,CAAC,MAAM,IACK;SACR;AACN,SAAO;;;;;;AAOX,eAAe,qBAA6C;AAC1D,QAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,KAAK,gBAAgB;GACzB,OAAO,QAAQ;GACf,QAAQ,QAAQ;GACjB,CAAC;AAEF,UAAQ,OAAO,MAAM,gDAAgD;AAErE,KAAG,GAAG,SAAS,WAAmB;AAChC,M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AAmB,kBAAkB,YAAY,eAAe;EACtE,MAAM,kBAAkB,kBAAkB;AAG1C,MAAI,aAAa;AAEf,SAAM,MAAM,IAAK;AAEjB,SAAM,wBAAwB,iBAAiB,aAAa,QAAQ;AAGpE,SAAM,MAAM,IAAK;;AAGnB,MAAI,QACF,SAAQ,IAAI,8BAA8B;AAI5C,MAAI,CAAC,gBAAgB;AACnB,OAAI,SAAS;AACX,YAAQ,IAAI,sBAAsB;IAClC,MAAM,SAAS,kBACX,GAAG,SAAS,IAAI,oBAChB;AACJ,YAAQ,IAAI,iCAAiC,SAAS;;AAExD,WAAQ,KAAK;AACb,WAAQ,IAAI,MAAM,mCAAmC,cAAc,CAAC;GAEpE,MAAM,mBAAmB,iBAAiB,MAAM;AAEhD,SAAM,iBACJ;IACE,GAAG;IACH,kBAAkB,kBACd,CAAC,UAAU,gBAAgB,CAAC,KAAK,IAAI,GACrC;IACJ,wBAAwB;IACxB,MAAM;IACN;IACA;IACM;IACA;IACA;IACM;IACD;IACO;IACJ;IACf,EACD,iBACD;;UAEI,OAAO;AACd,UAAQ,MAAM,MAAM"}
1
+ {"version":3,"file":"vetra-Bii4o1sa.mjs","names":[],"sources":["../src/utils/configure-vetra-github-url.ts","../src/services/vetra.ts"],"sourcesContent":["import {\n createVetraDocument,\n getVetraDocuments,\n setPackageGithubUrl,\n} from \"@powerhousedao/common/utils\";\nimport { red } from \"colorette\";\nimport { execSync } from \"node:child_process\";\nimport { createInterface } from \"node:readline\";\n\n/**\n * Get git remote URL (origin)\n * @returns Git remote URL or null if not configured\n */\nfunction getGitRemoteUrl(): string | null {\n try {\n const url = execSync(\"git remote get-url origin\", {\n encoding: \"utf-8\",\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n }).trim();\n return url || null;\n } catch {\n return null;\n }\n}\n\n/**\n * Prompt user to enter a custom GitHub URL\n */\nasync function promptForCustomUrl(): Promise<string | null> {\n return new Promise((resolve) => {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n process.stdout.write(\"\\nEnter GitHub URL (or press Enter to skip): \");\n\n rl.on(\"line\", (answer: string) => {\n rl.close();\n const url = answer.trim();\n resolve(url || null);\n });\n });\n}\n\n/**\n * Prompt yes/no question\n */\nasync function promptYesNo(question: string): Promise<boolean> {\n return new Promise((resolve) => {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n process.stdout.write(`\\n${question} (y/n): `);\n\n rl.on(\"line\", (answer: string) => {\n rl.close();\n const response = answer.trim().toLowerCase();\n resolve(response === \"y\" || response === \"yes\");\n });\n });\n}\n\n/**\n * Prompt user to select or enter GitHub URL\n * @param gitRemoteUrl - Git remote URL if available\n * @returns Selected URL or null if skipped\n */\nasync function promptForGithubUrl(\n gitRemoteUrl: string | null,\n): Promise<string | null> {\n return new Promise((resolve) => {\n const rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n console.log(\"\\n\" + \"=\".repeat(50));\n console.log(\"🔍 Vetra Package Configuration\");\n console.log(\"=\".repeat(50));\n console.log(\n \"\\nWe detected a Vetra package document in your remote drive without a GitHub URL configured.\",\n );\n console.log(\"\\nWould you like to configure the GitHub URL now?\");\n\n if (gitRemoteUrl) {\n console.log(`\\nGit remote URL detected: ${gitRemoteUrl}`);\n console.log(\"\\nOptions:\");\n console.log(\"1. Use detected URL\");\n console.log(\"2. Enter a different URL\");\n console.log(\"3. Skip configuration\");\n\n process.stdout.write(\"\\nSelect an option (1-3): \");\n\n const handleAnswer = (answer: string) => {\n const choice = answer.trim();\n\n if (choice === \"1\") {\n rl.close();\n resolve(gitRemoteUrl);\n } else if (choice === \"2\") {\n rl.close();\n promptForCustomUrl()\n .then(resolve)\n .catch(() => resolve(null));\n } else if (choice === \"3\") {\n rl.close();\n resolve(null);\n } else {\n process.stdout.write(\"Invalid choice. Select an option (1-3): \");\n }\n };\n\n rl.on(\"line\", handleAnswer);\n } else {\n console.log(\"\\nNo git remote URL detected.\");\n console.log(\"\\nOptions:\");\n console.log(\"1. Enter GitHub URL manually\");\n console.log(\"2. Skip configuration\");\n\n process.stdout.write(\"\\nSelect an option (1-2): \");\n\n const handleAnswer = (answer: string) => {\n const choice = answer.trim();\n\n if (choice === \"1\") {\n rl.close();\n promptForCustomUrl()\n .then(resolve)\n .catch(() => resolve(null));\n } else if (choice === \"2\") {\n rl.close();\n resolve(null);\n } else {\n process.stdout.write(\"Invalid choice. Select an option (1-2): \");\n }\n };\n\n rl.on(\"line\", handleAnswer);\n }\n });\n}\n\n/**\n * Set git remote URL (origin)\n */\nfunction setGitRemoteUrl(url: string): void {\n try {\n execSync(`git remote add origin ${url}`, {\n stdio: \"inherit\",\n });\n console.log(`✅ Git remote origin set to: ${url}`);\n } catch {\n try {\n execSync(`git remote set-url origin ${url}`, {\n stdio: \"inherit\",\n });\n console.log(`✅ Git remote origin updated to: ${url}`);\n } catch {\n console.error(red(`❌ Failed to set git remote URL`));\n }\n }\n}\n\n/**\n * Validates documents and returns the target document to use\n * Warns if multiple documents found\n */\nfunction validateAndSelectDocument<T>(documents: T[]): T | null {\n if (documents.length === 0) {\n return null;\n }\n\n if (documents.length > 1) {\n console.warn(\n `⚠️ Warning: Multiple Vetra documents found (${documents.length}). Using first document.`,\n );\n }\n\n return documents[0];\n}\n\nasync function applyGithubUrlConfiguration(\n graphqlEndpoint: string,\n vetraDriveId: string,\n documentId: string,\n selectedUrl: string,\n shouldSetRemote: boolean,\n): Promise<void> {\n // Set package GitHub URL\n await setPackageGithubUrl(\n graphqlEndpoint,\n vetraDriveId,\n documentId,\n selectedUrl,\n );\n\n console.log(`✅ GitHub URL configured: ${selectedUrl}`);\n\n // Set git remote URL if requested\n if (shouldSetRemote) {\n setGitRemoteUrl(selectedUrl);\n }\n}\n\nfunction logVerbose(message: string, verbose?: boolean): void {\n if (verbose) {\n console.log(message);\n }\n}\n\n/**\n * Sleep for a specified number of milliseconds\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Configure GitHub URL for Vetra documents\n * @param switchboardPort - Port where switchboard is running\n * @param vetraDriveUrl - Remote drive URL\n * @param verbose - Enable verbose logging\n */\nexport async function configureVetraGithubUrl(\n switchboardPort: number,\n vetraDriveUrl: string,\n verbose?: boolean,\n): Promise<void> {\n logVerbose(\"Checking GitHub URL configuration...\", verbose);\n\n try {\n const graphqlEndpoint = `http://localhost:${switchboardPort}/graphql`;\n const vetraDriveId = vetraDriveUrl.split(\"/\").pop();\n if (!vetraDriveId) {\n throw new Error(\"Invalid vetraDriveUrl: unable to extract drive ID\");\n }\n\n const documents = await getVetraDocuments(graphqlEndpoint, vetraDriveId);\n\n // Skip if already configured\n if (documents.some((doc) => doc.githubUrl)) {\n logVerbose(\"GitHub URL already configured, skipping setup\", verbose);\n return;\n }\n\n // Get or create target document\n let targetDocumentId: string;\n const targetDocument = validateAndSelectDocument(documents);\n\n // Collect user input\n const gitRemoteUrl = getGitRemoteUrl();\n const selectedUrl = await promptForGithubUrl(gitRemoteUrl);\n\n if (!selectedUrl) {\n logVerbose(\"GitHub URL configuration skipped\", verbose);\n return;\n }\n\n let shouldSetRemote = false;\n if (selectedUrl !== gitRemoteUrl && !gitRemoteUrl) {\n shouldSetRemote = await promptYesNo(\"Set this as your git remote URL?\");\n }\n\n if (!targetDocument) {\n logVerbose(\"No Vetra documents found, creating new document...\", verbose);\n\n targetDocumentId = await createVetraDocument(\n graphqlEndpoint,\n vetraDriveId,\n \"vetra-package\",\n );\n\n logVerbose(`Created new document: ${targetDocumentId}`, verbose);\n } else {\n targetDocumentId = targetDocument.id;\n }\n\n await applyGithubUrlConfiguration(\n graphqlEndpoint,\n vetraDriveId,\n targetDocumentId,\n selectedUrl,\n shouldSetRemote,\n );\n } catch (error) {\n console.error(\n red(\n `⚠️ GitHub URL configuration failed: ${error instanceof Error ? error.message : String(error)}`,\n ),\n );\n logVerbose(String(error), verbose);\n }\n}\n","import type { VetraProcessorConfigType } from \"@powerhousedao/config\";\nimport { VETRA_PROCESSOR_CONFIG_KEY } from \"@powerhousedao/config\";\nimport type {\n IDocumentDriveServer,\n IReactorClient,\n} from \"@powerhousedao/reactor\";\nimport { addDefaultDrive } from \"@powerhousedao/switchboard/utils\";\nimport type { ILogger } from \"document-model\";\nimport { blue, green, red, yellow, type Color } from \"colorette\";\nimport { createLogger } from \"vite\";\nimport { childLogger, setLogLevel } from \"document-model\";\nimport type { VetraArgs } from \"../types.js\";\nimport { generateProjectDriveId } from \"../utils.js\";\nimport {\n configureVetraGithubUrl,\n sleep,\n} from \"../utils/configure-vetra-github-url.js\";\nimport { runConnectStudio } from \"./connect-studio.js\";\nimport { startSwitchboard } from \"./switchboard.js\";\n\nconst VETRA_DRIVE_NAME = \"vetra\";\n\nconst getDefaultVetraUrl = (port: number) =>\n `http://localhost:${port}/d/${generateProjectDriveId(VETRA_DRIVE_NAME)}`;\n\nconst getDriveId = (driveUrl: string | undefined): string =>\n driveUrl?.split(\"/\").pop() ?? generateProjectDriveId(VETRA_DRIVE_NAME);\n\nfunction createViteLogger(color: Color) {\n const customLogger = createLogger(\"info\");\n const loggerInfo = customLogger.info.bind(customLogger);\n customLogger.info = (msg, options) => {\n loggerInfo(color(msg), options);\n };\n const loggerWarn = customLogger.warn.bind(customLogger);\n customLogger.warn = (msg, options) => {\n loggerWarn(yellow(msg), options);\n };\n const loggerError = customLogger.error.bind(customLogger);\n customLogger.error = (msg, options) => {\n loggerError(red(msg), options);\n };\n\n const loggerWarnOnce = customLogger.warnOnce.bind(customLogger);\n customLogger.warnOnce = (msg, options) => {\n loggerWarnOnce(yellow(msg), options);\n };\n return customLogger;\n}\n\nasync function startVetraPreviewDrive(\n reactor: IReactorClient,\n port: number,\n verbose?: boolean,\n): Promise<string> {\n const previewDriveId = generateProjectDriveId(\"preview\");\n\n const previewDrive = {\n id: previewDriveId,\n slug: previewDriveId,\n global: {\n name: \"Vetra Preview\",\n icon: \"https://azure-elderly-tortoise-212.mypinata.cloud/ipfs/bafkreifddkbopiyvcirf7vaqar74th424r5phlxkdxniirdyg3qgu2ajha\",\n nodes: [],\n },\n local: {\n availableOffline: true,\n listeners: [],\n sharingType: \"public\" as const,\n triggers: [],\n },\n };\n\n const driveUrl = await addDefaultDrive(reactor, previewDrive, port);\n\n if (verbose) {\n console.log(blue(`Vetra Switchboard: Preview drive: ${driveUrl}`));\n }\n return driveUrl;\n}\nasync function startLocalVetraSwitchboard(args: VetraArgs, logger?: ILogger) {\n const {\n connectPort,\n switchboardPort,\n dev,\n packages,\n disableLocalPackages,\n debug,\n httpsKeyFile,\n httpsCertFile,\n remoteDrive,\n interactive,\n watch,\n verbose,\n } = args;\n\n // Convert single remote drive to array if provided\n const remoteDrives = remoteDrive ? [remoteDrive] : [];\n\n const vetraProcessorConfig: VetraProcessorConfigType = {\n interactive,\n driveUrl: remoteDrive ?? getDefaultVetraUrl(connectPort),\n driveId: getDriveId(remoteDrive),\n };\n\n const processorConfig = new Map<string, unknown>();\n processorConfig.set(VETRA_PROCESSOR_CONFIG_KEY, vetraProcessorConfig);\n\n const vetraDriveId = generateProjectDriveId(VETRA_DRIVE_NAME);\n\n try {\n const switchboard = await startSwitchboard(\n {\n ...args,\n useVetraDrive: true, // Use Vetra drive instead of Powerhouse drive\n mcp: true,\n port: switchboardPort,\n dev,\n packages,\n remoteDrives,\n vetraDriveId,\n disableLocalPackages,\n debug,\n httpsKeyFile,\n httpsCertFile,\n basePath: undefined,\n keypairPath: undefined,\n dbPath: undefined,\n useIdentity: undefined,\n migrate: undefined,\n migrateStatus: undefined,\n requireIdentity: undefined,\n },\n logger,\n );\n\n // Add preview drive (only in watch mode)\n let previewDriveUrl: string | null = null;\n if (watch) {\n try {\n previewDriveUrl = await startVetraPreviewDrive(\n switchboard.reactor,\n switchboardPort,\n verbose,\n );\n } catch (error) {\n console.error(error);\n }\n }\n\n if (verbose) {\n console.log(blue(`Vetra Switchboard: Started successfully`));\n if (remoteDrive) {\n console.log(\n blue(`Vetra Switchboard: Syncing with remote drive: ${remoteDrive}`),\n );\n }\n } else {\n console.log();\n console.log(\n blue(`Vetra Switchboard: http://localhost:${switchboardPort}/graphql`),\n );\n console.log(blue(` ➜ Drive URL: ${switchboard.defaultDriveUrl}`));\n if (previewDriveUrl) {\n console.log(blue(` ➜ Preview Drive URL: ${previewDriveUrl}`));\n }\n }\n return {\n driveUrl: switchboard.defaultDriveUrl || \"\",\n previewDriveUrl: previewDriveUrl,\n };\n } catch (error) {\n console.error(\n red(\n `Vetra Switchboard: ${error instanceof Error ? error.message : String(error)}`,\n ),\n );\n throw error instanceof Error ? error : new Error(String(error));\n }\n}\n\nexport async function startVetra(args: VetraArgs) {\n const {\n switchboardPort,\n connectPort,\n verbose,\n remoteDrive,\n disableConnect,\n debug,\n httpsCertFile,\n httpsKeyFile,\n disableLocalPackages,\n host,\n open,\n cors,\n strictPort,\n printUrls,\n bindCLIShortcuts,\n watchTimeout,\n } = args;\n\n const switchboardLogger = childLogger([\"vetra\", \"switchboard\"]);\n\n try {\n // Set default log level to info if not already specified\n if (!process.env.LOG_LEVEL) {\n setLogLevel(\"info\");\n }\n\n if (verbose) {\n switchboardLogger.info(\"Starting Vetra Switchboard...\");\n if (remoteDrive) {\n const source = remoteDrive\n ? \"command line argument\"\n : \"powerhouse.config.json\";\n switchboardLogger.info(`Using vetraUrl from ${source}: ${remoteDrive}`);\n }\n }\n const switchboardResult = await startLocalVetraSwitchboard(\n {\n ...args,\n dev: true, // Vetra always runs in dev mode to load local packages\n httpsKeyFile,\n httpsCertFile,\n disableLocalPackages,\n debug,\n },\n switchboardLogger,\n );\n const driveUrl: string = switchboardResult.driveUrl || remoteDrive || \"\";\n const previewDriveUrl = switchboardResult.previewDriveUrl;\n\n // Configure GitHub URL if remote drive is set\n if (remoteDrive) {\n // give some time for the drive to process initial strands\n await sleep(3000);\n\n await configureVetraGithubUrl(switchboardPort, remoteDrive, verbose);\n\n // give some time for the user to read log messages\n await sleep(2000);\n }\n\n if (verbose) {\n console.log(\"Starting Codegen Reactor...\");\n }\n\n // Start Connect pointing to the drive (unless disabled)\n if (!disableConnect) {\n if (verbose) {\n console.log(\"Starting Connect...\");\n const drives = previewDriveUrl\n ? `${driveUrl}, ${previewDriveUrl}`\n : driveUrl;\n console.log(` ➜ Connect will use drives: ${drives}`);\n }\n console.log();\n console.log(green(`Vetra Connect: http://localhost:${connectPort}`));\n\n const customViteLogger = createViteLogger(green);\n\n await runConnectStudio(\n {\n ...args,\n defaultDrivesUrl: previewDriveUrl\n ? [driveUrl, previewDriveUrl].join(\",\")\n : driveUrl,\n drivesPreserveStrategy: \"preserve-all\",\n port: connectPort,\n disableLocalPackages,\n debug,\n host: host,\n open: open,\n cors: cors,\n strictPort: strictPort,\n printUrls: printUrls,\n bindCLIShortcuts: bindCLIShortcuts,\n watchTimeout: watchTimeout,\n },\n customViteLogger,\n );\n }\n } catch (error) {\n console.error(error);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAaA,SAAS,kBAAiC;AACxC,KAAI;AAKF,SAJY,SAAS,6BAA6B;GAChD,UAAU;GACV,OAAO;IAAC;IAAQ;IAAQ;IAAO;GAChC,CAAC,CAAC,MAAM,IACK;SACR;AACN,SAAO;;;;;;AAOX,eAAe,qBAA6C;AAC1D,QAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,KAAK,gBAAgB;GACzB,OAAO,QAAQ;GACf,QAAQ,QAAQ;GACjB,CAAC;AAEF,UAAQ,OAAO,MAAM,gDAAgD;AAErE,KAAG,GAAG,SAAS,WAAmB;AAChC,MAAG,OAAO;AAEV,WADY,OAAO,MAAM,IACV,KAAK;IACpB;GACF;;;;;AAMJ,eAAe,YAAY,UAAoC;AAC7D,QAAO,IAAI,SAAS,YAAY;EAC9B,MAAM,KAAK,gBAAgB;GACzB,OAAO,QAAQ;GACf,QAAQ,QAAQ;GACjB,CAAC;AAEF,UAAQ,OAAO,MAAM,KAAK,SAAS,UAAU;AAE7C,KAAG,GAAG,SAAS,WAAmB;AAChC,MAAG,OAAO;GACV,MAAM,WAAW,OAA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SAAS,IAAI,oBAChB;AACJ,YAAQ,IAAI,iCAAiC,SAAS;;AAExD,WAAQ,KAAK;AACb,WAAQ,IAAI,MAAM,mCAAmC,cAAc,CAAC;GAEpE,MAAM,mBAAmB,iBAAiB,MAAM;AAEhD,SAAM,iBACJ;IACE,GAAG;IACH,kBAAkB,kBACd,CAAC,UAAU,gBAAgB,CAAC,KAAK,IAAI,GACrC;IACJ,wBAAwB;IACxB,MAAM;IACN;IACA;IACM;IACA;IACA;IACM;IACD;IACO;IACJ;IACf,EACD,iBACD;;UAEI,OAAO;AACd,UAAQ,MAAM,MAAM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/ph-cli",
3
- "version": "6.0.0-dev.106",
3
+ "version": "6.0.0-dev.108",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0-only",
6
6
  "type": "module",
@@ -33,15 +33,15 @@
33
33
  "read-pkg": "10.1.0",
34
34
  "ts-morph": "27.0.2",
35
35
  "write-package": "7.2.0",
36
- "document-model": "6.0.0-dev.106",
37
- "@powerhousedao/common": "6.0.0-dev.106",
38
- "@powerhousedao/reactor": "6.0.0-dev.106",
39
- "@powerhousedao/shared": "6.0.0-dev.106",
40
- "@powerhousedao/config": "6.0.0-dev.106",
41
- "@powerhousedao/codegen": "6.0.0-dev.106",
42
- "@powerhousedao/switchboard": "6.0.0-dev.106",
43
- "@powerhousedao/builder-tools": "6.0.0-dev.106",
44
- "@renown/sdk": "6.0.0-dev.106"
36
+ "@powerhousedao/codegen": "6.0.0-dev.108",
37
+ "document-model": "6.0.0-dev.108",
38
+ "@powerhousedao/config": "6.0.0-dev.108",
39
+ "@powerhousedao/common": "6.0.0-dev.108",
40
+ "@powerhousedao/reactor": "6.0.0-dev.108",
41
+ "@powerhousedao/shared": "6.0.0-dev.108",
42
+ "@powerhousedao/switchboard": "6.0.0-dev.108",
43
+ "@powerhousedao/builder-tools": "6.0.0-dev.108",
44
+ "@renown/sdk": "6.0.0-dev.108"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "25.2.3",
@@ -1,2 +0,0 @@
1
- import { t as startGenerate } from "./generate-BfeI7CLg.mjs";
2
- export { startGenerate };
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils-5r3OKhGj.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import type { PowerhouseConfig } from \"@powerhousedao/config\";\nimport crypto from \"node:crypto\";\nimport fs from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport path, { dirname } from \"node:path\";\nexport const POWERHOUSE_CONFIG_FILE = \"powerhouse.config.json\";\nexport const POWERHOUSE_GLOBAL_DIR = path.join(homedir(), \".ph\");\nexport const SUPPORTED_PACKAGE_MANAGERS = [\"npm\", \"yarn\", \"pnpm\", \"bun\"];\n\nexport const packageManagers = {\n bun: {\n globalPathRegexp: /[\\\\/].bun[\\\\/]/,\n installCommand: \"bun add {{dependency}}\",\n uninstallCommand: \"bun remove {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"bun.lock\",\n updateCommand: \"bun update {{dependency}}\",\n buildAffected: \"bun run build:affected\",\n },\n pnpm: {\n globalPathRegexp: /[\\\\/]pnpm[\\\\/]/,\n installCommand: \"pnpm add {{dependency}}\",\n uninstallCommand: \"pnpm remove {{dependency}}\",\n workspaceOption: \"--workspace-root\",\n lockfile: \"pnpm-lock.yaml\",\n updateCommand: \"pnpm update {{dependency}}\",\n buildAffected: \"pnpm run build:affected\",\n },\n yarn: {\n globalPathRegexp: /[\\\\/]yarn[\\\\/]/,\n installCommand: \"yarn add {{dependency}}\",\n uninstallCommand: \"yarn remove {{dependency}}\",\n workspaceOption: \"-W\",\n lockfile: \"yarn.lock\",\n updateCommand: \"yarn upgrade {{dependency}}\",\n buildAffected: \"yarn run build:affected\",\n },\n npm: {\n installCommand: \"npm install {{dependency}}\",\n uninstallCommand: \"npm uninstall {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"package-lock.json\",\n updateCommand: \"npm update {{dependency}} --save\",\n buildAffected: \"npm run build:affected\",\n },\n};\n\ntype PathValidation = (dir: string) => boolean;\n\nexport type PackageManager = \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\nexport type ProjectInfo = {\n isGlobal: boolean;\n path: string;\n packageManager: PackageManager;\n};\n\nexport function defaultPathValidation() {\n return true;\n}\n\nexport function isPowerhouseProject(dir: string) {\n const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);\n\n return fs.existsSync(powerhouseConfigPath);\n}\n\nexport function findNodeProjectRoot(\n dir: string,\n pathValidation: PathValidation = defaultPathValidation,\n) {\n const packageJsonPath = path.join(dir, \"package.json\");\n\n if (fs.existsSync(packageJsonPath) && pathValidation(dir)) {\n return dir;\n }\n\n const parentDir = dirname(dir);\n\n if (parentDir === dir) {\n return null;\n }\n\n return findNodeProjectRoot(parentDir, pathValidation);\n}\n\nexport function getProjectInfo(debug?: boolean): ProjectInfo {\n const currentPath = process.cwd();\n\n if (debug) {\n console.log(\">>> currentPath\", currentPath);\n }\n\n const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);\n\n if (!projectPath) {\n return {\n isGlobal: true,\n path: POWERHOUSE_GLOBAL_DIR,\n packageManager: getPackageManagerFromLockfile(POWERHOUSE_GLOBAL_DIR),\n };\n }\n\n return {\n isGlobal: false,\n path: projectPath,\n packageManager: getPackageManagerFromLockfile(projectPath),\n };\n}\n\n/**\n * Generates a unique drive ID based on the project path.\n * The same project path will always generate the same ID.\n * @param name - The name prefix for the drive ID (e.g., \"vetra\", \"powerhouse\")\n * @returns A unique drive ID in the format \"{name}-{hash}\"\n */\nexport function generateProjectDriveId(name: string): string {\n const projectInfo = getProjectInfo();\n const hash = crypto\n .createHash(\"sha256\")\n .update(projectInfo.path)\n .digest(\"hex\");\n const shortHash = hash.substring(0, 8);\n return `${name}-${shortHash}`;\n}\n\nexport function getPackageManagerFromLockfile(dir: string): PackageManager {\n if (fs.existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {\n return \"pnpm\";\n } else if (fs.existsSync(path.join(dir, packageManagers.yarn.lockfile))) {\n return \"yarn\";\n } else if (fs.existsSync(path.join(dir, packageManagers.bun.lockfile))) {\n return \"bun\";\n }\n\n return \"npm\";\n}\n\nexport function updatePackagesArray(\n currentPackages: PowerhouseConfig[\"packages\"] = [],\n dependencies: { name: string; version: string | undefined }[],\n task: \"install\" | \"uninstall\" = \"install\",\n): PowerhouseConfig[\"packages\"] {\n const isInstall = task === \"install\";\n const mappedPackages = dependencies.map((dep) => ({\n packageName: dep.name,\n version: dep.version,\n provider: \"npm\" as const,\n }));\n\n if (isInstall) {\n // Overwrite existing package if version is different\n const filteredPackages = currentPackages.filter(\n (pkg) => !dependencies.find((dep) => dep.name === pkg.packageName),\n );\n return [...filteredPackages, ...mappedPackages];\n }\n\n return currentPackages.filter(\n (pkg) => !dependencies.map((dep) => dep.name).includes(pkg.packageName),\n );\n}\n\n// Modify updateConfigFile to use the new function\nexport function updateConfigFile(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n task: \"install\" | \"uninstall\" = \"install\",\n) {\n const configPath = path.join(projectPath, POWERHOUSE_CONFIG_FILE);\n\n if (!fs.existsSync(configPath)) {\n throw new Error(\n `powerhouse.config.json file not found. projectPath: ${projectPath}`,\n );\n }\n\n const config = JSON.parse(\n fs.readFileSync(configPath, \"utf-8\"),\n ) as PowerhouseConfig;\n\n const updatedConfig: PowerhouseConfig = {\n ...config,\n packages: updatePackagesArray(config.packages, dependencies, task),\n };\n\n fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));\n}\n\n/**\n * Recursively searches for a specific file by traversing up the directory tree.\n * Starting from the given path, it checks each parent directory until it finds\n * the target file or reaches the root directory.\n *\n * @param startPath - The absolute path of the directory to start searching from\n * @param targetFile - The name of the file to search for (e.g., 'package.json', 'pnpm-workspace.yaml')\n * @returns The absolute path of the directory containing the target file, or null if not found\n *\n * @example\n * // Find the workspace root directory\n * const workspaceRoot = findContainerDirectory('/path/to/project/src', 'pnpm-workspace.yaml');\n *\n * // Find the nearest package.json\n * const packageDir = findContainerDirectory('/path/to/project/src/components', 'package.json');\n */\nexport const findContainerDirectory = (\n startPath: string,\n targetFile: string,\n): string | null => {\n const filePath = path.join(startPath, targetFile);\n\n if (fs.existsSync(filePath)) {\n return startPath;\n }\n\n const parentDir = path.dirname(startPath);\n\n //reached the root directory and haven't found the file\n if (parentDir === startPath) {\n return null;\n }\n\n return findContainerDirectory(parentDir, targetFile);\n};\n\n/**\n * Updates the styles.css file to include imports for newly installed packages\n * @param dependencies - Array of dependencies that were installed\n * @param projectPath - Path to the project root\n */\nexport function updateStylesFile(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n) {\n const stylesPath = path.join(projectPath, \"style.css\");\n\n // Check if styles.css exists\n if (!fs.existsSync(stylesPath)) {\n console.warn(\"⚠️ Warning: style.css file not found in project root\");\n return;\n }\n\n const currentStyles = fs.readFileSync(stylesPath, \"utf-8\");\n let updatedStyles = currentStyles;\n\n for (const dep of dependencies) {\n const cssPath = `./node_modules/${dep.name}/dist/style.css`;\n const fullCssPath = path.join(projectPath, cssPath);\n const importStatement = `@import '${cssPath}';`;\n\n // Check if the CSS file exists\n if (!fs.existsSync(fullCssPath)) {\n console.warn(`⚠️ Warning: CSS file not found at ${cssPath}`);\n continue;\n }\n\n // Check if import already exists\n if (currentStyles.includes(importStatement)) {\n continue;\n }\n\n // Find the last @import statement\n const importLines = currentStyles\n .split(\"\\n\")\n .filter((line) => line.trim().startsWith(\"@import\"));\n const lastImport = importLines[importLines.length - 1];\n\n if (lastImport) {\n // Insert new import after the last existing import\n updatedStyles = currentStyles.replace(\n lastImport,\n `${lastImport}\\n${importStatement}`,\n );\n } else {\n // If no imports exist, add at the top of the file\n updatedStyles = `${importStatement}\\n${currentStyles}`;\n }\n }\n\n // Only write if changes were made\n if (updatedStyles !== currentStyles) {\n fs.writeFileSync(stylesPath, updatedStyles);\n }\n}\n\n/**\n * Removes CSS imports for uninstalled packages from styles.css\n */\nexport function removeStylesImports(\n dependencies: { name: string; version: string | undefined }[],\n projectPath: string,\n) {\n const stylesPath = path.join(projectPath, \"style.css\");\n\n // Check if styles.css exists\n if (!fs.existsSync(stylesPath)) {\n console.warn(\"⚠️ Warning: style.css file not found in project root\");\n return;\n }\n\n const currentStyles = fs.readFileSync(stylesPath, \"utf-8\");\n let updatedStyles = currentStyles;\n\n for (const dep of dependencies) {\n const cssPath = `./node_modules/${dep.name}/dist/style.css`;\n const importStatement = `@import '${cssPath}';`;\n\n // Remove the import line if it exists\n const lines = updatedStyles.split(\"\\n\");\n const filteredLines = lines.filter(\n (line) => !line.trim().includes(importStatement),\n );\n\n if (filteredLines.length !== lines.length) {\n updatedStyles = filteredLines.join(\"\\n\");\n }\n }\n\n // Only write if changes were made\n if (updatedStyles !== currentStyles) {\n fs.writeFileSync(stylesPath, updatedStyles);\n }\n}\n"],"mappings":";;;;;AAKA,MAAa,yBAAyB;AACtC,MAAa,wBAAwB,KAAK,KAAK,SAAS,EAAE,MAAM;AAGhE,MAAa,kBAAkB;CAC7B,KAAK;EACH,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;EAChB;CACD,MAAM;EACJ,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;EAChB;CACD,MAAM;EACJ,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;EAChB;CACD,KAAK;EACH,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;EAChB;CACF;AAYD,SAAgB,wBAAwB;AACtC,QAAO;;AAGT,SAAgB,oBAAoB,KAAa;CAC/C,MAAM,uBAAuB,KAAK,KAAK,KAAK,uBAAuB;AAEnE,QAAO,GAAG,WAAW,qBAAqB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