@powerhousedao/codegen 4.1.0-dev.10 → 4.1.0-dev.100
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/README.md +0 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/index.js +10 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/resolvers.esm.t +17 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/schema.esm.t +16 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/documentModel.esm.t +2 -2
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.esm.t +8 -2
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.js +69 -54
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/ph-factories.esm.t +93 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/reducer.esm.t +9 -4
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/rootIndex.esm.t +6 -7
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/types.esm.t +20 -8
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/utils.esm.t +19 -26
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/creators.esm.t +1 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/customTest.esm.t +2 -2
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/error.esm.t +6 -10
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js +52 -27
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/index.js +21 -20
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/resolvers.esm.t +64 -51
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/schema.esm.t +4 -10
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/CreateDocument.esm.t +39 -28
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/DriveExplorer.esm.t +138 -223
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/FolderTree.esm.t +95 -72
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/config.esm.t +10 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/editor.esm.t +7 -71
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.esm.t +5 -10
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.js +12 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/editor.esm.t +103 -18
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/hooks.esm.t +16 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.esm.t +5 -12
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js +28 -15
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.js +8 -10
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/factory.esm.t +5 -4
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.esm.t +5 -9
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.js +11 -15
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.root.inject.esm.t +12 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.esm.t +8 -6
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.inject_call.esm.t +1 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.inject_import.esm.t +1 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/factory.esm.t +6 -5
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.esm.t +6 -13
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.js +11 -15
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.root.inject.esm.t +12 -0
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.esm.t +8 -9
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.inject_call.esm.t +2 -2
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.inject_import.esm.t +1 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/migrations.esm.t +2 -2
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/schema.esm.t +10 -2
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.esm.t +5 -36
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.js +9 -11
- package/dist/src/codegen/generate.d.ts +33 -0
- package/dist/src/codegen/generate.d.ts.map +1 -0
- package/dist/src/codegen/generate.js +202 -0
- package/dist/src/codegen/generate.js.map +1 -0
- package/dist/src/codegen/graphql.d.ts +2 -2
- package/dist/src/codegen/graphql.d.ts.map +1 -1
- package/dist/src/codegen/graphql.js +1 -1
- package/dist/src/codegen/graphql.js.map +1 -1
- package/dist/src/codegen/hygen.d.ts +18 -11
- package/dist/src/codegen/hygen.d.ts.map +1 -1
- package/dist/src/codegen/hygen.js +57 -21
- package/dist/src/codegen/hygen.js.map +1 -1
- package/dist/src/codegen/index.d.ts +6 -32
- package/dist/src/codegen/index.d.ts.map +1 -1
- package/dist/src/codegen/index.js +6 -182
- package/dist/src/codegen/index.js.map +1 -1
- package/dist/src/codegen/types.d.ts +9 -0
- package/dist/src/codegen/types.d.ts.map +1 -0
- package/dist/src/codegen/types.js +2 -0
- package/dist/src/codegen/types.js.map +1 -0
- package/dist/src/codegen/utils.d.ts +5 -2
- package/dist/src/codegen/utils.d.ts.map +1 -1
- package/dist/src/codegen/utils.js +42 -4
- package/dist/src/codegen/utils.js.map +1 -1
- package/dist/src/create-lib/checkout-project.d.ts +13 -0
- package/dist/src/create-lib/checkout-project.d.ts.map +1 -0
- package/dist/src/create-lib/checkout-project.js +47 -0
- package/dist/src/create-lib/checkout-project.js.map +1 -0
- package/dist/src/create-lib/create-project.d.ts +9 -5
- package/dist/src/create-lib/create-project.d.ts.map +1 -1
- package/dist/src/create-lib/create-project.js +37 -30
- package/dist/src/create-lib/create-project.js.map +1 -1
- package/dist/src/create-lib/feature-flags.d.ts +4 -0
- package/dist/src/create-lib/feature-flags.d.ts.map +1 -0
- package/dist/src/create-lib/feature-flags.js +4 -0
- package/dist/src/create-lib/feature-flags.js.map +1 -0
- package/dist/src/create-lib/index.d.ts +1 -0
- package/dist/src/create-lib/index.d.ts.map +1 -1
- package/dist/src/create-lib/index.js +1 -0
- package/dist/src/create-lib/index.js.map +1 -1
- package/dist/src/{utils/package-manager.d.ts → create-lib/utils.d.ts} +3 -1
- package/dist/src/create-lib/utils.d.ts.map +1 -0
- package/dist/src/{utils/package-manager.js → create-lib/utils.js} +12 -1
- package/dist/src/create-lib/utils.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/ts-morph-generator/core/FileGenerator.d.ts +2 -3
- package/dist/src/ts-morph-generator/core/FileGenerator.d.ts.map +1 -1
- package/dist/src/ts-morph-generator/core/FileGenerator.js.map +1 -1
- package/dist/src/ts-morph-generator/core/GenerationContext.d.ts +18 -8
- package/dist/src/ts-morph-generator/core/GenerationContext.d.ts.map +1 -1
- package/dist/src/ts-morph-generator/core/ReducerGenerator.d.ts +12 -0
- package/dist/src/ts-morph-generator/core/ReducerGenerator.d.ts.map +1 -0
- package/dist/src/ts-morph-generator/core/ReducerGenerator.js +140 -0
- package/dist/src/ts-morph-generator/core/ReducerGenerator.js.map +1 -0
- package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts +4 -3
- package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts.map +1 -1
- package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js +11 -10
- package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js.map +1 -1
- package/dist/src/ts-morph-generator/index.d.ts +2 -2
- package/dist/src/ts-morph-generator/index.d.ts.map +1 -1
- package/dist/src/ts-morph-generator/index.js +2 -2
- package/dist/src/ts-morph-generator/index.js.map +1 -1
- package/dist/src/ts-morph-generator/utilities/DirectoryManager.d.ts +2 -2
- package/dist/src/ts-morph-generator/utilities/DirectoryManager.d.ts.map +1 -1
- package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts +1 -1
- package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts.map +1 -1
- package/dist/src/utils/index.d.ts +0 -1
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +0 -1
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/utils/validation.d.ts +6 -6
- package/dist/src/utils/validation.d.ts.map +1 -1
- package/dist/src/utils/validation.js +2 -2
- package/dist/src/utils/validation.js.map +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +25 -27
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.d.ts +0 -25
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/index.js.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/object.esm.t +0 -49
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts +0 -23
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/object.esm.t +0 -37
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/index.d.ts +0 -22
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/index.js.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/EditorContainer.esm.t +0 -124
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/FileItemsGrid.esm.t +0 -44
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/FolderItemsGrid.esm.t +0 -96
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/hooks/useSelectedFolderChildren.esm.t +0 -35
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/hooks/useTransformedNodes.esm.t +0 -35
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/types/css.d.esm.t +0 -8
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.d.ts +0 -20
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.d.ts +0 -14
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-import-script/index.js.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.d.ts +0 -20
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/index.js.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.d.ts +0 -20
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/index.js.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.d.ts +0 -16
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.d.ts.map +0 -1
- package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.js.map +0 -1
- package/dist/src/ts-morph-generator/core/index.d.ts +0 -4
- package/dist/src/ts-morph-generator/core/index.d.ts.map +0 -1
- package/dist/src/ts-morph-generator/core/index.js +0 -4
- package/dist/src/ts-morph-generator/core/index.js.map +0 -1
- package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.d.ts +0 -9
- package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.d.ts.map +0 -1
- package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.js +0 -69
- package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.js.map +0 -1
- package/dist/src/ts-morph-generator/file-generators/index.d.ts +0 -2
- package/dist/src/ts-morph-generator/file-generators/index.d.ts.map +0 -1
- package/dist/src/ts-morph-generator/file-generators/index.js +0 -2
- package/dist/src/ts-morph-generator/file-generators/index.js.map +0 -1
- package/dist/src/utils/package-manager.d.ts.map +0 -1
- package/dist/src/utils/package-manager.js.map +0 -1
- package/dist/tsconfig.hygen.tsbuildinfo +0 -1
|
@@ -1,33 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare function generate(config: PowerhouseConfig): Promise<void>;
|
|
8
|
-
export declare function generateFromFile(path: string, config: PowerhouseConfig, options?: CodegenOptions): Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* Generates code from a DocumentModelDocument object directly.
|
|
11
|
-
*
|
|
12
|
-
* @remarks
|
|
13
|
-
* This function performs the same code generation as generateFromFile but takes
|
|
14
|
-
* a DocumentModelDocument object directly instead of loading from a file. This allows for
|
|
15
|
-
* programmatic code generation without file I/O.
|
|
16
|
-
*
|
|
17
|
-
* @param documentModelDocument - The DocumentModelDocument object containing the document model
|
|
18
|
-
* @param config - The PowerhouseConfig configuration object
|
|
19
|
-
* @param options - Optional configuration for generation behavior (verbose logging, etc.)
|
|
20
|
-
* @returns A promise that resolves when code generation is complete
|
|
21
|
-
*/
|
|
22
|
-
export declare function generateFromDocument(documentModelState: DocumentModelState, config: PowerhouseConfig, options?: CodegenOptions): Promise<void>;
|
|
23
|
-
export declare function generateEditor(name: string, documentTypes: string[], config: PowerhouseConfig): Promise<void>;
|
|
24
|
-
export declare function generateSubgraphFromDocumentModel(name: string, documentModel: DocumentModelState, config: PowerhouseConfig, options?: CodegenOptions): Promise<void>;
|
|
25
|
-
export declare function generateSubgraph(name: string, file: string | null, config: PowerhouseConfig, options?: CodegenOptions): Promise<void>;
|
|
26
|
-
export declare function generateProcessor(name: string, type: "analytics" | "relationalDb", documentTypes: string[], config: PowerhouseConfig): Promise<void>;
|
|
27
|
-
export type DocumentTypesMap = Record<string, {
|
|
28
|
-
name: string;
|
|
29
|
-
importPath: string;
|
|
30
|
-
}>;
|
|
31
|
-
export declare function generateDriveEditor(name: string, config: PowerhouseConfig): Promise<void>;
|
|
32
|
-
export declare function generateImportScript(name: string, config: PowerhouseConfig): Promise<void>;
|
|
1
|
+
export * from "./generate.js";
|
|
2
|
+
export * from "./graphql.js";
|
|
3
|
+
export * from "./hygen.js";
|
|
4
|
+
export * from "./kysely.js";
|
|
5
|
+
export * from "./types.js";
|
|
6
|
+
export * from "./utils.js";
|
|
33
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/codegen/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/codegen/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
|
@@ -1,183 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { loadDocumentModel } from "./utils.js";
|
|
8
|
-
export { generateDBSchema } from "./kysely.js";
|
|
9
|
-
function generateGraphqlSchema(documentModel) {
|
|
10
|
-
const spec = documentModel.specifications[documentModel.specifications.length - 1];
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
12
|
-
if (!spec) {
|
|
13
|
-
throw new Error(`No spec found for ${documentModel.id}`);
|
|
14
|
-
}
|
|
15
|
-
const { modules, state: { global, local }, } = spec;
|
|
16
|
-
const schemas = [
|
|
17
|
-
global.schema,
|
|
18
|
-
local.schema,
|
|
19
|
-
...modules
|
|
20
|
-
.map((module) => [
|
|
21
|
-
`# ${module.name}`,
|
|
22
|
-
...module.operations.map((op) => op.schema),
|
|
23
|
-
])
|
|
24
|
-
.flat()
|
|
25
|
-
.filter((schema) => schema && schema.length > 0),
|
|
26
|
-
];
|
|
27
|
-
return schemas.join("\n\n");
|
|
28
|
-
}
|
|
29
|
-
// returns map of document model id to document model name in pascal case and import path
|
|
30
|
-
async function getDocumentTypesMap(dir, pathOrigin = "../../") {
|
|
31
|
-
const documentTypesMap = {};
|
|
32
|
-
// add document types from provided dir
|
|
33
|
-
if (fs.existsSync(dir)) {
|
|
34
|
-
fs.readdirSync(dir, { withFileTypes: true })
|
|
35
|
-
.filter((dirent) => dirent.isDirectory())
|
|
36
|
-
.map((dirent) => dirent.name)
|
|
37
|
-
.forEach((name) => {
|
|
38
|
-
const specPath = resolve(dir, name, `${name}.json`);
|
|
39
|
-
if (!fs.existsSync(specPath)) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const specRaw = fs.readFileSync(specPath, "utf-8");
|
|
43
|
-
try {
|
|
44
|
-
const spec = JSON.parse(specRaw);
|
|
45
|
-
if (spec.id) {
|
|
46
|
-
documentTypesMap[spec.id] = {
|
|
47
|
-
name: pascalCase(name),
|
|
48
|
-
importPath: join(pathOrigin, dir, name),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
console.error(`Failed to parse ${specPath}`);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
// add documents from document-model-libs if lib is installed
|
|
58
|
-
try {
|
|
59
|
-
/* eslint-disable */
|
|
60
|
-
// @ts-ignore-error TS2307 this import is expected to fail if document-model-libs is not available
|
|
61
|
-
const documentModels = await import("document-model-libs/document-models");
|
|
62
|
-
Object.keys(documentModels).forEach((name) => {
|
|
63
|
-
const documentModel = documentModels[name];
|
|
64
|
-
documentTypesMap[documentModel.documentModel.id] = {
|
|
65
|
-
name,
|
|
66
|
-
importPath: `document-model-libs/${paramCase(name)}`,
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
/* eslint-enable */
|
|
70
|
-
}
|
|
71
|
-
catch {
|
|
72
|
-
/* document-model-libs is not available */
|
|
73
|
-
}
|
|
74
|
-
return documentTypesMap;
|
|
75
|
-
}
|
|
76
|
-
export async function generate(config) {
|
|
77
|
-
const { skipFormat, watch } = config;
|
|
78
|
-
await generateSchemas(config.documentModelsDir, { skipFormat, watch });
|
|
79
|
-
await generateAll(config.documentModelsDir, { skipFormat, watch });
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Generates code from a DocumentModelState.
|
|
83
|
-
*
|
|
84
|
-
* @remarks
|
|
85
|
-
* This is the core generation function that both generateFromFile and generateFromDocument
|
|
86
|
-
* use internally. It handles the actual code generation from a DocumentModelState object.
|
|
87
|
-
*
|
|
88
|
-
* @param documentModel - The DocumentModelState containing the document model specification
|
|
89
|
-
* @param config - The PowerhouseConfig configuration object
|
|
90
|
-
* @param filePath - Optional file path for generateSubgraph (null if not from file)
|
|
91
|
-
* @param options - Optional configuration for generation behavior
|
|
92
|
-
* @returns A promise that resolves when code generation is complete
|
|
93
|
-
*/
|
|
94
|
-
async function generateFromDocumentModel(documentModel, config, filePath, options = {}) {
|
|
95
|
-
// Derive verbose from config.logLevel if not explicitly provided
|
|
96
|
-
// Show hygen logs for verbose, debug, and info levels (default behavior before ts-morph)
|
|
97
|
-
const { verbose = config.logLevel === "verbose" ||
|
|
98
|
-
config.logLevel === "debug" ||
|
|
99
|
-
config.logLevel === "info", } = options;
|
|
100
|
-
const name = paramCase(documentModel.name);
|
|
101
|
-
// create document model folder and spec as json
|
|
102
|
-
fs.mkdirSync(join(config.documentModelsDir, name), { recursive: true });
|
|
103
|
-
fs.writeFileSync(join(config.documentModelsDir, name, `${name}.json`), JSON.stringify(documentModel, null, 4));
|
|
104
|
-
// bundle graphql schemas together
|
|
105
|
-
const schemaStr = [
|
|
106
|
-
typeDefs.join("\n"), // inject ph scalars
|
|
107
|
-
generateGraphqlSchema(documentModel),
|
|
108
|
-
].join("\n");
|
|
109
|
-
if (schemaStr) {
|
|
110
|
-
fs.writeFileSync(join(config.documentModelsDir, name, `schema.graphql`), schemaStr);
|
|
111
|
-
}
|
|
112
|
-
await generateSchema(name, config.documentModelsDir, {
|
|
113
|
-
skipFormat: config.skipFormat,
|
|
114
|
-
verbose,
|
|
115
|
-
});
|
|
116
|
-
await generateDocumentModel(documentModel, config.documentModelsDir, {
|
|
117
|
-
skipFormat: config.skipFormat,
|
|
118
|
-
verbose,
|
|
119
|
-
});
|
|
120
|
-
await generateSubgraph(name, filePath || null, config, { verbose });
|
|
121
|
-
}
|
|
122
|
-
export async function generateFromFile(path, config, options = {}) {
|
|
123
|
-
// load document model spec from file
|
|
124
|
-
const documentModel = await loadDocumentModel(path);
|
|
125
|
-
// delegate to shared generation function
|
|
126
|
-
await generateFromDocumentModel(documentModel, config, path, options);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Generates code from a DocumentModelDocument object directly.
|
|
130
|
-
*
|
|
131
|
-
* @remarks
|
|
132
|
-
* This function performs the same code generation as generateFromFile but takes
|
|
133
|
-
* a DocumentModelDocument object directly instead of loading from a file. This allows for
|
|
134
|
-
* programmatic code generation without file I/O.
|
|
135
|
-
*
|
|
136
|
-
* @param documentModelDocument - The DocumentModelDocument object containing the document model
|
|
137
|
-
* @param config - The PowerhouseConfig configuration object
|
|
138
|
-
* @param options - Optional configuration for generation behavior (verbose logging, etc.)
|
|
139
|
-
* @returns A promise that resolves when code generation is complete
|
|
140
|
-
*/
|
|
141
|
-
export async function generateFromDocument(documentModelState, config, options = {}) {
|
|
142
|
-
// delegate to shared generation function
|
|
143
|
-
await generateFromDocumentModel(documentModelState, config, null, options);
|
|
144
|
-
}
|
|
145
|
-
export async function generateEditor(name, documentTypes, config) {
|
|
146
|
-
const pathOrigin = "../../";
|
|
147
|
-
const { documentModelsDir, skipFormat } = config;
|
|
148
|
-
const documentTypesMap = await getDocumentTypesMap(documentModelsDir, pathOrigin);
|
|
149
|
-
const invalidType = documentTypes.find((type) => !Object.keys(documentTypesMap).includes(type));
|
|
150
|
-
if (invalidType) {
|
|
151
|
-
throw new Error(`Document model for ${invalidType} not found`);
|
|
152
|
-
}
|
|
153
|
-
return _generateEditor(name, documentTypes, documentTypesMap, config.editorsDir, config.documentModelsDir, { skipFormat });
|
|
154
|
-
}
|
|
155
|
-
export async function generateSubgraphFromDocumentModel(name, documentModel, config, options = {}) {
|
|
156
|
-
return _generateSubgraph(name, documentModel, config.subgraphsDir, {
|
|
157
|
-
skipFormat: config.skipFormat,
|
|
158
|
-
verbose: options.verbose,
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
export async function generateSubgraph(name, file, config, options = {}) {
|
|
162
|
-
return _generateSubgraph(name, file !== null ? await loadDocumentModel(file) : null, config.subgraphsDir, { skipFormat: config.skipFormat, verbose: options.verbose });
|
|
163
|
-
}
|
|
164
|
-
export async function generateProcessor(name, type, documentTypes, config) {
|
|
165
|
-
const { documentModelsDir, skipFormat } = config;
|
|
166
|
-
const documentTypesMap = await getDocumentTypesMap(documentModelsDir);
|
|
167
|
-
const invalidType = documentTypes.find((type) => !Object.keys(documentTypesMap).includes(type));
|
|
168
|
-
if (invalidType) {
|
|
169
|
-
throw new Error(`Document model for ${invalidType} not found`);
|
|
170
|
-
}
|
|
171
|
-
return _generateProcessor(name, documentTypes, documentTypesMap, config.processorsDir, config.documentModelsDir, type, { skipFormat });
|
|
172
|
-
}
|
|
173
|
-
export async function generateDriveEditor(name, config) {
|
|
174
|
-
return _generateDriveEditor(name, config.editorsDir, {
|
|
175
|
-
skipFormat: config.skipFormat,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
export async function generateImportScript(name, config) {
|
|
179
|
-
return _generateImportScript(name, config.importScriptsDir, {
|
|
180
|
-
skipFormat: config.skipFormat,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
1
|
+
export * from "./generate.js";
|
|
2
|
+
export * from "./graphql.js";
|
|
3
|
+
export * from "./hygen.js";
|
|
4
|
+
export * from "./kysely.js";
|
|
5
|
+
export * from "./types.js";
|
|
6
|
+
export * from "./utils.js";
|
|
183
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codegen/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codegen/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/codegen/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CACnC,MAAM,EACN;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CACrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/codegen/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { DocumentTypesMap } from "@powerhousedao/codegen";
|
|
2
|
+
import type { DocumentModelGlobalState } from "document-model";
|
|
3
|
+
export declare function loadDocumentModel(path: string): Promise<DocumentModelGlobalState>;
|
|
3
4
|
export declare function formatWithPrettierBeforeWrite(outputFile: string, content: string): Promise<string>;
|
|
5
|
+
/** returns map of document model id to document model name in pascal case and import path */
|
|
6
|
+
export declare function getDocumentTypesMap(dir: string, pathOrigin?: string): DocumentTypesMap;
|
|
4
7
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/codegen/utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/codegen/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,OAAO,KAAK,EAEV,wBAAwB,EACzB,MAAM,gBAAgB,CAAC;AAOxB,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,wBAAwB,CAAC,CAyBnC;AAED,wBAAsB,6BAA6B,CACjD,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,mBAMhB;AAED,6FAA6F;AAC7F,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EACX,UAAU,SAAW,GACpB,gBAAgB,CAmClB"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { pascalCase } from "change-case";
|
|
2
|
+
import { documentModelReducer } from "document-model";
|
|
3
|
+
import { baseLoadFromFile } from "document-model/node";
|
|
2
4
|
import fs from "node:fs";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
3
6
|
import { format } from "prettier";
|
|
4
7
|
export async function loadDocumentModel(path) {
|
|
5
8
|
let documentModel;
|
|
@@ -7,8 +10,8 @@ export async function loadDocumentModel(path) {
|
|
|
7
10
|
if (!path) {
|
|
8
11
|
throw new Error("Document model file not specified");
|
|
9
12
|
}
|
|
10
|
-
else if (path.endsWith(".zip")) {
|
|
11
|
-
const file = await
|
|
13
|
+
else if (path.endsWith(".zip") || path.endsWith(".phd")) {
|
|
14
|
+
const file = await baseLoadFromFile(path, documentModelReducer);
|
|
12
15
|
documentModel = file.state.global;
|
|
13
16
|
}
|
|
14
17
|
else if (path.endsWith(".json")) {
|
|
@@ -22,7 +25,7 @@ export async function loadDocumentModel(path) {
|
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
else {
|
|
25
|
-
throw new Error("File type not supported. Must be zip or json.");
|
|
28
|
+
throw new Error("File type not supported. Must be zip, phd, or json.");
|
|
26
29
|
}
|
|
27
30
|
return documentModel;
|
|
28
31
|
}
|
|
@@ -38,4 +41,39 @@ export async function formatWithPrettierBeforeWrite(outputFile, content) {
|
|
|
38
41
|
});
|
|
39
42
|
return modifiedContent;
|
|
40
43
|
}
|
|
44
|
+
/** returns map of document model id to document model name in pascal case and import path */
|
|
45
|
+
export function getDocumentTypesMap(dir, pathOrigin = "../../") {
|
|
46
|
+
const documentTypesMap = {
|
|
47
|
+
"powerhouse/document-model": {
|
|
48
|
+
name: "DocumentModel",
|
|
49
|
+
importPath: `document-model`,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
// add document types from provided dir
|
|
53
|
+
if (fs.existsSync(dir)) {
|
|
54
|
+
fs.readdirSync(dir, { withFileTypes: true })
|
|
55
|
+
.filter((dirent) => dirent.isDirectory())
|
|
56
|
+
.map((dirent) => dirent.name)
|
|
57
|
+
.forEach((name) => {
|
|
58
|
+
const specPath = resolve(dir, name, `${name}.json`);
|
|
59
|
+
if (!fs.existsSync(specPath)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const specRaw = fs.readFileSync(specPath, "utf-8");
|
|
63
|
+
try {
|
|
64
|
+
const spec = JSON.parse(specRaw);
|
|
65
|
+
if (spec.id) {
|
|
66
|
+
documentTypesMap[spec.id] = {
|
|
67
|
+
name: pascalCase(name),
|
|
68
|
+
importPath: join(pathOrigin, dir, name, "index.js"),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
console.error(`Failed to parse ${specPath}`);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return documentTypesMap;
|
|
78
|
+
}
|
|
41
79
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/codegen/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/codegen/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAY;IAEZ,IAAI,aAAuC,CAAC;IAC5C,I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AAC;QACH,CAAC,CAAC,CAAC;IACP,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clones a git repository and returns the path to the cloned project.
|
|
3
|
+
* @param repositoryUrl - The URL of the git repository to clone
|
|
4
|
+
* @returns The absolute path to the cloned project directory
|
|
5
|
+
*/
|
|
6
|
+
export declare function cloneRepository(repositoryUrl: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Installs dependencies in a project directory using the specified package manager.
|
|
9
|
+
* @param projectPath - The absolute path to the project directory
|
|
10
|
+
* @param packageManager - The package manager to use (npm, pnpm, yarn, bun)
|
|
11
|
+
*/
|
|
12
|
+
export declare function installDependencies(projectPath: string, packageManager: string): void;
|
|
13
|
+
//# sourceMappingURL=checkout-project.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout-project.d.ts","sourceRoot":"","sources":["../../../src/create-lib/checkout-project.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CA0B7D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,GACrB,IAAI,CAiBN"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { runCmd } from "./utils.js";
|
|
3
|
+
/**
|
|
4
|
+
* Clones a git repository and returns the path to the cloned project.
|
|
5
|
+
* @param repositoryUrl - The URL of the git repository to clone
|
|
6
|
+
* @returns The absolute path to the cloned project directory
|
|
7
|
+
*/
|
|
8
|
+
export function cloneRepository(repositoryUrl) {
|
|
9
|
+
try {
|
|
10
|
+
console.log("\x1b[33m", `Cloning repository from ${repositoryUrl}...`, "\x1b[0m");
|
|
11
|
+
runCmd(`git clone ${repositoryUrl}`);
|
|
12
|
+
// Extract project name from repository URL
|
|
13
|
+
// e.g., https://github.com/org/repo.git -> repo
|
|
14
|
+
const repoName = repositoryUrl
|
|
15
|
+
.split("/")
|
|
16
|
+
.pop()
|
|
17
|
+
?.replace(/\.git$/, "");
|
|
18
|
+
if (!repoName) {
|
|
19
|
+
throw new Error("Could not determine project name from repository URL");
|
|
20
|
+
}
|
|
21
|
+
const projectPath = path.join(process.cwd(), repoName);
|
|
22
|
+
return projectPath;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.log(error);
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Installs dependencies in a project directory using the specified package manager.
|
|
31
|
+
* @param projectPath - The absolute path to the project directory
|
|
32
|
+
* @param packageManager - The package manager to use (npm, pnpm, yarn, bun)
|
|
33
|
+
*/
|
|
34
|
+
export function installDependencies(projectPath, packageManager) {
|
|
35
|
+
try {
|
|
36
|
+
process.chdir(projectPath);
|
|
37
|
+
console.log("\x1b[34m", `Installing dependencies with ${packageManager}...`, "\x1b[0m");
|
|
38
|
+
runCmd(`${packageManager} install --loglevel error`);
|
|
39
|
+
console.log("\x1b[32m", "Dependencies installed successfully!", "\x1b[0m");
|
|
40
|
+
console.log();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.log(error);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=checkout-project.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout-project.js","sourceRoot":"","sources":["../../../src/create-lib/checkout-project.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,aAAqB;IACnD,IAAI,CAAC;QACH,OAAO,CAAC,GAAG,CACT,UAAU,EACV,2BAA2B,aAAa,KA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
-
readonly "--
|
|
4
|
+
readonly "--branch": StringConstructor;
|
|
5
|
+
readonly "--tag": StringConstructor;
|
|
5
6
|
readonly "--interactive": BooleanConstructor;
|
|
6
7
|
readonly "--dev": BooleanConstructor;
|
|
7
8
|
readonly "--staging": BooleanConstructor;
|
|
8
9
|
readonly "-p": "--name";
|
|
9
|
-
readonly "-
|
|
10
|
+
readonly "-b": "--branch";
|
|
11
|
+
readonly "-t": "--tag";
|
|
10
12
|
readonly "--package-manager": StringConstructor;
|
|
11
13
|
};
|
|
12
14
|
export interface ICreateProjectOptions {
|
|
13
15
|
name: string | undefined;
|
|
14
|
-
|
|
16
|
+
tag: string;
|
|
15
17
|
interactive: boolean;
|
|
18
|
+
branch?: string;
|
|
16
19
|
packageManager?: string;
|
|
20
|
+
vetraDriveUrl?: string;
|
|
17
21
|
}
|
|
18
|
-
export declare function
|
|
19
|
-
|
|
22
|
+
export declare function parseTag(args: {
|
|
23
|
+
tag?: string;
|
|
20
24
|
dev?: boolean;
|
|
21
25
|
staging?: boolean;
|
|
22
26
|
}): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-project.d.ts","sourceRoot":"","sources":["../../../src/create-lib/create-project.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-project.d.ts","sourceRoot":"","sources":["../../../src/create-lib/create-project.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,iBAAiB;;;;;;;;;;;;CAYpB,CAAC;AAEX,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAuED,wBAAgB,QAAQ,CAAC,IAAI,EAAE;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,UAWA;AAUD,wBAAgB,OAAO,kBAStB;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,qBAAqB,iBAuDjE"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { parseArgs, promptDirectories } from "
|
|
2
|
-
import { getPackageManager } from "#utils/package-manager";
|
|
3
|
-
import { execSync } from "child_process";
|
|
1
|
+
import { parseArgs, promptDirectories } from "@powerhousedao/codegen";
|
|
4
2
|
import enquirer from "enquirer";
|
|
5
3
|
import fs from "node:fs";
|
|
6
4
|
import path from "path";
|
|
5
|
+
import { featureFlags } from "./feature-flags.js";
|
|
6
|
+
import { envPackageManager, runCmd } from "./utils.js";
|
|
7
7
|
const BOILERPLATE_REPO = "https://github.com/powerhouse-inc/document-model-boilerplate.git";
|
|
8
|
-
const envPackageManager = getPackageManager(process.env.npm_config_user_agent);
|
|
9
8
|
const defaultDirectories = {
|
|
10
9
|
documentModelsDir: "./document-models",
|
|
11
10
|
editorsDir: "./editors",
|
|
@@ -13,12 +12,14 @@ const defaultDirectories = {
|
|
|
13
12
|
export const createCommandSpec = {
|
|
14
13
|
"--name": String,
|
|
15
14
|
"--project-name": "--name",
|
|
16
|
-
"--
|
|
15
|
+
"--branch": String,
|
|
16
|
+
"--tag": String,
|
|
17
17
|
"--interactive": Boolean,
|
|
18
18
|
"--dev": Boolean,
|
|
19
19
|
"--staging": Boolean,
|
|
20
20
|
"-p": "--name",
|
|
21
|
-
"-
|
|
21
|
+
"-b": "--branch",
|
|
22
|
+
"-t": "--tag",
|
|
22
23
|
"--package-manager": String,
|
|
23
24
|
};
|
|
24
25
|
const { prompt } = enquirer;
|
|
@@ -32,7 +33,7 @@ function buildPackageJson(appPath, projectName) {
|
|
|
32
33
|
};
|
|
33
34
|
fs.writeFileSync(path.join(appPath, "package.json"), JSON.stringify(newPackage, null, 2), "utf8");
|
|
34
35
|
}
|
|
35
|
-
function buildPowerhouseConfig(appPath, documentModelsDir, editorsDir) {
|
|
36
|
+
function buildPowerhouseConfig(appPath, documentModelsDir, editorsDir, vetraDriveUrl) {
|
|
36
37
|
const filePath = path.join(appPath, "powerhouse.config.json");
|
|
37
38
|
const packageJson = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
38
39
|
const newPackage = {
|
|
@@ -40,6 +41,14 @@ function buildPowerhouseConfig(appPath, documentModelsDir, editorsDir) {
|
|
|
40
41
|
documentModelsDir,
|
|
41
42
|
editorsDir,
|
|
42
43
|
};
|
|
44
|
+
// Add vetra configuration if vetraDriveUrl is provided
|
|
45
|
+
if (vetraDriveUrl) {
|
|
46
|
+
const driveId = vetraDriveUrl.split("/").pop();
|
|
47
|
+
newPackage.vetra = {
|
|
48
|
+
driveId: driveId ?? "",
|
|
49
|
+
driveUrl: vetraDriveUrl,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
43
52
|
fs.writeFileSync(filePath, JSON.stringify(newPackage, null, 2), "utf8");
|
|
44
53
|
}
|
|
45
54
|
function buildIndex(appPath, documentModelsDir, editorsDir) {
|
|
@@ -53,17 +62,9 @@ export const documentModels = Object.values(documentModelsExports);
|
|
|
53
62
|
export const editors = Object.values(editorsExports);
|
|
54
63
|
`, "utf8");
|
|
55
64
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
console.log("\x1b[31m", error, "\x1b[0m");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
export function parseVersion(args) {
|
|
65
|
-
if (args.version) {
|
|
66
|
-
return args.version;
|
|
65
|
+
export function parseTag(args) {
|
|
66
|
+
if (args.tag) {
|
|
67
|
+
return args.tag;
|
|
67
68
|
}
|
|
68
69
|
if (args.dev) {
|
|
69
70
|
return "dev";
|
|
@@ -75,9 +76,9 @@ export function parseVersion(args) {
|
|
|
75
76
|
return "main";
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
|
-
function
|
|
79
|
-
return
|
|
80
|
-
|
|
79
|
+
function parseTagArgs(args) {
|
|
80
|
+
return parseTag({
|
|
81
|
+
tag: args["--tag"],
|
|
81
82
|
dev: args["--dev"],
|
|
82
83
|
staging: args["--staging"],
|
|
83
84
|
});
|
|
@@ -87,7 +88,8 @@ export function initCli() {
|
|
|
87
88
|
const options = {
|
|
88
89
|
name: args["--name"] ?? args._.shift(),
|
|
89
90
|
interactive: args["--interactive"] ?? false,
|
|
90
|
-
|
|
91
|
+
tag: parseTagArgs(args),
|
|
92
|
+
branch: args["--branch"],
|
|
91
93
|
};
|
|
92
94
|
return createProject(options);
|
|
93
95
|
}
|
|
@@ -110,9 +112,13 @@ export async function createProject(options) {
|
|
|
110
112
|
}
|
|
111
113
|
projectName = result.projectName;
|
|
112
114
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
let documentModelsDir = defaultDirectories.documentModelsDir;
|
|
116
|
+
let editorsDir = defaultDirectories.editorsDir;
|
|
117
|
+
if (featureFlags.allowCustomDirectories && options.interactive) {
|
|
118
|
+
const result = await promptDirectories(defaultDirectories);
|
|
119
|
+
documentModelsDir = result.documentModelsDir;
|
|
120
|
+
editorsDir = result.editorsDir;
|
|
121
|
+
}
|
|
116
122
|
const appPath = path.join(process.cwd(), projectName);
|
|
117
123
|
try {
|
|
118
124
|
fs.mkdirSync(appPath);
|
|
@@ -126,19 +132,20 @@ export async function createProject(options) {
|
|
|
126
132
|
}
|
|
127
133
|
process.exit(1);
|
|
128
134
|
}
|
|
129
|
-
handleCreateProject(projectName, documentModelsDir, editorsDir, options.
|
|
135
|
+
handleCreateProject(projectName, documentModelsDir, editorsDir, options.tag, options.branch, options.packageManager, options.vetraDriveUrl);
|
|
130
136
|
}
|
|
131
|
-
function handleCreateProject(projectName, documentModelsDir, editorsDir,
|
|
137
|
+
function handleCreateProject(projectName, documentModelsDir, editorsDir, tag = "main", branch, packageManager, vetraDriveUrl) {
|
|
138
|
+
branch = branch ?? tag;
|
|
132
139
|
packageManager = packageManager ?? envPackageManager;
|
|
133
140
|
try {
|
|
134
141
|
console.log("\x1b[33m", "Downloading the project structure...", "\x1b[0m");
|
|
135
|
-
runCmd(`git clone --depth 1 -b ${
|
|
142
|
+
runCmd(`git clone --depth 1 -b ${branch} ${BOILERPLATE_REPO} ${projectName}`);
|
|
136
143
|
const appPath = path.join(process.cwd(), projectName);
|
|
137
144
|
process.chdir(appPath);
|
|
138
145
|
console.log("\x1b[34m", `Installing dependencies with ${packageManager}...`, "\x1b[0m");
|
|
139
146
|
runCmd(`${packageManager} install --loglevel error`);
|
|
140
147
|
fs.rmSync(path.join(appPath, "./.git"), { recursive: true });
|
|
141
|
-
runCmd(`git init -b ${
|
|
148
|
+
runCmd(`git init -b ${tag}`);
|
|
142
149
|
try {
|
|
143
150
|
fs.mkdirSync(path.join(appPath, documentModelsDir));
|
|
144
151
|
fs.writeFileSync(path.join(appPath, documentModelsDir, "index.ts"), "");
|
|
@@ -151,7 +158,7 @@ function handleCreateProject(projectName, documentModelsDir, editorsDir, version
|
|
|
151
158
|
}
|
|
152
159
|
}
|
|
153
160
|
buildPackageJson(appPath, projectName);
|
|
154
|
-
buildPowerhouseConfig(appPath, documentModelsDir, editorsDir);
|
|
161
|
+
buildPowerhouseConfig(appPath, documentModelsDir, editorsDir, vetraDriveUrl);
|
|
155
162
|
buildIndex(appPath, documentModelsDir, editorsDir);
|
|
156
163
|
console.log("\x1b[32m", "The installation is done!", "\x1b[0m");
|
|
157
164
|
console.log();
|