@powerhousedao/ph-cli 0.1.0 → 0.2.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.
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var child_process = require('child_process');
5
+ var colorette = require('colorette');
6
+ var fs = require('fs');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var path__default = /*#__PURE__*/_interopDefault(path);
11
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
12
+
13
+ const CONNECT_BIN_PATH = "node_modules/.bin/connect";
14
+ const dev = ({
15
+ projectPath
16
+ }) => {
17
+ let binPath = path__default.default.join(projectPath || ".", "node_modules/.bin/connect");
18
+ if (!fs__default.default.existsSync(binPath)) {
19
+ const packagePath = require.resolve("@powerhousedao/connect/package.json");
20
+ const packageDir = path__default.default.dirname(packagePath);
21
+ binPath = path__default.default.join(packageDir, CONNECT_BIN_PATH);
22
+ }
23
+ const child = child_process.spawn(binPath);
24
+ child.stdout.on("data", (data) => {
25
+ colorette.green(data.toString());
26
+ process.stdout.write(colorette.green(`[Connect]: ${data.toString()}`));
27
+ });
28
+ child.stderr.on("data", (data) => {
29
+ process.stderr.write(colorette.red(`[Connect]: ${data.toString()}`));
30
+ });
31
+ child.on("close", (code) => {
32
+ console.log(`Connect process exited with code ${code}`);
33
+ });
34
+ };
35
+ function devCommand(program) {
36
+ program.command("dev").description("Starts dev environment").option("--project-path <type>", "path to the project").action(dev);
37
+ }
38
+
39
+ exports.dev = dev;
40
+ exports.devCommand = devCommand;
41
+ //# sourceMappingURL=dev.js.map
42
+ //# sourceMappingURL=dev.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/commands/dev.ts"],"names":["path","fs","spawn","green","red"],"mappings":";;;;;;;;;;;;AAQA,MAAM,gBAAmB,GAAA,2BAAA,CAAA;AAElB,MAAM,MAAqD,CAAC;AAAA,EACjE,WAAA;A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CAAA,CACb,WAAY,CAAA,wBAAwB,CACpC,CAAA,MAAA,CAAO,uBAAyB,EAAA,qBAAqB,CACrD,CAAA,MAAA,CAAO,GAAG,CAAA,CAAA;AACf","file":"dev.js","sourcesContent":["import { Command } from \"commander\";\nimport path from \"path\";\nimport { spawn } from \"child_process\";\nimport { green, red } from \"colorette\";\nimport fs from \"fs\";\n\nimport { CommandActionType } from \"../types\";\n\nconst CONNECT_BIN_PATH = \"node_modules/.bin/connect\";\n\nexport const dev: CommandActionType<[{ projectPath?: string }]> = ({\n projectPath,\n}) => {\n let binPath = path.join(projectPath || \".\", \"node_modules/.bin/connect\");\n\n if (!fs.existsSync(binPath)) {\n const packagePath = require.resolve(\"@powerhousedao/connect/package.json\");\n const packageDir = path.dirname(packagePath);\n\n binPath = path.join(packageDir, CONNECT_BIN_PATH);\n }\n\n const child = spawn(binPath);\n\n child.stdout.on(\"data\", (data: Buffer) => {\n green(data.toString());\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\nexport function devCommand(program: Command) {\n program\n .command(\"dev\")\n .description(\"Starts dev environment\")\n .option(\"--project-path <type>\", \"path to the project\")\n .action(dev);\n}\n"]}
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ var codegen = require('@powerhousedao/codegen');
4
+
5
+ const generate = async (filePath, options) => {
6
+ const baseConfig = codegen.getConfig();
7
+ const config = {
8
+ ...baseConfig,
9
+ ...{
10
+ ...options.editors && { editorsDir: options.editors },
11
+ ...options.documentModels && {
12
+ documentModelsDir: options.documentModels
13
+ },
14
+ ...options.format && { format: options.format },
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
+ };
24
+ if (config.interactive) {
25
+ const result = await codegen.promptDirectories(config);
26
+ Object.assign(config, result);
27
+ }
28
+ if (command.editor) {
29
+ if (!command.editorName) {
30
+ throw new Error("Editor name is required (--editor or -e)");
31
+ }
32
+ await codegen.generateEditor(
33
+ command.editorName,
34
+ command.documentTypes?.split(/[|,;]/g) ?? [],
35
+ config
36
+ );
37
+ return;
38
+ }
39
+ if (filePath) {
40
+ await codegen.generateFromFile(filePath, config);
41
+ return;
42
+ }
43
+ await codegen.generate(config);
44
+ };
45
+ function generateCommand(program) {
46
+ 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("--document-models <type>", "Path to the document models directory").option("--document-types <type>", "Supported document types by the editor").option("-f, --format", "Format the generated code").option("-w, --watch", "Watch the generated code").action(generate);
47
+ }
48
+
49
+ exports.generate = generate;
50
+ exports.generateCommand = generateCommand;
51
+ //# sourceMappingURL=generate.js.map
52
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/commands/generate.ts"],"names":["getConfig","promptDirectories","generateEditor","generateFromFile","generateCode"],"mappings":";;;;AAWa,MAAA,QAAA,GAaT,OAAO,QAAA,EAAU,OAAY,KAAA;AAC/B,EAAA,MAAM,aAAaA,iBAAU,EAAA,CAAA;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,QAAQ,cAAkB,IAAA;AAAA,QAC5B,mBAAmB,OAAQ,CAAA,cAAA;AAAA,OAC7B;AAAA,MACA,GAAI,OAAQ,CAAA,MAAA,IAAU,EAAE,MAAA,EAAQ,QAAQ,MAAO,EAAA;AAAA,MAC/C,GAAI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E,MAAO,CAAA,kBAAA,EAAoB,+BAA+B,CAC1D,CAAA,MAAA,CAAO,qBAAuB,EAAA,aAAa,EAC3C,MAAO,CAAA,0BAAA,EAA4B,uCAAuC,CAC1E,CAAA,MAAA,CAAO,2BAA2B,wCAAwC,CAAA,CAC1E,MAAO,CAAA,cAAA,EAAgB,2BAA2B,CAClD,CAAA,MAAA,CAAO,eAAe,0BAA0B,CAAA,CAChD,OAAO,QAAQ,CAAA,CAAA;AACpB","file":"generate.js","sourcesContent":["import { Command } from \"commander\";\nimport {\n getConfig,\n generate as generateCode,\n generateEditor,\n generateFromFile,\n promptDirectories,\n} from \"@powerhousedao/codegen\";\n\nimport { CommandActionType } from \"../types\";\n\nexport const generate: CommandActionType<\n [\n string | undefined,\n {\n interactive?: boolean;\n editors?: string;\n documentModels?: string;\n format?: boolean;\n watch?: boolean;\n editor?: string;\n documentTypes?: 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.documentModels && {\n documentModelsDir: options.documentModels,\n }),\n ...(options.format && { format: options.format }),\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 };\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 (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(\"--document-models <type>\", \"Path to the document models directory\")\n .option(\"--document-types <type>\", \"Supported document types by the editor\")\n .option(\"-f, --format\", \"Format the generated code\")\n .option(\"-w, --watch\", \"Watch the generated code\")\n .action(generate);\n}\n"]}
@@ -2,17 +2,24 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var dev = require('./dev');
5
6
  var help = require('./help');
