@powerhousedao/ph-cli 0.30.0 → 0.31.1
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/chunk-27FF7J6K.js +45 -0
- package/dist/chunk-6O6TUXJK.js +90 -0
- package/dist/chunk-CWUXPR5K.js +109 -0
- package/dist/chunk-E3EWRF5U.js +97 -0
- package/dist/chunk-FDMMJENR.js +132 -0
- package/dist/chunk-KPMNRIJU.js +10 -0
- package/dist/chunk-OH5NZOCQ.js +85 -0
- package/dist/chunk-PUQARXW2.js +44 -0
- package/dist/chunk-X2RNXISI.js +98 -0
- package/dist/chunk-ZN4M6TJ2.js +119 -0
- package/dist/cli.js +15 -5
- package/dist/commands/connect.js +8 -42
- package/dist/commands/dev.js +8 -97
- package/dist/commands/generate.js +7 -69
- package/dist/commands/help.js +6 -9
- package/dist/commands/index.js +57 -28
- package/dist/commands/install.js +10 -193
- package/dist/commands/service.js +7 -117
- package/dist/commands/switchboard.js +10 -0
- package/dist/commands/uninstall.js +11 -0
- package/dist/index.js +84 -4
- package/dist/scripts/setup.sh +18 -6
- package/dist/types.js +0 -3
- package/dist/utils.js +28 -3
- package/package.json +12 -19
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js.map +0 -1
- package/dist/commands/connect.d.ts +0 -8
- package/dist/commands/connect.js.map +0 -1
- package/dist/commands/dev.d.ts +0 -14
- package/dist/commands/dev.js.map +0 -1
- package/dist/commands/generate.d.ts +0 -22
- package/dist/commands/generate.js.map +0 -1
- package/dist/commands/help.d.ts +0 -5
- package/dist/commands/help.js.map +0 -1
- package/dist/commands/index.d.ts +0 -16
- package/dist/commands/index.js.map +0 -1
- package/dist/commands/init.d.ts +0 -17
- package/dist/commands/init.js +0 -28
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/install.d.ts +0 -29
- package/dist/commands/install.js.map +0 -1
- package/dist/commands/reactor.d.ts +0 -36
- package/dist/commands/reactor.js +0 -79
- package/dist/commands/reactor.js.map +0 -1
- package/dist/commands/service.d.ts +0 -7
- package/dist/commands/service.js.map +0 -1
- package/dist/index.d.ts +0 -11
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts +0 -3
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -1
- package/dist/utils.js.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/commands/connect.ts
|
|
2
|
+
import {
|
|
3
|
+
startConnectStudio
|
|
4
|
+
} from "@powerhousedao/connect";
|
|
5
|
+
import { getConfig } from "@powerhousedao/config/powerhouse";
|
|
6
|
+
async function startConnect(connectOptions) {
|
|
7
|
+
const { documentModelsDir, editorsDir } = getConfig();
|
|
8
|
+
const options = { documentModelsDir, editorsDir, ...connectOptions };
|
|
9
|
+
return await startConnectStudio(options);
|
|
10
|
+
}
|
|
11
|
+
function connectCommand(program) {
|
|
12
|
+
program.command("connect").description("Starts Connect Studio").option("-p, --port <port>", "Port to run the server on", "3000").option("-h, --host", "Expose the server to the network").option("--https", "Enable HTTPS").option("--open", "Open the browser").option(
|
|
13
|
+
"--config-file <configFile>",
|
|
14
|
+
"Path to the powerhouse.config.js file"
|
|
15
|
+
).option(
|
|
16
|
+
"-le, --local-editors <localEditors>",
|
|
17
|
+
"Link local document editors path"
|
|
18
|
+
).option(
|
|
19
|
+
"-ld, --local-documents <localDocuments>",
|
|
20
|
+
"Link local documents path"
|
|
21
|
+
).action(async (...args) => {
|
|
22
|
+
const connectOptions = args.at(0) || {};
|
|
23
|
+
const { documentModelsDir, editorsDir, packages, studio } = getConfig();
|
|
24
|
+
await startConnectStudio({
|
|
25
|
+
port: studio?.port?.toString() || void 0,
|
|
26
|
+
packages,
|
|
27
|
+
localDocuments: documentModelsDir || void 0,
|
|
28
|
+
localEditors: editorsDir || void 0,
|
|
29
|
+
open: studio?.openBrowser,
|
|
30
|
+
...connectOptions
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (process.argv.at(2) === "spawn") {
|
|
35
|
+
const optionsArg = process.argv.at(3);
|
|
36
|
+
const options = optionsArg ? JSON.parse(optionsArg) : {};
|
|
37
|
+
startConnect(options).catch((e) => {
|
|
38
|
+
throw e;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
startConnect,
|
|
44
|
+
connectCommand
|
|
45
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/commands/switchboard.ts
|
|
2
|
+
import { generateFromFile } from "@powerhousedao/codegen";
|
|
3
|
+
import { getConfig } from "@powerhousedao/config/powerhouse";
|
|
4
|
+
import {
|
|
5
|
+
DefaultStartServerOptions,
|
|
6
|
+
startServer
|
|
7
|
+
} from "@powerhousedao/reactor-local";
|
|
8
|
+
var DefaultSwitchboardOptions = {
|
|
9
|
+
...DefaultStartServerOptions,
|
|
10
|
+
dev: true
|
|
11
|
+
};
|
|
12
|
+
async function startLocalSwitchboard(switchboardOptions) {
|
|
13
|
+
const baseConfig = getConfig(switchboardOptions.configFile);
|
|
14
|
+
const options = {
|
|
15
|
+
...DefaultSwitchboardOptions,
|
|
16
|
+
...switchboardOptions
|
|
17
|
+
};
|
|
18
|
+
const https = switchboardOptions.httpsKeyFile && switchboardOptions.httpsCertFile ? {
|
|
19
|
+
keyPath: switchboardOptions.httpsKeyFile,
|
|
20
|
+
certPath: switchboardOptions.httpsCertFile
|
|
21
|
+
} : void 0;
|
|
22
|
+
const reactor = await startServer({ ...options, https });
|
|
23
|
+
if (options.generate) {
|
|
24
|
+
await addGenerateTransmitter(reactor, baseConfig);
|
|
25
|
+
}
|
|
26
|
+
return reactor;
|
|
27
|
+
}
|
|
28
|
+
async function addGenerateTransmitter(reactor, config) {
|
|
29
|
+
return reactor.addListener(
|
|
30
|
+
"powerhouse",
|
|
31
|
+
{
|
|
32
|
+
onStrands: async function(strands) {
|
|
33
|
+
const documentPaths = /* @__PURE__ */ new Set();
|
|
34
|
+
for (const strand of strands) {
|
|
35
|
+
documentPaths.add(
|
|
36
|
+
reactor.getDocumentPath(strand.driveId, strand.documentId)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
for (const path of documentPaths) {
|
|
40
|
+
await generateFromFile(path, config);
|
|
41
|
+
}
|
|
42
|
+
return Promise.resolve();
|
|
43
|
+
},
|
|
44
|
+
onDisconnect: () => Promise.resolve()
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
filter: {
|
|
48
|
+
documentType: ["powerhouse/document-model"],
|
|
49
|
+
scope: ["global"],
|
|
50
|
+
branch: ["*"],
|
|
51
|
+
documentId: ["*"]
|
|
52
|
+
},
|
|
53
|
+
block: false,
|
|
54
|
+
listenerId: "reactor-local-document-model-generator",
|
|
55
|
+
label: "reactor-local-document-model-generator"
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
var switchboard = (options) => {
|
|
60
|
+
return startLocalSwitchboard(options);
|
|
61
|
+
};
|
|
62
|
+
function reactorCommand(program) {
|
|
63
|
+
program.command("switchboard").alias("reactor").description("Starts local switchboard").option("--port <PORT>", "port to host the api", "4001").option(
|
|
64
|
+
"--config-file <configFile>",
|
|
65
|
+
"Path to the powerhouse.config.js file"
|
|
66
|
+
).option("--generate", "generate code when document model is updated").option("--db-path <DB_PATH>", "path to the database").option("--https-key-file <HTTPS_KEY_FILE>", "path to the ssl key file").option("--https-cert-file <HTTPS_CERT_FILE>", "path to the ssl cert file").option(
|
|
67
|
+
"-w, --watch",
|
|
68
|
+
"if the reactor should watch for local changes to document models and processors"
|
|
69
|
+
).option(
|
|
70
|
+
"--packages <packages...>",
|
|
71
|
+
"list of packages to be loaded, if defined then packages on config file are ignored"
|
|
72
|
+
).action(async (...args) => {
|
|
73
|
+
await switchboard(...args);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (process.argv.at(2) === "spawn") {
|
|
77
|
+
const optionsArg = process.argv.at(3);
|
|
78
|
+
const options = optionsArg ? JSON.parse(optionsArg) : {};
|
|
79
|
+
startLocalSwitchboard(options).then((switchboard2) => {
|
|
80
|
+
process.send?.(`driveUrl:${switchboard2.driveUrl}`);
|
|
81
|
+
}).catch((e) => {
|
|
82
|
+
throw e;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
DefaultSwitchboardOptions,
|
|
88
|
+
switchboard,
|
|
89
|
+
reactorCommand
|
|
90
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DefaultSwitchboardOptions
|
|
3
|
+
} from "./chunk-6O6TUXJK.js";
|
|
4
|
+
|
|
5
|
+
// src/commands/dev.ts
|
|
6
|
+
import { blue, green, red } from "colorette";
|
|
7
|
+
import { fork } from "node:child_process";
|
|
8
|
+
import path, { dirname } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
var __dirname = import.meta.dirname || dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
function spawnLocalSwitchboard(options) {
|
|
12
|
+
const child = fork(
|
|
13
|
+
path.join(__dirname, "switchboard.js"),
|
|
14
|
+
["spawn", JSON.stringify(options)],
|
|
15
|
+
{ silent: true }
|
|
16
|
+
);
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
child.on("message", (message) => {
|
|
19
|
+
const text = message.toString();
|
|
20
|
+
if (text.startsWith("driveUrl:")) {
|
|
21
|
+
const driveUrl = text.substring("driveUrl:".length);
|
|
22
|
+
resolve({ driveUrl });
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
child.stdout.on("data", (data) => {
|
|
26
|
+
const message = data.toString();
|
|
27
|
+
const lines = message.split("\n").filter((line) => line.trim().length);
|
|
28
|
+
for (const line of lines) {
|
|
29
|
+
process.stdout.write(blue(`[Switchboard]: ${line}
|
|
30
|
+
`));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
child.stderr.on("error", (data) => {
|
|
34
|
+
process.stderr.write(red(`[Switchboard]: ${data.toString()}`));
|
|
35
|
+
});
|
|
36
|
+
child.on("error", (err) => {
|
|
37
|
+
process.stderr.write(red(`[Switchboard]: ${err}`));
|
|
38
|
+
});
|
|
39
|
+
child.on("exit", (code) => {
|
|
40
|
+
console.log(`Switchboard process exited with code ${code}`);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async function spawnConnect(options, localReactorUrl) {
|
|
45
|
+
const child = fork(
|
|
46
|
+
path.join(__dirname, "connect.js"),
|
|
47
|
+
["spawn", JSON.stringify(options ?? {})],
|
|
48
|
+
{
|
|
49
|
+
silent: true,
|
|
50
|
+
env: {
|
|
51
|
+
...process.env,
|
|
52
|
+
// TODO add studio variables?
|
|
53
|
+
LOCAL_DOCUMENT_MODELS: options?.localDocuments,
|
|
54
|
+
LOCAL_DOCUMENT_EDITORS: options?.localEditors,
|
|
55
|
+
PH_CONNECT_DEFAULT_DRIVES_URL: localReactorUrl
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
child.stdout.on("data", (data) => {
|
|
61
|
+
resolve();
|
|
62
|
+
process.stdout.write(green(`[Connect]: ${data.toString()}`));
|
|
63
|
+
});
|
|
64
|
+
child.stderr.on("data", (data) => {
|
|
65
|
+
process.stderr.write(red(`[Connect]: ${data.toString()}`));
|
|
66
|
+
});
|
|
67
|
+
child.on("close", (code) => {
|
|
68
|
+
console.log(`Connect process exited with code ${code}`);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
var dev = async ({
|
|
73
|
+
generate,
|
|
74
|
+
watch,
|
|
75
|
+
switchboardPort = DefaultSwitchboardOptions.port,
|
|
76
|
+
configFile,
|
|
77
|
+
httpsKeyFile,
|
|
78
|
+
httpsCertFile
|
|
79
|
+
}) => {
|
|
80
|
+
try {
|
|
81
|
+
const https = httpsKeyFile && httpsCertFile ? {
|
|
82
|
+
keyPath: httpsKeyFile,
|
|
83
|
+
certPath: httpsCertFile
|
|
84
|
+
} : void 0;
|
|
85
|
+
const { driveUrl } = await spawnLocalSwitchboard({
|
|
86
|
+
generate,
|
|
87
|
+
port: switchboardPort,
|
|
88
|
+
watch,
|
|
89
|
+
https
|
|
90
|
+
});
|
|
91
|
+
await spawnConnect({ configFile }, driveUrl);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error(error);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
function devCommand(program) {
|
|
97
|
+
program.command("dev").description("Starts dev environment").option("--generate", "generate code when document model is updated").option("--switchboard-port <port>", "port to use for the switchboard").option("--https-key-file <HTTPS_KEY_FILE>", "path to the ssl key file").option("--https-cert-file <HTTPS_CERT_FILE>", "path to the ssl cert file").option(
|
|
98
|
+
"--config-file <configFile>",
|
|
99
|
+
"Path to the powerhouse.config.js file"
|
|
100
|
+
).option(
|
|
101
|
+
"-w, --watch",
|
|
102
|
+
"if the switchboard should watch for local changes to document models and processors"
|
|
103
|
+
).action(dev);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export {
|
|
107
|
+
dev,
|
|
108
|
+
devCommand
|
|
109
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SUPPORTED_PACKAGE_MANAGERS,
|
|
3
|
+
getPackageManagerFromLockfile,
|
|
4
|
+
getProjectInfo,
|
|
5
|
+
packageManagers,
|
|
6
|
+
updateConfigFile
|
|
7
|
+
} from "./chunk-FDMMJENR.js";
|
|
8
|
+
|
|
9
|
+
// src/commands/install.ts
|
|
10
|
+
import { execSync } from "node:child_process";
|
|
11
|
+
import fs from "node:fs";
|
|
12
|
+
function installDependency(packageManager, dependencies, projectPath, workspace) {
|
|
13
|
+
if (!fs.existsSync(projectPath)) {
|
|
14
|
+
throw new Error(`Project path not found: ${projectPath}`);
|
|
15
|
+
}
|
|
16
|
+
const manager = packageManagers[packageManager];
|
|
17
|
+
let installCommand2 = manager.installCommand.replace(
|
|
18
|
+
"{{dependency}}",
|
|
19
|
+
dependencies.join(" ")
|
|
20
|
+
);
|
|
21
|
+
if (workspace) {
|
|
22
|
+
installCommand2 += ` ${manager.workspaceOption}`;
|
|
23
|
+
}
|
|
24
|
+
const commandOptions = { cwd: projectPath };
|
|
25
|
+
execSync(installCommand2, {
|
|
26
|
+
stdio: "inherit",
|
|
27
|
+
...commandOptions
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
var install = (dependencies, options) => {
|
|
31
|
+
if (options.debug) {
|
|
32
|
+
console.log(">>> command arguments", { dependencies, options });
|
|
33
|
+
}
|
|
34
|
+
if (!dependencies || dependencies.length === 0) {
|
|
35
|
+
throw new Error("\u274C Dependency name is required");
|
|
36
|
+
}
|
|
37
|
+
if (options.packageManager && !SUPPORTED_PACKAGE_MANAGERS.includes(options.packageManager)) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
"\u274C Unsupported package manager. Supported package managers: npm, yarn, pnpm, bun"
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
const projectInfo = getProjectInfo(options.debug);
|
|
43
|
+
if (options.debug) {
|
|
44
|
+
console.log("\n>>> projectInfo", projectInfo);
|
|
45
|
+
}
|
|
46
|
+
const isGlobal = options.global || projectInfo.isGlobal;
|
|
47
|
+
const packageManager = options.packageManager || getPackageManagerFromLockfile(projectInfo.path);
|
|
48
|
+
if (options.debug) {
|
|
49
|
+
console.log("\n>>> installDependency arguments:");
|
|
50
|
+
console.log(">>> packageManager", packageManager);
|
|
51
|
+
console.log(">>> dependencies", dependencies);
|
|
52
|
+
console.log(">>> isGlobal", isGlobal);
|
|
53
|
+
console.log(">>> projectPath", projectInfo.path);
|
|
54
|
+
console.log(">>> workspace", options.workspace);
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
console.log("installing dependencies \u{1F4E6} ...");
|
|
58
|
+
installDependency(
|
|
59
|
+
packageManager,
|
|
60
|
+
dependencies,
|
|
61
|
+
projectInfo.path,
|
|
62
|
+
options.workspace
|
|
63
|
+
);
|
|
64
|
+
console.log("Dependency installed successfully \u{1F389}");
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error("\u274C Failed to install dependencies");
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
if (options.debug) {
|
|
70
|
+
console.log("\n>>> updateConfigFile arguments:");
|
|
71
|
+
console.log(">>> dependencies", dependencies);
|
|
72
|
+
console.log(">>> projectPath", projectInfo.path);
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
console.log("\u2699\uFE0F Updating powerhouse config file...");
|
|
76
|
+
updateConfigFile(dependencies, projectInfo.path, "install");
|
|
77
|
+
console.log("Config file updated successfully \u{1F389}");
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error("\u274C Failed to update config file");
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
function installCommand(program) {
|
|
84
|
+
program.command("install").alias("add").alias("i").description("Install a powerhouse dependency").argument("[dependencies...]", "Names of the dependencies to install").option("-g, --global", "Install the dependency globally").option("--debug", "Show additional logs").option(
|
|
85
|
+
"-w, --workspace",
|
|
86
|
+
"Install the dependency in the workspace (use this option for monorepos)"
|
|
87
|
+
).option(
|
|
88
|
+
"--package-manager <packageManager>",
|
|
89
|
+
"force package manager to use"
|
|
90
|
+
).action(install);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
installDependency,
|
|
95
|
+
install,
|
|
96
|
+
installCommand
|
|
97
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
import path, { dirname } from "node:path";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { getConfig } from "@powerhousedao/config/powerhouse";
|
|
6
|
+
var POWERHOUSE_CONFIG_FILE = "powerhouse.config.json";
|
|
7
|
+
var POWERHOUSE_GLOBAL_DIR = path.join(homedir(), ".ph");
|
|
8
|
+
var SUPPORTED_PACKAGE_MANAGERS = ["npm", "yarn", "pnpm", "bun"];
|
|
9
|
+
var packageManagers = {
|
|
10
|
+
bun: {
|
|
11
|
+
globalPathRegexp: /[\\/].bun[\\/]/,
|
|
12
|
+
installCommand: "bun add {{dependency}}",
|
|
13
|
+
uninstallCommand: "bun remove {{dependency}}",
|
|
14
|
+
workspaceOption: "",
|
|
15
|
+
lockfile: "bun.lock"
|
|
16
|
+
},
|
|
17
|
+
pnpm: {
|
|
18
|
+
globalPathRegexp: /[\\/]pnpm[\\/]/,
|
|
19
|
+
installCommand: "pnpm add {{dependency}}",
|
|
20
|
+
uninstallCommand: "pnpm remove {{dependency}}",
|
|
21
|
+
workspaceOption: "--workspace-root",
|
|
22
|
+
lockfile: "pnpm-lock.yaml"
|
|
23
|
+
},
|
|
24
|
+
yarn: {
|
|
25
|
+
globalPathRegexp: /[\\/]yarn[\\/]/,
|
|
26
|
+
installCommand: "yarn add {{dependency}}",
|
|
27
|
+
uninstallCommand: "yarn remove {{dependency}}",
|
|
28
|
+
workspaceOption: "-W",
|
|
29
|
+
lockfile: "yarn.lock"
|
|
30
|
+
},
|
|
31
|
+
npm: {
|
|
32
|
+
installCommand: "npm install {{dependency}}",
|
|
33
|
+
uninstallCommand: "npm uninstall {{dependency}}",
|
|
34
|
+
workspaceOption: "",
|
|
35
|
+
lockfile: "package-lock.json"
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
function defaultPathValidation() {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
function isPowerhouseProject(dir) {
|
|
42
|
+
const powerhouseConfigPath = path.join(dir, POWERHOUSE_CONFIG_FILE);
|
|
43
|
+
return fs.existsSync(powerhouseConfigPath);
|
|
44
|
+
}
|
|
45
|
+
function findNodeProjectRoot(dir, pathValidation = defaultPathValidation) {
|
|
46
|
+
const packageJsonPath = path.join(dir, "package.json");
|
|
47
|
+
if (fs.existsSync(packageJsonPath) && pathValidation(dir)) {
|
|
48
|
+
return dir;
|
|
49
|
+
}
|
|
50
|
+
const parentDir = dirname(dir);
|
|
51
|
+
if (parentDir === dir) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return findNodeProjectRoot(parentDir, pathValidation);
|
|
55
|
+
}
|
|
56
|
+
function getProjectInfo(debug) {
|
|
57
|
+
const currentPath = process.cwd();
|
|
58
|
+
if (debug) {
|
|
59
|
+
console.log(">>> currentPath", currentPath);
|
|
60
|
+
}
|
|
61
|
+
const projectPath = findNodeProjectRoot(currentPath, isPowerhouseProject);
|
|
62
|
+
if (!projectPath) {
|
|
63
|
+
return {
|
|
64
|
+
isGlobal: true,
|
|
65
|
+
path: POWERHOUSE_GLOBAL_DIR
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
isGlobal: false,
|
|
70
|
+
path: projectPath
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function getPackageManagerFromLockfile(dir) {
|
|
74
|
+
if (fs.existsSync(path.join(dir, packageManagers.pnpm.lockfile))) {
|
|
75
|
+
return "pnpm";
|
|
76
|
+
} else if (fs.existsSync(path.join(dir, packageManagers.yarn.lockfile))) {
|
|
77
|
+
return "yarn";
|
|
78
|
+
} else if (fs.existsSync(path.join(dir, packageManagers.bun.lockfile))) {
|
|
79
|
+
return "bun";
|
|
80
|
+
}
|
|
81
|
+
return "npm";
|
|
82
|
+
}
|
|
83
|
+
function getPackageManagerFromPath(dir) {
|
|
84
|
+
const lowerCasePath = dir.toLowerCase();
|
|
85
|
+
if (packageManagers.bun.globalPathRegexp.test(lowerCasePath)) {
|
|
86
|
+
return "bun";
|
|
87
|
+
} else if (packageManagers.pnpm.globalPathRegexp.test(lowerCasePath)) {
|
|
88
|
+
return "pnpm";
|
|
89
|
+
} else if (packageManagers.yarn.globalPathRegexp.test(lowerCasePath)) {
|
|
90
|
+
return "yarn";
|
|
91
|
+
}
|
|
92
|
+
return "npm";
|
|
93
|
+
}
|
|
94
|
+
function updateConfigFile(dependencies, projectPath, task = "install") {
|
|
95
|
+
const configPath = path.join(projectPath, POWERHOUSE_CONFIG_FILE);
|
|
96
|
+
const isInstall = task === "install";
|
|
97
|
+
if (!fs.existsSync(configPath)) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`powerhouse.config.json file not found. projectPath: ${projectPath}`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
const config = JSON.parse(
|
|
103
|
+
fs.readFileSync(configPath, "utf-8")
|
|
104
|
+
);
|
|
105
|
+
const mappedPackages = dependencies.map(
|
|
106
|
+
(dep) => ({
|
|
107
|
+
packageName: dep
|
|
108
|
+
})
|
|
109
|
+
);
|
|
110
|
+
const updatedConfig = {
|
|
111
|
+
...config,
|
|
112
|
+
packages: isInstall ? [...config.packages || [], ...mappedPackages] : [...config.packages || []].filter(
|
|
113
|
+
(pkg) => !dependencies.includes(pkg.packageName)
|
|
114
|
+
)
|
|
115
|
+
};
|
|
116
|
+
fs.writeFileSync(configPath, JSON.stringify(updatedConfig, null, 2));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
POWERHOUSE_CONFIG_FILE,
|
|
121
|
+
POWERHOUSE_GLOBAL_DIR,
|
|
122
|
+
SUPPORTED_PACKAGE_MANAGERS,
|
|
123
|
+
packageManagers,
|
|
124
|
+
defaultPathValidation,
|
|
125
|
+
isPowerhouseProject,
|
|
126
|
+
findNodeProjectRoot,
|
|
127
|
+
getProjectInfo,
|
|
128
|
+
getPackageManagerFromLockfile,
|
|
129
|
+
getPackageManagerFromPath,
|
|
130
|
+
updateConfigFile,
|
|
131
|
+
getConfig
|
|
132
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// src/commands/generate.ts
|
|
2
|
+
import {
|
|
3
|
+
generate as generateCode,
|
|
4
|
+
generateEditor,
|
|
5
|
+
generateFromFile,
|
|
6
|
+
generateImportScript,
|
|
7
|
+
generateProcessor,
|
|
8
|
+
generateSubgraph,
|
|
9
|
+
promptDirectories
|
|
10
|
+
} from "@powerhousedao/codegen";
|
|
11
|
+
import { getConfig } from "@powerhousedao/config/powerhouse";
|
|
12
|
+
var generate = async (filePath, options) => {
|
|
13
|
+
const baseConfig = getConfig();
|
|
14
|
+
const config = {
|
|
15
|
+
...baseConfig,
|
|
16
|
+
...{
|
|
17
|
+
...options.editors && { editorsDir: options.editors },
|
|
18
|
+
...options.processors && { processorsDir: options.processors },
|
|
19
|
+
...options.documentModels && {
|
|
20
|
+
documentModelsDir: options.documentModels
|
|
21
|
+
},
|
|
22
|
+
...options.skipFormat && { skipFormat: options.skipFormat },
|
|
23
|
+
...options.interactive && { interactive: options.interactive },
|
|
24
|
+
...options.watch && { watch: options.watch }
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const command = {
|
|
28
|
+
editor: !!options.editor,
|
|
29
|
+
editorName: options.editor,
|
|
30
|
+
documentTypes: options.documentTypes,
|
|
31
|
+
processor: !!options.processor,
|
|
32
|
+
processorName: options.processor,
|
|
33
|
+
processorType: options.processorType,
|
|
34
|
+
subgraph: !!options.subgraph,
|
|
35
|
+
subgraphName: options.subgraph,
|
|
36
|
+
importScript: !!options.importScript,
|
|
37
|
+
importScriptName: options.importScript
|
|
38
|
+
};
|
|
39
|
+
if (config.interactive) {
|
|
40
|
+
const result = await promptDirectories(config);
|
|
41
|
+
Object.assign(config, result);
|
|
42
|
+
}
|
|
43
|
+
if (command.editor) {
|
|
44
|
+
if (!command.editorName) {
|
|
45
|
+
throw new Error("Editor name is required (--editor or -e)");
|
|
46
|
+
}
|
|
47
|
+
await generateEditor(
|
|
48
|
+
command.editorName,
|
|
49
|
+
command.documentTypes?.split(/[|,;]/g) ?? [],
|
|
50
|
+
config
|
|
51
|
+
);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (command.processor && options.processor) {
|
|
55
|
+
const processorType = options.processorType === "operational" ? "operational" : "analytics";
|
|
56
|
+
await generateProcessor(
|
|
57
|
+
options.processor,
|
|
58
|
+
processorType,
|
|
59
|
+
options.documentTypes?.split(",") ?? [],
|
|
60
|
+
config
|
|
61
|
+
);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (command.subgraph && command.subgraphName) {
|
|
65
|
+
await generateSubgraph(command.subgraphName, config);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (command.importScript && command.importScriptName) {
|
|
69
|
+
await generateImportScript(command.importScriptName, config);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (filePath) {
|
|
73
|
+
await generateFromFile(filePath, config);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
await generateCode(config);
|
|
77
|
+
};
|
|
78
|
+
function generateCommand(program) {
|
|
79
|
+
program.command("generate").description("Generate code from the document models").argument("[document-model-file]", "Path to the document model file").option("-i, --interactive", "Run the command in interactive mode").option("--editors <type>", "Path to the editors directory").option("-e, --editor <type>", "Editor Name").option("--processors <type>", "Path to the processors directory").option("-p, --processor <type>", "Processor Name").option("--processor-type <type>", "Processor Type").option("-s, --subgraph <type>", "Subgraph Name").option("--document-models <type>", "Path to the document models directory").option("--document-types <type>", "Supported document types by the editor").option("-is, --import-script <type>", "Import Script Name").option("-sf, --skip-format", "Skip formatting the generated code").option("-w, --watch", "Watch the generated code").action(generate);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
generate,
|
|
84
|
+
generateCommand
|
|
85
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
installCommand
|
|
3
|
+
} from "./chunk-E3EWRF5U.js";
|
|
4
|
+
import {
|
|
5
|
+
serviceCommand
|
|
6
|
+
} from "./chunk-ZN4M6TJ2.js";
|
|
7
|
+
import {
|
|
8
|
+
uninstallCommand
|
|
9
|
+
} from "./chunk-X2RNXISI.js";
|
|
10
|
+
import {
|
|
11
|
+
connectCommand
|
|
12
|
+
} from "./chunk-27FF7J6K.js";
|
|
13
|
+
import {
|
|
14
|
+
devCommand
|
|
15
|
+
} from "./chunk-CWUXPR5K.js";
|
|
16
|
+
import {
|
|
17
|
+
reactorCommand
|
|
18
|
+
} from "./chunk-6O6TUXJK.js";
|
|
19
|
+
import {
|
|
20
|
+
generateCommand
|
|
21
|
+
} from "./chunk-OH5NZOCQ.js";
|
|
22
|
+
import {
|
|
23
|
+
helpCommand
|
|
24
|
+
} from "./chunk-KPMNRIJU.js";
|
|
25
|
+
|
|
26
|
+
// src/commands/index.ts
|
|
27
|
+
var commands = [
|
|
28
|
+
devCommand,
|
|
29
|
+
connectCommand,
|
|
30
|
+
generateCommand,
|
|
31
|
+
reactorCommand,
|
|
32
|
+
helpCommand,
|
|
33
|
+
installCommand,
|
|
34
|
+
uninstallCommand,
|
|
35
|
+
serviceCommand
|
|
36
|
+
];
|
|
37
|
+
function registerCommands(program) {
|
|
38
|
+
commands.forEach((command) => command(program));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
commands,
|
|
43
|
+
registerCommands
|
|
44
|
+
};
|