@powerhousedao/codegen 0.1.0 → 0.3.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/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
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
@@ -1,14 +1,13 @@
1
1
  ---
2
- to: "<%= rootDir %>/<%= name %>/editor.tsx"
2
+ to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/editor.tsx"
3
3
  unless_exists: true
4
4
  ---
5
- <% if(!documentTypes.length){ %>import { Action } from 'document-model/document';<% } %>
6
- import { EditorProps } from 'document-model-libs/utils';
5
+ <% if(!documentTypes.length){ %>import { Action, EditorProps } from 'document-model/document';<% } else { %>import { EditorProps } from 'document-model/document';<% } %>
7
6
  <% documentTypes.forEach(type => { _%>
8
- import { <%= documentTypesMap[type] %>State, <%= documentTypesMap[type] %>Action } from "../.<%= documentModelsDir %>/<%= h.changeCase.param(documentTypesMap[type]) %>";
7
+ import { <%= documentTypesMap[type] %>State, <%= documentTypesMap[type] %>Action, <%= documentTypesMap[type] %>LocalState } from "../.<%= documentModelsDir %>/<%= h.changeCase.param(documentTypesMap[type]) %>";
9
8
  %><% }); _%>
10
9
 
11
- export type IProps = <% if(!documentTypes.length){ %>EditorProps<unknown, Action><% } else { %><% documentTypes.forEach((type, index) => { _%>EditorProps<<%= documentTypesMap[type] %>State, <%= documentTypesMap[type] %>Action%>%>><% if(index < documentTypes.length - 1){ %> | <% }%><% }); _%> <% } %>;
10
+ export type IProps = <% if(!documentTypes.length){ %>EditorProps<unknown, Action><% } else { %><% documentTypes.forEach((type, index) => { _%>EditorProps<<%= documentTypesMap[type] %>State, <%= documentTypesMap[type] %>Action, <%= documentTypesMap[type] %>LocalState%>%>><% if(index < documentTypes.length - 1){ %> | <% }%><% }); _%> <% } %>;
12
11
 
