@powerhousedao/codegen 4.1.0-dev.1 → 4.1.0-dev.10

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 (62) hide show
  1. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/reducer.esm.t +1 -1
  2. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/types.esm.t +1 -1
  3. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/actions.esm.t +3 -3
  4. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts +1 -2
  5. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts.map +1 -1
  6. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/schema.esm.t +1 -1
  7. package/dist/src/codegen/graphql.d.ts +5 -1
  8. package/dist/src/codegen/graphql.d.ts.map +1 -1
  9. package/dist/src/codegen/graphql.js +28 -5
  10. package/dist/src/codegen/graphql.js.map +1 -1
  11. package/dist/src/codegen/hygen.d.ts +2 -1
  12. package/dist/src/codegen/hygen.d.ts.map +1 -1
  13. package/dist/src/codegen/hygen.js +17 -1
  14. package/dist/src/codegen/hygen.js.map +1 -1
  15. package/dist/src/codegen/index.d.ts +2 -3
  16. package/dist/src/codegen/index.d.ts.map +1 -1
  17. package/dist/src/codegen/index.js +11 -1
  18. package/dist/src/codegen/index.js.map +1 -1
  19. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts +10 -0
  20. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts.map +1 -0
  21. package/dist/src/ts-morph-generator/core/FileGenerator.js +9 -0
  22. package/dist/src/ts-morph-generator/core/FileGenerator.js.map +1 -0
  23. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts +28 -0
  24. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts.map +1 -0
  25. package/dist/src/ts-morph-generator/core/GenerationContext.js +2 -0
  26. package/dist/src/ts-morph-generator/core/GenerationContext.js.map +1 -0
  27. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts +18 -0
  28. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts.map +1 -0
  29. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js +112 -0
  30. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js.map +1 -0
  31. package/dist/src/ts-morph-generator/core/index.d.ts +4 -0
  32. package/dist/src/ts-morph-generator/core/index.d.ts.map +1 -0
  33. package/dist/src/ts-morph-generator/core/index.js +4 -0
  34. package/dist/src/ts-morph-generator/core/index.js.map +1 -0
  35. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.d.ts +9 -0
  36. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.d.ts.map +1 -0
  37. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.js +69 -0
  38. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.js.map +1 -0
  39. package/dist/src/ts-morph-generator/file-generators/index.d.ts +2 -0
  40. package/dist/src/ts-morph-generator/file-generators/index.d.ts.map +1 -0
  41. package/dist/src/ts-morph-generator/file-generators/index.js +2 -0
  42. package/dist/src/ts-morph-generator/file-generators/index.js.map +1 -0
  43. package/dist/src/ts-morph-generator/index.d.ts +4 -0
  44. package/dist/src/ts-morph-generator/index.d.ts.map +1 -0
  45. package/dist/src/ts-morph-generator/index.js +4 -0
  46. package/dist/src/ts-morph-generator/index.js.map +1 -0
  47. package/dist/src/ts-morph-generator/utilities/DirectoryManager.d.ts +13 -0
  48. package/dist/src/ts-morph-generator/utilities/DirectoryManager.d.ts.map +1 -0
  49. package/dist/src/ts-morph-generator/utilities/DirectoryManager.js +45 -0
  50. package/dist/src/ts-morph-generator/utilities/DirectoryManager.js.map +1 -0
  51. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts +14 -0
  52. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts.map +1 -0
  53. package/dist/src/ts-morph-generator/utilities/ImportManager.js +40 -0
  54. package/dist/src/ts-morph-generator/utilities/ImportManager.js.map +1 -0
  55. package/dist/src/ts-morph-generator/utilities/index.d.ts +3 -0
  56. package/dist/src/ts-morph-generator/utilities/index.d.ts.map +1 -0
  57. package/dist/src/ts-morph-generator/utilities/index.js +3 -0
  58. package/dist/src/ts-morph-generator/utilities/index.js.map +1 -0
  59. package/dist/tsconfig.hygen.tsbuildinfo +1 -1
  60. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  61. package/package.json +7 -6
  62. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/customReducers.esm.t +0 -20
