@comet/api-generator 8.0.0-beta.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.
Files changed (27) hide show
  1. package/LICENSE +24 -0
  2. package/bin/api-generator.js +5 -0
  3. package/lib/apiGenerator.d.ts +1 -0
  4. package/lib/apiGenerator.js +7 -0
  5. package/lib/commands/generate/generate-command.d.ts +2 -0
  6. package/lib/commands/generate/generate-command.js +45 -0
  7. package/lib/commands/generate/generateCrud/generate-crud.d.ts +24 -0
  8. package/lib/commands/generate/generateCrud/generate-crud.js +1212 -0
  9. package/lib/commands/generate/generateCrudInput/generate-crud-input.d.ts +11 -0
  10. package/lib/commands/generate/generateCrudInput/generate-crud-input.js +463 -0
  11. package/lib/commands/generate/generateCrudSingle/generate-crud-single.d.ts +4 -0
  12. package/lib/commands/generate/generateCrudSingle/generate-crud-single.js +153 -0
  13. package/lib/commands/generate/utils/build-name-variants.d.ts +10 -0
  14. package/lib/commands/generate/utils/build-name-variants.js +25 -0
  15. package/lib/commands/generate/utils/constants.d.ts +1 -0
  16. package/lib/commands/generate/utils/constants.js +4 -0
  17. package/lib/commands/generate/utils/generate-imports-code.d.ts +5 -0
  18. package/lib/commands/generate/utils/generate-imports-code.js +32 -0
  19. package/lib/commands/generate/utils/test-helper.d.ts +5 -0
  20. package/lib/commands/generate/utils/test-helper.js +72 -0
  21. package/lib/commands/generate/utils/ts-morph-helper.d.ts +10 -0
  22. package/lib/commands/generate/utils/ts-morph-helper.js +191 -0
  23. package/lib/commands/generate/utils/write-generated-file.d.ts +1 -0
  24. package/lib/commands/generate/utils/write-generated-file.js +69 -0
  25. package/lib/commands/generate/utils/write-generated-files.d.ts +8 -0
  26. package/lib/commands/generate/utils/write-generated-files.js +20 -0
  27. package/package.json +65 -0
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.classNameToInstanceName = classNameToInstanceName;
4
+ exports.buildNameVariants = buildNameVariants;
5
+ const pluralize_1 = require("pluralize");
6
+ function classNameToInstanceName(className) {
7
+ return className[0].toLocaleLowerCase() + className.slice(1);
8
+ }
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ function buildNameVariants(metadata) {
11
+ const classNameSingular = metadata.className;
12
+ const classNamePlural = (0, pluralize_1.plural)(metadata.className);
13
+ const instanceNameSingular = classNameToInstanceName(classNameSingular);
14
+ const instanceNamePlural = classNameToInstanceName(classNamePlural);
15
+ const fileNameSingular = instanceNameSingular.replace(/[A-Z]/g, (i) => `-${i.toLocaleLowerCase()}`);
16
+ const fileNamePlural = instanceNamePlural.replace(/[A-Z]/g, (i) => `-${i.toLocaleLowerCase()}`);
17
+ return {
18
+ classNameSingular,
19
+ classNamePlural,
20
+ instanceNameSingular,
21
+ instanceNamePlural,
22
+ fileNameSingular,
23
+ fileNamePlural,
24
+ };
25
+ }
@@ -0,0 +1 @@
1
+ export declare const integerTypes: string[];
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.integerTypes = void 0;
4
+ exports.integerTypes = ["int", "integer", "tinyint", "smallint", "mediumint", "bigint", "int2", "int4", "int8", "serial"];
@@ -0,0 +1,5 @@
1
+ export type Imports = Array<{
2
+ name: string;
3
+ importPath: string;
4
+ }>;
5
+ export declare function generateImportsCode(imports: Imports): string;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateImportsCode = generateImportsCode;
4
+ // generate imports code and filter duplicates
5
+ function generateImportsCode(imports) {
6
+ const importsNameToPath = new Map(); // name -> importPath
7
+ const filteredImports = imports.filter((imp) => {
8
+ if (importsNameToPath.has(imp.name)) {
9
+ if (importsNameToPath.get(imp.name) !== imp.importPath) {
10
+ throw new Error(`Duplicate import name ${imp.name}`);
11
+ }
12
+ else {
13
+ // duplicate import, skip
14
+ return false;
15
+ }
16
+ }
17
+ importsNameToPath.set(imp.name, imp.importPath);
18
+ return true;
19
+ });
20
+ const importsPathToName = {};
21
+ for (const imp of filteredImports) {
22
+ if (!importsPathToName[imp.importPath]) {
23
+ importsPathToName[imp.importPath] = [];
24
+ }
25
+ importsPathToName[imp.importPath].push(imp.name);
26
+ }
27
+ let importsString = "";
28
+ for (const [importPath, importNames] of Object.entries(importsPathToName)) {
29
+ importsString += `import { ${importNames.sort().join(", ")} } from "${importPath}";\n`;
30
+ }
31
+ return importsString;
32
+ }
@@ -0,0 +1,5 @@
1
+ import { type SourceFile } from "ts-morph";
2
+ import { type GeneratedFile } from "./write-generated-files";
3
+ export declare function formatSource(sourceCode: string): Promise<string>;
4
+ export declare function formatGeneratedFiles(files: GeneratedFile[]): Promise<GeneratedFile[]>;
5
+ export declare function parseSource(source: string): SourceFile;
@@ -0,0 +1,72 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.formatSource = formatSource;
46
+ exports.formatGeneratedFiles = formatGeneratedFiles;
47
+ exports.parseSource = parseSource;
48
+ const process = __importStar(require("node:process"));
49
+ const prettier_1 = require("prettier");
50
+ const ts_morph_1 = require("ts-morph");
51
+ let options;
52
+ function formatSource(sourceCode) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ if (!options)
55
+ options = yield (0, prettier_1.resolveConfig)(process.cwd());
56
+ return (0, prettier_1.format)(sourceCode, Object.assign(Object.assign({}, options), { filepath: "test.ts" }));
57
+ });
58
+ }
59
+ function formatGeneratedFiles(files) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ return Promise.all(files.map((file) => __awaiter(this, void 0, void 0, function* () {
62
+ return Object.assign(Object.assign({}, file), { content: yield formatSource(file.content) });
63
+ })));
64
+ });
65
+ }
66
+ function parseSource(source) {
67
+ const project = new ts_morph_1.Project({
68
+ tsConfigFilePath: "./tsconfig.json",
69
+ skipAddingFilesFromTsConfig: true,
70
+ });
71
+ return project.createSourceFile("test.ts", source);
72
+ }
@@ -0,0 +1,10 @@
1
+ import { type EntityMetadata } from "@mikro-orm/postgresql";
2
+ export declare function morphTsProperty(name: string, metadata: EntityMetadata<any>): import("ts-morph").PropertyDeclaration;
3
+ export declare function findEnumName(propertyName: string, metadata: EntityMetadata<any>): string;
4
+ export declare function findEnumImportPath(enumName: string, targetDirectory: string, metadata: EntityMetadata<any>): string;
5
+ export declare function findValidatorImportPath(validatorName: string, generatorOptions: {
6
+ targetDirectory: string;
7
+ }, metadata: EntityMetadata<any>): string;
8
+ export declare function findBlockName(propertyName: string, metadata: EntityMetadata<any>): string;
9
+ export declare function findBlockImportPath(blockName: string, targetDirectory: string, metadata: EntityMetadata<any>): string;
10
+ export declare function findInputClassImportPath(className: string, targetDirectory: string, metadata: EntityMetadata<any>): string;
@@ -0,0 +1,191 @@
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.morphTsProperty = morphTsProperty;
37
+ exports.findEnumName = findEnumName;
38
+ exports.findEnumImportPath = findEnumImportPath;
39
+ exports.findValidatorImportPath = findValidatorImportPath;
40
+ exports.findBlockName = findBlockName;
41
+ exports.findBlockImportPath = findBlockImportPath;
42
+ exports.findInputClassImportPath = findInputClassImportPath;
43
+ const path = __importStar(require("path"));
44
+ const ts_morph_1 = require("ts-morph");
45
+ /* eslint-disable @typescript-eslint/no-explicit-any */
46
+ const project = new ts_morph_1.Project({
47
+ tsConfigFilePath: "tsconfig.json",
48
+ skipAddingFilesFromTsConfig: true,
49
+ });
50
+ function morphTsSource(metadata) {
51
+ let tsSource = project.getSourceFile(metadata.path);
52
+ if (!tsSource)
53
+ tsSource = project.addSourceFileAtPath(metadata.path);
54
+ return tsSource;
55
+ }
56
+ function morphTsClass(metadata) {
57
+ const tsSource = morphTsSource(metadata);
58
+ const tsClass = tsSource.getClass(metadata.className);
59
+ if (!tsClass)
60
+ throw new Error(`Class ${metadata.className} not found in ${metadata.path}`);
61
+ return tsClass;
62
+ }
63
+ function morphTsProperty(name, metadata) {
64
+ const tsClass = morphTsClass(metadata);
65
+ return tsClass.getPropertyOrThrow(name);
66
+ }
67
+ function findImportPath(importName, targetDirectory, metadata) {
68
+ var _a;
69
+ const tsSource = morphTsSource(metadata);
70
+ for (const tsImport of tsSource.getImportDeclarations()) {
71
+ for (const namedImport of tsImport.getNamedImports()) {
72
+ if (((_a = namedImport.getAliasNode()) === null || _a === void 0 ? void 0 : _a.getText()) == importName) {
73
+ throw new Error("Aliased enum import is not supported");
74
+ }
75
+ if (namedImport.getNameNode().getText() == importName) {
76
+ const importPath = tsImport.getModuleSpecifierValue();
77
+ const importSource = tsImport.getModuleSpecifierSourceFile();
78
+ if (!importSource) {
79
+ throw new Error(`Can't resolve import ${importPath}`);
80
+ }
81
+ const exportedDeclarations = importSource.getExportedDeclarations().get(importName);
82
+ if (!exportedDeclarations)
83
+ throw new Error(`Can't get exported declaration for ${importName}`);
84
+ const exportedDeclaration = exportedDeclarations[0];
85
+ if (importPath.startsWith("./") || importPath.startsWith("../")) {
86
+ const absolutePath = path.resolve(path.dirname(metadata.path), importPath);
87
+ return {
88
+ importPath: path.relative(targetDirectory, absolutePath),
89
+ exportedDeclaration,
90
+ };
91
+ }
92
+ else {
93
+ return { importPath, exportedDeclaration };
94
+ }
95
+ }
96
+ }
97
+ }
98
+ throw new Error(`${importName} import not found in ${metadata.path}`);
99
+ }
100
+ function findEnumName(propertyName, metadata) {
101
+ const tsProp = morphTsProperty(propertyName, metadata);
102
+ return tsProp
103
+ .getType()
104
+ .getText(tsProp)
105
+ .replace(/ ?\| ?undefined$/, "")
106
+ .replace(/\[\]$/, "");
107
+ }
108
+ function findEnumImportPath(enumName, targetDirectory, metadata) {
109
+ var _a;
110
+ const tsSource = morphTsSource(metadata);
111
+ if (tsSource.getEnum(enumName)) {
112
+ //enum defined in same file as entity
113
+ if (!((_a = tsSource.getEnum(enumName)) === null || _a === void 0 ? void 0 : _a.isExported())) {
114
+ throw new Error(`Enum ${enumName} is not exported in ${metadata.path}`);
115
+ }
116
+ return path.relative(targetDirectory, metadata.path).replace(/\.ts$/, "");
117
+ }
118
+ else {
119
+ //try to find import where enum is imported from
120
+ const { importPath } = findImportPath(enumName, targetDirectory, metadata);
121
+ return importPath;
122
+ }
123
+ }
124
+ function findValidatorImportPath(validatorName, generatorOptions, metadata) {
125
+ var _a, _b;
126
+ const tsSource = morphTsSource(metadata);
127
+ //validator defined in same file as entity
128
+ if (tsSource.getVariableDeclaration(validatorName) || tsSource.getFunction(validatorName)) {
129
+ if (!(((_a = tsSource.getVariableDeclaration(validatorName)) === null || _a === void 0 ? void 0 : _a.isExported()) || ((_b = tsSource.getFunction(validatorName)) === null || _b === void 0 ? void 0 : _b.isExported()))) {
130
+ throw new Error(`Validator ${validatorName} is not exported in ${metadata.path}`);
131
+ }
132
+ return path.relative(`${generatorOptions.targetDirectory}/dto`, metadata.path).replace(/\.ts$/, "");
133
+ }
134
+ else {
135
+ const { importPath } = findImportPath(validatorName, generatorOptions.targetDirectory, metadata);
136
+ return importPath;
137
+ }
138
+ }
139
+ function findBlockName(propertyName, metadata) {
140
+ const tsProp = morphTsProperty(propertyName, metadata);
141
+ if (!tsProp)
142
+ throw new Error("property not found");
143
+ const rootBlockDecorator = tsProp.getDecorators().find((i) => i.getName() == "RootBlock");
144
+ if (!rootBlockDecorator)
145
+ throw new Error(`RootBlock decorator not found for property ${propertyName}`);
146
+ return rootBlockDecorator.getArguments()[0].getText();
147
+ }
148
+ function findBlockImportPath(blockName, targetDirectory, metadata) {
149
+ var _a;
150
+ const tsSource = morphTsSource(metadata);
151
+ if (tsSource.getVariableDeclaration(blockName)) {
152
+ //block defined in same file as entity
153
+ if (!((_a = tsSource.getVariableDeclaration(blockName)) === null || _a === void 0 ? void 0 : _a.isExported())) {
154
+ throw new Error(`Block ${blockName} is not exported in ${metadata.path}`);
155
+ }
156
+ return path.relative(targetDirectory, metadata.path).replace(/\.ts$/, "");
157
+ }
158
+ else {
159
+ //try to find import where block is imported from
160
+ const { importPath } = findImportPath(blockName, targetDirectory, metadata);
161
+ return importPath;
162
+ }
163
+ }
164
+ function findInputClassImportPath(className, targetDirectory, metadata) {
165
+ var _a;
166
+ const tsSource = morphTsSource(metadata);
167
+ let returnImportPath;
168
+ let classDeclaration;
169
+ if (tsSource.getClass(className)) {
170
+ //block defined in same file as entity
171
+ if (!((_a = tsSource.getClass(className)) === null || _a === void 0 ? void 0 : _a.isExported())) {
172
+ throw new Error(`Class ${className} is not exported in ${metadata.path}`);
173
+ }
174
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
175
+ classDeclaration = tsSource.getClass(className);
176
+ returnImportPath = path.relative(targetDirectory, metadata.path).replace(/\.ts$/, "");
177
+ }
178
+ else {
179
+ //try to find import where block is imported from
180
+ const { importPath, exportedDeclaration } = findImportPath(className, targetDirectory, metadata);
181
+ if (!(exportedDeclaration instanceof ts_morph_1.ClassDeclaration)) {
182
+ throw new Error(`Exported declaration for ${className} is not a class`);
183
+ }
184
+ classDeclaration = exportedDeclaration;
185
+ returnImportPath = importPath;
186
+ }
187
+ if (!classDeclaration.getDecorators().some((i) => i.getName() == "InputType")) {
188
+ throw new Error(`Exported declaration for ${className} is not decorated with @InputType`);
189
+ }
190
+ return returnImportPath;
191
+ }
@@ -0,0 +1 @@
1
+ export declare function writeGeneratedFile(filePath: string, contents: string): Promise<void>;
@@ -0,0 +1,69 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.writeGeneratedFile = writeGeneratedFile;
46
+ const eslint_1 = require("eslint");
47
+ const fs_1 = require("fs");
48
+ const path = __importStar(require("path"));
49
+ function writeGeneratedFile(filePath, contents) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ const header = `// This file has been generated by comet api-generator.
52
+ // You may choose to use this file as scaffold by moving this file out of generated folder and removing this comment.
53
+ `;
54
+ yield fs_1.promises.mkdir(path.dirname(filePath), { recursive: true });
55
+ yield fs_1.promises.writeFile(filePath, contents);
56
+ const eslint = new eslint_1.ESLint({
57
+ cwd: process.cwd(),
58
+ fix: true,
59
+ });
60
+ const lintResult = yield eslint.lintText(header + contents, {
61
+ filePath,
62
+ });
63
+ const output = lintResult[0] && lintResult[0].output ? lintResult[0].output : lintResult[0].source;
64
+ if (output) {
65
+ yield fs_1.promises.writeFile(filePath, output);
66
+ }
67
+ console.log(`generated ${filePath}`);
68
+ });
69
+ }
@@ -0,0 +1,8 @@
1
+ export interface GeneratedFile {
2
+ name: string;
3
+ content: string;
4
+ type: "resolver" | "input" | "filter" | "sort" | "service" | "args";
5
+ }
6
+ export declare function writeGeneratedFiles(files: GeneratedFile[], options: {
7
+ targetDirectory: string;
8
+ }): Promise<void>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.writeGeneratedFiles = writeGeneratedFiles;
13
+ const write_generated_file_1 = require("./write-generated-file");
14
+ function writeGeneratedFiles(files, options) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ for (const file of files) {
17
+ yield (0, write_generated_file_1.writeGeneratedFile)(`${options.targetDirectory}/${file.name}`, file.content);
18
+ }
19
+ });
20
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@comet/api-generator",
3
+ "version": "8.0.0-beta.0",
4
+ "repository": {
5
+ "directory": "packages/api/api-generator",
6
+ "type": "git",
7
+ "url": "https://github.com/vivid-planet/comet"
8
+ },
9
+ "license": "BSD-2-Clause",
10
+ "main": "lib/index.js",
11
+ "typings": "lib/index.d.ts",
12
+ "bin": {
13
+ "comet-api-generator": "bin/api-generator.js"
14
+ },
15
+ "files": [
16
+ "bin/**/*.js",
17
+ "lib/*"
18
+ ],
19
+ "dependencies": {
20
+ "commander": "^9.5.0",
21
+ "pluralize": "^8.0.0",
22
+ "ts-morph": "^25.0.1",
23
+ "ts-node": "^10.9.2",
24
+ "@comet/cms-api": "8.0.0-beta.0"
25
+ },
26
+ "devDependencies": {
27
+ "@mikro-orm/cli": "^6.4.5",
28
+ "@mikro-orm/postgresql": "^6.4.5",
29
+ "@nestjs/graphql": "^13.0.3",
30
+ "@types/jest": "^29.5.14",
31
+ "@types/node": "^22.13.4",
32
+ "@types/pluralize": "^0.0.33",
33
+ "class-validator": "^0.14.1",
34
+ "eslint": "^9.20.1",
35
+ "jest": "^29.7.0",
36
+ "npm-run-all2": "^5.0.2",
37
+ "prettier": "^3.5.1",
38
+ "reflect-metadata": "^0.2.2",
39
+ "rimraf": "^6.0.1",
40
+ "ts-jest": "^29.2.5",
41
+ "typescript": "^5.7.3",
42
+ "uuid": "^11.0.5",
43
+ "@comet/eslint-config": "8.0.0-beta.0"
44
+ },
45
+ "peerDependencies": {
46
+ "@mikro-orm/cli": "^6.0.0",
47
+ "@nestjs/graphql": "^13.0.0",
48
+ "class-validator": "^0.14.0"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public",
52
+ "registry": "https://registry.npmjs.org"
53
+ },
54
+ "scripts": {
55
+ "build": "$npm_execpath run clean && tsc -p tsconfig.build.json",
56
+ "clean": "rimraf lib",
57
+ "dev": "tsc --watch --preserveWatchOutput -p tsconfig.build.json",
58
+ "lint": "run-p lint:prettier lint:eslint lint:tsc",
59
+ "lint:eslint": "eslint --max-warnings 0 src/ **/*.json --no-warn-ignored",
60
+ "lint:prettier": "npx prettier --check './**/*.{js,json,md,yml,yaml}'",
61
+ "lint:tsc": "tsc",
62
+ "test": "NODE_OPTIONS=--experimental-vm-modules npx jest",
63
+ "test:watch": "jest --watch"
64
+ }
65
+ }