13
12
  export default function Editor(props: IProps) {
14
13
  return <></>;
@@ -1,14 +1,14 @@
1
1
  ---
2
- to: "<%= rootDir %>/<%= name %>/index.ts"
2
+ to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/index.ts"
3
3
  force: true
4
4
  ---
5
5
  import { type Editor as EditorModule<% if(!documentTypes.length){ %>, Action<% } %> } from 'document-model/document';
6
6
  import Editor from './editor';
7
7
  <% documentTypes.forEach(type => { _%>
8
- import { <%= documentTypesMap[type] %>State, <%= documentTypesMap[type] %>Action } from "../.<%= documentModelsDir %>/<%= h.changeCase.param(documentTypesMap[type]) %>";
8
+ import { <%= documentTypesMap[type] %>State, <%= documentTypesMap[type] %>Action, <%= documentTypesMap[type] %>LocalState } from "../.<%= documentModelsDir %>/<%= h.changeCase.param(documentTypesMap[type]) %>";
9
9
  %><% }); _%>
10
10
 
11
- export const module: <% if(!documentTypes.length){ %>EditorModule<unknown, Action><% } else { %><% documentTypes.forEach((type, index) => { _%>EditorModule<<%= documentTypesMap[type] %>State, <%= documentTypesMap[type] %>Action%>%>> <% if(index < documentTypes.length - 1){ %>| <% }%><% }); _%> <% } %>= {
11
+ export const module: <% if(!documentTypes.length){ %>EditorModule<unknown, Action><% } else { %><% documentTypes.forEach((type, index) => { _%>EditorModule<<%= documentTypesMap[type] %>State, <%= documentTypesMap[type] %>Action, <%= documentTypesMap[type] %>LocalState%>%>> <% if(index < documentTypes.length - 1){ %>| <% }%><% }); _%> <% } %>= {
12
12
  Component: Editor,
13
13
  documentTypes: [<% if(!documentTypes.length){ %>'*'<% } else { %><% documentTypes.forEach(type => { _%>"<%= type %>", %><% }); _%> <% } %>],
14
14
  };
@@ -1,5 +1,5 @@
1
1
  ---
2
- to: "<%= rootDir %>/<%= name %>/<%= name %>.stories.tsx"
2
+ to: "<%= rootDir %>/<%= h.changeCase.param(name) %>/<%= <%= h.changeCase.param(name) %> %>.stories.tsx"
3
3
  unless_exists: true
4
4
  ---
5
5
  import Editor from './editor';
@@ -7,7 +7,6 @@ const getDirectories = (source) => (0, fs_1.readdirSync)(source, { withFileTypes
7
7
  .filter(dirent => dirent.isDirectory())
8
8
  .map(dirent => dirent.name);
9
9
  const tsConfig = {
10
- strict: true,
11
10
  strictScalars: true,
12
11
  scalars: {
13
12
  Unknown: 'unknown',
@@ -20,8 +19,6 @@ const tsConfig = {
20
19
  avoidOptionals: {
21
20
  field: true,
22
21
  },
23
- useIndexSignature: true,
24
- noSchemaStitching: true,
25
22
  skipTypename: true,
26
23
  // maybeValue: "T | null | undefined",
27
24
  inputMaybeValue: 'T | null | undefined',
@@ -30,12 +30,13 @@ async function run(args, { watch = false, format = false } = {}) {
30
30
  });
31
31
  if (format) {
32
32
  const execa = await import('execa');
33
- result.actions
34
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
33
+ const actions = result.actions;
34
+ actions
35
35
  .filter(action => ['added', 'inject'].includes(action.status))
36
36
  .forEach(action => {
37
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
38
- execa.$ `prettier --ignore-path --write ${action.subject.replace('.', process.cwd())}`;
37
+ execa.$ `prettier --ignore-path --write ${action.subject.replace('.', process.cwd())}`.catch((err) => {
38
+ console.log(err);
39
+ });
39
40
  });
40
41
  }
41
42
  return result;
@@ -0,0 +1,4 @@
1
+ declare const packageManagers: readonly ["npm", "yarn", "pnpm", "bun"];
2
+ export type PackageManager = (typeof packageManagers)[number];
3
+ export declare function getPackageManager(userAgent?: string): PackageManager;
4
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPackageManager = getPackageManager;
4
+ const packageManagers = ['npm', 'yarn', 'pnpm', 'bun'];
5
+ const defaultPackageManager = 'npm';
6
+ function getPackageManager(userAgent) {
7
+ if (!userAgent) {
8
+ return defaultPackageManager;
9
+ }
10
+ const pkgSpec = userAgent.split(' ')[0];
11
+ const pkgSpecArr = pkgSpec.split('/');
12
+ const name = pkgSpecArr[0];
13
+ if (packageManagers.includes(name)) {
14
+ return name;
15
+ }
16
+ else {
17
+ return defaultPackageManager;
18
+ }
19
+ }
20
+ function pkgFromUserAgent(userAgent) {
21
+ if (!userAgent)
22
+ return undefined;
23
+ const pkgSpec = userAgent.split(' ')[0];
24
+ const pkgSpecArr = pkgSpec.split('/');
25
+ return {
26
+ name: pkgSpecArr[0],
27
+ version: pkgSpecArr[1],
28
+ };
29
+ }
@@ -8,13 +8,11 @@ const child_process_1 = require("child_process");
8
8
  const enquirer_1 = require("enquirer");
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const path_1 = __importDefault(require("path"));
11
- const util_1 = __importDefault(require("util"));
12
- const utils_1 = require("../utils");
13
- const exec = util_1.default.promisify(child_process_1.exec);
11
+ const cli_1 = require("../utils/cli");
12
+ const command_1 = require("./command");
14
13
  const BOILERPLATE_REPO = 'https://github.com/powerhouse-inc/document-model-boilerplate.git';
15
- function isUsingYarn() {
16
- return (process.env.npm_config_user_agent || '').startsWith('yarn');
17
- }
14
+ const packageManager = (0, command_1.getPackageManager)(process.env.npm_config_user_agent);
15
+ const isNpm = packageManager === 'npm';
18
16
  function buildPackageJson(appPath, projectName) {
19
17
  const packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join(appPath, 'package.json'), 'utf-8'));
20
18
  const newPackage = {
@@ -42,18 +40,16 @@ function buildIndex(appPath, documentModelsDir, editorsDir) {
42
40
  export const documentModels = Object.values(documentModelsExports);
43
41
  export const editors = Object.values(editorsExports);`, 'utf8');
44
42
  }
45
- async function runCmd(command) {
43
+ function runCmd(command) {
46
44
  try {
47
- const { stdout, stderr } = await exec(command);
48
- console.log(stdout);
49
- console.log(stderr);
45
+ (0, child_process_1.execSync)(command, { stdio: 'inherit' });
50
46
  }
51
47
  catch (error) {
52
48
  console.log('\x1b[31m', error, '\x1b[0m');
53
49
  }
54
50
  }
55
51
  async function init() {
56
- const args = (0, utils_1.parseArgs)(process.argv.slice(2), utils_1.configSpec);
52
+ const args = (0, cli_1.parseArgs)(process.argv.slice(2), cli_1.configSpec);
57
53
  // checks if a project name was provided
58
54
  let projectName = args._.shift();
59
55
  if (!projectName) {
@@ -72,8 +68,8 @@ async function init() {
72
68
  projectName = result.projectName;
73
69
  }
74
70
  const { documentModelsDir, editorsDir } = args['--interactive']
75
- ? await (0, utils_1.promptDirectories)()
76
- : utils_1.DEFAULT_CONFIG;
71
+ ? await (0, cli_1.promptDirectories)()
72
+ : cli_1.DEFAULT_CONFIG;
77
73
  const appPath = path_1.default.join(process.cwd(), projectName);
78
74
  try {
79
75
  fs_1.default.mkdirSync(appPath);
@@ -89,21 +85,21 @@ async function init() {
89
85
  }
90
86
  createProject(projectName, documentModelsDir, editorsDir);
91
87
  }
92
- async function createProject(projectName, documentModelsDir, editorsDir) {
88
+ function createProject(projectName, documentModelsDir, editorsDir) {
93
89
  try {
94
- const useYarn = isUsingYarn();
95
90
  console.log('\x1b[33m', 'Downloading the project structure...', '\x1b[0m');
96
- await runCmd(`git clone --depth 1 ${BOILERPLATE_REPO} ${projectName}`);
91
+ runCmd(`git clone --depth 1 ${BOILERPLATE_REPO} ${projectName}`);
97
92
  const appPath = path_1.default.join(process.cwd(), projectName);
98
93
  process.chdir(appPath);
99
94
  console.log('\x1b[34m', 'Installing dependencies...', '\x1b[0m');
100
- await runCmd(useYarn ? 'yarn install' : 'npm install');
101
- console.log();
95
+ runCmd(`${packageManager} install`);
102
96
  fs_1.default.rmSync(path_1.default.join(appPath, './.git'), { recursive: true });
103
- await runCmd('git init');
97
+ runCmd('git init');
104
98
  try {
105
99
  fs_1.default.mkdirSync(path_1.default.join(appPath, documentModelsDir));
100
+ fs_1.default.mkdirSync(path_1.default.join(appPath, documentModelsDir, 'index.ts'));
106
101
  fs_1.default.mkdirSync(path_1.default.join(appPath, editorsDir));
102
+ fs_1.default.mkdirSync(path_1.default.join(appPath, editorsDir, 'index.ts'));
107
103
  }
108
104
  catch (error) {
109
105
  if (!error.message.includes('EEXIST')) {
@@ -117,8 +113,7 @@ async function createProject(projectName, documentModelsDir, editorsDir) {
117
113
  console.log();
118
114
  console.log('\x1b[34m', 'You can start by typing:');
119
115
  console.log(` cd ${projectName}`);
120
- console.log(useYarn ? ' yarn generate' : ' npm run generate', '\x1b[0m');
121
- console.log();
116
+ console.log(isNpm ? ' npm run generate' : ` ${packageManager} generate`, '\x1b[0m');
122
117
  }
123
118
  catch (error) {
124
119
  console.log(error);
@@ -1,4 +1,3 @@
1
- import { generateMock as zodGenerateMock } from '@anatine/zod-mock';
2
1
  import arg from 'arg';
3
2
  export type PowerhouseConfig = {
4
3
  documentModelsDir: string;
@@ -23,5 +22,3 @@ export declare function writeConfig(config: PowerhouseConfig): void;
23
22
  export declare function parseArgs<T extends arg.Spec>(argv: string[], spec: T): arg.Result<T>;
24
23
  export declare function parseConfig(argv: string[]): Partial<PowerhouseConfig>;
25
24
  export declare function promptDirectories(config?: PowerhouseConfig): Promise<Pick<PowerhouseConfig, "documentModelsDir" | "editorsDir">>;
26
- export type generateMockTypeFn = typeof zodGenerateMock;
27
- export declare const generateMock: generateMockTypeFn;
@@ -3,13 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generateMock = exports.configSpec = exports.DEFAULT_CONFIG = void 0;
6
+ exports.configSpec = exports.DEFAULT_CONFIG = void 0;
7
7
  exports.getConfig = getConfig;
8
8
  exports.writeConfig = writeConfig;
9
9
  exports.parseArgs = parseArgs;
10
10
  exports.parseConfig = parseConfig;
11
11
  exports.promptDirectories = promptDirectories;
12
- const zod_mock_1 = require("@anatine/zod-mock");
13
12
  const arg_1 = __importDefault(require("arg"));
14
13
  const enquirer_1 = require("enquirer");
15
14
  const node_fs_1 = require("node:fs");
@@ -87,7 +86,3 @@ async function promptDirectories(config = exports.DEFAULT_CONFIG) {
87
86
  },
88
87
  ]);
89
88
  }
90
- const generateMock = (zodRef, options) => {
91
- return (0, zod_mock_1.generateMock)(zodRef, options);
92
- };
93
- exports.generateMock = generateMock;
@@ -0,0 +1,2 @@
1
+ export * from './cli';
2
+ export * from './mock';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./cli"), exports);
18
+ __exportStar(require("./mock"), exports);
@@ -0,0 +1,3 @@
1
+ import { generateMock as zodGenerateMock } from '@anatine/zod-mock';
2
+ export type generateMockTypeFn = typeof zodGenerateMock;
3
+ export declare const generateMock: generateMockTypeFn;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateMock = void 0;
4
+ const zod_mock_1 = require("@anatine/zod-mock");
5
+ const generateMock = (zodRef, options) => {
6
+ return (0, zod_mock_1.generateMock)(zodRef, options);
7
+ };
8
+ exports.generateMock = generateMock;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/codegen",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -22,7 +22,8 @@
22
22
  "start": "ts-node src/cli.ts",
23
23
  "check-types": "tsc --noEmit",
24
24
  "lint": "eslint . && yarn check-types",
25
- "lint:fix": "eslint . --fix"
25
+ "lint:fix": "eslint . --fix",
26
+ "clean:node_modules": "rimraf node_modules"
26
27
  },
27
28
  "dependencies": {
28
29
  "@acaldas/graphql-codegen-typescript-validation-schema": "^0.12.3",
@@ -49,9 +50,5 @@
49
50
  },
50
51
  "peerDependencies": {
51
52
  "graphql": "^16.8.1"
52
- },
53
- "resolutions": {
54
- "string-width": "4.2.3",
55
- "strip-ansi": "6.0.0"
56
53
  }
57
54
  }