@powerhousedao/ph-cli 6.2.3-dev.8 → 6.2.3-dev.80
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/{auth-AR3VxAIk.mjs → auth-BFUq7CvE.mjs} +3 -3
- package/dist/{auth-AR3VxAIk.mjs.map → auth-BFUq7CvE.mjs.map} +1 -1
- package/dist/auth-CNhbN5UM.mjs +4 -0
- package/dist/build-t5pFQx0f.mjs +304 -0
- package/dist/build-t5pFQx0f.mjs.map +1 -0
- package/dist/build-wvc_NiGr.mjs +4 -0
- package/dist/check-ecwBLzrg.mjs +56 -0
- package/dist/check-ecwBLzrg.mjs.map +1 -0
- package/dist/{cli-connect-override-D3hh4aH_.mjs → cli-connect-override-DW7OYAGx.mjs} +39 -27
- package/dist/cli-connect-override-DW7OYAGx.mjs.map +1 -0
- package/dist/cli.d.mts +2 -1
- package/dist/cli.mjs +35 -1179
- package/dist/cli.mjs.map +1 -1
- package/dist/compound-C7GuPnTP-Ba4ce2Xa.mjs +2813 -0
- package/dist/compound-C7GuPnTP-Ba4ce2Xa.mjs.map +1 -0
- package/dist/connect-build-7nmQw9c5.mjs +253 -0
- package/dist/connect-build-7nmQw9c5.mjs.map +1 -0
- package/dist/{connect-config-BWGiW3IB.mjs → connect-config-CfQwxG8G.mjs} +19 -12
- package/dist/connect-config-CfQwxG8G.mjs.map +1 -0
- package/dist/connect-plugin-configs-CXN8_KL0.mjs +50 -0
- package/dist/connect-plugin-configs-CXN8_KL0.mjs.map +1 -0
- package/dist/connect-preview-l0Car-nX.mjs +217 -0
- package/dist/connect-preview-l0Car-nX.mjs.map +1 -0
- package/dist/connect-studio-Cac3eE_U.mjs +81 -0
- package/dist/connect-studio-Cac3eE_U.mjs.map +1 -0
- package/dist/connect-studio-Cf6UZvOo.mjs +4 -0
- package/dist/dist-DcARVrSg.mjs +643 -0
- package/dist/dist-DcARVrSg.mjs.map +1 -0
- package/dist/explain-Rx7JW1OU.mjs +230 -0
- package/dist/explain-Rx7JW1OU.mjs.map +1 -0
- package/dist/export-ZnJeAtLS.mjs +42 -0
- package/dist/export-ZnJeAtLS.mjs.map +1 -0
- package/dist/feature-flags-xwqcHEWC.mjs +4 -0
- package/dist/{generate-all-DrT4ZxHX.mjs → generate-all-5Om0CB4N.mjs} +9 -3
- package/dist/generate-all-5Om0CB4N.mjs.map +1 -0
- package/dist/generate-app-hm6CJ_4O.mjs +72 -0
- package/dist/generate-app-hm6CJ_4O.mjs.map +1 -0
- package/dist/generate-desktop-shell-DzEzNspp.mjs +318 -0
- package/dist/generate-desktop-shell-DzEzNspp.mjs.map +1 -0
- package/dist/generate-document-model-CiW13Vf7.mjs +60 -0
- package/dist/generate-document-model-CiW13Vf7.mjs.map +1 -0
- package/dist/generate-editor-kTiUOmDW.mjs +64 -0
- package/dist/generate-editor-kTiUOmDW.mjs.map +1 -0
- package/dist/generate-hosts-BFmPIW2X.mjs +18 -0
- package/dist/generate-hosts-BFmPIW2X.mjs.map +1 -0
- package/dist/generate-hosts-RWj7WPHZ.mjs +4 -0
- package/dist/generate-migration-file-yK8uA70U.mjs +20 -0
- package/dist/generate-migration-file-yK8uA70U.mjs.map +1 -0
- package/dist/generate-piece-C6ymlErL.mjs +73 -0
- package/dist/generate-piece-C6ymlErL.mjs.map +1 -0
- package/dist/generate-piece-action-uYRdKtQA.mjs +29 -0
- package/dist/generate-piece-action-uYRdKtQA.mjs.map +1 -0
- package/dist/generate-piece-trigger-CZaDD-cc.mjs +30 -0
- package/dist/generate-piece-trigger-CZaDD-cc.mjs.map +1 -0
- package/dist/generate-processor-BVjOsfjJ.mjs +58 -0
- package/dist/generate-processor-BVjOsfjJ.mjs.map +1 -0
- package/dist/generate-subgraph-CrHbYK91.mjs +64 -0
- package/dist/generate-subgraph-CrHbYK91.mjs.map +1 -0
- package/dist/get-version-C-oL2owF.mjs +11 -0
- package/dist/get-version-C-oL2owF.mjs.map +1 -0
- package/dist/index-CJN_BRkc.d.mts +4459 -0
- package/dist/index-CJN_BRkc.d.mts.map +1 -0
- package/dist/{init-BZP6gvYd.mjs → init-Ch1rCksS.mjs} +16 -12
- package/dist/init-Ch1rCksS.mjs.map +1 -0
- package/dist/{inspect-DXjbQEV_.mjs → inspect-zWJnBDMJ.mjs} +11 -4
- package/dist/inspect-zWJnBDMJ.mjs.map +1 -0
- package/dist/install-added-dependencies-DnZFR3aE.mjs +18 -0
- package/dist/install-added-dependencies-DnZFR3aE.mjs.map +1 -0
- package/dist/mcp-DvyBEajv.mjs +262 -0
- package/dist/mcp-DvyBEajv.mjs.map +1 -0
- package/dist/member-config-0tHtiVN_.mjs +154 -0
- package/dist/member-config-0tHtiVN_.mjs.map +1 -0
- package/dist/migrate-CIJaE3iZ.mjs +177 -0
- package/dist/migrate-CIJaE3iZ.mjs.map +1 -0
- package/dist/module-dir-1avCXsBi.mjs +17 -0
- package/dist/module-dir-1avCXsBi.mjs.map +1 -0
- package/dist/offered-routes-imports-CQInWI6y.mjs +4 -0
- package/dist/offered-routes-imports-CalXK9dh.mjs +96 -0
- package/dist/offered-routes-imports-CalXK9dh.mjs.map +1 -0
- package/dist/ph-cli-commands-C8eWT5mr.mjs +1600 -0
- package/dist/ph-cli-commands-C8eWT5mr.mjs.map +1 -0
- package/dist/ph-cli-commands-DviLBBKz.mjs +4 -0
- package/dist/precompress-P6cJDPVC.mjs +77 -0
- package/dist/precompress-P6cJDPVC.mjs.map +1 -0
- package/dist/{registry-auth-DxEWCJu2.mjs → registry-auth-Bm5AR-fB.mjs} +4 -4
- package/dist/{registry-auth-DxEWCJu2.mjs.map → registry-auth-Bm5AR-fB.mjs.map} +1 -1
- package/dist/run-sugar-CRzZsmVo.mjs +39 -0
- package/dist/run-sugar-CRzZsmVo.mjs.map +1 -0
- package/dist/runners/connect.d.mts +1153 -0
- package/dist/runners/connect.d.mts.map +1 -0
- package/dist/runners/connect.mjs +300 -0
- package/dist/runners/connect.mjs.map +1 -0
- package/dist/runners/switchboard.d.mts +1481 -0
- package/dist/runners/switchboard.d.mts.map +1 -0
- package/dist/runners/switchboard.mjs +535 -0
- package/dist/runners/switchboard.mjs.map +1 -0
- package/dist/schemas-ByfuhvAb.mjs +5752 -0
- package/dist/schemas-ByfuhvAb.mjs.map +1 -0
- package/dist/scripts/emit-runner-schemas.ts +24 -0
- package/dist/scripts/generate-commands-docs.ts +12 -0
- package/dist/scripts/manage-environment +0 -0
- package/dist/scripts/setup.sh +0 -0
- package/dist/start-run-CRVBqQ8L.mjs +124 -0
- package/dist/start-run-CRVBqQ8L.mjs.map +1 -0
- package/dist/superseded-config-CbSTFun2.mjs +53 -0
- package/dist/superseded-config-CbSTFun2.mjs.map +1 -0
- package/dist/switchboard-B7mvNWcd.mjs +4 -0
- package/dist/switchboard-Cqs5IBNF.mjs +168 -0
- package/dist/switchboard-Cqs5IBNF.mjs.map +1 -0
- package/dist/{switchboard-migrate-NQ7LHWSi.mjs → switchboard-migrate-Docb8Cjv.mjs} +6 -5
- package/dist/{switchboard-migrate-NQ7LHWSi.mjs.map → switchboard-migrate-Docb8Cjv.mjs.map} +1 -1
- package/dist/switchboard-proxy-CGfMtENM.mjs +37 -0
- package/dist/switchboard-proxy-CGfMtENM.mjs.map +1 -0
- package/dist/{switchboard-reset-BcQXlcVf.mjs → switchboard-reset-MtTB_GAI.mjs} +8 -6
- package/dist/switchboard-reset-MtTB_GAI.mjs.map +1 -0
- package/dist/sync-connect-routes-BtAsFPXN.mjs +4 -0
- package/dist/sync-connect-routes-t0Slg-P6.mjs +25 -0
- package/dist/sync-connect-routes-t0Slg-P6.mjs.map +1 -0
- package/dist/{utils-C4isxXSO.mjs → utils-9KyRM0mf.mjs} +6 -34
- package/dist/{utils-C4isxXSO.mjs.map → utils-9KyRM0mf.mjs.map} +1 -1
- package/dist/utils-DAux4Ga7.mjs +4 -0
- package/dist/{vetra-DkF6EJMY.mjs → vetra-DZYtcHqV.mjs} +130 -147
- package/dist/vetra-DZYtcHqV.mjs.map +1 -0
- package/dist/vetra-launch-DQDZxGTV.mjs +343 -0
- package/dist/vetra-launch-DQDZxGTV.mjs.map +1 -0
- package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs +19 -0
- package/dist/warn-subgraph-type-conflicts-BOHBmThq.mjs.map +1 -0
- package/package.json +42 -18
- package/dist/auth-BNkN6kS9.mjs +0 -4
- package/dist/build-C-A5-ipO.mjs +0 -4
- package/dist/build-uQXq6_HU.mjs +0 -71
- package/dist/build-uQXq6_HU.mjs.map +0 -1
- package/dist/cli-connect-override-D3hh4aH_.mjs.map +0 -1
- package/dist/connect-build-WL4axo4z.mjs +0 -43
- package/dist/connect-build-WL4axo4z.mjs.map +0 -1
- package/dist/connect-config-BWGiW3IB.mjs.map +0 -1
- package/dist/connect-preview-D7ypzFDc.mjs +0 -28
- package/dist/connect-preview-D7ypzFDc.mjs.map +0 -1
- package/dist/connect-studio-BIQzyq5B.mjs +0 -5
- package/dist/connect-studio-D6rfWCNB.mjs +0 -31
- package/dist/connect-studio-D6rfWCNB.mjs.map +0 -1
- package/dist/generate-all-DrT4ZxHX.mjs.map +0 -1
- package/dist/generate-app-DNNqA-H3.mjs +0 -48
- package/dist/generate-app-DNNqA-H3.mjs.map +0 -1
- package/dist/generate-document-model-BJXyODfm.mjs +0 -34
- package/dist/generate-document-model-BJXyODfm.mjs.map +0 -1
- package/dist/generate-editor-BejvaVVT.mjs +0 -48
- package/dist/generate-editor-BejvaVVT.mjs.map +0 -1
- package/dist/generate-processor-_WOx-mMe.mjs +0 -40
- package/dist/generate-processor-_WOx-mMe.mjs.map +0 -1
- package/dist/generate-subgraph-BsHUstpl.mjs +0 -38
- package/dist/generate-subgraph-BsHUstpl.mjs.map +0 -1
- package/dist/init-BZP6gvYd.mjs.map +0 -1
- package/dist/inspect-DXjbQEV_.mjs.map +0 -1
- package/dist/migrate-jGKfE02L.mjs +0 -83
- package/dist/migrate-jGKfE02L.mjs.map +0 -1
- package/dist/switchboard-CJMoMzWx.mjs +0 -75
- package/dist/switchboard-CJMoMzWx.mjs.map +0 -1
- package/dist/switchboard-iRFugh8I.mjs +0 -4
- package/dist/switchboard-reset-BcQXlcVf.mjs.map +0 -1
- package/dist/utils-BzwczAW-.mjs +0 -4
- package/dist/vetra-DkF6EJMY.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switchboard-reset-MtTB_GAI.mjs","sources":["../src/services/switchboard-reset.ts"],"sourcesContent":["import { defaultStoreDirs } from \"@powerhousedao/shared/clis/ph-dir\";\nimport { yellow, red, green, cyan } from \"colorette\";\nimport { promises as fs } from \"node:fs\";\n\nexport interface ResetSwitchboardOptions {\n dbPath?: string;\n yes?: boolean;\n}\n\nexport interface ResolvedResetPaths {\n reactorDir: string | null;\n readModelDir: string | null;\n postgresUrl: string | null;\n}\n\nconst CONFIRMATION_TOKEN = \"reset\";\n\nexport function isPostgresUrl(url: string): boolean {\n return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nfunction isInteractive(): boolean {\n return Boolean(process.stdin.isTTY) && !process.env.CI;\n}\n\n/**\n * Resolves the on-disk PGlite directories that `--reset` would delete.\n * Mirrors the resolution in apps/switchboard/src/server.mts so we touch the\n * same paths the running switchboard uses. When a Postgres URL is configured\n * the corresponding directory is null and `postgresUrl` is populated so the\n * caller can refuse.\n */\nexport function resolveResetPaths(\n options: ResetSwitchboardOptions,\n env: NodeJS.ProcessEnv = process.env,\n): ResolvedResetPaths {\n const defaults = defaultStoreDirs(env);\n const readModelDbPath =\n options.dbPath ?? env.DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL;\n const readModelPath = readModelDbPath || defaults.readModel;\n const reactorDbUrl =\n options.dbPath ??\n env.PH_REACTOR_DATABASE_URL ??\n env.PH_SWITCHBOARD_DATABASE_URL;\n const reactorPath = reactorDbUrl || defaults.reactor;\n\n const reactorIsPostgres = !!reactorDbUrl && isPostgresUrl(reactorDbUrl);\n const readModelIsPostgres =\n !!readModelDbPath && isPostgresUrl(readModelDbPath);\n\n let postgresUrl: string | null = null;\n if (reactorIsPostgres) postgresUrl = reactorDbUrl as string;\n else if (readModelIsPostgres) postgresUrl = readModelDbPath as string;\n\n return {\n reactorDir: reactorIsPostgres ? null : reactorPath,\n readModelDir: readModelIsPostgres ? null : readModelPath,\n postgresUrl,\n };\n}\n\nasync function promptForConfirmation(): Promise<boolean> {\n const enquirer = await import(\"enquirer\");\n try {\n const answer = await enquirer.default.prompt<{ confirmation: string }>({\n type: \"input\",\n name: \"confirmation\",\n message: `Type \"${CONFIRMATION_TOKEN}\" to confirm wiping the local switchboard databases:`,\n });\n return answer.confirmation.trim() === CONFIRMATION_TOKEN;\n } catch {\n return false;\n }\n}\n\nexport async function resetSwitchboardDatabase(\n options: ResetSwitchboardOptions,\n): Promise<void> {\n const paths = resolveResetPaths(options);\n\n if (paths.postgresUrl) {\n console.error(\n red(\n `Refusing to reset: a PostgreSQL URL is configured (${paths.postgresUrl}).`,\n ),\n );\n console.error(\n yellow(\n \"`ph switchboard --reset` only wipes the local PGlite stores. \" +\n \"To reset a Postgres-backed switchboard, drop/recreate the database manually.\",\n ),\n );\n process.exit(1);\n }\n\n const targets = [paths.reactorDir, paths.readModelDir].filter(\n (d): d is string => d !== null,\n );\n\n if (targets.length === 0) {\n console.error(red(\"No local PGlite directories resolved; nothing to do.\"));\n process.exit(1);\n }\n\n console.log(yellow(\"The following directories will be permanently deleted:\"));\n for (const dir of targets) {\n console.log(` - ${dir}`);\n }\n console.log(\n yellow(\n \"This will wipe all local switchboard state. Migrations will re-run on next `ph switchboard`.\",\n ),\n );\n\n let confirmed = false;\n if (options.yes) {\n confirmed = true;\n } else if (isInteractive()) {\n confirmed = await promptForConfirmation();\n } else {\n console.error(\n red(\n \"Refusing to reset in a non-interactive context without --yes. Re-run with --yes to confirm.\",\n ),\n );\n process.exit(1);\n }\n\n if (!confirmed) {\n console.error(red(\"Aborted: confirmation not provided.\"));\n process.exit(1);\n }\n\n for (const dir of targets) {\n await fs.rm(dir, { recursive: true, force: true });\n console.log(cyan(`Removed ${dir}`));\n }\n\n console.log(\n green(\n \"Switchboard local storage reset. Run `ph switchboard` to re-initialize.\",\n ),\n );\n}\n"],"names":["fs"],"mappings":";;;;;;AAeA,MAAM,qBAAqB;AAE3B,SAAgB,cAAc,KAAsB;CAClD,OAAO,IAAI,WAAW,eAAe,KAAK,IAAI,WAAW,aAAa;AACxE;AAEA,SAAS,gBAAyB;CAChC,OAAO,QAAQ,QAAQ,MAAM,KAAK,KAAK,CAAC,QAAQ,IAAI;AACtD;;;;;;;;AASA,SAAgB,kBACd,SACA,MAAyB,QAAQ,KACb;CACpB,MAAM,WAAW,iBAAiB,GAAG;CACrC,MAAM,kBACJ,QAAQ,UAAU,IAAI,gBAAgB,IAAI;CAC5C,MAAM,gBAAgB,mBAAmB,SAAS;CAClD,MAAM,eACJ,QAAQ,UACR,IAAI,2BACJ,IAAI;CACN,MAAM,cAAc,gBAAgB,SAAS;CAE7C,MAAM,oBAAoB,CAAC,CAAC,gBAAgB,cAAc,YAAY;CACtE,MAAM,sBACJ,CAAC,CAAC,mBAAmB,cAAc,eAAe;CAEpD,IAAI,cAA6B;CACjC,IAAI,mBAAmB,cAAc;MAChC,IAAI,qBAAqB,cAAc;CAE5C,OAAO;EACL,YAAY,oBAAoB,OAAO;EACvC,cAAc,sBAAsB,OAAO;EAC3C;CACF;AACF;AAEA,eAAe,wBAA0C;CACvD,MAAM,WAAW,MAAM,OAAO;CAC9B,IAAI;EAMF,QAAO,MALc,SAAS,QAAQ,OAAiC;GACrE,MAAM;GACN,MAAM;GACN,SAAS,SAAS,mBAAmB;EACvC,CAAC,EAAA,CACa,aAAa,KAAK,MAAM;CACxC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,yBACpB,SACe;CACf,MAAM,QAAQ,kBAAkB,OAAO;CAEvC,IAAI,MAAM,aAAa;EACrB,QAAQ,MACN,IACE,sDAAsD,MAAM,YAAY,GAC1E,CACF;EACA,QAAQ,MACN,OACE,2IAEF,CACF;EACA,QAAQ,KAAK,CAAC;CAChB;CAEA,MAAM,UAAU,CAAC,MAAM,YAAY,MAAM,YAAY,CAAC,CAAC,QACpD,MAAmB,MAAM,IAC5B;CAEA,IAAI,QAAQ,WAAW,GAAG;EACxB,QAAQ,MAAM,IAAI,sDAAsD,CAAC;EACzE,QAAQ,KAAK,CAAC;CAChB;CAEA,QAAQ,IAAI,OAAO,wDAAwD,CAAC;CAC5E,KAAK,MAAM,OAAO,SAChB,QAAQ,IAAI,OAAO,KAAK;CAE1B,QAAQ,IACN,OACE,8FACF,CACF;CAEA,IAAI,YAAY;CAChB,IAAI,QAAQ,KACV,YAAY;MACP,IAAI,cAAc,GACvB,YAAY,MAAM,sBAAsB;MACnC;EACL,QAAQ,MACN,IACE,6FACF,CACF;EACA,QAAQ,KAAK,CAAC;CAChB;CAEA,IAAI,CAAC,WAAW;EACd,QAAQ,MAAM,IAAI,qCAAqC,CAAC;EACxD,QAAQ,KAAK,CAAC;CAChB;CAEA,KAAK,MAAM,OAAO,SAAS;EACzB,MAAMA,SAAG,GAAG,KAAK;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;EACjD,QAAQ,IAAI,KAAK,WAAW,KAAK,CAAC;CACpC;CAEA,QAAQ,IACN,MACE,yEACF,CACF;AACF","debug_id":"44d0c080-10cc-5316-947d-b0281777aade"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { r as syncProjectConnectRoutes } from "./sync-connect-routes-t0Slg-P6.mjs";
|
|
2
|
+
export { syncProjectConnectRoutes };
|
|
3
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a0e16059-68ca-5115-9c0e-68e1b5113d9c")}catch(e){}}();
|
|
4
|
+
//# debugId=a0e16059-68ca-5115-9c0e-68e1b5113d9c
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="635b041c-5cc1-56f7-aac5-714511c1dd4c")}catch(e){}}();
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
//#region src/utils/sync-connect-routes.ts
|
|
6
|
+
const OFFERED_ROUTES_MODULE = ".ph/connect-routes.package.ts";
|
|
7
|
+
const HOST_ROUTES_DIR = "hosts/connect/routes";
|
|
8
|
+
const CONNECT_ROUTES_GEN = ".ph/connect-routes.gen.ts";
|
|
9
|
+
/** Writes the tree hosts/connect/routes/ type-checks against; without the
|
|
10
|
+
* folder, a tree there keeps Connect's routes only. Loads builder-tools only
|
|
11
|
+
* for a project with routes or a tree. */
|
|
12
|
+
async function syncProjectConnectRoutes(projectRoot) {
|
|
13
|
+
if (![
|
|
14
|
+
"hosts/connect/routes",
|
|
15
|
+
CONNECT_ROUTES_GEN,
|
|
16
|
+
".ph/connect-routes.package.ts"
|
|
17
|
+
].some((p) => existsSync(join(projectRoot, p)))) return;
|
|
18
|
+
const { resolveConnectRoutesDir, syncConnectRoutes } = await import("@powerhousedao/builder-tools");
|
|
19
|
+
await syncConnectRoutes(projectRoot, resolveConnectRoutesDir(projectRoot));
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { OFFERED_ROUTES_MODULE as n, syncProjectConnectRoutes as r, HOST_ROUTES_DIR as t };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=sync-connect-routes-t0Slg-P6.mjs.map
|
|
25
|
+
//# debugId=635b041c-5cc1-56f7-aac5-714511c1dd4c
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-connect-routes-t0Slg-P6.mjs","sources":["../src/utils/sync-connect-routes.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\n// builder-tools' PACKAGE_ROUTES_MODULE and HOST_ROUTES_DIR, without loading it\n// for packages with no routes.\nexport const OFFERED_ROUTES_MODULE = \".ph/connect-routes.package.ts\";\nexport const HOST_ROUTES_DIR = \"hosts/connect/routes\";\nconst CONNECT_ROUTES_GEN = \".ph/connect-routes.gen.ts\";\n\n/** Writes the tree hosts/connect/routes/ type-checks against; without the\n * folder, a tree there keeps Connect's routes only. Loads builder-tools only\n * for a project with routes or a tree. */\nexport async function syncProjectConnectRoutes(projectRoot: string) {\n const probes = [HOST_ROUTES_DIR, CONNECT_ROUTES_GEN, OFFERED_ROUTES_MODULE];\n if (!probes.some((p) => existsSync(join(projectRoot, p)))) return;\n const { resolveConnectRoutesDir, syncConnectRoutes } =\n await import(\"@powerhousedao/builder-tools\");\n await syncConnectRoutes(projectRoot, resolveConnectRoutesDir(projectRoot));\n}\n"],"names":[],"mappings":";;;;;AAKA,MAAa,wBAAwB;AACrC,MAAa,kBAAkB;AAC/B,MAAM,qBAAqB;;;;AAK3B,eAAsB,yBAAyB,aAAqB;CAElE,IAAI,CAAC;;EAD4B;;CACvB,CAAC,CAAC,MAAM,MAAM,WAAW,KAAK,aAAa,CAAC,CAAC,CAAC,GAAG;CAC3D,MAAM,EAAE,yBAAyB,sBAC/B,MAAM,OAAO;CACf,MAAM,kBAAkB,aAAa,wBAAwB,WAAW,CAAC;AAC3E","debug_id":"635b041c-5cc1-56f7-aac5-714511c1dd4c"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e3fbf59a-7996-5c5c-9db7-c8d207b68849")}catch(e){}}();
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path, { dirname } from "node:path";
|
|
5
5
|
import crypto from "node:crypto";
|
|
@@ -111,36 +111,8 @@ function updateConfigFile(dependencies, projectPath, task = "install", provider
|
|
|
111
111
|
fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* @param projectPath - Path to the project root
|
|
117
|
-
*/
|
|
118
|
-
function updateStylesFile(dependencies, projectPath) {
|
|
119
|
-
const stylesPath = path.join(projectPath, "style.css");
|
|
120
|
-
if (!fs.existsSync(stylesPath)) {
|
|
121
|
-
console.warn("⚠️ Warning: style.css file not found in project root");
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const currentStyles = fs.readFileSync(stylesPath, "utf-8");
|
|
125
|
-
let updatedStyles = currentStyles;
|
|
126
|
-
for (const dep of dependencies) {
|
|
127
|
-
const cssPath = `./node_modules/${dep.name}/dist/style.css`;
|
|
128
|
-
const fullCssPath = path.join(projectPath, cssPath);
|
|
129
|
-
const importStatement = `@import '${cssPath}';`;
|
|
130
|
-
if (!fs.existsSync(fullCssPath)) {
|
|
131
|
-
console.warn(`⚠️ Warning: CSS file not found at ${cssPath}`);
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
if (currentStyles.includes(importStatement)) continue;
|
|
135
|
-
const importLines = currentStyles.split("\n").filter((line) => line.trim().startsWith("@import"));
|
|
136
|
-
const lastImport = importLines[importLines.length - 1];
|
|
137
|
-
if (lastImport) updatedStyles = currentStyles.replace(lastImport, `${lastImport}\n${importStatement}`);
|
|
138
|
-
else updatedStyles = `${importStatement}\n${currentStyles}`;
|
|
139
|
-
}
|
|
140
|
-
if (updatedStyles !== currentStyles) fs.writeFileSync(stylesPath, updatedStyles);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Removes CSS imports for uninstalled packages from styles.css
|
|
114
|
+
* Removes the CSS imports `ph install --local` used to add to style.css for
|
|
115
|
+
* uninstalled packages; Connect now loads a bundled package's CSS with its code.
|
|
144
116
|
*/
|
|
145
117
|
function removeStylesImports(dependencies, projectPath) {
|
|
146
118
|
const stylesPath = path.join(projectPath, "style.css");
|
|
@@ -159,7 +131,7 @@ function removeStylesImports(dependencies, projectPath) {
|
|
|
159
131
|
if (updatedStyles !== currentStyles) fs.writeFileSync(stylesPath, updatedStyles);
|
|
160
132
|
}
|
|
161
133
|
//#endregion
|
|
162
|
-
export { generateProjectDriveId as a, isPowerhouseProject as c, updateConfigFile as d, updatePackagesArray as f, findNodeProjectRoot as i, packageManagers as l, POWERHOUSE_GLOBAL_DIR as n, getPackageManagerFromLockfile as o,
|
|
134
|
+
export { generateProjectDriveId as a, isPowerhouseProject as c, updateConfigFile as d, updatePackagesArray as f, findNodeProjectRoot as i, packageManagers as l, POWERHOUSE_GLOBAL_DIR as n, getPackageManagerFromLockfile as o, defaultPathValidation as r, getProjectInfo as s, POWERHOUSE_CONFIG_FILE as t, removeStylesImports as u };
|
|
163
135
|
|
|
164
|
-
//# sourceMappingURL=utils-
|
|
165
|
-
//# debugId=
|
|
136
|
+
//# sourceMappingURL=utils-9KyRM0mf.mjs.map
|
|
137
|
+
//# debugId=e3fbf59a-7996-5c5c-9db7-c8d207b68849
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-C4isxXSO.mjs","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 provider: \"registry\" | \"local\" = \"registry\",\n): PowerhouseConfig[\"packages\"] {\n const isInstall = task === \"install\";\n const mappedPackages = dependencies.map((dep) => ({\n packageName: dep.name,\n version: dep.version,\n provider,\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 provider: \"registry\" | \"local\" = \"registry\",\n registryUrl?: string,\n registryUrlExplicit = false,\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(\n config.packages,\n dependencies,\n task,\n provider,\n ),\n };\n\n if (\n task === \"install\" &&\n registryUrl &&\n (registryUrlExplicit || !config.packageRegistryUrl) &&\n dependencies.length > 0\n ) {\n updatedConfig.packageRegistryUrl = registryUrl;\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"],"names":[],"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,MAAM,kBAAkB,KAAK,KAAK,KAAK,eAAe;AAEtD,KAAI,GAAG,WAAW,gBAAgB,IAAI,eAAe,IAAI,CACvD,QAAO;CAGT,MAAM,YAA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B,IAAI;;AAK3C,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","debug_id":"73159d3c-22a7-5dc6-8bd4-7b15f3b94c79"}
|
|
1
|
+
{"version":3,"file":"utils-9KyRM0mf.mjs","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 provider: \"registry\" | \"local\" = \"registry\",\n): PowerhouseConfig[\"packages\"] {\n const isInstall = task === \"install\";\n const mappedPackages = dependencies.map((dep) => ({\n packageName: dep.name,\n version: dep.version,\n provider,\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 provider: \"registry\" | \"local\" = \"registry\",\n registryUrl?: string,\n registryUrlExplicit = false,\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(\n config.packages,\n dependencies,\n task,\n provider,\n ),\n };\n\n if (\n task === \"install\" &&\n registryUrl &&\n (registryUrlExplicit || !config.packageRegistryUrl) &&\n dependencies.length > 0\n ) {\n updatedConfig.packageRegistryUrl = registryUrl;\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 * Removes the CSS imports `ph install --local` used to add to style.css for\n * uninstalled packages; Connect now loads a bundled package's CSS with its code.\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"],"names":[],"mappings":";;;;;;;AAKA,MAAa,yBAAyB;AACtC,MAAa,wBAAwB,KAAK,KAAK,QAAQ,GAAG,KAAK;AAG/D,MAAa,kBAAkB;CAC7B,KAAK;EACH,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;CACjB;CACA,MAAM;EACJ,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;CACjB;CACA,MAAM;EACJ,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;CACjB;CACA,KAAK;EACH,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;EACjB,UAAU;EACV,eAAe;EACf,eAAe;CACjB;AACF;AAYA,SAAgB,wBAAwB;CACtC,OAAO;AACT;AAEA,SAAgB,oBAAoB,KAAa;CAC/C,MAAM,uBAAuB,KAAK,KAAK,KAAK,sBAAsB;CAElE,OAAO,GAAG,WAAW,oBAAoB;AAC3C;AAEA,SAAgB,oBACd,KACA,iBAAiC,uBACjC;CACA,MAAM,kBAAkB,KAAK,KAAK,KAAK,cAAc;CAErD,IAAI,GAAG,WAAW,eAAe,KAAK,eA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@@
|
|
|
1
|
+
import { a as generateProjectDriveId, d as updateConfigFile, u as removeStylesImports } from "./utils-9KyRM0mf.mjs";
|
|
2
|
+
export { generateProjectDriveId, removeStylesImports, updateConfigFile };
|
|
3
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="7c1a1a3f-92dd-5f1b-bad9-e92f9f6be654")}catch(e){}}();
|
|
4
|
+
//# debugId=7c1a1a3f-92dd-5f1b-bad9-e92f9f6be654
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="52a29815-857a-5f84-b065-1de4bc5d740f")}catch(e){}}();
|
|
3
|
+
import { m as rebaseDriveUrl, o as mergeDefaultDrives } from "./dist-DcARVrSg.mjs";
|
|
4
|
+
import { a as parseDefaultDrivesUrl, i as wasFlagExplicitlyPassed } from "./cli-connect-override-DW7OYAGx.mjs";
|
|
5
|
+
import { t as runConnectStudio } from "./connect-studio-Cac3eE_U.mjs";
|
|
6
|
+
import { a as generateProjectDriveId, t as POWERHOUSE_CONFIG_FILE } from "./utils-9KyRM0mf.mjs";
|
|
7
|
+
import { a as stopVetra, c as probeVetraRuntime, d as writeVetraRuntime, o as clearVetraRuntime, s as legacyMcpConfigs, u as syncMcpPort } from "./vetra-launch-DQDZxGTV.mjs";
|
|
8
|
+
import { a as POWERHOUSE_DRIVE_ICON, r as startSwitchboard$1 } from "./switchboard-Cqs5IBNF.mjs";
|
|
9
|
+
import { join } from "node:path";
|
|
7
10
|
import { execSync } from "node:child_process";
|
|
8
11
|
import { blue, green, red, yellow } from "colorette";
|
|
9
|
-
import
|
|
10
|
-
import path from "node:path";
|
|
12
|
+
import { getConfig } from "@powerhousedao/shared/clis";
|
|
11
13
|
import { createLogger } from "vite";
|
|
12
14
|
import { createVetraDocument, getVetraDocuments, setPackageGithubUrl } from "@powerhousedao/common/utils";
|
|
13
15
|
import { isPortAvailable } from "@powerhousedao/switchboard/server";
|
|
@@ -254,121 +256,10 @@ async function resolveSwitchboardPort(requested) {
|
|
|
254
256
|
return candidate;
|
|
255
257
|
}
|
|
256
258
|
//#endregion
|
|
257
|
-
//#region src/utils/vetra-runtime.ts
|
|
258
|
-
const RECORD_REL = path.join(".ph", "vetra-runtime.json");
|
|
259
|
-
const READY_TIMEOUT_MS = 2e3;
|
|
260
|
-
const recordPath = (projectDir) => path.join(projectDir, RECORD_REL);
|
|
261
|
-
function readVetraRuntime(projectDir) {
|
|
262
|
-
try {
|
|
263
|
-
return JSON.parse(fs.readFileSync(recordPath(projectDir), "utf8"));
|
|
264
|
-
} catch {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
function writeVetraRuntime(projectDir, record) {
|
|
269
|
-
const target = recordPath(projectDir);
|
|
270
|
-
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
271
|
-
fs.writeFileSync(target, `${JSON.stringify(record, null, 2)}\n`);
|
|
272
|
-
}
|
|
273
|
-
function clearVetraRuntime(projectDir) {
|
|
274
|
-
try {
|
|
275
|
-
fs.rmSync(recordPath(projectDir));
|
|
276
|
-
} catch {}
|
|
277
|
-
}
|
|
278
|
-
function isPidAlive(pid) {
|
|
279
|
-
try {
|
|
280
|
-
process.kill(pid, 0);
|
|
281
|
-
return true;
|
|
282
|
-
} catch (error) {
|
|
283
|
-
return error.code === "EPERM";
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
async function isReady(port) {
|
|
287
|
-
try {
|
|
288
|
-
return (await fetch(`http://localhost:${port}/ready`, { signal: AbortSignal.timeout(READY_TIMEOUT_MS) })).ok;
|
|
289
|
-
} catch {
|
|
290
|
-
return false;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Decide whether the recorded instance is actually serving this project.
|
|
295
|
-
*
|
|
296
|
-
* All three checks are load-bearing. A pid can be reused by an unrelated
|
|
297
|
-
* process, so a live pid proves nothing on its own. Another project's
|
|
298
|
-
* switchboard would answer `/ready` on its own port, so a healthy `/ready`
|
|
299
|
-
* proves nothing either. And the recorded `projectName` is what separates
|
|
300
|
-
* "my instance" from "someone else's instance that happens to hold this
|
|
301
|
-
* port" — which is precisely the confusion that let an agent write document
|
|
302
|
-
* models into a different project's drive.
|
|
303
|
-
*
|
|
304
|
-
* A stale record is deleted so the next start is unblocked. A foreign one is
|
|
305
|
-
* left alone: it describes something that is alive.
|
|
306
|
-
*/
|
|
307
|
-
async function probeVetraRuntime(projectDir, projectName) {
|
|
308
|
-
const record = readVetraRuntime(projectDir);
|
|
309
|
-
if (!record) return { status: "none" };
|
|
310
|
-
if (!isPidAlive(record.pid) || !await isReady(record.switchboardPort)) {
|
|
311
|
-
clearVetraRuntime(projectDir);
|
|
312
|
-
return { status: "stale" };
|
|
313
|
-
}
|
|
314
|
-
if (record.projectName !== projectName) return {
|
|
315
|
-
status: "foreign",
|
|
316
|
-
record
|
|
317
|
-
};
|
|
318
|
-
return {
|
|
319
|
-
status: "live",
|
|
320
|
-
record
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
const MCP_FILES = [".mcp.json", path.join(".cursor", "mcp.json")];
|
|
324
|
-
/**
|
|
325
|
-
* Point every generated MCP config at `port`, returning the files changed.
|
|
326
|
-
*
|
|
327
|
-
* An MCP client resolves these files at session start and cannot read the
|
|
328
|
-
* project config or `.env`, so when an override moves the port the literal
|
|
329
|
-
* has to be corrected on disk. Rewrites in place rather than regenerating,
|
|
330
|
-
* so any other servers or hand-added keys survive.
|
|
331
|
-
*/
|
|
332
|
-
function syncMcpPort(projectDir, port) {
|
|
333
|
-
const changed = [];
|
|
334
|
-
for (const rel of MCP_FILES) {
|
|
335
|
-
const target = path.join(projectDir, rel);
|
|
336
|
-
if (!fs.existsSync(target)) continue;
|
|
337
|
-
let parsed;
|
|
338
|
-
try {
|
|
339
|
-
parsed = JSON.parse(fs.readFileSync(target, "utf8"));
|
|
340
|
-
} catch {
|
|
341
|
-
continue;
|
|
342
|
-
}
|
|
343
|
-
const server = parsed.mcpServers?.["reactor-mcp"];
|
|
344
|
-
if (!server?.url) continue;
|
|
345
|
-
const wanted = `http://localhost:${port}/mcp`;
|
|
346
|
-
if (server.url === wanted) continue;
|
|
347
|
-
server.url = wanted;
|
|
348
|
-
fs.writeFileSync(target, `${JSON.stringify(parsed, null, 2)}\n`);
|
|
349
|
-
changed.push(rel);
|
|
350
|
-
}
|
|
351
|
-
return changed;
|
|
352
|
-
}
|
|
353
|
-
//#endregion
|
|
354
259
|
//#region src/services/vetra.ts
|
|
355
260
|
const VETRA_DRIVE_NAME = "vetra";
|
|
356
261
|
const getDefaultVetraUrl = (port) => `http://localhost:${port}/d/${generateProjectDriveId(VETRA_DRIVE_NAME)}`;
|
|
357
262
|
const getDriveId = (driveUrl) => driveUrl?.split("/").pop() ?? generateProjectDriveId(VETRA_DRIVE_NAME);
|
|
358
|
-
const rebaseDriveUrl = (driveUrl, publicBase) => {
|
|
359
|
-
let url;
|
|
360
|
-
try {
|
|
361
|
-
url = new URL(driveUrl);
|
|
362
|
-
} catch {
|
|
363
|
-
return driveUrl;
|
|
364
|
-
}
|
|
365
|
-
if (![
|
|
366
|
-
"localhost",
|
|
367
|
-
"127.0.0.1",
|
|
368
|
-
"[::1]"
|
|
369
|
-
].includes(url.hostname)) return driveUrl;
|
|
370
|
-
return `${publicBase.replace(/\/+$/, "")}${url.pathname}`;
|
|
371
|
-
};
|
|
372
263
|
function createViteLogger(color) {
|
|
373
264
|
const customLogger = createLogger("info");
|
|
374
265
|
const loggerInfo = customLogger.info.bind(customLogger);
|
|
@@ -389,14 +280,15 @@ function createViteLogger(color) {
|
|
|
389
280
|
};
|
|
390
281
|
return customLogger;
|
|
391
282
|
}
|
|
392
|
-
|
|
283
|
+
/** Creates the Vetra Preview drive, or opens it, and opens it in `app` when given. */
|
|
284
|
+
async function startVetraPreviewDrive(reactor, port, verbose, app) {
|
|
393
285
|
const previewDriveId = generateProjectDriveId("preview");
|
|
394
286
|
const driveUrl = await addDefaultDrive(reactor, {
|
|
395
287
|
id: previewDriveId,
|
|
396
288
|
slug: previewDriveId,
|
|
397
289
|
global: {
|
|
398
290
|
name: "Vetra Preview",
|
|
399
|
-
icon:
|
|
291
|
+
icon: POWERHOUSE_DRIVE_ICON,
|
|
400
292
|
nodes: []
|
|
401
293
|
},
|
|
402
294
|
local: {
|
|
@@ -404,10 +296,44 @@ async function startVetraPreviewDrive(reactor, port, verbose) {
|
|
|
404
296
|
listeners: [],
|
|
405
297
|
sharingType: "public",
|
|
406
298
|
triggers: []
|
|
407
|
-
}
|
|
299
|
+
},
|
|
300
|
+
preferredEditor: app
|
|
408
301
|
}, port);
|
|
409
|
-
if (
|
|
410
|
-
|
|
302
|
+
if (app && driveUrl) await openDriveIn(reactor, previewDriveId, app);
|
|
303
|
+
if (verbose && driveUrl) console.log(blue(`Vetra Switchboard: Preview drive: ${driveUrl}`));
|
|
304
|
+
return driveUrl ?? null;
|
|
305
|
+
}
|
|
306
|
+
/** Sets the drive's app unless it already has it; a drive from an earlier run keeps its old one otherwise. */
|
|
307
|
+
async function openDriveIn(reactor, driveId, app) {
|
|
308
|
+
if ((await reactor.read.get(driveId)).header.meta?.preferredEditor === app) return;
|
|
309
|
+
await (await reactor.write.setPreferredEditor(driveId, app)).readable;
|
|
310
|
+
}
|
|
311
|
+
function buildVetraStudioOverride(defaultDrives, options = {}) {
|
|
312
|
+
const override = { drives: {
|
|
313
|
+
defaultDrives,
|
|
314
|
+
preserveStrategy: "preserve-all"
|
|
315
|
+
} };
|
|
316
|
+
if (options.projectConnect?.app?.cookieBanner === void 0) override.app = { cookieBanner: false };
|
|
317
|
+
const instance = options.projectConnect?.instance;
|
|
318
|
+
if (!options.remoteDrive && instance?.multiReactor === void 0 && instance?.reactorClient === void 0) override.instance = { reactorClient: "remote" };
|
|
319
|
+
return override;
|
|
320
|
+
}
|
|
321
|
+
async function seedWorkflowsDrive(reactor, port, verbose) {
|
|
322
|
+
const workflowsDrive = {
|
|
323
|
+
id: generateProjectDriveId("workflows"),
|
|
324
|
+
slug: "workflows",
|
|
325
|
+
global: { name: "Workflows" },
|
|
326
|
+
preferredEditor: "workflow-studio",
|
|
327
|
+
local: {
|
|
328
|
+
availableOffline: true,
|
|
329
|
+
listeners: [],
|
|
330
|
+
sharingType: "public",
|
|
331
|
+
triggers: []
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
const driveUrl = await addDefaultDrive(reactor, workflowsDrive, port);
|
|
335
|
+
if (verbose && driveUrl) console.log(blue(`Vetra Switchboard: Workflows drive: ${driveUrl}`));
|
|
336
|
+
return driveUrl ?? null;
|
|
411
337
|
}
|
|
412
338
|
async function startLocalVetraSwitchboard(args, logger) {
|
|
413
339
|
const { connectPort, switchboardPort, dev, packages, disableLocalPackages, debug, httpsKeyFile, httpsCertFile, remoteDrive, interactive, watch, verbose } = args;
|
|
@@ -450,7 +376,13 @@ async function startLocalVetraSwitchboard(args, logger) {
|
|
|
450
376
|
const actualSwitchboardPort = switchboard.port;
|
|
451
377
|
let previewDriveUrl = null;
|
|
452
378
|
if (watch) try {
|
|
453
|
-
previewDriveUrl = await startVetraPreviewDrive(switchboard.reactor, actualSwitchboardPort, verbose);
|
|
379
|
+
previewDriveUrl = await startVetraPreviewDrive(switchboard.reactor, actualSwitchboardPort, verbose, getConfig(join(process.cwd(), POWERHOUSE_CONFIG_FILE)).vetra?.previewDrive?.app);
|
|
380
|
+
} catch (error) {
|
|
381
|
+
console.error(error);
|
|
382
|
+
}
|
|
383
|
+
let workflowsDriveUrl = null;
|
|
384
|
+
if (switchboard.workflowsEnabled) try {
|
|
385
|
+
workflowsDriveUrl = await seedWorkflowsDrive(switchboard.reactor, actualSwitchboardPort, verbose);
|
|
454
386
|
} catch (error) {
|
|
455
387
|
console.error(error);
|
|
456
388
|
}
|
|
@@ -462,10 +394,12 @@ async function startLocalVetraSwitchboard(args, logger) {
|
|
|
462
394
|
console.log(blue(`Vetra Switchboard: http://localhost:${actualSwitchboardPort}/graphql`));
|
|
463
395
|
console.log(blue(` ➜ Drive URL: ${switchboard.defaultDriveUrl}`));
|
|
464
396
|
if (previewDriveUrl) console.log(blue(` ➜ Preview Drive URL: ${previewDriveUrl}`));
|
|
397
|
+
if (workflowsDriveUrl) console.log(blue(` ➜ Workflows Drive URL: ${workflowsDriveUrl}`));
|
|
465
398
|
}
|
|
466
399
|
return {
|
|
467
400
|
driveUrl: switchboard.defaultDriveUrl || "",
|
|
468
401
|
previewDriveUrl,
|
|
402
|
+
workflowsDriveUrl,
|
|
469
403
|
switchboardPort: actualSwitchboardPort
|
|
470
404
|
};
|
|
471
405
|
} catch (error) {
|
|
@@ -479,13 +413,22 @@ async function startVetra(args) {
|
|
|
479
413
|
const projectDir = process.cwd();
|
|
480
414
|
const { readPackageSync } = await import("read-pkg");
|
|
481
415
|
const projectName = readPackageSync({ cwd: projectDir }).name;
|
|
482
|
-
|
|
483
|
-
if (probe.status === "live") {
|
|
416
|
+
let probe = await probeVetraRuntime(projectDir, projectName);
|
|
417
|
+
if (args.restart && (probe.status === "live" || probe.status === "starting")) {
|
|
418
|
+
console.log(`Stopping this project's Vetra (pid ${probe.record.pid})...`);
|
|
419
|
+
await stopVetra({
|
|
420
|
+
projectDir,
|
|
421
|
+
projectName
|
|
422
|
+
});
|
|
423
|
+
probe = await probeVetraRuntime(projectDir, projectName);
|
|
424
|
+
}
|
|
425
|
+
if (probe.status === "live" || probe.status === "starting") {
|
|
484
426
|
console.log();
|
|
485
|
-
console.log(green("Vetra is already running for this project."));
|
|
486
|
-
|
|
487
|
-
console.log(green(` ➜
|
|
488
|
-
console.log(`
|
|
427
|
+
console.log(green(probe.status === "live" ? "Vetra is already running for this project." : "Vetra is already starting for this project."));
|
|
428
|
+
const { record } = probe;
|
|
429
|
+
console.log(green(` ➜ Connect: ${record.connectUrl ?? `http://localhost:${record.connectPort}`}`));
|
|
430
|
+
console.log(green(` ➜ Switchboard: ${record.switchboardUrl ?? `http://localhost:${record.switchboardPort}/graphql`}`));
|
|
431
|
+
console.log(`Run \`ph vetra --restart\` to restart it, or stop it (pid ${probe.record.pid}).`);
|
|
489
432
|
return;
|
|
490
433
|
}
|
|
491
434
|
if (probe.status === "foreign") {
|
|
@@ -511,16 +454,20 @@ async function startVetra(args) {
|
|
|
511
454
|
}, switchboardLogger);
|
|
512
455
|
const driveUrl = switchboardResult.driveUrl || remoteDrive || "";
|
|
513
456
|
const previewDriveUrl = switchboardResult.previewDriveUrl;
|
|
457
|
+
const workflowsDriveUrl = switchboardResult.workflowsDriveUrl;
|
|
514
458
|
const actualSwitchboardPort = switchboardResult.switchboardPort;
|
|
515
|
-
|
|
459
|
+
const runtimeRecord = {
|
|
516
460
|
pid: process.pid,
|
|
517
461
|
projectName,
|
|
518
462
|
switchboardPort: actualSwitchboardPort,
|
|
519
463
|
connectPort,
|
|
464
|
+
switchboardUrl: `http://localhost:${actualSwitchboardPort}/graphql`,
|
|
520
465
|
mcpUrl: `http://localhost:${actualSwitchboardPort}/mcp`,
|
|
466
|
+
...disableConnect ? {} : { connectUrl: `http://localhost:${connectPort}/` },
|
|
521
467
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
522
|
-
}
|
|
523
|
-
|
|
468
|
+
};
|
|
469
|
+
writeVetraRuntime(projectDir, runtimeRecord);
|
|
470
|
+
const releaseRuntimeRecord = () => clearVetraRuntime(projectDir, process.pid);
|
|
524
471
|
process.on("exit", releaseRuntimeRecord);
|
|
525
472
|
process.on("SIGINT", () => {
|
|
526
473
|
releaseRuntimeRecord();
|
|
@@ -532,6 +479,7 @@ async function startVetra(args) {
|
|
|
532
479
|
});
|
|
533
480
|
const driftedMcpFiles = syncMcpPort(projectDir, actualSwitchboardPort);
|
|
534
481
|
if (driftedMcpFiles.length > 0) console.log(yellow(`Updated ${driftedMcpFiles.join(" and ")} to port ${actualSwitchboardPort}. Reconnect your MCP client (/mcp) to pick it up. This edit is local — do not commit it.`));
|
|
482
|
+
if (legacyMcpConfigs(projectDir).length > 0) console.log(yellow("reactor-mcp still points at a URL; run `ph migrate` to switch it to the `ph mcp` launcher."));
|
|
535
483
|
if (remoteDrive) {
|
|
536
484
|
await sleep(3e3);
|
|
537
485
|
await configureVetraGithubUrl(actualSwitchboardPort, remoteDrive, verbose);
|
|
@@ -539,22 +487,52 @@ async function startVetra(args) {
|
|
|
539
487
|
}
|
|
540
488
|
if (verbose) console.log("Starting Codegen Reactor...");
|
|
541
489
|
if (!disableConnect) {
|
|
490
|
+
const publicBase = args.drivesPublicBase;
|
|
491
|
+
const browserDriveUrl = publicBase ? rebaseDriveUrl(driveUrl, publicBase) : driveUrl;
|
|
492
|
+
const browserPreviewDriveUrl = previewDriveUrl && publicBase ? rebaseDriveUrl(previewDriveUrl, publicBase) : previewDriveUrl;
|
|
493
|
+
const browserWorkflowsDriveUrl = workflowsDriveUrl && publicBase ? rebaseDriveUrl(workflowsDriveUrl, publicBase) : workflowsDriveUrl;
|
|
494
|
+
const vetraDriveEntries = [
|
|
495
|
+
...browserDriveUrl ? [{
|
|
496
|
+
url: browserDriveUrl,
|
|
497
|
+
name: null,
|
|
498
|
+
icon: null
|
|
499
|
+
}] : [],
|
|
500
|
+
...browserPreviewDriveUrl ? [{
|
|
501
|
+
url: browserPreviewDriveUrl,
|
|
502
|
+
name: null,
|
|
503
|
+
icon: null
|
|
504
|
+
}] : [],
|
|
505
|
+
...browserWorkflowsDriveUrl ? [{
|
|
506
|
+
url: browserWorkflowsDriveUrl,
|
|
507
|
+
name: null,
|
|
508
|
+
icon: null
|
|
509
|
+
}] : []
|
|
510
|
+
];
|
|
511
|
+
const studioDrives = () => {
|
|
512
|
+
const projectConnect = getConfig(join(projectDir, POWERHOUSE_CONFIG_FILE)).connect;
|
|
513
|
+
return {
|
|
514
|
+
projectConnect,
|
|
515
|
+
drives: mergeDefaultDrives(vetraDriveEntries, projectConnect?.drives?.defaultDrives ?? [])
|
|
516
|
+
};
|
|
517
|
+
};
|
|
518
|
+
const resolvedDefaultDrives = studioDrives().drives;
|
|
542
519
|
if (verbose) {
|
|
543
520
|
console.log("Starting Connect...");
|
|
544
|
-
const
|
|
545
|
-
|
|
521
|
+
const flagDefaultDrives = wasFlagExplicitlyPassed("default-drives-url") ? parseDefaultDrivesUrl(args.defaultDrivesUrl ?? "") : [];
|
|
522
|
+
const printedDefaultDrives = mergeDefaultDrives(resolvedDefaultDrives, flagDefaultDrives);
|
|
523
|
+
console.log(` ➜ Connect will use default drives: ${printedDefaultDrives.map((d) => "url" in d ? d.url : `local:${d.id}`).join(", ")}`);
|
|
546
524
|
}
|
|
547
525
|
console.log();
|
|
548
526
|
console.log(green(`Vetra Connect: http://localhost:${connectPort}`));
|
|
549
527
|
const customViteLogger = createViteLogger(green);
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
}
|
|
557
|
-
await runConnectStudio({
|
|
528
|
+
const vetraDrivesOverride = () => {
|
|
529
|
+
const { projectConnect, drives } = studioDrives();
|
|
530
|
+
return buildVetraStudioOverride(drives, {
|
|
531
|
+
remoteDrive,
|
|
532
|
+
projectConnect
|
|
533
|
+
});
|
|
534
|
+
};
|
|
535
|
+
const connectUrl = (await runConnectStudio({
|
|
558
536
|
...args,
|
|
559
537
|
port: connectPort,
|
|
560
538
|
disableLocalPackages,
|
|
@@ -566,14 +544,19 @@ async function startVetra(args) {
|
|
|
566
544
|
printUrls,
|
|
567
545
|
bindCLIShortcuts,
|
|
568
546
|
watchTimeout
|
|
569
|
-
}, customViteLogger, vetraDrivesOverride);
|
|
547
|
+
}, customViteLogger, vetraDrivesOverride, { reloadOnConfigChange: true })).resolvedUrls?.local[0];
|
|
548
|
+
if (connectUrl && connectUrl !== runtimeRecord.connectUrl) writeVetraRuntime(projectDir, {
|
|
549
|
+
...runtimeRecord,
|
|
550
|
+
connectPort: Number(new URL(connectUrl).port) || connectPort,
|
|
551
|
+
connectUrl
|
|
552
|
+
});
|
|
570
553
|
}
|
|
571
554
|
} catch (error) {
|
|
572
555
|
console.error(error);
|
|
573
556
|
}
|
|
574
557
|
}
|
|
575
558
|
//#endregion
|
|
576
|
-
export { startVetra };
|
|
559
|
+
export { seedWorkflowsDrive, startVetra };
|
|
577
560
|
|
|
578
|
-
//# sourceMappingURL=vetra-
|
|
579
|
-
//# debugId=
|
|
561
|
+
//# sourceMappingURL=vetra-DZYtcHqV.mjs.map
|
|
562
|
+
//# debugId=52a29815-857a-5f84-b065-1de4bc5d740f
|