ph-cmd 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/LICENSE +662 -0
- package/README.md +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +10 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/connect.d.ts +8 -0
- package/dist/commands/connect.js +33 -0
- package/dist/commands/connect.js.map +1 -0
- package/dist/commands/dev.d.ts +13 -0
- package/dist/commands/dev.js +90 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/generate.d.ts +22 -0
- package/dist/commands/generate.js +70 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/help.d.ts +5 -0
- package/dist/commands/help.js +9 -0
- package/dist/commands/help.js.map +1 -0
- package/dist/commands/index.d.ts +15 -0
- package/dist/commands/index.js +27 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/init.d.ts +12 -0
- package/dist/commands/init.js +25 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/reactor.d.ts +35 -0
- package/dist/commands/reactor.js +69 -0
- package/dist/commands/reactor.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +3 -0
- package/dist/utils.js.map +1 -0
- package/package.json +56 -0
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts"],"names":[],"mappings":";;;;AAIA,MAAM,OAAA,GAAU,IAAI,OAAQ,EAAA;AAE5B,OAAA,CACG,KAAK,QAAQ,CAAA,CACb,YAAY,6BAA6B,CAAA,CACzC,QAAQ,OAAO,CAAA;AAElB,gBAAA,CAAiB,OAAO,CAAA;AAExB,OAAQ,CAAA,KAAA,CAAM,QAAQ,IAAI,CAAA","file":"cli.js","sourcesContent":["#!/usr/bin/env node\nimport { Command } from \"commander\";\nimport registerCommands from \"./commands/index.js\";\n\nconst program = new Command();\n\nprogram\n .name(\"ph-cli\")\n .description(\"CLI tool for Powerhouse DAO\")\n .version(\"1.0.0\");\n\nregisterCommands(program);\n\nprogram.parse(process.argv);\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ConnectStudioOptions } from '@powerhousedao/connect';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
|
|
4
|
+
type ConnectOptions = ConnectStudioOptions;
|
|
5
|
+
declare function startConnect(connectOptions: ConnectOptions): Promise<void | undefined>;
|
|
6
|
+
declare function connectCommand(program: Command): void;
|
|
7
|
+
|
|
8
|
+
export { type ConnectOptions, connectCommand, startConnect };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { startConnectStudio } from '@powerhousedao/connect';
|
|
2
|
+
import { getConfig } from '@powerhousedao/config/powerhouse';
|
|
3
|
+
|
|
4
|
+
async function startConnect(connectOptions) {
|
|
5
|
+
const { documentModelsDir, editorsDir } = getConfig();
|
|
6
|
+
const options = { documentModelsDir, editorsDir, ...connectOptions };
|
|
7
|
+
return await startConnectStudio(options);
|
|
8
|
+
}
|
|
9
|
+
function connectCommand(program) {
|
|
10
|
+
program.name("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(
|
|
11
|
+
"--config-file <configFile>",
|
|
12
|
+
"Path to the powerhouse.config.js file"
|
|
13
|
+
).option(
|
|
14
|
+
"-le, --local-editors <localEditors>",
|
|
15
|
+
"Link local document editors path"
|
|
16
|
+
).option(
|
|
17
|
+
"-ld, --local-documents <localDocuments>",
|
|
18
|
+
"Link local documents path"
|
|
19
|
+
).action(async (...args) => {
|
|
20
|
+
await startConnectStudio(...args);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (process.argv.at(2) === "spawn") {
|
|
24
|
+
const optionsArg = process.argv.at(3);
|
|
25
|
+
const options = optionsArg ? JSON.parse(optionsArg) : {};
|
|
26
|
+
startConnect(options).catch((e) => {
|
|
27
|
+
throw e;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { connectCommand, startConnect };
|
|
32
|
+
//# sourceMappingURL=connect.js.map
|
|
33
|
+
//# sourceMappingURL=connect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/commands/connect.ts"],"names":[],"mappings":";;;AASA,eAAsB,aAAa,cAAgC,EAAA;AACjE,EAAA,MAAM,EAAE,iBAAA,EAAmB,UAAW,EAAA,GAAI,SAAU,EAAA;AACpD,EAAA,MAAM,OAAU,GAAA,EAAE,iBAAmB,EAAA,UAAA,EAAY,GAAG,cAAe,EAAA;AACnE,EAAO,OAAA,MAAM,mBAAmB,OAAO,CAAA;AACzC;AAEO,SAAS,eAAe,OAAkB,EAAA;AAC/C,EAAA,OAAA,CACG,IAAK,CAAA,SAAS,CACd,CAAA,WAAA,CAAY,uBAAuB,CACnC,CAAA,MAAA,CAAO,mBAAqB,EAAA,2BAAA,EAA6B,MAAM,CAAA,CAC/D,MAAO,CAAA,YAAA,EAAc,kCAAkC,CACvD,CAAA,MAAA;AAAA,IACC,4BAAA;AAAA,IACA;AAAA,GAED,CAAA,MAAA;AAAA,IACC,qCAAA;AAAA,IACA;AAAA,GAED,CAAA,MAAA;AAAA,IACC,yCAAA;AAAA,IACA;AAAA,GACF,CACC,MAAO,CAAA,OAAA,GAAU,IAA2B,KAAA;AAC3C,IAAM,MAAA,kBAAA,CAAmB,GAAG,IAAI,CAAA;AAAA,GACjC,CAAA;AACL;AAEA,IAAI,OAAQ,CAAA,IAAA,CAAK,EAAG,CAAA,CAAC,MAAM,OAAS,EAAA;AAClC,EAAA,MAAM,UAAa,GAAA,OAAA,CAAQ,IAAK,CAAA,EAAA,CAAG,CAAC,CAAA;AACpC,EAAA,MAAM,UAAU,UAAc,GAAA,IAAA,CAAK,KAAM,CAAA,UAAU,IAAuB,EAAC;AAC3E,EAAA,YAAA,CAAa,OAAO,CAAA,CAAE,KAAM,CAAA,CAAC,CAAe,KAAA;AAC1C,IAAM,MAAA,CAAA;AAAA,GACP,CAAA;AACH","file":"connect.js","sourcesContent":["import {\n startConnectStudio,\n ConnectStudioOptions,\n} from \"@powerhousedao/connect\";\nimport { getConfig } from \"@powerhousedao/config/powerhouse\";\nimport { Command } from \"commander\";\n\nexport type ConnectOptions = ConnectStudioOptions;\n\nexport async function startConnect(connectOptions: ConnectOptions) {\n const { documentModelsDir, editorsDir } = getConfig();\n const options = { documentModelsDir, editorsDir, ...connectOptions };\n return await startConnectStudio(options);\n}\n\nexport function connectCommand(program: Command) {\n program\n .name(\"connect\")\n .description(\"Starts Connect Studio\")\n .option(\"-p, --port <port>\", \"Port to run the server on\", \"3000\")\n .option(\"-h, --host\", \"Expose the server to the network\")\n .option(\n \"--config-file <configFile>\",\n \"Path to the powerhouse.config.js file\",\n )\n .option(\n \"-le, --local-editors <localEditors>\",\n \"Link local document editors path\",\n )\n .option(\n \"-ld, --local-documents <localDocuments>\",\n \"Link local documents path\",\n )\n .action(async (...args: [ConnectOptions]) => {\n await startConnectStudio(...args);\n });\n}\n\nif (process.argv.at(2) === \"spawn\") {\n const optionsArg = process.argv.at(3);\n const options = optionsArg ? (JSON.parse(optionsArg) as ConnectOptions) : {};\n startConnect(options).catch((e: unknown) => {\n throw e;\n });\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { CommandActionType } from '../types.js';
|
|
3
|
+
|
|
4
|
+
declare const dev: CommandActionType<[
|
|
5
|
+
{
|
|
6
|
+
generate?: boolean;
|
|
7
|
+
watch?: boolean;
|
|
8
|
+
reactorPort?: number;
|
|
9
|
+
}
|
|
10
|
+
]>;
|
|
11
|
+
declare function devCommand(program: Command): void;
|
|
12
|
+
|
|
13
|
+
export { dev, devCommand };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import path, { dirname } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { fork } from 'node:child_process';
|
|
4
|
+
import { blue, red, green } from 'colorette';
|
|
5
|
+
import { DefaultReactorOptions } from './reactor.js';
|
|
6
|
+
|
|
7
|
+
const __dirname = import.meta.dirname || dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
function spawnLocalReactor(options) {
|
|
9
|
+
const child = fork(
|
|
10
|
+
path.join(__dirname, "reactor.js"),
|
|
11
|
+
["spawn", JSON.stringify(options)],
|
|
12
|
+
{ silent: true }
|
|
13
|
+
);
|
|
14
|
+
return new Promise((resolve) => {
|
|
15
|
+
child.on("message", (message) => {
|
|
16
|
+
const text = message.toString();
|
|
17
|
+
if (text.startsWith("driveUrl:")) {
|
|
18
|
+
const driveUrl = text.substring("driveUrl:".length);
|
|
19
|
+
resolve({ driveUrl });
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
child.stdout.on("data", (data) => {
|
|
23
|
+
const message = data.toString();
|
|
24
|
+
const lines = message.split("\n").filter((line) => line.trim().length);
|
|
25
|
+
for (const line of lines) {
|
|
26
|
+
process.stdout.write(blue(`[Reactor]: ${line}
|
|
27
|
+
`));
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
child.stderr.on("error", (data) => {
|
|
31
|
+
process.stderr.write(red(`[Reactor]: ${data.toString()}`));
|
|
32
|
+
});
|
|
33
|
+
child.on("error", (err) => {
|
|
34
|
+
process.stderr.write(red(`[Reactor]: ${err}`));
|
|
35
|
+
});
|
|
36
|
+
child.on("exit", (code) => {
|
|
37
|
+
console.log(`Reactor process exited with code ${code}`);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async function spawnConnect(options, localReactorUrl) {
|
|
42
|
+
const child = fork(
|
|
43
|
+
path.join(__dirname, "connect.js"),
|
|
44
|
+
["spawn", JSON.stringify({})],
|
|
45
|
+
{
|
|
46
|
+
silent: true,
|
|
47
|
+
env: {
|
|
48
|
+
...process.env,
|
|
49
|
+
// TODO add studio variables?
|
|
50
|
+
LOCAL_DOCUMENT_MODELS: options?.localDocuments,
|
|
51
|
+
LOCAL_DOCUMENT_EDITORS: options?.localEditors,
|
|
52
|
+
PH_CONNECT_DEFAULT_DRIVES_URL: localReactorUrl
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
return new Promise((resolve) => {
|
|
57
|
+
child.stdout.on("data", (data) => {
|
|
58
|
+
resolve();
|
|
59
|
+
process.stdout.write(green(`[Connect]: ${data.toString()}`));
|
|
60
|
+
});
|
|
61
|
+
child.stderr.on("data", (data) => {
|
|
62
|
+
process.stderr.write(red(`[Connect]: ${data.toString()}`));
|
|
63
|
+
});
|
|
64
|
+
child.on("close", (code) => {
|
|
65
|
+
console.log(`Connect process exited with code ${code}`);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const dev = async ({ generate, watch, reactorPort = DefaultReactorOptions.port }) => {
|
|
70
|
+
try {
|
|
71
|
+
const { driveUrl } = await spawnLocalReactor({
|
|
72
|
+
generate,
|
|
73
|
+
port: reactorPort,
|
|
74
|
+
watch
|
|
75
|
+
});
|
|
76
|
+
await spawnConnect(void 0, driveUrl);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error(error);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
function devCommand(program) {
|
|
82
|
+
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(
|
|
83
|
+
"-w, --watch",
|
|
84
|
+
"if the reactor should watch for local changes to document models and processors"
|
|
85
|
+
).action(dev);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { dev, devCommand };
|
|
89
|
+
//# sourceMappingURL=dev.js.map
|
|
90
|
+
//# sourceMappingURL=dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/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c,KAAK,QAAS,EAAC,EAAE,CAAC,CAAA;AAAA,KAC5D,CAAA;AAED,IAAA,KAAA,CAAM,MAAO,CAAA,EAAA,CAAG,MAAQ,EAAA,CAAC,IAAiB,KAAA;AACxC,MAAQ,OAAA,CAAA,MAAA,CAAO,MAAM,GAAI,CAAA,CAAA,WAAA,EAAc,KAAK,QAAS,EAAC,EAAE,CAAC,CAAA;AAAA,KAC1D,CAAA;AAED,IAAM,KAAA,CAAA,EAAA,CAAG,OAAS,EAAA,CAAC,IAAS,KAAA;AAC1B,MAAQ,OAAA,CAAA,GAAA,CAAI,CAAoC,iCAAA,EAAA,IAAI,CAAE,CAAA,CAAA;AAAA,KACvD,CAAA;AAAA,GACF,CAAA;AACH;AAEa,MAAA,GAAA,GAQT,OAAO,EAAE,QAAA,EAAU,OAAO,WAAc,GAAA,qBAAA,CAAsB,MAAW,KAAA;AAC3E,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,IAAM,MAAA,YAAA,CAAa,QAAW,QAAQ,CAAA;AAAA,WAC/B,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,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 },\n ]\n> = async ({ generate, watch, reactorPort = DefaultReactorOptions.port }) => {\n try {\n const { driveUrl } = await spawnLocalReactor({\n generate,\n port: reactorPort,\n watch,\n });\n await spawnConnect(undefined, 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 \"-w, --watch\",\n \"if the reactor should watch for local changes to document models and processors\",\n )\n .action(dev);\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { CommandActionType } from '../types.js';
|
|
3
|
+
|
|
4
|
+
declare const generate: CommandActionType<[
|
|
5
|
+
string | undefined,
|
|
6
|
+
{
|
|
7
|
+
interactive?: boolean;
|
|
8
|
+
editors?: string;
|
|
9
|
+
processors?: string;
|
|
10
|
+
documentModels?: string;
|
|
11
|
+
skipFormat?: boolean;
|
|
12
|
+
watch?: boolean;
|
|
13
|
+
editor?: string;
|
|
14
|
+
processor?: string;
|
|
15
|
+
documentTypes?: string;
|
|
16
|
+
processorType?: "analytics" | "operational";
|
|
17
|
+
subgraph?: string;
|
|
18
|
+
}
|
|
19
|
+
]>;
|
|
20
|
+
declare function generateCommand(program: Command): void;
|
|
21
|
+
|
|
22
|
+
export { generate, generateCommand };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { promptDirectories, generateEditor, generateProcessor, generateSubgraph, generateFromFile, generate as generate$1 } from '@powerhousedao/codegen';
|
|
2
|
+
import { getConfig } from '@powerhousedao/config/powerhouse';
|
|
3
|
+
|
|
4
|
+
const generate = async (filePath, options) => {
|
|
5
|
+
const baseConfig = getConfig();
|
|
6
|
+
const config = {
|
|
7
|
+
...baseConfig,
|
|
8
|
+
...{
|
|
9
|
+
...options.editors && { editorsDir: options.editors },
|
|
10
|
+
...options.processors && { processorsDir: options.processors },
|
|
11
|
+
...options.documentModels && {
|
|
12
|
+
documentModelsDir: options.documentModels
|
|
13
|
+
},
|
|
14
|
+
...options.skipFormat && { skipFormat: options.skipFormat },
|
|
15
|
+
...options.interactive && { interactive: options.interactive },
|
|
16
|
+
...options.watch && { watch: options.watch }
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const command = {
|
|
20
|
+
editor: !!options.editor,
|
|
21
|
+
editorName: options.editor,
|
|
22
|
+
documentTypes: options.documentTypes,
|
|
23
|
+
processor: !!options.processor,
|
|
24
|
+
processorName: options.processor,
|
|
25
|
+
processorType: options.processorType,
|
|
26
|
+
subgraph: !!options.subgraph,
|
|
27
|
+
subgraphName: options.subgraph
|
|
28
|
+
};
|
|
29
|
+
if (config.interactive) {
|
|
30
|
+
const result = await promptDirectories(config);
|
|
31
|
+
Object.assign(config, result);
|
|
32
|
+
}
|
|
33
|
+
if (command.editor) {
|
|
34
|
+
if (!command.editorName) {
|
|
35
|
+
throw new Error("Editor name is required (--editor or -e)");
|
|
36
|
+
}
|
|
37
|
+
await generateEditor(
|
|
38
|
+
command.editorName,
|
|
39
|
+
command.documentTypes?.split(/[|,;]/g) ?? [],
|
|
40
|
+
config
|
|
41
|
+
);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (command.processor && options.processor) {
|
|
45
|
+
const processorType = options.processorType === "operational" ? "operational" : "analytics";
|
|
46
|
+
await generateProcessor(
|
|
47
|
+
options.processor,
|
|
48
|
+
processorType,
|
|
49
|
+
options.documentTypes?.split(",") ?? [],
|
|
50
|
+
config
|
|
51
|
+
);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (command.subgraph && command.subgraphName) {
|
|
55
|
+
await generateSubgraph(command.subgraphName, config);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (filePath) {
|
|
59
|
+
await generateFromFile(filePath, config);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
await generate$1(config);
|
|
63
|
+
};
|
|
64
|
+
function generateCommand(program) {
|
|
65
|
+
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("-sf, --skip-format", "Skip formatting the generated code").option("-w, --watch", "Watch the generated code").action(generate);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { generate, generateCommand };
|
|
69
|
+
//# sourceMappingURL=generate.js.map
|
|
70
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/commands/generate.ts"],"names":["generateCode"],"mappings":";;;AAYa,MAAA,QAAA,GAiBT,OAAO,QAAA,EAAU,OAAY,KAAA;AAC/B,EAAA,MAAM,aAAa,SAAU,EAAA;AAE7B,EAAA,MAAM,MAAS,GAAA;AAAA,IACb,GAAG,UAAA;AAAA,IACH,GAAG;AAAA,MACD,GAAI,OAAQ,CAAA,OAAA,IAAW,EAAE,UAAA,EAAY,QAAQ,OAAQ,EAAA;AAAA,MACrD,GAAI,OAAQ,CAAA,UAAA,IAAc,EAAE,aAAA,EAAe,QAAQ,UAAW,EAAA;AAAA,MAC9D,GAAI,QAAQ,cAAkB,IAAA;AAAA,QAC5B,mBAAmB,OAAQ,CAAA;AAAA,OAC7B;AAAA,MACA,GAAI,OAAQ,CAAA,UAAA,IAAc,EAAE,UAAA,EAAY,QAAQ,UAA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AAQ,CAAA,SAAA;AAAA,MACR,aAAA;AAAA,MACA,OAAQ,CAAA,aAAA,EAAe,KAAM,CAAA,GAAG,KAAK,EAAC;AAAA,MACtC;AAAA,KACF;AACA,IAAA;AAAA;AAGF,EAAI,IAAA,OAAA,CAAQ,QAAY,IAAA,OAAA,CAAQ,YAAc,EAAA;AAC5C,IAAM,MAAA,gBAAA,CAAiB,OAAQ,CAAA,YAAA,EAAc,MAAM,CAAA;AACnD,IAAA;AAAA;AAGF,EAAA,IAAI,QAAU,EAAA;AACZ,IAAM,MAAA,gBAAA,CAAiB,UAAU,MAAM,CAAA;AACvC,IAAA;AAAA;AAGF,EAAA,MAAMA,WAAa,MAAM,CAAA;AAC3B;AAEO,SAAS,gBAAgB,OAAkB,EAAA;AAChD,EACG,OAAA,CAAA,OAAA,CAAQ,UAAU,CAAA,CAClB,WAAY,CAAA,wCAAwC,EACpD,QAAS,CAAA,uBAAA,EAAyB,iCAAiC,CAAA,CACnE,MAAO,CAAA,mBAAA,EAAqB,qCAAqC,CACjE,CAAA,MAAA,CAAO,kBAAoB,EAAA,+BAA+B,CAC1D,CAAA,MAAA,CAAO,qBAAuB,EAAA,aAAa,CAC3C,CAAA,MAAA,CAAO,qBAAuB,EAAA,kCAAkC,CAChE,CAAA,MAAA,CAAO,0BAA0B,gBAAgB,CAAA,CACjD,MAAO,CAAA,yBAAA,EAA2B,gBAAgB,CAAA,CAClD,MAAO,CAAA,uBAAA,EAAyB,eAAe,CAAA,CAC/C,MAAO,CAAA,0BAAA,EAA4B,uCAAuC,CAAA,CAC1E,OAAO,yBAA2B,EAAA,wCAAwC,CAC1E,CAAA,MAAA,CAAO,oBAAsB,EAAA,oCAAoC,CACjE,CAAA,MAAA,CAAO,aAAe,EAAA,0BAA0B,CAChD,CAAA,MAAA,CAAO,QAAQ,CAAA;AACpB","file":"generate.js","sourcesContent":["import {\n generate as generateCode,\n generateEditor,\n generateFromFile,\n generateProcessor,\n generateSubgraph,\n promptDirectories,\n} from \"@powerhousedao/codegen\";\nimport { Command } from \"commander\";\nimport { CommandActionType } from \"../types.js\";\nimport { getConfig } from \"@powerhousedao/config/powerhouse\";\n\nexport const generate: CommandActionType<\n [\n string | undefined,\n {\n interactive?: boolean;\n editors?: string;\n processors?: string;\n documentModels?: string;\n skipFormat?: boolean;\n watch?: boolean;\n editor?: string;\n processor?: string;\n documentTypes?: string;\n processorType?: \"analytics\" | \"operational\";\n subgraph?: string;\n },\n ]\n> = async (filePath, options) => {\n const baseConfig = getConfig();\n\n const config = {\n ...baseConfig,\n ...{\n ...(options.editors && { editorsDir: options.editors }),\n ...(options.processors && { processorsDir: options.processors }),\n ...(options.documentModels && {\n documentModelsDir: options.documentModels,\n }),\n ...(options.skipFormat && { skipFormat: options.skipFormat }),\n ...(options.interactive && { interactive: options.interactive }),\n ...(options.watch && { watch: options.watch }),\n },\n };\n\n const command = {\n editor: !!options.editor,\n editorName: options.editor,\n documentTypes: options.documentTypes,\n processor: !!options.processor,\n processorName: options.processor,\n processorType: options.processorType,\n subgraph: !!options.subgraph,\n subgraphName: options.subgraph,\n };\n\n if (config.interactive) {\n const result = await promptDirectories(config);\n Object.assign(config, result);\n }\n\n if (command.editor) {\n if (!command.editorName) {\n throw new Error(\"Editor name is required (--editor or -e)\");\n }\n await generateEditor(\n command.editorName,\n command.documentTypes?.split(/[|,;]/g) ?? [],\n config,\n );\n\n return;\n }\n\n if (command.processor && options.processor) {\n const processorType =\n options.processorType === \"operational\" ? \"operational\" : \"analytics\";\n await generateProcessor(\n options.processor,\n processorType,\n options.documentTypes?.split(\",\") ?? [],\n config,\n );\n return;\n }\n\n if (command.subgraph && command.subgraphName) {\n await generateSubgraph(command.subgraphName, config);\n return;\n }\n\n if (filePath) {\n await generateFromFile(filePath, config);\n return;\n }\n\n await generateCode(config);\n};\n\nexport function generateCommand(program: Command) {\n program\n .command(\"generate\")\n .description(\"Generate code from the document models\")\n .argument(\"[document-model-file]\", \"Path to the document model file\")\n .option(\"-i, --interactive\", \"Run the command in interactive mode\")\n .option(\"--editors <type>\", \"Path to the editors directory\")\n .option(\"-e, --editor <type>\", \"Editor Name\")\n .option(\"--processors <type>\", \"Path to the processors directory\")\n .option(\"-p, --processor <type>\", \"Processor Name\")\n .option(\"--processor-type <type>\", \"Processor Type\")\n .option(\"-s, --subgraph <type>\", \"Subgraph Name\")\n .option(\"--document-models <type>\", \"Path to the document models directory\")\n .option(\"--document-types <type>\", \"Supported document types by the editor\")\n .option(\"-sf, --skip-format\", \"Skip formatting the generated code\")\n .option(\"-w, --watch\", \"Watch the generated code\")\n .action(generate);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/commands/help.ts"],"names":[],"mappings":"AAEO,SAAS,YAAY,OAAkB,EAAA;AAC5C,EAAA,OAAA,CACG,QAAQ,MAAM,CAAA,CACd,YAAY,0BAA0B,CAAA,CACtC,OAAO,MAAM;AACZ,IAAA,OAAA,CAAQ,IAAK,EAAA;AAAA,GACd,CAAA;AACL","file":"help.js","sourcesContent":["import { Command } from \"commander\";\n\nexport function helpCommand(program: Command) {\n program\n .command(\"help\")\n .description(\"Display help information\")\n .action(() => {\n program.help();\n });\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { initCommand } from './init.js';
|
|
3
|
+
export { init } from './init.js';
|
|
4
|
+
export { dev, devCommand } from './dev.js';
|
|
5
|
+
export { helpCommand } from './help.js';
|
|
6
|
+
export { generate, generateCommand } from './generate.js';
|
|
7
|
+
export { DefaultReactorOptions, ReactorOptions, reactor, reactorCommand } from './reactor.js';
|
|
8
|
+
import '@powerhousedao/config/powerhouse';
|
|
9
|
+
import '../types.js';
|
|
10
|
+
import '@powerhousedao/reactor-local';
|
|
11
|
+
|
|
12
|
+
declare const commands: (typeof initCommand)[];
|
|
13
|
+
declare function registerCommands(program: Command): void;
|
|
14
|
+
|
|
15
|
+
export { commands, registerCommands as default, initCommand };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { devCommand } from './dev.js';
|
|
2
|
+
export * from './dev.js';
|
|
3
|
+
import { helpCommand } from './help.js';
|
|
4
|
+
export * from './help.js';
|
|
5
|
+
import { initCommand } from './init.js';
|
|
6
|
+
export * from './init.js';
|
|
7
|
+
import { connectCommand } from './connect.js';
|
|
8
|
+
import { reactorCommand } from './reactor.js';
|
|
9
|
+
export * from './reactor.js';
|
|
10
|
+
import { generateCommand } from './generate.js';
|
|
11
|
+
export * from './generate.js';
|
|
12
|
+
|
|
13
|
+
const commands = [
|
|
14
|
+
initCommand,
|
|
15
|
+
devCommand,
|
|
16
|
+
connectCommand,
|
|
17
|
+
generateCommand,
|
|
18
|
+
reactorCommand,
|
|
19
|
+
helpCommand
|
|
20
|
+
];
|
|
21
|
+
function registerCommands(program) {
|
|
22
|
+
commands.forEach((command) => command(program));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { commands, registerCommands as default };
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/commands/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAQO,MAAM,QAAW,GAAA;AAAA,EACtB,WAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,cAAA;AAAA,EACA;AACF;AAEe,SAAR,iBAAkC,OAAkB,EAAA;AACzD,EAAA,QAAA,CAAS,OAAQ,CAAA,CAAC,OAAY,KAAA,OAAA,CAAQ,OAAO,CAAC,CAAA;AAChD","file":"index.js","sourcesContent":["import { Command } from \"commander\";\nimport { devCommand } from \"./dev.js\";\nimport { helpCommand } from \"./help.js\";\nimport { initCommand } from \"./init.js\";\nimport { connectCommand } from \"./connect.js\";\nimport { reactorCommand } from \"./reactor.js\";\nimport { generateCommand } from \"./generate.js\";\n\nexport const commands = [\n initCommand,\n devCommand,\n connectCommand,\n generateCommand,\n reactorCommand,\n helpCommand,\n];\n\nexport default function registerCommands(program: Command) {\n commands.forEach((command) => command(program));\n}\n\nexport * from \"./dev.js\";\nexport * from \"./help.js\";\nexport * from \"./init.js\";\nexport * from \"./generate.js\";\nexport * from \"./reactor.js\";\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { CommandActionType } from '../types.js';
|
|
3
|
+
|
|
4
|
+
declare const init: CommandActionType<[
|
|
5
|
+
string | undefined,
|
|
6
|
+
{
|
|
7
|
+
interactive?: boolean;
|
|
8
|
+
}
|
|
9
|
+
]>;
|
|
10
|
+
declare function initCommand(program: Command): void;
|
|
11
|
+
|
|
12
|
+
export { init, initCommand };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createProject } from '@powerhousedao/codegen';
|
|
2
|
+
|
|
3
|
+
const init = async (projectName, options) => {
|
|
4
|
+
console.log("Initializing a new project...", projectName);
|
|
5
|
+
console.log("Options", options);
|
|
6
|
+
const positionalArgs = [];
|
|
7
|
+
if (projectName) {
|
|
8
|
+
positionalArgs.push(projectName);
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
await createProject({
|
|
12
|
+
_: positionalArgs,
|
|
13
|
+
"--interactive": !!options.interactive
|
|
14
|
+
});
|
|
15
|
+
} catch {
|
|
16
|
+
console.log("Failed to initialize the project");
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
function initCommand(program) {
|
|
20
|
+
program.command("init").description("Initialize a new project").argument("[project-name]", "Name of the project").option("--interactive", "Run the command in interactive mode").action(init);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { init, initCommand };
|
|
24
|
+
//# sourceMappingURL=init.js.map
|
|
25
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/commands/init.ts"],"names":[],"mappings":";;AAIa,MAAA,IAAA,GAET,OAAO,WAAA,EAAa,OAAY,KAAA;AAClC,EAAQ,OAAA,CAAA,GAAA,CAAI,iCAAiC,WAAW,CAAA;AACxD,EAAQ,OAAA,CAAA,GAAA,CAAI,WAAW,OAAO,CAAA;AAC9B,EAAA,MAAM,iBAA2B,EAAC;AAElC,EAAA,IAAI,WAAa,EAAA;AACf,IAAA,cAAA,CAAe,KAAK,WAAW,CAAA;AAAA;AAGjC,EAAI,IAAA;AACF,IAAA,MAAM,aAAc,CAAA;AAAA,MAClB,CAAG,EAAA,cAAA;AAAA,MACH,eAAA,EAAiB,CAAC,CAAC,OAAQ,CAAA;AAAA,KAC5B,CAAA;AAAA,GACK,CAAA,MAAA;AACN,IAAA,OAAA,CAAQ,IAAI,kCAAkC,CAAA;AAAA;AAElD;AAEO,SAAS,YAAY,OAAkB,EAAA;AAC5C,EAAA,OAAA,CACG,OAAQ,CAAA,MAAM,CACd,CAAA,WAAA,CAAY,0BAA0B,CACtC,CAAA,QAAA,CAAS,gBAAkB,EAAA,qBAAqB,EAChD,MAAO,CAAA,eAAA,EAAiB,qCAAqC,CAAA,CAC7D,OAAO,IAAI,CAAA;AAChB","file":"init.js","sourcesContent":["import { Command } from \"commander\";\nimport { createProject } from \"@powerhousedao/codegen\";\nimport { CommandActionType } from \"../types.js\";\n\nexport const init: CommandActionType<\n [string | undefined, { interactive?: boolean }]\n> = async (projectName, options) => {\n console.log(\"Initializing a new project...\", projectName);\n console.log(\"Options\", options);\n const positionalArgs: string[] = [];\n\n if (projectName) {\n positionalArgs.push(projectName);\n }\n\n try {\n await createProject({\n _: positionalArgs,\n \"--interactive\": !!options.interactive,\n });\n } catch {\n console.log(\"Failed to initialize the project\");\n }\n};\n\nexport function initCommand(program: Command) {\n program\n .command(\"init\")\n .description(\"Initialize a new project\")\n .argument(\"[project-name]\", \"Name of the project\")\n .option(\"--interactive\", \"Run the command in interactive mode\")\n .action(init);\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { StartServerOptions, LocalReactor } from '@powerhousedao/reactor-local';
|
|
3
|
+
import { CommandActionType } from '../types.js';
|
|
4
|
+
|
|
5
|
+
type ReactorOptions = StartServerOptions & {
|
|
6
|
+
generate?: boolean;
|
|
7
|
+
watch?: boolean;
|
|
8
|
+
dbPath?: string;
|
|
9
|
+
};
|
|
10
|
+
declare const DefaultReactorOptions: {
|
|
11
|
+
dev: boolean;
|
|
12
|
+
port: number;
|
|
13
|
+
storagePath: string;
|
|
14
|
+
dbPath: string;
|
|
15
|
+
drive: {
|
|
16
|
+
global: {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
icon: string;
|
|
20
|
+
slug: string;
|
|
21
|
+
};
|
|
22
|
+
local: {
|
|
23
|
+
availableOffline: true;
|
|
24
|
+
listeners: never[];
|
|
25
|
+
sharingType: string;
|
|
26
|
+
triggers: never[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
declare const reactor: CommandActionType<[
|
|
31
|
+
ReactorOptions
|
|
32
|
+
], Promise<LocalReactor>>;
|
|
33
|
+
declare function reactorCommand(program: Command): void;
|
|
34
|
+
|
|
35
|
+
export { DefaultReactorOptions, type ReactorOptions, reactor, reactorCommand };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { DefaultStartServerOptions, startServer } from '@powerhousedao/reactor-local';
|
|
2
|
+
import { generateFromFile } from '@powerhousedao/codegen';
|
|
3
|
+
import { getConfig } from '@powerhousedao/config/powerhouse';
|
|
4
|
+
|
|
5
|
+
const DefaultReactorOptions = {
|
|
6
|
+
...DefaultStartServerOptions,
|
|
7
|
+
dev: true
|
|
8
|
+
};
|
|
9
|
+
async function startLocalReactor(reactorOptions) {
|
|
10
|
+
const baseConfig = getConfig();
|
|
11
|
+
const options = { ...DefaultReactorOptions, ...reactorOptions };
|
|
12
|
+
const reactor2 = await startServer(options);
|
|
13
|
+
if (options.generate) {
|
|
14
|
+
await reactor2.addListener(
|
|
15
|
+
"powerhouse",
|
|
16
|
+
{
|
|
17
|
+
onStrands: async function(strands) {
|
|
18
|
+
const documentPaths = /* @__PURE__ */ new Set();
|
|
19
|
+
for (const strand of strands) {
|
|
20
|
+
documentPaths.add(
|
|
21
|
+
reactor2.getDocumentPath(strand.driveId, strand.documentId)
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
for (const path of documentPaths) {
|
|
25
|
+
await generateFromFile(path, baseConfig);
|
|
26
|
+
}
|
|
27
|
+
return Promise.resolve();
|
|
28
|
+
},
|
|
29
|
+
onDisconnect: () => Promise.resolve()
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
filter: {
|
|
33
|
+
documentType: ["powerhouse/document-model"],
|
|
34
|
+
scope: ["global"],
|
|
35
|
+
branch: ["*"],
|
|
36
|
+
documentId: ["*"]
|
|
37
|
+
},
|
|
38
|
+
block: false,
|
|
39
|
+
listenerId: "reactor-local-document-model-generator",
|
|
40
|
+
label: "reactor-local-document-model-generator"
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return reactor2;
|
|
45
|
+
}
|
|
46
|
+
const reactor = (options) => {
|
|
47
|
+
return startLocalReactor(options);
|
|
48
|
+
};
|
|
49
|
+
function reactorCommand(program) {
|
|
50
|
+
program.command("reactor").description("Starts local reactor").option("--port <PORT>", "port to host the api", "4001").option("--generate", "generate code when document model is updated").option("--db-path <DB_PATH>", "path to the database").option(
|
|
51
|
+
"-w, --watch",
|
|
52
|
+
"if the reactor should watch for local changes to document models and processors"
|
|
53
|
+
).action(async (...args) => {
|
|
54
|
+
await reactor(...args);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (process.argv.at(2) === "spawn") {
|
|
58
|
+
const optionsArg = process.argv.at(3);
|
|
59
|
+
const options = optionsArg ? JSON.parse(optionsArg) : {};
|
|
60
|
+
startLocalReactor(options).then((reactor2) => {
|
|
61
|
+
process.send?.(`driveUrl:${reactor2.driveUrl}`);
|
|
62
|
+
}).catch((e) => {
|
|
63
|
+
throw e;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { DefaultReactorOptions, reactor, reactorCommand };
|
|
68
|
+
//# sourceMappingURL=reactor.js.map
|
|
69
|
+
//# sourceMappingURL=reactor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/commands/reactor.ts"],"names":["reactor"],"mappings":";;;;AAiBO,MAAM,qBAAwB,GAAA;AAAA,EACnC,GAAG,yBAAA;AAAA,EACH,GAAK,EAAA;AACP;AAEA,eAAe,kBAAkB,cAAgC,EAAA;AAC/D,EAAA,MAAM,aAAa,SAAU,EAAA;AAC7B,EAAA,MAAM,OAAU,GAAA,EAAE,GAAG,qBAAA,EAAuB,GAAG,cAAe,EAAA;AAC9D,EAAMA,MAAAA,QAAAA,GAAU,MAAM,WAAA,CAAY,OAAO,CAAA;AAEzC,EAAA,IAAI,QAAQ,QAAU,EAAA;AACpB,IAA4B,MAAMA,QAAQ,CAAA,WAAA;AAAA,MACxC,YAAA;AAAA,MACA;AAAA,QACE,SAAA,EAAW,eAAgB,OAAS,EAAA;AAClC,UAAM,MAAA,aAAA,uBAAoB,GAAY,EAAA;AACtC,UAAA,KAAA,MAAW,UAAU,OAAS,EAAA;AAC5B,YAAc,aAAA,CAAA,GAAA;AAAA,cACZA,QAAQ,CAAA,eAAA,CAAgB,MAAO,CAAA,OAAA,EAAS,OAAO,UAAU;AAAA,aAC3D;AAAA;AAEF,UAAA,KAAA,MAAW,QAAQ,aAAe,EAAA;AAChC,YAAM,MAAA,gBAAA,CAAiB,MAAM,UAAU,CAAA;AAAA;AAEzC,UAAA,OAAO,QAAQ,OAAQ,EAAA;AAAA,SACzB;AAAA,QACA,YAAA,EAAc,MAAM,OAAA,CAAQ,OAAQ;AAAA,OACtC;AAAA,MACA;AAAA,QACE,MAAQ,EAAA;AAAA,UACN,YAAA,EAAc,CAAC,2BAA2B,CAAA;AAAA,UAC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,CAAA;AACL","file":"reactor.js","sourcesContent":["import { Command } from \"commander\";\nimport {\n DefaultStartServerOptions,\n startServer,\n StartServerOptions,\n LocalReactor,\n} from \"@powerhousedao/reactor-local\";\nimport { generateFromFile } from \"@powerhousedao/codegen\";\nimport { CommandActionType } from \"../types.js\";\nimport { getConfig } from \"@powerhousedao/config/powerhouse\";\n\nexport type ReactorOptions = StartServerOptions & {\n generate?: boolean;\n watch?: boolean;\n dbPath?: string;\n};\n\nexport const DefaultReactorOptions = {\n ...DefaultStartServerOptions,\n dev: true,\n};\n\nasync function startLocalReactor(reactorOptions: ReactorOptions) {\n const baseConfig = getConfig();\n const options = { ...DefaultReactorOptions, ...reactorOptions };\n const reactor = await startServer(options);\n\n if (options.generate) {\n const generateTransmitter = await reactor.addListener(\n \"powerhouse\",\n {\n onStrands: async function (strands) {\n const documentPaths = new Set<string>();\n for (const strand of strands) {\n documentPaths.add(\n reactor.getDocumentPath(strand.driveId, strand.documentId),\n );\n }\n for (const path of documentPaths) {\n await generateFromFile(path, baseConfig);\n }\n return Promise.resolve();\n },\n onDisconnect: () => Promise.resolve(),\n },\n {\n filter: {\n documentType: [\"powerhouse/document-model\"],\n scope: [\"global\"],\n branch: [\"*\"],\n documentId: [\"*\"],\n },\n block: false,\n listenerId: \"reactor-local-document-model-generator\",\n label: \"reactor-local-document-model-generator\",\n },\n );\n }\n return reactor;\n}\n\nexport const reactor: CommandActionType<\n [ReactorOptions],\n Promise<LocalReactor>\n> = (options) => {\n return startLocalReactor(options);\n};\n\nexport function reactorCommand(program: Command) {\n program\n .command(\"reactor\")\n .description(\"Starts local reactor\")\n .option(\"--port <PORT>\", \"port to host the api\", \"4001\")\n .option(\"--generate\", \"generate code when document model is updated\")\n .option(\"--db-path <DB_PATH>\", \"path to the database\")\n .option(\n \"-w, --watch\",\n \"if the reactor should watch for local changes to document models and processors\",\n )\n .action(async (...args: [ReactorOptions]) => {\n await reactor(...args);\n });\n}\n\nif (process.argv.at(2) === \"spawn\") {\n const optionsArg = process.argv.at(3);\n const options = optionsArg ? (JSON.parse(optionsArg) as ReactorOptions) : {};\n startLocalReactor(options)\n .then((reactor) => {\n process.send?.(`driveUrl:${reactor.driveUrl}`);\n })\n .catch((e: unknown) => {\n throw e;\n });\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { commands } from './commands/index.js';
|
|
2
|
+
export { getConfig } from '@powerhousedao/config/powerhouse';
|
|
3
|
+
export { dev, devCommand } from './commands/dev.js';
|
|
4
|
+
export { helpCommand } from './commands/help.js';
|
|
5
|
+
export { init, initCommand } from './commands/init.js';
|
|
6
|
+
export { generate, generateCommand } from './commands/generate.js';
|
|
7
|
+
export { DefaultReactorOptions, ReactorOptions, reactor, reactorCommand } from './commands/reactor.js';
|
|
8
|
+
import 'commander';
|
|
9
|
+
import './types.js';
|
|
10
|
+
import '@powerhousedao/reactor-local';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getConfig } from '@powerhousedao/config/powerhouse';
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"utils.js","sourcesContent":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ph-cmd",
|
|
3
|
+
"version": "0.18.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "AGPL-3.0-only",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"ph": "dist/cli.js"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./dist/index.js",
|
|
17
|
+
"./cli": "./dist/cli.js",
|
|
18
|
+
"./utils": "./dist/utils.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup",
|
|
25
|
+
"dev": "tsx src/cli.ts",
|
|
26
|
+
"prepublishOnly": "npm run build",
|
|
27
|
+
"lint": "eslint .",
|
|
28
|
+
"lint:nx": "eslint . --fix --quiet",
|
|
29
|
+
"lint:fix": "eslint --fix"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [],
|
|
32
|
+
"author": "",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@powerhousedao/analytics-engine-core": "^0.3.0",
|
|
35
|
+
"@powerhousedao/analytics-engine-graphql": "^0.2.1",
|
|
36
|
+
"@powerhousedao/analytics-engine-pg": "^0.3.0",
|
|
37
|
+
"document-drive": "workspace:*",
|
|
38
|
+
"graphql-tag": "^2.12.6",
|
|
39
|
+
"knex": "^3.1.0",
|
|
40
|
+
"luxon": "^3.5.0"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@powerhousedao/codegen": "workspace:*",
|
|
44
|
+
"@powerhousedao/config": "workspace:*",
|
|
45
|
+
"@powerhousedao/connect": "1.0.0-dev.181",
|
|
46
|
+
"@powerhousedao/design-system": "workspace:*",
|
|
47
|
+
"@powerhousedao/reactor-local": "workspace:*",
|
|
48
|
+
"@powerhousedao/scalars": "workspace:*",
|
|
49
|
+
"colorette": "^2.0.20",
|
|
50
|
+
"commander": "^12.1.0",
|
|
51
|
+
"document-model-libs": "workspace:*",
|
|
52
|
+
"graphql": "^16.9.0",
|
|
53
|
+
"react": "^18.3.1",
|
|
54
|
+
"react-dom": "^18.3.1"
|
|
55
|
+
}
|
|
56
|
+
}
|