@powerhousedao/ph-cli 0.16.0 → 0.17.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.
@@ -10,13 +10,11 @@ type PathValidation = (dir: string) => boolean;
10
10
  declare function defaultPathValidation(): boolean;
11
11
  declare function isPowerhouseProject(dir: string): boolean;
12
12
  declare function findNodeProjectRoot(dir: string, pathValidation?: PathValidation): string | null;
13
- declare function findGlobalPhPath(): string | null;
14
13
  declare function getPackageManagerFromPath(dir: string): PackageManager;
15
14
  declare function getPackageManagerFromLockfile(dir: string): PackageManager;
16
15
  declare function getProjectInfo(debug?: boolean): ProjectInfo;
17
- declare function installDependency(packageManager: PackageManager, dependencies: string[], global?: boolean, projectPath?: string, workspace?: boolean): void;
18
- declare function createGlobalPHProject(debug?: boolean): void;
19
- declare function updateConfigFile(dependencies: string[], global: boolean, projectPath: string, debug?: boolean): void;
16
+ declare function installDependency(packageManager: PackageManager, dependencies: string[], projectPath: string, workspace?: boolean): void;
17
+ declare function updateConfigFile(dependencies: string[], projectPath: string): void;
20
18
  declare const install: CommandActionType<[
21
19
  string[] | undefined,
22
20
  {
@@ -28,4 +26,4 @@ declare const install: CommandActionType<[
28
26
  ]>;
29
27
  declare function installCommand(program: Command): void;
30
28
 
31
- export { type PackageManager, type ProjectInfo, createGlobalPHProject, defaultPathValidation, findGlobalPhPath, findNodeProjectRoot, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, install, installCommand, installDependency, isPowerhouseProject, updateConfigFile };
29
+ export { type PackageManager, type ProjectInfo, defaultPathValidation, findNodeProjectRoot, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, install, installCommand, installDependency, isPowerhouseProject, updateConfigFile };
@@ -3,28 +3,9 @@ import fs from 'node:fs';
3
3
  import { execSync } from 'node:child_process';
4
4
  import { homedir } from 'node:os';
5
5
 
6
- const PH_BIN = "ph";
7
6
  const POWERHOUSE_CONFIG_FILE = "powerhouse.config.json";
8
7
  const SUPPORTED_PACKAGE_MANAGERS = ["npm", "yarn", "pnpm", "bun"];
9
8
  const POWERHOUSE_GLOBAL_DIR = path.join(homedir(), ".ph");
10
- const GLOBAL_CONFIG_PATH = path.join(
11
- POWERHOUSE_GLOBAL_DIR,
12
- POWERHOUSE_CONFIG_FILE
13
- );
14
- const GLOBAL_PACKAGE_JSON_PATH = path.join(
15
- POWERHOUSE_GLOBAL_DIR,
16
- "package.json"
17
- );
18
- const defaultPackageJson = {
19
- name: "global-powerhouse-env",
20
- version: "1.0.0",
21
- description: "",
22
- author: "powerhouse",
23
- license: "ISC",
24
- dependencies: {
25
- "document-model": "^2.15.0"
26
- }
27
- };
28
9
  const packageManagers = {
29
10
  bun: {
30
11
  globalPathRegexp: /[\\/].bun[\\/]/,
@@ -68,14 +49,6 @@ function findNodeProjectRoot(dir, pathValidation = defaultPathValidation) {
68
49
  }
69
50
  return findNodeProjectRoot(parentDir, pathValidation);
70
51
  }
71
- function findGlobalPhPath() {
72
- const command = process.platform === "win32" ? `where ${PH_BIN}` : `which ${PH_BIN}`;
73
- try {
74
- return execSync(command, { encoding: "utf-8" }).trim();
75
- } catch {
76
- return null;
77
- }
78
- }
79
52
  function getPackageManagerFromPath(dir) {
80
53
  const lowerCasePath = dir.toLowerCase();
81
54
  if (packageManagers.bun.globalPathRegexp.test(lowerCasePath)) {
@@ -104,12 +77,6 @@ function getProjectInfo(debug) {
104
77
  }
105
78
  const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);
106
79
  if (!projectPath) {
107
- const globalPath = findGlobalPhPath();
108
- if (!globalPath) {
109
- throw new Error(
110
- "\u274C Could not find a powerhouse project or a global ph-cmd installation"
111
- );
112
- }
113
80
  return {
114
81
  isGlobal: true,
115
82
  path: POWERHOUSE_GLOBAL_DIR
@@ -120,9 +87,9 @@ function getProjectInfo(debug) {
120
87
  path: projectPath
121
88
  };
122
89
  }
123
- function installDependency(packageManager, dependencies, global = false, projectPath, workspace) {
124
- if (!global && !projectPath) {
125
- console.error("Project path is required for local installations");
90
+ function installDependency(packageManager, dependencies, projectPath, workspace) {
91
+ if (!fs.existsSync(projectPath)) {
92
+ throw new Error(`Project path not found: ${projectPath}`);
126
93
  }
127
94
  const manager = packageManagers[packageManager];
128
95
  let installCommand2 = manager.installCommand.replace(
@@ -138,55 +105,24 @@ function installDependency(packageManager, dependencies, global = false, project
138
105
  ...commandOptions
139
106
  });
140
107
  }
141
- function createGlobalPHProject(debug = false) {
142
- if (!fs.existsSync(POWERHOUSE_GLOBAL_DIR)) {
143
- if (debug) {
144
- console.log(">>> Creating a new global powerhouse project");
145
- }
146
- fs.mkdirSync(POWERHOUSE_GLOBAL_DIR, { recursive: true });
147
- }
148
- if (!fs.existsSync(GLOBAL_PACKAGE_JSON_PATH)) {
149
- if (debug) {
150
- console.log(">>> Creating a new global package.json file");
151
- }
152
- fs.writeFileSync(
153
- GLOBAL_PACKAGE_JSON_PATH,
154
- JSON.stringify(defaultPackageJson, null, 2)
155
- );
156
- }
157
- if (!fs.existsSync(GLOBAL_CONFIG_PATH)) {
158
- if (debug) {
159
- console.log(">>> Creating a new global config file");
160
- }
161
- fs.writeFileSync(GLOBAL_CONFIG_PATH, "{}");
162
- }
163
- }
164
- function updateConfigFile(dependencies, global, projectPath, debug) {
165
- const configPath = global ? GLOBAL_CONFIG_PATH : path.join(projectPath, POWERHOUSE_CONFIG_FILE);
166
- if (!global && !fs.existsSync(configPath)) {
108
+ function updateConfigFile(dependencies, projectPath) {
109
+ const configPath = path.join(projectPath, POWERHOUSE_CONFIG_FILE);
110
+ if (!fs.existsSync(configPath)) {
167
111
  throw new Error(
168
- `powerhouse.config.json file not found. global: ${global}; projectPath: ${projectPath}`
112
+ `powerhouse.config.json file not found. projectPath: ${projectPath}`
169
113
  );
170
114
  }
171
- if (global && !fs.existsSync(configPath)) {
172
- if (debug) {
173
- console.log(">>> Creating a new global config file: ", configPath);
174
- }
175
- fs.mkdirSync(path.dirname(configPath), { recursive: true });
176
- fs.writeFileSync(configPath, "{}");
177
- }
178
115
  const config = JSON.parse(
179
116
  fs.readFileSync(configPath, "utf-8")
180
117
  );
181
- const mappedProjects = dependencies.map(
118
+ const mappedPackages = dependencies.map(
182
119
  (dep) => ({
183
- packageName: dep,
184
- global
120
+ packageName: dep
185
121
  })
186
122
  );
187
123
  const updatedConfig = {
188
124
  ...config,
189
- projects: [...config.projects ?? [], ...mappedProjects]
125
+ packages: [...config.packages || [], ...mappedPackages]
190
126
  };
191
127
  fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));
192
128
  }
@@ -207,11 +143,7 @@ const install = (dependencies, options) => {
207
143
  console.log("\n>>> projectInfo", projectInfo);
208
144
  }
209
145
  const isGlobal = options.global || projectInfo.isGlobal;
210
- const getPackageManager = isGlobal ? getPackageManagerFromPath : getPackageManagerFromLockfile;
211
- const packageManager = options.packageManager || getPackageManager(projectInfo.path);
212
- if (isGlobal) {
213
- createGlobalPHProject(options.debug);
214
- }
146
+ const packageManager = options.packageManager || getPackageManagerFromLockfile(projectInfo.path);
215
147
  if (options.debug) {
216
148
  console.log("\n>>> installDependency arguments:");
217
149
  console.log(">>> packageManager", packageManager);
@@ -225,7 +157,6 @@ const install = (dependencies, options) => {
225
157
  installDependency(
226
158
  packageManager,
227
159
  dependencies,
228
- isGlobal,
229
160
  projectInfo.path,
230
161
  options.workspace
231
162
  );
@@ -237,12 +168,11 @@ const install = (dependencies, options) => {
237
168
  if (options.debug) {
238
169
  console.log("\n>>> updateConfigFile arguments:");
239
170
  console.log(">>> dependencies", dependencies);
240
- console.log(">>> isGlobal", isGlobal);
241
171
  console.log(">>> projectPath", projectInfo.path);
242
172
  }
243
173
  try {
244
174
  console.log("\u2699\uFE0F Updating powerhouse config file...");
245
- updateConfigFile(dependencies, isGlobal, projectInfo.path, options.debug);
175
+ updateConfigFile(dependencies, projectInfo.path);
246
176
  console.log("Config file updated successfully \u{1F389}");
247
177
  } catch (error) {
248
178
  console.error("\u274C Failed to update config file");
@@ -259,6 +189,6 @@ function installCommand(program) {
259
189
  ).action(install);
260
190
  }
261
191
 
262
- export { createGlobalPHProject, defaultPathValidation, findGlobalPhPath, findNodeProjectRoot, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, install, installCommand, installDependency, isPowerhouseProject, updateConfigFile };
192
+ export { defaultPathValidation, findNodeProjectRoot, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, install, installCommand, installDependency, isPowerhouseProject, updateConfigFile };
263
193
  //# sourceMappingURL=install.js.map
264
194
  //# sourceMappingURL=install.js.map
@@ -1 +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,qBAAwB,GAAA,IAAA,CAAK,IAAK,CAAA,OAAA,IAAW,KAAK,CAAA;AACxD,MAAM,qBAAqB,IAAK,CAAA,IAAA;AAAA,EAC9B,qBAAA;AAAA,EACA;AACF,CAAA;AACA,MAAM,2BAA2B,IAAK,CAAA,IAAA;AAAA,EACpC,qBAAA;AAAA,EACA;AACF,CAAA;AAEA,MAAM,kBAAqB,GAAA;AAAA,EACzB,IAAM,EAAA,uBAAA;AAAA,EACN,OAAS,EAAA,OAAA;AAAA,EACT,WAAa,EAAA,EAAA;AAAA,EACb,MAAQ,EAAA,YAAA;AAAA,EACR,OAAS,EAAA,KAAA;AAAA,EACT,YAAc,EAAA;AAAA,IACZ,gBAAkB,EAAA;AAAA;AAEtB,CAAA;AAEA,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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AA;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 POWERHOUSE_GLOBAL_DIR = path.join(homedir(), \".ph\");\nconst GLOBAL_CONFIG_PATH = path.join(\n POWERHOUSE_GLOBAL_DIR,\n POWERHOUSE_CONFIG_FILE,\n);\nconst GLOBAL_PACKAGE_JSON_PATH = path.join(\n POWERHOUSE_GLOBAL_DIR,\n \"package.json\",\n);\n\nconst defaultPackageJson = {\n name: \"global-powerhouse-env\",\n version: \"1.0.0\",\n description: \"\",\n author: \"powerhouse\",\n license: \"ISC\",\n dependencies: {\n \"document-model\": \"^2.15.0\",\n },\n};\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: POWERHOUSE_GLOBAL_DIR,\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 (workspace) {\n installCommand += ` ${manager.workspaceOption}`;\n }\n\n const commandOptions = { cwd: projectPath };\n\n execSync(installCommand, {\n stdio: \"inherit\",\n ...commandOptions,\n });\n}\n\nexport function createGlobalPHProject(debug = false) {\n if (!fs.existsSync(POWERHOUSE_GLOBAL_DIR)) {\n if (debug) {\n console.log(\">>> Creating a new global powerhouse project\");\n }\n fs.mkdirSync(POWERHOUSE_GLOBAL_DIR, { recursive: true });\n }\n\n if (!fs.existsSync(GLOBAL_PACKAGE_JSON_PATH)) {\n if (debug) {\n console.log(\">>> Creating a new global package.json file\");\n }\n fs.writeFileSync(\n GLOBAL_PACKAGE_JSON_PATH,\n JSON.stringify(defaultPackageJson, null, 2),\n );\n }\n\n if (!fs.existsSync(GLOBAL_CONFIG_PATH)) {\n if (debug) {\n console.log(\">>> Creating a new global config file\");\n }\n fs.writeFileSync(GLOBAL_CONFIG_PATH, \"{}\");\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 mappedProjects: PowerhouseConfig[\"projects\"] = dependencies.map(\n (dep) => ({\n packageName: dep,\n global,\n }),\n );\n\n const updatedConfig: PowerhouseConfig = {\n ...config,\n projects: [...(config.projects ?? []), ...mappedProjects],\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 (isGlobal) {\n createGlobalPHProject(options.debug);\n }\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
+ {"version":3,"sources":["../../src/commands/install.ts"],"names":["installCommand"],"mappings":";;;;;AASA,MAAM,sBAAyB,GAAA,wBAAA;AAC/B,MAAM,0BAA6B,GAAA,CAAC,KAAO,EAAA,MAAA,EAAQ,QAAQ,KAAK,CAAA;AAChE,MAAM,qBAAwB,GAAA,IAAA,CAAK,IAAK,CAAA,OAAA,IAAW,KAAK,CAAA;AAExD,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,sBAAsB,CAAA;AAElE,EA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,IAAI,mCAAmC,CAAA;AAC/C,IAAQ,OAAA,CAAA,GAAA,CAAI,oBAAoB,YAAY,CAAA;AAC5C,IAAQ,OAAA,CAAA,GAAA,CAAI,iBAAmB,EAAA,WAAA,CAAY,IAAI,CAAA;AAAA;AAGjD,EAAI,IAAA;AACF,IAAA,OAAA,CAAQ,IAAI,iDAAuC,CAAA;AACnD,IAAiB,gBAAA,CAAA,YAAA,EAAc,YAAY,IAAI,CAAA;AAC/C,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 POWERHOUSE_CONFIG_FILE = \"powerhouse.config.json\";\nconst SUPPORTED_PACKAGE_MANAGERS = [\"npm\", \"yarn\", \"pnpm\", \"bun\"];\nconst POWERHOUSE_GLOBAL_DIR = path.join(homedir(), \".ph\");\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 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 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 installDependency(\n packageManager: PackageManager,\n dependencies: string[],\n projectPath: string,\n workspace?: boolean,\n) {\n if (!fs.existsSync(projectPath)) {\n throw new Error(`Project path not found: ${projectPath}`);\n }\n\n const manager = packageManagers[packageManager];\n\n let installCommand = manager.installCommand.replace(\n \"{{dependency}}\",\n dependencies.join(\" \"),\n );\n\n if (workspace) {\n installCommand += ` ${manager.workspaceOption}`;\n }\n\n const commandOptions = { cwd: projectPath };\n\n execSync(installCommand, {\n stdio: \"inherit\",\n ...commandOptions,\n });\n}\n\nexport function updateConfigFile(dependencies: string[], projectPath: string) {\n const configPath = path.join(projectPath, POWERHOUSE_CONFIG_FILE);\n\n if (!fs.existsSync(configPath)) {\n throw new Error(\n `powerhouse.config.json file not found. projectPath: ${projectPath}`,\n );\n }\n\n const config = JSON.parse(\n fs.readFileSync(configPath, \"utf-8\"),\n ) as PowerhouseConfig;\n\n const mappedPackages: PowerhouseConfig[\"packages\"] = dependencies.map(\n (dep) => ({\n packageName: dep,\n }),\n );\n\n const updatedConfig: PowerhouseConfig = {\n ...config,\n packages: [...(config.packages || []), ...mappedPackages],\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 packageManager =\n options.packageManager || getPackageManagerFromLockfile(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 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(\">>> projectPath\", projectInfo.path);\n }\n\n try {\n console.log(\"⚙️ Updating powerhouse config file...\");\n updateConfigFile(dependencies, projectInfo.path);\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": "@powerhousedao/ph-cli",
3
- "version": "0.16.0",
3
+ "version": "0.17.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.14.0"
32
+ "document-drive": "1.14.1"
33
33
  },
34
34
  "dependencies": {
35
35
  "@powerhousedao/connect": "1.0.0-dev.181",
@@ -38,12 +38,12 @@
38
38
  "graphql": "^16.9.0",
39
39
  "react": "^18.3.1",
40
40
  "react-dom": "^18.3.1",
41
- "@powerhousedao/design-system": "1.20.0",
42
- "@powerhousedao/config": "1.8.0",
43
- "@powerhousedao/codegen": "0.30.0",
41
+ "@powerhousedao/codegen": "0.30.1",
42
+ "@powerhousedao/config": "1.9.0",
43
+ "@powerhousedao/design-system": "1.20.1",
44
+ "@powerhousedao/reactor-local": "1.14.1",
44
45
  "@powerhousedao/scalars": "1.17.0",
45
- "@powerhousedao/reactor-local": "1.14.0",
46
- "document-model-libs": "1.126.0"
46
+ "document-model-libs": "1.126.1"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsup",