@mxpicture/gcp-functions-generator 1.1.92 → 1.2.3
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/4testing/templates/template.example.d.ts +4 -3
- package/dist/4testing/templates/template.example.d.ts.map +1 -1
- package/dist/4testing/templates/template.example.js.map +1 -1
- package/dist/4testing/templates/template.medication.d.ts +2 -1
- package/dist/4testing/templates/template.medication.d.ts.map +1 -1
- package/dist/4testing/templates/template.medication.js.map +1 -1
- package/dist/4testing/templates/template.settings.d.ts +2 -1
- package/dist/4testing/templates/template.settings.d.ts.map +1 -1
- package/dist/4testing/templates/template.settings.js.map +1 -1
- package/dist/4testing/utils.d.ts +1 -1
- package/dist/4testing/utils.d.ts.map +1 -1
- package/dist/4testing/utils.js +24 -2
- package/dist/4testing/utils.js.map +1 -1
- package/dist/common/file.common.d.ts +11 -2
- package/dist/common/file.common.d.ts.map +1 -1
- package/dist/common/file.common.js +44 -8
- package/dist/common/file.common.js.map +1 -1
- package/dist/common/index.d.ts +1 -6
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +1 -6
- package/dist/common/index.js.map +1 -1
- package/dist/common/job.common.d.ts +1 -1
- package/dist/common/job.common.d.ts.map +1 -1
- package/dist/common/resolve.common.d.ts +16 -0
- package/dist/common/resolve.common.d.ts.map +1 -0
- package/dist/common/resolve.common.js +43 -0
- package/dist/common/resolve.common.js.map +1 -0
- package/dist/common/types.common.d.ts +42 -2
- package/dist/common/types.common.d.ts.map +1 -1
- package/dist/decorator/DecoExtractor.d.ts +22 -0
- package/dist/decorator/DecoExtractor.d.ts.map +1 -0
- package/dist/{common/Extractor.js → decorator/DecoExtractor.js} +2 -23
- package/dist/decorator/DecoExtractor.js.map +1 -0
- package/dist/decorator/deco.names.d.ts +4 -3
- package/dist/decorator/deco.names.d.ts.map +1 -1
- package/dist/decorator/deco.names.js +6 -6
- package/dist/decorator/deco.names.js.map +1 -1
- package/dist/decorator/index.d.ts +1 -1
- package/dist/decorator/index.d.ts.map +1 -1
- package/dist/decorator/index.js +1 -1
- package/dist/decorator/index.js.map +1 -1
- package/dist/exports.gen.json +1367 -0
- package/dist/generator/Generator.d.ts +20 -106
- package/dist/generator/Generator.d.ts.map +1 -1
- package/dist/generator/Generator.js +84 -169
- package/dist/generator/Generator.js.map +1 -1
- package/dist/generator/GeneratorAnnotations.d.ts +3 -4
- package/dist/generator/GeneratorAnnotations.d.ts.map +1 -1
- package/dist/generator/GeneratorAnnotations.js +20 -46
- package/dist/generator/GeneratorAnnotations.js.map +1 -1
- package/dist/generator/GeneratorBackend.d.ts +11 -30
- package/dist/generator/GeneratorBackend.d.ts.map +1 -1
- package/dist/generator/GeneratorBackend.js +68 -177
- package/dist/generator/GeneratorBackend.js.map +1 -1
- package/dist/generator/GeneratorDoc.d.ts +8 -9
- package/dist/generator/GeneratorDoc.d.ts.map +1 -1
- package/dist/generator/GeneratorDoc.js +34 -35
- package/dist/generator/GeneratorDoc.js.map +1 -1
- package/dist/generator/GeneratorEnum.d.ts +6 -7
- package/dist/generator/GeneratorEnum.d.ts.map +1 -1
- package/dist/generator/GeneratorEnum.js +26 -15
- package/dist/generator/GeneratorEnum.js.map +1 -1
- package/dist/generator/GeneratorFrontend.d.ts +5 -6
- package/dist/generator/GeneratorFrontend.d.ts.map +1 -1
- package/dist/generator/GeneratorFrontend.js +28 -48
- package/dist/generator/GeneratorFrontend.js.map +1 -1
- package/dist/generator/GeneratorRoutes.d.ts +6 -7
- package/dist/generator/GeneratorRoutes.d.ts.map +1 -1
- package/dist/generator/GeneratorRoutes.js +26 -31
- package/dist/generator/GeneratorRoutes.js.map +1 -1
- package/dist/generator/GeneratorZod.d.ts +9 -10
- package/dist/generator/GeneratorZod.d.ts.map +1 -1
- package/dist/generator/GeneratorZod.js +29 -25
- package/dist/generator/GeneratorZod.js.map +1 -1
- package/dist/run/GeneratorBarrel.d.ts +11 -0
- package/dist/run/GeneratorBarrel.d.ts.map +1 -0
- package/dist/run/GeneratorBarrel.js +22 -0
- package/dist/run/GeneratorBarrel.js.map +1 -0
- package/dist/run/GeneratorBase.d.ts +6 -0
- package/dist/run/GeneratorBase.d.ts.map +1 -0
- package/dist/run/GeneratorBase.js +4 -0
- package/dist/run/GeneratorBase.js.map +1 -0
- package/dist/run/GeneratorBaseFile.d.ts +16 -0
- package/dist/run/GeneratorBaseFile.d.ts.map +1 -0
- package/dist/run/GeneratorBaseFile.js +36 -0
- package/dist/run/GeneratorBaseFile.js.map +1 -0
- package/dist/run/GeneratorDirectory.d.ts +18 -0
- package/dist/run/GeneratorDirectory.d.ts.map +1 -0
- package/dist/run/GeneratorDirectory.js +42 -0
- package/dist/run/GeneratorDirectory.js.map +1 -0
- package/dist/run/GeneratorFile.d.ts +12 -0
- package/dist/run/GeneratorFile.d.ts.map +1 -0
- package/dist/run/GeneratorFile.js +31 -0
- package/dist/run/GeneratorFile.js.map +1 -0
- package/dist/run/GeneratorFs.d.ts +27 -0
- package/dist/run/GeneratorFs.d.ts.map +1 -0
- package/dist/run/GeneratorFs.js +81 -0
- package/dist/run/GeneratorFs.js.map +1 -0
- package/dist/run/GeneratorPackage.d.ts +21 -0
- package/dist/run/GeneratorPackage.d.ts.map +1 -0
- package/dist/run/GeneratorPackage.js +57 -0
- package/dist/run/GeneratorPackage.js.map +1 -0
- package/dist/run/GeneratorRun.d.ts +25 -0
- package/dist/run/GeneratorRun.d.ts.map +1 -0
- package/dist/run/GeneratorRun.js +58 -0
- package/dist/run/GeneratorRun.js.map +1 -0
- package/dist/run/GeneratorTemplate.d.ts +10 -0
- package/dist/run/GeneratorTemplate.d.ts.map +1 -0
- package/dist/run/GeneratorTemplate.js +27 -0
- package/dist/run/GeneratorTemplate.js.map +1 -0
- package/dist/run/index.d.ts +10 -0
- package/dist/run/index.d.ts.map +1 -0
- package/dist/run/index.js +11 -0
- package/dist/run/index.js.map +1 -0
- package/package.json +7 -6
- package/dist/common/Barrel.d.ts +0 -75
- package/dist/common/Barrel.d.ts.map +0 -1
- package/dist/common/Barrel.js +0 -119
- package/dist/common/Barrel.js.map +0 -1
- package/dist/common/CodeCollector.d.ts +0 -11
- package/dist/common/CodeCollector.d.ts.map +0 -1
- package/dist/common/CodeCollector.js +0 -29
- package/dist/common/CodeCollector.js.map +0 -1
- package/dist/common/Collector.d.ts +0 -70
- package/dist/common/Collector.d.ts.map +0 -1
- package/dist/common/Collector.js +0 -77
- package/dist/common/Collector.js.map +0 -1
- package/dist/common/Directories.d.ts +0 -60
- package/dist/common/Directories.d.ts.map +0 -1
- package/dist/common/Directories.js +0 -76
- package/dist/common/Directories.js.map +0 -1
- package/dist/common/Extractor.d.ts +0 -36
- package/dist/common/Extractor.d.ts.map +0 -1
- package/dist/common/Extractor.js.map +0 -1
- package/dist/common/generator.common.d.ts +0 -80
- package/dist/common/generator.common.d.ts.map +0 -1
- package/dist/common/generator.common.js +0 -138
- package/dist/common/generator.common.js.map +0 -1
- package/dist/decorator/deco.imports.d.ts +0 -31
- package/dist/decorator/deco.imports.d.ts.map +0 -1
- package/dist/decorator/deco.imports.js +0 -71
- package/dist/decorator/deco.imports.js.map +0 -1
|
@@ -1,57 +1,8 @@
|
|
|
1
|
-
import { DecoFile
|
|
2
|
-
import { DecoFileType, DecoFileExtension,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
/**
|
|
7
|
-
* Base structure shared by all generator outputs, containing imports and code lines.
|
|
8
|
-
*/
|
|
9
|
-
export interface GeneratorBase {
|
|
10
|
-
imports: DecoImport[];
|
|
11
|
-
code: string[];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Generator output for a single decorator header, including a name identifier.
|
|
15
|
-
*/
|
|
16
|
-
export interface GeneratorHeader extends GeneratorBase {
|
|
17
|
-
name: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Full result file produced by a generator, ready to be written to disk.
|
|
21
|
-
*/
|
|
22
|
-
export interface GeneratorResultFile extends GeneratorBase {
|
|
23
|
-
type: DecoFileType;
|
|
24
|
-
ext: DecoFileExtension;
|
|
25
|
-
inputFilePath: string;
|
|
26
|
-
targetFilePath: string;
|
|
27
|
-
targetType: DecoTargetType;
|
|
28
|
-
importsCode: string[];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Pairs a decorator with its resolved names for processing by a generator.
|
|
32
|
-
*/
|
|
33
|
-
export interface GeneratorRunItem {
|
|
34
|
-
decorator: Decorator;
|
|
35
|
-
names: DecoNames;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* A record of run items keyed by decorator name, providing lookup for cross-references.
|
|
39
|
-
*/
|
|
40
|
-
export type GeneratorRunItems = Record<string, GeneratorRunItem>;
|
|
41
|
-
/**
|
|
42
|
-
* Converts an array of {@link DecoImport} entries into TypeScript import statement strings.
|
|
43
|
-
*
|
|
44
|
-
* @param imports - The imports to convert.
|
|
45
|
-
* @returns An array of import statement strings (empty imports are filtered out).
|
|
46
|
-
*/
|
|
47
|
-
export declare const importsToCode: (imports: DecoImport[]) => string[];
|
|
48
|
-
/**
|
|
49
|
-
* Async variant of {@link importsToCode}.
|
|
50
|
-
*
|
|
51
|
-
* @param imports - The imports to convert.
|
|
52
|
-
* @returns A promise resolving to an array of import statement strings.
|
|
53
|
-
*/
|
|
54
|
-
export declare const importsToCodeAsync: (imports: DecoImport[]) => Promise<string[]>;
|
|
1
|
+
import type { DecoFile } from "@mxpicture/gcp-functions-common/types";
|
|
2
|
+
import { type DecoFileType, type DecoFileExtension, DecoPackageType, type Decorator } from "@mxpicture/gcp-functions-common/decorator";
|
|
3
|
+
import type { GeneratorEnv, GeneratorHeader, GeneratorRunItem, GeneratorRunItems, GeneratorRunResult } from "../common/types.common.js";
|
|
4
|
+
import type { GeneratorFs } from "../run/GeneratorFs.js";
|
|
5
|
+
import type { GeneratorFile } from "../run/GeneratorFile.js";
|
|
55
6
|
/**
|
|
56
7
|
* Abstract base class for all code generators.
|
|
57
8
|
*
|
|
@@ -61,24 +12,22 @@ export declare const importsToCodeAsync: (imports: DecoImport[]) => Promise<stri
|
|
|
61
12
|
* formatting, and writing to disk.
|
|
62
13
|
*/
|
|
63
14
|
export declare abstract class Generator {
|
|
64
|
-
readonly
|
|
65
|
-
readonly type: DecoFileType;
|
|
15
|
+
readonly fileType: DecoFileType;
|
|
66
16
|
readonly ext: DecoFileExtension;
|
|
67
|
-
readonly
|
|
68
|
-
readonly collector: Collector;
|
|
69
|
-
readonly useAdditionalImports: boolean;
|
|
70
|
-
protected usedImports: DecoSingleImport[];
|
|
17
|
+
readonly packageType: DecoPackageType;
|
|
71
18
|
/**
|
|
72
19
|
* Creates a new generator.
|
|
73
20
|
*
|
|
74
|
-
* @param
|
|
75
|
-
* @param type - The decorator file type this generator produces.
|
|
21
|
+
* @param fileType - The decorator file type this generator produces.
|
|
76
22
|
* @param ext - The output file extension.
|
|
77
|
-
* @param
|
|
78
|
-
* @param collector - The shared collector for cross-generator lookups.
|
|
23
|
+
* @param packageType - The target package (common, backend, frontend).
|
|
79
24
|
* @param useAdditionalImports - Whether to include additional imports from the decorator.
|
|
80
25
|
*/
|
|
81
|
-
constructor(
|
|
26
|
+
constructor(p: {
|
|
27
|
+
fileType: DecoFileType;
|
|
28
|
+
ext: DecoFileExtension;
|
|
29
|
+
packageType: DecoPackageType;
|
|
30
|
+
});
|
|
82
31
|
/**
|
|
83
32
|
* Processes a decorator file by running all its headers through the generator.
|
|
84
33
|
*
|
|
@@ -87,46 +36,11 @@ export declare abstract class Generator {
|
|
|
87
36
|
* @returns A promise resolving to the assembled result file.
|
|
88
37
|
* @throws Error if no headers are produced for the file.
|
|
89
38
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
static write(...files: GeneratorResultFile[]): Promise<void>;
|
|
97
|
-
/**
|
|
98
|
-
* Resolves an import path from the current generator's context to a target type and file type.
|
|
99
|
-
*
|
|
100
|
-
* @param targetType - The target type of the import destination.
|
|
101
|
-
* @param fileType - The file type of the import destination.
|
|
102
|
-
* @returns The resolved import path string.
|
|
103
|
-
*/
|
|
104
|
-
resolveImport(targetType: DecoTargetType, fileType: DecoFileType): string;
|
|
105
|
-
/**
|
|
106
|
-
* Resolves an import path to the common target for the given file type.
|
|
107
|
-
*
|
|
108
|
-
* @param fileType - The file type to import from common.
|
|
109
|
-
* @returns The resolved import path.
|
|
110
|
-
*/
|
|
111
|
-
importCommon(fileType: DecoFileType): string;
|
|
112
|
-
/**
|
|
113
|
-
* Resolves an import path to the frontend target for the given file type.
|
|
114
|
-
*
|
|
115
|
-
* @param fileType - The file type to import from frontend.
|
|
116
|
-
* @returns The resolved import path.
|
|
117
|
-
*/
|
|
118
|
-
importFrontend(fileType: DecoFileType): string;
|
|
119
|
-
/**
|
|
120
|
-
* Resolves an import path to the backend target for the given file type.
|
|
121
|
-
*
|
|
122
|
-
* @param fileType - The file type to import from backend.
|
|
123
|
-
* @returns The resolved import path.
|
|
124
|
-
*/
|
|
125
|
-
importBackend(fileType: DecoFileType): string;
|
|
126
|
-
protected processHeader(curretItem: GeneratorRunItem, all: GeneratorRunItems, env: GeneratorEnv): Promise<(GeneratorHeader & {
|
|
127
|
-
inputFilePath: string;
|
|
128
|
-
}) | null>;
|
|
129
|
-
protected i(_prop: string, isType?: boolean): string;
|
|
130
|
-
protected abstract runHeader(current: GeneratorRunItem, all: GeneratorRunItems, env: GeneratorEnv, result: CodeCollector): Promise<string | null>;
|
|
39
|
+
run4codes(decoFiles: DecoFile[], env: GeneratorEnv, fs: GeneratorFs): Promise<void>;
|
|
40
|
+
protected run4code(decoFile: DecoFile, env: GeneratorEnv, fs: GeneratorFs, runItems: GeneratorRunItems): Promise<GeneratorFile>;
|
|
41
|
+
run4imports(): Promise<void>;
|
|
42
|
+
protected buildRunItems(packageType: DecoPackageType, decorators: Decorator[]): GeneratorRunItems;
|
|
43
|
+
protected processHeader(curretItem: GeneratorRunItem, env: GeneratorEnv): Promise<GeneratorHeader | null>;
|
|
44
|
+
protected abstract runHeader(item: GeneratorRunItem, env: GeneratorEnv): Promise<GeneratorRunResult | null>;
|
|
131
45
|
}
|
|
132
46
|
//# sourceMappingURL=Generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Generator.d.ts","sourceRoot":"","sources":["../../src/generator/Generator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Generator.d.ts","sourceRoot":"","sources":["../../src/generator/Generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,eAAe,EACf,KAAK,SAAS,EAEf,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAO7D;;;;;;;GAOG;AACH,8BAAsB,SAAS;IAC7B,SAAgB,QAAQ,EAAE,YAAY,CAAC;IACvC,SAAgB,GAAG,EAAE,iBAAiB,CAAC;IACvC,SAAgB,WAAW,EAAE,eAAe,CAAC;IAE7C;;;;;;;OAOG;gBACgB,CAAC,EAAE;QACpB,QAAQ,EAAE,YAAY,CAAC;QACvB,GAAG,EAAE,iBAAiB,CAAC;QACvB,WAAW,EAAE,eAAe,CAAC;KAC9B;IAMD;;;;;;;OAOG;IACU,SAAS,CACpB,SAAS,EAAE,QAAQ,EAAE,EACrB,GAAG,EAAE,YAAY,EACjB,EAAE,EAAE,WAAW;cAeD,QAAQ,CACtB,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,YAAY,EACjB,EAAE,EAAE,WAAW,EACf,QAAQ,EAAE,iBAAiB,GAC1B,OAAO,CAAC,aAAa,CAAC;IAwBZ,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAuCzC,SAAS,CAAC,aAAa,CACrB,WAAW,EAAE,eAAe,EAC5B,UAAU,EAAE,SAAS,EAAE,GACtB,iBAAiB;cA0BJ,aAAa,CAC3B,UAAU,EAAE,gBAAgB,EAC5B,GAAG,EAAE,YAAY,GAChB,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAgBlC,SAAS,CAAC,QAAQ,CAAC,SAAS,CAC1B,IAAI,EAAE,gBAAgB,EACtB,GAAG,EAAE,YAAY,GAChB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;CACtC"}
|
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
-
import { DecoFileExtension, DecoTargetType, } from "@mxpicture/gcp-functions-common/decorator";
|
|
4
|
-
import { directories } from "../common/Directories.js";
|
|
5
|
-
import { decoBackendNames, decoFrontendNames, decoNames, } from "../decorator/deco.names.js";
|
|
6
|
-
import { formatCode, formatJson } from "@mxpicture/build-api/code";
|
|
1
|
+
import { DecoPackageType, } from "@mxpicture/gcp-functions-common/decorator";
|
|
7
2
|
import { toFilename } from "../common/file.common.js";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
? `import ${imp.isType ? "type " : ""}{ ${[...imp.props].join(", ")} } from "${imp.path}"`
|
|
11
|
-
: null;
|
|
12
|
-
const importToCodeAsync = async (imp) => Promise.resolve().then(() => importToCode(imp));
|
|
13
|
-
/**
|
|
14
|
-
* Converts an array of {@link DecoImport} entries into TypeScript import statement strings.
|
|
15
|
-
*
|
|
16
|
-
* @param imports - The imports to convert.
|
|
17
|
-
* @returns An array of import statement strings (empty imports are filtered out).
|
|
18
|
-
*/
|
|
19
|
-
export const importsToCode = (imports) => imports.map(importToCode).filter((imp) => imp !== null);
|
|
20
|
-
/**
|
|
21
|
-
* Async variant of {@link importsToCode}.
|
|
22
|
-
*
|
|
23
|
-
* @param imports - The imports to convert.
|
|
24
|
-
* @returns A promise resolving to an array of import statement strings.
|
|
25
|
-
*/
|
|
26
|
-
export const importsToCodeAsync = async (imports) => (await Promise.all(imports.map(importToCodeAsync))).filter((imp) => imp !== null);
|
|
3
|
+
import { basename } from "node:path";
|
|
4
|
+
import { decoBackendNames, decoFrontendNames, decoNames, } from "../decorator/deco.names.js";
|
|
27
5
|
/**
|
|
28
6
|
* Abstract base class for all code generators.
|
|
29
7
|
*
|
|
@@ -33,30 +11,21 @@ export const importsToCodeAsync = async (imports) => (await Promise.all(imports.
|
|
|
33
11
|
* formatting, and writing to disk.
|
|
34
12
|
*/
|
|
35
13
|
export class Generator {
|
|
36
|
-
|
|
37
|
-
type;
|
|
14
|
+
fileType;
|
|
38
15
|
ext;
|
|
39
|
-
|
|
40
|
-
collector;
|
|
41
|
-
useAdditionalImports;
|
|
42
|
-
usedImports = [];
|
|
16
|
+
packageType;
|
|
43
17
|
/**
|
|
44
18
|
* Creates a new generator.
|
|
45
19
|
*
|
|
46
|
-
* @param
|
|
47
|
-
* @param type - The decorator file type this generator produces.
|
|
20
|
+
* @param fileType - The decorator file type this generator produces.
|
|
48
21
|
* @param ext - The output file extension.
|
|
49
|
-
* @param
|
|
50
|
-
* @param collector - The shared collector for cross-generator lookups.
|
|
22
|
+
* @param packageType - The target package (common, backend, frontend).
|
|
51
23
|
* @param useAdditionalImports - Whether to include additional imports from the decorator.
|
|
52
24
|
*/
|
|
53
|
-
constructor(
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
57
|
-
this.targetType = targetType;
|
|
58
|
-
this.collector = collector;
|
|
59
|
-
this.useAdditionalImports = useAdditionalImports;
|
|
25
|
+
constructor(p) {
|
|
26
|
+
this.fileType = p.fileType;
|
|
27
|
+
this.ext = p.ext;
|
|
28
|
+
this.packageType = p.packageType;
|
|
60
29
|
}
|
|
61
30
|
/**
|
|
62
31
|
* Processes a decorator file by running all its headers through the generator.
|
|
@@ -66,147 +35,93 @@ export class Generator {
|
|
|
66
35
|
* @returns A promise resolving to the assembled result file.
|
|
67
36
|
* @throws Error if no headers are produced for the file.
|
|
68
37
|
*/
|
|
69
|
-
async
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
38
|
+
async run4codes(decoFiles, env, fs) {
|
|
39
|
+
const collects = decoFiles.map((decoFile) => ({
|
|
40
|
+
decoFile,
|
|
41
|
+
runItems: this.buildRunItems(this.packageType, decoFile.decorators),
|
|
42
|
+
}));
|
|
43
|
+
await Promise.all(collects.map(async (collect) => this.run4code(collect.decoFile, env, fs, collect.runItems)));
|
|
44
|
+
}
|
|
45
|
+
async run4code(decoFile, env, fs, runItems) {
|
|
46
|
+
const headerResults = (await Promise.all(Object.values(runItems).map((p) => this.processHeader(p, env)))).filter((h) => !!h);
|
|
47
|
+
if (headerResults.length === 0)
|
|
48
|
+
throw new Error(`Generator ${this.fileType}, file ${decoFile.templateRepoFilePath}: no headers provided`);
|
|
49
|
+
const filename = toFilename({
|
|
50
|
+
filename: basename(headerResults[0].inputFilePath),
|
|
51
|
+
fileType: this.fileType,
|
|
52
|
+
ext: this.ext,
|
|
53
|
+
generated: true,
|
|
54
|
+
});
|
|
55
|
+
const file = fs.file(this.packageType, this.fileType, filename);
|
|
56
|
+
file.code = headerResults.flatMap((res) => res.code);
|
|
57
|
+
return file;
|
|
58
|
+
}
|
|
59
|
+
async run4imports() {
|
|
60
|
+
// file.code = headerResults.flatMap((result) => result.code);
|
|
61
|
+
// const imports = nodesToImports(this.expFinder.requestedNodes);
|
|
62
|
+
// for (const imp of imports) {
|
|
63
|
+
// const parts = splitPackagePath(imp.path);
|
|
64
|
+
// if (!parts) continue;
|
|
65
|
+
// imp.path = this.resolveImp(parts.packageType, parts.type);
|
|
66
|
+
// }
|
|
67
|
+
// resultFile.importsCode = importsToCode(imports);
|
|
68
|
+
// return resultFile;
|
|
69
|
+
}
|
|
70
|
+
// /**
|
|
71
|
+
// * Resolves an import path from the current generator's context to a target type and file type.
|
|
72
|
+
// *
|
|
73
|
+
// * @param packageType - The target type of the import destination.
|
|
74
|
+
// * @param fileType - The file type of the import destination.
|
|
75
|
+
// * @returns The resolved import path string.
|
|
76
|
+
// */
|
|
77
|
+
// public resolveImp(
|
|
78
|
+
// packageType: DecoPackageType,
|
|
79
|
+
// fileType: DecoFileType,
|
|
80
|
+
// ): string {
|
|
81
|
+
// return directories.resolveImport(
|
|
82
|
+
// { packageType, fileType },
|
|
83
|
+
// { packageType: this.packageType, fileType: this.type },
|
|
84
|
+
// );
|
|
85
|
+
// }
|
|
86
|
+
// public resolveImpString(path: string): string {
|
|
87
|
+
// const parts = splitPackagePath(path);
|
|
88
|
+
// return parts ? this.resolveImp(parts.packageType, parts.type) : path;
|
|
89
|
+
// }
|
|
90
|
+
// public resolveImpDeco(deco: DecoImport): DecoImport {
|
|
91
|
+
// deco.path = this.resolveImpString(deco.path);
|
|
92
|
+
// return deco;
|
|
93
|
+
// }
|
|
94
|
+
buildRunItems(packageType, decorators) {
|
|
95
|
+
const runItems = {};
|
|
96
|
+
const allNames = [];
|
|
97
|
+
for (const decorator of decorators) {
|
|
74
98
|
const extr = decorator.extractRaw();
|
|
75
|
-
const names =
|
|
99
|
+
const names = packageType === DecoPackageType.backend
|
|
76
100
|
? decoBackendNames(extr.name, extr.namespace)
|
|
77
|
-
:
|
|
101
|
+
: packageType === DecoPackageType.frontend
|
|
78
102
|
? decoFrontendNames(extr.name, extr.namespace)
|
|
79
103
|
: decoNames(extr.name, extr.namespace);
|
|
80
|
-
|
|
104
|
+
allNames.push(names);
|
|
105
|
+
runItems[extr.name] = {
|
|
81
106
|
decorator,
|
|
82
107
|
names,
|
|
108
|
+
allNames,
|
|
83
109
|
};
|
|
84
110
|
}
|
|
85
|
-
|
|
86
|
-
for (const interfaceResult of interfaceResults) {
|
|
87
|
-
if (!interfaceResult)
|
|
88
|
-
continue;
|
|
89
|
-
if (!result) {
|
|
90
|
-
const targetFilename = toFilename({
|
|
91
|
-
filename: basename(interfaceResult.inputFilePath),
|
|
92
|
-
type: this.type,
|
|
93
|
-
ext: this.ext,
|
|
94
|
-
generated: true,
|
|
95
|
-
});
|
|
96
|
-
result = {
|
|
97
|
-
inputFilePath: interfaceResult.inputFilePath,
|
|
98
|
-
targetFilePath: directories.toTargetPath(this.type, targetFilename, this.targetType),
|
|
99
|
-
targetType: this.targetType,
|
|
100
|
-
imports: [],
|
|
101
|
-
importsCode: [],
|
|
102
|
-
code: [],
|
|
103
|
-
ext: this.ext,
|
|
104
|
-
type: this.type,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
resultsCollector.addCode(...interfaceResult.code);
|
|
108
|
-
resultsCollector.addImport(...interfaceResult.imports);
|
|
109
|
-
}
|
|
110
|
-
if (!result)
|
|
111
|
-
throw new Error(`Generator ${this.type}, file ${file.templateRepoFilePath}: no headers provided`);
|
|
112
|
-
result.code = resultsCollector.code;
|
|
113
|
-
result.imports = resultsCollector.imports;
|
|
114
|
-
result.importsCode = await importsToCodeAsync(result.imports);
|
|
115
|
-
return result;
|
|
111
|
+
return runItems;
|
|
116
112
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
*
|
|
120
|
-
* @param files - The result files to write.
|
|
121
|
-
*/
|
|
122
|
-
static async write(...files) {
|
|
123
|
-
const promises = [];
|
|
124
|
-
for (const file of files) {
|
|
125
|
-
const preCode = [...file.importsCode, "", ...file.code].join("\n");
|
|
126
|
-
promises.push((async () => {
|
|
127
|
-
let code;
|
|
128
|
-
if (file.ext === DecoFileExtension.ts)
|
|
129
|
-
code = await formatCode(preCode);
|
|
130
|
-
else if (file.ext === DecoFileExtension.json)
|
|
131
|
-
code = await formatJson(preCode);
|
|
132
|
-
else
|
|
133
|
-
code = preCode;
|
|
134
|
-
await mkdir(dirname(file.targetFilePath), { recursive: true });
|
|
135
|
-
return writeFile(file.targetFilePath, code);
|
|
136
|
-
})());
|
|
137
|
-
}
|
|
138
|
-
await Promise.all(promises);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Resolves an import path from the current generator's context to a target type and file type.
|
|
142
|
-
*
|
|
143
|
-
* @param targetType - The target type of the import destination.
|
|
144
|
-
* @param fileType - The file type of the import destination.
|
|
145
|
-
* @returns The resolved import path string.
|
|
146
|
-
*/
|
|
147
|
-
resolveImport(targetType, fileType) {
|
|
148
|
-
return directories.resolveImport({ targetType, fileType }, { targetType: this.targetType, fileType: this.type });
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Resolves an import path to the common target for the given file type.
|
|
152
|
-
*
|
|
153
|
-
* @param fileType - The file type to import from common.
|
|
154
|
-
* @returns The resolved import path.
|
|
155
|
-
*/
|
|
156
|
-
importCommon(fileType) {
|
|
157
|
-
return this.resolveImport(DecoTargetType.common, fileType);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Resolves an import path to the frontend target for the given file type.
|
|
161
|
-
*
|
|
162
|
-
* @param fileType - The file type to import from frontend.
|
|
163
|
-
* @returns The resolved import path.
|
|
164
|
-
*/
|
|
165
|
-
importFrontend(fileType) {
|
|
166
|
-
return this.resolveImport(DecoTargetType.frontend, fileType);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Resolves an import path to the backend target for the given file type.
|
|
170
|
-
*
|
|
171
|
-
* @param fileType - The file type to import from backend.
|
|
172
|
-
* @returns The resolved import path.
|
|
173
|
-
*/
|
|
174
|
-
importBackend(fileType) {
|
|
175
|
-
return this.resolveImport(DecoTargetType.backend, fileType);
|
|
176
|
-
}
|
|
177
|
-
async processHeader(curretItem, all, env) {
|
|
178
|
-
const { decorator, names } = curretItem;
|
|
113
|
+
async processHeader(curretItem, env) {
|
|
114
|
+
const { decorator } = curretItem;
|
|
179
115
|
const raw = decorator.extractRaw();
|
|
180
|
-
this.
|
|
181
|
-
|
|
182
|
-
});
|
|
183
|
-
const result = new CodeCollector();
|
|
184
|
-
const name = await this.runHeader(curretItem, all, env, result);
|
|
185
|
-
if (!name)
|
|
116
|
+
const headerResult = await this.runHeader(curretItem, env);
|
|
117
|
+
if (!headerResult)
|
|
186
118
|
return null;
|
|
119
|
+
// this.processPredictions(headerResult.code);
|
|
187
120
|
return {
|
|
188
|
-
name,
|
|
121
|
+
name: headerResult.name,
|
|
189
122
|
inputFilePath: raw.inputFilePath,
|
|
190
|
-
code: [...
|
|
191
|
-
imports: this.useAdditionalImports &&
|
|
192
|
-
raw.additionalImports &&
|
|
193
|
-
raw.additionalImports.length > 0
|
|
194
|
-
? [...result.imports, ...raw.additionalImports]
|
|
195
|
-
: [...result.imports],
|
|
123
|
+
code: [...headerResult.code],
|
|
196
124
|
};
|
|
197
125
|
}
|
|
198
|
-
// i for import
|
|
199
|
-
i(_prop, isType) {
|
|
200
|
-
// todo use it
|
|
201
|
-
const prop = _prop.substring(0);
|
|
202
|
-
let found = this.usedImports.find((i) => i.prop === prop);
|
|
203
|
-
if (!found) {
|
|
204
|
-
found = { prop, isType };
|
|
205
|
-
this.usedImports.push(found);
|
|
206
|
-
}
|
|
207
|
-
if (found.isType && !isType)
|
|
208
|
-
found.isType = false;
|
|
209
|
-
return prop;
|
|
210
|
-
}
|
|
211
126
|
}
|
|
212
127
|
//# sourceMappingURL=Generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Generator.js","sourceRoot":"","sources":["../../src/generator/Generator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Generator.js","sourceRoot":"","sources":["../../src/generator/Generator.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,eAAe,GAGhB,MAAM,2CAA2C,CAAC;AASnD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,GACV,MAAM,4BAA4B,CAA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.js";
|
|
1
|
+
import { Generator } from "./Generator.js";
|
|
2
|
+
import type { GeneratorEnv, GeneratorRunItem, GeneratorRunResult } from "../common/types.common.js";
|
|
4
3
|
/**
|
|
5
4
|
* Generator that produces annotation metadata and initial-value factory functions.
|
|
6
5
|
*
|
|
@@ -10,7 +9,7 @@ import { GeneratorEnv } from "../common/types.common.js";
|
|
|
10
9
|
*/
|
|
11
10
|
export declare class GeneratorAnnotations extends Generator {
|
|
12
11
|
constructor();
|
|
13
|
-
protected runHeader(
|
|
12
|
+
protected runHeader(item: GeneratorRunItem, env: GeneratorEnv): Promise<GeneratorRunResult | null>;
|
|
14
13
|
}
|
|
15
14
|
declare const _default: GeneratorAnnotations;
|
|
16
15
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeneratorAnnotations.d.ts","sourceRoot":"","sources":["../../src/generator/GeneratorAnnotations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"GeneratorAnnotations.d.ts","sourceRoot":"","sources":["../../src/generator/GeneratorAnnotations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAO3C,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,2BAA2B,CAAC;AASnC;;;;;;GAMG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;;cASxB,SAAS,CAChC,IAAI,EAAE,gBAAgB,EACtB,GAAG,EAAE,YAAY,GAChB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;CAuEtC;;AAED,wBAA0C"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Generator } from "./Generator.js";
|
|
2
|
-
import { Collector } from "../common/Collector.js";
|
|
3
2
|
import { formatJsonStringify } from "@mxpicture/build-api/code";
|
|
4
|
-
import { DecoFileExtension, DecoFileType,
|
|
3
|
+
import { DecoFileExtension, DecoFileType, DecoPackageType, } from "@mxpicture/gcp-functions-common/decorator";
|
|
5
4
|
const typeRegex = /\"type\": \"([a-zA-Z][a-zA-Z0-9]*)\"/;
|
|
6
5
|
const itemTypeRegex = /\"itemType\": \"(DecoPropertyType\.|)([a-zA-Z][a-zA-Z0-9]*)\"/;
|
|
7
6
|
const propertyRefRegex = /\"propertyRef\": \"([a-zA-Z][a-zA-Z0-9]*)\"/;
|
|
@@ -16,59 +15,46 @@ const dateFormatRegex = /\"dateFormat\": \"([a-zA-Z][a-zA-Z0-9]*)\"/;
|
|
|
16
15
|
*/
|
|
17
16
|
export class GeneratorAnnotations extends Generator {
|
|
18
17
|
constructor() {
|
|
19
|
-
super(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
result.addImport({
|
|
24
|
-
path: "@mxpicture/gcp-functions-common/types",
|
|
25
|
-
props: ["AnnotationsHeader"],
|
|
26
|
-
isType: true,
|
|
27
|
-
}, {
|
|
28
|
-
path: "@mxpicture/gcp-functions-common/helper",
|
|
29
|
-
props: ["annoDocInitial"],
|
|
30
|
-
isType: false,
|
|
31
|
-
}, {
|
|
32
|
-
path: this.importCommon(DecoFileType.doc),
|
|
33
|
-
props: [names.doc],
|
|
34
|
-
isType: true,
|
|
18
|
+
super({
|
|
19
|
+
fileType: DecoFileType.annotations,
|
|
20
|
+
ext: DecoFileExtension.ts,
|
|
21
|
+
packageType: DecoPackageType.common,
|
|
35
22
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
}
|
|
24
|
+
async runHeader(item, env) {
|
|
25
|
+
void env;
|
|
26
|
+
const names = item.names;
|
|
27
|
+
const code = [];
|
|
28
|
+
const header = item.decorator.extractAnnotations();
|
|
39
29
|
const json = await formatJsonStringify(JSON.stringify(header));
|
|
40
30
|
const lines = json.split("\n");
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
code.push("", `export const ${names.initialFunc} = (): Partial<${names.doc}> => annoDocInitial(${names.annotations}.properties);`, "");
|
|
32
|
+
code.push(`export const ${names.annotations}: AnnotationsHeader = `);
|
|
43
33
|
// replace enums and types
|
|
44
34
|
for (let line of lines) {
|
|
45
35
|
// type
|
|
46
36
|
let match = null;
|
|
47
37
|
match = line.match(typeRegex);
|
|
48
38
|
while (match && match.length > 1) {
|
|
49
|
-
|
|
50
|
-
line = line.replace(typeRegex, `type: ${this.i("DecoPropertyType")}.${match[1]}`);
|
|
39
|
+
line = line.replace(typeRegex, `type: DecoPropertyType.${match[1]}`);
|
|
51
40
|
match = line.match(typeRegex);
|
|
52
41
|
}
|
|
53
42
|
// itemType
|
|
54
43
|
match = line.match(itemTypeRegex);
|
|
55
44
|
while (match && match.length > 2) {
|
|
56
|
-
|
|
57
|
-
line = line.replace(itemTypeRegex, `itemType: ${this.i("DecoPropertyType")}.${match[2]}`);
|
|
45
|
+
line = line.replace(itemTypeRegex, `itemType: DecoPropertyType.${match[2]}`);
|
|
58
46
|
match = line.match(itemTypeRegex);
|
|
59
47
|
}
|
|
60
48
|
// propertyRef
|
|
61
49
|
match = line.match(propertyRefRegex);
|
|
62
50
|
while (match && match.length > 1) {
|
|
63
|
-
|
|
64
|
-
line = line.replace(propertyRefRegex, `propertyRef: "${match[1]}" as keyof ${this.i("DecoPropertyDataWoType")}`);
|
|
51
|
+
line = line.replace(propertyRefRegex, `propertyRef: "${match[1]}" as keyof DecoPropertyDataWoType`);
|
|
65
52
|
match = line.match(propertyRefRegex);
|
|
66
53
|
}
|
|
67
54
|
// dateFormat
|
|
68
55
|
match = line.match(dateFormatRegex);
|
|
69
56
|
while (match && match.length > 1) {
|
|
70
|
-
|
|
71
|
-
line = line.replace(dateFormatRegex, `dateFormat: ${this.i("DecoDateFormat")}.${match[1]}`);
|
|
57
|
+
line = line.replace(dateFormatRegex, `dateFormat: DecoDateFormat.${match[1]}`);
|
|
72
58
|
match = line.match(dateFormatRegex);
|
|
73
59
|
}
|
|
74
60
|
// subHeader(Name)
|
|
@@ -77,22 +63,10 @@ export class GeneratorAnnotations extends Generator {
|
|
|
77
63
|
line = line.replace(subHeaderNameRegex, `subHeader: ${match[1]}`);
|
|
78
64
|
match = line.match(subHeaderNameRegex);
|
|
79
65
|
}
|
|
80
|
-
|
|
66
|
+
code.push(line);
|
|
81
67
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
result.addImport({
|
|
85
|
-
path: "@mxpicture/gcp-functions-common/decorator",
|
|
86
|
-
props: [...importDecoTypeProps],
|
|
87
|
-
isType: true,
|
|
88
|
-
});
|
|
89
|
-
if (importDecoProps.size > 0)
|
|
90
|
-
result.addImport({
|
|
91
|
-
path: "@mxpicture/gcp-functions-common/decorator",
|
|
92
|
-
props: [...importDecoProps],
|
|
93
|
-
isType: false,
|
|
94
|
-
});
|
|
95
|
-
return current.decorator.name;
|
|
68
|
+
code.push(";");
|
|
69
|
+
return { name: item.decorator.name, code };
|
|
96
70
|
}
|
|
97
71
|
}
|
|
98
72
|
export default new GeneratorAnnotations();
|