ph-cmd 0.19.0 → 0.20.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.
|
@@ -15,6 +15,7 @@ declare function getPackageManagerFromPath(dir: string): PackageManager;
|
|
|
15
15
|
declare function getPackageManagerFromLockfile(dir: string): PackageManager;
|
|
16
16
|
declare function getProjectInfo(debug?: boolean): ProjectInfo;
|
|
17
17
|
declare function installDependency(packageManager: PackageManager, dependencies: string[], global?: boolean, projectPath?: string, workspace?: boolean): void;
|
|
18
|
+
declare function createGlobalPHProject(debug?: boolean): void;
|
|
18
19
|
declare function updateConfigFile(dependencies: string[], global: boolean, projectPath: string, debug?: boolean): void;
|
|
19
20
|
declare const install: CommandActionType<[
|
|
20
21
|
string[] | undefined,
|
|
@@ -27,4 +28,4 @@ declare const install: CommandActionType<[
|
|
|
27
28
|
]>;
|
|
28
29
|
declare function installCommand(program: Command): void;
|
|
29
30
|
|
|
30
|
-
export { type PackageManager, type ProjectInfo, defaultPathValidation, findGlobalPhPath, findNodeProjectRoot, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, install, installCommand, installDependency, isPowerhouseProject, updateConfigFile };
|
|
31
|
+
export { type PackageManager, type ProjectInfo, createGlobalPHProject, defaultPathValidation, findGlobalPhPath, findNodeProjectRoot, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, install, installCommand, installDependency, isPowerhouseProject, updateConfigFile };
|
package/dist/commands/install.js
CHANGED
|
@@ -6,7 +6,25 @@ import { homedir } from 'node:os';
|
|
|
6
6
|
const PH_BIN = "ph";
|
|
7
7
|
const POWERHOUSE_CONFIG_FILE = "powerhouse.config.json";
|
|
8
8
|
const SUPPORTED_PACKAGE_MANAGERS = ["npm", "yarn", "pnpm", "bun"];
|
|
9
|
-
const
|
|
9
|
+
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
|
+
};
|
|
10
28
|
const packageManagers = {
|
|
11
29
|
bun: {
|
|
12
30
|
globalPathRegexp: /[\\/].bun[\\/]/,
|
|
@@ -94,7 +112,7 @@ function getProjectInfo(debug) {
|
|
|
94
112
|
}
|
|
95
113
|
return {
|
|
96
114
|
isGlobal: true,
|
|
97
|
-
path:
|
|
115
|
+
path: POWERHOUSE_GLOBAL_DIR
|
|
98
116
|
};
|
|
99
117
|
}
|
|
100
118
|
return {
|
|
@@ -111,18 +129,38 @@ function installDependency(packageManager, dependencies, global = false, project
|
|
|
111
129
|
"{{dependency}}",
|
|
112
130
|
dependencies.join(" ")
|
|
113
131
|
);
|
|
114
|
-
if (global) {
|
|
115
|
-
installCommand2 += " -g";
|
|
116
|
-
}
|
|
117
132
|
if (workspace) {
|
|
118
133
|
installCommand2 += ` ${manager.workspaceOption}`;
|
|
119
134
|
}
|
|
120
|
-
const commandOptions =
|
|
135
|
+
const commandOptions = { cwd: projectPath };
|
|
121
136
|
execSync(installCommand2, {
|
|
122
137
|
stdio: "inherit",
|
|
123
138
|
...commandOptions
|
|
124
139
|
});
|
|
125
140
|
}
|
|
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
|
+
}
|
|
126
164
|
function updateConfigFile(dependencies, global, projectPath, debug) {
|
|
127
165
|
const configPath = global ? GLOBAL_CONFIG_PATH : path.join(projectPath, POWERHOUSE_CONFIG_FILE);
|
|
128
166
|
if (!global && !fs.existsSync(configPath)) {
|
|
@@ -140,9 +178,15 @@ function updateConfigFile(dependencies, global, projectPath, debug) {
|
|
|
140
178
|
const config = JSON.parse(
|
|
141
179
|
fs.readFileSync(configPath, "utf-8")
|
|
142
180
|
);
|
|
181
|
+
const mappedProjects = dependencies.map(
|
|
182
|
+
(dep) => ({
|
|
183
|
+
packageName: dep,
|
|
184
|
+
global
|
|
185
|
+
})
|
|
186
|
+
);
|
|
143
187
|
const updatedConfig = {
|
|
144
188
|
...config,
|
|
145
|
-
projects: [...config.projects
|
|
189
|
+
projects: [...config.projects ?? [], ...mappedProjects]
|
|
146
190
|
};
|
|
147
191
|
fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));
|
|
148
192
|
}
|
|
@@ -165,6 +209,9 @@ const install = (dependencies, options) => {
|
|
|
165
209
|
const isGlobal = options.global || projectInfo.isGlobal;
|
|
166
210
|
const getPackageManager = isGlobal ? getPackageManagerFromPath : getPackageManagerFromLockfile;
|
|
167
211
|
const packageManager = options.packageManager || getPackageManager(projectInfo.path);
|
|
212
|
+
if (isGlobal) {
|
|
213
|
+
createGlobalPHProject(options.debug);
|
|
214
|
+
}
|
|
168
215
|
if (options.debug) {
|
|
169
216
|
console.log("\n>>> installDependency arguments:");
|
|
170
217
|
console.log(">>> packageManager", packageManager);
|
|
@@ -212,6 +259,6 @@ function installCommand(program) {
|
|
|
212
259
|
).action(install);
|
|
213
260
|
}
|
|
214
261
|
|
|
215
|
-
export { defaultPathValidation, findGlobalPhPath, findNodeProjectRoot, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, install, installCommand, installDependency, isPowerhouseProject, updateConfigFile };
|
|
262
|
+
export { createGlobalPHProject, defaultPathValidation, findGlobalPhPath, findNodeProjectRoot, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, install, installCommand, installDependency, isPowerhouseProject, updateConfigFile };
|
|
216
263
|
//# sourceMappingURL=install.js.map
|
|
217
264
|
//# 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,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,E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AAA,CAAQ,IAAI,6CAAsC,CAAA;AAAA,WAC3C,KAAO,EAAA;AACd,IAAA,OAAA,CAAQ,MAAM,uCAAkC,CAAA;AAChD,IAAM,MAAA,KAAA;AAAA;AAGR,EAAA,IAAI,QAAQ,KAAO,EAAA;AACjB,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
|
+
{"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,2BAA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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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ph-cmd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.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.
|
|
32
|
+
"document-drive": "1.13.5"
|
|
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/codegen": "0.29.
|
|
42
|
-
"@powerhousedao/
|
|
43
|
-
"@powerhousedao/
|
|
44
|
-
"@powerhousedao/reactor-local": "1.13.
|
|
45
|
-
"
|
|
46
|
-
"
|
|
41
|
+
"@powerhousedao/codegen": "0.29.1",
|
|
42
|
+
"@powerhousedao/design-system": "1.19.2",
|
|
43
|
+
"@powerhousedao/scalars": "1.16.0",
|
|
44
|
+
"@powerhousedao/reactor-local": "1.13.2",
|
|
45
|
+
"@powerhousedao/config": "1.7.0",
|
|
46
|
+
"document-model-libs": "1.125.5"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsup",
|