@powerhousedao/codegen 4.1.0-dev.3 → 4.1.0-dev.30

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.
Files changed (98) hide show
  1. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/index.d.ts +14 -0
  2. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/index.d.ts.map +1 -0
  3. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/index.js +12 -0
  4. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/index.js.map +1 -0
  5. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/resolvers.esm.t +17 -0
  6. package/dist/src/codegen/.hygen/templates/powerhouse/generate-custom-subgraph/schema.esm.t +16 -0
  7. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/object.esm.t +3 -3
  8. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/reducer.esm.t +3 -0
  9. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/types.esm.t +2 -2
  10. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/utils.esm.t +2 -1
  11. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/customTest.esm.t +2 -2
  12. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/error.esm.t +6 -10
  13. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts +4 -0
  14. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts.map +1 -1
  15. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js +13 -1
  16. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.js.map +1 -1
  17. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/resolvers.esm.t +59 -50
  18. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/schema.esm.t +3 -3
  19. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/CreateDocument.esm.t +45 -24
  20. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/DriveExplorer.esm.t +248 -181
  21. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/EditorContainer.esm.t +53 -72
  22. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/FolderTree.esm.t +44 -26
  23. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/editor.esm.t +22 -58
  24. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.d.ts +16 -0
  25. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.d.ts.map +1 -0
  26. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.esm.t +2 -3
  27. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.js +12 -0
  28. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/index.js.map +1 -0
  29. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.d.ts +2 -0
  30. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.d.ts.map +1 -1
  31. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.esm.t +1 -1
  32. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js +1 -0
  33. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js.map +1 -1
  34. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/factory.esm.t +2 -1
  35. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-analytics/lib.esm.t +7 -5
  36. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/factory.esm.t +3 -2
  37. package/dist/src/codegen/.hygen/templates/powerhouse/generate-processor-relationalDb/lib.esm.t +6 -5
  38. package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/index.esm.t +0 -32
  39. package/dist/src/codegen/graphql.d.ts +5 -1
  40. package/dist/src/codegen/graphql.d.ts.map +1 -1
  41. package/dist/src/codegen/graphql.js +28 -5
  42. package/dist/src/codegen/graphql.js.map +1 -1
  43. package/dist/src/codegen/hygen.d.ts +7 -4
  44. package/dist/src/codegen/hygen.d.ts.map +1 -1
  45. package/dist/src/codegen/hygen.js +50 -7
  46. package/dist/src/codegen/hygen.js.map +1 -1
  47. package/dist/src/codegen/index.d.ts +7 -6
  48. package/dist/src/codegen/index.d.ts.map +1 -1
  49. package/dist/src/codegen/index.js +82 -5
  50. package/dist/src/codegen/index.js.map +1 -1
  51. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts +10 -0
  52. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts.map +1 -0
  53. package/dist/src/ts-morph-generator/core/FileGenerator.js +9 -0
  54. package/dist/src/ts-morph-generator/core/FileGenerator.js.map +1 -0
  55. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts +30 -0
  56. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts.map +1 -0
  57. package/dist/src/ts-morph-generator/core/GenerationContext.js +2 -0
  58. package/dist/src/ts-morph-generator/core/GenerationContext.js.map +1 -0
  59. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts +19 -0
  60. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts.map +1 -0
  61. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js +114 -0
  62. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js.map +1 -0
  63. package/dist/src/ts-morph-generator/core/index.d.ts +4 -0
  64. package/dist/src/ts-morph-generator/core/index.d.ts.map +1 -0
  65. package/dist/src/ts-morph-generator/core/index.js +4 -0
  66. package/dist/src/ts-morph-generator/core/index.js.map +1 -0
  67. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.d.ts +12 -0
  68. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.d.ts.map +1 -0
  69. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.js +140 -0
  70. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.js.map +1 -0
  71. package/dist/src/ts-morph-generator/file-generators/index.d.ts +2 -0
  72. package/dist/src/ts-morph-generator/file-generators/index.d.ts.map +1 -0
  73. package/dist/src/ts-morph-generator/file-generators/index.js +2 -0
  74. package/dist/src/ts-morph-generator/file-generators/index.js.map +1 -0
  75. package/dist/src/ts-morph-generator/index.d.ts +4 -0
  76. package/dist/src/ts-morph-generator/index.d.ts.map +1 -0
  77. package/dist/src/ts-morph-generator/index.js +4 -0
  78. package/dist/src/ts-morph-generator/index.js.map +1 -0
  79. package/dist/src/ts-morph-generator/utilities/DirectoryManager.d.ts +13 -0
  80. package/dist/src/ts-morph-generator/utilities/DirectoryManager.d.ts.map +1 -0
  81. package/dist/src/ts-morph-generator/utilities/DirectoryManager.js +45 -0
  82. package/dist/src/ts-morph-generator/utilities/DirectoryManager.js.map +1 -0
  83. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts +14 -0
  84. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts.map +1 -0
  85. package/dist/src/ts-morph-generator/utilities/ImportManager.js +40 -0
  86. package/dist/src/ts-morph-generator/utilities/ImportManager.js.map +1 -0
  87. package/dist/src/ts-morph-generator/utilities/index.d.ts +3 -0
  88. package/dist/src/ts-morph-generator/utilities/index.d.ts.map +1 -0
  89. package/dist/src/ts-morph-generator/utilities/index.js +3 -0
  90. package/dist/src/ts-morph-generator/utilities/index.js.map +1 -0
  91. package/dist/tsconfig.hygen.tsbuildinfo +1 -1
  92. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  93. package/package.json +14 -6
  94. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/customReducers.esm.t +0 -20
  95. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/FileItemsGrid.esm.t +0 -44
  96. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/components/FolderItemsGrid.esm.t +0 -96
  97. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/hooks/useSelectedFolderChildren.esm.t +0 -35
  98. package/dist/src/codegen/.hygen/templates/powerhouse/generate-drive-editor/hooks/useTransformedNodes.esm.t +0 -35
