@powerhousedao/codegen 6.0.0-dev.151 → 6.0.0-dev.153
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/{file-builders-CNatGM0p.mjs → file-builders-C2QoGrDi.mjs} +466 -467
- package/dist/file-builders-C2QoGrDi.mjs.map +1 -0
- package/dist/index.mjs +32 -34
- package/dist/index.mjs.map +1 -1
- package/dist/src/file-builders/index.mjs +2 -2
- package/dist/src/templates/index.d.mts +2 -3
- package/dist/src/templates/index.d.mts.map +1 -1
- package/dist/src/templates/index.mjs +1 -1
- package/dist/{templates-Bn7kq5sb.mjs → templates-Cu_xr8aR.mjs} +1767 -3
- package/dist/templates-Cu_xr8aR.mjs.map +1 -0
- package/package.json +6 -4
- package/dist/file-builders-CNatGM0p.mjs.map +0 -1
- package/dist/templates-Bn7kq5sb.mjs.map +0 -1
|
@@ -1,321 +1,22 @@
|
|
|
1
|
-
import { A as documentModelHooksFileTemplate, Bt as appDriveContentsFileTemplate, D as documentModelSrcIndexFileTemplate, E as documentModelSrcUtilsTemplate, F as documentModelPhFactoriesFileTemplate, Ft as folderTreeFileTemplate, G as documentModelGenControllerFileTemplate, H as documentModelDocumentTypeTemplate, I as documentModelOperationsModuleOperationsFileTemplate, It as appFoldersFileTemplate, J as documentEditorModuleFileTemplate, K as documentModelGenActionsFileTemplate, L as documentModelOperationsModuleErrorFileTemplate, Lt as appFilesFileTemplate, M as documentModelGenTypesTemplate, Mt as appEditorFileTemplate, N as documentModelSchemaIndexTemplate, Nt as appConfigFileTemplate, O as documentModelModuleFileTemplate, P as documentModelGenReducerFileTemplate, Pt as driveExplorerNavigationBreadcrumbsFileTemplate, R as documentModelOperationsModuleCreatorsFileTemplate, Rt as emptyStateFileTemplate, S as makeActionImportNames, T as documentModelTestFileTemplate, U as documentModelDocumentSchemaFileTemplate, V as documentModelGenIndexFileTemplate, Vt as createDocumentFileTemplate, W as documentModelGenCreatorsFileTemplate, X as docsFromCliHelpTemplate, Y as documentEditorEditorFileTemplate, _ as analyticsFactoryTemplate, a as subgraphLibFileTemplate, b as upgradeManifestTemplate, c as relationalDbProcessorTemplate, d as relationalDbFactoryTemplate, g as analyticsIndexTemplate, h as analyticsProcessorTemplate, i as customSubgraphSchemaTemplate, j as documentModelGenUtilsTemplate, k as documentModelIndexTemplate, l as relationalDbMigrationsTemplate, lt as packageJsonTemplate, m as factoryBuildersTemplate, n as documentModelSubgraphSchemaTemplate, o as subgraphIndexFileTemplate, q as documentModelRootActionsFileTemplate, r as customSubgraphResolversTemplate, s as relationalDbSchemaTemplate, t as documentModelSubgraphResolversTemplate, u as relationalDbIndexTemplate, v as documentModelUtilsTemplate, w as makeTestCaseForAction, y as upgradeTransitionTemplate, z as documentModelOperationModuleActionsFileTemplate, zt as driveExplorerFileTemplate } from "./templates-
|
|
1
|
+
import { A as documentModelHooksFileTemplate, Bt as appDriveContentsFileTemplate, D as documentModelSrcIndexFileTemplate, E as documentModelSrcUtilsTemplate, F as documentModelPhFactoriesFileTemplate, Ft as folderTreeFileTemplate, G as documentModelGenControllerFileTemplate, H as documentModelDocumentTypeTemplate, Ht as ts$1, I as documentModelOperationsModuleOperationsFileTemplate, It as appFoldersFileTemplate, J as documentEditorModuleFileTemplate, K as documentModelGenActionsFileTemplate, L as documentModelOperationsModuleErrorFileTemplate, Lt as appFilesFileTemplate, M as documentModelGenTypesTemplate, Mt as appEditorFileTemplate, N as documentModelSchemaIndexTemplate, Nt as appConfigFileTemplate, O as documentModelModuleFileTemplate, P as documentModelGenReducerFileTemplate, Pt as driveExplorerNavigationBreadcrumbsFileTemplate, R as documentModelOperationsModuleCreatorsFileTemplate, Rt as emptyStateFileTemplate, S as makeActionImportNames, T as documentModelTestFileTemplate, U as documentModelDocumentSchemaFileTemplate, V as documentModelGenIndexFileTemplate, Vt as createDocumentFileTemplate, W as documentModelGenCreatorsFileTemplate, X as docsFromCliHelpTemplate, Y as documentEditorEditorFileTemplate, _ as analyticsFactoryTemplate, a as subgraphLibFileTemplate, b as upgradeManifestTemplate, c as relationalDbProcessorTemplate, d as relationalDbFactoryTemplate, g as analyticsIndexTemplate, h as analyticsProcessorTemplate, i as customSubgraphSchemaTemplate, j as documentModelGenUtilsTemplate, k as documentModelIndexTemplate, l as relationalDbMigrationsTemplate, lt as packageJsonTemplate, m as factoryBuildersTemplate, n as documentModelSubgraphSchemaTemplate, o as subgraphIndexFileTemplate, q as documentModelRootActionsFileTemplate, r as customSubgraphResolversTemplate, s as relationalDbSchemaTemplate, t as documentModelSubgraphResolversTemplate, u as relationalDbIndexTemplate, v as documentModelUtilsTemplate, w as makeTestCaseForAction, y as upgradeTransitionTemplate, z as documentModelOperationModuleActionsFileTemplate, zt as driveExplorerFileTemplate } from "./templates-Cu_xr8aR.mjs";
|
|
2
2
|
import { getDocumentModelDirName, getDocumentModelOperationsModuleVariableNames, getDocumentModelVariableNames, getEditorVariableNames } from "./src/name-builders/index.mjs";
|
|
3
3
|
import { applyGraphQLTypePrefixes, buildObjectLiteral, buildTsMorphProject, ensureDirectoriesExist, extractTypeNames, formatSourceFileWithPrettier, getDocumentTypeMetadata, getInitialStates, getObjectLiteral, getOrCreateDirectory, getOrCreateSourceFile, getPreviousVersionSourceFile, getVariableDeclarationByTypeName } from "./src/utils/index.mjs";
|
|
4
4
|
import { VERSIONED_DEPENDENCIES, VERSIONED_DEV_DEPENDENCIES, directoryExists, fileExists, makeVersionedDependencies } from "@powerhousedao/shared/clis";
|
|
5
5
|
import { camelCase, kebabCase, pascalCase } from "change-case";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { ts } from "@tmpl/core";
|
|
9
|
-
import path$1 from "path";
|
|
10
|
-
import { IndentationText, Project, SyntaxKind, VariableDeclarationKind, ts as ts$1 } from "ts-morph";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { IndentationText, Project, SyntaxKind, VariableDeclarationKind, ts } from "ts-morph";
|
|
11
8
|
import { format } from "prettier";
|
|
9
|
+
import path$1 from "node:path";
|
|
10
|
+
import fs, { copyFile, mkdir, readdir, rename, writeFile } from "node:fs/promises";
|
|
11
|
+
import { stripVTControlCharacters } from "node:util";
|
|
12
12
|
import { generate } from "@graphql-codegen/cli";
|
|
13
13
|
import { generatorTypeDefs, validationSchema } from "@powerhousedao/document-engineering/graphql";
|
|
14
|
-
import { stripVTControlCharacters } from "node:util";
|
|
15
14
|
import { existsSync } from "fs";
|
|
16
|
-
//#region src/file-builders/processors/analytics.ts
|
|
17
|
-
async function tsMorphGenerateAnalyticsProcessor(args) {
|
|
18
|
-
const { project, documentTypes, pascalCaseName, dirPath, camelCaseName } = args;
|
|
19
|
-
await makeIndexFile$1({
|
|
20
|
-
project,
|
|
21
|
-
pascalCaseName,
|
|
22
|
-
dirPath
|
|
23
|
-
});
|
|
24
|
-
await makeProcessorFile$1({
|
|
25
|
-
project,
|
|
26
|
-
pascalCaseName,
|
|
27
|
-
dirPath
|
|
28
|
-
});
|
|
29
|
-
await makeFactoryFile$1({
|
|
30
|
-
project,
|
|
31
|
-
pascalCaseName,
|
|
32
|
-
camelCaseName,
|
|
33
|
-
dirPath,
|
|
34
|
-
documentTypes
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
async function makeIndexFile$1(v) {
|
|
38
|
-
const template = analyticsIndexTemplate;
|
|
39
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path$1.join(v.dirPath, "index.ts"));
|
|
40
|
-
if (alreadyExists) return;
|
|
41
|
-
sourceFile.replaceWithText(template);
|
|
42
|
-
await formatSourceFileWithPrettier(sourceFile);
|
|
43
|
-
}
|
|
44
|
-
async function makeProcessorFile$1(v) {
|
|
45
|
-
const template = analyticsProcessorTemplate(v);
|
|
46
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path$1.join(v.dirPath, "processor.ts"));
|
|
47
|
-
if (alreadyExists) return;
|
|
48
|
-
sourceFile.replaceWithText(template);
|
|
49
|
-
await formatSourceFileWithPrettier(sourceFile);
|
|
50
|
-
}
|
|
51
|
-
async function makeFactoryFile$1(v) {
|
|
52
|
-
const template = analyticsFactoryTemplate(v);
|
|
53
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path$1.join(v.dirPath, "factory.ts"));
|
|
54
|
-
if (alreadyExists) return;
|
|
55
|
-
sourceFile.replaceWithText(template);
|
|
56
|
-
await formatSourceFileWithPrettier(sourceFile);
|
|
57
|
-
}
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/file-builders/processors/relational-db.ts
|
|
60
|
-
async function tsMorphGenerateRelationalDbProcessor(args) {
|
|
61
|
-
const { project, documentTypes, camelCaseName, pascalCaseName, dirPath } = args;
|
|
62
|
-
await makeIndexFile({
|
|
63
|
-
project,
|
|
64
|
-
pascalCaseName,
|
|
65
|
-
dirPath
|
|
66
|
-
});
|
|
67
|
-
await makeProcessorFile({
|
|
68
|
-
project,
|
|
69
|
-
pascalCaseName,
|
|
70
|
-
dirPath
|
|
71
|
-
});
|
|
72
|
-
await makeFactoryFile({
|
|
73
|
-
project,
|
|
74
|
-
pascalCaseName,
|
|
75
|
-
camelCaseName,
|
|
76
|
-
dirPath,
|
|
77
|
-
documentTypes
|
|
78
|
-
});
|
|
79
|
-
await makeMigrationsFile({
|
|
80
|
-
project,
|
|
81
|
-
dirPath
|
|
82
|
-
});
|
|
83
|
-
await makeSchemaFile({
|
|
84
|
-
project,
|
|
85
|
-
dirPath
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
async function makeIndexFile(v) {
|
|
89
|
-
const template = relationalDbIndexTemplate;
|
|
90
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path$1.join(v.dirPath, "index.ts"));
|
|
91
|
-
if (alreadyExists) return;
|
|
92
|
-
sourceFile.replaceWithText(template);
|
|
93
|
-
await formatSourceFileWithPrettier(sourceFile);
|
|
94
|
-
}
|
|
95
|
-
async function makeProcessorFile(v) {
|
|
96
|
-
const template = relationalDbProcessorTemplate(v);
|
|
97
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path$1.join(v.dirPath, "processor.ts"));
|
|
98
|
-
if (alreadyExists) return;
|
|
99
|
-
sourceFile.replaceWithText(template);
|
|
100
|
-
await formatSourceFileWithPrettier(sourceFile);
|
|
101
|
-
}
|
|
102
|
-
async function makeFactoryFile(v) {
|
|
103
|
-
const template = relationalDbFactoryTemplate(v);
|
|
104
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path$1.join(v.dirPath, "factory.ts"));
|
|
105
|
-
if (alreadyExists) return;
|
|
106
|
-
sourceFile.replaceWithText(template);
|
|
107
|
-
await formatSourceFileWithPrettier(sourceFile);
|
|
108
|
-
}
|
|
109
|
-
async function makeSchemaFile(v) {
|
|
110
|
-
const template = relationalDbSchemaTemplate();
|
|
111
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path$1.join(v.dirPath, "schema.ts"));
|
|
112
|
-
if (alreadyExists) return;
|
|
113
|
-
sourceFile.replaceWithText(template);
|
|
114
|
-
await formatSourceFileWithPrettier(sourceFile);
|
|
115
|
-
}
|
|
116
|
-
async function makeMigrationsFile(v) {
|
|
117
|
-
const template = relationalDbMigrationsTemplate();
|
|
118
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path$1.join(v.dirPath, "migrations.ts"));
|
|
119
|
-
if (alreadyExists) return;
|
|
120
|
-
sourceFile.replaceWithText(template);
|
|
121
|
-
await formatSourceFileWithPrettier(sourceFile);
|
|
122
|
-
}
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region src/file-builders/processors/processor.ts
|
|
125
|
-
async function tsMorphGenerateProcessor(args) {
|
|
126
|
-
const { processorName, documentTypes, rootDir, processorType, processorApps } = args;
|
|
127
|
-
const kebabCaseName = kebabCase(processorName);
|
|
128
|
-
const camelCaseName = camelCase(processorName);
|
|
129
|
-
const pascalCaseName = pascalCase(processorName);
|
|
130
|
-
const processorsDirPath = path$1.join(rootDir, "processors");
|
|
131
|
-
const dirPath = path$1.join(processorsDirPath, kebabCaseName);
|
|
132
|
-
const sourceFilesPath = path$1.join(processorsDirPath, "**/*");
|
|
133
|
-
const project = buildTsMorphProject(rootDir);
|
|
134
|
-
await ensureDirectoriesExist(project, processorsDirPath, dirPath);
|
|
135
|
-
project.addSourceFilesAtPaths(sourceFilesPath);
|
|
136
|
-
if (processorType === "analytics") await tsMorphGenerateAnalyticsProcessor({
|
|
137
|
-
processorName,
|
|
138
|
-
documentTypes,
|
|
139
|
-
rootDir,
|
|
140
|
-
camelCaseName,
|
|
141
|
-
dirPath,
|
|
142
|
-
kebabCaseName,
|
|
143
|
-
pascalCaseName,
|
|
144
|
-
processorsDirPath,
|
|
145
|
-
project
|
|
146
|
-
});
|
|
147
|
-
else await tsMorphGenerateRelationalDbProcessor({
|
|
148
|
-
processorName,
|
|
149
|
-
documentTypes,
|
|
150
|
-
rootDir,
|
|
151
|
-
camelCaseName,
|
|
152
|
-
dirPath,
|
|
153
|
-
kebabCaseName,
|
|
154
|
-
pascalCaseName,
|
|
155
|
-
processorsDirPath,
|
|
156
|
-
project
|
|
157
|
-
});
|
|
158
|
-
for (const processorApp of processorApps) await updateFactoryBuildersFile({
|
|
159
|
-
processorsDirPath,
|
|
160
|
-
processorApp,
|
|
161
|
-
project,
|
|
162
|
-
camelCaseName,
|
|
163
|
-
kebabCaseName
|
|
164
|
-
});
|
|
165
|
-
await project.save();
|
|
166
|
-
}
|
|
167
|
-
async function updateFactoryBuildersFile(v) {
|
|
168
|
-
const { project, processorsDirPath, processorApp, camelCaseName, kebabCaseName } = v;
|
|
169
|
-
const template = factoryBuildersTemplate;
|
|
170
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path$1.join(processorsDirPath, `${processorApp}.ts`));
|
|
171
|
-
if (!alreadyExists) sourceFile.replaceWithText(template);
|
|
172
|
-
const name = `${camelCaseName}FactoryBuilder`;
|
|
173
|
-
const moduleSpecifier = path$1.join("processors", kebabCaseName);
|
|
174
|
-
const factoriesArrayName = "processorFactoryBuilders";
|
|
175
|
-
let factoryBuildersArray = getFactoryBuildersArray(sourceFile, factoriesArrayName);
|
|
176
|
-
if (!factoryBuildersArray) {
|
|
177
|
-
sourceFile.replaceWithText(template);
|
|
178
|
-
factoryBuildersArray = getFactoryBuildersArray(sourceFile, factoriesArrayName);
|
|
179
|
-
}
|
|
180
|
-
if (!factoryBuildersArray) throw new Error(`Could not get factory builders array in file ${processorApp}.ts`);
|
|
181
|
-
if (!sourceFile.getImportDeclarations().flatMap((importDeclaration) => importDeclaration.getNamedImports().map((n) => n.getText())).find((n) => n === name)) sourceFile.addImportDeclaration({
|
|
182
|
-
namedImports: [name],
|
|
183
|
-
moduleSpecifier
|
|
184
|
-
});
|
|
185
|
-
if (!factoryBuildersArray.getElements().map((e) => e.getText()).includes(name)) factoryBuildersArray.addElement(name);
|
|
186
|
-
await formatSourceFileWithPrettier(sourceFile);
|
|
187
|
-
}
|
|
188
|
-
function getFactoryBuildersArray(sourceFile, name) {
|
|
189
|
-
return sourceFile.getDescendantsOfKind(ts$1.SyntaxKind.VariableStatement).flatMap((d) => d.getDescendantsOfKind(ts$1.SyntaxKind.VariableDeclaration)).find((d) => d.getName() === name)?.getDescendantsOfKind(ts$1.SyntaxKind.ArrayLiteralExpression).at(0);
|
|
190
|
-
}
|
|
191
|
-
//#endregion
|
|
192
|
-
//#region src/codegen/graphql.ts
|
|
193
|
-
const getDirectories = async (source) => {
|
|
194
|
-
return (await fs.readdir(source, { withFileTypes: true })).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent);
|
|
195
|
-
};
|
|
196
|
-
const scalars = {
|
|
197
|
-
Unknown: "unknown",
|
|
198
|
-
DateTime: "string",
|
|
199
|
-
Attachment: "string",
|
|
200
|
-
Address: "`${string}:0x${string}`",
|
|
201
|
-
...generatorTypeDefs
|
|
202
|
-
};
|
|
203
|
-
const scalarsValidation = {
|
|
204
|
-
Unknown: "z.unknown()",
|
|
205
|
-
DateTime: "z.string().datetime()",
|
|
206
|
-
Attachment: "z.string()",
|
|
207
|
-
Address: "z.custom<`${string}:0x${string}`>((val) => /^[a-zA-Z0-9]+:0x[a-fA-F0-9]{40}$/.test(val as string))",
|
|
208
|
-
...validationSchema
|
|
209
|
-
};
|
|
210
|
-
const avoidOptionals = {
|
|
211
|
-
field: true,
|
|
212
|
-
inputValue: false
|
|
213
|
-
};
|
|
214
|
-
const maybeValue = "T | null | undefined";
|
|
215
|
-
const typescriptConfig = {
|
|
216
|
-
avoidOptionals,
|
|
217
|
-
scalars,
|
|
218
|
-
strictScalars: true,
|
|
219
|
-
enumsAsTypes: true,
|
|
220
|
-
skipTypename: true,
|
|
221
|
-
maybeValue
|
|
222
|
-
};
|
|
223
|
-
const validationSchemaConfig = {
|
|
224
|
-
avoidOptionals,
|
|
225
|
-
scalars,
|
|
226
|
-
strictScalars: true,
|
|
227
|
-
enumsAsTypes: true,
|
|
228
|
-
skipTypename: true,
|
|
229
|
-
importFrom: `./types.js`,
|
|
230
|
-
schema: "zodv4",
|
|
231
|
-
useTypeImports: true,
|
|
232
|
-
scalarSchemas: scalarsValidation,
|
|
233
|
-
directives: { equals: { value: ["regex", "/^$1$/"] } },
|
|
234
|
-
withObjectType: true,
|
|
235
|
-
maybeValue
|
|
236
|
-
};
|
|
237
|
-
function buildSchemasForModules(modules) {
|
|
238
|
-
const schemaStrings = [];
|
|
239
|
-
for (const module of modules) {
|
|
240
|
-
schemaStrings.push(`# ${module.name}`);
|
|
241
|
-
const operationsSchemas = module.operations.map((operation) => operation.schema).filter((schema) => schema !== null);
|
|
242
|
-
schemaStrings.push(...operationsSchemas);
|
|
243
|
-
}
|
|
244
|
-
return schemaStrings;
|
|
245
|
-
}
|
|
246
|
-
function buildGraphqlDocumentStringForSpecification(specification) {
|
|
247
|
-
const customScalarSchemas = Object.keys(scalars).map((k) => `scalar ${k}`).join("\n");
|
|
248
|
-
const stateSchemas = Object.values(specification.state).map((state) => state.schema);
|
|
249
|
-
const moduleSchemas = buildSchemasForModules(specification.modules);
|
|
250
|
-
return [
|
|
251
|
-
customScalarSchemas,
|
|
252
|
-
...stateSchemas,
|
|
253
|
-
...moduleSchemas
|
|
254
|
-
];
|
|
255
|
-
}
|
|
256
|
-
async function formatContentWithPrettier(path, content) {
|
|
257
|
-
return await format(content, { parser: "typescript" });
|
|
258
|
-
}
|
|
259
|
-
async function generateTypesAndZodSchemasFromGraphql(args) {
|
|
260
|
-
const { dirName, schema, skipFormat, writeFile, watch } = args;
|
|
261
|
-
await generate({
|
|
262
|
-
overwrite: true,
|
|
263
|
-
watch,
|
|
264
|
-
hooks: { beforeOneFileWrite: skipFormat ? void 0 : formatContentWithPrettier },
|
|
265
|
-
generates: {
|
|
266
|
-
[`${dirName}/gen/schema/types.ts`]: {
|
|
267
|
-
schema,
|
|
268
|
-
config: typescriptConfig,
|
|
269
|
-
plugins: [{ typescript: typescriptConfig }]
|
|
270
|
-
},
|
|
271
|
-
[`${dirName}/gen/schema/zod.ts`]: {
|
|
272
|
-
schema,
|
|
273
|
-
config: validationSchemaConfig,
|
|
274
|
-
plugins: [{ add: { content: "/* eslint-disable @typescript-eslint/no-empty-object-type */" } }, { "graphql-codegen-typescript-validation-schema": validationSchemaConfig }]
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}, writeFile);
|
|
278
|
-
}
|
|
279
|
-
async function generateDocumentModelZodSchemas(args) {
|
|
280
|
-
const { documentModelDirPath, specification, writeFile = true, skipFormat = false, watch = false } = args;
|
|
281
|
-
const schema = buildGraphqlDocumentStringForSpecification(specification).filter(Boolean).join("\n\n");
|
|
282
|
-
await generateTypesAndZodSchemasFromGraphql({
|
|
283
|
-
dirName: documentModelDirPath,
|
|
284
|
-
schema,
|
|
285
|
-
writeFile,
|
|
286
|
-
skipFormat,
|
|
287
|
-
watch
|
|
288
|
-
});
|
|
289
|
-
await fs.writeFile(path.join(documentModelDirPath, "schema.graphql"), schema);
|
|
290
|
-
}
|
|
291
|
-
const generateSchemas = async (inDir, { watch = false, skipFormat = false, writeFile = true, outDir = inDir } = {}) => {
|
|
292
|
-
const dirs = await getDirectories(inDir);
|
|
293
|
-
const inputs = await Promise.all(dirs.map(async (dir) => {
|
|
294
|
-
const documentModelJsonFile = await fs.readFile(path.join(dir.parentPath, dir.name, `${dir.name}.json`), "utf-8");
|
|
295
|
-
const parsedJson = JSON.parse(documentModelJsonFile);
|
|
296
|
-
const latestSpecification = parsedJson.specifications[parsedJson.specifications.length - 1];
|
|
297
|
-
const schema = buildGraphqlDocumentStringForSpecification(latestSpecification).filter(Boolean).join("\n\n");
|
|
298
|
-
return {
|
|
299
|
-
dirName: path.join(outDir, dir.name),
|
|
300
|
-
schema
|
|
301
|
-
};
|
|
302
|
-
}));
|
|
303
|
-
await Promise.all(inputs.map(async ({ schema, dirName }) => {
|
|
304
|
-
await generateTypesAndZodSchemasFromGraphql({
|
|
305
|
-
schema,
|
|
306
|
-
dirName,
|
|
307
|
-
writeFile,
|
|
308
|
-
skipFormat,
|
|
309
|
-
watch
|
|
310
|
-
});
|
|
311
|
-
}));
|
|
312
|
-
};
|
|
313
|
-
//#endregion
|
|
314
15
|
//#region src/file-builders/editor-common.ts
|
|
315
16
|
/** Generates the `module.ts` file for a document editor or app */
|
|
316
17
|
function makeEditorModuleFile({ project, editorDirPath, editorName, documentModelId, editorId, legacyMultipleDocumentTypes }) {
|
|
317
18
|
if (documentModelId && !!legacyMultipleDocumentTypes) throw new Error("Cannot specify both documentModelId and legacyMultipleDocumentTypes");
|
|
318
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
19
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(editorDirPath, "module.ts"));
|
|
319
20
|
sourceFile.replaceWithText("");
|
|
320
21
|
const template = documentEditorModuleFileTemplate({
|
|
321
22
|
editorName,
|
|
@@ -331,7 +32,7 @@ function makeEditorModuleFile({ project, editorDirPath, editorName, documentMode
|
|
|
331
32
|
* Makes a legacy index.ts file for the modules file which exports the modules as individual exports instead of an array of named exports.
|
|
332
33
|
*/
|
|
333
34
|
function makeLegacyIndexFile({ project, modulesDirPath, modules }) {
|
|
334
|
-
const indexSourceFilePath = path.join(modulesDirPath, "index.ts");
|
|
35
|
+
const indexSourceFilePath = path$1.join(modulesDirPath, "index.ts");
|
|
335
36
|
let indexSourceFile = project.getSourceFile(indexSourceFilePath);
|
|
336
37
|
if (!indexSourceFile) indexSourceFile = project.createSourceFile(indexSourceFilePath, "");
|
|
337
38
|
else indexSourceFile.replaceWithText("");
|
|
@@ -347,7 +48,7 @@ function makeLegacyIndexFile({ project, modulesDirPath, modules }) {
|
|
|
347
48
|
*/
|
|
348
49
|
async function makeModulesFile({ project, modulesDirPath, outputFileName, typeName, variableName, variableType, shouldMakeLegacyIndexFile = true, moduleFileName = "module.ts" }) {
|
|
349
50
|
await ensureDirectoriesExist(project, modulesDirPath);
|
|
350
|
-
const modulesSourceFilesPath = path.join(modulesDirPath, "**/*");
|
|
51
|
+
const modulesSourceFilesPath = path$1.join(modulesDirPath, "**/*");
|
|
351
52
|
project.addSourceFilesAtPaths(modulesSourceFilesPath);
|
|
352
53
|
const { directory: modulesDir } = getOrCreateDirectory(project, modulesDirPath);
|
|
353
54
|
const modules = modulesDir.getDescendantSourceFiles().filter((file) => file.getBaseName().includes(moduleFileName)).map((file) => getVariableDeclarationByTypeName(file, typeName)).filter((v) => v !== void 0).map((module) => {
|
|
@@ -361,7 +62,7 @@ async function makeModulesFile({ project, modulesDirPath, outputFileName, typeNa
|
|
|
361
62
|
moduleSpecifier
|
|
362
63
|
};
|
|
363
64
|
});
|
|
364
|
-
const { sourceFile: moduleExportsSourceFile } = getOrCreateSourceFile(project, path.join(modulesDirPath, outputFileName));
|
|
65
|
+
const { sourceFile: moduleExportsSourceFile } = getOrCreateSourceFile(project, path$1.join(modulesDirPath, outputFileName));
|
|
365
66
|
moduleExportsSourceFile.replaceWithText("");
|
|
366
67
|
const importDeclarations = [{
|
|
367
68
|
namedImports: [typeName],
|
|
@@ -396,7 +97,7 @@ async function makeUpgradeManifestsFile(args) {
|
|
|
396
97
|
const { project, projectDir } = args;
|
|
397
98
|
await makeModulesFile({
|
|
398
99
|
project,
|
|
399
|
-
modulesDirPath: path.join(projectDir, "document-models"),
|
|
100
|
+
modulesDirPath: path$1.join(projectDir, "document-models"),
|
|
400
101
|
outputFileName: "upgrade-manifests.ts",
|
|
401
102
|
typeName: "UpgradeManifest",
|
|
402
103
|
variableName: "upgradeManifests",
|
|
@@ -409,7 +110,7 @@ async function makeUpgradeManifestsFile(args) {
|
|
|
409
110
|
async function makeDocumentModelModulesFile({ project, projectDir }) {
|
|
410
111
|
await makeModulesFile({
|
|
411
112
|
project,
|
|
412
|
-
modulesDirPath: path.join(projectDir, "document-models"),
|
|
113
|
+
modulesDirPath: path$1.join(projectDir, "document-models"),
|
|
413
114
|
outputFileName: "document-models.ts",
|
|
414
115
|
typeName: "DocumentModelModule",
|
|
415
116
|
variableName: "documentModels",
|
|
@@ -420,7 +121,7 @@ async function makeDocumentModelModulesFile({ project, projectDir }) {
|
|
|
420
121
|
async function makeEditorsModulesFile(project, projectDir) {
|
|
421
122
|
await makeModulesFile({
|
|
422
123
|
project,
|
|
423
|
-
modulesDirPath: path.join(projectDir, "editors"),
|
|
124
|
+
modulesDirPath: path$1.join(projectDir, "editors"),
|
|
424
125
|
outputFileName: "editors.ts",
|
|
425
126
|
typeName: "EditorModule",
|
|
426
127
|
variableName: "editors",
|
|
@@ -436,8 +137,8 @@ function getVersionDirFromModuleSpecifier(moduleSpecifier) {
|
|
|
436
137
|
* adds imports for each, and creates the upgradeManifests array export.
|
|
437
138
|
*/
|
|
438
139
|
function makeUpgradeManifestsExport({ project, modulesDirPath, outputFilePath, variableName, variableType, typeName }) {
|
|
439
|
-
const absoluteModulesDirPath = path.resolve(modulesDirPath);
|
|
440
|
-
const absoluteOutputFilePath = path.resolve(outputFilePath);
|
|
140
|
+
const absoluteModulesDirPath = path$1.resolve(modulesDirPath);
|
|
141
|
+
const absoluteOutputFilePath = path$1.resolve(outputFilePath);
|
|
441
142
|
const upgradeManifestGlob = `${absoluteModulesDirPath}/**/upgrade-manifest.ts`;
|
|
442
143
|
project.addSourceFilesAtPaths(upgradeManifestGlob);
|
|
443
144
|
const upgradeManifestFiles = project.getSourceFiles().filter((file) => file.getFilePath().includes("upgrade-manifest.ts")).filter((file) => file.getFilePath().startsWith(absoluteModulesDirPath));
|
|
@@ -489,12 +190,12 @@ function makeUpgradeManifestsExport({ project, modulesDirPath, outputFilePath, v
|
|
|
489
190
|
//#region src/file-builders/app.ts
|
|
490
191
|
/** Generates a app with the configs for `allowedDocumentModelIds` and `isDragAndDropEnabled` */
|
|
491
192
|
async function tsMorphGenerateApp({ projectDir, editorDir, editorName, editorId, allowedDocumentModelIds, isDragAndDropEnabled }) {
|
|
492
|
-
const documentModelsDirPath = path
|
|
493
|
-
const documentModelsSourceFilesPath = path
|
|
494
|
-
const editorsDirPath = path
|
|
495
|
-
const editorSourceFilesPath = path
|
|
496
|
-
const editorDirPath = path
|
|
497
|
-
const editorComponentsDirPath = path
|
|
193
|
+
const documentModelsDirPath = path.join(projectDir, "document-models");
|
|
194
|
+
const documentModelsSourceFilesPath = path.join(documentModelsDirPath, "/**/*");
|
|
195
|
+
const editorsDirPath = path.join(projectDir, "editors");
|
|
196
|
+
const editorSourceFilesPath = path.join(editorsDirPath, "/**/*");
|
|
197
|
+
const editorDirPath = path.join(editorsDirPath, editorDir);
|
|
198
|
+
const editorComponentsDirPath = path.join(editorDirPath, "components");
|
|
498
199
|
const project = buildTsMorphProject(projectDir);
|
|
499
200
|
await ensureDirectoriesExist(project, documentModelsDirPath, editorsDirPath, editorDirPath, editorComponentsDirPath);
|
|
500
201
|
project.addSourceFilesAtPaths(documentModelsSourceFilesPath);
|
|
@@ -552,7 +253,7 @@ async function tsMorphGenerateApp({ projectDir, editorDir, editorName, editorId,
|
|
|
552
253
|
await project.save();
|
|
553
254
|
}
|
|
554
255
|
async function makeAppComponent({ project, editorDirPath }) {
|
|
555
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path
|
|
256
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(editorDirPath, "editor.tsx"));
|
|
556
257
|
if (alreadyExists) {
|
|
557
258
|
const editorFunction = sourceFile.getFunction("Editor");
|
|
558
259
|
if (editorFunction) {
|
|
@@ -565,7 +266,7 @@ async function makeAppComponent({ project, editorDirPath }) {
|
|
|
565
266
|
await formatSourceFileWithPrettier(sourceFile);
|
|
566
267
|
}
|
|
567
268
|
async function makeAppConfigFile({ project, editorDirPath, allowedDocumentModelIds, isDragAndDropEnabled }) {
|
|
568
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
269
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(editorDirPath, "config.ts"));
|
|
569
270
|
const allowedDocumentTypesString = JSON.stringify(allowedDocumentModelIds);
|
|
570
271
|
const template = appConfigFileTemplate({
|
|
571
272
|
isDragAndDropEnabledString: isDragAndDropEnabled ? "true" : "false",
|
|
@@ -575,52 +276,52 @@ async function makeAppConfigFile({ project, editorDirPath, allowedDocumentModelI
|
|
|
575
276
|
await formatSourceFileWithPrettier(sourceFile);
|
|
576
277
|
}
|
|
577
278
|
async function makeDriveContentsFile({ project, editorComponentsDirPath }) {
|
|
578
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path
|
|
279
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(editorComponentsDirPath, "DriveContents.tsx"));
|
|
579
280
|
if (alreadyExists) return;
|
|
580
281
|
const template = appDriveContentsFileTemplate();
|
|
581
282
|
sourceFile.replaceWithText(template);
|
|
582
283
|
await formatSourceFileWithPrettier(sourceFile);
|
|
583
284
|
}
|
|
584
285
|
async function makeNavigationBreadcrumbsFile({ project, editorComponentsDirPath }) {
|
|
585
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path
|
|
286
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(editorComponentsDirPath, "NavigationBreadcrumbs.tsx"));
|
|
586
287
|
if (alreadyExists) return;
|
|
587
288
|
sourceFile.replaceWithText(driveExplorerNavigationBreadcrumbsFileTemplate());
|
|
588
289
|
await formatSourceFileWithPrettier(sourceFile);
|
|
589
290
|
}
|
|
590
291
|
async function makeFoldersFile({ project, editorComponentsDirPath }) {
|
|
591
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path
|
|
292
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(editorComponentsDirPath, "Folders.tsx"));
|
|
592
293
|
if (alreadyExists) return;
|
|
593
294
|
const template = appFoldersFileTemplate();
|
|
594
295
|
sourceFile.replaceWithText(template);
|
|
595
296
|
await formatSourceFileWithPrettier(sourceFile);
|
|
596
297
|
}
|
|
597
298
|
async function makeFilesFile({ project, editorComponentsDirPath }) {
|
|
598
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path
|
|
299
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(editorComponentsDirPath, "Files.tsx"));
|
|
599
300
|
if (alreadyExists) return;
|
|
600
301
|
const template = appFilesFileTemplate();
|
|
601
302
|
sourceFile.replaceWithText(template);
|
|
602
303
|
await formatSourceFileWithPrettier(sourceFile);
|
|
603
304
|
}
|
|
604
305
|
async function makeDriveExplorerFile({ project, editorComponentsDirPath }) {
|
|
605
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path
|
|
306
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(editorComponentsDirPath, "DriveExplorer.tsx"));
|
|
606
307
|
if (alreadyExists) return;
|
|
607
308
|
sourceFile.replaceWithText(driveExplorerFileTemplate);
|
|
608
309
|
await formatSourceFileWithPrettier(sourceFile);
|
|
609
310
|
}
|
|
610
311
|
async function makeFolderTreeFile({ project, editorComponentsDirPath }) {
|
|
611
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path
|
|
312
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(editorComponentsDirPath, "FolderTree.tsx"));
|
|
612
313
|
if (alreadyExists) return;
|
|
613
314
|
sourceFile.replaceWithText(folderTreeFileTemplate);
|
|
614
315
|
await formatSourceFileWithPrettier(sourceFile);
|
|
615
316
|
}
|
|
616
317
|
async function makeEmptyStateFile({ project, editorComponentsDirPath }) {
|
|
617
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path
|
|
318
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(editorComponentsDirPath, "EmptyState.tsx"));
|
|
618
319
|
if (alreadyExists) return;
|
|
619
320
|
sourceFile.replaceWithText(emptyStateFileTemplate);
|
|
620
321
|
await formatSourceFileWithPrettier(sourceFile);
|
|
621
322
|
}
|
|
622
323
|
async function makeCreateDocumentFile({ project, editorComponentsDirPath }) {
|
|
623
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path
|
|
324
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(editorComponentsDirPath, "CreateDocument.tsx"));
|
|
624
325
|
if (alreadyExists) return;
|
|
625
326
|
sourceFile.replaceWithText(createDocumentFileTemplate);
|
|
626
327
|
await formatSourceFileWithPrettier(sourceFile);
|
|
@@ -664,56 +365,178 @@ async function writeCliDocsMarkdownFile(args) {
|
|
|
664
365
|
const { filePath, ...restArgs } = args;
|
|
665
366
|
await writeFile(filePath, makeCliDocsFromHelp(restArgs), { encoding: "utf-8" });
|
|
666
367
|
}
|
|
667
|
-
//#endregion
|
|
668
|
-
//#region src/file-builders/document-editor.ts
|
|
669
|
-
/** Generates a document editor for the given `documentModelId` (also called `documentType`) */
|
|
670
|
-
async function tsMorphGenerateDocumentEditor({ projectDir, editorDir, editorName, editorId, documentModelId }) {
|
|
671
|
-
const documentModelsDirPath = path
|
|
672
|
-
const editorsDirPath = path
|
|
673
|
-
const editorDirPath = path
|
|
674
|
-
const componentsDirPath = path
|
|
675
|
-
const editorSourceFilesPath = path
|
|
676
|
-
const documentModelsSourceFilesPath = path
|
|
677
|
-
const project = buildTsMorphProject(projectDir);
|
|
678
|
-
await ensureDirectoriesExist(project, documentModelsDirPath, editorsDirPath, editorDirPath, componentsDirPath);
|
|
679
|
-
project.addSourceFilesAtPaths(documentModelsSourceFilesPath);
|
|
680
|
-
project.addSourceFilesAtPaths(editorSourceFilesPath);
|
|
681
|
-
const documentTypeMetadata = getDocumentTypeMetadata({
|
|
682
|
-
project,
|
|
683
|
-
documentModelId,
|
|
684
|
-
documentModelsDirPath
|
|
685
|
-
});
|
|
686
|
-
const editorVariableNames = getEditorVariableNames(documentTypeMetadata);
|
|
687
|
-
await makeEditorComponent({
|
|
688
|
-
project,
|
|
689
|
-
editorDirPath,
|
|
690
|
-
...documentTypeMetadata,
|
|
691
|
-
...editorVariableNames
|
|
692
|
-
});
|
|
693
|
-
makeEditorModuleFile({
|
|
694
|
-
project,
|
|
695
|
-
editorName,
|
|
696
|
-
editorId,
|
|
697
|
-
documentModelId,
|
|
698
|
-
editorDirPath
|
|
699
|
-
});
|
|
700
|
-
await makeEditorsModulesFile(project, projectDir);
|
|
701
|
-
await project.save();
|
|
368
|
+
//#endregion
|
|
369
|
+
//#region src/file-builders/document-editor.ts
|
|
370
|
+
/** Generates a document editor for the given `documentModelId` (also called `documentType`) */
|
|
371
|
+
async function tsMorphGenerateDocumentEditor({ projectDir, editorDir, editorName, editorId, documentModelId }) {
|
|
372
|
+
const documentModelsDirPath = path.join(projectDir, "document-models");
|
|
373
|
+
const editorsDirPath = path.join(projectDir, "editors");
|
|
374
|
+
const editorDirPath = path.join(editorsDirPath, editorDir);
|
|
375
|
+
const componentsDirPath = path.join(editorDirPath, "components");
|
|
376
|
+
const editorSourceFilesPath = path.join(editorsDirPath, "/**/*");
|
|
377
|
+
const documentModelsSourceFilesPath = path.join(documentModelsDirPath, "/**/*");
|
|
378
|
+
const project = buildTsMorphProject(projectDir);
|
|
379
|
+
await ensureDirectoriesExist(project, documentModelsDirPath, editorsDirPath, editorDirPath, componentsDirPath);
|
|
380
|
+
project.addSourceFilesAtPaths(documentModelsSourceFilesPath);
|
|
381
|
+
project.addSourceFilesAtPaths(editorSourceFilesPath);
|
|
382
|
+
const documentTypeMetadata = getDocumentTypeMetadata({
|
|
383
|
+
project,
|
|
384
|
+
documentModelId,
|
|
385
|
+
documentModelsDirPath
|
|
386
|
+
});
|
|
387
|
+
const editorVariableNames = getEditorVariableNames(documentTypeMetadata);
|
|
388
|
+
await makeEditorComponent({
|
|
389
|
+
project,
|
|
390
|
+
editorDirPath,
|
|
391
|
+
...documentTypeMetadata,
|
|
392
|
+
...editorVariableNames
|
|
393
|
+
});
|
|
394
|
+
makeEditorModuleFile({
|
|
395
|
+
project,
|
|
396
|
+
editorName,
|
|
397
|
+
editorId,
|
|
398
|
+
documentModelId,
|
|
399
|
+
editorDirPath
|
|
400
|
+
});
|
|
401
|
+
await makeEditorsModulesFile(project, projectDir);
|
|
402
|
+
await project.save();
|
|
403
|
+
}
|
|
404
|
+
async function makeEditorComponent(args) {
|
|
405
|
+
const { project, editorDirPath } = args;
|
|
406
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(editorDirPath, "editor.tsx"));
|
|
407
|
+
if (alreadyExists) {
|
|
408
|
+
const functionDeclaration = sourceFile.getFunction("Editor");
|
|
409
|
+
if (functionDeclaration) {
|
|
410
|
+
if (!functionDeclaration.isDefaultExport()) functionDeclaration.setIsDefaultExport(true);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const template = documentEditorEditorFileTemplate(args);
|
|
415
|
+
sourceFile.replaceWithText(template);
|
|
416
|
+
await formatSourceFileWithPrettier(sourceFile);
|
|
417
|
+
}
|
|
418
|
+
//#endregion
|
|
419
|
+
//#region src/codegen/graphql.ts
|
|
420
|
+
const getDirectories = async (source) => {
|
|
421
|
+
return (await fs.readdir(source, { withFileTypes: true })).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent);
|
|
422
|
+
};
|
|
423
|
+
const scalars = {
|
|
424
|
+
Unknown: "unknown",
|
|
425
|
+
DateTime: "string",
|
|
426
|
+
Attachment: "string",
|
|
427
|
+
Address: "`${string}:0x${string}`",
|
|
428
|
+
...generatorTypeDefs
|
|
429
|
+
};
|
|
430
|
+
const scalarsValidation = {
|
|
431
|
+
Unknown: "z.unknown()",
|
|
432
|
+
DateTime: "z.string().datetime()",
|
|
433
|
+
Attachment: "z.string()",
|
|
434
|
+
Address: "z.custom<`${string}:0x${string}`>((val) => /^[a-zA-Z0-9]+:0x[a-fA-F0-9]{40}$/.test(val as string))",
|
|
435
|
+
...validationSchema
|
|
436
|
+
};
|
|
437
|
+
const avoidOptionals = {
|
|
438
|
+
field: true,
|
|
439
|
+
inputValue: false
|
|
440
|
+
};
|
|
441
|
+
const maybeValue = "T | null | undefined";
|
|
442
|
+
const typescriptConfig = {
|
|
443
|
+
avoidOptionals,
|
|
444
|
+
scalars,
|
|
445
|
+
strictScalars: true,
|
|
446
|
+
enumsAsTypes: true,
|
|
447
|
+
skipTypename: true,
|
|
448
|
+
maybeValue
|
|
449
|
+
};
|
|
450
|
+
const validationSchemaConfig = {
|
|
451
|
+
avoidOptionals,
|
|
452
|
+
scalars,
|
|
453
|
+
strictScalars: true,
|
|
454
|
+
enumsAsTypes: true,
|
|
455
|
+
skipTypename: true,
|
|
456
|
+
importFrom: `./types.js`,
|
|
457
|
+
schema: "zodv4",
|
|
458
|
+
useTypeImports: true,
|
|
459
|
+
scalarSchemas: scalarsValidation,
|
|
460
|
+
directives: { equals: { value: ["regex", "/^$1$/"] } },
|
|
461
|
+
withObjectType: true,
|
|
462
|
+
maybeValue
|
|
463
|
+
};
|
|
464
|
+
function buildSchemasForModules(modules) {
|
|
465
|
+
const schemaStrings = [];
|
|
466
|
+
for (const module of modules) {
|
|
467
|
+
schemaStrings.push(`# ${module.name}`);
|
|
468
|
+
const operationsSchemas = module.operations.map((operation) => operation.schema).filter((schema) => schema !== null);
|
|
469
|
+
schemaStrings.push(...operationsSchemas);
|
|
470
|
+
}
|
|
471
|
+
return schemaStrings;
|
|
472
|
+
}
|
|
473
|
+
function buildGraphqlDocumentStringForSpecification(specification) {
|
|
474
|
+
const customScalarSchemas = Object.keys(scalars).map((k) => `scalar ${k}`).join("\n");
|
|
475
|
+
const stateSchemas = Object.values(specification.state).map((state) => state.schema);
|
|
476
|
+
const moduleSchemas = buildSchemasForModules(specification.modules);
|
|
477
|
+
return [
|
|
478
|
+
customScalarSchemas,
|
|
479
|
+
...stateSchemas,
|
|
480
|
+
...moduleSchemas
|
|
481
|
+
];
|
|
482
|
+
}
|
|
483
|
+
async function formatContentWithPrettier(path, content) {
|
|
484
|
+
return await format(content, { parser: "typescript" });
|
|
702
485
|
}
|
|
703
|
-
async function
|
|
704
|
-
const {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
486
|
+
async function generateTypesAndZodSchemasFromGraphql(args) {
|
|
487
|
+
const { dirName, schema, skipFormat, writeFile, watch } = args;
|
|
488
|
+
await generate({
|
|
489
|
+
overwrite: true,
|
|
490
|
+
watch,
|
|
491
|
+
hooks: { beforeOneFileWrite: skipFormat ? void 0 : formatContentWithPrettier },
|
|
492
|
+
generates: {
|
|
493
|
+
[`${dirName}/gen/schema/types.ts`]: {
|
|
494
|
+
schema,
|
|
495
|
+
config: typescriptConfig,
|
|
496
|
+
plugins: [{ typescript: typescriptConfig }]
|
|
497
|
+
},
|
|
498
|
+
[`${dirName}/gen/schema/zod.ts`]: {
|
|
499
|
+
schema,
|
|
500
|
+
config: validationSchemaConfig,
|
|
501
|
+
plugins: [{ add: { content: "/* eslint-disable @typescript-eslint/no-empty-object-type */" } }, { "graphql-codegen-typescript-validation-schema": validationSchemaConfig }]
|
|
502
|
+
}
|
|
711
503
|
}
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
504
|
+
}, writeFile);
|
|
505
|
+
}
|
|
506
|
+
async function generateDocumentModelZodSchemas(args) {
|
|
507
|
+
const { documentModelDirPath, specification, writeFile = true, skipFormat = false, watch = false } = args;
|
|
508
|
+
const schema = buildGraphqlDocumentStringForSpecification(specification).filter(Boolean).join("\n\n");
|
|
509
|
+
await generateTypesAndZodSchemasFromGraphql({
|
|
510
|
+
dirName: documentModelDirPath,
|
|
511
|
+
schema,
|
|
512
|
+
writeFile,
|
|
513
|
+
skipFormat,
|
|
514
|
+
watch
|
|
515
|
+
});
|
|
516
|
+
await fs.writeFile(path$1.join(documentModelDirPath, "schema.graphql"), schema);
|
|
716
517
|
}
|
|
518
|
+
const generateSchemas = async (inDir, { watch = false, skipFormat = false, writeFile = true, outDir = inDir } = {}) => {
|
|
519
|
+
const dirs = await getDirectories(inDir);
|
|
520
|
+
const inputs = await Promise.all(dirs.map(async (dir) => {
|
|
521
|
+
const documentModelJsonFile = await fs.readFile(path$1.join(dir.parentPath, dir.name, `${dir.name}.json`), "utf-8");
|
|
522
|
+
const parsedJson = JSON.parse(documentModelJsonFile);
|
|
523
|
+
const latestSpecification = parsedJson.specifications[parsedJson.specifications.length - 1];
|
|
524
|
+
const schema = buildGraphqlDocumentStringForSpecification(latestSpecification).filter(Boolean).join("\n\n");
|
|
525
|
+
return {
|
|
526
|
+
dirName: path$1.join(outDir, dir.name),
|
|
527
|
+
schema
|
|
528
|
+
};
|
|
529
|
+
}));
|
|
530
|
+
await Promise.all(inputs.map(async ({ schema, dirName }) => {
|
|
531
|
+
await generateTypesAndZodSchemasFromGraphql({
|
|
532
|
+
schema,
|
|
533
|
+
dirName,
|
|
534
|
+
writeFile,
|
|
535
|
+
skipFormat,
|
|
536
|
+
watch
|
|
537
|
+
});
|
|
538
|
+
}));
|
|
539
|
+
};
|
|
717
540
|
//#endregion
|
|
718
541
|
//#region src/file-builders/document-model/gen-dir.ts
|
|
719
542
|
async function makeGenDirFiles(fileMakerArgs) {
|
|
@@ -748,34 +571,34 @@ async function makeGenDirOperationModuleFiles(fileMakerArgs) {
|
|
|
748
571
|
async function makeDocumentModelGenUtilsFile(args) {
|
|
749
572
|
const template = documentModelGenUtilsTemplate(args);
|
|
750
573
|
const { project, genDirPath } = args;
|
|
751
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
574
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(genDirPath, "utils.ts"));
|
|
752
575
|
sourceFile.replaceWithText(template);
|
|
753
576
|
await formatSourceFileWithPrettier(sourceFile);
|
|
754
577
|
}
|
|
755
578
|
async function makeDocumentModelDocumentTypeFile(args) {
|
|
756
579
|
const template = documentModelDocumentTypeTemplate(args);
|
|
757
580
|
const { project, genDirPath } = args;
|
|
758
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
581
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(genDirPath, "document-type.ts"));
|
|
759
582
|
sourceFile.replaceWithText(template);
|
|
760
583
|
await formatSourceFileWithPrettier(sourceFile);
|
|
761
584
|
}
|
|
762
585
|
async function makeDocumentModelSchemaIndexFile(args) {
|
|
763
586
|
const template = documentModelSchemaIndexTemplate;
|
|
764
587
|
const { project, schemaDirPath } = args;
|
|
765
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
588
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(schemaDirPath, "index.ts"));
|
|
766
589
|
sourceFile.replaceWithText(template);
|
|
767
590
|
await formatSourceFileWithPrettier(sourceFile);
|
|
768
591
|
}
|
|
769
592
|
async function makeDocumentModelGenTypesFile(args) {
|
|
770
593
|
const template = documentModelGenTypesTemplate(args);
|
|
771
594
|
const { project, genDirPath } = args;
|
|
772
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
595
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(genDirPath, "types.ts"));
|
|
773
596
|
sourceFile.replaceWithText(template);
|
|
774
597
|
await formatSourceFileWithPrettier(sourceFile);
|
|
775
598
|
}
|
|
776
599
|
async function makeDocumentModelGenDocumentModelFile(args) {
|
|
777
600
|
const { project, genDirPath, documentModelState } = args;
|
|
778
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
601
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(genDirPath, "document-model.ts"));
|
|
779
602
|
sourceFile.replaceWithText("");
|
|
780
603
|
sourceFile.addImportDeclaration({
|
|
781
604
|
namedImports: ["DocumentModelGlobalState"],
|
|
@@ -797,49 +620,49 @@ async function makeDocumentModelGenDocumentModelFile(args) {
|
|
|
797
620
|
async function makeDocumentModelGenDocumentSchemaFile(args) {
|
|
798
621
|
const template = documentModelDocumentSchemaFileTemplate(args);
|
|
799
622
|
const { project, genDirPath } = args;
|
|
800
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
623
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(genDirPath, "document-schema.ts"));
|
|
801
624
|
sourceFile.replaceWithText(template);
|
|
802
625
|
await formatSourceFileWithPrettier(sourceFile);
|
|
803
626
|
}
|
|
804
627
|
async function makeDocumentModelGenCreatorsFile(args) {
|
|
805
628
|
const template = documentModelGenCreatorsFileTemplate(args);
|
|
806
629
|
const { project, genDirPath } = args;
|
|
807
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
630
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(genDirPath, "creators.ts"));
|
|
808
631
|
sourceFile.replaceWithText(template);
|
|
809
632
|
await formatSourceFileWithPrettier(sourceFile);
|
|
810
633
|
}
|
|
811
634
|
async function makeDocumentModelGenPhFactoriesFile(args) {
|
|
812
635
|
const template = documentModelPhFactoriesFileTemplate(args);
|
|
813
636
|
const { project, genDirPath } = args;
|
|
814
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
637
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(genDirPath, "ph-factories.ts"));
|
|
815
638
|
sourceFile.replaceWithText(template);
|
|
816
639
|
await formatSourceFileWithPrettier(sourceFile);
|
|
817
640
|
}
|
|
818
641
|
async function makeDocumentModelGenControllerFile(args) {
|
|
819
642
|
const template = documentModelGenControllerFileTemplate(args);
|
|
820
643
|
const { project, genDirPath } = args;
|
|
821
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
644
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(genDirPath, "controller.ts"));
|
|
822
645
|
sourceFile.replaceWithText(template);
|
|
823
646
|
await formatSourceFileWithPrettier(sourceFile);
|
|
824
647
|
}
|
|
825
648
|
async function makeDocumentModelGenIndexFile(args) {
|
|
826
649
|
const template = documentModelGenIndexFileTemplate(args);
|
|
827
650
|
const { project, genDirPath } = args;
|
|
828
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
651
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(genDirPath, "index.ts"));
|
|
829
652
|
sourceFile.replaceWithText(template);
|
|
830
653
|
await formatSourceFileWithPrettier(sourceFile);
|
|
831
654
|
}
|
|
832
655
|
async function makeDocumentModelGenActionsFile(args) {
|
|
833
656
|
const template = documentModelGenActionsFileTemplate(args);
|
|
834
657
|
const { project, genDirPath } = args;
|
|
835
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
658
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(genDirPath, "actions.ts"));
|
|
836
659
|
sourceFile.replaceWithText(template);
|
|
837
660
|
await formatSourceFileWithPrettier(sourceFile);
|
|
838
661
|
}
|
|
839
662
|
async function makeDocumentModelGenReducerFile(args) {
|
|
840
663
|
const template = documentModelGenReducerFileTemplate(args);
|
|
841
664
|
const { project, genDirPath } = args;
|
|
842
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
665
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(genDirPath, "reducer.ts"));
|
|
843
666
|
sourceFile.replaceWithText(template);
|
|
844
667
|
await formatSourceFileWithPrettier(sourceFile);
|
|
845
668
|
}
|
|
@@ -854,8 +677,8 @@ async function makeOperationModuleGenActionsFile(args) {
|
|
|
854
677
|
pascalCaseModuleName
|
|
855
678
|
});
|
|
856
679
|
const { project, genDirPath } = args;
|
|
857
|
-
const dirPath = path
|
|
858
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
680
|
+
const dirPath = path.join(genDirPath, kebabCaseModuleName);
|
|
681
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(dirPath, "actions.ts"));
|
|
859
682
|
sourceFile.replaceWithText(template);
|
|
860
683
|
await formatSourceFileWithPrettier(sourceFile);
|
|
861
684
|
}
|
|
@@ -868,8 +691,8 @@ async function makeOperationModuleGenCreatorsFile(args) {
|
|
|
868
691
|
...moduleVariableNames
|
|
869
692
|
});
|
|
870
693
|
const { project, genDirPath } = args;
|
|
871
|
-
const dirPath = path
|
|
872
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
694
|
+
const dirPath = path.join(genDirPath, kebabCaseModuleName);
|
|
695
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(dirPath, "creators.ts"));
|
|
873
696
|
sourceFile.replaceWithText(template);
|
|
874
697
|
await formatSourceFileWithPrettier(sourceFile);
|
|
875
698
|
}
|
|
@@ -882,8 +705,8 @@ async function makeOperationModuleGenOperationsFile(args) {
|
|
|
882
705
|
...moduleVariableNames
|
|
883
706
|
});
|
|
884
707
|
const { project, genDirPath } = args;
|
|
885
|
-
const dirPath = path
|
|
886
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
708
|
+
const dirPath = path.join(genDirPath, kebabCaseModuleName);
|
|
709
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(dirPath, "operations.ts"));
|
|
887
710
|
sourceFile.replaceWithText(template);
|
|
888
711
|
await formatSourceFileWithPrettier(sourceFile);
|
|
889
712
|
}
|
|
@@ -896,8 +719,8 @@ async function makeOperationModuleGenErrorFile(args) {
|
|
|
896
719
|
...moduleVariableNames
|
|
897
720
|
});
|
|
898
721
|
const { project, genDirPath } = args;
|
|
899
|
-
const dirPath = path
|
|
900
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
722
|
+
const dirPath = path.join(genDirPath, kebabCaseModuleName);
|
|
723
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(dirPath, "error.ts"));
|
|
901
724
|
sourceFile.replaceWithText(template);
|
|
902
725
|
await formatSourceFileWithPrettier(sourceFile);
|
|
903
726
|
}
|
|
@@ -921,9 +744,9 @@ async function makeOperationModuleGenErrorFile(args) {
|
|
|
921
744
|
* no-op.
|
|
922
745
|
*/
|
|
923
746
|
async function migrateLegacyToVersioned(documentModelDirPath) {
|
|
924
|
-
const srcReducersPath = path
|
|
925
|
-
const v1Path = path
|
|
926
|
-
const legacyPath = path
|
|
747
|
+
const srcReducersPath = path.join(documentModelDirPath, "src", "reducers");
|
|
748
|
+
const v1Path = path.join(documentModelDirPath, "v1");
|
|
749
|
+
const legacyPath = path.join(documentModelDirPath, "legacy");
|
|
927
750
|
const hasSrcReducers = await directoryExists(srcReducersPath);
|
|
928
751
|
const hasV1 = await directoryExists(v1Path);
|
|
929
752
|
if (!hasSrcReducers || hasV1) return;
|
|
@@ -943,45 +766,45 @@ async function migrateLegacyToVersioned(documentModelDirPath) {
|
|
|
943
766
|
"schema.graphql"
|
|
944
767
|
];
|
|
945
768
|
for (const dirName of dirsToMove) {
|
|
946
|
-
const srcPath = path
|
|
769
|
+
const srcPath = path.join(documentModelDirPath, dirName);
|
|
947
770
|
if (await directoryExists(srcPath)) {
|
|
948
|
-
await rename(srcPath, path
|
|
771
|
+
await rename(srcPath, path.join(legacyPath, dirName));
|
|
949
772
|
console.log(`[migrate-legacy] Moved ${dirName}/ → legacy/${dirName}/`);
|
|
950
773
|
}
|
|
951
774
|
}
|
|
952
775
|
for (const fileName of filesToMove) {
|
|
953
|
-
const srcPath = path
|
|
776
|
+
const srcPath = path.join(documentModelDirPath, fileName);
|
|
954
777
|
if (await fileExists(srcPath)) {
|
|
955
|
-
await rename(srcPath, path
|
|
778
|
+
await rename(srcPath, path.join(legacyPath, fileName));
|
|
956
779
|
console.log(`[migrate-legacy] Moved ${fileName} → legacy/${fileName}`);
|
|
957
780
|
}
|
|
958
781
|
}
|
|
959
|
-
const v1SrcReducersPath = path
|
|
960
|
-
const v1SrcPath = path
|
|
961
|
-
const v1TestsPath = path
|
|
962
|
-
const legacySrcReducersPath = path
|
|
782
|
+
const v1SrcReducersPath = path.join(v1Path, "src", "reducers");
|
|
783
|
+
const v1SrcPath = path.join(v1Path, "src");
|
|
784
|
+
const v1TestsPath = path.join(v1Path, "tests");
|
|
785
|
+
const legacySrcReducersPath = path.join(legacyPath, "src", "reducers");
|
|
963
786
|
if (await directoryExists(legacySrcReducersPath)) {
|
|
964
787
|
await mkdir(v1SrcReducersPath, { recursive: true });
|
|
965
788
|
await copyDirectoryFiles(legacySrcReducersPath, v1SrcReducersPath);
|
|
966
789
|
console.log(`[migrate-legacy] Copied src/reducers/ → v1/src/reducers/`);
|
|
967
790
|
}
|
|
968
|
-
const legacySrcTestsPath = path
|
|
791
|
+
const legacySrcTestsPath = path.join(legacyPath, "src", "tests");
|
|
969
792
|
if (await directoryExists(legacySrcTestsPath)) {
|
|
970
|
-
const v1SrcTestsPath = path
|
|
793
|
+
const v1SrcTestsPath = path.join(v1SrcPath, "tests");
|
|
971
794
|
await mkdir(v1SrcTestsPath, { recursive: true });
|
|
972
795
|
await copyDirectoryFiles(legacySrcTestsPath, v1SrcTestsPath);
|
|
973
796
|
console.log(`[migrate-legacy] Copied src/tests/ → v1/src/tests/`);
|
|
974
797
|
}
|
|
975
|
-
const legacyTestsPath = path
|
|
798
|
+
const legacyTestsPath = path.join(legacyPath, "tests");
|
|
976
799
|
if (await directoryExists(legacyTestsPath)) {
|
|
977
800
|
await mkdir(v1TestsPath, { recursive: true });
|
|
978
801
|
await copyDirectoryFiles(legacyTestsPath, v1TestsPath);
|
|
979
802
|
console.log(`[migrate-legacy] Copied tests/ → v1/tests/`);
|
|
980
803
|
}
|
|
981
|
-
const legacyUtilsPath = path
|
|
804
|
+
const legacyUtilsPath = path.join(legacyPath, "src", "utils.ts");
|
|
982
805
|
if (await fileExists(legacyUtilsPath)) {
|
|
983
806
|
await mkdir(v1SrcPath, { recursive: true });
|
|
984
|
-
await copyFile(legacyUtilsPath, path
|
|
807
|
+
await copyFile(legacyUtilsPath, path.join(v1SrcPath, "utils.ts"));
|
|
985
808
|
console.log(`[migrate-legacy] Copied src/utils.ts → v1/src/utils.ts`);
|
|
986
809
|
}
|
|
987
810
|
console.log(`[migrate-legacy] Migration complete for ${documentModelDirPath}`);
|
|
@@ -989,7 +812,7 @@ async function migrateLegacyToVersioned(documentModelDirPath) {
|
|
|
989
812
|
/** Copy all files (non-recursive) from srcDir to destDir */
|
|
990
813
|
async function copyDirectoryFiles(srcDir, destDir) {
|
|
991
814
|
const entries = await readdir(srcDir, { withFileTypes: true });
|
|
992
|
-
for (const entry of entries) if (entry.isFile()) await copyFile(path
|
|
815
|
+
for (const entry of entries) if (entry.isFile()) await copyFile(path.join(srcDir, entry.name), path.join(destDir, entry.name));
|
|
993
816
|
}
|
|
994
817
|
//#endregion
|
|
995
818
|
//#region src/file-builders/document-model/root-dir.ts
|
|
@@ -1003,35 +826,35 @@ async function makeRootDirFiles(fileMakerArgs) {
|
|
|
1003
826
|
async function makeDocumentModelVersionIndexFile(args) {
|
|
1004
827
|
const template = documentModelIndexTemplate;
|
|
1005
828
|
const { project, documentModelVersionDirPath } = args;
|
|
1006
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
829
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(documentModelVersionDirPath, "index.ts"));
|
|
1007
830
|
sourceFile.replaceWithText(template);
|
|
1008
831
|
await formatSourceFileWithPrettier(sourceFile);
|
|
1009
832
|
}
|
|
1010
833
|
async function makeDocumentModelUtilsFile(args) {
|
|
1011
834
|
const template = documentModelUtilsTemplate(args);
|
|
1012
835
|
const { project, documentModelVersionDirPath } = args;
|
|
1013
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
836
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(documentModelVersionDirPath, "utils.ts"));
|
|
1014
837
|
sourceFile.replaceWithText(template);
|
|
1015
838
|
await formatSourceFileWithPrettier(sourceFile);
|
|
1016
839
|
}
|
|
1017
840
|
async function makeDocumentModelRootActionsFile(args) {
|
|
1018
841
|
const template = documentModelRootActionsFileTemplate(args);
|
|
1019
842
|
const { project, documentModelVersionDirPath } = args;
|
|
1020
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
843
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(documentModelVersionDirPath, "actions.ts"));
|
|
1021
844
|
sourceFile.replaceWithText(template);
|
|
1022
845
|
await formatSourceFileWithPrettier(sourceFile);
|
|
1023
846
|
}
|
|
1024
847
|
async function makeDocumentModelHooksFile(args) {
|
|
1025
848
|
const template = documentModelHooksFileTemplate(args);
|
|
1026
849
|
const { project, documentModelVersionDirPath } = args;
|
|
1027
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
850
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(documentModelVersionDirPath, "hooks.ts"));
|
|
1028
851
|
sourceFile.replaceWithText(template);
|
|
1029
852
|
await formatSourceFileWithPrettier(sourceFile);
|
|
1030
853
|
}
|
|
1031
854
|
async function makeDocumentModelModuleFile(args) {
|
|
1032
855
|
const { project, documentModelVersionDirPath } = args;
|
|
1033
856
|
const template = documentModelModuleFileTemplate(args);
|
|
1034
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
857
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(documentModelVersionDirPath, "module.ts"));
|
|
1035
858
|
sourceFile.replaceWithText(template);
|
|
1036
859
|
await formatSourceFileWithPrettier(sourceFile);
|
|
1037
860
|
}
|
|
@@ -1052,7 +875,7 @@ async function makeReducerOperationHandlersForModules(fileMakerArgs) {
|
|
|
1052
875
|
async function makeReducerOperationHandlerForModule({ project, module, version, reducersDirPath, pascalCaseDocumentType, camelCaseDocumentType, versionedDocumentModelPackageImportPath }) {
|
|
1053
876
|
const kebabCaseModuleName = kebabCase(module.name);
|
|
1054
877
|
const pascalCaseModuleName = pascalCase(module.name);
|
|
1055
|
-
const filePath = path
|
|
878
|
+
const filePath = path.join(reducersDirPath, `${kebabCaseModuleName}.ts`);
|
|
1056
879
|
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, filePath);
|
|
1057
880
|
if (!alreadyExists) {
|
|
1058
881
|
const previousVersionFile = getPreviousVersionSourceFile({
|
|
@@ -1095,7 +918,7 @@ async function makeReducerOperationHandlerForModule({ project, module, version,
|
|
|
1095
918
|
operationsInterfaceObject.addMethod({
|
|
1096
919
|
name,
|
|
1097
920
|
parameters: [{ name: "state" }, { name: "action" }],
|
|
1098
|
-
statements: reducerCode ? [reducerCode] : [`// TODO: implement ${name} reducer`, ts`throw new Error("Reducer for '${name}' not implemented.")`.raw]
|
|
921
|
+
statements: reducerCode ? [reducerCode] : [`// TODO: implement ${name} reducer`, ts$1`throw new Error("Reducer for '${name}' not implemented.")`.raw]
|
|
1099
922
|
});
|
|
1100
923
|
}
|
|
1101
924
|
addErrorImportsForModule(sourceFile, module);
|
|
@@ -1104,13 +927,13 @@ async function makeReducerOperationHandlerForModule({ project, module, version,
|
|
|
1104
927
|
async function makeDocumentModelSrcIndexFile({ project, ...variableNames }) {
|
|
1105
928
|
const template = documentModelSrcIndexFileTemplate;
|
|
1106
929
|
const { srcDirPath } = variableNames;
|
|
1107
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
930
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(srcDirPath, "index.ts"));
|
|
1108
931
|
sourceFile.replaceWithText(template);
|
|
1109
932
|
await formatSourceFileWithPrettier(sourceFile);
|
|
1110
933
|
}
|
|
1111
934
|
async function makeDocumentModelSrcUtilsFile({ project, srcDirPath, version }) {
|
|
1112
935
|
const template = documentModelSrcUtilsTemplate;
|
|
1113
|
-
const filePath = path
|
|
936
|
+
const filePath = path.join(srcDirPath, "utils.ts");
|
|
1114
937
|
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, filePath);
|
|
1115
938
|
if (!alreadyExists) {
|
|
1116
939
|
const previousVersionSourceFile = getPreviousVersionSourceFile({
|
|
@@ -1160,7 +983,7 @@ async function makeOperationModuleTestFile(args) {
|
|
|
1160
983
|
const { actions } = moduleVariableNames;
|
|
1161
984
|
const kebabCaseModuleName = kebabCase(module.name);
|
|
1162
985
|
const moduleOperationsTypeName = `${pascalCase(module.name)}Operations`;
|
|
1163
|
-
const filePath = path
|
|
986
|
+
const filePath = path.join(testsDirPath, `${kebabCaseModuleName}.test.ts`);
|
|
1164
987
|
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, filePath);
|
|
1165
988
|
if (!alreadyExists) {
|
|
1166
989
|
const previousVersionSourceFile = getPreviousVersionSourceFile({
|
|
@@ -1169,7 +992,7 @@ async function makeOperationModuleTestFile(args) {
|
|
|
1169
992
|
filePath
|
|
1170
993
|
});
|
|
1171
994
|
if (previousVersionSourceFile) sourceFile.replaceWithText(previousVersionSourceFile.getText());
|
|
1172
|
-
else sourceFile.replaceWithText(ts`
|
|
995
|
+
else sourceFile.replaceWithText(ts$1`
|
|
1173
996
|
import { generateMock } from "document-model";
|
|
1174
997
|
import { describe, expect, it } from "vitest";
|
|
1175
998
|
|
|
@@ -1225,7 +1048,7 @@ async function makeOperationModuleTestFile(args) {
|
|
|
1225
1048
|
async function makeDocumentModelTestFile(args) {
|
|
1226
1049
|
const { project, testsDirPath } = args;
|
|
1227
1050
|
const template = documentModelTestFileTemplate(args);
|
|
1228
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path
|
|
1051
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(testsDirPath, "document-model.test.ts"));
|
|
1229
1052
|
if (alreadyExists) return;
|
|
1230
1053
|
sourceFile.replaceWithText(template);
|
|
1231
1054
|
await formatSourceFileWithPrettier(sourceFile);
|
|
@@ -1235,7 +1058,7 @@ async function makeDocumentModelTestFile(args) {
|
|
|
1235
1058
|
async function makeUpgradeFile(args) {
|
|
1236
1059
|
const { project, version, upgradesDirPath, documentModelPackageImportPath, phStateName } = args;
|
|
1237
1060
|
if (version < 2) return;
|
|
1238
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path
|
|
1061
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(upgradesDirPath, `v${version}.ts`));
|
|
1239
1062
|
if (alreadyExists) return;
|
|
1240
1063
|
const template = upgradeTransitionTemplate({
|
|
1241
1064
|
version,
|
|
@@ -1248,7 +1071,7 @@ async function makeUpgradeFile(args) {
|
|
|
1248
1071
|
}
|
|
1249
1072
|
async function createOrUpdateUpgradeManifestFile(args) {
|
|
1250
1073
|
const { project, specVersions, upgradesDirPath, documentModelId, upgradeManifestName } = args;
|
|
1251
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
1074
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(upgradesDirPath, "upgrade-manifest.ts"));
|
|
1252
1075
|
const template = upgradeManifestTemplate({
|
|
1253
1076
|
documentModelId,
|
|
1254
1077
|
upgradeManifestName
|
|
@@ -1286,7 +1109,7 @@ function buildUpgradeTransitionImports(specVersions) {
|
|
|
1286
1109
|
async function createOrUpdateVersionConstantsFile({ specVersions, latestVersion, project, upgradesDirPath }) {
|
|
1287
1110
|
const SUPPORTED_VERSIONS = "supportedVersions";
|
|
1288
1111
|
const LATEST_VERSION = "latestVersion";
|
|
1289
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
1112
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(upgradesDirPath, "versions.ts"));
|
|
1290
1113
|
sourceFile.replaceWithText("");
|
|
1291
1114
|
const latestVersionIndex = specVersions.indexOf(latestVersion);
|
|
1292
1115
|
const versionInitializer = `[${specVersions.join(", ")}] as const;`;
|
|
@@ -1310,7 +1133,7 @@ async function createOrUpdateVersionConstantsFile({ specVersions, latestVersion,
|
|
|
1310
1133
|
await formatSourceFileWithPrettier(sourceFile);
|
|
1311
1134
|
}
|
|
1312
1135
|
async function makeUpgradesIndexFile({ project, upgradesDirPath, specVersions, upgradeManifestName }) {
|
|
1313
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
1136
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(upgradesDirPath, "index.ts"));
|
|
1314
1137
|
sourceFile.replaceWithText("");
|
|
1315
1138
|
const upgradeReducerExports = makeUpgradeReducerExports(specVersions);
|
|
1316
1139
|
sourceFile.addExportDeclarations([
|
|
@@ -1347,18 +1170,18 @@ function makeUpgradeReducerExports(specVersions) {
|
|
|
1347
1170
|
* for each `specification` in the `documentModelState`
|
|
1348
1171
|
*/
|
|
1349
1172
|
async function tsMorphGenerateDocumentModel({ projectDir, documentModelState, useVersioning, migrateLegacy }) {
|
|
1350
|
-
if (migrateLegacy) await migrateLegacyToVersioned(path
|
|
1173
|
+
if (migrateLegacy) await migrateLegacyToVersioned(path.join(projectDir, "document-models", getDocumentModelDirName(documentModelState)));
|
|
1351
1174
|
const project = buildTsMorphProject(projectDir);
|
|
1352
|
-
const documentModelsSourceFilesPath = path
|
|
1353
|
-
const documentModelsDirPath = path
|
|
1175
|
+
const documentModelsSourceFilesPath = path.join(projectDir, "document-models/**/*");
|
|
1176
|
+
const documentModelsDirPath = path.join(projectDir, "document-models");
|
|
1354
1177
|
const documentModelDirName = getDocumentModelDirName(documentModelState);
|
|
1355
|
-
const documentModelDirPath = path
|
|
1356
|
-
const upgradesDirPath = path
|
|
1178
|
+
const documentModelDirPath = path.join(documentModelsDirPath, documentModelDirName);
|
|
1179
|
+
const upgradesDirPath = path.join(documentModelDirPath, "upgrades");
|
|
1357
1180
|
const documentModelVariableNames = getDocumentModelVariableNames(documentModelState.name);
|
|
1358
1181
|
await ensureDirectoriesExist(project, documentModelsDirPath, documentModelDirPath);
|
|
1359
1182
|
if (useVersioning) await ensureDirectoriesExist(project, upgradesDirPath);
|
|
1360
1183
|
project.addSourceFilesAtPaths(documentModelsSourceFilesPath);
|
|
1361
|
-
const documentModelPackageImportPath = path
|
|
1184
|
+
const documentModelPackageImportPath = path.join("document-models", documentModelDirName);
|
|
1362
1185
|
const specVersions = [...new Set([...documentModelState.specifications.map((spec) => spec.version)])].toSorted();
|
|
1363
1186
|
if (specVersions.length !== documentModelState.specifications.length) throw new Error("Document model specifications array is misconfigured. Length is not match with spec versions.");
|
|
1364
1187
|
const latestVersion = specVersions[specVersions.length - 1];
|
|
@@ -1432,20 +1255,20 @@ async function generateDocumentModelForSpec({ project, projectDir, documentModel
|
|
|
1432
1255
|
const specification = documentModelState.specifications.find((spec) => spec.version === version);
|
|
1433
1256
|
if (!specification) throw new Error(`Document model specifications array is misconfigured, no specification found for version: ${version}`);
|
|
1434
1257
|
const versionDirName = useVersioning ? `v${version}` : "";
|
|
1435
|
-
const documentModelVersionDirName = path
|
|
1436
|
-
const documentModelVersionDirPath = path
|
|
1437
|
-
const versionedDocumentModelPackageImportPath = path
|
|
1258
|
+
const documentModelVersionDirName = path.join(documentModelDirName, versionDirName);
|
|
1259
|
+
const documentModelVersionDirPath = path.join(documentModelDirPath, versionDirName);
|
|
1260
|
+
const versionedDocumentModelPackageImportPath = path.join(documentModelPackageImportPath, versionDirName);
|
|
1438
1261
|
const fileExtension = documentModelState.extension;
|
|
1439
1262
|
const documentTypeId = documentModelState.id;
|
|
1440
|
-
const srcDirPath = path
|
|
1441
|
-
const reducersDirPath = path
|
|
1442
|
-
const testsDirPath = path
|
|
1443
|
-
const genDirPath = path
|
|
1444
|
-
const schemaDirPath = path
|
|
1263
|
+
const srcDirPath = path.join(documentModelVersionDirPath, "src");
|
|
1264
|
+
const reducersDirPath = path.join(srcDirPath, "reducers");
|
|
1265
|
+
const testsDirPath = path.join(documentModelVersionDirPath, "tests");
|
|
1266
|
+
const genDirPath = path.join(documentModelVersionDirPath, "gen");
|
|
1267
|
+
const schemaDirPath = path.join(genDirPath, "schema");
|
|
1445
1268
|
const { initialGlobalState, initialLocalState } = getInitialStates(specification.state);
|
|
1446
1269
|
const hasLocalSchema = specification.state.local.schema !== "";
|
|
1447
1270
|
const modules = specification.modules;
|
|
1448
|
-
await ensureDirectoriesExist(project, documentModelVersionDirPath, reducersDirPath, testsDirPath, schemaDirPath, ...modules.map((module) => path
|
|
1271
|
+
await ensureDirectoriesExist(project, documentModelVersionDirPath, reducersDirPath, testsDirPath, schemaDirPath, ...modules.map((module) => path.join(genDirPath, kebabCase(module.name))));
|
|
1449
1272
|
const fileMakerArgs = {
|
|
1450
1273
|
project,
|
|
1451
1274
|
projectDir,
|
|
@@ -1495,17 +1318,17 @@ async function generateDocumentModelForSpec({ project, projectDir, documentModel
|
|
|
1495
1318
|
}
|
|
1496
1319
|
/** Writes a json file derived from a `documentModelState` */
|
|
1497
1320
|
async function writeDocumentModelStateJsonFile({ documentModelState, documentModelDirName, documentModelDirPath }) {
|
|
1498
|
-
await writeFile(path
|
|
1321
|
+
await writeFile(path.join(documentModelDirPath, `${documentModelDirName}.json`), JSON.stringify(documentModelState, null, 2));
|
|
1499
1322
|
}
|
|
1500
1323
|
function getPreviousVersionDirPath(documentModelDirPath, version) {
|
|
1501
1324
|
const previousVersion = version - 1;
|
|
1502
1325
|
if (previousVersion < 1) return;
|
|
1503
1326
|
const previousVersionDirName = `v${previousVersion}`;
|
|
1504
|
-
return path
|
|
1327
|
+
return path.join(documentModelDirPath, previousVersionDirName);
|
|
1505
1328
|
}
|
|
1506
1329
|
async function makeDocumentModelIndexFile(args) {
|
|
1507
1330
|
const { project, documentModelDirPath, latestVersion } = args;
|
|
1508
|
-
const { sourceFile } = getOrCreateSourceFile(project, path
|
|
1331
|
+
const { sourceFile } = getOrCreateSourceFile(project, path.join(documentModelDirPath, "index.ts"));
|
|
1509
1332
|
sourceFile.replaceWithText("");
|
|
1510
1333
|
sourceFile.addExportDeclarations([{ moduleSpecifier: `./v${latestVersion}/index.js` }, { moduleSpecifier: `./upgrades/index.js` }]);
|
|
1511
1334
|
await formatSourceFileWithPrettier(sourceFile);
|
|
@@ -1519,21 +1342,197 @@ async function persistCustomFilesFromPreviousVersion(args) {
|
|
|
1519
1342
|
})).filter((dirEnt) => dirEnt.isFile()).map(({ name, parentPath }) => ({
|
|
1520
1343
|
name,
|
|
1521
1344
|
parentPath,
|
|
1522
|
-
relativePath: path
|
|
1345
|
+
relativePath: path.relative(previousVersionDirPath, parentPath)
|
|
1523
1346
|
}));
|
|
1524
1347
|
for (const { name, relativePath } of previousVersionFiles) {
|
|
1525
|
-
const filePathInCurrentVersionDir = path
|
|
1526
|
-
const filePathInPreviousVersionDir = path
|
|
1348
|
+
const filePathInCurrentVersionDir = path.join(currentVersionDirPath, relativePath, name);
|
|
1349
|
+
const filePathInPreviousVersionDir = path.join(previousVersionDirPath, relativePath, name);
|
|
1527
1350
|
const existsInPreviousVersionDir = await fileExists(filePathInPreviousVersionDir);
|
|
1528
1351
|
const existsInCurrentVersionDir = await fileExists(filePathInCurrentVersionDir);
|
|
1529
1352
|
if (existsInPreviousVersionDir && !existsInCurrentVersionDir) {
|
|
1530
|
-
console.log(`Persisting file "${path
|
|
1531
|
-
await mkdir(path
|
|
1353
|
+
console.log(`Persisting file "${path.join(relativePath, name)}" from previous version directory.`);
|
|
1354
|
+
await mkdir(path.join(currentVersionDirPath, relativePath), { recursive: true });
|
|
1532
1355
|
await copyFile(filePathInPreviousVersionDir, filePathInCurrentVersionDir);
|
|
1533
1356
|
}
|
|
1534
1357
|
}
|
|
1535
1358
|
}
|
|
1536
1359
|
//#endregion
|
|
1360
|
+
//#region src/file-builders/processors/analytics.ts
|
|
1361
|
+
async function tsMorphGenerateAnalyticsProcessor(args) {
|
|
1362
|
+
const { project, documentTypes, pascalCaseName, dirPath, camelCaseName } = args;
|
|
1363
|
+
await makeIndexFile$1({
|
|
1364
|
+
project,
|
|
1365
|
+
pascalCaseName,
|
|
1366
|
+
dirPath
|
|
1367
|
+
});
|
|
1368
|
+
await makeProcessorFile$1({
|
|
1369
|
+
project,
|
|
1370
|
+
pascalCaseName,
|
|
1371
|
+
dirPath
|
|
1372
|
+
});
|
|
1373
|
+
await makeFactoryFile$1({
|
|
1374
|
+
project,
|
|
1375
|
+
pascalCaseName,
|
|
1376
|
+
camelCaseName,
|
|
1377
|
+
dirPath,
|
|
1378
|
+
documentTypes
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
async function makeIndexFile$1(v) {
|
|
1382
|
+
const template = analyticsIndexTemplate;
|
|
1383
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path.join(v.dirPath, "index.ts"));
|
|
1384
|
+
if (alreadyExists) return;
|
|
1385
|
+
sourceFile.replaceWithText(template);
|
|
1386
|
+
await formatSourceFileWithPrettier(sourceFile);
|
|
1387
|
+
}
|
|
1388
|
+
async function makeProcessorFile$1(v) {
|
|
1389
|
+
const template = analyticsProcessorTemplate(v);
|
|
1390
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path.join(v.dirPath, "processor.ts"));
|
|
1391
|
+
if (alreadyExists) return;
|
|
1392
|
+
sourceFile.replaceWithText(template);
|
|
1393
|
+
await formatSourceFileWithPrettier(sourceFile);
|
|
1394
|
+
}
|
|
1395
|
+
async function makeFactoryFile$1(v) {
|
|
1396
|
+
const template = analyticsFactoryTemplate(v);
|
|
1397
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path.join(v.dirPath, "factory.ts"));
|
|
1398
|
+
if (alreadyExists) return;
|
|
1399
|
+
sourceFile.replaceWithText(template);
|
|
1400
|
+
await formatSourceFileWithPrettier(sourceFile);
|
|
1401
|
+
}
|
|
1402
|
+
//#endregion
|
|
1403
|
+
//#region src/file-builders/processors/relational-db.ts
|
|
1404
|
+
async function tsMorphGenerateRelationalDbProcessor(args) {
|
|
1405
|
+
const { project, documentTypes, camelCaseName, pascalCaseName, dirPath } = args;
|
|
1406
|
+
await makeIndexFile({
|
|
1407
|
+
project,
|
|
1408
|
+
pascalCaseName,
|
|
1409
|
+
dirPath
|
|
1410
|
+
});
|
|
1411
|
+
await makeProcessorFile({
|
|
1412
|
+
project,
|
|
1413
|
+
pascalCaseName,
|
|
1414
|
+
dirPath
|
|
1415
|
+
});
|
|
1416
|
+
await makeFactoryFile({
|
|
1417
|
+
project,
|
|
1418
|
+
pascalCaseName,
|
|
1419
|
+
camelCaseName,
|
|
1420
|
+
dirPath,
|
|
1421
|
+
documentTypes
|
|
1422
|
+
});
|
|
1423
|
+
await makeMigrationsFile({
|
|
1424
|
+
project,
|
|
1425
|
+
dirPath
|
|
1426
|
+
});
|
|
1427
|
+
await makeSchemaFile({
|
|
1428
|
+
project,
|
|
1429
|
+
dirPath
|
|
1430
|
+
});
|
|
1431
|
+
}
|
|
1432
|
+
async function makeIndexFile(v) {
|
|
1433
|
+
const template = relationalDbIndexTemplate;
|
|
1434
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path.join(v.dirPath, "index.ts"));
|
|
1435
|
+
if (alreadyExists) return;
|
|
1436
|
+
sourceFile.replaceWithText(template);
|
|
1437
|
+
await formatSourceFileWithPrettier(sourceFile);
|
|
1438
|
+
}
|
|
1439
|
+
async function makeProcessorFile(v) {
|
|
1440
|
+
const template = relationalDbProcessorTemplate(v);
|
|
1441
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path.join(v.dirPath, "processor.ts"));
|
|
1442
|
+
if (alreadyExists) return;
|
|
1443
|
+
sourceFile.replaceWithText(template);
|
|
1444
|
+
await formatSourceFileWithPrettier(sourceFile);
|
|
1445
|
+
}
|
|
1446
|
+
async function makeFactoryFile(v) {
|
|
1447
|
+
const template = relationalDbFactoryTemplate(v);
|
|
1448
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path.join(v.dirPath, "factory.ts"));
|
|
1449
|
+
if (alreadyExists) return;
|
|
1450
|
+
sourceFile.replaceWithText(template);
|
|
1451
|
+
await formatSourceFileWithPrettier(sourceFile);
|
|
1452
|
+
}
|
|
1453
|
+
async function makeSchemaFile(v) {
|
|
1454
|
+
const template = relationalDbSchemaTemplate();
|
|
1455
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path.join(v.dirPath, "schema.ts"));
|
|
1456
|
+
if (alreadyExists) return;
|
|
1457
|
+
sourceFile.replaceWithText(template);
|
|
1458
|
+
await formatSourceFileWithPrettier(sourceFile);
|
|
1459
|
+
}
|
|
1460
|
+
async function makeMigrationsFile(v) {
|
|
1461
|
+
const template = relationalDbMigrationsTemplate();
|
|
1462
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(v.project, path.join(v.dirPath, "migrations.ts"));
|
|
1463
|
+
if (alreadyExists) return;
|
|
1464
|
+
sourceFile.replaceWithText(template);
|
|
1465
|
+
await formatSourceFileWithPrettier(sourceFile);
|
|
1466
|
+
}
|
|
1467
|
+
//#endregion
|
|
1468
|
+
//#region src/file-builders/processors/processor.ts
|
|
1469
|
+
async function tsMorphGenerateProcessor(args) {
|
|
1470
|
+
const { processorName, documentTypes, rootDir, processorType, processorApps } = args;
|
|
1471
|
+
const kebabCaseName = kebabCase(processorName);
|
|
1472
|
+
const camelCaseName = camelCase(processorName);
|
|
1473
|
+
const pascalCaseName = pascalCase(processorName);
|
|
1474
|
+
const processorsDirPath = path.join(rootDir, "processors");
|
|
1475
|
+
const dirPath = path.join(processorsDirPath, kebabCaseName);
|
|
1476
|
+
const sourceFilesPath = path.join(processorsDirPath, "**/*");
|
|
1477
|
+
const project = buildTsMorphProject(rootDir);
|
|
1478
|
+
await ensureDirectoriesExist(project, processorsDirPath, dirPath);
|
|
1479
|
+
project.addSourceFilesAtPaths(sourceFilesPath);
|
|
1480
|
+
if (processorType === "analytics") await tsMorphGenerateAnalyticsProcessor({
|
|
1481
|
+
processorName,
|
|
1482
|
+
documentTypes,
|
|
1483
|
+
rootDir,
|
|
1484
|
+
camelCaseName,
|
|
1485
|
+
dirPath,
|
|
1486
|
+
kebabCaseName,
|
|
1487
|
+
pascalCaseName,
|
|
1488
|
+
processorsDirPath,
|
|
1489
|
+
project
|
|
1490
|
+
});
|
|
1491
|
+
else await tsMorphGenerateRelationalDbProcessor({
|
|
1492
|
+
processorName,
|
|
1493
|
+
documentTypes,
|
|
1494
|
+
rootDir,
|
|
1495
|
+
camelCaseName,
|
|
1496
|
+
dirPath,
|
|
1497
|
+
kebabCaseName,
|
|
1498
|
+
pascalCaseName,
|
|
1499
|
+
processorsDirPath,
|
|
1500
|
+
project
|
|
1501
|
+
});
|
|
1502
|
+
for (const processorApp of processorApps) await updateFactoryBuildersFile({
|
|
1503
|
+
processorsDirPath,
|
|
1504
|
+
processorApp,
|
|
1505
|
+
project,
|
|
1506
|
+
camelCaseName,
|
|
1507
|
+
kebabCaseName
|
|
1508
|
+
});
|
|
1509
|
+
await project.save();
|
|
1510
|
+
}
|
|
1511
|
+
async function updateFactoryBuildersFile(v) {
|
|
1512
|
+
const { project, processorsDirPath, processorApp, camelCaseName, kebabCaseName } = v;
|
|
1513
|
+
const template = factoryBuildersTemplate;
|
|
1514
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(processorsDirPath, `${processorApp}.ts`));
|
|
1515
|
+
if (!alreadyExists) sourceFile.replaceWithText(template);
|
|
1516
|
+
const name = `${camelCaseName}FactoryBuilder`;
|
|
1517
|
+
const moduleSpecifier = path.join("processors", kebabCaseName);
|
|
1518
|
+
const factoriesArrayName = "processorFactoryBuilders";
|
|
1519
|
+
let factoryBuildersArray = getFactoryBuildersArray(sourceFile, factoriesArrayName);
|
|
1520
|
+
if (!factoryBuildersArray) {
|
|
1521
|
+
sourceFile.replaceWithText(template);
|
|
1522
|
+
factoryBuildersArray = getFactoryBuildersArray(sourceFile, factoriesArrayName);
|
|
1523
|
+
}
|
|
1524
|
+
if (!factoryBuildersArray) throw new Error(`Could not get factory builders array in file ${processorApp}.ts`);
|
|
1525
|
+
if (!sourceFile.getImportDeclarations().flatMap((importDeclaration) => importDeclaration.getNamedImports().map((n) => n.getText())).find((n) => n === name)) sourceFile.addImportDeclaration({
|
|
1526
|
+
namedImports: [name],
|
|
1527
|
+
moduleSpecifier
|
|
1528
|
+
});
|
|
1529
|
+
if (!factoryBuildersArray.getElements().map((e) => e.getText()).includes(name)) factoryBuildersArray.addElement(name);
|
|
1530
|
+
await formatSourceFileWithPrettier(sourceFile);
|
|
1531
|
+
}
|
|
1532
|
+
function getFactoryBuildersArray(sourceFile, name) {
|
|
1533
|
+
return sourceFile.getDescendantsOfKind(ts.SyntaxKind.VariableStatement).flatMap((d) => d.getDescendantsOfKind(ts.SyntaxKind.VariableDeclaration)).find((d) => d.getName() === name)?.getDescendantsOfKind(ts.SyntaxKind.ArrayLiteralExpression).at(0);
|
|
1534
|
+
}
|
|
1535
|
+
//#endregion
|
|
1537
1536
|
//#region src/file-builders/subgraph.ts
|
|
1538
1537
|
async function tsMorphGenerateSubgraph(args) {
|
|
1539
1538
|
const { subgraphsDir, subgraphName, documentModel } = args;
|
|
@@ -1544,14 +1543,14 @@ async function tsMorphGenerateSubgraph(args) {
|
|
|
1544
1543
|
const kebabCaseName = kebabCase(subgraphName);
|
|
1545
1544
|
const pascalCaseName = pascalCase(subgraphName);
|
|
1546
1545
|
const camelCaseName = camelCase(subgraphName);
|
|
1547
|
-
const subgraphDir = path
|
|
1546
|
+
const subgraphDir = path.join(subgraphsDir, kebabCaseName);
|
|
1548
1547
|
if (existsSync(subgraphDir)) for (const name of [
|
|
1549
1548
|
"index.ts",
|
|
1550
1549
|
"lib.ts",
|
|
1551
1550
|
"schema.ts",
|
|
1552
1551
|
"resolvers.ts"
|
|
1553
1552
|
]) {
|
|
1554
|
-
const filePath = path
|
|
1553
|
+
const filePath = path.join(subgraphDir, name);
|
|
1555
1554
|
if (existsSync(filePath)) project.addSourceFileAtPath(filePath);
|
|
1556
1555
|
}
|
|
1557
1556
|
await makeBaseSubgraphIndexFile(project, subgraphDir, {
|
|
@@ -1567,21 +1566,21 @@ async function tsMorphGenerateSubgraph(args) {
|
|
|
1567
1566
|
await project.save();
|
|
1568
1567
|
}
|
|
1569
1568
|
async function makeBaseSubgraphIndexFile(project, dirPath, v) {
|
|
1570
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path
|
|
1569
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(dirPath, "index.ts"));
|
|
1571
1570
|
if (alreadyExists) return;
|
|
1572
1571
|
sourceFile.replaceWithText(subgraphIndexFileTemplate(v));
|
|
1573
1572
|
await formatSourceFileWithPrettier(sourceFile);
|
|
1574
1573
|
}
|
|
1575
1574
|
async function makeBaseSubgraphLibFile(project, dirPath) {
|
|
1576
|
-
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path
|
|
1575
|
+
const { alreadyExists, sourceFile } = getOrCreateSourceFile(project, path.join(dirPath, "lib.ts"));
|
|
1577
1576
|
if (alreadyExists) return;
|
|
1578
1577
|
sourceFile.replaceWithText(subgraphLibFileTemplate());
|
|
1579
1578
|
await formatSourceFileWithPrettier(sourceFile);
|
|
1580
1579
|
}
|
|
1581
1580
|
async function makeCustomSubgraphFiles(project, dirPath, v) {
|
|
1582
|
-
const schema = getOrCreateSourceFile(project, path
|
|
1581
|
+
const schema = getOrCreateSourceFile(project, path.join(dirPath, "schema.ts"));
|
|
1583
1582
|
if (!schema.alreadyExists) schema.sourceFile.replaceWithText(customSubgraphSchemaTemplate(v));
|
|
1584
|
-
const resolvers = getOrCreateSourceFile(project, path
|
|
1583
|
+
const resolvers = getOrCreateSourceFile(project, path.join(dirPath, "resolvers.ts"));
|
|
1585
1584
|
if (!resolvers.alreadyExists) {
|
|
1586
1585
|
resolvers.sourceFile.replaceWithText(customSubgraphResolversTemplate(v));
|
|
1587
1586
|
await formatSourceFileWithPrettier(resolvers.sourceFile);
|
|
@@ -1604,11 +1603,11 @@ async function makeDocumentModelSubgraphFiles(project, dirPath, documentModel) {
|
|
|
1604
1603
|
schema: applyGraphQLTypePrefixes(op.schema ?? "", pascalCaseDocumentType, stateTypeNames)
|
|
1605
1604
|
}))
|
|
1606
1605
|
}));
|
|
1607
|
-
getOrCreateSourceFile(project, path
|
|
1606
|
+
getOrCreateSourceFile(project, path.join(dirPath, "schema.ts")).sourceFile.replaceWithText(documentModelSubgraphSchemaTemplate({
|
|
1608
1607
|
pascalCaseDocumentType,
|
|
1609
1608
|
modules
|
|
1610
1609
|
}));
|
|
1611
|
-
getOrCreateSourceFile(project, path
|
|
1610
|
+
getOrCreateSourceFile(project, path.join(dirPath, "resolvers.ts")).sourceFile.replaceWithText(documentModelSubgraphResolversTemplate({
|
|
1612
1611
|
pascalCaseDocumentType,
|
|
1613
1612
|
camelCaseDocumentType,
|
|
1614
1613
|
phDocumentTypeName,
|
|
@@ -1621,7 +1620,7 @@ async function makeDocumentModelSubgraphFiles(project, dirPath, documentModel) {
|
|
|
1621
1620
|
//#region src/file-builders/subgraphs.ts
|
|
1622
1621
|
async function makeSubgraphsIndexFile({ projectDir }) {
|
|
1623
1622
|
const project = new Project({
|
|
1624
|
-
tsConfigFilePath: path
|
|
1623
|
+
tsConfigFilePath: path.join(projectDir, "tsconfig.json"),
|
|
1625
1624
|
skipAddingFilesFromTsConfig: true,
|
|
1626
1625
|
skipLoadingLibFiles: true,
|
|
1627
1626
|
manipulationSettings: {
|
|
@@ -1630,9 +1629,9 @@ async function makeSubgraphsIndexFile({ projectDir }) {
|
|
|
1630
1629
|
}
|
|
1631
1630
|
});
|
|
1632
1631
|
project.addSourceFilesAtPaths(`${projectDir}/subgraphs/**/*`);
|
|
1633
|
-
const subgraphsSubdirs = project.getDirectory(path
|
|
1634
|
-
let subgraphsIndexSourceFile = project.getSourceFile(path
|
|
1635
|
-
if (!subgraphsIndexSourceFile) subgraphsIndexSourceFile = project.createSourceFile(path
|
|
1632
|
+
const subgraphsSubdirs = project.getDirectory(path.join(projectDir, "subgraphs"))?.getDirectories() ?? [];
|
|
1633
|
+
let subgraphsIndexSourceFile = project.getSourceFile(path.join(projectDir, "subgraphs/index.ts"));
|
|
1634
|
+
if (!subgraphsIndexSourceFile) subgraphsIndexSourceFile = project.createSourceFile(path.join(projectDir, "subgraphs/index.js"), "");
|
|
1636
1635
|
for (const subgraphSubdir of subgraphsSubdirs) {
|
|
1637
1636
|
const subgraphIndexSourceFilePath = `${subgraphSubdir.getPath()}/index.ts`;
|
|
1638
1637
|
const subgraphIndexSourceFile = project.getSourceFile(subgraphIndexSourceFilePath);
|
|
@@ -1648,6 +1647,6 @@ async function makeSubgraphsIndexFile({ projectDir }) {
|
|
|
1648
1647
|
await project.save();
|
|
1649
1648
|
}
|
|
1650
1649
|
//#endregion
|
|
1651
|
-
export {
|
|
1650
|
+
export { makeEditorModuleFile as C, makeLegacyIndexFile as S, makeDocumentModelModulesFile as _, generateDocumentModelZodSchemas as a, makeUpgradeManifestsExport as b, scalars as c, getCommandHelpInfo as d, getCommandsHelpInfo as f, tsMorphGenerateApp as g, buildBoilerplatePackageJson as h, tsMorphGenerateDocumentModel as i, scalarsValidation as l, writeCliDocsMarkdownFile as m, tsMorphGenerateSubgraph as n, generateSchemas as o, makeCliDocsFromHelp as p, tsMorphGenerateProcessor as r, generateTypesAndZodSchemasFromGraphql as s, makeSubgraphsIndexFile as t, tsMorphGenerateDocumentEditor as u, makeEditorsModulesFile as v, makeUpgradeManifestsFile as x, makeModulesFile as y };
|
|
1652
1651
|
|
|
1653
|
-
//# sourceMappingURL=file-builders-
|
|
1652
|
+
//# sourceMappingURL=file-builders-C2QoGrDi.mjs.map
|