ph-cmd 0.18.2 → 0.19.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.
@@ -9,6 +9,7 @@ import { reactorCommand } from './reactor.js';
9
9
  export * from './reactor.js';
10
10
  import { generateCommand } from './generate.js';
11
11
  export * from './generate.js';
12
+ import { installCommand } from './install.js';
12
13
 
13
14
  const commands = [
14
15
  initCommand,
@@ -16,7 +17,8 @@ const commands = [
16
17
  connectCommand,
17
18
  generateCommand,
18
19
  reactorCommand,
19
- helpCommand
20
+ helpCommand,
21
+ installCommand
20
22
  ];
21
23
  function registerCommands(program) {
22
24
  commands.forEach((command) => command(program));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAQO,MAAM,QAAW,GAAA;AAAA,EACtB,WAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,cAAA;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\";\n\nexport const commands = [\n initCommand,\n devCommand,\n connectCommand,\n generateCommand,\n reactorCommand,\n helpCommand,\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":";;;;;;;;;;;;;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"]}
@@ -4,7 +4,11 @@ import { CommandActionType } from '../types.js';
4
4
  declare const init: CommandActionType<[
5
5
  string | undefined,
6
6
  {
7
+ project?: string;
7
8
  interactive?: boolean;
9
+ version?: string;
10
+ dev?: boolean;
11
+ staging?: boolean;
8
12
  }
9
13
  ]>;
10
14
  declare function initCommand(program: Command): void;
@@ -1,23 +1,22 @@
1
- import { createProject } from '@powerhousedao/codegen';
1
+ import { createProject, parseVersion } from '@powerhousedao/codegen';
2
2
 
3
3
  const init = async (projectName, options) => {
4
- console.log("Initializing a new project...", projectName);
5
- console.log("Options", options);
6
- const positionalArgs = [];
7
- if (projectName) {
8
- positionalArgs.push(projectName);
9
- }
4
+ console.log("Initializing a new project...");
10
5
  try {
11
6
  await createProject({
12
- _: positionalArgs,
13
- "--interactive": !!options.interactive
7
+ name: options.project ?? projectName,
8
+ interactive: options.interactive ?? false,
9
+ version: parseVersion(options)
14
10
  });
15
- } catch {
16
- console.log("Failed to initialize the project");
11
+ } catch (error) {
12
+ console.error("Failed to initialize the project", error);
17
13
  }
18
14
  };
19
15
  function initCommand(program) {
20
- program.command("init").description("Initialize a new project").argument("[project-name]", "Name of the project").option("--interactive", "Run the command in interactive mode").action(init);
16
+ program.command("init").description("Initialize a new project").argument("[project-name]", "Name of the project").option("-p, --project", "Name of the project").option("-i, --interactive", "Run the command in interactive mode").option(
17
+ "-v, --version",
18
+ 'Specify development version to use. Defaults to "main"'
19
+ ).option("--dev", 'Use "development" version of the boilerplate').option("--staging", 'Use "development" version of the boilerplate').action(init);
21
20
  }
22
21
 
23
22
  export { init, initCommand };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/init.ts"],"names":[],"mappings":";;AAIa,MAAA,IAAA,GAET,OAAO,WAAA,EAAa,OAAY,KAAA;AAClC,EAAQ,OAAA,CAAA,GAAA,CAAI,iCAAiC,WAAW,CAAA;AACxD,EAAQ,OAAA,CAAA,GAAA,CAAI,WAAW,OAAO,CAAA;AAC9B,EAAA,MAAM,iBAA2B,EAAC;AAElC,EAAA,IAAI,WAAa,EAAA;AACf,IAAA,cAAA,CAAe,KAAK,WAAW,CAAA;AAAA;AAGjC,EAAI,IAAA;AACF,IAAA,MAAM,aAAc,CAAA;AAAA,MAClB,CAAG,EAAA,cAAA;AAAA,MACH,eAAA,EAAiB,CAAC,CAAC,OAAQ,CAAA;AAAA,KAC5B,CAAA;AAAA,GACK,CAAA,MAAA;AACN,IAAA,OAAA,CAAQ,IAAI,kCAAkC,CAAA;AAAA;AAElD;AAEO,SAAS,YAAY,OAAkB,EAAA;AAC5C,EAAA,OAAA,CACG,OAAQ,CAAA,MAAM,CACd,CAAA,WAAA,CAAY,0BAA0B,CACtC,CAAA,QAAA,CAAS,gBAAkB,EAAA,qBAAqB,EAChD,MAAO,CAAA,eAAA,EAAiB,qCAAqC,CAAA,CAC7D,OAAO,IAAI,CAAA;AAChB","file":"init.js","sourcesContent":["import { Command } from \"commander\";\nimport { createProject } from \"@powerhousedao/codegen\";\nimport { CommandActionType } from \"../types.js\";\n\nexport const init: CommandActionType<\n [string | undefined, { interactive?: boolean }]\n> = async (projectName, options) => {\n console.log(\"Initializing a new project...\", projectName);\n console.log(\"Options\", options);\n const positionalArgs: string[] = [];\n\n if (projectName) {\n positionalArgs.push(projectName);\n }\n\n try {\n await createProject({\n _: positionalArgs,\n \"--interactive\": !!options.interactive,\n });\n } catch {\n console.log(\"Failed to initialize the project\");\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(\"--interactive\", \"Run the command in interactive mode\")\n .action(init);\n}\n"]}
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"]}
@@ -0,0 +1,30 @@
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 };
@@ -0,0 +1,217 @@
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
@@ -0,0 +1 @@
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;AAAA,IAClB,cAAgB,EAAA,yBAAA;AAAA,IAChB,eAAiB,EAAA,IAAA;AAAA,IACjB,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,GAAK,EAAA;AAAA,IACH,cAAgB,EAAA,4BAAA;AAAA,IAChB,eAAiB,EAAA,EAAA;AAAA,IACjB,QAAU,EAAA;AAAA;AAEd,CAAA;AAWO,SAAS,qBAAwB,GAAA;AACtC,EAAO,OAAA,IAAA;AACT;AAEO,SAAS,oBAAoB,GAAa,EAAA;AAC/C,EAAA,MAAM,oBAAuB,GAAA,IAAA,CAAK,IAAK,CAAA,GAAA,EAAK,sB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AQ,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ph-cmd",
3
- "version": "0.18.2",
3
+ "version": "0.19.0",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0-only",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "graphql-tag": "^2.12.6",
30
30
  "knex": "^3.1.0",
31
31
  "luxon": "^3.5.0",
32
- "document-drive": "1.13.3"
32
+ "document-drive": "1.13.4"
33
33
  },
34
34
  "dependencies": {
35
35
  "@powerhousedao/connect": "1.0.0-dev.181",
@@ -38,11 +38,11 @@
38
38
  "graphql": "^16.9.0",
39
39
  "react": "^18.3.1",
40
40
  "react-dom": "^18.3.1",
41
- "@powerhousedao/config": "1.5.0",
42
- "@powerhousedao/codegen": "0.28.1",
43
- "@powerhousedao/design-system": "1.19.0",
44
- "@powerhousedao/reactor-local": "1.13.0",
45
- "document-model-libs": "1.125.3",
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
46
  "@powerhousedao/scalars": "1.16.0"
47
47
  },
48
48
  "scripts": {