@@ -0,0 +1,140 @@
1
+ import { camelCase, paramCase, pascalCase } from "change-case";
2
+ import { SyntaxKind, VariableDeclarationKind, } from "ts-morph";
3
+ import { FileGenerator } from "../core/FileGenerator.js";
4
+ export class ReducerGenerator extends FileGenerator {
5
+ async generate(context) {
6
+ // Skip if no actions to generate
7
+ if (context.operations.length === 0)
8
+ return;
9
+ const filePath = this.getOutputPath(context);
10
+ const sourceFile = await this.directoryManager.createSourceFile(context.project, filePath);
11
+ // Reducer-specific import logic
12
+ const typeImportName = `${pascalCase(context.docModel.name)}${pascalCase(context.module.name)}Operations`;
13
+ const typeImportPath = `../../gen/${paramCase(context.module.name)}/operations.js`;
14
+ // Import management (shared utility)
15
+ this.importManager.addTypeImport(sourceFile, typeImportName, typeImportPath);
16
+ // AST logic (specific to reducers)
17
+ this.createReducerObject(sourceFile, typeImportName, context.operations, context.forceUpdate);
18
+ // Detect and import error classes used in the actual reducer code (after generation)
19
+ this.addErrorImports(sourceFile, context);
20
+ await sourceFile.save();
21
+ }
22
+ static getDefaultReducerCode(methodName) {
23
+ return [
24
+ `// TODO: Implement "${methodName}" reducer`,
25
+ `throw new Error('Reducer "${methodName}" not yet implemented');`,
26
+ ];
27
+ }
28
+ addErrorImports(sourceFile, context) {
29
+ // Collect all errors from all operations
30
+ const allErrors = [];
31
+ context.operations.forEach((operation) => {
32
+ if (Array.isArray(operation.errors)) {
33
+ operation.errors
34
+ .filter((error) => error.name)
35
+ .forEach((error) => {
36
+ // Deduplicate errors by name
37
+ if (!allErrors.find((e) => e.name === error.name)) {
38
+ allErrors.push(error);
39
+ }
40
+ });
41
+ }
42
+ });
43
+ if (allErrors.length === 0)
44
+ return;
45
+ // Analyze the actual source file content to find which errors are used
46
+ const sourceFileContent = sourceFile.getFullText();
47
+ const usedErrors = new Set();
48
+ allErrors.forEach((error) => {
49
+ // Check if error class name is mentioned anywhere in the source file
50
+ // Look for patterns like "new ErrorName" or "throw ErrorName" or "ErrorName("
51
+ const errorPattern = new RegExp(`\\b${error.name}\\b`, "g");
52
+ if (errorPattern.test(sourceFileContent)) {
53
+ usedErrors.add(error.name);
54
+ }
55
+ });
56
+ // Add imports for used errors (only if they're not already imported)
57
+ if (usedErrors.size > 0) {
58
+ const errorImportPath = `../../gen/${paramCase(context.module.name)}/error.js`;
59
+ const errorClassNames = Array.from(usedErrors);
60
+ // Check if imports already exist to avoid duplicates
61
+ const existingImports = sourceFile.getImportDeclarations();
62
+ const existingErrorImport = existingImports.find((importDecl) => importDecl.getModuleSpecifierValue() === errorImportPath);
63
+ if (existingErrorImport) {
64
+ // Get already imported error names
65
+ const existingNamedImports = existingErrorImport
66
+ .getNamedImports()
67
+ .map((namedImport) => namedImport.getName());
68
+ // Only import errors that aren't already imported
69
+ const newErrorsToImport = errorClassNames.filter((errorName) => !existingNamedImports.includes(errorName));
70
+ if (newErrorsToImport.length > 0) {
71
+ // Add new named imports to existing import declaration
72
+ existingErrorImport.addNamedImports(newErrorsToImport);
73
+ }
74
+ }
75
+ else {
76
+ // Create new import declaration
77
+ this.importManager.addNamedImports(sourceFile, errorClassNames, errorImportPath);
78
+ }
79
+ }
80
+ }
81
+ getOutputPath(context) {
82
+ return this.directoryManager.getReducerPath(context.rootDir, context.docModel.name, context.module.name);
83
+ }
84
+ createReducerObject(sourceFile, typeName, operations, forceUpdate = false) {
85
+ let reducerVar = sourceFile.getVariableDeclaration("reducer");
86
+ if (!reducerVar) {
87
+ sourceFile.addVariableStatement({
88
+ declarationKind: VariableDeclarationKind.Const,
89
+ isExported: true,
90
+ declarations: [
91
+ {
92
+ name: "reducer",
93
+ type: typeName,
94
+ initializer: "{}",
95
+ },
96
+ ],
97
+ });
98
+ reducerVar = sourceFile.getVariableDeclarationOrThrow("reducer");
99
+ }
100
+ else {
101
+ // Ensure correct type
102
+ const typeNode = reducerVar.getTypeNode();
103
+ if (!typeNode || typeNode.getText() !== typeName) {
104
+ reducerVar.setType(typeName);
105
+ }
106
+ }
107
+ const initializer = reducerVar.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
108
+ for (const operation of operations) {
109
+ this.addReducerMethod(initializer, operation, forceUpdate);
110
+ }
111
+ }
112
+ addReducerMethod(objectLiteral, operation, forceUpdate = false) {
113
+ const actionName = camelCase(operation.name ?? "");
114
+ if (!actionName)
115
+ return;
116
+ const methodName = `${actionName}Operation`;
117
+ const reducerCode = operation.reducer?.trim();
118
+ const existingReducer = objectLiteral
119
+ .getProperty(methodName)
120
+ ?.asKind(SyntaxKind.MethodDeclaration);
121
+ // if reducer already exists but forceUpdate is true, update it
122
+ if (existingReducer) {
123
+ if (forceUpdate && reducerCode) {
124
+ existingReducer.setBodyText("");
125
+ this.setReducerMethodCode(existingReducer, reducerCode);
126
+ }
127
+ return;
128
+ }
129
+ // if reducer doesn't exist, create it and set the code with the default code if no code is provided
130
+ const method = objectLiteral.addMethod({
131
+ name: methodName,
132
+ parameters: [{ name: "state" }, { name: "action" }, { name: "dispatch" }],
133
+ });
134
+ this.setReducerMethodCode(method, reducerCode);
135
+ }
136
+ setReducerMethodCode(reducer, code) {
137
+ reducer.addStatements(code ? [code] : ReducerGenerator.getDefaultReducerCode(reducer.getName()));
138
+ }
139
+ }
140
+ //# sourceMappingURL=ReducerGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReducerGenerator.js","sourceRoot":"","sources":["../../../../src/ts-morph-generator/file-generators/ReducerGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EACL,UAAU,EACV,uBAAuB,GAIxB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAOzD,MAAM,OAAO,gBAAiB,SAAQ,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C;gBAC/B,eAAe,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;gBAChC,IAAI,CAAC,oBAAoB,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;YAC1D,CAAC;YACD,OAAO;QACT,CAAC;QAED,oGAAoG;QACpG,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC;YACrC,IAAI,EAAE,UAAU;YAChB,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;SAC1E,CAAC,CAAC;QACH,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACjD,CAAC;IAEO,oBAAoB,CAAC,OAA0B,EAAE,IAAa;QACpE,OAAO,CAAC,aAAa,CACnB,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAC1E,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export * from "./ReducerGenerator.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ts-morph-generator/file-generators/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./ReducerGenerator.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ts-morph-generator/file-generators/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./core/index.js";
2
+ export * from "./file-generators/index.js";
3
+ export * from "./utilities/index.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ts-morph-generator/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./core/index.js";
2
+ export * from "./file-generators/index.js";
3
+ export * from "./utilities/index.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ts-morph-generator/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { type Project, type SourceFile } from "ts-morph";
2
+ import { type PHProjectDirectories } from "../core/GenerationContext.js";
3
+ export declare class DirectoryManager {
4
+ private directories;
5
+ constructor(directories?: PHProjectDirectories);
6
+ ensureExists(dirPath: string): Promise<void>;
7
+ getReducerPath(rootDir: string, docModelName: string, moduleName: string): string;
8
+ getActionsPath(rootDir: string, docModelName: string, moduleName: string): string;
9
+ getComponentPath(rootDir: string, docModelName: string, componentName: string): string;
10
+ getTypesPath(rootDir: string, docModelName: string): string;
11
+ createSourceFile(project: Project, filePath: string): Promise<SourceFile>;
12
+ }
13
+ //# sourceMappingURL=DirectoryManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DirectoryManager.d.ts","sourceRoot":"","sources":["../../../../src/ts-morph-generator/utilities/DirectoryManager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,WAAW,CAKjB;gBAEU,WAAW,GAAE,oBAAyB;IAM5C,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUlD,cAAc,CACZ,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,MAAM;IAWT,cAAc,CACZ,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,MAAM;IAWT,gBAAgB,CACd,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,GACpB,MAAM;IAWT,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM;IAUrD,gBAAgB,CACpB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,CAAC;CAOvB"}
@@ -0,0 +1,45 @@
1
+ import { paramCase, pascalCase } from "change-case";
2
+ import fs from "fs/promises";
3
+ import path from "path";
4
+ export class DirectoryManager {
5
+ directories = {
6
+ documentModelDir: "document-model",
7
+ editorsDir: "editors",
8
+ processorsDir: "processors",
9
+ subgraphsDir: "subgraphs",
10
+ };
11
+ constructor(directories = {}) {
12
+ this.directories = {
13
+ ...this.directories,
14
+ ...directories,
15
+ };
16
+ }
17
+ async ensureExists(dirPath) {
18
+ try {
19
+ await fs.mkdir(dirPath, { recursive: true });
20
+ }
21
+ catch (err) {
22
+ console.error(`Failed to create directory: ${dirPath}`, err);
23
+ throw err;
24
+ }
25
+ }
26
+ // Path builders for different file types
27
+ getReducerPath(rootDir, docModelName, moduleName) {
28
+ return path.join(rootDir, this.directories.documentModelDir, paramCase(docModelName), "src", "reducers", `${paramCase(moduleName)}.ts`);
29
+ }
30
+ getActionsPath(rootDir, docModelName, moduleName) {
31
+ return path.join(rootDir, this.directories.documentModelDir, paramCase(docModelName), "src", "actions", `${paramCase(moduleName)}.ts`);
32
+ }
33
+ getComponentPath(rootDir, docModelName, componentName) {
34
+ return path.join(rootDir, this.directories.documentModelDir, paramCase(docModelName), "src", "components", `${pascalCase(componentName)}.tsx`);
35
+ }
36
+ getTypesPath(rootDir, docModelName) {
37
+ return path.join(rootDir, this.directories.documentModelDir, paramCase(docModelName), "src", "types.ts");
38
+ }
39
+ async createSourceFile(project, filePath) {
40
+ await this.ensureExists(path.dirname(filePath));
41
+ return (project.addSourceFileAtPathIfExists(filePath) ??
42
+ project.createSourceFile(filePath, "", { overwrite: false }));
43
+ }
44
+ }
45
+ //# sourceMappingURL=DirectoryManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DirectoryManager.js","sourceRoot":"","sources":["../../../../src/ts-morph-generator/utilities/DirectoryManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,MAAM,OAAO,gBAAgB;IACnB,WAAW,GAAmC;QACpD,gBAAgB,EAAE,gBAAgB;QAClC,UAAU,EAAE,SAAS;QACrB,aAAa,EAAE,YAAY;QAC3B,YAAY,EAAE,WAAW;KAC1B,CAAC;IAEF,YAAY,cAAoC,EAAE;QAChD,IAAI,CAAC,WAAW,GAAG;YACjB,GAAG,IAAI,CAAC,WAAW;YACnB,GAAG,WAAW;SACf,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,YAAY,CAAC,OAAe;QAChC,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,+BAA+B,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;YAC7D,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;IAED,yCAAyC;IACzC,cAAc,CACZ,OAAe,EACf,YAAoB,EACpB,UAAkB;QAElB,OAAO,IAAI,CAAC,IAAI,CACd,OAAO,EACP,I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ier: string;
4
+ namedImports?: string[];
5
+ defaultImport?: string;
6
+ isTypeOnly?: boolean;
7
+ }
8
+ export declare class ImportManager {
9
+ addImport(sourceFile: SourceFile, spec: ImportSpec): void;
10
+ addTypeImport(sourceFile: SourceFile, typeName: string, path: string): void;
11
+ addNamedImports(sourceFile: SourceFile, imports: string[], path: string): void;
12
+ private mergeImports;
13
+ }
14
+ //# sourceMappingURL=ImportManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImportManager.d.ts","sourceRoot":"","sources":["../../../../src/ts-morph-generator/utilities/ImportManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAEnE,MAAM,WAAW,UAAU;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,qBAAa,aAAa;IACxB,SAAS,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI;IAazD,aAAa,CAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ3E,eAAe,CACb,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,MAAM,EAAE,EACjB,IAAI,EAAE,MAAM,GACX,IAAI;IAOP,OAAO,CAAC,YAAY;CAkBrB"}
@@ -0,0 +1,40 @@
1
+ export class ImportManager {
2
+ addImport(sourceFile, spec) {
3
+ // Check if import already exists
4
+ const existing = sourceFile
5
+ .getImportDeclarations()
6
+ .find((imp) => imp.getModuleSpecifierValue() === spec.moduleSpecifier);
7
+ if (existing) {
8
+ this.mergeImports(existing, spec);
9
+ }
10
+ else {
11
+ sourceFile.addImportDeclaration(spec);
12
+ }
13
+ }
14
+ addTypeImport(sourceFile, typeName, path) {
15
+ this.addImport(sourceFile, {
16
+ moduleSpecifier: path,
17
+ namedImports: [typeName],
18
+ isTypeOnly: true,
19
+ });
20
+ }
21
+ addNamedImports(sourceFile, imports, path) {
22
+ this.addImport(sourceFile, {
23
+ moduleSpecifier: path,
24
+ namedImports: imports,
25
+ });
26
+ }
27
+ mergeImports(existingImport, newSpec) {
28
+ // Logic to merge named imports if they don't already exist
29
+ if (newSpec.namedImports) {
30
+ const existingNames = existingImport
31
+ .getNamedImports()
32
+ .map((ni) => ni.getName());
33
+ const newNames = newSpec.namedImports.filter((name) => !existingNames.includes(name));
34
+ if (newNames.length > 0) {
35
+ existingImport.addNamedImports(newNames);
36
+ }
37
+ }
38
+ }
39
+ }
40
+ //# sourceMappingURL=ImportManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImportManager.js","sourceRoot":"","sources":["../../../../src/ts-morph-generator/utilities/ImportManager.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,aAAa;IACxB,SAAS,CAAC,UAAsB,EAAE,IAAgB;QAChD,iCAAiC;QACjC,MAAM,QAAQ,GAAG,UAAU;aACxB,qBAAqB,EAAE;aACvB,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,uBAAuB,EAAE,KAAK,IAAI,CAAC,eAAe,CAAC,CAAC;QAEzE,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACpC,CAAC;aAAM,CAAC;YACN,UAAU,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,aAAa,CAAC,UAAsB,EAAE,QAAgB,EAAE,IAAY;QAClE,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE;YACzB,eAAe,EAAE,IAAI;YACrB,YAAY,EAAE,CAAC,QAAQ,CAAC;YACxB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;IACL,CAAC;IAED,eAAe,CACb,UAAsB,EACtB,OAAiB,EACjB,IAAY;QAEZ,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE;YACzB,eAAe,EAAE,IAAI;YACrB,YAAY,EAAE,OAAO;SACtB,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAClB,cAAiC,EACjC,OAAmB;QAEnB,2DAA2D;QAC3D,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;YACzB,MAAM,aAAa,GAAG,cAAc;iBACjC,eAAe,EAAE;iBACjB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;YAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,MAAM,CAC1C,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CACxC,CAAC;YAEF,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACxB,cAAc,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export * from "./DirectoryManager.js";
2
+ export * from "./ImportManager.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ts-morph-generator/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./DirectoryManager.js";
2
+ export * from "./ImportManager.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ts-morph-generator/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}