@mxpicture/gcp-functions-generator 0.2.0
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/index.d.ts +1 -0
- package/dist/4testing/index.js +2 -0
- package/dist/4testing/templates/index.d.ts +2 -0
- package/dist/4testing/templates/index.js +3 -0
- package/dist/4testing/templates/template.medication.d.ts +35 -0
- package/dist/4testing/templates/template.medication.js +134 -0
- package/dist/4testing/templates/template.settings.d.ts +23 -0
- package/dist/4testing/templates/template.settings.js +73 -0
- package/dist/4testing/utils.d.ts +5 -0
- package/dist/4testing/utils.js +14 -0
- package/dist/common/Barrel.d.ts +24 -0
- package/dist/common/Barrel.js +80 -0
- package/dist/common/Collector.d.ts +22 -0
- package/dist/common/Collector.js +37 -0
- package/dist/common/Directories.d.ts +36 -0
- package/dist/common/Directories.js +69 -0
- package/dist/common/Evaluate.d.ts +12 -0
- package/dist/common/Evaluate.js +120 -0
- package/dist/common/Extractor.d.ts +33 -0
- package/dist/common/Extractor.js +201 -0
- package/dist/common/GenChangeDetector.d.ts +19 -0
- package/dist/common/GenChangeDetector.js +33 -0
- package/dist/common/generator.common.d.ts +21 -0
- package/dist/common/generator.common.js +86 -0
- package/dist/common/index.d.ts +7 -0
- package/dist/common/index.js +8 -0
- package/dist/generator/Generator.d.ts +41 -0
- package/dist/generator/Generator.js +132 -0
- package/dist/generator/GeneratorAnnotations.d.ts +9 -0
- package/dist/generator/GeneratorAnnotations.js +65 -0
- package/dist/generator/GeneratorBackend.d.ts +13 -0
- package/dist/generator/GeneratorBackend.js +134 -0
- package/dist/generator/GeneratorDoc.d.ts +9 -0
- package/dist/generator/GeneratorDoc.js +22 -0
- package/dist/generator/GeneratorFrontend.d.ts +12 -0
- package/dist/generator/GeneratorFrontend.js +94 -0
- package/dist/generator/GeneratorRoutes.d.ts +11 -0
- package/dist/generator/GeneratorRoutes.js +52 -0
- package/dist/generator/GeneratorZod.d.ts +25 -0
- package/dist/generator/GeneratorZod.js +149 -0
- package/dist/generator/index.d.ts +7 -0
- package/dist/generator/index.js +8 -0
- package/dist/meta/index.d.ts +3 -0
- package/dist/meta/index.js +4 -0
- package/dist/meta/meta.decorators.d.ts +26 -0
- package/dist/meta/meta.decorators.js +17 -0
- package/dist/meta/meta.imports.d.ts +11 -0
- package/dist/meta/meta.imports.js +54 -0
- package/dist/meta/meta.names.d.ts +13 -0
- package/dist/meta/meta.names.js +93 -0
- package/package.json +48 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./utils.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Decorator-based Zod schema generation
|
|
3
|
+
*
|
|
4
|
+
* Since TypeScript interfaces are compile-time only and don't exist at runtime,
|
|
5
|
+
* we demonstrate the decorator system using classes that can serve as both
|
|
6
|
+
* type definitions and runtime metadata carriers.
|
|
7
|
+
*
|
|
8
|
+
* This example shows how to:
|
|
9
|
+
* 1. Use decorators to annotate class properties
|
|
10
|
+
* 2. Generate Zod schemas from the decorator metadata
|
|
11
|
+
* 3. Use the generated schemas for validation
|
|
12
|
+
*/
|
|
13
|
+
import type { DocumentAdmin, DocumentKey } from "@mxpicture/gcp-functions-common/types";
|
|
14
|
+
export declare class MedicationPlanTimesTemplate {
|
|
15
|
+
morning: number;
|
|
16
|
+
noon: number;
|
|
17
|
+
evening: number;
|
|
18
|
+
night: number;
|
|
19
|
+
}
|
|
20
|
+
export declare class MedicationPlanTemplate {
|
|
21
|
+
lastPickDate?: Date;
|
|
22
|
+
times: MedicationPlanTimesTemplate;
|
|
23
|
+
}
|
|
24
|
+
export declare class MedicationTemplate implements DocumentKey, DocumentAdmin {
|
|
25
|
+
id: string;
|
|
26
|
+
createTime?: Date;
|
|
27
|
+
updateTime?: Date;
|
|
28
|
+
ingredient: string;
|
|
29
|
+
dosageMg: number;
|
|
30
|
+
tradeNames: string[];
|
|
31
|
+
size?: number;
|
|
32
|
+
stock: number;
|
|
33
|
+
orderMail?: string;
|
|
34
|
+
plan?: MedicationPlanTemplate;
|
|
35
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Decorator-based Zod schema generation
|
|
3
|
+
*
|
|
4
|
+
* Since TypeScript interfaces are compile-time only and don't exist at runtime,
|
|
5
|
+
* we demonstrate the decorator system using classes that can serve as both
|
|
6
|
+
* type definitions and runtime metadata carriers.
|
|
7
|
+
*
|
|
8
|
+
* This example shows how to:
|
|
9
|
+
* 1. Use decorators to annotate class properties
|
|
10
|
+
* 2. Generate Zod schemas from the decorator metadata
|
|
11
|
+
* 3. Use the generated schemas for validation
|
|
12
|
+
*/
|
|
13
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
14
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
+
};
|
|
19
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
21
|
+
};
|
|
22
|
+
import { MetaArray, MetaCreateTime, MetaDate, MetaInterface, MetaKey, MetaHeadInterface, MetaNumber, MetaObject, MetaString, MetaUpdateTime, } from "../../meta/meta.decorators.js";
|
|
23
|
+
import { MetaPropertyType } from "@mxpicture/gcp-functions-common/meta";
|
|
24
|
+
let MedicationPlanTimesTemplate = class MedicationPlanTimesTemplate {
|
|
25
|
+
morning;
|
|
26
|
+
noon;
|
|
27
|
+
evening;
|
|
28
|
+
night;
|
|
29
|
+
};
|
|
30
|
+
__decorate([
|
|
31
|
+
MetaNumber({ title: "Morning", min: 0, minInclusive: false }),
|
|
32
|
+
__metadata("design:type", Number)
|
|
33
|
+
], MedicationPlanTimesTemplate.prototype, "morning", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
MetaNumber({ title: "Noon", min: 0, minInclusive: false }),
|
|
36
|
+
__metadata("design:type", Number)
|
|
37
|
+
], MedicationPlanTimesTemplate.prototype, "noon", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
MetaNumber({ title: "Evening", min: 0, minInclusive: false }),
|
|
40
|
+
__metadata("design:type", Number)
|
|
41
|
+
], MedicationPlanTimesTemplate.prototype, "evening", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
MetaNumber({ title: "Night", min: 0, minInclusive: false }),
|
|
44
|
+
__metadata("design:type", Number)
|
|
45
|
+
], MedicationPlanTimesTemplate.prototype, "night", void 0);
|
|
46
|
+
MedicationPlanTimesTemplate = __decorate([
|
|
47
|
+
MetaInterface({ title: "Medication Plan Times" })
|
|
48
|
+
], MedicationPlanTimesTemplate);
|
|
49
|
+
export { MedicationPlanTimesTemplate };
|
|
50
|
+
let MedicationPlanTemplate = class MedicationPlanTemplate {
|
|
51
|
+
lastPickDate;
|
|
52
|
+
times;
|
|
53
|
+
};
|
|
54
|
+
__decorate([
|
|
55
|
+
MetaDate({ title: "Last Pick Date", optional: true }),
|
|
56
|
+
__metadata("design:type", Date)
|
|
57
|
+
], MedicationPlanTemplate.prototype, "lastPickDate", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
MetaObject({ title: "Times" }),
|
|
60
|
+
__metadata("design:type", MedicationPlanTimesTemplate)
|
|
61
|
+
], MedicationPlanTemplate.prototype, "times", void 0);
|
|
62
|
+
MedicationPlanTemplate = __decorate([
|
|
63
|
+
MetaInterface({ title: "Medication Plan" })
|
|
64
|
+
], MedicationPlanTemplate);
|
|
65
|
+
export { MedicationPlanTemplate };
|
|
66
|
+
let MedicationTemplate = class MedicationTemplate {
|
|
67
|
+
id;
|
|
68
|
+
createTime;
|
|
69
|
+
updateTime;
|
|
70
|
+
ingredient;
|
|
71
|
+
dosageMg;
|
|
72
|
+
tradeNames;
|
|
73
|
+
size;
|
|
74
|
+
stock;
|
|
75
|
+
orderMail;
|
|
76
|
+
plan;
|
|
77
|
+
};
|
|
78
|
+
__decorate([
|
|
79
|
+
MetaKey({}),
|
|
80
|
+
__metadata("design:type", String)
|
|
81
|
+
], MedicationTemplate.prototype, "id", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
MetaCreateTime({ optional: true }),
|
|
84
|
+
__metadata("design:type", Date)
|
|
85
|
+
], MedicationTemplate.prototype, "createTime", void 0);
|
|
86
|
+
__decorate([
|
|
87
|
+
MetaUpdateTime({ optional: true }),
|
|
88
|
+
__metadata("design:type", Date)
|
|
89
|
+
], MedicationTemplate.prototype, "updateTime", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
MetaString({ title: "Ingredient" }),
|
|
92
|
+
__metadata("design:type", String)
|
|
93
|
+
], MedicationTemplate.prototype, "ingredient", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
MetaNumber({ title: "Dosage mg", min: 0 }),
|
|
96
|
+
__metadata("design:type", Number)
|
|
97
|
+
], MedicationTemplate.prototype, "dosageMg", void 0);
|
|
98
|
+
__decorate([
|
|
99
|
+
MetaArray({ title: "Trade Names", itemType: MetaPropertyType.string }),
|
|
100
|
+
__metadata("design:type", Array)
|
|
101
|
+
], MedicationTemplate.prototype, "tradeNames", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
MetaNumber({ title: "Size", min: 1, optional: true }),
|
|
104
|
+
__metadata("design:type", Number)
|
|
105
|
+
], MedicationTemplate.prototype, "size", void 0);
|
|
106
|
+
__decorate([
|
|
107
|
+
MetaNumber({ title: "Stock", min: 0 }),
|
|
108
|
+
__metadata("design:type", Number)
|
|
109
|
+
], MedicationTemplate.prototype, "stock", void 0);
|
|
110
|
+
__decorate([
|
|
111
|
+
MetaString({ title: "Order Mail", optional: true }),
|
|
112
|
+
__metadata("design:type", String)
|
|
113
|
+
], MedicationTemplate.prototype, "orderMail", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
MetaObject({ title: "Plan", optional: true }),
|
|
116
|
+
__metadata("design:type", MedicationPlanTemplate)
|
|
117
|
+
], MedicationTemplate.prototype, "plan", void 0);
|
|
118
|
+
MedicationTemplate = __decorate([
|
|
119
|
+
MetaHeadInterface({
|
|
120
|
+
title: "Medication",
|
|
121
|
+
routes: {
|
|
122
|
+
crud: true,
|
|
123
|
+
testRoute: { requestType: "DocumentKey", responseType: "{test:boolean}" },
|
|
124
|
+
},
|
|
125
|
+
additionalImports: [
|
|
126
|
+
{
|
|
127
|
+
path: "@mxpicture/gcp-functions-common/types",
|
|
128
|
+
props: ["DocumentKey"],
|
|
129
|
+
isType: true,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
})
|
|
133
|
+
], MedicationTemplate);
|
|
134
|
+
export { MedicationTemplate };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Decorator-based Zod schema generation
|
|
3
|
+
*
|
|
4
|
+
* Since TypeScript interfaces are compile-time only and don't exist at runtime,
|
|
5
|
+
* we demonstrate the decorator system using classes that can serve as both
|
|
6
|
+
* type definitions and runtime metadata carriers.
|
|
7
|
+
*
|
|
8
|
+
* This example shows how to:
|
|
9
|
+
* 1. Use decorators to annotate class properties
|
|
10
|
+
* 2. Generate Zod schemas from the decorator metadata
|
|
11
|
+
* 3. Use the generated schemas for validation
|
|
12
|
+
*/
|
|
13
|
+
import type { DocumentAdmin, DocumentKey } from "@mxpicture/gcp-functions-common/types";
|
|
14
|
+
export declare class SettingsTemplate implements DocumentKey, DocumentAdmin {
|
|
15
|
+
id: string;
|
|
16
|
+
createTime?: Date;
|
|
17
|
+
updateTime?: Date;
|
|
18
|
+
active: boolean;
|
|
19
|
+
name: string;
|
|
20
|
+
type: string;
|
|
21
|
+
valueNumber?: number;
|
|
22
|
+
valueString?: string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Decorator-based Zod schema generation
|
|
3
|
+
*
|
|
4
|
+
* Since TypeScript interfaces are compile-time only and don't exist at runtime,
|
|
5
|
+
* we demonstrate the decorator system using classes that can serve as both
|
|
6
|
+
* type definitions and runtime metadata carriers.
|
|
7
|
+
*
|
|
8
|
+
* This example shows how to:
|
|
9
|
+
* 1. Use decorators to annotate class properties
|
|
10
|
+
* 2. Generate Zod schemas from the decorator metadata
|
|
11
|
+
* 3. Use the generated schemas for validation
|
|
12
|
+
*/
|
|
13
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
14
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
+
};
|
|
19
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
21
|
+
};
|
|
22
|
+
import { MetaBoolean, MetaCreateTime, MetaKey, MetaHeadInterface, MetaNumber, MetaString, MetaUpdateTime, } from "../../meta/meta.decorators.js";
|
|
23
|
+
let SettingsTemplate = class SettingsTemplate {
|
|
24
|
+
id;
|
|
25
|
+
createTime;
|
|
26
|
+
updateTime;
|
|
27
|
+
active;
|
|
28
|
+
name;
|
|
29
|
+
type; // todo enum
|
|
30
|
+
valueNumber;
|
|
31
|
+
valueString;
|
|
32
|
+
};
|
|
33
|
+
__decorate([
|
|
34
|
+
MetaKey({}),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], SettingsTemplate.prototype, "id", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
MetaCreateTime({ optional: true }),
|
|
39
|
+
__metadata("design:type", Date)
|
|
40
|
+
], SettingsTemplate.prototype, "createTime", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
MetaUpdateTime({ optional: true }),
|
|
43
|
+
__metadata("design:type", Date)
|
|
44
|
+
], SettingsTemplate.prototype, "updateTime", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
MetaBoolean({ title: "Active" }),
|
|
47
|
+
__metadata("design:type", Boolean)
|
|
48
|
+
], SettingsTemplate.prototype, "active", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
MetaString({ title: "Name" }),
|
|
51
|
+
__metadata("design:type", String)
|
|
52
|
+
], SettingsTemplate.prototype, "name", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
MetaString({ title: "Type" }),
|
|
55
|
+
__metadata("design:type", String)
|
|
56
|
+
], SettingsTemplate.prototype, "type", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
MetaNumber({ title: "Number", optional: true }),
|
|
59
|
+
__metadata("design:type", Number)
|
|
60
|
+
], SettingsTemplate.prototype, "valueNumber", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
MetaString({ title: "String", optional: true }),
|
|
63
|
+
__metadata("design:type", String)
|
|
64
|
+
], SettingsTemplate.prototype, "valueString", void 0);
|
|
65
|
+
SettingsTemplate = __decorate([
|
|
66
|
+
MetaHeadInterface({
|
|
67
|
+
title: "Settings",
|
|
68
|
+
routes: {
|
|
69
|
+
crud: true,
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
], SettingsTemplate);
|
|
73
|
+
export { SettingsTemplate };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const testingDir: string;
|
|
2
|
+
export declare const wsRoot: string;
|
|
3
|
+
export declare const templatesDir: string;
|
|
4
|
+
export declare const createTestWorkspace: () => Promise<string>;
|
|
5
|
+
export declare const removeTestWorkspace: (p: string | null) => Promise<void>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { rm } from "node:fs/promises";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
export const testingDir = __dirname;
|
|
4
|
+
export const wsRoot = resolve(testingDir, "../..");
|
|
5
|
+
export const templatesDir = resolve(testingDir, "./templates");
|
|
6
|
+
export const createTestWorkspace = async () => join(testingDir, `generator-test-${Date.now()}`);
|
|
7
|
+
export const removeTestWorkspace = async (p) => {
|
|
8
|
+
if (!p)
|
|
9
|
+
return;
|
|
10
|
+
try {
|
|
11
|
+
return rm(p, { recursive: true });
|
|
12
|
+
}
|
|
13
|
+
catch { }
|
|
14
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MetaTargetType } from "@mxpicture/gcp-functions-common/meta";
|
|
2
|
+
export interface BarrelResult {
|
|
3
|
+
dirPath: string;
|
|
4
|
+
barrelFilePath: string;
|
|
5
|
+
exportsCode: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface BarrelFileGroup {
|
|
8
|
+
dirPath: string;
|
|
9
|
+
barrelFilename: string;
|
|
10
|
+
filenames: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare class Barrel {
|
|
13
|
+
readonly targetType: MetaTargetType;
|
|
14
|
+
static ignorePackageJson: boolean;
|
|
15
|
+
static instances: Barrel[];
|
|
16
|
+
protected filePaths: string[];
|
|
17
|
+
static instance(targetType: MetaTargetType): Barrel;
|
|
18
|
+
protected constructor(targetType: MetaTargetType);
|
|
19
|
+
add(...filePaths: string[]): void;
|
|
20
|
+
create(): BarrelResult[];
|
|
21
|
+
write(results: BarrelResult[]): Promise<void>;
|
|
22
|
+
ensurePackageBarrels(results: BarrelResult[]): Promise<void>;
|
|
23
|
+
protected groupPaths(filePaths: string[]): BarrelFileGroup[];
|
|
24
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { basename, dirname, join } from "node:path";
|
|
2
|
+
import { formatCode } from "@mxpicture/gcp-functions-code/common";
|
|
3
|
+
import { mkdir, writeFile, readFile } from "node:fs/promises";
|
|
4
|
+
import { directories } from "./Directories.js";
|
|
5
|
+
export class Barrel {
|
|
6
|
+
targetType;
|
|
7
|
+
static ignorePackageJson = false;
|
|
8
|
+
static instances = [];
|
|
9
|
+
filePaths = [];
|
|
10
|
+
static instance(targetType) {
|
|
11
|
+
let found = this.instances.find((barrel) => barrel.targetType === targetType);
|
|
12
|
+
if (!found) {
|
|
13
|
+
found = new Barrel(targetType);
|
|
14
|
+
this.instances.push(found);
|
|
15
|
+
}
|
|
16
|
+
return found;
|
|
17
|
+
}
|
|
18
|
+
constructor(targetType) {
|
|
19
|
+
this.targetType = targetType;
|
|
20
|
+
}
|
|
21
|
+
add(...filePaths) {
|
|
22
|
+
this.filePaths.push(...filePaths);
|
|
23
|
+
}
|
|
24
|
+
create() {
|
|
25
|
+
return this.groupPaths(this.filePaths).map((group) => ({
|
|
26
|
+
dirPath: group.dirPath,
|
|
27
|
+
barrelFilePath: join(group.dirPath, group.barrelFilename),
|
|
28
|
+
exportsCode: group.filenames.map((fielname) => `export * from "./${fielname}";`),
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
async write(results) {
|
|
32
|
+
const promises = [];
|
|
33
|
+
for (const result of results) {
|
|
34
|
+
promises.push((async () => {
|
|
35
|
+
const code = await formatCode(result.exportsCode.join("\n"));
|
|
36
|
+
await mkdir(result.dirPath, { recursive: true });
|
|
37
|
+
return writeFile(result.barrelFilePath, code);
|
|
38
|
+
})());
|
|
39
|
+
}
|
|
40
|
+
await Promise.all(promises);
|
|
41
|
+
}
|
|
42
|
+
async ensurePackageBarrels(results) {
|
|
43
|
+
if (Barrel.ignorePackageJson) {
|
|
44
|
+
console.log("ensurePackageBarrels ignored");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const filePath = directories.targetPackageJson(this.targetType);
|
|
48
|
+
const raw = await readFile(filePath, "utf8");
|
|
49
|
+
const pkg = JSON.parse(raw);
|
|
50
|
+
for (const result of results) {
|
|
51
|
+
const parts = result.barrelFilePath.split("/src/");
|
|
52
|
+
if (parts.length < 2)
|
|
53
|
+
continue; // todo logging?
|
|
54
|
+
const indexPath = `./src/${parts[parts.length - 1]}`;
|
|
55
|
+
const expPath = dirname(`./${parts[parts.length - 1]}`);
|
|
56
|
+
if (!pkg.exports)
|
|
57
|
+
pkg.exports = {};
|
|
58
|
+
pkg.exports[expPath] = indexPath;
|
|
59
|
+
}
|
|
60
|
+
await writeFile(filePath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
61
|
+
}
|
|
62
|
+
groupPaths(filePaths) {
|
|
63
|
+
const groups = [];
|
|
64
|
+
for (const filePath of filePaths) {
|
|
65
|
+
const dirPath = dirname(filePath);
|
|
66
|
+
const filename = basename(filePath);
|
|
67
|
+
let group = groups.find((g) => g.dirPath === dirPath);
|
|
68
|
+
if (!group) {
|
|
69
|
+
group = {
|
|
70
|
+
dirPath,
|
|
71
|
+
filenames: [],
|
|
72
|
+
barrelFilename: "index.ts",
|
|
73
|
+
};
|
|
74
|
+
groups.push(group);
|
|
75
|
+
}
|
|
76
|
+
group.filenames.push(filename.replace(/\.ts$/, ".js"));
|
|
77
|
+
}
|
|
78
|
+
return groups;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { MetaTargetType } from "@mxpicture/gcp-functions-common/meta";
|
|
2
|
+
import { MetaNames } from "@mxpicture/gcp-functions-common/types";
|
|
3
|
+
export interface CollectorKey {
|
|
4
|
+
basename: string;
|
|
5
|
+
targetType: MetaTargetType;
|
|
6
|
+
}
|
|
7
|
+
export interface CollectorData {
|
|
8
|
+
names: MetaNames;
|
|
9
|
+
}
|
|
10
|
+
export interface CollectorItem {
|
|
11
|
+
key: CollectorKey;
|
|
12
|
+
data: CollectorData;
|
|
13
|
+
}
|
|
14
|
+
export declare class Collector {
|
|
15
|
+
protected items: CollectorItem[];
|
|
16
|
+
static instance(): Collector;
|
|
17
|
+
constructor();
|
|
18
|
+
add(basename: string, targetType: MetaTargetType, data: CollectorData): void;
|
|
19
|
+
find(basename: string, targetType: MetaTargetType): CollectorItem | null;
|
|
20
|
+
findGeneric(name: string): CollectorItem[];
|
|
21
|
+
findFirst(name: string): CollectorItem | null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { metaNameProperties, } from "@mxpicture/gcp-functions-common/types";
|
|
2
|
+
let __instance = null;
|
|
3
|
+
export class Collector {
|
|
4
|
+
items = [];
|
|
5
|
+
static instance() {
|
|
6
|
+
if (!__instance)
|
|
7
|
+
__instance = new Collector();
|
|
8
|
+
return __instance;
|
|
9
|
+
}
|
|
10
|
+
constructor() { }
|
|
11
|
+
add(basename, targetType, data) {
|
|
12
|
+
if (this.find(basename, targetType))
|
|
13
|
+
return;
|
|
14
|
+
this.items.push({ key: { basename, targetType }, data: { ...data } });
|
|
15
|
+
}
|
|
16
|
+
find(basename, targetType) {
|
|
17
|
+
return (this.items.find((item) => item.key.basename === basename && item.key.targetType === targetType) ?? null);
|
|
18
|
+
}
|
|
19
|
+
findGeneric(name) {
|
|
20
|
+
const results = [];
|
|
21
|
+
for (const item of this.items) {
|
|
22
|
+
if (item.key.basename === name)
|
|
23
|
+
results.push(item);
|
|
24
|
+
for (const prop of metaNameProperties) {
|
|
25
|
+
if (item.data.names[prop] === name) {
|
|
26
|
+
results.push(item);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return results;
|
|
32
|
+
}
|
|
33
|
+
findFirst(name) {
|
|
34
|
+
const results = this.findGeneric(name);
|
|
35
|
+
return results.length > 0 ? results[0] : null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { MetaFileType, MetaTargetType } from "@mxpicture/gcp-functions-common/meta";
|
|
2
|
+
export interface DirectoriesResolverParams {
|
|
3
|
+
targetType: MetaTargetType;
|
|
4
|
+
fileType: MetaFileType;
|
|
5
|
+
}
|
|
6
|
+
export type DirectoriesResolver = (imp: DirectoriesResolverParams, // e.g ${TargetType}/${MetaFileType} --> common/doc,
|
|
7
|
+
current: DirectoriesResolverParams) => string;
|
|
8
|
+
export interface DirectoriesParams {
|
|
9
|
+
cwd: string;
|
|
10
|
+
templatesDir: string;
|
|
11
|
+
targetDir: string;
|
|
12
|
+
importResolver: DirectoriesResolver;
|
|
13
|
+
}
|
|
14
|
+
declare class Directories {
|
|
15
|
+
protected _params: DirectoriesParams | null;
|
|
16
|
+
constructor();
|
|
17
|
+
setup(params: DirectoriesParams): void;
|
|
18
|
+
get templatesDir(): string;
|
|
19
|
+
targetDir(targetType: MetaTargetType): string;
|
|
20
|
+
targetBasePath(targetType: MetaTargetType): string;
|
|
21
|
+
toTargetPath(type: MetaFileType, filename: string, targetType: MetaTargetType): string;
|
|
22
|
+
targetPackageJson(targetType: MetaTargetType): string;
|
|
23
|
+
templatesPathRead(): Promise<string[]>;
|
|
24
|
+
resolveImport(imp: {
|
|
25
|
+
targetType: MetaTargetType;
|
|
26
|
+
fileType: MetaFileType;
|
|
27
|
+
} | string, currentFile: {
|
|
28
|
+
targetType: MetaTargetType;
|
|
29
|
+
fileType: MetaFileType;
|
|
30
|
+
} | string): string;
|
|
31
|
+
splitResolverPath(path: string): DirectoriesResolverParams;
|
|
32
|
+
concatResolverPath(params: DirectoriesResolverParams): string;
|
|
33
|
+
protected get params(): DirectoriesParams;
|
|
34
|
+
}
|
|
35
|
+
export declare const directories: Directories;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { join, resolve } from "node:path";
|
|
2
|
+
import { isTemplateFile } from "@mxpicture/gcp-functions-code/common";
|
|
3
|
+
import { readdir } from "node:fs/promises";
|
|
4
|
+
import { guardMetaFileType, guardMetaTargetType, } from "@mxpicture/gcp-functions-common/meta";
|
|
5
|
+
let __instance = null;
|
|
6
|
+
const instance = () => {
|
|
7
|
+
if (!__instance)
|
|
8
|
+
__instance = new Directories();
|
|
9
|
+
return __instance;
|
|
10
|
+
};
|
|
11
|
+
class Directories {
|
|
12
|
+
_params = null;
|
|
13
|
+
constructor() { }
|
|
14
|
+
setup(params) {
|
|
15
|
+
this._params = {
|
|
16
|
+
cwd: params.cwd,
|
|
17
|
+
templatesDir: resolve(params.cwd, params.templatesDir),
|
|
18
|
+
targetDir: resolve(params.cwd, params.targetDir),
|
|
19
|
+
importResolver: params.importResolver,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
get templatesDir() {
|
|
23
|
+
return this.params.templatesDir;
|
|
24
|
+
}
|
|
25
|
+
targetDir(targetType) {
|
|
26
|
+
return `${this.targetBasePath(targetType)}/src`;
|
|
27
|
+
}
|
|
28
|
+
targetBasePath(targetType) {
|
|
29
|
+
return join(this.params.targetDir, targetType);
|
|
30
|
+
}
|
|
31
|
+
toTargetPath(type, filename, targetType) {
|
|
32
|
+
return join(this.targetDir(targetType), type, filename);
|
|
33
|
+
}
|
|
34
|
+
targetPackageJson(targetType) {
|
|
35
|
+
return `${this.targetBasePath(targetType)}/package.json`;
|
|
36
|
+
}
|
|
37
|
+
async templatesPathRead() {
|
|
38
|
+
return (await readdir(this.templatesDir))
|
|
39
|
+
.filter(isTemplateFile)
|
|
40
|
+
.map((name) => join(this.templatesDir, name));
|
|
41
|
+
}
|
|
42
|
+
resolveImport(imp, currentFile) {
|
|
43
|
+
return this.params.importResolver(typeof imp === "string" ? this.splitResolverPath(imp) : imp, typeof currentFile === "string"
|
|
44
|
+
? this.splitResolverPath(currentFile)
|
|
45
|
+
: currentFile);
|
|
46
|
+
}
|
|
47
|
+
splitResolverPath(path) {
|
|
48
|
+
const parts = path.split("/");
|
|
49
|
+
if (parts.length !== 2)
|
|
50
|
+
throw new Error(`${path} does not fit the pattern {TargetType}/{MetaFileType}`);
|
|
51
|
+
const [_targetType, _fileType] = parts;
|
|
52
|
+
const fileType = guardMetaFileType(_fileType);
|
|
53
|
+
if (!fileType)
|
|
54
|
+
throw new Error(`${path}: fileType ${_fileType} invalid`);
|
|
55
|
+
const targetType = guardMetaTargetType(_targetType);
|
|
56
|
+
if (!targetType)
|
|
57
|
+
throw new Error(`${path}: targetType ${_targetType} invalid`);
|
|
58
|
+
return { targetType, fileType };
|
|
59
|
+
}
|
|
60
|
+
concatResolverPath(params) {
|
|
61
|
+
return `${params.targetType}/${params.fileType}`;
|
|
62
|
+
}
|
|
63
|
+
get params() {
|
|
64
|
+
if (!this._params)
|
|
65
|
+
throw new Error("Directories: setup needed!");
|
|
66
|
+
return this._params;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export const directories = instance();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
export declare class Evaluate {
|
|
3
|
+
protected checker: ts.TypeChecker;
|
|
4
|
+
protected seen: Set<ts.Node>;
|
|
5
|
+
constructor(checker: ts.TypeChecker, seen?: Set<ts.Node>);
|
|
6
|
+
protected array(expr: ts.Expression): any[] | undefined;
|
|
7
|
+
protected prop(expr: ts.Expression): any;
|
|
8
|
+
protected identifier(expr: ts.Expression): any;
|
|
9
|
+
protected object(expr: ts.Expression): Record<string, any> | undefined;
|
|
10
|
+
protected getNameText(name: ts.PropertyName): string | undefined;
|
|
11
|
+
run(expr: ts.Expression): any;
|
|
12
|
+
}
|