ph-cmd 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  #!/usr/bin/env node
2
- import '@powerhousedao/config/powerhouse';
package/dist/cli.js CHANGED
@@ -1,9 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
3
  import registerCommands from './commands/index.js';
4
+ import { forwardCommand } from './commands/forward.js';
4
5
 
5
6
  const program = new Command();
6
- program.name("ph-cli").description("CLI tool for Powerhouse DAO").version("1.0.0");
7
+ const defaultCommand = (options) => {
8
+ const allArgs = process.argv.slice(2);
9
+ const filteredArgs = allArgs.filter((arg) => arg !== "--verbose");
10
+ const args = filteredArgs.join(" ");
11
+ forwardCommand(args, { debug: !!options.verbose });
12
+ };
13
+ program.name("ph-cmd").description("CLI tool for Powerhouse DAO").allowUnknownOption().option("--verbose", "Enable debug mode").action(defaultCommand).version("1.0.0");
7
14
  registerCommands(program);
8
15
  program.parse(process.argv);
9
16
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts"],"names":[],"mappings":";;;;AAIA,MAAM,OAAA,GAAU,IAAI,OAAQ,EAAA;AAE5B,OAAA,CACG,KAAK,QAAQ,CAAA,CACb,YAAY,6BAA6B,CAAA,CACzC,QAAQ,OAAO,CAAA;AAElB,gBAAA,CAAiB,OAAO,CAAA;AAExB,OAAQ,CAAA,KAAA,CAAM,QAAQ,IAAI,CAAA","file":"cli.js","sourcesContent":["#!/usr/bin/env node\nimport { Command } from \"commander\";\nimport registerCommands from \"./commands/index.js\";\n\nconst program = new Command();\n\nprogram\n .name(\"ph-cli\")\n .description(\"CLI tool for Powerhouse DAO\")\n .version(\"1.0.0\");\n\nregisterCommands(program);\n\nprogram.parse(process.argv);\n"]}
1
+ {"version":3,"sources":["../src/cli.ts"],"names":[],"mappings":";;;;;AAMA,MAAM,OAAA,GAAU,IAAI,OAAQ,EAAA;AAE5B,MAAM,cAAA,GAA6D,CACjE,OACG,KAAA;AACH,EAAA,MAAM,OAAU,GAAA,OAAA,CAAQ,IAAK,CAAA,KAAA,CAAM,CAAC,CAAA;AACpC,EAAA,MAAM,eAAe,OAAQ,CAAA,MAAA,CAAO,CAAC,GAAA,KAAQ,QAAQ,WAAW,CAAA;AAChE,EAAM,MAAA,IAAA,GAAO,YAAa,CAAA,IAAA,CAAK,GAAG,CAAA;AAElC,EAAA,cAAA,CAAe,MAAM,EAAE,KAAA,EAAO,CAAC,CAAC,OAAA,CAAQ,SAAS,CAAA;AACnD,CAAA;AAEA,OAAA,CACG,KAAK,QAAQ,CAAA,CACb,WAAY,CAAA,6BAA6B,EACzC,kBAAmB,EAAA,CACnB,MAAO,CAAA,WAAA,EAAa,mBAAmB,CACvC,CAAA,MAAA,CAAO,cAAc,CAAA,CACrB,QAAQ,OAAO,CAAA;AAElB,gBAAA,CAAiB,OAAO,CAAA;AAExB,OAAQ,CAAA,KAAA,CAAM,QAAQ,IAAI,CAAA","file":"cli.js","sourcesContent":["#!/usr/bin/env node\nimport { Command } from \"commander\";\nimport registerCommands from \"./commands/index.js\";\nimport { forwardCommand } from \"./commands/forward.js\";\nimport { CommandActionType } from \"./types.js\";\n\nconst program = new Command();\n\nconst defaultCommand: CommandActionType<[{ verbose?: boolean }]> = (\n options,\n) => {\n const allArgs = process.argv.slice(2);\n const filteredArgs = allArgs.filter((arg) => arg !== \"--verbose\");\n const args = filteredArgs.join(\" \");\n\n forwardCommand(args, { debug: !!options.verbose });\n};\n\nprogram\n .name(\"ph-cmd\")\n .description(\"CLI tool for Powerhouse DAO\")\n .allowUnknownOption()\n .option(\"--verbose\", \"Enable debug mode\")\n .action(defaultCommand)\n .version(\"1.0.0\");\n\nregisterCommands(program);\n\nprogram.parse(process.argv);\n"]}
@@ -0,0 +1,6 @@
1
+ type ForwardPHCommandOptions = {
2
+ debug?: boolean;
3
+ };
4
+ declare const forwardCommand: (args: string, options: ForwardPHCommandOptions) => void;
5
+
6
+ export { forwardCommand };
@@ -0,0 +1,28 @@
1
+ import { getProjectInfo, getPackageManagerFromLockfile, forwardPHCommand } from '../utils.js';
2
+
3
+ const forwardCommand = (args, options) => {
4
+ if (options.debug) {
5
+ console.log(">>> command arguments:", { options });
6
+ }
7
+ const projectInfo = getProjectInfo(options.debug);
8
+ if (options.debug) {
9
+ console.log("\n>>> projectInfo:", projectInfo);
10
+ }
11
+ const packageManager = getPackageManagerFromLockfile(projectInfo.path);
12
+ if (options.debug) {
13
+ console.log("\n>>> forwardCommand arguments:");
14
+ console.log(">>> packageManager:", packageManager);
15
+ console.log(">>> projectPath:", projectInfo.path);
16
+ console.log(">>> args:", args);
17
+ }
18
+ try {
19
+ forwardPHCommand(packageManager, projectInfo.path, args, options.debug);
20
+ } catch (error) {
21
+ console.error("\u274C Failed to forward command");
22
+ throw error;
23
+ }
24
+ };
25
+
26
+ export { forwardCommand };
27
+ //# sourceMappingURL=forward.js.map
28
+ //# sourceMappingURL=forward.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/commands/forward.ts"],"names":[],"mappings":";;AAUa,MAAA,cAAA,GAAiB,CAC5B,IAAA,EACA,OACG,KAAA;AACH,EAAA,IAAI,QAAQ,KAAO,EAAA;AACjB,IAAA,OAAA,CAAQ,GAAI,CAAA,wBAAA,EAA0B,EAAE,OAAA,EAAS,CAAA;AAAA;AAGnD,EAAM,MAAA,WAAA,GAAc,cAAe,CAAA,OAAA,CAAQ,KAAK,CAAA;AAEhD,EAAA,IAAI,QAAQ,KAAO,EAAA;AACjB,IAAQ,OAAA,CAAA,GAAA,CAAI,sBAAsB,WAAW,CAAA;AAAA;AAG/C,EAAM,MAAA,cAAA,GAAiB,6BAA8B,CAAA,WAAA,CAAY,IAAI,CAAA;AAErE,EAAA,IAAI,QAAQ,KAAO,EAAA;AACjB,IAAA,OAAA,CAAQ,IAAI,iCAAiC,CAAA;AAC7C,IAAQ,OAAA,CAAA,GAAA,CAAI,uBAAuB,cAAc,CAAA;AACjD,IAAQ,OAAA,CAAA,GAAA,CAAI,kBAAoB,EAAA,WAAA,CAAY,IAAI,CAAA;AAChD,IAAQ,OAAA,CAAA,GAAA,CAAI,aAAa,IAAI,CAAA;AAAA;AAG/B,EAAI,IAAA;AACF,IAAA,gBAAA,CAAiB,cAAgB,EAAA,WAAA,CAAY,IAAM,EAAA,IAAA,EAAM,QAAQ,KAAK,CAAA;AAAA,WAC/D,KAAO,EAAA;AACd,IAAA,OAAA,CAAQ,MAAM,kCAA6B,CAAA;AAC3C,IAAM,MAAA,KAAA;AAAA;AAEV","file":"forward.js","sourcesContent":["import {\n getProjectInfo,\n getPackageManagerFromLockfile,\n forwardPHCommand,\n} from \"../utils.js\";\n\ntype ForwardPHCommandOptions = {\n debug?: boolean;\n};\n\nexport const forwardCommand = (\n args: string,\n options: ForwardPHCommandOptions,\n) => {\n if (options.debug) {\n console.log(\">>> command arguments:\", { options });\n }\n\n const projectInfo = getProjectInfo(options.debug);\n\n if (options.debug) {\n console.log(\"\\n>>> projectInfo:\", projectInfo);\n }\n\n const packageManager = getPackageManagerFromLockfile(projectInfo.path);\n\n if (options.debug) {\n console.log(\"\\n>>> forwardCommand arguments:\");\n console.log(\">>> packageManager:\", packageManager);\n console.log(\">>> projectPath:\", projectInfo.path);\n console.log(\">>> args:\", args);\n }\n\n try {\n forwardPHCommand(packageManager, projectInfo.path, args, options.debug);\n } catch (error) {\n console.error(\"❌ Failed to forward command\");\n throw error;\n }\n};\n"]}
@@ -1,13 +1,7 @@
1
1
  import { Command } from 'commander';
2
2
  import { initCommand } from './init.js';
3
3
  export { init } from './init.js';
4
- export { dev, devCommand } from './dev.js';
5
- export { helpCommand } from './help.js';
6
- export { generate, generateCommand } from './generate.js';
7
- export { DefaultReactorOptions, ReactorOptions, reactor, reactorCommand } from './reactor.js';
8
- import '@powerhousedao/config/powerhouse';
9
4
  import '../types.js';
10
- import '@powerhousedao/reactor-local';
11
5
 
12
6
  declare const commands: (typeof initCommand)[];
13
7
  declare function registerCommands(program: Command): void;
@@ -1,25 +1,7 @@
1
- import { devCommand } from './dev.js';
2
- export * from './dev.js';
3
- import { helpCommand } from './help.js';
4
- export * from './help.js';
5
1
  import { initCommand } from './init.js';
6
2
  export * from './init.js';
7
- import { connectCommand } from './connect.js';
8
- import { reactorCommand } from './reactor.js';
9
- export * from './reactor.js';
10
- import { generateCommand } from './generate.js';
11
- export * from './generate.js';
12
- import { installCommand } from './install.js';
13
3
 