@@ -0,0 +1,69 @@
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.actions.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.actions);
18
+ await sourceFile.save();
19
+ }
20
+ getOutputPath(context) {
21
+ return this.directoryManager.getReducerPath(context.rootDir, context.docModel.name, context.module.name);
22
+ }
23
+ createReducerObject(sourceFile, typeName, actions) {
24
+ let reducerVar = sourceFile.getVariableDeclaration("reducer");
25
+ if (!reducerVar) {
26
+ sourceFile.addVariableStatement({
27
+ declarationKind: VariableDeclarationKind.Const,
28
+ isExported: true,
29
+ declarations: [
30
+ {
31
+ name: "reducer",
32
+ type: typeName,
33
+ initializer: "{}",
34
+ },
35
+ ],
36
+ });
37
+ reducerVar = sourceFile.getVariableDeclarationOrThrow("reducer");
38
+ }
39
+ else {
40
+ // Ensure correct type
41
+ const typeNode = reducerVar.getTypeNode();
42
+ if (!typeNode || typeNode.getText() !== typeName) {
43
+ reducerVar.setType(typeName);
44
+ }
45
+ }
46
+ const initializer = reducerVar.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
47
+ for (const action of actions) {
48
+ this.addReducerMethod(initializer, action);
49
+ }
50
+ }
51
+ addReducerMethod(objectLiteral, action) {
52
+ const actionName = camelCase(action.name ?? "");
53
+ if (!actionName)
54
+ return;
55
+ const methodName = `${actionName}Operation`;
56
+ // Skip if method already exists
57
+ if (objectLiteral.getProperty(methodName))
58
+ return;
59
+ objectLiteral.addMethod({
60
+ name: methodName,
61
+ parameters: [{ name: "state" }, { name: "action" }, { name: "dispatch" }],
62
+ statements: [
63
+ `// TODO: Implement "${methodName}" reducer`,
64
+ `throw new Error('Reducer "${methodName}" not yet implemented');`,
65
+ ],
66
+ });
67
+ }
68
+ }
69
+ //# 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,GAGxB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzD,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IACjD,KAAK,CAAC,QAAQ,CAAC,OAA0B;QACvC,iCAAiC;QACjC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAEzC,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC7C,MAAM,UA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SAAS,CAAC,CAAC;QACnE,CAAC;aAAM,CAAC;YACN,sBAAsB;YACtB,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;YAC1C,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;gBACjD,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QAED,MAAM,WAAW,GAAG,UAAU,CAAC,2BAA2B,CACxD,UAAU,CAAC,uBAAuB,CACnC,CAAC;QAEF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAEO,gBAAgB,CACtB,aAAsC,EACtC,MAAe;QAEf,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,UAAU;YAAE,OAAO;QAExB,MAAM,UAAU,GAAG,GAAG,UAAU,WAAW,CAAC;QAE5C,gCAAgC;QAChC,IAAI,aAAa,CAAC,WAAW,CAAC,UAAU,CAAC;YAAE,OAAO;QAElD,aAAa,CAAC,SAAS,CAAC;YACtB,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;YACzE,UAAU,EAAE;gBACV,uBAAuB,UAAU,WAAW;gBAC5C,6BAA6B,UAAU,0BAA0B;aAClE;SACF,CAAC,CAAC;IACL,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,OAA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,gBAAgB,CACpB,OAAgB,EAChB,QAAgB;QAEhB,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QAChD,OAAO,CACL,OAAO,CAAC,2BAA2B,CAAC,QAAQ,CAAC;YAC7C,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAC7D,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ import { type SourceFile } from "ts-morph";
2
+ export interface ImportSpec {
3
+ moduleSpecifier: 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"}