6
7
  var init = require('./init');
7
- var createDocument = require('./create-document');
8
+ var generate = require('./generate');
8
9
 
9
- const commands = [init.initCommand, createDocument.createDocumentCommand, help.helpCommand];
10
+ const commands = [init.initCommand, dev.devCommand, generate.generateCommand, help.helpCommand];
10
11
  function registerCommands(program) {
11
12
  commands.forEach((command) => command(program));
12
13
  }
13
14
 
14
15
  exports.commands = commands;
15
16
  exports.default = registerCommands;
17
+ Object.keys(dev).forEach(function (k) {
18
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
19
+ enumerable: true,
20
+ get: function () { return dev[k]; }
21
+ });
22
+ });
16
23
  Object.keys(help).forEach(function (k) {
17
24
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
18
25
  enumerable: true,
@@ -25,10 +32,10 @@ Object.keys(init).forEach(function (k) {
25
32
  get: function () { return init[k]; }
26
33
  });
27
34
  });
28
- Object.keys(createDocument).forEach(function (k) {
35
+ Object.keys(generate).forEach(function (k) {
29
36
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
30
37
  enumerable: true,
31
- get: function () { return createDocument[k]; }
38
+ get: function () { return generate[k]; }
32
39
  });
33
40
  });
34
41
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/index.ts"],"names":["initCommand","createDocumentCommand","helpCommand"],"mappings":";;;;;;;;AAMO,MAAM,QAAW,GAAA,CAACA,gBAAa,EAAAC,oCAAA,EAAuBC,gBAAW,EAAA;AAEzD,SAAR,iBAAkC,OAAkB,EAAA;AACzD,EAAA,QAAA,CAAS,OAAQ,CAAA,CAAC,OAAY,KAAA,OAAA,CAAQ,OAAO,CAAC,CAAA,CAAA;AAChD","file":"index.js","sourcesContent":["import { Command } from \"commander\";\n\nimport { helpCommand } from \"./help\";\nimport { initCommand } from \"./init\";\nimport { createDocumentCommand } from \"./create-document\";\n\nexport const commands = [initCommand, createDocumentCommand, helpCommand];\n\nexport default function registerCommands(program: Command) {\n commands.forEach((command) => command(program));\n}\n\nexport * from \"./help\";\nexport * from \"./init\";\nexport * from \"./create-document\";\n"]}
1
+ {"version":3,"sources":["../../src/commands/index.ts"],"names":["initCommand","devCommand","generateCommand","helpCommand"],"mappings":";;;;;;;;;AAOO,MAAM,QAAW,GAAA,CAACA,gBAAa,EAAAC,cAAA,EAAYC,0BAAiBC,gBAAW,EAAA;AAE/D,SAAR,iBAAkC,OAAkB,EAAA;AACzD,EAAA,QAAA,CAAS,OAAQ,CAAA,CAAC,OAAY,KAAA,OAAA,CAAQ,OAAO,CAAC,CAAA,CAAA;AAChD","file":"index.js","sourcesContent":["import { Command } from \"commander\";\n\nimport { devCommand } from \"./dev\";\nimport { helpCommand } from \"./help\";\nimport { initCommand } from \"./init\";\nimport { generateCommand } from \"./generate\";\n\nexport const commands = [initCommand, devCommand, generateCommand, helpCommand];\n\nexport default function registerCommands(program: Command) {\n commands.forEach((command) => command(program));\n}\n\nexport * from \"./dev\";\nexport * from \"./help\";\nexport * from \"./init\";\nexport * from \"./generate\";\n"]}
package/dist/index.d.ts CHANGED
@@ -10,10 +10,27 @@ declare const init: CommandActionType<[
10
10
  ]>;
