@powerhousedao/ph-cli 6.2.3-dev.9 → 6.2.3-dev.90
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/README.md +21 -0
- 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-BdeBTBzN.mjs +65 -0
- package/dist/check-BdeBTBzN.mjs.map +1 -0
- package/dist/{cli-connect-override-D3hh4aH_.mjs → cli-connect-override-CY_Zf7wG.mjs} +39 -27
- package/dist/cli-connect-override-CY_Zf7wG.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-BSOW40st-CWIT2x84.mjs +2788 -0
- package/dist/compound-BSOW40st-CWIT2x84.mjs.map +1 -0
- package/dist/connect-build-6OzCZczA.mjs +321 -0
- package/dist/connect-build-6OzCZczA.mjs.map +1 -0
- package/dist/{connect-config-BWGiW3IB.mjs → connect-config-nuwLOG8I.mjs} +19 -12
- package/dist/connect-config-nuwLOG8I.mjs.map +1 -0
- package/dist/connect-preview-DBcsUnSB.mjs +48 -0
- package/dist/connect-preview-DBcsUnSB.mjs.map +1 -0
- package/dist/connect-studio-B3amPdLj.mjs +81 -0
- package/dist/connect-studio-B3amPdLj.mjs.map +1 -0
- package/dist/connect-studio-Mhhe7W5g.mjs +4 -0
- package/dist/dist-Dw0p_A5j.mjs +480 -0
- package/dist/dist-Dw0p_A5j.mjs.map +1 -0
- package/dist/explain-BS1cIzPW.mjs +230 -0
- package/dist/explain-BS1cIzPW.mjs.map +1 -0
- package/dist/export-BkYfEgBr.mjs +42 -0
- package/dist/export-BkYfEgBr.mjs.map +1 -0
- package/dist/feature-flags-xwqcHEWC.mjs +4 -0
- package/dist/{generate-all-DrT4ZxHX.mjs → generate-all-sPjxvgql.mjs} +9 -3
- package/dist/generate-all-sPjxvgql.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-DR5vuZu9.mjs +323 -0
- package/dist/generate-desktop-shell-DR5vuZu9.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-DqR8BcoO.mjs +31 -0
- package/dist/generate-piece-action-DqR8BcoO.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-CdS7U_Q8.mjs +11 -0
- package/dist/get-version-CdS7U_Q8.mjs.map +1 -0
- package/dist/index-BCSl7lP0.d.mts +4460 -0
- package/dist/index-BCSl7lP0.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/keyframes-bFo9iDhT.mjs +201 -0
- package/dist/keyframes-bFo9iDhT.mjs.map +1 -0
- package/dist/mcp-DnKGQZ10.mjs +262 -0
- package/dist/mcp-DnKGQZ10.mjs.map +1 -0
- package/dist/migrate-B9F_cSCA.mjs +177 -0
- package/dist/migrate-B9F_cSCA.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-DQ7kfVak.mjs +1641 -0
- package/dist/ph-cli-commands-DQ7kfVak.mjs.map +1 -0
- package/dist/ph-cli-commands-oih3l80w.mjs +4 -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-5TYsoc3n.mjs +39 -0
- package/dist/run-sugar-5TYsoc3n.mjs.map +1 -0
- package/dist/runners/connect.d.mts +17 -0
- package/dist/runners/connect.d.mts.map +1 -0
- package/dist/runners/connect.mjs +63 -0
- package/dist/runners/connect.mjs.map +1 -0
- package/dist/runners/switchboard.d.mts +11 -0
- package/dist/runners/switchboard.d.mts.map +1 -0
- package/dist/runners/switchboard.mjs +21 -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 +14 -0
- package/dist/scripts/manage-environment +0 -0
- package/dist/scripts/setup.sh +0 -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-TO9lB8Xs.mjs +4 -0
- package/dist/{vetra-DkF6EJMY.mjs → vetra-CwhVV4_U.mjs} +115 -148
- package/dist/vetra-CwhVV4_U.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 +43 -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,24 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { emittedRunnerSchemas } from "../src/runners/emitted-schemas.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Writes the runners' editor JSON Schemas into clis/ph-cli/schemas/. Run
|
|
8
|
+
* `pnpm --filter @powerhousedao/ph-cli emit-schemas` after changing a
|
|
9
|
+
* runner's hostSchema or outputsSchema; the drift test
|
|
10
|
+
* (test/runner-schemas-drift.test.ts) fails while the files are behind.
|
|
11
|
+
*/
|
|
12
|
+
const outDir = path.join(
|
|
13
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
14
|
+
"..",
|
|
15
|
+
"schemas",
|
|
16
|
+
);
|
|
17
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
18
|
+
for (const [file, schema] of Object.entries(emittedRunnerSchemas())) {
|
|
19
|
+
fs.writeFileSync(
|
|
20
|
+
path.join(outDir, file),
|
|
21
|
+
`${JSON.stringify(schema, null, 2)}\n`,
|
|
22
|
+
);
|
|
23
|
+
console.log(`emitted schemas/${file}`);
|
|
24
|
+
}
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { writeCliDocsMarkdownFile } from "@powerhousedao/codegen/file-builders";
|
|
2
2
|
import { accessToken } from "../src/commands/access-token.js";
|
|
3
|
+
import { build as buildCmd } from "../src/commands/build.js";
|
|
3
4
|
import { build, connect, preview, studio } from "../src/commands/connect.js";
|
|
4
5
|
import { generateAllCmd } from "../src/commands/generate-all.js";
|
|
5
6
|
import { generateAppCmd } from "../src/commands/generate-app.js";
|
|
7
|
+
import { generateConnectRoutesCmd } from "../src/commands/generate-connect-routes.js";
|
|
6
8
|
import { generateDocumentModelCmd } from "../src/commands/generate-document-model.js";
|
|
7
9
|
import { generateEditorCmd } from "../src/commands/generate-editor.js";
|
|
8
10
|
import { generateMigrationFileCmd } from "../src/commands/generate-migration-file.js";
|
|
11
|
+
import { generatePieceActionCmd } from "../src/commands/generate-piece-action.js";
|
|
12
|
+
import { generatePieceTriggerCmd } from "../src/commands/generate-piece-trigger.js";
|
|
13
|
+
import { generatePieceCmd } from "../src/commands/generate-piece.js";
|
|
9
14
|
import { generateProcessorCmd } from "../src/commands/generate-processor.js";
|
|
10
15
|
import { generateSubgraphCmd } from "../src/commands/generate-subgraph.js";
|
|
11
16
|
import { generate } from "../src/commands/generate.js";
|
|
12
17
|
import { inspect } from "../src/commands/inspect.js";
|
|
13
18
|
import { install } from "../src/commands/install.js";
|
|
19
|
+
import { keyframes } from "../src/commands/keyframes.js";
|
|
14
20
|
import { list } from "../src/commands/list.js";
|
|
15
21
|
import { login } from "../src/commands/login.js";
|
|
22
|
+
import { mcp } from "../src/commands/mcp.js";
|
|
16
23
|
import { migrate } from "../src/commands/migrate.js";
|
|
17
24
|
import { phCli } from "../src/commands/ph-cli.js";
|
|
18
25
|
import { switchboard } from "../src/commands/switchboard.js";
|
|
@@ -27,15 +34,22 @@ const commands = [
|
|
|
27
34
|
{ name: "app", command: generateAppCmd },
|
|
28
35
|
{ name: "processor", command: generateProcessorCmd },
|
|
29
36
|
{ name: "subgraph", command: generateSubgraphCmd },
|
|
37
|
+
{ name: "piece", command: generatePieceCmd },
|
|
38
|
+
{ name: "piece-action", command: generatePieceActionCmd },
|
|
39
|
+
{ name: "piece-trigger", command: generatePieceTriggerCmd },
|
|
30
40
|
{ name: "migration-file", command: generateMigrationFileCmd },
|
|
41
|
+
{ name: "connect-routes", command: generateConnectRoutesCmd },
|
|
31
42
|
{ name: "vetra", command: vetra },
|
|
43
|
+
{ name: "build", command: buildCmd },
|
|
32
44
|
{ name: "connect", command: connect },
|
|
33
45
|
{ name: "connect studio", command: studio },
|
|
34
46
|
{ name: "connect build", command: build },
|
|
35
47
|
{ name: "connect preview", command: preview },
|
|
36
48
|
{ name: "access token", command: accessToken },
|
|
37
49
|
{ name: "inspect", command: inspect },
|
|
50
|
+
{ name: "keyframes", command: keyframes },
|
|
38
51
|
{ name: "list", command: list },
|
|
52
|
+
{ name: "mcp", command: mcp },
|
|
39
53
|
{ name: "migrate", command: migrate },
|
|
40
54
|
{ name: "switchboard", command: switchboard },
|
|
41
55
|
{ name: "login", command: login },
|
|
File without changes
|
package/dist/scripts/setup.sh
CHANGED
|
File without changes
|
|
@@ -1,8 +1,8 @@
|
|
|
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]="ff779d1d-972c-53db-a71e-946208cc05bd")}catch(e){}}();
|
|
3
|
+
import { REACTOR_SCHEMA, getMigrationStatus, runMigrations } from "@powerhousedao/reactor";
|
|
3
4
|
import { Kysely, PostgresDialect } from "kysely";
|
|
4
5
|
import { Pool } from "pg";
|
|
5
|
-
import { REACTOR_SCHEMA, getMigrationStatus, runMigrations } from "@powerhousedao/reactor";
|
|
6
6
|
//#region src/services/switchboard-migrate.ts
|
|
7
7
|
function isPostgresUrl(url) {
|
|
8
8
|
return url.startsWith("postgresql://") || url.startsWith("postgres://");
|
|
@@ -15,7 +15,8 @@ async function runSwitchboardMigrations(options) {
|
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
console.log(`Database: ${dbPath}`);
|
|
18
|
-
const
|
|
18
|
+
const pool = new Pool({ connectionString: dbPath });
|
|
19
|
+
const db = new Kysely({ dialect: new PostgresDialect({ pool }) });
|
|
19
20
|
try {
|
|
20
21
|
if (options.statusOnly) {
|
|
21
22
|
console.log("\nChecking migration status...");
|
|
@@ -49,5 +50,5 @@ async function runSwitchboardMigrations(options) {
|
|
|
49
50
|
//#endregion
|
|
50
51
|
export { runSwitchboardMigrations };
|
|
51
52
|
|
|
52
|
-
//# sourceMappingURL=switchboard-migrate-
|
|
53
|
-
//# debugId=
|
|
53
|
+
//# sourceMappingURL=switchboard-migrate-Docb8Cjv.mjs.map
|
|
54
|
+
//# debugId=ff779d1d-972c-53db-a71e-946208cc05bd
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switchboard-migrate-
|
|
1
|
+
{"version":3,"file":"switchboard-migrate-Docb8Cjv.mjs","sources":["../src/services/switchboard-migrate.ts"],"sourcesContent":["import { Kysely, PostgresDialect } from \"kysely\";\nimport { Pool } from \"pg\";\nimport {\n runMigrations,\n getMigrationStatus,\n REACTOR_SCHEMA,\n} from \"@powerhousedao/reactor\";\n\ninterface MigrationOptions {\n dbPath?: string;\n statusOnly?: boolean;\n}\n\nfunction isPostgresUrl(url: string): boolean {\n return url.startsWith(\"postgresql://\") || url.startsWith(\"postgres://\");\n}\n\nexport async function runSwitchboardMigrations(\n options: MigrationOptions,\n): Promise<void> {\n const dbPath =\n options.dbPath ??\n process.env.PH_REACTOR_DATABASE_URL ??\n process.env.DATABASE_URL;\n\n if (!dbPath || !isPostgresUrl(dbPath)) {\n console.log(\"No PostgreSQL URL configured. Skipping migrations.\");\n console.log(\"(PGlite migrations are handled automatically on startup)\");\n return;\n }\n\n console.log(`Database: ${dbPath}`);\n\n const pool = new Pool({ connectionString: dbPath });\n\n const db = new Kysely<any>({\n dialect: new PostgresDialect({ pool }),\n });\n\n try {\n if (options.statusOnly) {\n console.log(\"\\nChecking migration status...\");\n const migrations = await getMigrationStatus(db, REACTOR_SCHEMA);\n\n console.log(\"\\nMigration Status:\");\n console.log(\"=================\");\n\n for (const migration of migrations) {\n const status = migration.executedAt\n ? `[OK] Executed at ${migration.executedAt.toISOString()}`\n : \"[--] Pending\";\n console.log(`${status} - ${migration.name}`);\n }\n } else {\n console.log(\"\\nRunning migrations...\");\n const result = await runMigrations(db, REACTOR_SCHEMA);\n\n if (!result.success) {\n console.error(\"Migration failed:\", result.error?.message);\n process.exit(1);\n }\n\n if (result.migrationsExecuted.length === 0) {\n console.log(\"No migrations to run - database is up to date\");\n } else {\n console.log(\n `Successfully executed ${result.migrationsExecuted.length} migration(s):`,\n );\n for (const name of result.migrationsExecuted) {\n console.log(` - ${name}`);\n }\n }\n }\n } catch (error) {\n console.error(\n \"Error:\",\n error instanceof Error ? error.message : String(error),\n );\n process.exit(1);\n } finally {\n await db.destroy();\n }\n}\n"],"names":[],"mappings":";;;;;;AAaA,SAAS,cAAc,KAAsB;CAC3C,OAAO,IAAI,WAAW,eAAe,KAAK,IAAI,WAAW,aAAa;AACxE;AAEA,eAAsB,yBACpB,SACe;CACf,MAAM,SACJ,QAAQ,UACR,QAAQ,IAAI,2BACZ,QAAQ,IAAI;CAEd,IAAI,CAAC,UAAU,CAAC,cAAc,MAAM,GAAG;EACrC,QAAQ,IAAI,oDAAoD;EAChE,QAAQ,IAAI,0DAA0D;EACtE;CACF;CAEA,QAAQ,IAAI,aAAa,QAAQ;CAEjC,MAAM,OAAO,IAAI,KAAK,EAAE,kBAAkB,OAAO,CAAC;CAElD,MAAM,KAAK,IAAI,OAAY,EACzB,SAAS,IAAI,gBAAgB,EAAE,KAAK,CAAC,EACvC,CAAC;CAED,IAAI;EACF,IAAI,QAAQ,YAAY;GACtB,QAAQ,IAAI,gCAAgC;GAC5C,MAAM,aAAa,MAAM,mBAAmB,IAAI,cAAc;GAE9D,QAAQ,IAAI,qBAAqB;GACjC,QAAQ,IAAI,mBAAmB;GAE/B,KAAK,MAAM,aAAa,YAAY;IAClC,MAAM,SAAS,UAAU,aACrB,oBAAoB,UAAU,WAAW,YAAY,MACrD;IACJ,QAAQ,IAAI,GAAG,OAAO,KAAK,UAAU,MAAM;GAC7C;EACF,OAAO;GACL,QAAQ,IAAI,yBAAyB;GACrC,MAAM,SAAS,MAAM,cAAc,IAAI,cAAc;GAErD,IAAI,CAAC,OAAO,SAAS;IACnB,QAAQ,MAAM,qBAAqB,OAAO,OAAO,OAAO;IACxD,QAAQ,KAAK,CAAC;GAChB;GAEA,IAAI,OAAO,mBAAmB,WAAW,GACvC,QAAQ,IAAI,+CAA+C;QACtD;IACL,QAAQ,IACN,yBAAyB,OAAO,mBAAmB,OAAO,eAC5D;IACA,KAAK,MAAM,QAAQ,OAAO,oBACxB,QAAQ,IAAI,OAAO,MAAM;GAE7B;EACF;CACF,SAAS,OAAO;EACd,QAAQ,MACN,UACA,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CACvD;EACA,QAAQ,KAAK,CAAC;CAChB,UAAU;EACR,MAAM,GAAG,QAAQ;CACnB;AACF","debug_id":"ff779d1d-972c-53db-a71e-946208cc05bd"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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]="c5e3cd62-660a-5978-8304-6ea0c3f41894")}catch(e){}}();
|
|
3
|
+
import { SWITCHBOARD_PROXY_PATHS, isHtmlNavigation } from "@powerhousedao/shared/connect/origin-placeholder";
|
|
4
|
+
//#region src/utils/switchboard-proxy.ts
|
|
5
|
+
/**
|
|
6
|
+
* Vite proxy rules (dev and preview servers alike) that send the
|
|
7
|
+
* switchboard's paths to `target`, so a browser on Connect's origin reaches
|
|
8
|
+
* the switchboard through it and the served config can name the switchboard
|
|
9
|
+
* as `${origin}` (runner.proxy on the connect host).
|
|
10
|
+
*
|
|
11
|
+
* `/d/<drive>` is both a switchboard endpoint and one of Connect's own
|
|
12
|
+
* routes: a browser navigation there (it accepts HTML) is left to Connect,
|
|
13
|
+
* every other request on the path goes to the switchboard. GraphQL carries
|
|
14
|
+
* the subscriptions websocket, so that rule upgrades too. The Host header
|
|
15
|
+
* is left as the browser sent it: the switchboard builds the URLs it hands
|
|
16
|
+
* out from it, and on the page's origin is where they must point.
|
|
17
|
+
*/
|
|
18
|
+
function switchboardProxy(target) {
|
|
19
|
+
const origin = new URL(target).origin;
|
|
20
|
+
const rules = {};
|
|
21
|
+
for (const prefix of SWITCHBOARD_PROXY_PATHS) {
|
|
22
|
+
const key = prefix.endsWith("/") ? `^${escape(prefix)}` : `^${escape(prefix)}(/|$)`;
|
|
23
|
+
rules[key] = {
|
|
24
|
+
target: origin,
|
|
25
|
+
changeOrigin: false,
|
|
26
|
+
...prefix === "/graphql" ? { ws: true } : {},
|
|
27
|
+
...prefix === "/d/" ? { bypass: (req) => isHtmlNavigation(req.headers.accept) ? req.url : void 0 } : {}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return rules;
|
|
31
|
+
}
|
|
32
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
33
|
+
//#endregion
|
|
34
|
+
export { switchboardProxy as t };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=switchboard-proxy-CGfMtENM.mjs.map
|
|
37
|
+
//# debugId=c5e3cd62-660a-5978-8304-6ea0c3f41894
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switchboard-proxy-CGfMtENM.mjs","sources":["../src/utils/switchboard-proxy.ts"],"sourcesContent":["import {\n isHtmlNavigation,\n SWITCHBOARD_PROXY_PATHS,\n} from \"@powerhousedao/shared/connect/origin-placeholder\";\nimport type { ProxyOptions } from \"vite\";\n\n/**\n * Vite proxy rules (dev and preview servers alike) that send the\n * switchboard's paths to `target`, so a browser on Connect's origin reaches\n * the switchboard through it and the served config can name the switchboard\n * as `${origin}` (runner.proxy on the connect host).\n *\n * `/d/<drive>` is both a switchboard endpoint and one of Connect's own\n * routes: a browser navigation there (it accepts HTML) is left to Connect,\n * every other request on the path goes to the switchboard. GraphQL carries\n * the subscriptions websocket, so that rule upgrades too. The Host header\n * is left as the browser sent it: the switchboard builds the URLs it hands\n * out from it, and on the page's origin is where they must point.\n */\nexport function switchboardProxy(target: string): Record<string, ProxyOptions> {\n const origin = new URL(target).origin;\n const rules: Record<string, ProxyOptions> = {};\n for (const prefix of SWITCHBOARD_PROXY_PATHS) {\n const key = prefix.endsWith(\"/\")\n ? `^${escape(prefix)}`\n : `^${escape(prefix)}(/|$)`;\n rules[key] = {\n target: origin,\n changeOrigin: false,\n ...(prefix === \"/graphql\" ? { ws: true } : {}),\n ...(prefix === \"/d/\"\n ? {\n bypass: (req) =>\n isHtmlNavigation(req.headers.accept) ? req.url : undefined,\n }\n : {}),\n };\n }\n return rules;\n}\n\nconst escape = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAmBA,SAAgB,iBAAiB,QAA8C;CAC7E,MAAM,SAAS,IAAI,IAAI,MAAM,CAAC,CAAC;CAC/B,MAAM,QAAsC,CAAC;CAC7C,KAAK,MAAM,UAAU,yBAAyB;EAC5C,MAAM,MAAM,OAAO,SAAS,GAAG,IAC3B,IAAI,OAAO,MAAM,MACjB,IAAI,OAAO,MAAM,EAAE;EACvB,MAAM,OAAO;GACX,QAAQ;GACR,cAAc;GACd,GAAI,WAAW,aAAa,EAAE,IAAI,KAAK,IAAI,CAAC;GAC5C,GAAI,WAAW,QACX,EACE,SAAS,QACP,iBAAiB,IAAI,QAAQ,MAAM,IAAI,IAAI,MAAM,KAAA,EACrD,IACA,CAAC;EACP;CACF;CACA,OAAO;AACT;AAEA,MAAM,UAAU,MAAc,EAAE,QAAQ,uBAAuB,MAAM","debug_id":"c5e3cd62-660a-5978-8304-6ea0c3f41894"}
|
|
@@ -1,7 +1,8 @@
|
|
|
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 { cyan, green, red, yellow } from "colorette";
|
|
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]="44d0c080-10cc-5316-947d-b0281777aade")}catch(e){}}();
|
|
4
3
|
import { promises } from "node:fs";
|
|
4
|
+
import { cyan, green, red, yellow } from "colorette";
|
|
5
|
+
import { defaultStoreDirs } from "@powerhousedao/shared/clis/ph-dir";
|
|
5
6
|
//#region src/services/switchboard-reset.ts
|
|
6
7
|
const CONFIRMATION_TOKEN = "reset";
|
|
7
8
|
function isPostgresUrl(url) {
|
|
@@ -18,10 +19,11 @@ function isInteractive() {
|
|
|
18
19
|
* caller can refuse.
|
|
19
20
|
*/
|
|
20
21
|
function resolveResetPaths(options, env = process.env) {
|
|
22
|
+
const defaults = defaultStoreDirs(env);
|
|
21
23
|
const readModelDbPath = options.dbPath ?? env.DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL;
|
|
22
|
-
const readModelPath = readModelDbPath ||
|
|
24
|
+
const readModelPath = readModelDbPath || defaults.readModel;
|
|
23
25
|
const reactorDbUrl = options.dbPath ?? env.PH_REACTOR_DATABASE_URL ?? env.PH_SWITCHBOARD_DATABASE_URL;
|
|
24
|
-
const reactorPath = reactorDbUrl ||
|
|
26
|
+
const reactorPath = reactorDbUrl || defaults.reactor;
|
|
25
27
|
const reactorIsPostgres = !!reactorDbUrl && isPostgresUrl(reactorDbUrl);
|
|
26
28
|
const readModelIsPostgres = !!readModelDbPath && isPostgresUrl(readModelDbPath);
|
|
27
29
|
let postgresUrl = null;
|
|
@@ -83,5 +85,5 @@ async function resetSwitchboardDatabase(options) {
|
|
|
83
85
|
//#endregion
|
|
84
86
|
export { resetSwitchboardDatabase };
|
|
85
87
|
|
|
86
|
-
//# sourceMappingURL=switchboard-reset-
|
|
87
|
-
//# debugId=
|
|
88
|
+
//# sourceMappingURL=switchboard-reset-MtTB_GAI.mjs.map
|
|
89
|
+
//# debugId=44d0c080-10cc-5316-947d-b0281777aade
|
|
@@ -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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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,YAAY,QAAQ,IAAI;AAE9B,KAAI,cAAc,IAChB,QAAO;AAGT,QAAO,oBAAoB,WAAW,eAAe;;AAGvD,SAAgB,eAAe,OAA8B;CAC3D,MAAM,cAAc,QAAQ,KAAK;AAEjC,KAAI,MACF,SAAQ,IAAI,mBAAmB,YAAY;CAG7C,MAAM,cAAc,oBAAoB,aAAa,oBAAoB;AAEzE,KAAI,C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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,eAAe,GAAG,GACtD,OAAO;CAGT,MAAM,YAAY,QAAQ,GAAG;CAE7B,IAAI,cAAc,KAChB,OAAO;CAGT,OAAO,oBAAoB,WAAW,cAAc;AACtD;AAEA,SAAgB,eAAe,OAA8B;CAC3D,MAAM,cAAc,QAAQ,IAAI;CAEhC,IAAI,OACF,QAAQ,IAAI,mBAAmB,WAAW;CAG5C,MAAM,cA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,IAAI,CAAC,GAAG,WAAW,UAAU,GAC3B,MAAM,IAAI,MACR,uDAAuD,aACzD;CAGF,MAAM,SAAS,KAAK,MAClB,GAAG,aAAa,YAAY,OAAO,CACrC;CAEA,MAAM,gBAAkC;EACtC,GAAG;EACH,UAAU,oBACR,OAAO,UACP,cACA,MACA,QACF;CACF;CAEA,IACE,SAAS,aACT,gBACC,uBAAuB,CAAC,OAAO,uBAChC,aAAa,SAAS,GAEtB,cAAc,qBAAqB;CAGrC,GAAG,cAAc,YAAY,KAAK,UAAU,eAAe,MAAM,CAAC,CAAC;AACrE;;;;;AA0CA,SAAgB,oBACd,cACA,aACA;CACA,MAAM,aAAa,KAAK,KAAK,aAAa,WAAW;CAGrD,IAAI,CAAC,GAAG,WAAW,UAAU,GAAG;EAC9B,QAAQ,KAAK,sDAAsD;EACnE;CACF;CAEA,MAAM,gBAAgB,GAAG,aAAa,YAAY,OAAO;CACzD,IAAI,gBAAgB;CAEpB,KAAK,MAAM,OAAO,cAAc;EAE9B,MAAM,kBAAkB,YAAY,kBADF,IAAI,KAAK,iBACC;EAG5C,MAAM,QAAQ,cAAc,MAAM,IAAI;EACtC,MAAM,gBAAgB,MAAM,QACzB,SAAS,CAAC,KAAK,KAAK,CAAC,CAAC,SAAS,eAAe,CACjD;EAEA,IAAI,cAAc,WAAW,MAAM,QACjC,gBAAgB,cAAc,KAAK,IAAI;CAE3C;CAGA,IAAI,kBAAkB,eACpB,GAAG,cAAc,YAAY,aAAa;AAE9C","debug_id":"e3fbf59a-7996-5c5c-9db7-c8d207b68849"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { d as updateConfigFile, u as removeStylesImports } from "./utils-9KyRM0mf.mjs";
|
|
2
|
+
export { 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]="76be3b2a-b7dc-5775-8844-ce31e31fe2d1")}catch(e){}}();
|
|
4
|
+
//# debugId=76be3b2a-b7dc-5775-8844-ce31e31fe2d1
|