@powerhousedao/codegen 0.1.0 → 0.2.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 +11 -0
- package/dist/codegen/.hygen/templates/powerhouse/generate-editor/editor.esm.t +4 -5
- package/dist/codegen/.hygen/templates/powerhouse/generate-editor/index.esm.t +3 -3
- package/dist/codegen/graphql.js +0 -3
- package/dist/codegen/hygen.js +5 -4
- package/dist/create-lib/command.d.ts +4 -0
- package/dist/create-lib/command.js +29 -0
- package/dist/create-lib/index.js +14 -21
- package/dist/{utils.d.ts → utils/cli.d.ts} +0 -3
- package/dist/{utils.js → utils/cli.js} +1 -6
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/mock.d.ts +3 -0
- package/dist/utils/mock.js +8 -0
- package/package.json +3 -6
package/CHANGELOG.md
ADDED
|
@@ -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
|
};
|
package/dist/codegen/graphql.js
CHANGED
|
@@ -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',
|
package/dist/codegen/hygen.js
CHANGED
|
@@ -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
|
-
|
|
33
|
+
const actions = result.actions;
|
|
34
|
+
actions
|
|
35
35
|
.filter(action => ['added', 'inject'].includes(action.status))
|
|
36
36
|
.forEach(action => {
|
|
37
|
-
|
|
38
|
-
|
|
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,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
|
+
}
|
package/dist/create-lib/index.js
CHANGED
|
@@ -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
|
|
12
|
-
const
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
43
|
+
function runCmd(command) {
|
|
46
44
|
try {
|
|
47
|
-
|
|
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,
|
|
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,
|
|
76
|
-
:
|
|
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,18 +85,16 @@ async function init() {
|
|
|
89
85
|
}
|
|
90
86
|
createProject(projectName, documentModelsDir, editorsDir);
|
|
91
87
|
}
|
|
92
|
-
|
|
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
|
-
|
|
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
|
-
|
|
101
|
-
console.log();
|
|
95
|
+
runCmd(`${packageManager} install`);
|
|
102
96
|
fs_1.default.rmSync(path_1.default.join(appPath, './.git'), { recursive: true });
|
|
103
|
-
|
|
97
|
+
runCmd('git init');
|
|
104
98
|
try {
|
|
105
99
|
fs_1.default.mkdirSync(path_1.default.join(appPath, documentModelsDir));
|
|
106
100
|
fs_1.default.mkdirSync(path_1.default.join(appPath, editorsDir));
|
|
@@ -117,8 +111,7 @@ async function createProject(projectName, documentModelsDir, editorsDir) {
|
|
|
117
111
|
console.log();
|
|
118
112
|
console.log('\x1b[34m', 'You can start by typing:');
|
|
119
113
|
console.log(` cd ${projectName}`);
|
|
120
|
-
console.log(
|
|
121
|
-
console.log();
|
|
114
|
+
console.log(isNpm ? ' npm run generate' : ` ${packageManager} generate`, '\x1b[0m');
|
|
122
115
|
}
|
|
123
116
|
catch (error) {
|
|
124
117
|
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.
|
|
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,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,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.
|
|
3
|
+
"version": "0.2.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
|
}
|