@postxl/generator 0.74.1 → 1.0.1
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/LICENSE +50 -0
- package/README.md +79 -1
- package/dist/generator-manager.class.d.ts +59 -0
- package/dist/generator-manager.class.js +221 -0
- package/dist/generator.class.d.ts +90 -0
- package/dist/generator.class.js +32 -0
- package/dist/generator.context.d.ts +174 -0
- package/dist/generator.context.js +125 -0
- package/dist/helpers/branded.types.d.ts +149 -0
- package/dist/helpers/branded.types.js +111 -0
- package/dist/helpers/config-builder.class.d.ts +27 -0
- package/dist/helpers/config-builder.class.js +54 -0
- package/dist/helpers/import-generator.class.d.ts +70 -0
- package/dist/helpers/import-generator.class.js +166 -0
- package/dist/helpers/importable.types.d.ts +52 -0
- package/dist/helpers/importable.types.js +15 -0
- package/dist/helpers/index-generator.class.d.ts +10 -0
- package/dist/helpers/index-generator.class.js +46 -0
- package/dist/helpers/index.d.ts +8 -0
- package/dist/helpers/index.js +24 -0
- package/dist/helpers/package-json.generator.d.ts +56 -0
- package/dist/helpers/package-json.generator.js +36 -0
- package/dist/helpers/tsconfig.generator.d.ts +1 -0
- package/dist/helpers/tsconfig.generator.js +14 -0
- package/dist/helpers/verify-context.d.ts +4 -0
- package/dist/helpers/verify-context.js +23 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +21 -0
- package/dist/utils/checksum.d.ts +10 -0
- package/dist/utils/checksum.js +132 -0
- package/dist/utils/fs-utils.d.ts +34 -0
- package/dist/utils/fs-utils.js +126 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.js +26 -0
- package/dist/utils/jsdoc.d.ts +12 -0
- package/dist/utils/jsdoc.js +37 -0
- package/dist/utils/lint.d.ts +46 -0
- package/dist/utils/lint.js +154 -0
- package/dist/utils/lockfile.d.ts +7 -0
- package/dist/utils/lockfile.js +80 -0
- package/dist/utils/logger.class.d.ts +25 -0
- package/dist/utils/logger.class.js +55 -0
- package/dist/utils/merge-conflict.d.ts +55 -0
- package/dist/utils/merge-conflict.js +264 -0
- package/dist/utils/path.d.ts +52 -0
- package/dist/utils/path.js +183 -0
- package/dist/utils/prettier-config.d.ts +2 -0
- package/dist/utils/prettier-config.js +13 -0
- package/dist/utils/prettier.d.ts +5 -0
- package/dist/utils/prettier.js +67 -0
- package/dist/utils/prettier.skiptest.d.ts +1 -0
- package/dist/utils/prettier.skiptest.js +22 -0
- package/dist/utils/promise.d.ts +2 -0
- package/dist/utils/promise.js +10 -0
- package/dist/utils/string-functions.d.ts +9 -0
- package/dist/utils/string-functions.js +23 -0
- package/dist/utils/sync-log-result.d.ts +9 -0
- package/dist/utils/sync-log-result.js +90 -0
- package/dist/utils/sync.d.ts +143 -0
- package/dist/utils/sync.js +325 -0
- package/dist/utils/template.d.ts +66 -0
- package/dist/utils/template.js +159 -0
- package/dist/utils/vfs.class.d.ts +115 -0
- package/dist/utils/vfs.class.js +239 -0
- package/dist/utils/zip.d.ts +13 -0
- package/dist/utils/zip.js +40 -0
- package/package.json +57 -34
- package/dist/generator.d.ts +0 -13
- package/dist/generator.js +0 -455
- package/dist/generators/enums/react.generator.d.ts +0 -10
- package/dist/generators/enums/react.generator.js +0 -110
- package/dist/generators/enums/types.generator.d.ts +0 -10
- package/dist/generators/enums/types.generator.js +0 -39
- package/dist/generators/indices/data/module.generator.d.ts +0 -9
- package/dist/generators/indices/data/module.generator.js +0 -60
- package/dist/generators/indices/data/service.generator.d.ts +0 -9
- package/dist/generators/indices/data/service.generator.js +0 -249
- package/dist/generators/indices/data/types.generator.d.ts +0 -9
- package/dist/generators/indices/data/types.generator.js +0 -49
- package/dist/generators/indices/dispatcher-service.generator.d.ts +0 -9
- package/dist/generators/indices/dispatcher-service.generator.js +0 -107
- package/dist/generators/indices/export/class.generator.d.ts +0 -9
- package/dist/generators/indices/export/class.generator.js +0 -140
- package/dist/generators/indices/export/encoder.generator.d.ts +0 -9
- package/dist/generators/indices/export/encoder.generator.js +0 -50
- package/dist/generators/indices/import/convert-functions.generator.d.ts +0 -9
- package/dist/generators/indices/import/convert-functions.generator.js +0 -509
- package/dist/generators/indices/import/decoder.generator.d.ts +0 -9
- package/dist/generators/indices/import/decoder.generator.js +0 -40
- package/dist/generators/indices/import/service.generator.d.ts +0 -9
- package/dist/generators/indices/import/service.generator.js +0 -573
- package/dist/generators/indices/import/types.generator.d.ts +0 -9
- package/dist/generators/indices/import/types.generator.js +0 -242
- package/dist/generators/indices/repositories.generator.d.ts +0 -9
- package/dist/generators/indices/repositories.generator.js +0 -25
- package/dist/generators/indices/routes.generator.d.ts +0 -9
- package/dist/generators/indices/routes.generator.js +0 -29
- package/dist/generators/indices/seed-migration.generator.d.ts +0 -9
- package/dist/generators/indices/seed-migration.generator.js +0 -36
- package/dist/generators/indices/seed-template.generator.d.ts +0 -9
- package/dist/generators/indices/seed-template.generator.js +0 -80
- package/dist/generators/indices/testids.generator.d.ts +0 -7
- package/dist/generators/indices/testids.generator.js +0 -71
- package/dist/generators/indices/types.generator.d.ts +0 -10
- package/dist/generators/indices/types.generator.js +0 -35
- package/dist/generators/indices/update/actiontypes.generator.d.ts +0 -9
- package/dist/generators/indices/update/actiontypes.generator.js +0 -49
- package/dist/generators/indices/update/module.generator.d.ts +0 -9
- package/dist/generators/indices/update/module.generator.js +0 -41
- package/dist/generators/indices/update/service.generator.d.ts +0 -9
- package/dist/generators/indices/update/service.generator.js +0 -34
- package/dist/generators/indices/view/module.generator.d.ts +0 -9
- package/dist/generators/indices/view/module.generator.js +0 -39
- package/dist/generators/indices/view/service.generator.d.ts +0 -9
- package/dist/generators/indices/view/service.generator.js +0 -34
- package/dist/generators/models/admin.page.generator.d.ts +0 -7
- package/dist/generators/models/admin.page.generator.js +0 -74
- package/dist/generators/models/export/encoder.generator.d.ts +0 -9
- package/dist/generators/models/export/encoder.generator.js +0 -51
- package/dist/generators/models/import/decoder.generator.d.ts +0 -9
- package/dist/generators/models/import/decoder.generator.js +0 -148
- package/dist/generators/models/react/context.generator.d.ts +0 -9
- package/dist/generators/models/react/context.generator.js +0 -71
- package/dist/generators/models/react/index.d.ts +0 -10
- package/dist/generators/models/react/index.js +0 -31
- package/dist/generators/models/react/library.generator.d.ts +0 -10
- package/dist/generators/models/react/library.generator.js +0 -94
- package/dist/generators/models/react/lookup.generator.d.ts +0 -9
- package/dist/generators/models/react/lookup.generator.js +0 -175
- package/dist/generators/models/react/modals.generator.d.ts +0 -23
- package/dist/generators/models/react/modals.generator.js +0 -710
- package/dist/generators/models/repository.generator.d.ts +0 -9
- package/dist/generators/models/repository.generator.js +0 -955
- package/dist/generators/models/route.generator.d.ts +0 -9
- package/dist/generators/models/route.generator.js +0 -92
- package/dist/generators/models/seed.generator.d.ts +0 -21
- package/dist/generators/models/seed.generator.js +0 -285
- package/dist/generators/models/stub.generator.d.ts +0 -9
- package/dist/generators/models/stub.generator.js +0 -92
- package/dist/generators/models/types.generator.d.ts +0 -9
- package/dist/generators/models/types.generator.js +0 -125
- package/dist/generators/models/update/service.generator.d.ts +0 -10
- package/dist/generators/models/update/service.generator.js +0 -302
- package/dist/generators/models/view/service.generator.d.ts +0 -10
- package/dist/generators/models/view/service.generator.js +0 -239
- package/dist/lib/attributes.d.ts +0 -114
- package/dist/lib/attributes.js +0 -2
- package/dist/lib/exports.d.ts +0 -45
- package/dist/lib/exports.js +0 -90
- package/dist/lib/imports.d.ts +0 -65
- package/dist/lib/imports.js +0 -114
- package/dist/lib/meta.d.ts +0 -1191
- package/dist/lib/meta.js +0 -434
- package/dist/lib/schema/fields.d.ts +0 -46
- package/dist/lib/schema/fields.js +0 -62
- package/dist/lib/schema/schema.d.ts +0 -466
- package/dist/lib/schema/schema.js +0 -18
- package/dist/lib/schema/types.d.ts +0 -201
- package/dist/lib/schema/types.js +0 -112
- package/dist/lib/serializer.d.ts +0 -15
- package/dist/lib/serializer.js +0 -24
- package/dist/lib/test-id-collector.d.ts +0 -42
- package/dist/lib/test-id-collector.js +0 -53
- package/dist/lib/types.d.ts +0 -7
- package/dist/lib/types.js +0 -13
- package/dist/lib/typescript.d.ts +0 -5
- package/dist/lib/typescript.js +0 -22
- package/dist/lib/utils/ast.d.ts +0 -29
- package/dist/lib/utils/ast.js +0 -23
- package/dist/lib/utils/error.d.ts +0 -17
- package/dist/lib/utils/error.js +0 -52
- package/dist/lib/utils/file.d.ts +0 -10
- package/dist/lib/utils/file.js +0 -56
- package/dist/lib/utils/jsdoc.d.ts +0 -9
- package/dist/lib/utils/jsdoc.js +0 -37
- package/dist/lib/utils/logger.d.ts +0 -17
- package/dist/lib/utils/logger.js +0 -12
- package/dist/lib/utils/string.d.ts +0 -40
- package/dist/lib/utils/string.js +0 -187
- package/dist/lib/utils/types.d.ts +0 -12
- package/dist/lib/utils/types.js +0 -2
- package/dist/lib/zod.d.ts +0 -8
- package/dist/lib/zod.js +0 -60
- package/dist/prisma/attributes.d.ts +0 -21
- package/dist/prisma/attributes.js +0 -175
- package/dist/prisma/client-path.d.ts +0 -7
- package/dist/prisma/client-path.js +0 -29
- package/dist/prisma/parse.d.ts +0 -12
- package/dist/prisma/parse.js +0 -452
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { NonEmptyArray } from '@postxl/utils';
|
|
2
|
+
import * as Brands from './branded.types';
|
|
3
|
+
/**
|
|
4
|
+
* A structured definition of multiple imports: The key of the object is the "from" path,
|
|
5
|
+
* the value is a list (or single item) of items to import.
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* ```
|
|
9
|
+
* {
|
|
10
|
+
* [context.data.importPath]: context.data.repository.className,
|
|
11
|
+
* [context.types.packageName]: [model.id.brandedType, model.typeName],
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type BulkImportDefinition = Record<Brands.ImportPaths, NonEmptyArray<Brands.ImportableTypes> | Brands.ImportableTypes>;
|
|
16
|
+
/**
|
|
17
|
+
* A utility component that lets you generate TypeScript import statements
|
|
18
|
+
* and makes sure every import is only added once.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ImportGenerator {
|
|
21
|
+
#private;
|
|
22
|
+
constructor({ path }: {
|
|
23
|
+
path: string;
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new instance of the imports generator.
|
|
27
|
+
*/
|
|
28
|
+
static from(path: Brands.ImportPaths): ImportGenerator;
|
|
29
|
+
/**
|
|
30
|
+
* Convenience method to add a single import statement.
|
|
31
|
+
*/
|
|
32
|
+
add({ name, location }: {
|
|
33
|
+
name: Brands.ImportableTypes;
|
|
34
|
+
location: Brands.ImportPaths;
|
|
35
|
+
}): this;
|
|
36
|
+
/**
|
|
37
|
+
* Convenience method to add a single import statement.
|
|
38
|
+
*/
|
|
39
|
+
addType({ name, location }: {
|
|
40
|
+
name: Brands.TypeName;
|
|
41
|
+
location: Brands.ImportPaths;
|
|
42
|
+
}): this;
|
|
43
|
+
/**
|
|
44
|
+
* Adds a given import statement to the imports list.
|
|
45
|
+
*/
|
|
46
|
+
addImport({ items, from: fromSource, }: {
|
|
47
|
+
items: NonEmptyArray<Brands.ImportableTypes>;
|
|
48
|
+
from: Brands.ImportPaths;
|
|
49
|
+
}): this;
|
|
50
|
+
/**
|
|
51
|
+
* Adds a given type import statement to the imports list.
|
|
52
|
+
*/
|
|
53
|
+
addTypeImport({ items, from }: {
|
|
54
|
+
items: NonEmptyArray<Brands.TypeName>;
|
|
55
|
+
from: Brands.ImportPaths;
|
|
56
|
+
}): this;
|
|
57
|
+
/**
|
|
58
|
+
* Adds a multiple import statements to the imports list.
|
|
59
|
+
*/
|
|
60
|
+
addImports(entries: BulkImportDefinition): this;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the TypeScript import statement.
|
|
63
|
+
*/
|
|
64
|
+
generate(): string;
|
|
65
|
+
private removeTs;
|
|
66
|
+
static getRelativePath({ from, to }: {
|
|
67
|
+
from: string;
|
|
68
|
+
to: string;
|
|
69
|
+
}): string;
|
|
70
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ImportGenerator = void 0;
|
|
37
|
+
const path_1 = require("../utils/path");
|
|
38
|
+
const Brands = __importStar(require("./branded.types"));
|
|
39
|
+
// export type ImportExportLocation = {
|
|
40
|
+
// /**
|
|
41
|
+
// * Name of the item to import/export.
|
|
42
|
+
// */
|
|
43
|
+
// itemName: Brands.ImportableTypes
|
|
44
|
+
// /**
|
|
45
|
+
// * Path of the item to import/export.
|
|
46
|
+
// */
|
|
47
|
+
// filePath: Brands.FilePath
|
|
48
|
+
// /**
|
|
49
|
+
// * Name of the package that exports the item.
|
|
50
|
+
// */
|
|
51
|
+
// packageName?: Brands.PackageName
|
|
52
|
+
// }
|
|
53
|
+
/**
|
|
54
|
+
* A utility component that lets you generate TypeScript import statements
|
|
55
|
+
* and makes sure every import is only added once.
|
|
56
|
+
*/
|
|
57
|
+
class ImportGenerator {
|
|
58
|
+
/**
|
|
59
|
+
* Lists of values and types we import from a given path indexed by the path.
|
|
60
|
+
*/
|
|
61
|
+
#imports = {};
|
|
62
|
+
/**
|
|
63
|
+
* Path of the file we're generating imports for.
|
|
64
|
+
*/
|
|
65
|
+
#path;
|
|
66
|
+
constructor({ path }) {
|
|
67
|
+
this.#path = this.removeTs(path);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates a new instance of the imports generator.
|
|
71
|
+
*/
|
|
72
|
+
static from(path) {
|
|
73
|
+
return new ImportGenerator({ path });
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Convenience method to add a single import statement.
|
|
77
|
+
*/
|
|
78
|
+
add({ name, location }) {
|
|
79
|
+
return this.addImport({ items: [name], from: location });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Convenience method to add a single import statement.
|
|
83
|
+
*/
|
|
84
|
+
addType({ name, location }) {
|
|
85
|
+
return this.addTypeImport({ items: [name], from: location });
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Adds a given import statement to the imports list.
|
|
89
|
+
*/
|
|
90
|
+
addImport({ items, from: fromSource, }) {
|
|
91
|
+
if (items.length === 0) {
|
|
92
|
+
throw new Error(`You cannot add an import statement without any items from ${fromSource}.`);
|
|
93
|
+
}
|
|
94
|
+
const from = this.removeTs(fromSource);
|
|
95
|
+
// Do not import from self
|
|
96
|
+
if (from === this.#path) {
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
const resolvedPath = ImportGenerator.getRelativePath({ from: this.#path, to: from });
|
|
100
|
+
if (!this.#imports[resolvedPath]) {
|
|
101
|
+
this.#imports[resolvedPath] = { types: new Set(), nonTypes: new Set() };
|
|
102
|
+
}
|
|
103
|
+
items.forEach((item) => {
|
|
104
|
+
if (Brands.isAnnotatedTypeName(item)) {
|
|
105
|
+
this.#imports[resolvedPath].types.add(item.typeName);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.#imports[resolvedPath].nonTypes.add(item);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Adds a given type import statement to the imports list.
|
|
115
|
+
*/
|
|
116
|
+
addTypeImport({ items, from }) {
|
|
117
|
+
return this.addImport({
|
|
118
|
+
items: items.map((i) => Brands.toAnnotatedTypeName(i)),
|
|
119
|
+
from,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Adds a multiple import statements to the imports list.
|
|
124
|
+
*/
|
|
125
|
+
addImports(entries) {
|
|
126
|
+
for (const [key, items] of Object.entries(entries)) {
|
|
127
|
+
if (Array.isArray(items)) {
|
|
128
|
+
this.addImport({ items, from: key });
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
this.addImport({ items: [items], from: key });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns the TypeScript import statement.
|
|
138
|
+
*/
|
|
139
|
+
generate() {
|
|
140
|
+
const statements = Object.entries(this.#imports)
|
|
141
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
142
|
+
.map(([path, items]) => {
|
|
143
|
+
const nonTypes = Array.from(items.nonTypes).sort((a, b) => a.localeCompare(b));
|
|
144
|
+
const nonTypesImportStatement = nonTypes.length > 0 ? `import { ${nonTypes.join(', ')} } from '${path}'\n` : '';
|
|
145
|
+
const types = Array.from(items.types).sort((a, b) => a.localeCompare(b));
|
|
146
|
+
const typesImportStatement = types.length > 0 ? `import type { ${types.join(', ')} } from '${path}'` : '';
|
|
147
|
+
return `${nonTypesImportStatement}${typesImportStatement}`;
|
|
148
|
+
})
|
|
149
|
+
.join('\n');
|
|
150
|
+
return statements;
|
|
151
|
+
}
|
|
152
|
+
removeTs(path) {
|
|
153
|
+
return path.replace(/\.ts$/, '');
|
|
154
|
+
}
|
|
155
|
+
static getRelativePath({ from, to }) {
|
|
156
|
+
if (to.startsWith('@') && from.startsWith('@')) {
|
|
157
|
+
const toModuleName = to.split('/')[0];
|
|
158
|
+
const fromModuleName = from.split('/')[0];
|
|
159
|
+
if (toModuleName === fromModuleName) {
|
|
160
|
+
return (0, path_1.getRelativePath)({ from: from.replace(fromModuleName, '.'), to: to.replace(toModuleName, '.') });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return (0, path_1.getRelativePath)({ from, to });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.ImportGenerator = ImportGenerator;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BackendModuleLocation, ClassName, ConstantName, FilePath, FunctionName, TypeName } from './branded.types';
|
|
2
|
+
export type ImportableItem = ImportableType | ImportableClass | ImportableFunction | ImportableConstant;
|
|
3
|
+
export type ImportableConstant = {
|
|
4
|
+
/**
|
|
5
|
+
* Name of the constant, e.g. `User`, `ExecutionInterface`
|
|
6
|
+
*/
|
|
7
|
+
readonly name: ConstantName;
|
|
8
|
+
/**
|
|
9
|
+
* The location where the constant is imported from, e.g. `@database/database.types`
|
|
10
|
+
*/
|
|
11
|
+
readonly location: BackendModuleLocation;
|
|
12
|
+
};
|
|
13
|
+
export type ImportableType = {
|
|
14
|
+
/**
|
|
15
|
+
* Name of the type, e.g. `User`, `ExecutionInterface`
|
|
16
|
+
*/
|
|
17
|
+
readonly name: TypeName;
|
|
18
|
+
/**
|
|
19
|
+
* The location where the type is imported from, e.g. `@database/database.types`
|
|
20
|
+
*/
|
|
21
|
+
readonly location: BackendModuleLocation;
|
|
22
|
+
};
|
|
23
|
+
export type ImportableClass = {
|
|
24
|
+
/**
|
|
25
|
+
* Name of the type, e.g. `RepositoriesModule`, `ActionService`
|
|
26
|
+
*/
|
|
27
|
+
readonly name: ClassName;
|
|
28
|
+
/**
|
|
29
|
+
* The location where the type is imported from, e.g. `@repositories/repositories.module`
|
|
30
|
+
*/
|
|
31
|
+
readonly location: BackendModuleLocation;
|
|
32
|
+
};
|
|
33
|
+
export type ImportableFunction = {
|
|
34
|
+
/**
|
|
35
|
+
* Name of the type, e.g. `createUser`, `updateUser`
|
|
36
|
+
*/
|
|
37
|
+
readonly name: FunctionName;
|
|
38
|
+
/**
|
|
39
|
+
* The location where the type is imported from, e.g. `@database/database.service`
|
|
40
|
+
*/
|
|
41
|
+
readonly location: BackendModuleLocation;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Utility function that converts an importable item to a local file path.
|
|
45
|
+
*/
|
|
46
|
+
export declare function toLocalFile({ location, extension, }: {
|
|
47
|
+
location: BackendModuleLocation;
|
|
48
|
+
extension?: string;
|
|
49
|
+
}): FilePath;
|
|
50
|
+
export declare function toLocalReactComponent({ location }: {
|
|
51
|
+
location: BackendModuleLocation;
|
|
52
|
+
}): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toLocalFile = toLocalFile;
|
|
4
|
+
exports.toLocalReactComponent = toLocalReactComponent;
|
|
5
|
+
const branded_types_1 = require("./branded.types");
|
|
6
|
+
/**
|
|
7
|
+
* Utility function that converts an importable item to a local file path.
|
|
8
|
+
*/
|
|
9
|
+
function toLocalFile({ location, extension = 'ts', }) {
|
|
10
|
+
const moduleName = location.split('/')[0];
|
|
11
|
+
return (0, branded_types_1.toFilePath)(location.replace(moduleName, '.') + '.' + extension);
|
|
12
|
+
}
|
|
13
|
+
function toLocalReactComponent({ location }) {
|
|
14
|
+
return toLocalFile({ location, extension: 'tsx' });
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BackendModuleLocation, FilePath } from './branded.types';
|
|
2
|
+
import { ImportableItem } from './importable.types';
|
|
3
|
+
export declare class IndexGenerator {
|
|
4
|
+
private readonly imports;
|
|
5
|
+
private readonly root;
|
|
6
|
+
constructor(root: BackendModuleLocation | FilePath);
|
|
7
|
+
add(item: BackendModuleLocation | ImportableItem | FilePath): this;
|
|
8
|
+
generate(): string;
|
|
9
|
+
private getRelativePath;
|
|
10
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IndexGenerator = void 0;
|
|
4
|
+
const path_1 = require("../utils/path");
|
|
5
|
+
class IndexGenerator {
|
|
6
|
+
imports = new Set();
|
|
7
|
+
root;
|
|
8
|
+
constructor(root) {
|
|
9
|
+
if (root.endsWith('.ts') || root.endsWith('.tsx')) {
|
|
10
|
+
root = root.replace(/\.ts$/, '');
|
|
11
|
+
}
|
|
12
|
+
if (!root.endsWith('/index')) {
|
|
13
|
+
root = (root + '/index');
|
|
14
|
+
}
|
|
15
|
+
this.root = root;
|
|
16
|
+
}
|
|
17
|
+
add(item) {
|
|
18
|
+
const location = typeof item === 'string' ? item : item.location;
|
|
19
|
+
if (this.root.includes(location)) {
|
|
20
|
+
throw new Error(`You cannot import from the index of the same module that you are exporting from.`);
|
|
21
|
+
}
|
|
22
|
+
const path = this.getRelativePath({ from: this.root, to: location });
|
|
23
|
+
this.imports.add(path);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
generate() {
|
|
27
|
+
if (this.imports.size === 0) {
|
|
28
|
+
throw new Error('You must add at least one item before generating the index.');
|
|
29
|
+
}
|
|
30
|
+
return Array.from(this.imports)
|
|
31
|
+
.toSorted((a, b) => a.localeCompare(b))
|
|
32
|
+
.map((f) => `export * from '${f}'`)
|
|
33
|
+
.join('\n');
|
|
34
|
+
}
|
|
35
|
+
getRelativePath({ from, to }) {
|
|
36
|
+
if (to.startsWith('@') && from.startsWith('@')) {
|
|
37
|
+
const toModuleName = to.split('/')[0];
|
|
38
|
+
const fromModuleName = from.split('/')[0];
|
|
39
|
+
if (toModuleName === fromModuleName) {
|
|
40
|
+
return (0, path_1.getRelativePath)({ from: from.replace(fromModuleName, '.'), to: to.replace(toModuleName, '.') });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return (0, path_1.getRelativePath)({ from, to });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.IndexGenerator = IndexGenerator;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './branded.types';
|
|
2
|
+
export * from './config-builder.class';
|
|
3
|
+
export * from './importable.types';
|
|
4
|
+
export * from './import-generator.class';
|
|
5
|
+
export * from './index-generator.class';
|
|
6
|
+
export * from './package-json.generator';
|
|
7
|
+
export * from './tsconfig.generator';
|
|
8
|
+
export * from './verify-context';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./branded.types"), exports);
|
|
18
|
+
__exportStar(require("./config-builder.class"), exports);
|
|
19
|
+
__exportStar(require("./importable.types"), exports);
|
|
20
|
+
__exportStar(require("./import-generator.class"), exports);
|
|
21
|
+
__exportStar(require("./index-generator.class"), exports);
|
|
22
|
+
__exportStar(require("./package-json.generator"), exports);
|
|
23
|
+
__exportStar(require("./tsconfig.generator"), exports);
|
|
24
|
+
__exportStar(require("./verify-context"), exports);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { BackendModuleName, PackageName } from './branded.types';
|
|
2
|
+
export type PackageJsonConfig = {
|
|
3
|
+
/**
|
|
4
|
+
* Name of the package. Should contain `@postxl/` prefix.
|
|
5
|
+
*/
|
|
6
|
+
name: PackageName;
|
|
7
|
+
/**
|
|
8
|
+
* Description of the package.
|
|
9
|
+
*/
|
|
10
|
+
description: string;
|
|
11
|
+
/**
|
|
12
|
+
* package.json dependencies that should be added to the project.
|
|
13
|
+
*
|
|
14
|
+
* Example: `ctx.dependencies.push({name: toPackageName("@aws-sdk/client-s3"), version: "3.400.0"})`
|
|
15
|
+
*/
|
|
16
|
+
dependencies: PackageDependency[];
|
|
17
|
+
/**
|
|
18
|
+
* package.json devDependencies that should be added to the project.
|
|
19
|
+
*
|
|
20
|
+
* Example: `ctx.devDependencies.push({name: toPackageName("@types/jsonwebtoken"), version: "9.6.0"})`
|
|
21
|
+
*/
|
|
22
|
+
devDependencies: PackageDependency[];
|
|
23
|
+
/**
|
|
24
|
+
* package.json scripts that should be added to the project.
|
|
25
|
+
*
|
|
26
|
+
* Example: `ctx.scripts.push({name: 'build', command: 'nest build'})`
|
|
27
|
+
*/
|
|
28
|
+
scripts: PackageScript[];
|
|
29
|
+
/**
|
|
30
|
+
* Type of the package.
|
|
31
|
+
*/
|
|
32
|
+
type?: 'module' | 'commonjs';
|
|
33
|
+
/**
|
|
34
|
+
* The package manager used in the project.
|
|
35
|
+
*/
|
|
36
|
+
packageManager?: string;
|
|
37
|
+
};
|
|
38
|
+
export type PackageDependency = PackageDependency_Workspace | PackageDependency_Package | PackageDependency_LocalProject;
|
|
39
|
+
export type PackageDependency_Workspace = {
|
|
40
|
+
packageName: PackageName;
|
|
41
|
+
};
|
|
42
|
+
export type PackageDependency_Package = {
|
|
43
|
+
packageName: string;
|
|
44
|
+
version: string;
|
|
45
|
+
};
|
|
46
|
+
export type PackageDependency_LocalProject = {
|
|
47
|
+
packageName: PackageName;
|
|
48
|
+
backendModuleName: BackendModuleName;
|
|
49
|
+
path: string;
|
|
50
|
+
};
|
|
51
|
+
export declare function isLocalProjectDependency(dependency: PackageDependency): dependency is PackageDependency_LocalProject;
|
|
52
|
+
export type PackageScript = {
|
|
53
|
+
name: string;
|
|
54
|
+
command: string;
|
|
55
|
+
};
|
|
56
|
+
export declare function generatePackageJson({ dependencies, devDependencies, scripts, name, description, type: pType, packageManager, }: PackageJsonConfig): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLocalProjectDependency = isLocalProjectDependency;
|
|
4
|
+
exports.generatePackageJson = generatePackageJson;
|
|
5
|
+
function isLocalProjectDependency(dependency) {
|
|
6
|
+
return 'path' in dependency;
|
|
7
|
+
}
|
|
8
|
+
function generatePackageJson({ dependencies, devDependencies, scripts, name, description, type: pType, packageManager, }) {
|
|
9
|
+
return JSON.stringify({
|
|
10
|
+
name,
|
|
11
|
+
version: '0.0.0',
|
|
12
|
+
description,
|
|
13
|
+
...(pType ? { type: pType } : {}),
|
|
14
|
+
author: 'PostXL GmbH',
|
|
15
|
+
private: true,
|
|
16
|
+
scripts: scripts
|
|
17
|
+
.toSorted((a, b) => a.name.localeCompare(b.name))
|
|
18
|
+
.reduce((acc, script) => ({ ...acc, [script.name]: script.command }), {}),
|
|
19
|
+
packageManager,
|
|
20
|
+
dependencies: dependencies
|
|
21
|
+
.map(toDependency_Package)
|
|
22
|
+
.toSorted((a, b) => a.packageName.localeCompare(b.packageName))
|
|
23
|
+
.reduce((acc, dep) => ({ ...acc, [dep.packageName]: dep.version }), {}),
|
|
24
|
+
devDependencies: devDependencies
|
|
25
|
+
.map(toDependency_Package)
|
|
26
|
+
.toSorted((a, b) => a.packageName.localeCompare(b.packageName))
|
|
27
|
+
.reduce((acc, dep) => ({ ...acc, [dep.packageName]: dep.version }), {}),
|
|
28
|
+
license: 'UNLICENSED',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function toDependency_Package(dependency) {
|
|
32
|
+
if ('version' in dependency) {
|
|
33
|
+
return dependency;
|
|
34
|
+
}
|
|
35
|
+
return { packageName: dependency.packageName, version: 'workspace:*' };
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateTsConfig(name: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateTsConfig = generateTsConfig;
|
|
4
|
+
function generateTsConfig(name) {
|
|
5
|
+
return /* json */ `{
|
|
6
|
+
"extends": "../../tsconfig.json",
|
|
7
|
+
"compilerOptions": {
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"outDir": "../../dist/libs/${name}"
|
|
10
|
+
},
|
|
11
|
+
"include": ["src/**/*"],
|
|
12
|
+
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
|
|
13
|
+
}`;
|
|
14
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { EnumName, ModelName } from '@postxl/schema';
|
|
2
|
+
import { Context as BaseContext } from '../generator.context';
|
|
3
|
+
export declare function verifyModelExists<Context extends BaseContext>(modelName: ModelName, context: Context): void;
|
|
4
|
+
export declare function verifyEnumExists<Context extends BaseContext>(enumName: EnumName, context: Context): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyModelExists = verifyModelExists;
|
|
4
|
+
exports.verifyEnumExists = verifyEnumExists;
|
|
5
|
+
function verifyModelExists(modelName, context) {
|
|
6
|
+
const model = context.models.get(modelName);
|
|
7
|
+
if (!model) {
|
|
8
|
+
err(`Cannot find model ${modelName} in schema! Please ensure that model was added, either to "standardModels" or "model"!`, context);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function verifyEnumExists(enumName, context) {
|
|
12
|
+
const enum_ = context.enums.get(enumName);
|
|
13
|
+
if (!enum_) {
|
|
14
|
+
err(`Cannot find enum ${enumName} in schema! Please ensure that enum was added, either to "standardEnums" or "enum"!`, context);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function err(message, { options: { ignoreErrors } }) {
|
|
18
|
+
if (ignoreErrors) {
|
|
19
|
+
console.error(message);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
throw new Error(message);
|
|
23
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./helpers"), exports);
|
|
18
|
+
__exportStar(require("./generator.context"), exports);
|
|
19
|
+
__exportStar(require("./generator-manager.class"), exports);
|
|
20
|
+
__exportStar(require("./generator.class"), exports);
|
|
21
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
export declare const zChecksum: z.ZodBranded<z.ZodString, "PXL.Checksum">;
|
|
3
|
+
/**
|
|
4
|
+
* Branded Id type that should be used to identify checksum strings.
|
|
5
|
+
*/
|
|
6
|
+
export type Checksum = z.infer<typeof zChecksum>;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the checksum of the given file
|
|
9
|
+
*/
|
|
10
|
+
export declare function calculateChecksum(content: string | Buffer): Promise<Checksum>;
|