@powerhousedao/codegen 0.3.2 → 0.5.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/cli.js CHANGED
@@ -5,15 +5,15 @@ const index_1 = require("./codegen/index");
5
5
  const utils_1 = require("./utils");
6
6
  async function parseCommand(argv) {
7
7
  const args = (0, utils_1.parseArgs)(argv, {
8
- '--editor': String,
9
- '-e': '--editor',
10
- '--document-types': String,
8
+ "--editor": String,
9
+ "-e": "--editor",
10
+ "--document-types": String,
11
11
  });
12
- const editorName = args['--editor'];
12
+ const editorName = args["--editor"];
13
13
  return {
14
14
  editor: !!editorName,
15
15
  editorName,
16
- documentTypes: args['--document-types'],
16
+ documentTypes: args["--document-types"],
17
17
  arg: args._,
18
18
  };
19
19
  }
@@ -4,7 +4,7 @@ const change_case_1 = require("change-case");
4
4
  function documentModelToString(documentModel) {
5
5
  return JSON.stringify({
6
6
  ...documentModel,
7
- specifications: documentModel.specifications.map(s => ({
7
+ specifications: documentModel.specifications.map((s) => ({
8
8
  ...s,
9
9
  state: Object.keys(s.state).reduce((values, scope) => {
10
10
  const state = s.state[scope];
@@ -31,12 +31,12 @@ exports.default = {
31
31
  documentTypeId: documentModel.id,
32
32
  documentType: documentModel.name,
33
33
  extension: documentModel.extension,
34
- modules: latestSpec.modules.map(m => ({
34
+ modules: latestSpec.modules.map((m) => ({
35
35
  ...m,
36
36
  name: (0, change_case_1.paramCase)(m.name),
37
37
  })),
38
38
  fileExtension: documentModel.extension,
39
- hasLocalSchema: latestSpec.state.local.schema !== '',
39
+ hasLocalSchema: latestSpec.state.local.schema !== "",
40
40
  ...getInitialStates(latestSpec.state),
41
41
  };
42
42
  },
@@ -45,7 +45,7 @@ function getInitialStates(scopeState) {
45
45
  const { global, local } = scopeState;
46
46
  const scopes = { global, local };
47
47
  Object.entries(scopes).forEach(([scope, state]) => {
48
- if (!isEmptyStateSchema(state.schema) && state.initialValue === '') {
48
+ if (!isEmptyStateSchema(state.schema) && state.initialValue === "") {
49
49
  throw new Error(`${scope.charAt(0).toLocaleUpperCase() + scope.slice(1)} scope has a defined schema but is missing an initial value.`);
50
50
  }
51
51
  });
@@ -55,8 +55,8 @@ function getInitialStates(scopeState) {
55
55
  };
56
56
  }
57
57
  function isEmptyStateSchema(schema) {
58
- return schema === '' || !schema.includes('{');
58
+ return schema === "" || !schema.includes("{");
59
59
  }
60
60
  function handleEmptyState(state) {
61
- return state === '' ? '{}' : state;
61
+ return state === "" ? "{}" : state;
62
62
  }
@@ -1,5 +1,5 @@
1
- import { Maybe, OperationScope } from 'document-model/document';
2
- import { Args } from '../generate-document-model';
1
+ import { Maybe, OperationScope } from "document-model/document";
2
+ import { Args } from "../generate-document-model";
3
3
  type ModuleArgs = Args & {
4
4
  module: string;
5
5
  };
@@ -5,14 +5,14 @@ exports.default = {
5
5
  params: ({ args }) => {
6
6
  const documentModel = JSON.parse(args.documentModel);
7
7
  const latestSpec = documentModel.specifications[documentModel.specifications.length - 1];
8
- const filteredModules = latestSpec.modules.filter(m => m.name === args.module);
8
+ const filteredModules = latestSpec.modules.filter((m) => m.name === args.module);
9
9
  const actions = filteredModules.length > 0
10
- ? filteredModules[0].operations.map(a => ({
10
+ ? filteredModules[0].operations.map((a) => ({
11
11
  name: a.name,
12
12
  hasInput: a.schema !== null,
13
- hasAttachment: a.schema?.includes(': Attachment'),
14
- scope: a.scope || 'global',
15
- state: a.scope === 'global' ? '' : a.scope, // the state this action affects
13
+ hasAttachment: a.schema?.includes(": Attachment"),
14
+ scope: a.scope || "global",
15
+ state: a.scope === "global" ? "" : a.scope, // the state this action affects
16
16
  }))
17
17
  : [];
18
18
  return {
@@ -13,7 +13,7 @@ declare const _default: {
13
13
  documentModelsDir: string;
14
14
  name: string;
15
15
  documentTypes: string[];
16
- documentTypesMap: unknown;
16
+ documentTypesMap: Record<string, string>;
17
17
  };
18
18
  };
19
19
  export default _default;
@@ -7,8 +7,8 @@ exports.default = {
7
7
  documentModelsDir: args.documentModelsDir,
8
8
  name: args.name,
9
9
  documentTypes: args.documentTypes
10
- .split(',')
11
- .filter(type => type !== ''),
10
+ .split(",")
11
+ .filter((type) => type !== ""),
12
12
  documentTypesMap: JSON.parse(args.documentTypesMap),
13
13
  };
14
14
  },
@@ -4,15 +4,15 @@ exports.generateSchemas = exports.generateSchema = void 0;
4
4
  const cli_1 = require("@graphql-codegen/cli");
5
5
  const fs_1 = require("fs");
6
6
  const getDirectories = (source) => (0, fs_1.readdirSync)(source, { withFileTypes: true })
7
- .filter(dirent => dirent.isDirectory())
8
- .map(dirent => dirent.name);
7
+ .filter((dirent) => dirent.isDirectory())
8
+ .map((dirent) => dirent.name);
9
9
  const tsConfig = {
10
10
  strictScalars: true,
11
11
  scalars: {
12
- Unknown: 'unknown',
13
- DateTime: 'string',
14
- Attachment: 'string',
15
- Address: '`${string}:0x${string}`',
12
+ Unknown: "unknown",
13
+ DateTime: "string",
14
+ Attachment: "string",
15
+ Address: "`${string}:0x${string}`",
16
16
  },
17
17
  enumsAsTypes: true,
18
18
  allowEnumStringTypes: true,
@@ -21,7 +21,7 @@ const tsConfig = {
21
21
  },
22
22
  skipTypename: true,
23
23
  // maybeValue: "T | null | undefined",
24
- inputMaybeValue: 'T | null | undefined',
24
+ inputMaybeValue: "T | null | undefined",
25
25
  };
26
26
  function schemaConfig(name, dir) {
27
27
  return {
@@ -33,25 +33,25 @@ function schemaConfig(name, dir) {
33
33
  },
34
34
  },
35
35
  ],
36
- plugins: ['typescript'],
36
+ plugins: ["typescript"],
37
37
  config: tsConfig,
38
38
  },
39
39
  [`${dir}/${name}/gen/schema/zod.ts`]: {
40
40
  schema: `${dir}/${name}/schema.graphql`,
41
- plugins: ['@acaldas/graphql-codegen-typescript-validation-schema'],
41
+ plugins: ["@acaldas/graphql-codegen-typescript-validation-schema"],
42
42
  config: {
43
43
  importFrom: `./types`,
44
- schema: 'zod',
44
+ schema: "zod",
45
45
  ...tsConfig,
46
46
  scalarSchemas: {
47
- Unknown: 'z.unknown()',
48
- DateTime: 'z.string().datetime()',
49
- Attachment: 'z.string()',
50
- Address: 'z.custom<`${string}:0x${string}`>((val) => /^[a-zA-Z0-9]+:0x[a-fA-F0-9]{40}$/.test(val as string))',
47
+ Unknown: "z.unknown()",
48
+ DateTime: "z.string().datetime()",
49
+ Attachment: "z.string()",
50
+ Address: "z.custom<`${string}:0x${string}`>((val) => /^[a-zA-Z0-9]+:0x[a-fA-F0-9]{40}$/.test(val as string))",
51
51
  },
52
52
  directives: {
53
53
  equals: {
54
- value: ['regex', '/^$1$/'],
54
+ value: ["regex", "/^$1$/"],
55
55
  },
56
56
  },
57
57
  withObjectType: true,
@@ -66,7 +66,7 @@ const generateSchema = (model, dir, { watch = false, format = false } = {}) => {
66
66
  generates: documentModelConfig,
67
67
  watch,
68
68
  hooks: {
69
- afterOneFileWrite: format ? ['prettier --ignore-path --write'] : [],
69
+ afterOneFileWrite: format ? ["prettier --ignore-path --write"] : [],
70
70
  },
71
71
  };
72
72
  return (0, cli_1.generate)(config, true);
@@ -83,7 +83,7 @@ const generateSchemas = (dir, { watch = false, format = false } = {}) => {
83
83
  generates: documentModelConfigs,
84
84
  watch,
85
85
  hooks: {
86
- afterOneFileWrite: format ? ['prettier --ignore-path --write'] : [],
86
+ afterOneFileWrite: format ? ["prettier --ignore-path --write"] : [],
87
87
  },
88
88
  };
89
89
  return (0, cli_1.generate)(config, true);
@@ -1,4 +1,4 @@
1
- import { DocumentModel } from 'document-model';
1
+ import { DocumentModel } from "document-model";
2
2
  export declare function generateAll(dir: string, { watch, format }?: {
3
3
  watch?: boolean | undefined;
4
4
  format?: boolean | undefined;
@@ -11,30 +11,30 @@ const hygen_1 = require("hygen");
11
11
  const path_1 = __importDefault(require("path"));
12
12
  const utils_1 = require("./utils");
13
13
  const logger = new hygen_1.Logger(console.log.bind(console));
14
- const defaultTemplates = path_1.default.join(__dirname, '.hygen', 'templates');
14
+ const defaultTemplates = path_1.default.join(__dirname, ".hygen", "templates");
15
15
  async function run(args, { watch = false, format = false } = {}) {
16
16
  const result = await (0, hygen_1.runner)(args, {
17
17
  templates: defaultTemplates,
18
18
  cwd: process.cwd(),
19
19
  logger,
20
20
  createPrompter: () => {
21
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
22
- return require('enquirer');
21
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-require-imports
22
+ return require("enquirer");
23
23
  },
24
24
  exec: (action, body) => {
25
25
  const opts = body && body.length > 0 ? { input: body } : {};
26
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-member-access
27
- return require('execa').shell(action, opts);
26
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-require-imports
27
+ return require("execa").shell(action, opts);
28
28
  },
29
29
  debug: !!process.env.DEBUG,
30
30
  });
31
31
  if (format) {
32
- const execa = await import('execa');
32
+ const execa = await import("execa");
33
33
  const actions = result.actions;
34
34
  actions
35
- .filter(action => ['added', 'inject'].includes(action.status))
36
- .forEach(action => {
37
- execa.$ `prettier --ignore-path --write ${action.subject.replace('.', process.cwd())}`.catch((err) => {
35
+ .filter((action) => ["added", "inject"].includes(action.status))
36
+ .forEach((action) => {
37
+ execa.$ `prettier --ignore-path --write ${action.subject.replace(".", process.cwd())}`.catch((err) => {
38
38
  console.log(err);
39
39
  });
40
40
  });
@@ -43,7 +43,7 @@ async function run(args, { watch = false, format = false } = {}) {
43
43
  }
44
44
  async function generateAll(dir, { watch = false, format = false } = {}) {
45
45
  const files = fs_1.default.readdirSync(dir, { withFileTypes: true });
46
- for (const directory of files.filter(f => f.isDirectory())) {
46
+ for (const directory of files.filter((f) => f.isDirectory())) {
47
47
  const documentModelPath = path_1.default.join(dir, directory.name, `${directory.name}.json`);
48
48
  if (!fs_1.default.existsSync(documentModelPath)) {
49
49
  continue;
@@ -60,24 +60,24 @@ async function generateAll(dir, { watch = false, format = false } = {}) {
60
60
  async function generateDocumentModel(documentModel, dir, { watch = false, format = false } = {}) {
61
61
  // Generate the singular files for the document model logic
62
62
  await run([
63
- 'powerhouse',
64
- 'generate-document-model',
65
- '--document-model',
63
+ "powerhouse",
64
+ "generate-document-model",
65
+ "--document-model",
66
66
  JSON.stringify(documentModel),
67
- '--root-dir',
67
+ "--root-dir",
68
68
  dir,
69
69
  ], { watch, format });
70
70
  // Generate the module-specific files for the document model logic
71
71
  const latestSpec = documentModel.specifications[documentModel.specifications.length - 1];
72
72
  for (const module of latestSpec.modules) {
73
73
  await run([
74
- 'powerhouse',
75
- 'generate-document-model-module',
76
- '--document-model',
74
+ "powerhouse",
75
+ "generate-document-model-module",
76
+ "--document-model",
77
77
  JSON.stringify(documentModel),
78
- '--root-dir',
78
+ "--root-dir",
79
79
  dir,
80
- '--module',
80
+ "--module",
81
81
  module.name,
82
82
  ], { watch, format });
83
83
  }
@@ -85,17 +85,17 @@ async function generateDocumentModel(documentModel, dir, { watch = false, format
85
85
  async function generateEditor(name, documentTypes, documentTypesMap, dir, documentModelsDir, { format = false } = {}) {
86
86
  // Generate the singular files for the document model logic
87
87
  await run([
88
- 'powerhouse',
89
- 'generate-editor',
90
- '--name',
88
+ "powerhouse",
89
+ "generate-editor",
90
+ "--name",
91
91
  name,
92
- '--root-dir',
92
+ "--root-dir",
93
93
  dir,
94
- '--document-types',
95
- documentTypes.join(','),
96
- '--document-types-map',
94
+ "--document-types",
95
+ documentTypes.join(","),
96
+ "--document-types-map",
97
97
  JSON.stringify(documentTypesMap),
98
- '--document-models-dir',
98
+ "--document-models-dir",
99
99
  documentModelsDir,
100
100
  ], { format });
101
101
  }
@@ -1,5 +1,5 @@
1
1
  #! /usr/bin/env node
2
- import type { PowerhouseConfig } from '../utils';
2
+ import type { PowerhouseConfig } from "../utils";
3
3
  export declare function generate(config: PowerhouseConfig): Promise<void>;
4
4
  export declare function generateFromFile(path: string, config: PowerhouseConfig): Promise<void>;
5
5
  export declare function generateEditor(name: string, documentTypes: string[], config: PowerhouseConfig): Promise<void>;
@@ -24,26 +24,26 @@ function generateGraphqlSchema(documentModel) {
24
24
  global.schema,
25
25
  local.schema,
26
26
  ...modules
27
- .map(module => [
27
+ .map((module) => [
28
28
  `# ${module.name}`,
29
- ...module.operations.map(op => op.schema),
29
+ ...module.operations.map((op) => op.schema),
30
30
  ])
31
31
  .flat()
32
- .filter(schema => schema && schema.length > 0),
32
+ .filter((schema) => schema && schema.length > 0),
33
33
  ];
34
- return schemas.join('\n\n');
34
+ return schemas.join("\n\n");
35
35
  }
36
36
  function getDocumentTypesMap(dir) {
37
37
  const documentTypesMap = {};
38
38
  fs_1.default.readdirSync(dir, { withFileTypes: true })
39
- .filter(dirent => dirent.isDirectory())
40
- .map(dirent => dirent.name)
41
- .forEach(name => {
39
+ .filter((dirent) => dirent.isDirectory())
40
+ .map((dirent) => dirent.name)
41
+ .forEach((name) => {
42
42
  const specPath = (0, path_1.resolve)(dir, name, `${name}.json`);
43
43
  if (!fs_1.default.existsSync(specPath)) {
44
44
  return;
45
45
  }
46
- const specRaw = fs_1.default.readFileSync(specPath, 'utf-8');
46
+ const specRaw = fs_1.default.readFileSync(specPath, "utf-8");
47
47
  try {
48
48
  const spec = JSON.parse(specRaw);
49
49
  if (spec.id) {
@@ -79,7 +79,7 @@ async function generateFromFile(path, config) {
79
79
  async function generateEditor(name, documentTypes, config) {
80
80
  const { documentModelsDir, format } = config;
81
81
  const docummentTypesMap = getDocumentTypesMap(documentModelsDir);
82
- const invalidType = documentTypes.find(type => !Object.keys(docummentTypesMap).includes(type));
82
+ const invalidType = documentTypes.find((type) => !Object.keys(docummentTypesMap).includes(type));
83
83
  if (invalidType) {
84
84
  throw new Error(`Document model for ${invalidType} not found`);
85
85
  }
@@ -1,2 +1,2 @@
1
- import { DocumentModelState } from 'document-model/document-model';
1
+ import { DocumentModelState } from "document-model/document-model";
2
2
  export declare function loadDocumentModel(path: string): Promise<DocumentModelState>;
@@ -10,26 +10,26 @@ async function loadDocumentModel(path) {
10
10
  let documentModel;
11
11
  try {
12
12
  if (!path) {
13
- throw new Error('Document model file not specified');
13
+ throw new Error("Document model file not specified");
14
14
  }
15
- else if (path.endsWith('.zip')) {
15
+ else if (path.endsWith(".zip")) {
16
16
  const file = await document_model_1.utils.loadFromFile(path);
17
17
  documentModel = file.state.global;
18
18
  }
19
- else if (path.endsWith('.json')) {
20
- const data = fs_1.default.readFileSync(path, 'utf-8');
19
+ else if (path.endsWith(".json")) {
20
+ const data = fs_1.default.readFileSync(path, "utf-8");
21
21
  const document = JSON.parse(data);
22
22
  // z.DocumentModelStateSchema().parse(document);
23
23
  documentModel = document;
24
24
  }
25
25
  else {
26
- throw new Error('File type not supported. Must be zip or json.');
26
+ throw new Error("File type not supported. Must be zip or json.");
27
27
  }
28
28
  return documentModel;
29
29
  }
30
30
  catch (error) {
31
31
  // @ts-expect-error
32
- throw error.code === 'MODULE_NOT_FOUND'
32
+ throw error.code === "MODULE_NOT_FOUND"
33
33
  ? new Error(`Document model not found.`)
34
34
  : error;
35
35
  }
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPackageManager = getPackageManager;
4
- const packageManagers = ['npm', 'yarn', 'pnpm', 'bun'];
5
- const defaultPackageManager = 'npm';
4
+ const packageManagers = ["npm", "yarn", "pnpm", "bun"];
5
+ const defaultPackageManager = "npm";
6
6
  function getPackageManager(userAgent) {
7
7
  if (!userAgent) {
8
8
  return defaultPackageManager;
9
9
  }
10
- const pkgSpec = userAgent.split(' ')[0];
11
- const pkgSpecArr = pkgSpec.split('/');
10
+ const pkgSpec = userAgent.split(" ")[0];
11
+ const pkgSpecArr = pkgSpec.split("/");
12
12
  const name = pkgSpecArr[0];
13
13
  if (packageManagers.includes(name)) {
14
14
  return name;
@@ -20,8 +20,8 @@ function getPackageManager(userAgent) {
20
20
  function pkgFromUserAgent(userAgent) {
21
21
  if (!userAgent)
22
22
  return undefined;
23
- const pkgSpec = userAgent.split(' ')[0];
24
- const pkgSpecArr = pkgSpec.split('/');
23
+ const pkgSpec = userAgent.split(" ")[0];
24
+ const pkgSpecArr = pkgSpec.split("/");
25
25
  return {
26
26
  name: pkgSpecArr[0],
27
27
  version: pkgSpecArr[1],
@@ -10,42 +10,42 @@ const fs_1 = __importDefault(require("fs"));
10
10
  const path_1 = __importDefault(require("path"));
11
11
  const cli_1 = require("../utils/cli");
12
12
  const command_1 = require("./command");
13
- const BOILERPLATE_REPO = 'https://github.com/powerhouse-inc/document-model-boilerplate.git';
13
+ const BOILERPLATE_REPO = "https://github.com/powerhouse-inc/document-model-boilerplate.git";
14
14
  const packageManager = (0, command_1.getPackageManager)(process.env.npm_config_user_agent);
15
- const isNpm = packageManager === 'npm';
15
+ const isNpm = packageManager === "npm";
16
16
  function buildPackageJson(appPath, projectName) {
17
- const packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join(appPath, 'package.json'), 'utf-8'));
17
+ const packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join(appPath, "package.json"), "utf-8"));
18
18
  const newPackage = {
19
19
  ...packageJson,
20
20
  name: projectName,
21
- version: '1.0.0',
22
- description: '',
21
+ version: "1.0.0",
22
+ description: "",
23
23
  };
24
- fs_1.default.writeFileSync(path_1.default.join(appPath, 'package.json'), JSON.stringify(newPackage, null, 2), 'utf8');
24
+ fs_1.default.writeFileSync(path_1.default.join(appPath, "package.json"), JSON.stringify(newPackage, null, 2), "utf8");
25
25
  }
26
26
  function buildPowerhouseConfig(appPath, documentModelsDir, editorsDir) {
27
- const filePath = path_1.default.join(appPath, 'powerhouse.config.json');
28
- const packageJson = JSON.parse(fs_1.default.readFileSync(filePath, 'utf-8'));
27
+ const filePath = path_1.default.join(appPath, "powerhouse.config.json");
28
+ const packageJson = JSON.parse(fs_1.default.readFileSync(filePath, "utf-8"));
29
29
  const newPackage = {
30
30
  ...packageJson,
31
31
  documentModelsDir,
32
32
  editorsDir,
33
33
  };
34
- fs_1.default.writeFileSync(filePath, JSON.stringify(newPackage, null, 2), 'utf8');
34
+ fs_1.default.writeFileSync(filePath, JSON.stringify(newPackage, null, 2), "utf8");
35
35
  }
36
36
  function buildIndex(appPath, documentModelsDir, editorsDir) {
37
- fs_1.default.writeFileSync(path_1.default.join(appPath, 'index.ts'), `import * as documentModelsExports from '${documentModelsDir}';
37
+ fs_1.default.writeFileSync(path_1.default.join(appPath, "index.ts"), `import * as documentModelsExports from '${documentModelsDir}';
38
38
  import * as editorsExports from '${editorsDir}';
39
39
 
40
40
  export const documentModels = Object.values(documentModelsExports);
41
- export const editors = Object.values(editorsExports);`, 'utf8');
41
+ export const editors = Object.values(editorsExports);`, "utf8");
42
42
  }
43
43
  function runCmd(command) {
44
44
  try {
45
- (0, child_process_1.execSync)(command, { stdio: 'inherit' });
45
+ (0, child_process_1.execSync)(command, { stdio: "inherit" });
46
46
  }
47
47
  catch (error) {
48
- console.log('\x1b[31m', error, '\x1b[0m');
48
+ console.log("\x1b[31m", error, "\x1b[0m");
49
49
  }
50
50
  }
51
51
  async function init() {
@@ -55,19 +55,19 @@ async function init() {
55
55
  if (!projectName) {
56
56
  const result = await (0, enquirer_1.prompt)([
57
57
  {
58
- type: 'input',
59
- name: 'projectName',
60
- message: 'What is the project name?',
58
+ type: "input",
59
+ name: "projectName",
60
+ message: "What is the project name?",
61
61
  required: true,
62
62
  },
63
63
  ]);
64
64
  if (!result.projectName) {
65
- console.log('\x1b[31m', 'You have to provide name to your app.');
65
+ console.log("\x1b[31m", "You have to provide name to your app.");
66
66
  process.exit(1);
67
67
  }
68
68
  projectName = result.projectName;
69
69
  }
70
- const { documentModelsDir, editorsDir } = args['--interactive']
70
+ const { documentModelsDir, editorsDir } = args["--interactive"]
71
71
  ? await (0, cli_1.promptDirectories)()
72
72
  : cli_1.DEFAULT_CONFIG;
73
73
  const appPath = path_1.default.join(process.cwd(), projectName);
@@ -75,8 +75,8 @@ async function init() {
75
75
  fs_1.default.mkdirSync(appPath);
76
76
  }
77
77
  catch (err) {
78
- if (err.code === 'EEXIST') {
79
- console.log('\x1b[31m', `The folder ${projectName} already exists in the current directory, please give it another name.`, '\x1b[0m');
78
+ if (err.code === "EEXIST") {
79
+ console.log("\x1b[31m", `The folder ${projectName} already exists in the current directory, please give it another name.`, "\x1b[0m");
80
80
  }
81
81
  else {
82
82
  console.log(err);
@@ -87,33 +87,33 @@ async function init() {
87
87
  }
88
88
  function createProject(projectName, documentModelsDir, editorsDir) {
89
89
  try {
90
- console.log('\x1b[33m', 'Downloading the project structure...', '\x1b[0m');
90
+ console.log("\x1b[33m", "Downloading the project structure...", "\x1b[0m");
91
91
  runCmd(`git clone --depth 1 ${BOILERPLATE_REPO} ${projectName}`);
92
92
  const appPath = path_1.default.join(process.cwd(), projectName);
93
93
  process.chdir(appPath);
94
- console.log('\x1b[34m', 'Installing dependencies...', '\x1b[0m');
94
+ console.log("\x1b[34m", "Installing dependencies...", "\x1b[0m");
95
95
  runCmd(`${packageManager} install`);
96
- fs_1.default.rmSync(path_1.default.join(appPath, './.git'), { recursive: true });
97
- runCmd('git init');
96
+ fs_1.default.rmSync(path_1.default.join(appPath, "./.git"), { recursive: true });
97
+ runCmd("git init");
98
98
  try {
99
99
  fs_1.default.mkdirSync(path_1.default.join(appPath, documentModelsDir));
100
- fs_1.default.writeFileSync(path_1.default.join(appPath, documentModelsDir, 'index.ts'), '');
100
+ fs_1.default.writeFileSync(path_1.default.join(appPath, documentModelsDir, "index.ts"), "");
101
101
  fs_1.default.mkdirSync(path_1.default.join(appPath, editorsDir));
102
- fs_1.default.writeFileSync(path_1.default.join(appPath, editorsDir, 'index.ts'), '');
102
+ fs_1.default.writeFileSync(path_1.default.join(appPath, editorsDir, "index.ts"), "");
103
103
  }
104
104
  catch (error) {
105
- if (!error.message.includes('EEXIST')) {
105
+ if (!error.message.includes("EEXIST")) {
106
106
  throw error;
107
107
  }
108
108
  }
109
109
  buildPackageJson(appPath, projectName);
110
110
  buildPowerhouseConfig(appPath, documentModelsDir, editorsDir);
111
111
  buildIndex(appPath, documentModelsDir, editorsDir);
112
- console.log('\x1b[32m', 'The installation is done!', '\x1b[0m');
112
+ console.log("\x1b[32m", "The installation is done!", "\x1b[0m");
113
113
  console.log();
114
- console.log('\x1b[34m', 'You can start by typing:');
114
+ console.log("\x1b[34m", "You can start by typing:");
115
115
  console.log(` cd ${projectName}`);
116
- console.log(isNpm ? ' npm run generate' : ` ${packageManager} generate`, '\x1b[0m');
116
+ console.log(isNpm ? " npm run generate" : ` ${packageManager} generate`, "\x1b[0m");
117
117
  }
118
118
  catch (error) {
119
119
  console.log(error);
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './codegen';
2
- export * from './utils';
1
+ export * from "./codegen";
2
+ export * from "./utils";
@@ -1,4 +1,4 @@
1
- import arg from 'arg';
1
+ import arg from "arg";
2
2
  export type PowerhouseConfig = {
3
3
  documentModelsDir: string;
4
4
  editorsDir: string;
@@ -8,14 +8,14 @@ export type PowerhouseConfig = {
8
8
  };
9
9
  export declare const DEFAULT_CONFIG: PowerhouseConfig;
10
10
  export declare const configSpec: {
11
- readonly '--document-models': StringConstructor;
12
- readonly '--editors': StringConstructor;
13
- readonly '--interactive': BooleanConstructor;
14
- readonly '--format': BooleanConstructor;
15
- readonly '--watch': BooleanConstructor;
16
- readonly '-i': "--interactive";
17
- readonly '-f': "--format";
18
- readonly '-w': "--watch";
11
+ readonly "--document-models": StringConstructor;
12
+ readonly "--editors": StringConstructor;
13
+ readonly "--interactive": BooleanConstructor;
14
+ readonly "--format": BooleanConstructor;
15
+ readonly "--watch": BooleanConstructor;
16
+ readonly "-i": "--interactive";
17
+ readonly "-f": "--format";
18
+ readonly "-w": "--watch";
19
19
  };
20
20
  export declare function getConfig(): PowerhouseConfig;
21
21
  export declare function writeConfig(config: PowerhouseConfig): void;
package/dist/utils/cli.js CHANGED
@@ -12,36 +12,36 @@ exports.promptDirectories = promptDirectories;
12
12
  const arg_1 = __importDefault(require("arg"));
13
13
  const enquirer_1 = require("enquirer");
14
14
  const node_fs_1 = require("node:fs");
15
- const DEFAULT_DOCUMENT_MODELS_DIR = './document-models';
16
- const DEFAULT_EDITORS_DIR = './editors';
15
+ const DEFAULT_DOCUMENT_MODELS_DIR = "./document-models";
16
+ const DEFAULT_EDITORS_DIR = "./editors";
17
17
  exports.DEFAULT_CONFIG = {
18
18
  documentModelsDir: DEFAULT_DOCUMENT_MODELS_DIR,
19
19
  editorsDir: DEFAULT_EDITORS_DIR,
20
20
  };
21
21
  exports.configSpec = {
22
- '--document-models': String,
23
- '--editors': String,
24
- '--interactive': Boolean,
25
- '--format': Boolean,
26
- '--watch': Boolean,
27
- '-i': '--interactive',
28
- '-f': '--format',
29
- '-w': '--watch',
22
+ "--document-models": String,
23
+ "--editors": String,
24
+ "--interactive": Boolean,
25
+ "--format": Boolean,
26
+ "--watch": Boolean,
27
+ "-i": "--interactive",
28
+ "-f": "--format",
29
+ "-w": "--watch",
30
30
  };
31
31
  function getConfig() {
32
32
  let config = { ...exports.DEFAULT_CONFIG };
33
33
  try {
34
- const configStr = (0, node_fs_1.readFileSync)('./powerhouse.config.json', 'utf-8');
34
+ const configStr = (0, node_fs_1.readFileSync)("./powerhouse.config.json", "utf-8");
35
35
  const userConfig = JSON.parse(configStr);
36
36
  config = { ...config, ...userConfig };
37
37
  }
38
38
  catch {
39
- console.warn('No powerhouse.config.json found, using defaults');
39
+ console.warn("No powerhouse.config.json found, using defaults");
40
40
  }
41
41
  return config;
42
42
  }
43
43
  function writeConfig(config) {
44
- (0, node_fs_1.writeFileSync)('./powerhouse.config.json', JSON.stringify(config, null, 4));
44
+ (0, node_fs_1.writeFileSync)("./powerhouse.config.json", JSON.stringify(config, null, 4));
45
45
  }
46
46
  function parseArgs(argv, spec) {
47
47
  const args = (0, arg_1.default)(spec, {
@@ -53,19 +53,19 @@ function parseArgs(argv, spec) {
53
53
  function parseConfig(argv) {
54
54
  const config = {};
55
55
  const args = parseArgs(argv, exports.configSpec);
56
- if ('--document-models' in args) {
57
- config.documentModelsDir = args['--document-models'];
56
+ if ("--document-models" in args) {
57
+ config.documentModelsDir = args["--document-models"];
58
58
  }
59
- if ('--editors' in args) {
60
- config.editorsDir = args['--editors'];
59
+ if ("--editors" in args) {
60
+ config.editorsDir = args["--editors"];
61
61
  }
62
- if ('--format' in args) {
62
+ if ("--format" in args) {
63
63
  config.format = true;
64
64
  }
65
- if ('--interactive' in args) {
65
+ if ("--interactive" in args) {
66
66
  config.interactive = true;
67
67
  }
68
- if ('--watch' in args) {
68
+ if ("--watch" in args) {
69
69
  config.watch = true;
70
70
  }
71
71
  return config;
@@ -73,15 +73,15 @@ function parseConfig(argv) {
73
73
  async function promptDirectories(config = exports.DEFAULT_CONFIG) {
74
74
  return (0, enquirer_1.prompt)([
75
75
  {
76
- type: 'input',
77
- name: 'documentModelsDir',
78
- message: 'Where to place the Document Models?',
76
+ type: "input",
77
+ name: "documentModelsDir",
78
+ message: "Where to place the Document Models?",
79
79
  initial: config.documentModelsDir,
80
80
  },
81
81
  {
82
- type: 'input',
83
- name: 'editorsDir',
84
- message: 'Where to place the Editors?',
82
+ type: "input",
83
+ name: "editorsDir",
84
+ message: "Where to place the Editors?",
85
85
  initial: config.editorsDir,
86
86
  },
87
87
  ]);
@@ -1,2 +1,2 @@
1
- export * from './cli';
2
- export * from './mock';
1
+ export * from "./cli";
2
+ export * from "./mock";
@@ -1,3 +1,3 @@
1
- import { generateMock as zodGenerateMock } from '@anatine/zod-mock';
1
+ import { generateMock as zodGenerateMock } from "@anatine/zod-mock";
2
2
  export type generateMockTypeFn = typeof zodGenerateMock;
3
3
  export declare const generateMock: generateMockTypeFn;
package/package.json CHANGED
@@ -1,54 +1,53 @@
1
1
  {
2
- "name": "@powerhousedao/codegen",
3
- "version": "0.3.2",
4
- "license": "AGPL-3.0-only",
5
- "private": false,
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "bin": {
9
- "powerhouse": "./dist/cli.js",
10
- "create-document-model-lib": "./dist/create-lib/index.js"
11
- },
12
- "files": [
13
- "/dist"
14
- ],
15
- "scripts": {
16
- "clean": "rimraf dist/",
17
- "copy-files": "copyfiles -u 1 src/codegen/.hygen/templates/**/*.esm.t dist/",
18
- "build": "yarn clean && tsc && yarn copy-files",
19
- "prepublishOnly": "yarn build",
20
- "build:create-lib": "tsc --project src/create-lib/tsconfig.json",
21
- "publish:create-lib": "yarn publish --cwd ./src/create-lib/",
22
- "start": "ts-node src/cli.ts",
23
- "check-types": "tsc --noEmit",
24
- "lint": "eslint . && yarn check-types",
25
- "lint:fix": "eslint . --fix",
26
- "clean:node_modules": "rimraf node_modules"
27
- },
28
- "dependencies": {
29
- "@acaldas/graphql-codegen-typescript-validation-schema": "^0.12.3",
30
- "@anatine/zod-mock": "^3.13.3",
31
- "@faker-js/faker": "^8.3.1",
32
- "@graphql-codegen/cli": "^5.0.0",
33
- "@graphql-codegen/typescript": "^4.0.1",
34
- "@types/node": "^20.11.2",
35
- "arg": "^5.0.2",
36
- "change-case": "^4.1.2",
37
- "document-model": "1.0.29",
38
- "enquirer": "^2.4.1",
39
- "execa": "^8.0.1",
40
- "hygen": "^6.2.11",
41
- "typescript": "^5.3.3"
42
- },
43
- "devDependencies": {
44
- "@total-typescript/ts-reset": "^0.5.1",
45
- "copyfiles": "^2.4.1",
46
- "graphql": "^16.8.1",
47
- "husky": "^8.0.3",
48
- "rimraf": "^5.0.5",
49
- "ts-node": "^10.9.2"
50
- },
51
- "peerDependencies": {
52
- "graphql": "^16.8.1"
53
- }
54
- }
2
+ "name": "@powerhousedao/codegen",
3
+ "version": "0.5.0",
4
+ "license": "AGPL-3.0-only",
5
+ "private": false,
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "powerhouse": "./dist/cli.js",
10
+ "create-document-model-lib": "./dist/create-lib/index.js"
11
+ },
12
+ "files": [
13
+ "/dist"
14
+ ],
15
+ "dependencies": {
16
+ "@acaldas/graphql-codegen-typescript-validation-schema": "^0.12.3",
17
+ "@anatine/zod-mock": "^3.13.3",
18
+ "@faker-js/faker": "^8.3.1",
19
+ "@graphql-codegen/cli": "^5.0.0",
20
+ "@graphql-codegen/typescript": "^4.0.1",
21
+ "@types/node": "^20.11.2",
22
+ "arg": "^5.0.2",
23
+ "change-case": "^4.1.2",
24
+ "document-model": "1.0.29",
25
+ "enquirer": "^2.4.1",
26
+ "execa": "^8.0.1",
27
+ "hygen": "^6.2.11"
28
+ },
29
+ "devDependencies": {
30
+ "copyfiles": "^2.4.1",
31
+ "graphql": "^16.8.1",
32
+ "husky": "^8.0.3",
33
+ "rimraf": "^5.0.5",
34
+ "ts-node": "^10.9.2"
35
+ },
36
+ "peerDependencies": {
37
+ "graphql": "^16.8.1"
38
+ },
39
+ "scripts": {
40
+ "check-types": "tsc --noEmit",
41
+ "postlint": "npm run check-types",
42
+ "lint": "eslint",
43
+ "clean": "rimraf dist/",
44
+ "copy-files": "copyfiles -u 1 src/codegen/.hygen/templates/**/*.esm.t dist/",
45
+ "prebuild": "npm run clean",
46
+ "build": "tsc",
47
+ "postbuild": "npm run copy-files",
48
+ "build:create-lib": "tsc --project src/create-lib/tsconfig.json",
49
+ "publish:create-lib": "npm publish --cwd ./src/create-lib/",
50
+ "start": "ts-node src/cli.ts",
51
+ "clean:node_modules": "rimraf node_modules"
52
+ }
53
+ }
package/CHANGELOG.md DELETED
@@ -1,25 +0,0 @@
1
- ## 0.2.0 (2024-10-08)
2
-
3
-
4
- ### 🚀 Features
5
-
6
- - **codegen:** added support for local state on editor codegen ([14c84bde](https://github.com/powerhouse-inc/powerhouse/commit/14c84bde))
7
-
8
- - **codegen:** fixed editor folder name ([ae0e6e2c](https://github.com/powerhouse-inc/powerhouse/commit/ae0e6e2c))
9
-
10
-
11
- ### ❤️ Thank You
12
-
13
- - acaldas @acaldas
14
- -
15
- ## 0.1.0 (2024-09-26)
16
-
17
-
18
- ### 🚀 Features
19
-
20
- - **codegen:** initial codegen package setup ([0f67da6](https://github.com/powerhouse-inc/powerhouse/commit/0f67da6))
21
-
22
-
23
- ### ❤️ Thank You
24
-
25
- - Guillermo Puente @gpuente