11
11
  declare function initCommand(program: Command): void;
12
12
 
13
+ declare const dev: CommandActionType<[{
14
+ projectPath?: string;
15
+ }]>;
16
+ declare function devCommand(program: Command): void;
17
+
13
18
  declare function helpCommand(program: Command): void;
14
19
 
15
- declare function createDocumentCommand(program: Command): void;
20
+ declare const generate: CommandActionType<[
21
+ string | undefined,
22
+ {
23
+ interactive?: boolean;
24
+ editors?: string;
25
+ documentModels?: string;
26
+ format?: boolean;
27
+ watch?: boolean;
28
+ editor?: string;
29
+ documentTypes?: string;
30
+ }
31
+ ]>;
32
+ declare function generateCommand(program: Command): void;
16
33
 
17
34
  declare const commands: (typeof initCommand)[];
18
35
 
19
- export { commands, createDocumentCommand, helpCommand, init, initCommand };
36
+ export { commands, dev, devCommand, generate, generateCommand, helpCommand, init, initCommand };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/ph-cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0-only",
6
6
  "types": "dist/index.d.ts",
@@ -21,9 +21,15 @@
21
21
  "tsup": "^8.3.0"
22
22
  },
23
23
  "dependencies": {
24
+ "@powerhousedao/connect": "develop",
25
+ "colorette": "^2.0.20",
24
26
  "commander": "^12.1.0",
27
+ "graphql": "^16.8.1",
25
28
  "@powerhousedao/codegen": "0.7.0"
26
29
  },
30
+ "resolutions": {
31
+ "graphql": "^16.8.1"
32
+ },
27
33
  "scripts": {
28
34
  "build": "tsup",
29
35
  "dev": "ts-node src/cli.ts",
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- function createDocumentCommand(program) {
4
- program.command("create-document").description("Create a new document").action(() => {
5
- console.log("Creating a new document...");
6
- });
7
- }
8
-
9
- exports.createDocumentCommand = createDocumentCommand;
10
- //# sourceMappingURL=create-document.js.map
11
- //# sourceMappingURL=create-document.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/commands/create-document.ts"],"names":[],"mappings":";;AAEO,SAAS,sBAAsB,OAAkB,EAAA;AACtD,EAAA,OAAA,CACG,QAAQ,iBAAiB,CAAA,CACzB,YAAY,uBAAuB,CAAA,CACnC,OAAO,MAAM;AACZ,IAAA,OAAA,CAAQ,IAAI,4BAA4B,CAAA,CAAA;AAAA,GACzC,CAAA,CAAA;AACL","file":"create-document.js","sourcesContent":["import { Command } from \"commander\";\n\nexport function createDocumentCommand(program: Command) {\n program\n .command(\"create-document\")\n .description(\"Create a new document\")\n .action(() => {\n console.log(\"Creating a new document...\");\n });\n}\n"]}