@powerhousedao/codegen 0.3.1 → 0.4.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/codegen/.hygen/templates/powerhouse/generate-editor/story.esm.t +1 -1
- package/package.json +50 -53
- package/CHANGELOG.md +0 -25
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -40
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/index.d.ts +0 -27
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model/index.js +0 -62
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts +0 -23
- package/dist/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js +0 -25
- package/dist/codegen/.hygen/templates/powerhouse/generate-editor/index.d.ts +0 -19
- package/dist/codegen/.hygen/templates/powerhouse/generate-editor/index.js +0 -15
- package/dist/codegen/graphql.d.ts +0 -8
- package/dist/codegen/graphql.js +0 -91
- package/dist/codegen/hygen.d.ts +0 -12
- package/dist/codegen/hygen.js +0 -101
- package/dist/codegen/index.d.ts +0 -5
- package/dist/codegen/index.js +0 -87
- package/dist/codegen/utils.d.ts +0 -2
- package/dist/codegen/utils.js +0 -36
- package/dist/create-lib/command.d.ts +0 -4
- package/dist/create-lib/command.js +0 -29
- package/dist/create-lib/index.d.ts +0 -2
- package/dist/create-lib/index.js +0 -122
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -18
- package/dist/utils/cli.d.ts +0 -24
- package/dist/utils/cli.js +0 -88
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/mock.d.ts +0 -3
- package/dist/utils/mock.js +0 -8
package/package.json
CHANGED
|
@@ -1,54 +1,51 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"graphql": "^16.8.1"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
2
|
+
"name": "@powerhousedao/codegen",
|
|
3
|
+
"version": "0.4.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
|
+
"build": "npm run clean && npm run copy-files",
|
|
46
|
+
"build:create-lib": "tsc --project src/create-lib/tsconfig.json",
|
|
47
|
+
"publish:create-lib": "yarn publish --cwd ./src/create-lib/",
|
|
48
|
+
"start": "ts-node src/cli.ts",
|
|
49
|
+
"clean:node_modules": "rimraf node_modules"
|
|
50
|
+
}
|
|
51
|
+
}
|
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
|
package/dist/cli.d.ts
DELETED
package/dist/cli.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const index_1 = require("./codegen/index");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
async function parseCommand(argv) {
|
|
7
|
-
const args = (0, utils_1.parseArgs)(argv, {
|
|
8
|
-
'--editor': String,
|
|
9
|
-
'-e': '--editor',
|
|
10
|
-
'--document-types': String,
|
|
11
|
-
});
|
|
12
|
-
const editorName = args['--editor'];
|
|
13
|
-
return {
|
|
14
|
-
editor: !!editorName,
|
|
15
|
-
editorName,
|
|
16
|
-
documentTypes: args['--document-types'],
|
|
17
|
-
arg: args._,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
async function main() {
|
|
21
|
-
const argv = process.argv.slice(2);
|
|
22
|
-
const baseConfig = (0, utils_1.getConfig)();
|
|
23
|
-
const argsConfig = (0, utils_1.parseConfig)(argv);
|
|
24
|
-
const config = { ...baseConfig, ...argsConfig };
|
|
25
|
-
if (config.interactive) {
|
|
26
|
-
const result = await (0, utils_1.promptDirectories)(config);
|
|
27
|
-
Object.assign(config, result);
|
|
28
|
-
}
|
|
29
|
-
const command = await parseCommand(argv);
|
|
30
|
-
if (command.editor) {
|
|
31
|
-
await (0, index_1.generateEditor)(command.editorName, command.documentTypes?.split(/[|,;]/g) ?? [], config);
|
|
32
|
-
}
|
|
33
|
-
else if (command.arg.length === 2) {
|
|
34
|
-
await (0, index_1.generateFromFile)(command.arg[1], config);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
await (0, index_1.generate)(config);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
main();
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export type Args = {
|
|
2
|
-
documentModel: string;
|
|
3
|
-
rootDir: string;
|
|
4
|
-
};
|
|
5
|
-
declare const _default: {
|
|
6
|
-
params: ({ args }: {
|
|
7
|
-
args: Args;
|
|
8
|
-
}) => {
|
|
9
|
-
initialGlobalState: string;
|
|
10
|
-
initialLocalState: string;
|
|
11
|
-
rootDir: string;
|
|
12
|
-
documentModel: string;
|
|
13
|
-
documentTypeId: string;
|
|
14
|
-
documentType: string;
|
|
15
|
-
extension: string;
|
|
16
|
-
modules: {
|
|
17
|
-
name: string;
|
|
18
|
-
__typename?: "Module";
|
|
19
|
-
description: import("document-model/document-model").Maybe<import("document-model/document-model").Scalars["String"]["output"]>;
|
|
20
|
-
id: import("document-model/document-model").Scalars["ID"]["output"];
|
|
21
|
-
operations: Array<import("document-model/document-model").Operation>;
|
|
22
|
-
}[];
|
|
23
|
-
fileExtension: string;
|
|
24
|
-
hasLocalSchema: boolean;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
export default _default;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const change_case_1 = require("change-case");
|
|
4
|
-
function documentModelToString(documentModel) {
|
|
5
|
-
return JSON.stringify({
|
|
6
|
-
...documentModel,
|
|
7
|
-
specifications: documentModel.specifications.map(s => ({
|
|
8
|
-
...s,
|
|
9
|
-
state: Object.keys(s.state).reduce((values, scope) => {
|
|
10
|
-
const state = s.state[scope];
|
|
11
|
-
return {
|
|
12
|
-
...values,
|
|
13
|
-
[scope]: {
|
|
14
|
-
...state,
|
|
15
|
-
// initial value has to be stringified twice
|
|
16
|
-
// as it is expected to be a string
|
|
17
|
-
initialValue: JSON.stringify(state.initialValue),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
}, {}),
|
|
21
|
-
})),
|
|
22
|
-
}, null, 4);
|
|
23
|
-
}
|
|
24
|
-
exports.default = {
|
|
25
|
-
params: ({ args }) => {
|
|
26
|
-
const documentModel = JSON.parse(args.documentModel);
|
|
27
|
-
const latestSpec = documentModel.specifications[documentModel.specifications.length - 1];
|
|
28
|
-
return {
|
|
29
|
-
rootDir: args.rootDir,
|
|
30
|
-
documentModel: documentModelToString(documentModel),
|
|
31
|
-
documentTypeId: documentModel.id,
|
|
32
|
-
documentType: documentModel.name,
|
|
33
|
-
extension: documentModel.extension,
|
|
34
|
-
modules: latestSpec.modules.map(m => ({
|
|
35
|
-
...m,
|
|
36
|
-
name: (0, change_case_1.paramCase)(m.name),
|
|
37
|
-
})),
|
|
38
|
-
fileExtension: documentModel.extension,
|
|
39
|
-
hasLocalSchema: latestSpec.state.local.schema !== '',
|
|
40
|
-
...getInitialStates(latestSpec.state),
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
function getInitialStates(scopeState) {
|
|
45
|
-
const { global, local } = scopeState;
|
|
46
|
-
const scopes = { global, local };
|
|
47
|
-
Object.entries(scopes).forEach(([scope, state]) => {
|
|
48
|
-
if (!isEmptyStateSchema(state.schema) && state.initialValue === '') {
|
|
49
|
-
throw new Error(`${scope.charAt(0).toLocaleUpperCase() + scope.slice(1)} scope has a defined schema but is missing an initial value.`);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return {
|
|
53
|
-
initialGlobalState: handleEmptyState(global.initialValue),
|
|
54
|
-
initialLocalState: handleEmptyState(local.initialValue),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function isEmptyStateSchema(schema) {
|
|
58
|
-
return schema === '' || !schema.includes('{');
|
|
59
|
-
}
|
|
60
|
-
function handleEmptyState(state) {
|
|
61
|
-
return state === '' ? '{}' : state;
|
|
62
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Maybe, OperationScope } from 'document-model/document';
|
|
2
|
-
import { Args } from '../generate-document-model';
|
|
3
|
-
type ModuleArgs = Args & {
|
|
4
|
-
module: string;
|
|
5
|
-
};
|
|
6
|
-
type Actions = {
|
|
7
|
-
name: Maybe<string>;
|
|
8
|
-
hasInput: boolean;
|
|
9
|
-
hasAttachment: boolean | undefined;
|
|
10
|
-
scope: OperationScope;
|
|
11
|
-
state: string;
|
|
12
|
-
};
|
|
13
|
-
declare const _default: {
|
|
14
|
-
params: ({ args }: {
|
|
15
|
-
args: ModuleArgs;
|
|
16
|
-
}) => {
|
|
17
|
-
rootDir: string;
|
|
18
|
-
documentType: string;
|
|
19
|
-
module: string;
|
|
20
|
-
actions: Actions[];
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
export default _default;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const change_case_1 = require("change-case");
|
|
4
|
-
exports.default = {
|
|
5
|
-
params: ({ args }) => {
|
|
6
|
-
const documentModel = JSON.parse(args.documentModel);
|
|
7
|
-
const latestSpec = documentModel.specifications[documentModel.specifications.length - 1];
|
|
8
|
-
const filteredModules = latestSpec.modules.filter(m => m.name === args.module);
|
|
9
|
-
const actions = filteredModules.length > 0
|
|
10
|
-
? filteredModules[0].operations.map(a => ({
|
|
11
|
-
name: a.name,
|
|
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
|
|
16
|
-
}))
|
|
17
|
-
: [];
|
|
18
|
-
return {
|
|
19
|
-
rootDir: args.rootDir,
|
|
20
|
-
documentType: documentModel.name,
|
|
21
|
-
module: (0, change_case_1.paramCase)(args.module),
|
|
22
|
-
actions,
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export type Args = {
|
|
2
|
-
name: string;
|
|
3
|
-
rootDir: string;
|
|
4
|
-
documentModelsDir: string;
|
|
5
|
-
documentTypes: string;
|
|
6
|
-
documentTypesMap: string;
|
|
7
|
-
};
|
|
8
|
-
declare const _default: {
|
|
9
|
-
params: ({ args }: {
|
|
10
|
-
args: Args;
|
|
11
|
-
}) => {
|
|
12
|
-
rootDir: string;
|
|
13
|
-
documentModelsDir: string;
|
|
14
|
-
name: string;
|
|
15
|
-
documentTypes: string[];
|
|
16
|
-
documentTypesMap: unknown;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export default _default;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = {
|
|
4
|
-
params: ({ args }) => {
|
|
5
|
-
return {
|
|
6
|
-
rootDir: args.rootDir,
|
|
7
|
-
documentModelsDir: args.documentModelsDir,
|
|
8
|
-
name: args.name,
|
|
9
|
-
documentTypes: args.documentTypes
|
|
10
|
-
.split(',')
|
|
11
|
-
.filter(type => type !== ''),
|
|
12
|
-
documentTypesMap: JSON.parse(args.documentTypesMap),
|
|
13
|
-
};
|
|
14
|
-
},
|
|
15
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare const generateSchema: (model: string, dir: string, { watch, format }?: {
|
|
2
|
-
watch?: boolean | undefined;
|
|
3
|
-
format?: boolean | undefined;
|
|
4
|
-
}) => Promise<any>;
|
|
5
|
-
export declare const generateSchemas: (dir: string, { watch, format }?: {
|
|
6
|
-
watch?: boolean | undefined;
|
|
7
|
-
format?: boolean | undefined;
|
|
8
|
-
}) => Promise<any>;
|
package/dist/codegen/graphql.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateSchemas = exports.generateSchema = void 0;
|
|
4
|
-
const cli_1 = require("@graphql-codegen/cli");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const getDirectories = (source) => (0, fs_1.readdirSync)(source, { withFileTypes: true })
|
|
7
|
-
.filter(dirent => dirent.isDirectory())
|
|
8
|
-
.map(dirent => dirent.name);
|
|
9
|
-
const tsConfig = {
|
|
10
|
-
strictScalars: true,
|
|
11
|
-
scalars: {
|
|
12
|
-
Unknown: 'unknown',
|
|
13
|
-
DateTime: 'string',
|
|
14
|
-
Attachment: 'string',
|
|
15
|
-
Address: '`${string}:0x${string}`',
|
|
16
|
-
},
|
|
17
|
-
enumsAsTypes: true,
|
|
18
|
-
allowEnumStringTypes: true,
|
|
19
|
-
avoidOptionals: {
|
|
20
|
-
field: true,
|
|
21
|
-
},
|
|
22
|
-
skipTypename: true,
|
|
23
|
-
// maybeValue: "T | null | undefined",
|
|
24
|
-
inputMaybeValue: 'T | null | undefined',
|
|
25
|
-
};
|
|
26
|
-
function schemaConfig(name, dir) {
|
|
27
|
-
return {
|
|
28
|
-
[`${dir}/${name}/gen/schema/types.ts`]: {
|
|
29
|
-
schema: [
|
|
30
|
-
{
|
|
31
|
-
[`${dir}/${name}/schema.graphql`]: {
|
|
32
|
-
skipGraphQLImport: false,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
plugins: ['typescript'],
|
|
37
|
-
config: tsConfig,
|
|
38
|
-
},
|
|
39
|
-
[`${dir}/${name}/gen/schema/zod.ts`]: {
|
|
40
|
-
schema: `${dir}/${name}/schema.graphql`,
|
|
41
|
-
plugins: ['@acaldas/graphql-codegen-typescript-validation-schema'],
|
|
42
|
-
config: {
|
|
43
|
-
importFrom: `./types`,
|
|
44
|
-
schema: 'zod',
|
|
45
|
-
...tsConfig,
|
|
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))',
|
|
51
|
-
},
|
|
52
|
-
directives: {
|
|
53
|
-
equals: {
|
|
54
|
-
value: ['regex', '/^$1$/'],
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
withObjectType: true,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
const generateSchema = (model, dir, { watch = false, format = false } = {}) => {
|
|
63
|
-
const documentModelConfig = schemaConfig(model, dir);
|
|
64
|
-
const config = {
|
|
65
|
-
overwrite: true,
|
|
66
|
-
generates: documentModelConfig,
|
|
67
|
-
watch,
|
|
68
|
-
hooks: {
|
|
69
|
-
afterOneFileWrite: format ? ['prettier --ignore-path --write'] : [],
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
return (0, cli_1.generate)(config, true);
|
|
73
|
-
};
|
|
74
|
-
exports.generateSchema = generateSchema;
|
|
75
|
-
const generateSchemas = (dir, { watch = false, format = false } = {}) => {
|
|
76
|
-
const documentModels = getDirectories(dir);
|
|
77
|
-
const documentModelConfigs = documentModels.reduce((obj, model) => ({
|
|
78
|
-
...obj,
|
|
79
|
-
...schemaConfig(model, dir),
|
|
80
|
-
}), {});
|
|
81
|
-
const config = {
|
|
82
|
-
overwrite: true,
|
|
83
|
-
generates: documentModelConfigs,
|
|
84
|
-
watch,
|
|
85
|
-
hooks: {
|
|
86
|
-
afterOneFileWrite: format ? ['prettier --ignore-path --write'] : [],
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
return (0, cli_1.generate)(config, true);
|
|
90
|
-
};
|
|
91
|
-
exports.generateSchemas = generateSchemas;
|
package/dist/codegen/hygen.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { DocumentModel } from 'document-model';
|
|
2
|
-
export declare function generateAll(dir: string, { watch, format }?: {
|
|
3
|
-
watch?: boolean | undefined;
|
|
4
|
-
format?: boolean | undefined;
|
|
5
|
-
}): Promise<void>;
|
|
6
|
-
export declare function generateDocumentModel(documentModel: DocumentModel.DocumentModelState, dir: string, { watch, format }?: {
|
|
7
|
-
watch?: boolean | undefined;
|
|
8
|
-
format?: boolean | undefined;
|
|
9
|
-
}): Promise<void>;
|
|
10
|
-
export declare function generateEditor(name: string, documentTypes: string[], documentTypesMap: Record<string, string>, dir: string, documentModelsDir: string, { format }?: {
|
|
11
|
-
format?: boolean | undefined;
|
|
12
|
-
}): Promise<void>;
|
package/dist/codegen/hygen.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateAll = generateAll;
|
|
7
|
-
exports.generateDocumentModel = generateDocumentModel;
|
|
8
|
-
exports.generateEditor = generateEditor;
|
|
9
|
-
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const hygen_1 = require("hygen");
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const utils_1 = require("./utils");
|
|
13
|
-
const logger = new hygen_1.Logger(console.log.bind(console));
|
|
14
|
-
const defaultTemplates = path_1.default.join(__dirname, '.hygen', 'templates');
|
|
15
|
-
async function run(args, { watch = false, format = false } = {}) {
|
|
16
|
-
const result = await (0, hygen_1.runner)(args, {
|
|
17
|
-
templates: defaultTemplates,
|
|
18
|
-
cwd: process.cwd(),
|
|
19
|
-
logger,
|
|
20
|
-
createPrompter: () => {
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
22
|
-
return require('enquirer');
|
|
23
|
-
},
|
|
24
|
-
exec: (action, body) => {
|
|
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);
|
|
28
|
-
},
|
|
29
|
-
debug: !!process.env.DEBUG,
|
|
30
|
-
});
|
|
31
|
-
if (format) {
|
|
32
|
-
const execa = await import('execa');
|
|
33
|
-
const actions = result.actions;
|
|
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) => {
|
|
38
|
-
console.log(err);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
async function generateAll(dir, { watch = false, format = false } = {}) {
|
|
45
|
-
const files = fs_1.default.readdirSync(dir, { withFileTypes: true });
|
|
46
|
-
for (const directory of files.filter(f => f.isDirectory())) {
|
|
47
|
-
const documentModelPath = path_1.default.join(dir, directory.name, `${directory.name}.json`);
|
|
48
|
-
if (!fs_1.default.existsSync(documentModelPath)) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
const documentModel = await (0, utils_1.loadDocumentModel)(documentModelPath);
|
|
53
|
-
await generateDocumentModel(documentModel, dir, { watch, format });
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
console.error(directory.name, error);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async function generateDocumentModel(documentModel, dir, { watch = false, format = false } = {}) {
|
|
61
|
-
// Generate the singular files for the document model logic
|
|
62
|
-
await run([
|
|
63
|
-
'powerhouse',
|
|
64
|
-
'generate-document-model',
|
|
65
|
-
'--document-model',
|
|
66
|
-
JSON.stringify(documentModel),
|
|
67
|
-
'--root-dir',
|
|
68
|
-
dir,
|
|
69
|
-
], { watch, format });
|
|
70
|
-
// Generate the module-specific files for the document model logic
|
|
71
|
-
const latestSpec = documentModel.specifications[documentModel.specifications.length - 1];
|
|
72
|
-
for (const module of latestSpec.modules) {
|
|
73
|
-
await run([
|
|
74
|
-
'powerhouse',
|
|
75
|
-
'generate-document-model-module',
|
|
76
|
-
'--document-model',
|
|
77
|
-
JSON.stringify(documentModel),
|
|
78
|
-
'--root-dir',
|
|
79
|
-
dir,
|
|
80
|
-
'--module',
|
|
81
|
-
module.name,
|
|
82
|
-
], { watch, format });
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async function generateEditor(name, documentTypes, documentTypesMap, dir, documentModelsDir, { format = false } = {}) {
|
|
86
|
-
// Generate the singular files for the document model logic
|
|
87
|
-
await run([
|
|
88
|
-
'powerhouse',
|
|
89
|
-
'generate-editor',
|
|
90
|
-
'--name',
|
|
91
|
-
name,
|
|
92
|
-
'--root-dir',
|
|
93
|
-
dir,
|
|
94
|
-
'--document-types',
|
|
95
|
-
documentTypes.join(','),
|
|
96
|
-
'--document-types-map',
|
|
97
|
-
JSON.stringify(documentTypesMap),
|
|
98
|
-
'--document-models-dir',
|
|
99
|
-
documentModelsDir,
|
|
100
|
-
], { format });
|
|
101
|
-
}
|
package/dist/codegen/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
import type { PowerhouseConfig } from '../utils';
|
|
3
|
-
export declare function generate(config: PowerhouseConfig): Promise<void>;
|
|
4
|
-
export declare function generateFromFile(path: string, config: PowerhouseConfig): Promise<void>;
|
|
5
|
-
export declare function generateEditor(name: string, documentTypes: string[], config: PowerhouseConfig): Promise<void>;
|
package/dist/codegen/index.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.generate = generate;
|
|
8
|
-
exports.generateFromFile = generateFromFile;
|
|
9
|
-
exports.generateEditor = generateEditor;
|
|
10
|
-
const hygen_1 = require("./hygen");
|
|
11
|
-
const graphql_1 = require("./graphql");
|
|
12
|
-
const fs_1 = __importDefault(require("fs"));
|
|
13
|
-
const path_1 = require("path");
|
|
14
|
-
const change_case_1 = require("change-case");
|
|
15
|
-
const utils_1 = require("./utils");
|
|
16
|
-
function generateGraphqlSchema(documentModel) {
|
|
17
|
-
const spec = documentModel.specifications[documentModel.specifications.length - 1];
|
|
18
|
-
if (!spec) {
|
|
19
|
-
console.log(`No spec found for ${documentModel.id}`);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const { modules, state: { global, local }, } = spec;
|
|
23
|
-
const schemas = [
|
|
24
|
-
global.schema,
|
|
25
|
-
local.schema,
|
|
26
|
-
...modules
|
|
27
|
-
.map(module => [
|
|
28
|
-
`# ${module.name}`,
|
|
29
|
-
...module.operations.map(op => op.schema),
|
|
30
|
-
])
|
|
31
|
-
.flat()
|
|
32
|
-
.filter(schema => schema && schema.length > 0),
|
|
33
|
-
];
|
|
34
|
-
return schemas.join('\n\n');
|
|
35
|
-
}
|
|
36
|
-
function getDocumentTypesMap(dir) {
|
|
37
|
-
const documentTypesMap = {};
|
|
38
|
-
fs_1.default.readdirSync(dir, { withFileTypes: true })
|
|
39
|
-
.filter(dirent => dirent.isDirectory())
|
|
40
|
-
.map(dirent => dirent.name)
|
|
41
|
-
.forEach(name => {
|
|
42
|
-
const specPath = (0, path_1.resolve)(dir, name, `${name}.json`);
|
|
43
|
-
if (!fs_1.default.existsSync(specPath)) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const specRaw = fs_1.default.readFileSync(specPath, 'utf-8');
|
|
47
|
-
try {
|
|
48
|
-
const spec = JSON.parse(specRaw);
|
|
49
|
-
if (spec.id) {
|
|
50
|
-
documentTypesMap[spec.id] = (0, change_case_1.pascalCase)(name);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
console.error(`Failed to parse ${specPath}`);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
return documentTypesMap;
|
|
58
|
-
}
|
|
59
|
-
async function generate(config) {
|
|
60
|
-
const { format, watch } = config;
|
|
61
|
-
await (0, graphql_1.generateSchemas)(config.documentModelsDir, { format, watch });
|
|
62
|
-
await (0, hygen_1.generateAll)(config.documentModelsDir, { format, watch });
|
|
63
|
-
}
|
|
64
|
-
async function generateFromFile(path, config) {
|
|
65
|
-
// load document model spec from file
|
|
66
|
-
const documentModel = await (0, utils_1.loadDocumentModel)(path);
|
|
67
|
-
const name = (0, change_case_1.paramCase)(documentModel.name);
|
|
68
|
-
// create document model folder and spec as json
|
|
69
|
-
fs_1.default.mkdirSync((0, path_1.join)(config.documentModelsDir, name), { recursive: true });
|
|
70
|
-
fs_1.default.writeFileSync((0, path_1.join)(config.documentModelsDir, name, `${name}.json`), JSON.stringify(documentModel, null, 4));
|
|
71
|
-
// bundle graphql schemas together
|
|
72
|
-
const schemaStr = generateGraphqlSchema(documentModel);
|
|
73
|
-
if (schemaStr) {
|
|
74
|
-
fs_1.default.writeFileSync((0, path_1.join)(config.documentModelsDir, name, `schema.graphql`), schemaStr);
|
|
75
|
-
}
|
|
76
|
-
await (0, graphql_1.generateSchema)(name, config.documentModelsDir, config);
|
|
77
|
-
await (0, hygen_1.generateDocumentModel)(documentModel, config.documentModelsDir, config);
|
|
78
|
-
}
|
|
79
|
-
async function generateEditor(name, documentTypes, config) {
|
|
80
|
-
const { documentModelsDir, format } = config;
|
|
81
|
-
const docummentTypesMap = getDocumentTypesMap(documentModelsDir);
|
|
82
|
-
const invalidType = documentTypes.find(type => !Object.keys(docummentTypesMap).includes(type));
|
|
83
|
-
if (invalidType) {
|
|
84
|
-
throw new Error(`Document model for ${invalidType} not found`);
|
|
85
|
-
}
|
|
86
|
-
return (0, hygen_1.generateEditor)(name, documentTypes, docummentTypesMap, config.editorsDir, config.documentModelsDir, { format });
|
|
87
|
-
}
|
package/dist/codegen/utils.d.ts
DELETED
package/dist/codegen/utils.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.loadDocumentModel = loadDocumentModel;
|
|
7
|
-
const document_model_1 = require("document-model/document-model");
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
async function loadDocumentModel(path) {
|
|
10
|
-
let documentModel;
|
|
11
|
-
try {
|
|
12
|
-
if (!path) {
|
|
13
|
-
throw new Error('Document model file not specified');
|
|
14
|
-
}
|
|
15
|
-
else if (path.endsWith('.zip')) {
|
|
16
|
-
const file = await document_model_1.utils.loadFromFile(path);
|
|
17
|
-
documentModel = file.state.global;
|
|
18
|
-
}
|
|
19
|
-
else if (path.endsWith('.json')) {
|
|
20
|
-
const data = fs_1.default.readFileSync(path, 'utf-8');
|
|
21
|
-
const document = JSON.parse(data);
|
|
22
|
-
// z.DocumentModelStateSchema().parse(document);
|
|
23
|
-
documentModel = document;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
throw new Error('File type not supported. Must be zip or json.');
|
|
27
|
-
}
|
|
28
|
-
return documentModel;
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
// @ts-expect-error
|
|
32
|
-
throw error.code === 'MODULE_NOT_FOUND'
|
|
33
|
-
? new Error(`Document model not found.`)
|
|
34
|
-
: error;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const child_process_1 = require("child_process");
|
|
8
|
-
const enquirer_1 = require("enquirer");
|
|
9
|
-
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const cli_1 = require("../utils/cli");
|
|
12
|
-
const command_1 = require("./command");
|
|
13
|
-
const BOILERPLATE_REPO = 'https://github.com/powerhouse-inc/document-model-boilerplate.git';
|
|
14
|
-
const packageManager = (0, command_1.getPackageManager)(process.env.npm_config_user_agent);
|
|
15
|
-
const isNpm = packageManager === 'npm';
|
|
16
|
-
function buildPackageJson(appPath, projectName) {
|
|
17
|
-
const packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join(appPath, 'package.json'), 'utf-8'));
|
|
18
|
-
const newPackage = {
|
|
19
|
-
...packageJson,
|
|
20
|
-
name: projectName,
|
|
21
|
-
version: '1.0.0',
|
|
22
|
-
description: '',
|
|
23
|
-
};
|
|
24
|
-
fs_1.default.writeFileSync(path_1.default.join(appPath, 'package.json'), JSON.stringify(newPackage, null, 2), 'utf8');
|
|
25
|
-
}
|
|
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'));
|
|
29
|
-
const newPackage = {
|
|
30
|
-
...packageJson,
|
|
31
|
-
documentModelsDir,
|
|
32
|
-
editorsDir,
|
|
33
|
-
};
|
|
34
|
-
fs_1.default.writeFileSync(filePath, JSON.stringify(newPackage, null, 2), 'utf8');
|
|
35
|
-
}
|
|
36
|
-
function buildIndex(appPath, documentModelsDir, editorsDir) {
|
|
37
|
-
fs_1.default.writeFileSync(path_1.default.join(appPath, 'index.ts'), `import * as documentModelsExports from '${documentModelsDir}';
|
|
38
|
-
import * as editorsExports from '${editorsDir}';
|
|
39
|
-
|
|
40
|
-
export const documentModels = Object.values(documentModelsExports);
|
|
41
|
-
export const editors = Object.values(editorsExports);`, 'utf8');
|
|
42
|
-
}
|
|
43
|
-
function runCmd(command) {
|
|
44
|
-
try {
|
|
45
|
-
(0, child_process_1.execSync)(command, { stdio: 'inherit' });
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
console.log('\x1b[31m', error, '\x1b[0m');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
async function init() {
|
|
52
|
-
const args = (0, cli_1.parseArgs)(process.argv.slice(2), cli_1.configSpec);
|
|
53
|
-
// checks if a project name was provided
|
|
54
|
-
let projectName = args._.shift();
|
|
55
|
-
if (!projectName) {
|
|
56
|
-
const result = await (0, enquirer_1.prompt)([
|
|
57
|
-
{
|
|
58
|
-
type: 'input',
|
|
59
|
-
name: 'projectName',
|
|
60
|
-
message: 'What is the project name?',
|
|
61
|
-
required: true,
|
|
62
|
-
},
|
|
63
|
-
]);
|
|
64
|
-
if (!result.projectName) {
|
|
65
|
-
console.log('\x1b[31m', 'You have to provide name to your app.');
|
|
66
|
-
process.exit(1);
|
|
67
|
-
}
|
|
68
|
-
projectName = result.projectName;
|
|
69
|
-
}
|
|
70
|
-
const { documentModelsDir, editorsDir } = args['--interactive']
|
|
71
|
-
? await (0, cli_1.promptDirectories)()
|
|
72
|
-
: cli_1.DEFAULT_CONFIG;
|
|
73
|
-
const appPath = path_1.default.join(process.cwd(), projectName);
|
|
74
|
-
try {
|
|
75
|
-
fs_1.default.mkdirSync(appPath);
|
|
76
|
-
}
|
|
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');
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
console.log(err);
|
|
83
|
-
}
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
86
|
-
createProject(projectName, documentModelsDir, editorsDir);
|
|
87
|
-
}
|
|
88
|
-
function createProject(projectName, documentModelsDir, editorsDir) {
|
|
89
|
-
try {
|
|
90
|
-
console.log('\x1b[33m', 'Downloading the project structure...', '\x1b[0m');
|
|
91
|
-
runCmd(`git clone --depth 1 ${BOILERPLATE_REPO} ${projectName}`);
|
|
92
|
-
const appPath = path_1.default.join(process.cwd(), projectName);
|
|
93
|
-
process.chdir(appPath);
|
|
94
|
-
console.log('\x1b[34m', 'Installing dependencies...', '\x1b[0m');
|
|
95
|
-
runCmd(`${packageManager} install`);
|
|
96
|
-
fs_1.default.rmSync(path_1.default.join(appPath, './.git'), { recursive: true });
|
|
97
|
-
runCmd('git init');
|
|
98
|
-
try {
|
|
99
|
-
fs_1.default.mkdirSync(path_1.default.join(appPath, documentModelsDir));
|
|
100
|
-
fs_1.default.writeFileSync(path_1.default.join(appPath, documentModelsDir, 'index.ts'), '');
|
|
101
|
-
fs_1.default.mkdirSync(path_1.default.join(appPath, editorsDir));
|
|
102
|
-
fs_1.default.writeFileSync(path_1.default.join(appPath, editorsDir, 'index.ts'), '');
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
if (!error.message.includes('EEXIST')) {
|
|
106
|
-
throw error;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
buildPackageJson(appPath, projectName);
|
|
110
|
-
buildPowerhouseConfig(appPath, documentModelsDir, editorsDir);
|
|
111
|
-
buildIndex(appPath, documentModelsDir, editorsDir);
|
|
112
|
-
console.log('\x1b[32m', 'The installation is done!', '\x1b[0m');
|
|
113
|
-
console.log();
|
|
114
|
-
console.log('\x1b[34m', 'You can start by typing:');
|
|
115
|
-
console.log(` cd ${projectName}`);
|
|
116
|
-
console.log(isNpm ? ' npm run generate' : ` ${packageManager} generate`, '\x1b[0m');
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
console.log(error);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
init();
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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("./codegen"), exports);
|
|
18
|
-
__exportStar(require("./utils"), exports);
|
package/dist/utils/cli.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import arg from 'arg';
|
|
2
|
-
export type PowerhouseConfig = {
|
|
3
|
-
documentModelsDir: string;
|
|
4
|
-
editorsDir: string;
|
|
5
|
-
interactive?: boolean;
|
|
6
|
-
format?: boolean;
|
|
7
|
-
watch?: boolean;
|
|
8
|
-
};
|
|
9
|
-
export declare const DEFAULT_CONFIG: PowerhouseConfig;
|
|
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";
|
|
19
|
-
};
|
|
20
|
-
export declare function getConfig(): PowerhouseConfig;
|
|
21
|
-
export declare function writeConfig(config: PowerhouseConfig): void;
|
|
22
|
-
export declare function parseArgs<T extends arg.Spec>(argv: string[], spec: T): arg.Result<T>;
|
|
23
|
-
export declare function parseConfig(argv: string[]): Partial<PowerhouseConfig>;
|
|
24
|
-
export declare function promptDirectories(config?: PowerhouseConfig): Promise<Pick<PowerhouseConfig, "documentModelsDir" | "editorsDir">>;
|
package/dist/utils/cli.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.configSpec = exports.DEFAULT_CONFIG = void 0;
|
|
7
|
-
exports.getConfig = getConfig;
|
|
8
|
-
exports.writeConfig = writeConfig;
|
|
9
|
-
exports.parseArgs = parseArgs;
|
|
10
|
-
exports.parseConfig = parseConfig;
|
|
11
|
-
exports.promptDirectories = promptDirectories;
|
|
12
|
-
const arg_1 = __importDefault(require("arg"));
|
|
13
|
-
const enquirer_1 = require("enquirer");
|
|
14
|
-
const node_fs_1 = require("node:fs");
|
|
15
|
-
const DEFAULT_DOCUMENT_MODELS_DIR = './document-models';
|
|
16
|
-
const DEFAULT_EDITORS_DIR = './editors';
|
|
17
|
-
exports.DEFAULT_CONFIG = {
|
|
18
|
-
documentModelsDir: DEFAULT_DOCUMENT_MODELS_DIR,
|
|
19
|
-
editorsDir: DEFAULT_EDITORS_DIR,
|
|
20
|
-
};
|
|
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',
|
|
30
|
-
};
|
|
31
|
-
function getConfig() {
|
|
32
|
-
let config = { ...exports.DEFAULT_CONFIG };
|
|
33
|
-
try {
|
|
34
|
-
const configStr = (0, node_fs_1.readFileSync)('./powerhouse.config.json', 'utf-8');
|
|
35
|
-
const userConfig = JSON.parse(configStr);
|
|
36
|
-
config = { ...config, ...userConfig };
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
console.warn('No powerhouse.config.json found, using defaults');
|
|
40
|
-
}
|
|
41
|
-
return config;
|
|
42
|
-
}
|
|
43
|
-
function writeConfig(config) {
|
|
44
|
-
(0, node_fs_1.writeFileSync)('./powerhouse.config.json', JSON.stringify(config, null, 4));
|
|
45
|
-
}
|
|
46
|
-
function parseArgs(argv, spec) {
|
|
47
|
-
const args = (0, arg_1.default)(spec, {
|
|
48
|
-
permissive: true,
|
|
49
|
-
argv,
|
|
50
|
-
});
|
|
51
|
-
return args;
|
|
52
|
-
}
|
|
53
|
-
function parseConfig(argv) {
|
|
54
|
-
const config = {};
|
|
55
|
-
const args = parseArgs(argv, exports.configSpec);
|
|
56
|
-
if ('--document-models' in args) {
|
|
57
|
-
config.documentModelsDir = args['--document-models'];
|
|
58
|
-
}
|
|
59
|
-
if ('--editors' in args) {
|
|
60
|
-
config.editorsDir = args['--editors'];
|
|
61
|
-
}
|
|
62
|
-
if ('--format' in args) {
|
|
63
|
-
config.format = true;
|
|
64
|
-
}
|
|
65
|
-
if ('--interactive' in args) {
|
|
66
|
-
config.interactive = true;
|
|
67
|
-
}
|
|
68
|
-
if ('--watch' in args) {
|
|
69
|
-
config.watch = true;
|
|
70
|
-
}
|
|
71
|
-
return config;
|
|
72
|
-
}
|
|
73
|
-
async function promptDirectories(config = exports.DEFAULT_CONFIG) {
|
|
74
|
-
return (0, enquirer_1.prompt)([
|
|
75
|
-
{
|
|
76
|
-
type: 'input',
|
|
77
|
-
name: 'documentModelsDir',
|
|
78
|
-
message: 'Where to place the Document Models?',
|
|
79
|
-
initial: config.documentModelsDir,
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
type: 'input',
|
|
83
|
-
name: 'editorsDir',
|
|
84
|
-
message: 'Where to place the Editors?',
|
|
85
|
-
initial: config.editorsDir,
|
|
86
|
-
},
|
|
87
|
-
]);
|
|
88
|
-
}
|
package/dist/utils/index.d.ts
DELETED
package/dist/utils/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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);
|
package/dist/utils/mock.d.ts
DELETED
package/dist/utils/mock.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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;
|