@powerhousedao/ph-cli 0.16.0 → 0.18.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/commands/dev.d.ts
CHANGED
package/dist/commands/dev.js
CHANGED
|
@@ -41,7 +41,7 @@ function spawnLocalReactor(options) {
|
|
|
41
41
|
async function spawnConnect(options, localReactorUrl) {
|
|
42
42
|
const child = fork(
|
|
43
43
|
path.join(__dirname, "connect.js"),
|
|
44
|
-
["spawn", JSON.stringify(
|
|
44
|
+
["spawn", JSON.stringify(options)],
|
|
45
45
|
{
|
|
46
46
|
silent: true,
|
|
47
47
|
env: {
|
|
@@ -66,20 +66,28 @@ async function spawnConnect(options, localReactorUrl) {
|
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
-
const dev = async ({
|
|
69
|
+
const dev = async ({
|
|
70
|
+
generate,
|
|
71
|
+
watch,
|
|
72
|
+
reactorPort = DefaultReactorOptions.port,
|
|
73
|
+
configFile
|
|
74
|
+
}) => {
|
|
70
75
|
try {
|
|
71
76
|
const { driveUrl } = await spawnLocalReactor({
|
|
72
77
|
generate,
|
|
73
78
|
port: reactorPort,
|
|
74
79
|
watch
|
|
75
80
|
});
|
|
76
|
-
await spawnConnect(
|
|
81
|
+
await spawnConnect({ configFile }, driveUrl);
|
|
77
82
|
} catch (error) {
|
|
78
83
|
console.error(error);
|
|
79
84
|
}
|
|
80
85
|
};
|
|
81
86
|
function devCommand(program) {
|
|
82
87
|
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(
|
|
88
|
+
"--config-file <configFile>",
|
|
89
|
+
"Path to the powerhouse.config.js file"
|
|
90
|
+
).option(
|
|
83
91
|
"-w, --watch",
|
|
84
92
|
"if the reactor should watch for local changes to document models and processors"
|
|
85
93
|
).action(dev);
|
package/dist/commands/dev.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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,CAAA;AACH;AAEO,MAAM,MAST,OAAO;AAAA,EACT,QAAA;AAAA,EACA,KAAA;AAAA,EACA,cAAc,qBAAsB,CAAA,IAAA;AAAA,EACpC;AACF,CAAM,KAAA;AACJ,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,IAAA,MAAM,YAAa,CAAA,EAAE,UAAW,EAAA,EAAG,QAAQ,CAAA;AAAA,WACpC,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,4BAAA;AAAA,IACA;AAAA,GAED,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 configFile?: string;\n },\n ]\n> = async ({\n generate,\n watch,\n reactorPort = DefaultReactorOptions.port,\n configFile,\n}) => {\n try {\n const { driveUrl } = await spawnLocalReactor({\n generate,\n port: reactorPort,\n watch,\n });\n await spawnConnect({ configFile }, 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 \"--config-file <configFile>\",\n \"Path to the powerhouse.config.js file\",\n )\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"]}
|
|
@@ -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[],
|
|
18
|
-
declare function
|
|
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,
|
|
29
|
+
export { type PackageManager, type ProjectInfo, defaultPathValidation, findNodeProjectRoot, getPackageManagerFromLockfile, getPackageManagerFromPath, getProjectInfo, install, installCommand, installDependency, isPowerhouseProject, updateConfigFile };
|
package/dist/commands/install.js
CHANGED
|
@@ -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,
|
|
124
|
-
if (!
|
|
125
|
-
|
|
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
|
|
142
|
-
|
|
143
|
-
|
|
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.
|
|
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
|
|
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
|
-
|
|
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
|
|
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,
|
|
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 {
|
|
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,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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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 .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;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.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
|
@@ -29,21 +29,21 @@
|
|
|
29
29
|
"graphql-tag": "^2.12.6",
|
|
30
30
|
"knex": "^3.1.0",
|
|
31
31
|
"luxon": "^3.5.0",
|
|
32
|
-
"document-drive": "1.14.
|
|
32
|
+
"document-drive": "1.14.1"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@powerhousedao/connect": "1.0.0-dev.
|
|
35
|
+
"@powerhousedao/connect": "1.0.0-dev.187",
|
|
36
36
|
"colorette": "^2.0.20",
|
|
37
37
|
"commander": "^12.1.0",
|
|
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.
|
|
42
|
-
"@powerhousedao/config": "1.
|
|
43
|
-
"@powerhousedao/codegen": "0.30.0",
|
|
41
|
+
"@powerhousedao/design-system": "1.20.1",
|
|
42
|
+
"@powerhousedao/config": "1.9.0",
|
|
44
43
|
"@powerhousedao/scalars": "1.17.0",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
44
|
+
"document-model-libs": "1.126.1",
|
|
45
|
+
"@powerhousedao/reactor-local": "1.14.1",
|
|
46
|
+
"@powerhousedao/codegen": "0.30.1"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsup",
|