14
- const commands = [
15
- initCommand,
16
- devCommand,
17
- connectCommand,
18
- generateCommand,
19
- reactorCommand,
20
- helpCommand,
21
- installCommand
22
- ];
4
+ const commands = [initCommand];
23
5
  function registerCommands(program) {
24
6
  commands.forEach((command) => command(program));
25
7
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AASO,MAAM,QAAW,GAAA;AAAA,EACtB,WAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,cAAA;AAAA,EACA,WAAA;AAAA,EACA;AACF;AAEe,SAAR,iBAAkC,OAAkB,EAAA;AACzD,EAAA,QAAA,CAAS,OAAQ,CAAA,CAAC,OAAY,KAAA,OAAA,CAAQ,OAAO,CAAC,CAAA;AAChD","file":"index.js","sourcesContent":["import { Command } from \"commander\";\nimport { devCommand } from \"./dev.js\";\nimport { helpCommand } from \"./help.js\";\nimport { initCommand } from \"./init.js\";\nimport { connectCommand } from \"./connect.js\";\nimport { reactorCommand } from \"./reactor.js\";\nimport { generateCommand } from \"./generate.js\";\nimport { installCommand } from \"./install.js\";\n\nexport const commands = [\n initCommand,\n devCommand,\n connectCommand,\n generateCommand,\n reactorCommand,\n helpCommand,\n installCommand,\n];\n\nexport default function registerCommands(program: Command) {\n commands.forEach((command) => command(program));\n}\n\nexport * from \"./dev.js\";\nexport * from \"./help.js\";\nexport * from \"./init.js\";\nexport * from \"./generate.js\";\nexport * from \"./reactor.js\";\n"]}
1
+ {"version":3,"sources":["../../src/commands/index.ts"],"names":[],"mappings":";;;AAGa,MAAA,QAAA,GAAW,CAAC,WAAW;AAErB,SAAR,iBAAkC,OAAkB,EAAA;AACzD,EAAA,QAAA,CAAS,OAAQ,CAAA,CAAC,OAAY,KAAA,OAAA,CAAQ,OAAO,CAAC,CAAA;AAChD","file":"index.js","sourcesContent":["import { Command } from \"commander\";\nimport { initCommand } from \"./init.js\";\n\nexport const commands = [initCommand];\n\nexport default function registerCommands(program: Command) {\n commands.forEach((command) => command(program));\n}\n\nexport * from \"./init.js\";\n"]}
@@ -1,15 +1,20 @@
1
1
  import { createProject, parseVersion } from '@powerhousedao/codegen';
2
+ import { HOME_DIR, PH_GLOBAL_PROJECT_NAME, POWERHOUSE_GLOBAL_DIR } from '../utils.js';
2
3
 
3
4
  const init = async (projectName, options) => {
4
- console.log("Initializing a new project...");
5
+ console.log("\u{1F4E6} Initializing global project...");
6
+ process.chdir(HOME_DIR);
5
7
  try {
6
8
  await createProject({
7
- name: options.project ?? projectName,
8
- interactive: options.interactive ?? false,
9
+ name: PH_GLOBAL_PROJECT_NAME,
10
+ interactive: false,
9
11
  version: parseVersion(options)
10
12
  });
13
+ console.log(
14
+ `\u{1F680} Global project initialized successfully: ${POWERHOUSE_GLOBAL_DIR}`
15
+ );
11
16
  } catch (error) {
12
- console.error("Failed to initialize the project", error);
17
+ console.error("\u274C Failed to initialize the global project", error);
13
18
  }
14
19
  };
15
20
  function initCommand(program) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/init.ts"],"names":[],"mappings":";;AAIa,MAAA,IAAA,GAWT,OAAO,WAAA,EAAa,OAAY,KAAA;AAClC,EAAA,OAAA,CAAQ,IAAI,+BAA+B,CAAA;AAE3C,EAAI,IAAA;AACF,IAAA,MAAM,aAAc,CAAA;AAAA,MAClB,IAAA,EAAM,QAAQ,OAAW,IAAA,WAAA;AAAA,MACzB,WAAA,EAAa,QAAQ,WAAe,IAAA,KAAA;AAAA,MACpC,OAAA,EAAS,aAAa,OAAO;AAAA,KAC9B,CAAA;AAAA,WACM,KAAO,EAAA;AACd,IAAQ,OAAA,CAAA,KAAA,CAAM,oCAAoC,KAAK,CAAA;AAAA;AAE3D;AAEO,SAAS,YAAY,OAAkB,EAAA;AAC5C,EAAA,OAAA,CACG,QAAQ,MAAM,CAAA,CACd,WAAY,CAAA,0BAA0B,EACtC,QAAS,CAAA,gBAAA,EAAkB,qBAAqB,CAAA,CAChD,OAAO,eAAiB,EAAA,qBAAqB,EAC7C,MAAO,CAAA,mBAAA,EAAqB,qCAAqC,CACjE,CAAA,MAAA;AAAA,IACC,eAAA;AAAA,IACA;AAAA,GACF,CACC,MAAO,CAAA,OAAA,EAAS,8CAA8C,CAAA,CAC9D,OAAO,WAAa,EAAA,8CAA8C,CAClE,CAAA,MAAA,CAAO,IAAI,CAAA;AAChB","file":"init.js","sourcesContent":["import { Command } from \"commander\";\nimport { createProject, parseVersion } from \"@powerhousedao/codegen\";\nimport { CommandActionType } from \"../types.js\";\n\nexport const init: CommandActionType<\n [\n string | undefined,\n {\n project?: string;\n interactive?: boolean;\n version?: string;\n dev?: boolean;\n staging?: boolean;\n },\n ]\n> = async (projectName, options) => {\n console.log(\"Initializing a new project...\");\n\n try {\n await createProject({\n name: options.project ?? projectName,\n interactive: options.interactive ?? false,\n version: parseVersion(options),\n });\n } catch (error) {\n console.error(\"Failed to initialize the project\", error);\n }\n};\n\nexport function initCommand(program: Command) {\n program\n .command(\"init\")\n .description(\"Initialize a new project\")\n .argument(\"[project-name]\", \"Name of the project\")\n .option(\"-p, --project\", \"Name of the project\")\n .option(\"-i, --interactive\", \"Run the command in interactive mode\")\n .option(\n \"-v, --version\",\n 'Specify development version to use. Defaults to \"main\"',\n )\n .option(\"--dev\", 'Use \"development\" version of the boilerplate')\n .option(\"--staging\", 'Use \"development\" version of the boilerplate')\n .action(init);\n}\n"]}
1
+ {"version":3,"sources":["../../src/commands/init.ts"],"names":[],"mappings":";;;AASa,MAAA,IAAA,GAWT,OAAO,WAAA,EAAa,OAAY,KAAA;AAClC,EAAA,OAAA,CAAQ,IAAI,0CAAmC,CAAA;AAE/C,EAAA,OAAA,CAAQ,MAAM,QAAQ,CAAA;AAEtB,EAAI,IAAA;AACF,IAAA,MAAM,aAAc,CAAA;AAAA,MAClB,IAAM,EAAA,sBAAA;AAAA,MACN,WAAa,EAAA,KAAA;AAAA,MACb,OAAA,EAAS,aAAa,OAAO;AAAA,KAC9B,CAAA;AAED,IAAQ,OAAA,CAAA,GAAA;AAAA,MACN,sDAA+C,qBAAqB,CAAA;AAAA,KACtE;AAAA,WACO,KAAO,EAAA;AACd,IAAQ,OAAA,CAAA,KAAA,CAAM,kDAA6C,KAAK,CAAA;AAAA;AAEpE;AAEO,SAAS,YAAY,OAAkB,EAAA;AAC5C,EAAA,OAAA,CACG,QAAQ,MAAM,CAAA,CACd,WAAY,CAAA,0BAA0B,EACtC,QAAS,CAAA,gBAAA,EAAkB,qBAAqB,CAAA,CAChD,OAAO,eAAiB,EAAA,qBAAqB,EAC7C,MAAO,CAAA,mBAAA,EAAqB,qCAAqC,CACjE,CAAA,MAAA;AAAA,IACC,eAAA;AAAA,IACA;AAAA,GACF,CACC,MAAO,CAAA,OAAA,EAAS,8CAA8C,CAAA,CAC9D,OAAO,WAAa,EAAA,8CAA8C,CAClE,CAAA,MAAA,CAAO,IAAI,CAAA;AAChB","file":"init.js","sourcesContent":["import { Command } from \"commander\";\nimport { createProject, parseVersion } from \"@powerhousedao/codegen\";\nimport { CommandActionType } from \"../types.js\";\nimport {\n HOME_DIR,\n POWERHOUSE_GLOBAL_DIR,\n PH_GLOBAL_PROJECT_NAME,\n} from \"../utils.js\";\n\nexport const init: CommandActionType<\n [\n string | undefined,\n {\n project?: string;\n interactive?: boolean;\n version?: string;\n dev?: boolean;\n staging?: boolean;\n },\n ]\n> = async (projectName, options) => {\n console.log(\"📦 Initializing global project...\");\n\n process.chdir(HOME_DIR);\n\n try {\n await createProject({\n name: PH_GLOBAL_PROJECT_NAME,\n interactive: false,\n version: parseVersion(options),\n });\n\n console.log(\n `🚀 Global project initialized successfully: ${POWERHOUSE_GLOBAL_DIR}`,\n );\n } catch (error) {\n console.error(\"Failed to initialize the global project\", error);\n }\n};\n\nexport function initCommand(program: Command) {\n program\n .command(\"init\")\n .description(\"Initialize a new project\")\n .argument(\"[project-name]\", \"Name of the project\")\n .option(\"-p, --project\", \"Name of the project\")\n .option(\"-i, --interactive\", \"Run the command in interactive mode\")\n .option(\n \"-v, --version\",\n 'Specify development version to use. Defaults to \"main\"',\n )\n .option(\"--dev\", 'Use \"development\" version of the boilerplate')\n .option(\"--staging\", 'Use \"development\" version of the boilerplate')\n .action(init);\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,5 @@
1
1
  export { commands } from './commands/index.js';
2
- export { getConfig } from '@powerhousedao/config/powerhouse';
3
- export { dev, devCommand } from './commands/dev.js';
4
- export { helpCommand } from './commands/help.js';
2
+ export { HOME_DIR, PH_BIN, PH_GLOBAL_PROJECT_NAME, POWERHOUSE_CONFIG_FILE, POWERHOUSE_GLOBAL_DIR, PackageManager, ProjectInfo, defaultPathValidation, findNodeProjectRoot, forwardPHCommand, getPackageManagerFromLockfile, getProjectInfo, isPowerhouseProject, packageManagers } from './utils.js';
5
3
  export { init, initCommand } from './commands/init.js';
6
- export { generate, generateCommand } from './commands/generate.js';
7
- export { DefaultReactorOptions, ReactorOptions, reactor, reactorCommand } from './commands/reactor.js';
8
4
  import 'commander';
9
5
  import './types.js';
10
- import '@powerhousedao/reactor-local';
package/dist/utils.d.ts CHANGED
@@ -1 +1,37 @@
1
- export { getConfig } from '@powerhousedao/config/powerhouse';
1
+ declare const PH_BIN = "ph";
2
+ declare const POWERHOUSE_CONFIG_FILE = "powerhouse.config.json";
3
+ declare const HOME_DIR: string;
4
+ declare const PH_GLOBAL_PROJECT_NAME = ".ph";
5
+ declare const POWERHOUSE_GLOBAL_DIR: string;
6
+ declare const packageManagers: {
7
+ bun: {
8
+ execCommand: string;
9
+ lockfile: string;
10
+ };
11
+ pnpm: {
12
+ execCommand: string;
13
+ lockfile: string;
14
+ };
15
+ yarn: {
16
+ execCommand: string;
17
+ lockfile: string;
18
+ };
19
+ npm: {
20
+ execCommand: string;
21
+ lockfile: string;
22
+ };
23
+ };
24
+ type ProjectInfo = {
25
+ isGlobal: boolean;
26
+ path: string;
27
+ };
28
+ type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
29
+ type PathValidation = (dir: string) => boolean;
30
+ declare function defaultPathValidation(): boolean;
31
+ declare function isPowerhouseProject(dir: string): boolean;
32
+ declare function findNodeProjectRoot(dir: string, pathValidation?: PathValidation): string | null;
33
+ declare function getPackageManagerFromLockfile(dir: string): PackageManager;
34
+ declare function getProjectInfo(debug?: boolean): ProjectInfo;
35
+ declare function forwardPHCommand(packageManager: PackageManager, projectPath: string, args: string, debug?: boolean): void;
36
+
37
+ export { HOME_DIR, PH_BIN, PH_GLOBAL_PROJECT_NAME, POWERHOUSE_CONFIG_FILE, POWERHOUSE_GLOBAL_DIR, type PackageManager, type ProjectInfo, defaultPathValidation, findNodeProjectRoot, forwardPHCommand, getPackageManagerFromLockfile, getProjectInfo, isPowerhouseProject, packageManagers };
package/dist/utils.js CHANGED
@@ -1,3 +1,95 @@
1
- export { getConfig } from '@powerhousedao/config/powerhouse';
1
+ import path, { dirname } from 'node:path';
2
+ import fs from 'node:fs';
3
+ import { execSync } from 'node:child_process';
4
+ import { homedir } from 'node:os';
5
+
6
+ const PH_BIN = "ph";
7
+ const POWERHOUSE_CONFIG_FILE = "powerhouse.config.json";
8
+ const HOME_DIR = homedir();
9
+ const PH_GLOBAL_PROJECT_NAME = ".ph";
10
+ const POWERHOUSE_GLOBAL_DIR = path.join(
11
+ HOME_DIR,
12
+ PH_GLOBAL_PROJECT_NAME
13
+ );
14
+ const packageManagers = {
15
+ bun: {
16
+ execCommand: `bun ${PH_BIN} {{arguments}}`,
17
+ lockfile: "bun.lock"
18
+ },
19
+ pnpm: {
20
+ execCommand: `pnpm exec ${PH_BIN} {{arguments}}`,
21
+ lockfile: "pnpm-lock.yaml"
22
+ },
23
+ yarn: {
24
+ execCommand: `yarn ${PH_BIN} {{arguments}}`,
25
+ lockfile: "yarn.lock"
26
+ },
27
+ npm: {
28
+ execCommand: `npx ${PH_BIN} {{arguments}}`,
29
+ lockfile: "package-lock.json"
30
+ }
31
+ };
32
+ function defaultPathValidation() {
33
+ return true;
34
+ }
35
+ function isPowerhouseProject(dir) {
36
+ const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);
37
+ return fs.existsSync(powerhouseConfigPath);
38
+ }
39
+ function findNodeProjectRoot(dir, pathValidation = defaultPathValidation) {
40
+ const packageJsonPath = path.join(dir, "package.json");
41
+ if (fs.existsSync(packageJsonPath) && pathValidation(dir)) {
42
+ return dir;
43
+ }
44
+ const parentDir = dirname(dir);
45
+ if (parentDir === dir) {
46
+ return null;
47
+ }
48
+ return findNodeProjectRoot(parentDir, pathValidation);
49
+ }
50
+ function getPackageManagerFromLockfile(dir) {
51
+ if (fs.existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {
52
+ return "pnpm";
53
+ } else if (fs.existsSync(path.join(dir, packageManagers.yarn.lockfile))) {
54
+ return "yarn";
55
+ } else if (fs.existsSync(path.join(dir, packageManagers.bun.lockfile))) {
56
+ return "bun";
57
+ }
58
+ return "npm";
59
+ }
60
+ function getProjectInfo(debug) {
61
+ const currentPath = process.cwd();
62
+ if (debug) {
63
+ console.log(">>> currentPath:", currentPath);
64
+ }
65
+ const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);
66
+ if (!projectPath) {
67
+ return {
68
+ isGlobal: true,
69
+ path: POWERHOUSE_GLOBAL_DIR
70
+ };
71
+ }
72
+ return {
73
+ isGlobal: false,
74
+ path: projectPath
75
+ };
76
+ }
77
+ function forwardPHCommand(packageManager, projectPath, args, debug) {
78
+ const manager = packageManagers[packageManager];
79
+ const execCommand = manager.execCommand.replace("{{arguments}}", args);
80
+ const commandOptions = { cwd: projectPath };
81
+ if (debug) {
82
+ console.log(">>> execCommand:", execCommand);
83
+ console.log(">>> commandOptions:", commandOptions);
84
+ console.log(">>> projectPath:", projectPath);
85
+ console.log(">>> packageManager:", packageManager);
86
+ }
87
+ execSync(execCommand, {
88
+ stdio: "inherit",
89
+ ...commandOptions
90
+ });
91
+ }
92
+
93
+ export { HOME_DIR, PH_BIN, PH_GLOBAL_PROJECT_NAME, POWERHOUSE_CONFIG_FILE, POWERHOUSE_GLOBAL_DIR, defaultPathValidation, findNodeProjectRoot, forwardPHCommand, getPackageManagerFromLockfile, getProjectInfo, isPowerhouseProject, packageManagers };
2
94
  //# sourceMappingURL=utils.js.map
3
95
  //# sourceMappingURL=utils.js.map
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"utils.js","sourcesContent":[]}
1
+ {"version":3,"sources":["../src/utils.ts"],"names":[],"mappings":";;;;;AAKO,MAAM,MAAS,GAAA;AACf,MAAM,sBAAyB,GAAA;AAC/B,MAAM,WAAW,OAAQ;AACzB,MAAM,sBAAyB,GAAA;AAC/B,MAAM,wBAAwB,IAAK,CAAA,IAAA;AAAA,EACxC,QAAA;AAAA,EACA;AACF;AAEO,MAAM,eAAkB,GAAA;AAAA,EAC7B,GAAK,EAAA;AAAA,IACH,WAAA,EAAa,OAAO,MAAM,CAAA,cAAA,CAAA;AAAA,IAC1B,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,IAAM,EAAA;AAAA,IACJ,WAAA,EAAa,aAAa,MAAM,CAAA,cAAA,CAAA;AAAA,IAChC,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,IAAM,EAAA;AAAA,IACJ,WAAA,EAAa,QAAQ,MAAM,CAAA,cAAA,CAAA;AAAA,IAC3B,QAAU,EAAA;AAAA,GACZ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IAAO,OAAA,KAAA;AAAA;AAGT,EAAO,OAAA,KAAA;AACT;AAEO,SAAS,eAAe,KAA8B,EAAA;AAC3D,EAAM,MAAA,WAAA,GAAc,QAAQ,GAAI,EAAA;AAEhC,EAAA,IAAI,KAAO,EAAA;AACT,IAAQ,OAAA,CAAA,GAAA,CAAI,oBAAoB,WAAW,CAAA;AAAA;AAG7C,EAAM,MAAA,WAAA,GAAc,mBAAoB,CAAA,WAAA,EAAa,mBAAmB,CAAA;AAExE,EAAA,IAAI,CAAC,WAAa,EAAA;AAChB,IAAO,OAAA;AAAA,MACL,QAAU,EAAA,IAAA;AAAA,MACV,IAAM,EAAA;AAAA,KACR;AAAA;AAGF,EAAO,OAAA;AAAA,IACL,QAAU,EAAA,KAAA;AAAA,IACV,IAAM,EAAA;AAAA,GACR;AACF;AAEO,SAAS,gBACd,CAAA,cAAA,EACA,WACA,EAAA,IAAA,EACA,KACA,EAAA;AACA,EAAM,MAAA,OAAA,GAAU,gBAAgB,cAAc,CAAA;AAC9C,EAAA,MAAM,WAAc,GAAA,OAAA,CAAQ,WAAY,CAAA,OAAA,CAAQ,iBAAiB,IAAI,CAAA;AAErE,EAAM,MAAA,cAAA,GAAiB,EAAE,GAAA,EAAK,WAAY,EAAA;AAE1C,EAAA,IAAI,KAAO,EAAA;AACT,IAAQ,OAAA,CAAA,GAAA,CAAI,oBAAoB,WAAW,CAAA;AAC3C,IAAQ,OAAA,CAAA,GAAA,CAAI,uBAAuB,cAAc,CAAA;AACjD,IAAQ,OAAA,CAAA,GAAA,CAAI,oBAAoB,WAAW,CAAA;AAC3C,IAAQ,OAAA,CAAA,GAAA,CAAI,uBAAuB,cAAc,CAAA;AAAA;AAGnD,EAAA,QAAA,CAAS,WAAa,EAAA;AAAA,IACpB,KAAO,EAAA,SAAA;AAAA,IACP,GAAG;AAAA,GACJ,CAAA;AACH","file":"utils.js","sourcesContent":["import path, { dirname } from \"node:path\";\nimport fs from \"node:fs\";\nimport { execSync } from \"node:child_process\";\nimport { homedir } from \"node:os\";\n\nexport const PH_BIN = \"ph\";\nexport const POWERHOUSE_CONFIG_FILE = \"powerhouse.config.json\";\nexport const HOME_DIR = homedir();\nexport const PH_GLOBAL_PROJECT_NAME = \".ph\";\nexport const POWERHOUSE_GLOBAL_DIR = path.join(\n HOME_DIR,\n PH_GLOBAL_PROJECT_NAME,\n);\n\nexport const packageManagers = {\n bun: {\n execCommand: `bun ${PH_BIN} {{arguments}}`,\n lockfile: \"bun.lock\",\n },\n pnpm: {\n execCommand: `pnpm exec ${PH_BIN} {{arguments}}`,\n lockfile: \"pnpm-lock.yaml\",\n },\n yarn: {\n execCommand: `yarn ${PH_BIN} {{arguments}}`,\n lockfile: \"yarn.lock\",\n },\n npm: {\n execCommand: `npx ${PH_BIN} {{arguments}}`,\n lockfile: \"package-lock.json\",\n },\n};\n\nexport type ProjectInfo = {\n isGlobal: boolean;\n path: string;\n};\n\nexport type PackageManager = \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\ntype PathValidation = (dir: string) => boolean;\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 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 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 };\n }\n\n return {\n isGlobal: false,\n path: projectPath,\n };\n}\n\nexport function forwardPHCommand(\n packageManager: PackageManager,\n projectPath: string,\n args: string,\n debug?: boolean,\n) {\n const manager = packageManagers[packageManager];\n const execCommand = manager.execCommand.replace(\"{{arguments}}\", args);\n\n const commandOptions = { cwd: projectPath };\n\n if (debug) {\n console.log(\">>> execCommand:\", execCommand);\n console.log(\">>> commandOptions:\", commandOptions);\n console.log(\">>> projectPath:\", projectPath);\n console.log(\">>> packageManager:\", packageManager);\n }\n\n execSync(execCommand, {\n stdio: \"inherit\",\n ...commandOptions,\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ph-cmd",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0-only",
6
6
  "type": "module",
@@ -22,28 +22,10 @@
22
22
  ],
23
23
  "keywords": [],
24
24
  "author": "",
25
- "devDependencies": {
26
- "@powerhousedao/analytics-engine-core": "^0.3.0",
27
- "@powerhousedao/analytics-engine-graphql": "^0.2.1",
28
- "@powerhousedao/analytics-engine-pg": "^0.3.0",
29
- "graphql-tag": "^2.12.6",
30
- "knex": "^3.1.0",
31
- "luxon": "^3.5.0",
32
- "document-drive": "1.13.4"
33
- },
25
+ "devDependencies": {},
34
26
  "dependencies": {
35
- "@powerhousedao/connect": "1.0.0-dev.181",
36
- "colorette": "^2.0.20",
37
27
  "commander": "^12.1.0",
38
- "graphql": "^16.9.0",
39
- "react": "^18.3.1",
40
- "react-dom": "^18.3.1",
41
- "@powerhousedao/codegen": "0.29.0",
42
- "@powerhousedao/config": "1.6.0",
43
- "@powerhousedao/design-system": "1.19.1",
44
- "@powerhousedao/reactor-local": "1.13.1",
45
- "document-model-libs": "1.125.4",
46
- "@powerhousedao/scalars": "1.16.0"
28
+ "@powerhousedao/codegen": "0.30.0"
47
29
  },
48
30
  "scripts": {
49
31
  "build": "tsup",
@@ -1,8 +0,0 @@
1
- import { ConnectStudioOptions } from '@powerhousedao/connect';
2
- import { Command } from 'commander';
3
-
4
- type ConnectOptions = ConnectStudioOptions;
5
- declare function startConnect(connectOptions: ConnectOptions): Promise<void | undefined>;
6
- declare function connectCommand(program: Command): void;
7
-
8
- export { type ConnectOptions, connectCommand, startConnect };
@@ -1,33 +0,0 @@
1
- import { startConnectStudio } from '@powerhousedao/connect';
2
- import { getConfig } from '@powerhousedao/config/powerhouse';
3
-
4
- async function startConnect(connectOptions) {
5
- const { documentModelsDir, editorsDir } = getConfig();
6
- const options = { documentModelsDir, editorsDir, ...connectOptions };
7
- return await startConnectStudio(options);
8
- }
9
- function connectCommand(program) {
10
- program.command("connect").description("Starts Connect Studio").option("-p, --port <port>", "Port to run the server on", "3000").option("-h, --host", "Expose the server to the network").option(
11
- "--config-file <configFile>",
12
- "Path to the powerhouse.config.js file"
13
- ).option(
14
- "-le, --local-editors <localEditors>",
15
- "Link local document editors path"
16
- ).option(
17
- "-ld, --local-documents <localDocuments>",
18
- "Link local documents path"
19
- ).action(async (...args) => {
20
- await startConnectStudio(...args);
21
- });
22
- }
23
- if (process.argv.at(2) === "spawn") {
24
- const optionsArg = process.argv.at(3);
25
- const options = optionsArg ? JSON.parse(optionsArg) : {};
26
- startConnect(options).catch((e) => {
27
- throw e;
28
- });
29
- }
30
-
31
- export { connectCommand, startConnect };
32
- //# sourceMappingURL=connect.js.map
33
- //# sourceMappingURL=connect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/commands/connect.ts"],"names":[],"mappings":";;;AASA,eAAsB,aAAa,cAAgC,EAAA;AACjE,EAAA,MAAM,EAAE,iBAAA,EAAmB,UAAW,EAAA,GAAI,SAAU,EAAA;AACpD,EAAA,MAAM,OAAU,GAAA,EAAE,iBAAmB,EAAA,UAAA,EAAY,GAAG,cAAe,EAAA;AACnE,EAAO,OAAA,MAAM,mBAAmB,OAAO,CAAA;AACzC;AAEO,SAAS,eAAe,OAAkB,EAAA;AAC/C,EAAA,OAAA,CACG,OAAQ,CAAA,SAAS,CACjB,CAAA,WAAA,CAAY,uBAAuB,CACnC,CAAA,MAAA,CAAO,mBAAqB,EAAA,2BAAA,EAA6B,MAAM,CAAA,CAC/D,MAAO,CAAA,YAAA,EAAc,kCAAkC,CACvD,CAAA,MAAA;AAAA,IACC,4BAAA;AAAA,IACA;AAAA,GAED,CAAA,MAAA;AAAA,IACC,qCAAA;AAAA,IACA;AAAA,GAED,CAAA,MAAA;AAAA,IACC,yCAAA;AAAA,IACA;AAAA,GACF,CACC,MAAO,CAAA,OAAA,GAAU,IAA2B,KAAA;AAC3C,IAAM,MAAA,kBAAA,CAAmB,GAAG,IAAI,CAAA;AAAA,GACjC,CAAA;AACL;AAEA,IAAI,OAAQ,CAAA,IAAA,CAAK,EAAG,CAAA,CAAC,MAAM,OAAS,EAAA;AAClC,EAAA,MAAM,UAAa,GAAA,OAAA,CAAQ,IAAK,CAAA,EAAA,CAAG,CAAC,CAAA;AACpC,EAAA,MAAM,UAAU,UAAc,GAAA,IAAA,CAAK,KAAM,CAAA,UAAU,IAAuB,EAAC;AAC3E,EAAA,YAAA,CAAa,OAAO,CAAA,CAAE,KAAM,CAAA,CAAC,CAAe,KAAA;AAC1C,IAAM,MAAA,CAAA;AAAA,GACP,CAAA;AACH","file":"connect.js","sourcesContent":["import {\n startConnectStudio,\n ConnectStudioOptions,\n} from \"@powerhousedao/connect\";\nimport { getConfig } from \"@powerhousedao/config/powerhouse\";\nimport { Command } from \"commander\";\n\nexport type ConnectOptions = ConnectStudioOptions;\n\nexport async function startConnect(connectOptions: ConnectOptions) {\n const { documentModelsDir, editorsDir } = getConfig();\n const options = { documentModelsDir, editorsDir, ...connectOptions };\n return await startConnectStudio(options);\n}\n\nexport function connectCommand(program: Command) {\n program\n .command(\"connect\")\n .description(\"Starts Connect Studio\")\n .option(\"-p, --port <port>\", \"Port to run the server on\", \"3000\")\n .option(\"-h, --host\", \"Expose the server to the network\")\n .option(\n \"--config-file <configFile>\",\n \"Path to the powerhouse.config.js file\",\n )\n .option(\n \"-le, --local-editors <localEditors>\",\n \"Link local document editors path\",\n )\n .option(\n \"-ld, --local-documents <localDocuments>\",\n \"Link local documents path\",\n )\n .action(async (...args: [ConnectOptions]) => {\n await startConnectStudio(...args);\n });\n}\n\nif (process.argv.at(2) === \"spawn\") {\n const optionsArg = process.argv.at(3);\n const options = optionsArg ? (JSON.parse(optionsArg) as ConnectOptions) : {};\n startConnect(options).catch((e: unknown) => {\n throw e;\n });\n}\n"]}
@@ -1,13 +0,0 @@
1
- import { Command } from 'commander';
2
- import { CommandActionType } from '../types.js';
3
-
4
- declare const dev: CommandActionType<[
5
- {
6
- generate?: boolean;
7
- watch?: boolean;
8
- reactorPort?: number;
9
- }
10
- ]>;
11
- declare function devCommand(program: Command): void;
12
-
13
- export { dev, devCommand };
@@ -1,90 +0,0 @@
1
- import path, { dirname } from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
- import { fork } from 'node:child_process';
4
- import { blue, red, green } from 'colorette';
5
- import { DefaultReactorOptions } from './reactor.js';
6
-
7
- const __dirname = import.meta.dirname || dirname(fileURLToPath(import.meta.url));
8
- function spawnLocalReactor(options) {
9
- const child = fork(
10
- path.join(__dirname, "reactor.js"),
11
- ["spawn", JSON.stringify(options)],
12
- { silent: true }
13
- );
14
- return new Promise((resolve) => {
15
- child.on("message", (message) => {
16
- const text = message.toString();
17
- if (text.startsWith("driveUrl:")) {
18
- const driveUrl = text.substring("driveUrl:".length);
19
- resolve({ driveUrl });
20
- }
21
- });
22
- child.stdout.on("data", (data) => {
23
- const message = data.toString();
24
- const lines = message.split("\n").filter((line) => line.trim().length);
25
- for (const line of lines) {
26
- process.stdout.write(blue(`[Reactor]: ${line}
27
- `));
28
- }
29
- });
30
- child.stderr.on("error", (data) => {
31
- process.stderr.write(red(`[Reactor]: ${data.toString()}`));
32
- });
33
- child.on("error", (err) => {
34
- process.stderr.write(red(`[Reactor]: ${err}`));
35
- });
36
- child.on("exit", (code) => {
37
- console.log(`Reactor process exited with code ${code}`);
38
- });
39
- });
40
- }
41
- async function spawnConnect(options, localReactorUrl) {
42
- const child = fork(
43
- path.join(__dirname, "connect.js"),
44
- ["spawn", JSON.stringify({})],
45
- {
46
- silent: true,
47
- env: {
48
- ...process.env,
49
- // TODO add studio variables?
50
- LOCAL_DOCUMENT_MODELS: options?.localDocuments,
51
- LOCAL_DOCUMENT_EDITORS: options?.localEditors,
52
- PH_CONNECT_DEFAULT_DRIVES_URL: localReactorUrl
53
- }
54
- }
55
- );
56
- return new Promise((resolve) => {
57
- child.stdout.on("data", (data) => {
58
- resolve();
59
- process.stdout.write(green(`[Connect]: ${data.toString()}`));
60
- });
61
- child.stderr.on("data", (data) => {
62
- process.stderr.write(red(`[Connect]: ${data.toString()}`));
63
- });
64
- child.on("close", (code) => {
65
- console.log(`Connect process exited with code ${code}`);
66
- });
67
- });
68
- }
69
- const dev = async ({ generate, watch, reactorPort = DefaultReactorOptions.port }) => {
70
- try {
71
- const { driveUrl } = await spawnLocalReactor({
72
- generate,
73
- port: reactorPort,
74
- watch
75
- });
76
- await spawnConnect(void 0, driveUrl);
77
- } catch (error) {
78
- console.error(error);
79
- }
80
- };
81
- function devCommand(program) {
82
- program.command("dev").description("Starts dev environment").option("--generate", "generate code when document model is updated").option("--reactor-port <port>", "port to use for the reactor").option(
83
- "-w, --watch",
84
- "if the reactor should watch for local changes to document models and processors"
85
- ).action(dev);
86
- }
87
-
88
- export { dev, devCommand };
89
- //# sourceMappingURL=dev.js.map
90
- //# sourceMappingURL=dev.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/commands/dev.ts"],"names":[],"mapp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AAE,CAAC,CAAA;AAAA,KAC5D,CAAA;AAED,IAAA,KAAA,CAAM,MAAO,CAAA,EAAA,CAAG,MAAQ,EAAA,CAAC,IAAiB,KAAA;AACxC,MAAQ,OAAA,CAAA,MAAA,CAAO,MAAM,GAAI,CAAA,CAAA,WAAA,EAAc,KAAK,QAAS,EAAC,EAAE,CAAC,CAAA;AAAA,KAC1D,CAAA;AAED,IAAM,KAAA,CAAA,EAAA,CAAG,OAAS,EAAA,CAAC,IAAS,KAAA;AAC1B,MAAQ,OAAA,CAAA,GAAA,CAAI,CAAoC,iCAAA,EAAA,IAAI,CAAE,CAAA,CAAA;AAAA,KACvD,CAAA;AAAA,GACF,CAAA;AACH;AAEa,MAAA,GAAA,GAQT,OAAO,EAAE,QAAA,EAAU,OAAO,WAAc,GAAA,qBAAA,CAAsB,MAAW,KAAA;AAC3E,EAAI,IAAA;AACF,IAAA,MAAM,EAAE,QAAA,EAAa,GAAA,MAAM,iBAAkB,CAAA;AAAA,MAC3C,QAAA;AAAA,MACA,IAAM,EAAA,WAAA;AAAA,MACN;AAAA,KACD,CAAA;AACD,IAAM,MAAA,YAAA,CAAa,QAAW,QAAQ,CAAA;AAAA,WAC/B,KAAO,EAAA;AACd,IAAA,OAAA,CAAQ,MAAM,KAAK,CAAA;AAAA;AAEvB;AAEO,SAAS,WAAW,OAAkB,EAAA;AAC3C,EAAA,OAAA,CACG,OAAQ,CAAA,KAAK,CACb,CAAA,WAAA,CAAY,wBAAwB,CAAA,CACpC,MAAO,CAAA,YAAA,EAAc,8CAA8C,CAAA,CACnE,MAAO,CAAA,uBAAA,EAAyB,6BAA6B,CAC7D,CAAA,MAAA;AAAA,IACC,aAAA;AAAA,IACA;AAAA,GACF,CACC,OAAO,GAAG,CAAA;AACf","file":"dev.js","sourcesContent":["import path, { dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { fork, ChildProcessWithoutNullStreams } from \"node:child_process\";\nimport { Command } from \"commander\";\nimport { blue, green, red } from \"colorette\";\nimport { CommandActionType } from \"../types.js\";\nimport { DefaultReactorOptions, type ReactorOptions } from \"./reactor.js\";\nimport { type ConnectOptions } from \"./connect.js\";\n\nconst __dirname =\n import.meta.dirname || dirname(fileURLToPath(import.meta.url));\n\nfunction spawnLocalReactor(options?: ReactorOptions) {\n const child = fork(\n path.join(__dirname, \"reactor.js\"),\n [\"spawn\", JSON.stringify(options)],\n { silent: true },\n ) as ChildProcessWithoutNullStreams;\n\n return new Promise<{ driveUrl: string }>((resolve) => {\n child.on(\"message\", (message) => {\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n const text = message.toString();\n\n if (text.startsWith(\"driveUrl:\")) {\n const driveUrl = text.substring(\"driveUrl:\".length);\n resolve({ driveUrl });\n }\n });\n\n child.stdout.on(\"data\", (data: Buffer) => {\n const message = data.toString();\n const lines = message.split(\"\\n\").filter((line) => line.trim().length);\n for (const line of lines) {\n process.stdout.write(blue(`[Reactor]: ${line}\\n`));\n }\n });\n\n child.stderr.on(\"error\", (data: Buffer) => {\n process.stderr.write(red(`[Reactor]: ${data.toString()}`));\n });\n child.on(\"error\", (err) => {\n process.stderr.write(red(`[Reactor]: ${err}`));\n });\n\n child.on(\"exit\", (code) => {\n console.log(`Reactor process exited with code ${code}`);\n });\n });\n}\n\nasync function spawnConnect(\n options?: ConnectOptions,\n localReactorUrl?: string,\n) {\n const child = fork(\n path.join(__dirname, \"connect.js\"),\n [\"spawn\", JSON.stringify(options ?? {})],\n {\n silent: true,\n env: {\n ...process.env,\n // TODO add studio variables?\n LOCAL_DOCUMENT_MODELS: options?.localDocuments,\n LOCAL_DOCUMENT_EDITORS: options?.localEditors,\n PH_CONNECT_DEFAULT_DRIVES_URL: localReactorUrl,\n },\n },\n ) as ChildProcessWithoutNullStreams;\n\n return new Promise<void>((resolve) => {\n child.stdout.on(\"data\", (data: Buffer) => {\n resolve();\n process.stdout.write(green(`[Connect]: ${data.toString()}`));\n });\n\n child.stderr.on(\"data\", (data: Buffer) => {\n process.stderr.write(red(`[Connect]: ${data.toString()}`));\n });\n\n child.on(\"close\", (code) => {\n console.log(`Connect process exited with code ${code}`);\n });\n });\n}\n\nexport const dev: CommandActionType<\n [\n {\n generate?: boolean;\n watch?: boolean;\n reactorPort?: number;\n },\n ]\n> = async ({ generate, watch, reactorPort = DefaultReactorOptions.port }) => {\n try {\n const { driveUrl } = await spawnLocalReactor({\n generate,\n port: reactorPort,\n watch,\n });\n await spawnConnect(undefined, driveUrl);\n } catch (error) {\n console.error(error);\n }\n};\n\nexport function devCommand(program: Command) {\n program\n .command(\"dev\")\n .description(\"Starts dev environment\")\n .option(\"--generate\", \"generate code when document model is updated\")\n .option(\"--reactor-port <port>\", \"port to use for the reactor\")\n .option(\n \"-w, --watch\",\n \"if the reactor should watch for local changes to document models and processors\",\n )\n .action(dev);\n}\n"]}
@@ -1,22 +0,0 @@
1
- import { Command } from 'commander';
2
- import { CommandActionType } from '../types.js';
3
-
4
- declare const generate: CommandActionType<[
5
- string | undefined,
6
- {
7
- interactive?: boolean;
8
- editors?: string;
9
- processors?: string;
10
- documentModels?: string;
11
- skipFormat?: boolean;
12
- watch?: boolean;
13
- editor?: string;
14
- processor?: string;
15
- documentTypes?: string;
16
- processorType?: "analytics" | "operational";
17
- subgraph?: string;
18
- }
19
- ]>;
20
- declare function generateCommand(program: Command): void;
21
-
22
- export { generate, generateCommand };
@@ -1,70 +0,0 @@
1
- import { promptDirectories, generateEditor, generateProcessor, generateSubgraph, generateFromFile, generate as generate$1 } from '@powerhousedao/codegen';
2
- import { getConfig } from '@powerhousedao/config/powerhouse';
3
-
4
- const generate = async (filePath, options) => {
5
- const baseConfig = getConfig();
6
- const config = {
7
- ...baseConfig,
8
- ...{
9
- ...options.editors && { editorsDir: options.editors },
10
- ...options.processors && { processorsDir: options.processors },
11
- ...options.documentModels && {
12
- documentModelsDir: options.documentModels
13
- },
14
- ...options.skipFormat && { skipFormat: options.skipFormat },
15
- ...options.interactive && { interactive: options.interactive },
16
- ...options.watch && { watch: options.watch }
17
- }
18
- };
19
- const command = {
20
- editor: !!options.editor,
21
- editorName: options.editor,
22
- documentTypes: options.documentTypes,
23
- processor: !!options.processor,
24
- processorName: options.processor,
25
- processorType: options.processorType,
26
- subgraph: !!options.subgraph,
27
- subgraphName: options.subgraph
28
- };
29
- if (config.interactive) {
30
- const result = await promptDirectories(config);
31
- Object.assign(config, result);
32
- }
33
- if (command.editor) {
34
- if (!command.editorName) {
35
- throw new Error("Editor name is required (--editor or -e)");
36
- }
37
- await generateEditor(
38
- command.editorName,
39
- command.documentTypes?.split(/[|,;]/g) ?? [],
40
- config
41
- );
42
- return;
43
- }
44
- if (command.processor && options.processor) {
45
- const processorType = options.processorType === "operational" ? "operational" : "analytics";
46
- await generateProcessor(
47
- options.processor,
48
- processorType,
49
- options.documentTypes?.split(",") ?? [],
50
- config
51
- );
52
- return;
53
- }
54
- if (command.subgraph && command.subgraphName) {
55
- await generateSubgraph(command.subgraphName, config);
56
- return;
57
- }
58
- if (filePath) {
59
- await generateFromFile(filePath, config);
60
- return;
61
- }
62
- await generate$1(config);
63
- };
64
- function generateCommand(program) {
65
- program.command("generate").description("Generate code from the document models").argument("[document-model-file]", "Path to the document model file").option("-i, --interactive", "Run the command in interactive mode").option("--editors <type>", "Path to the editors directory").option("-e, --editor <type>", "Editor Name").option("--processors <type>", "Path to the processors directory").option("-p, --processor <type>", "Processor Name").option("--processor-type <type>", "Processor Type").option("-s, --subgraph <type>", "Subgraph Name").option("--document-models <type>", "Path to the document models directory").option("--document-types <type>", "Supported document types by the editor").option("-sf, --skip-format", "Skip formatting the generated code").option("-w, --watch", "Watch the generated code").action(generate);
66
- }
67
-
68
- export { generate, generateCommand };
69
- //# sourceMappingURL=generate.js.map
70
- //# sourceMappingURL=generate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/commands/generate.ts"],"names":["generateCode"],"mappings":";;;AAYa,MAAA,QAAA,GAiBT,OAAO,QAAA,EAAU,OAAY,KAAA;AAC/B,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gBAAgB,CAAA,CACjD,MAAO,CAAA,yBAAA,EAA2B,gBAAgB,CAAA,CAClD,MAAO,CAAA,uBAAA,EAAyB,eAAe,CAAA,CAC/C,MAAO,CAAA,0BAAA,EAA4B,uCAAuC,CAAA,CAC1E,OAAO,yBAA2B,EAAA,wCAAwC,CAC1E,CAAA,MAAA,CAAO,oBAAsB,EAAA,oCAAoC,CACjE,CAAA,MAAA,CAAO,aAAe,EAAA,0BAA0B,CAChD,CAAA,MAAA,CAAO,QAAQ,CAAA;AACpB","file":"generate.js","sourcesContent":["import {\n generate as generateCode,\n generateEditor,\n generateFromFile,\n generateProcessor,\n generateSubgraph,\n promptDirectories,\n} from \"@powerhousedao/codegen\";\nimport { Command } from \"commander\";\nimport { CommandActionType } from \"../types.js\";\nimport { getConfig } from \"@powerhousedao/config/powerhouse\";\n\nexport const generate: CommandActionType<\n [\n string | undefined,\n {\n interactive?: boolean;\n editors?: string;\n processors?: string;\n documentModels?: string;\n skipFormat?: boolean;\n watch?: boolean;\n editor?: string;\n processor?: string;\n documentTypes?: string;\n processorType?: \"analytics\" | \"operational\";\n subgraph?: string;\n },\n ]\n> = async (filePath, options) => {\n const baseConfig = getConfig();\n\n const config = {\n ...baseConfig,\n ...{\n ...(options.editors && { editorsDir: options.editors }),\n ...(options.processors && { processorsDir: options.processors }),\n ...(options.documentModels && {\n documentModelsDir: options.documentModels,\n }),\n ...(options.skipFormat && { skipFormat: options.skipFormat }),\n ...(options.interactive && { interactive: options.interactive }),\n ...(options.watch && { watch: options.watch }),\n },\n };\n\n const command = {\n editor: !!options.editor,\n editorName: options.editor,\n documentTypes: options.documentTypes,\n processor: !!options.processor,\n processorName: options.processor,\n processorType: options.processorType,\n subgraph: !!options.subgraph,\n subgraphName: options.subgraph,\n };\n\n if (config.interactive) {\n const result = await promptDirectories(config);\n Object.assign(config, result);\n }\n\n if (command.editor) {\n if (!command.editorName) {\n throw new Error(\"Editor name is required (--editor or -e)\");\n }\n await generateEditor(\n command.editorName,\n command.documentTypes?.split(/[|,;]/g) ?? [],\n config,\n );\n\n return;\n }\n\n if (command.processor && options.processor) {\n const processorType =\n options.processorType === \"operational\" ? \"operational\" : \"analytics\";\n await generateProcessor(\n options.processor,\n processorType,\n options.documentTypes?.split(\",\") ?? [],\n config,\n );\n return;\n }\n\n if (command.subgraph && command.subgraphName) {\n await generateSubgraph(command.subgraphName, config);\n return;\n }\n\n if (filePath) {\n await generateFromFile(filePath, config);\n return;\n }\n\n await generateCode(config);\n};\n\nexport function generateCommand(program: Command) {\n program\n .command(\"generate\")\n .description(\"Generate code from the document models\")\n .argument(\"[document-model-file]\", \"Path to the document model file\")\n .option(\"-i, --interactive\", \"Run the command in interactive mode\")\n .option(\"--editors <type>\", \"Path to the editors directory\")\n .option(\"-e, --editor <type>\", \"Editor Name\")\n .option(\"--processors <type>\", \"Path to the processors directory\")\n .option(\"-p, --processor <type>\", \"Processor Name\")\n .option(\"--processor-type <type>\", \"Processor Type\")\n .option(\"-s, --subgraph <type>\", \"Subgraph Name\")\n .option(\"--document-models <type>\", \"Path to the document models directory\")\n .option(\"--document-types <type>\", \"Supported document types by the editor\")\n .option(\"-sf, --skip-format\", \"Skip formatting the generated code\")\n .option(\"-w, --watch\", \"Watch the generated code\")\n .action(generate);\n}\n"]}
@@ -1,5 +0,0 @@
1
- import { Command } from 'commander';
2
-
3
- declare function helpCommand(program: Command): void;
4
-
5
- export { helpCommand };
@@ -1,9 +0,0 @@
1
- function helpCommand(program) {
2
- program.command("help").description("Display help information").action(() => {
3
- program.help();
4
- });
5
- }
6
-
7
- export { helpCommand };
8
- //# sourceMappingURL=help.js.map
9
- //# sourceMappingURL=help.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/commands/help.ts"],"names":[],"mappings":"AAEO,SAAS,YAAY,OAAkB,EAAA;AAC5C,EAAA,OAAA,CACG,QAAQ,MAAM,CAAA,CACd,YAAY,0BAA0B,CAAA,CACtC,OAAO,MAAM;AACZ,IAAA,OAAA,CAAQ,IAAK,EAAA;AAAA,GACd,CAAA;AACL","file":"help.js","sourcesContent":["import { Command } from \"commander\";\n\nexport function helpCommand(program: Command) {\n program\n .command(\"help\")\n .description(\"Display help information\")\n .action(() => {\n program.help();\n });\n}\n"]}
@@ -1,30 +0,0 @@
1
- import { Command } from 'commander';
2
- import { CommandActionType } from '../types.js';
3
-
4
- type ProjectInfo = {
5
- isGlobal: boolean;
6
- path: string;
7
- };
8
- type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
9
- type PathValidation = (dir: string) => boolean;
10
- declare function defaultPathValidation(): boolean;
11
- declare function isPowerhouseProject(dir: string): boolean;
12
- declare function findNodeProjectRoot(dir: string, pathValidation?: PathValidation): string | null;
13
- declare function findGlobalPhPath(): string | null;
14
- declare function getPackageManagerFromPath(dir: string): PackageManager;
15
- declare function getPackageManagerFromLockfile(dir: string): PackageManager;
16
- declare function getProjectInfo(debug?: boolean): ProjectInfo;
17
- declare function installDependency(packageManager: PackageManager, dependencies: string[], global?: boolean, projectPath?: string, workspace?: boolean): void;
18
- declare function updateConfigFile(dependencies: string[], global: boolean, projectPath: string, debug?: boolean): void;
19
- declare const install: CommandActionType<[
20
- string[] | undefined,
21
- {
22
- debug?: boolean;
23
- global?: boolean;
24
- workspace?: boolean;
25
- packageManager?: string;
26
- }
27
- ]>;
28
- declare function installCommand(program: Command): void;
29
-
30
- export { type PackageManager, type ProjectInfo, defaultPathValidation, findGlobalPhPath, findNodeProjectRoot, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, install, installCommand, installDependency, isPowerhouseProject, updateConfigFile };
@@ -1,217 +0,0 @@
1
- import path, { dirname } from 'node:path';
2
- import fs from 'node:fs';
3
- import { execSync } from 'node:child_process';
4
- import { homedir } from 'node:os';
5
-
6
- const PH_BIN = "ph";
7
- const POWERHOUSE_CONFIG_FILE = "powerhouse.config.json";
8
- const SUPPORTED_PACKAGE_MANAGERS = ["npm", "yarn", "pnpm", "bun"];
9
- const GLOBAL_CONFIG_PATH = path.join(homedir(), ".ph", POWERHOUSE_CONFIG_FILE);
10
- const packageManagers = {
11
- bun: {
12
- globalPathRegexp: /[\\/].bun[\\/]/,
13
- installCommand: "bun add {{dependency}}",
14
- workspaceOption: "",
15
- lockfile: "bun.lock"
16
- },
17
- pnpm: {
18
- globalPathRegexp: /[\\/]pnpm[\\/]/,
19
- installCommand: "pnpm add {{dependency}}",
20
- workspaceOption: "--workspace-root",
21
- lockfile: "pnpm-lock.yaml"
22
- },
23
- yarn: {
24
- globalPathRegexp: /[\\/]yarn[\\/]/,
25
- installCommand: "yarn add {{dependency}}",
26
- workspaceOption: "-W",
27
- lockfile: "yarn.lock"
28
- },
29
- npm: {
30
- installCommand: "npm install {{dependency}}",
31
- workspaceOption: "",
32
- lockfile: "package-lock.json"
33
- }
34
- };
35
- function defaultPathValidation() {
36
- return true;
37
- }
38
- function isPowerhouseProject(dir) {
39
- const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);
40
- return fs.existsSync(powerhouseConfigPath);
41
- }
42
- function findNodeProjectRoot(dir, pathValidation = defaultPathValidation) {
43
- const packageJsonPath = path.join(dir, "package.json");
44
- if (fs.existsSync(packageJsonPath) && pathValidation(dir)) {
45
- return dir;
46
- }
47
- const parentDir = dirname(dir);
48
- if (parentDir === dir) {
49
- return null;
50
- }
51
- return findNodeProjectRoot(parentDir, pathValidation);
52
- }
53
- function findGlobalPhPath() {
54
- const command = process.platform === "win32" ? `where ${PH_BIN}` : `which ${PH_BIN}`;
55
- try {
56
- return execSync(command, { encoding: "utf-8" }).trim();
57
- } catch {
58
- return null;
59
- }
60
- }
61
- function getPackageManagerFromPath(dir) {
62
- const lowerCasePath = dir.toLowerCase();
63
- if (packageManagers.bun.globalPathRegexp.test(lowerCasePath)) {
64
- return "bun";
65
- } else if (packageManagers.pnpm.globalPathRegexp.test(lowerCasePath)) {
66
- return "pnpm";
67
- } else if (packageManagers.yarn.globalPathRegexp.test(lowerCasePath)) {
68
- return "yarn";
69
- }
70
- return "npm";
71
- }
72
- function getPackageManagerFromLockfile(dir) {
73
- if (fs.existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {
74
- return "pnpm";
75
- } else if (fs.existsSync(path.join(dir, packageManagers.yarn.lockfile))) {
76
- return "yarn";
77
- } else if (fs.existsSync(path.join(dir, packageManagers.bun.lockfile))) {
78
- return "bun";
79
- }
80
- return "npm";
81
- }
82
- function getProjectInfo(debug) {
83
- const currentPath = process.cwd();
84
- if (debug) {
85
- console.log(">>> currentPath", currentPath);
86
- }
87
- const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);
88
- if (!projectPath) {
89
- const globalPath = findGlobalPhPath();
90
- if (!globalPath) {
91
- throw new Error(
92
- "\u274C Could not find a powerhouse project or a global ph-cmd installation"
93
- );
94
- }
95
- return {
96
- isGlobal: true,
97
- path: globalPath
98
- };
99
- }
100
- return {
101
- isGlobal: false,
102
- path: projectPath
103
- };
104
- }
105
- function installDependency(packageManager, dependencies, global = false, projectPath, workspace) {
106
- if (!global && !projectPath) {
107
- console.error("Project path is required for local installations");
108
- }
109
- const manager = packageManagers[packageManager];
110
- let installCommand2 = manager.installCommand.replace(
111
- "{{dependency}}",
112
- dependencies.join(" ")
113
- );
114
- if (global) {
115
- installCommand2 += " -g";
116
- }
117
- if (workspace) {
118
- installCommand2 += ` ${manager.workspaceOption}`;
119
- }
120
- const commandOptions = global ? {} : { cwd: projectPath };
121
- execSync(installCommand2, {
122
- stdio: "inherit",
123
- ...commandOptions
124
- });
125
- }
126
- function updateConfigFile(dependencies, global, projectPath, debug) {
127
- const configPath = global ? GLOBAL_CONFIG_PATH : path.join(projectPath, POWERHOUSE_CONFIG_FILE);
128
- if (!global && !fs.existsSync(configPath)) {
129
- throw new Error(
130
- `powerhouse.config.json file not found. global: ${global}; projectPath: ${projectPath}`
131
- );
132
- }
133
- if (global && !fs.existsSync(configPath)) {
134
- if (debug) {
135
- console.log(">>> Creating a new global config file: ", configPath);
136
- }
137
- fs.mkdirSync(path.dirname(configPath), { recursive: true });
138
- fs.writeFileSync(configPath, "{}");
139
- }
140
- const config = JSON.parse(
141
- fs.readFileSync(configPath, "utf-8")
142
- );
143
- const updatedConfig = {
144
- ...config,
145
- projects: [...config.projects || [], ...dependencies]
146
- };
147
- fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));
148
- }
149
- const install = (dependencies, options) => {
150
- if (options.debug) {
151
- console.log(">>> command arguments", { dependencies, options });
152
- }
153
- if (!dependencies || dependencies.length === 0) {
154
- throw new Error("\u274C Dependency name is required");
155
- }
156
- if (options.packageManager && !SUPPORTED_PACKAGE_MANAGERS.includes(options.packageManager)) {
157
- throw new Error(
158
- "\u274C Unsupported package manager. Supported package managers: npm, yarn, pnpm, bun"
159
- );
160
- }
161
- const projectInfo = getProjectInfo(options.debug);
162
- if (options.debug) {
163
- console.log("\n>>> projectInfo", projectInfo);
164
- }
165
- const isGlobal = options.global || projectInfo.isGlobal;
166
- const getPackageManager = isGlobal ? getPackageManagerFromPath : getPackageManagerFromLockfile;
167
- const packageManager = options.packageManager || getPackageManager(projectInfo.path);
168
- if (options.debug) {
169
- console.log("\n>>> installDependency arguments:");
170
- console.log(">>> packageManager", packageManager);
171
- console.log(">>> dependencies", dependencies);
172
- console.log(">>> isGlobal", isGlobal);
173
- console.log(">>> projectPath", projectInfo.path);
174
- console.log(">>> workspace", options.workspace);
175
- }
176
- try {
177
- console.log("installing dependencies \u{1F4E6} ...");
178
- installDependency(
179
- packageManager,
180
- dependencies,
181
- isGlobal,
182
- projectInfo.path,
183
- options.workspace
184
- );
185
- console.log("Dependency installed successfully \u{1F389}");
186
- } catch (error) {
187
- console.error("\u274C Failed to install dependencies");
188
- throw error;
189
- }
190
- if (options.debug) {
191
- console.log("\n>>> updateConfigFile arguments:");
192
- console.log(">>> dependencies", dependencies);
193
- console.log(">>> isGlobal", isGlobal);
194
- console.log(">>> projectPath", projectInfo.path);
195
- }
196
- try {
197
- console.log("\u2699\uFE0F Updating powerhouse config file...");
198
- updateConfigFile(dependencies, isGlobal, projectInfo.path, options.debug);
199
- console.log("Config file updated successfully \u{1F389}");
200
- } catch (error) {
201
- console.error("\u274C Failed to update config file");
202
- throw error;
203
- }
204
- };
205
- function installCommand(program) {
206
- program.command("install").description("Install a powerhouse dependency").argument("[dependencies...]", "Names of the dependencies to install").option("-g, --global", "Install the dependency globally").option("--debug", "Show additional logs").option(
207
- "-w, --workspace",
208
- "Install the dependency in the workspace (use this option for monorepos)"
209
- ).option(
210
- "--package-manager <packageManager>",
211
- "force package manager to use"
212
- ).action(install);
213
- }
214
-
215
- export { defaultPathValidation, findGlobalPhPath, findNodeProjectRoot, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, install, installCommand, installDependency, isPowerhouseProject, updateConfigFile };
216
- //# sourceMappingURL=install.js.map
217
- //# sourceMappingURL=install.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/commands/install.ts"],"names":["installCommand"],"mappings":";;;;;AASA,MAAM,MAAS,GAAA,IAAA;AACf,MAAM,sBAAyB,GAAA,wBAAA;AAC/B,MAAM,0BAA6B,GAAA,CAAC,KAAO,EAAA,MAAA,EAAQ,QAAQ,KAAK,CAAA;AAChE,MAAM,qBAAqB,IAAK,CAAA,IAAA,CAAK,OAAQ,EAAA,EAAG,OAAO,sBAAsB,CAAA;AAE7E,MAAM,eAAkB,GAAA;AAAA,EACtB,GAAK,EAAA;AAAA,IACH,gBAAkB,EAAA,gBAAA;AAAA,IAClB,cAAgB,EAAA,wBAAA;AAAA,IAChB,eAAiB,EAAA,EAAA;AAAA,IACjB,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,IAAM,EAAA;AAAA,IACJ,gBAAkB,EAAA,gBAAA;AAAA,IAClB,cAAgB,EAAA,yBAAA;AAAA,IAChB,eAAiB,EAAA,kBAAA;AAAA,IACjB,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,IAAM,EAAA;AAAA,IACJ,gBAAkB,EAAA,gBAAA;AA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jB,IAAA,OAAA,CAAQ,IAAI,mCAAmC,CAAA;AAC/C,IAAQ,OAAA,CAAA,GAAA,CAAI,oBAAoB,YAAY,CAAA;AAC5C,IAAQ,OAAA,CAAA,GAAA,CAAI,gBAAgB,QAAQ,CAAA;AACpC,IAAQ,OAAA,CAAA,GAAA,CAAI,iBAAmB,EAAA,WAAA,CAAY,IAAI,CAAA;AAAA;AAGjD,EAAI,IAAA;AACF,IAAA,OAAA,CAAQ,IAAI,iDAAuC,CAAA;AACnD,IAAA,gBAAA,CAAiB,YAAc,EAAA,QAAA,EAAU,WAAY,CAAA,IAAA,EAAM,QAAQ,KAAK,CAAA;AACxE,IAAA,OAAA,CAAQ,IAAI,4CAAqC,CAAA;AAAA,WAC1C,KAAO,EAAA;AACd,IAAA,OAAA,CAAQ,MAAM,qCAAgC,CAAA;AAC9C,IAAM,MAAA,KAAA;AAAA;AAEV;AAEO,SAAS,eAAe,OAAkB,EAAA;AAC/C,EAAA,OAAA,CACG,QAAQ,SAAS,CAAA,CACjB,WAAY,CAAA,iCAAiC,EAC7C,QAAS,CAAA,mBAAA,EAAqB,sCAAsC,CAAA,CACpE,OAAO,cAAgB,EAAA,iCAAiC,EACxD,MAAO,CAAA,SAAA,EAAW,sBAAsB,CACxC,CAAA,MAAA;AAAA,IACC,iBAAA;AAAA,IACA;AAAA,GAED,CAAA,MAAA;AAAA,IACC,oCAAA;AAAA,IACA;AAAA,GACF,CACC,OAAO,OAAO,CAAA;AACnB","file":"install.js","sourcesContent":["import path, { dirname } from \"node:path\";\nimport fs from \"node:fs\";\nimport { execSync } from \"node:child_process\";\nimport { homedir } from \"node:os\";\nimport { Command } from \"commander\";\nimport { PowerhouseConfig } from \"@powerhousedao/config/powerhouse\";\n\nimport { CommandActionType } from \"../types.js\";\n\nconst PH_BIN = \"ph\";\nconst POWERHOUSE_CONFIG_FILE = \"powerhouse.config.json\";\nconst SUPPORTED_PACKAGE_MANAGERS = [\"npm\", \"yarn\", \"pnpm\", \"bun\"];\nconst GLOBAL_CONFIG_PATH = path.join(homedir(), \".ph\", POWERHOUSE_CONFIG_FILE);\n\nconst packageManagers = {\n bun: {\n globalPathRegexp: /[\\\\/].bun[\\\\/]/,\n installCommand: \"bun add {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"bun.lock\",\n },\n pnpm: {\n globalPathRegexp: /[\\\\/]pnpm[\\\\/]/,\n installCommand: \"pnpm add {{dependency}}\",\n workspaceOption: \"--workspace-root\",\n lockfile: \"pnpm-lock.yaml\",\n },\n yarn: {\n globalPathRegexp: /[\\\\/]yarn[\\\\/]/,\n installCommand: \"yarn add {{dependency}}\",\n workspaceOption: \"-W\",\n lockfile: \"yarn.lock\",\n },\n npm: {\n installCommand: \"npm install {{dependency}}\",\n workspaceOption: \"\",\n lockfile: \"package-lock.json\",\n },\n};\n\nexport type ProjectInfo = {\n isGlobal: boolean;\n path: string;\n};\n\nexport type PackageManager = \"npm\" | \"yarn\" | \"pnpm\" | \"bun\";\n\ntype PathValidation = (dir: string) => boolean;\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 findGlobalPhPath() {\n const command =\n process.platform === \"win32\" ? `where ${PH_BIN}` : `which ${PH_BIN}`;\n\n try {\n return execSync(command, { encoding: \"utf-8\" }).trim();\n } catch {\n return null;\n }\n}\n\nexport function getPackageManagerFromPath(dir: string): PackageManager {\n const lowerCasePath = dir.toLowerCase();\n\n if (packageManagers.bun.globalPathRegexp.test(lowerCasePath)) {\n return \"bun\";\n } else if (packageManagers.pnpm.globalPathRegexp.test(lowerCasePath)) {\n return \"pnpm\";\n } else if (packageManagers.yarn.globalPathRegexp.test(lowerCasePath)) {\n return \"yarn\";\n }\n\n return \"npm\";\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 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 const globalPath = findGlobalPhPath();\n\n if (!globalPath) {\n throw new Error(\n \"❌ Could not find a powerhouse project or a global ph-cmd installation\",\n );\n }\n\n return {\n isGlobal: true,\n path: globalPath,\n };\n }\n\n return {\n isGlobal: false,\n path: projectPath,\n };\n}\n\nexport function installDependency(\n packageManager: PackageManager,\n dependencies: string[],\n global = false,\n projectPath?: string,\n workspace?: boolean,\n) {\n if (!global && !projectPath) {\n console.error(\"Project path is required for local installations\");\n }\n\n const manager = packageManagers[packageManager];\n\n let installCommand = manager.installCommand.replace(\n \"{{dependency}}\",\n dependencies.join(\" \"),\n );\n\n if (global) {\n installCommand += \" -g\";\n }\n\n if (workspace) {\n installCommand += ` ${manager.workspaceOption}`;\n }\n\n const commandOptions = global ? {} : { cwd: projectPath };\n\n execSync(installCommand, {\n stdio: \"inherit\",\n ...commandOptions,\n });\n}\n\nexport function updateConfigFile(\n dependencies: string[],\n global: boolean,\n projectPath: string,\n debug?: boolean,\n) {\n const configPath = global\n ? GLOBAL_CONFIG_PATH\n : path.join(projectPath, POWERHOUSE_CONFIG_FILE);\n\n if (!global && !fs.existsSync(configPath)) {\n throw new Error(\n `powerhouse.config.json file not found. global: ${global}; projectPath: ${projectPath}`,\n );\n }\n\n // Create an empty config file if it doesn't exist (only for global)\n if (global && !fs.existsSync(configPath)) {\n if (debug) {\n console.log(\">>> Creating a new global config file: \", configPath);\n }\n\n // create empty json config file in config path and create missing directories\n fs.mkdirSync(path.dirname(configPath), { recursive: true });\n fs.writeFileSync(configPath, \"{}\");\n }\n\n const config = JSON.parse(\n fs.readFileSync(configPath, \"utf-8\"),\n ) as PowerhouseConfig;\n\n const updatedConfig: PowerhouseConfig = {\n ...config,\n projects: [...((config.projects || []) as string[]), ...dependencies],\n };\n\n fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));\n}\n\nexport const install: CommandActionType<\n [\n string[] | undefined,\n {\n debug?: boolean;\n global?: boolean;\n workspace?: boolean;\n packageManager?: string;\n },\n ]\n> = (dependencies, options) => {\n if (options.debug) {\n console.log(\">>> command arguments\", { dependencies, options });\n }\n\n if (!dependencies || dependencies.length === 0) {\n throw new Error(\"❌ Dependency name is required\");\n }\n\n if (\n options.packageManager &&\n !SUPPORTED_PACKAGE_MANAGERS.includes(options.packageManager)\n ) {\n throw new Error(\n \"❌ Unsupported package manager. Supported package managers: npm, yarn, pnpm, bun\",\n );\n }\n\n const projectInfo = getProjectInfo(options.debug);\n\n if (options.debug) {\n console.log(\"\\n>>> projectInfo\", projectInfo);\n }\n\n const isGlobal = options.global || projectInfo.isGlobal;\n const getPackageManager = isGlobal\n ? getPackageManagerFromPath\n : getPackageManagerFromLockfile;\n\n const packageManager =\n options.packageManager || getPackageManager(projectInfo.path);\n\n if (options.debug) {\n console.log(\"\\n>>> installDependency arguments:\");\n console.log(\">>> packageManager\", packageManager);\n console.log(\">>> dependencies\", dependencies);\n console.log(\">>> isGlobal\", isGlobal);\n console.log(\">>> projectPath\", projectInfo.path);\n console.log(\">>> workspace\", options.workspace);\n }\n\n try {\n console.log(\"installing dependencies 📦 ...\");\n installDependency(\n packageManager as PackageManager,\n dependencies,\n isGlobal,\n projectInfo.path,\n options.workspace,\n );\n console.log(\"Dependency installed successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to install dependencies\");\n throw error;\n }\n\n if (options.debug) {\n console.log(\"\\n>>> updateConfigFile arguments:\");\n console.log(\">>> dependencies\", dependencies);\n console.log(\">>> isGlobal\", isGlobal);\n console.log(\">>> projectPath\", projectInfo.path);\n }\n\n try {\n console.log(\"⚙️ Updating powerhouse config file...\");\n updateConfigFile(dependencies, isGlobal, projectInfo.path, options.debug);\n console.log(\"Config file updated successfully 🎉\");\n } catch (error) {\n console.error(\"❌ Failed to update config file\");\n throw error;\n }\n};\n\nexport function installCommand(program: Command) {\n program\n .command(\"install\")\n .description(\"Install a powerhouse dependency\")\n .argument(\"[dependencies...]\", \"Names of the dependencies to install\")\n .option(\"-g, --global\", \"Install the dependency globally\")\n .option(\"--debug\", \"Show additional logs\")\n .option(\n \"-w, --workspace\",\n \"Install the dependency in the workspace (use this option for monorepos)\",\n )\n .option(\n \"--package-manager <packageManager>\",\n \"force package manager to use\",\n )\n .action(install);\n}\n"]}
@@ -1,35 +0,0 @@
1
- import { Command } from 'commander';
2
- import { StartServerOptions, LocalReactor } from '@powerhousedao/reactor-local';
3
- import { CommandActionType } from '../types.js';
4
-
5
- type ReactorOptions = StartServerOptions & {
6
- generate?: boolean;
7
- watch?: boolean;
8
- dbPath?: string;
9
- };
10
- declare const DefaultReactorOptions: {
11
- dev: boolean;
12
- port: number;
13
- storagePath: string;
14
- dbPath: string;
15
- drive: {
16
- global: {
17
- id: string;
18
- name: string;
19
- icon: string;
20
- slug: string;
21
- };
22
- local: {
23
- availableOffline: true;
24
- listeners: never[];
25
- sharingType: string;
26
- triggers: never[];
27
- };
28
- };
29
- };
30
- declare const reactor: CommandActionType<[
31
- ReactorOptions
32
- ], Promise<LocalReactor>>;
33
- declare function reactorCommand(program: Command): void;
34
-
35
- export { DefaultReactorOptions, type ReactorOptions, reactor, reactorCommand };
@@ -1,69 +0,0 @@
1
- import { DefaultStartServerOptions, startServer } from '@powerhousedao/reactor-local';
2
- import { generateFromFile } from '@powerhousedao/codegen';
3
- import { getConfig } from '@powerhousedao/config/powerhouse';
4
-
5
- const DefaultReactorOptions = {
6
- ...DefaultStartServerOptions,
7
- dev: true
8
- };
9
- async function startLocalReactor(reactorOptions) {
10
- const baseConfig = getConfig();
11
- const options = { ...DefaultReactorOptions, ...reactorOptions };
12
- const reactor2 = await startServer(options);
13
- if (options.generate) {
14
- await reactor2.addListener(
15
- "powerhouse",
16
- {
17
- onStrands: async function(strands) {
18
- const documentPaths = /* @__PURE__ */ new Set();
19
- for (const strand of strands) {
20
- documentPaths.add(
21
- reactor2.getDocumentPath(strand.driveId, strand.documentId)
22
- );
23
- }
24
- for (const path of documentPaths) {
25
- await generateFromFile(path, baseConfig);
26
- }
27
- return Promise.resolve();
28
- },
29
- onDisconnect: () => Promise.resolve()
30
- },
31
- {
32
- filter: {
33
- documentType: ["powerhouse/document-model"],
34
- scope: ["global"],
35
- branch: ["*"],
36
- documentId: ["*"]
37
- },
38
- block: false,
39
- listenerId: "reactor-local-document-model-generator",
40
- label: "reactor-local-document-model-generator"
41
- }
42
- );
43
- }
44
- return reactor2;
45
- }
46
- const reactor = (options) => {
47
- return startLocalReactor(options);
48
- };
49
- function reactorCommand(program) {
50
- program.command("reactor").description("Starts local reactor").option("--port <PORT>", "port to host the api", "4001").option("--generate", "generate code when document model is updated").option("--db-path <DB_PATH>", "path to the database").option(
51
- "-w, --watch",
52
- "if the reactor should watch for local changes to document models and processors"
53
- ).action(async (...args) => {
54
- await reactor(...args);
55
- });
56
- }
57
- if (process.argv.at(2) === "spawn") {
58
- const optionsArg = process.argv.at(3);
59
- const options = optionsArg ? JSON.parse(optionsArg) : {};
60
- startLocalReactor(options).then((reactor2) => {
61
- process.send?.(`driveUrl:${reactor2.driveUrl}`);
62
- }).catch((e) => {
63
- throw e;
64
- });
65
- }
66
-
67
- export { DefaultReactorOptions, reactor, reactorComm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,KAAA;AAAA,QACP,UAAY,EAAA,wCAAA;AAAA,QACZ,KAAO,EAAA;AAAA;AACT;AACF;AAEF,EAAOA,OAAAA,QAAAA;AACT;AAEa,MAAA,OAAA,GAGT,CAAC,OAAY,KAAA;AACf,EAAA,OAAO,kBAAkB,OAAO,CAAA;AAClC;AAEO,SAAS,eAAe,OAAkB,EAAA;AAC/C,EAAA,OAAA,CACG,QAAQ,SAAS,CAAA,CACjB,YAAY,sBAAsB,CAAA,CAClC,OAAO,eAAiB,EAAA,sBAAA,EAAwB,MAAM,CAAA,CACtD,OAAO,YAAc,EAAA,8CAA8C,EACnE,MAAO,CAAA,qBAAA,EAAuB,sBAAsB,CACpD,CAAA,MAAA;AAAA,IACC,aAAA;AAAA,IACA;AAAA,GACF,CACC,MAAO,CAAA,OAAA,GAAU,IAA2B,KAAA;AAC3C,IAAM,MAAA,OAAA,CAAQ,GAAG,IAAI,CAAA;AAAA,GACtB,CAAA;AACL;AAEA,IAAI,OAAQ,CAAA,IAAA,CAAK,EAAG,CAAA,CAAC,MAAM,OAAS,EAAA;AAClC,EAAA,MAAM,UAAa,GAAA,OAAA,CAAQ,IAAK,CAAA,EAAA,CAAG,CAAC,CAAA;AACpC,EAAA,MAAM,UAAU,UAAc,GAAA,IAAA,CAAK,KAAM,CAAA,UAAU,IAAuB,EAAC;AAC3E,EAAA,iBAAA,CAAkB,OAAO,CAAA,CACtB,IAAK,CAAA,CAACA,QAAY,KAAA;AACjB,IAAA,OAAA,CAAQ,IAAO,GAAA,CAAA,SAAA,EAAYA,QAAQ,CAAA,QAAQ,CAAE,CAAA,CAAA;AAAA,GAC9C,CAAA,CACA,KAAM,CAAA,CAAC,CAAe,KAAA;AACrB,IAAM,MAAA,CAAA;AAAA,GACP,CAAA;AACL","file":"reactor.js","sourcesContent":["import { Command } from \"commander\";\nimport {\n DefaultStartServerOptions,\n startServer,\n StartServerOptions,\n LocalReactor,\n} from \"@powerhousedao/reactor-local\";\nimport { generateFromFile } from \"@powerhousedao/codegen\";\nimport { CommandActionType } from \"../types.js\";\nimport { getConfig } from \"@powerhousedao/config/powerhouse\";\n\nexport type ReactorOptions = StartServerOptions & {\n generate?: boolean;\n watch?: boolean;\n dbPath?: string;\n};\n\nexport const DefaultReactorOptions = {\n ...DefaultStartServerOptions,\n dev: true,\n};\n\nasync function startLocalReactor(reactorOptions: ReactorOptions) {\n const baseConfig = getConfig();\n const options = { ...DefaultReactorOptions, ...reactorOptions };\n const reactor = await startServer(options);\n\n if (options.generate) {\n const generateTransmitter = await reactor.addListener(\n \"powerhouse\",\n {\n onStrands: async function (strands) {\n const documentPaths = new Set<string>();\n for (const strand of strands) {\n documentPaths.add(\n reactor.getDocumentPath(strand.driveId, strand.documentId),\n );\n }\n for (const path of documentPaths) {\n await generateFromFile(path, baseConfig);\n }\n return Promise.resolve();\n },\n onDisconnect: () => Promise.resolve(),\n },\n {\n filter: {\n documentType: [\"powerhouse/document-model\"],\n scope: [\"global\"],\n branch: [\"*\"],\n documentId: [\"*\"],\n },\n block: false,\n listenerId: \"reactor-local-document-model-generator\",\n label: \"reactor-local-document-model-generator\",\n },\n );\n }\n return reactor;\n}\n\nexport const reactor: CommandActionType<\n [ReactorOptions],\n Promise<LocalReactor>\n> = (options) => {\n return startLocalReactor(options);\n};\n\nexport function reactorCommand(program: Command) {\n program\n .command(\"reactor\")\n .description(\"Starts local reactor\")\n .option(\"--port <PORT>\", \"port to host the api\", \"4001\")\n .option(\"--generate\", \"generate code when document model is updated\")\n .option(\"--db-path <DB_PATH>\", \"path to the database\")\n .option(\n \"-w, --watch\",\n \"if the reactor should watch for local changes to document models and processors\",\n )\n .action(async (...args: [ReactorOptions]) => {\n await reactor(...args);\n });\n}\n\nif (process.argv.at(2) === \"spawn\") {\n const optionsArg = process.argv.at(3);\n const options = optionsArg ? (JSON.parse(optionsArg) as ReactorOptions) : {};\n startLocalReactor(options)\n .then((reactor) => {\n process.send?.(`driveUrl:${reactor.driveUrl}`);\n })\n .catch((e: unknown) => {\n throw e;\n });\n}\n"]}