@postxl/generator 0.35.0 → 0.37.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/generator.js +60 -19
- package/dist/generators/indices/businesslogic-view-service.generator.js +6 -6
- package/dist/generators/indices/datamocker.generator.js +43 -33
- package/dist/generators/indices/dispatcher-service.generator.js +1 -1
- package/dist/generators/models/businesslogic-view.generator.js +1 -0
- package/dist/lib/vfs.d.ts +33 -0
- package/dist/lib/vfs.js +157 -0
- package/package.json +8 -3
package/dist/generator.js
CHANGED
|
@@ -56,24 +56,25 @@ const stub_generator_1 = require("./generators/models/stub.generator");
|
|
|
56
56
|
const types_generator_3 = require("./generators/models/types.generator");
|
|
57
57
|
const meta_1 = require("./lib/meta");
|
|
58
58
|
const types_1 = require("./lib/schema/types");
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const datamocker_generator_1 = require("./generators/indices/datamocker.generator");
|
|
62
|
-
const businesslogic_update_service_generator_1 = require("./generators/indices/businesslogic-update-service.generator");
|
|
59
|
+
const vfs_1 = require("./lib/vfs");
|
|
60
|
+
const businesslogic_actiontypes_generator_1 = require("./generators/indices/businesslogic-actiontypes.generator");
|
|
63
61
|
const businesslogic_update_index_generator_1 = require("./generators/indices/businesslogic-update-index.generator");
|
|
64
62
|
const businesslogic_update_module_generator_1 = require("./generators/indices/businesslogic-update-module.generator");
|
|
63
|
+
const businesslogic_update_service_generator_1 = require("./generators/indices/businesslogic-update-service.generator");
|
|
64
|
+
const businesslogic_view_index_generator_1 = require("./generators/indices/businesslogic-view-index.generator");
|
|
65
|
+
const businesslogic_view_module_generator_1 = require("./generators/indices/businesslogic-view-module.generator");
|
|
66
|
+
const businesslogic_view_service_generator_1 = require("./generators/indices/businesslogic-view-service.generator");
|
|
67
|
+
const datamocker_generator_1 = require("./generators/indices/datamocker.generator");
|
|
68
|
+
const dispatcher_service_generator_1 = require("./generators/indices/dispatcher-service.generator");
|
|
69
|
+
const seed_migration_generator_1 = require("./generators/indices/seed-migration.generator");
|
|
70
|
+
const seed_service_generator_1 = require("./generators/indices/seed-service.generator");
|
|
65
71
|
const seed_template_decoder_generator_1 = require("./generators/indices/seed-template-decoder.generator");
|
|
66
72
|
const seed_template_generator_1 = require("./generators/indices/seed-template.generator");
|
|
67
|
-
const seed_service_generator_1 = require("./generators/indices/seed-service.generator");
|
|
68
|
-
const dispatcher_service_generator_1 = require("./generators/indices/dispatcher-service.generator");
|
|
69
|
-
const businesslogic_actiontypes_generator_1 = require("./generators/indices/businesslogic-actiontypes.generator");
|
|
70
73
|
const seeddata_type_generator_1 = require("./generators/indices/seeddata-type.generator");
|
|
71
|
-
const seed_migration_generator_1 = require("./generators/indices/seed-migration.generator");
|
|
72
|
-
const businesslogic_view_generator_1 = require("./generators/models/businesslogic-view.generator");
|
|
73
74
|
const businesslogic_update_generator_1 = require("./generators/models/businesslogic-update.generator");
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const
|
|
75
|
+
const businesslogic_view_generator_1 = require("./generators/models/businesslogic-view.generator");
|
|
76
|
+
const client_path_1 = require("./prisma/client-path");
|
|
77
|
+
const parse_1 = require("./prisma/parse");
|
|
77
78
|
const CONFIG_SCHEMA = zod_1.z
|
|
78
79
|
.object({
|
|
79
80
|
project: zod_1.z.string(),
|
|
@@ -158,8 +159,8 @@ function generate({ models, enums, config, prismaClientPath, logger, }) {
|
|
|
158
159
|
if (root == undefined) {
|
|
159
160
|
throw new Error(`Could not find lock file. Make sure you are running the generator in a project folder.`);
|
|
160
161
|
}
|
|
161
|
-
const vfs = yield
|
|
162
|
-
const generated = new
|
|
162
|
+
const vfs = yield vfs_1.ExtendedVirtualFS.fromLockFile(root);
|
|
163
|
+
const generated = new vfs_1.ExtendedVirtualFS();
|
|
163
164
|
// Generate Models
|
|
164
165
|
for (const model of models) {
|
|
165
166
|
const meta = (0, meta_1.getModelMetadata)({ model });
|
|
@@ -189,7 +190,7 @@ function generate({ models, enums, config, prismaClientPath, logger, }) {
|
|
|
189
190
|
}
|
|
190
191
|
// React
|
|
191
192
|
if (!config.disableGenerators.react) {
|
|
192
|
-
generated.copy((0, react_generator_2.generateReactComponentsForModel)({ model, meta }), meta.react.folderPath);
|
|
193
|
+
yield generated.copy((0, react_generator_2.generateReactComponentsForModel)({ model, meta }), meta.react.folderPath);
|
|
193
194
|
}
|
|
194
195
|
logger.log(`- ${model.name} processed`);
|
|
195
196
|
}
|
|
@@ -200,7 +201,7 @@ function generate({ models, enums, config, prismaClientPath, logger, }) {
|
|
|
200
201
|
generated.write(`/${meta.types.filePath}.ts`, (0, types_generator_1.generateEnumType)({ enumerator, prismaClientPath, meta }));
|
|
201
202
|
}
|
|
202
203
|
if (!config.disableGenerators.react) {
|
|
203
|
-
generated.copy((0, react_generator_1.generateEnumReactComponents)({ enumerator, meta }), meta.react.folderPath);
|
|
204
|
+
yield generated.copy((0, react_generator_1.generateEnumReactComponents)({ enumerator, meta }), meta.react.folderPath);
|
|
204
205
|
}
|
|
205
206
|
}
|
|
206
207
|
// Generate Index Files and Services
|
|
@@ -249,11 +250,51 @@ function generate({ models, enums, config, prismaClientPath, logger, }) {
|
|
|
249
250
|
// -------------------------------------------------------------------------
|
|
250
251
|
// Add disclaimer and format.
|
|
251
252
|
const prettierConfig = yield prettier.resolveConfig(process.cwd());
|
|
252
|
-
generated.transformUTF8Files((path, content) => `${DISCLAIMER}\n${content}`);
|
|
253
|
-
generated.formatUTF8Files(prettierConfig);
|
|
253
|
+
yield generated.transformUTF8Files((path, content) => `${DISCLAIMER}\n${content}`);
|
|
254
|
+
yield generated.formatUTF8Files(prettierConfig);
|
|
255
|
+
const lintResult = yield generated.lintUTF8Files({
|
|
256
|
+
fix: true,
|
|
257
|
+
useEslintrc: false,
|
|
258
|
+
allowInlineConfig: true,
|
|
259
|
+
extensions: ['.ts', '.tsx', '.js', '.jsx'],
|
|
260
|
+
overrideConfig: {
|
|
261
|
+
parser: '@typescript-eslint/parser',
|
|
262
|
+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
|
|
263
|
+
plugins: ['@typescript-eslint'],
|
|
264
|
+
parserOptions: {
|
|
265
|
+
sourceType: 'module',
|
|
266
|
+
ecmaVersion: 'latest',
|
|
267
|
+
},
|
|
268
|
+
env: {
|
|
269
|
+
es2022: true,
|
|
270
|
+
node: true,
|
|
271
|
+
},
|
|
272
|
+
rules: {
|
|
273
|
+
// The "curly" rule ensures that all if, else if, else, for, while, or do blocks are followed by a block in braces, even if it is only a single line.
|
|
274
|
+
// This will flag `if(condition) return x` and expect it to be written as `if (condition) { return x }`
|
|
275
|
+
curly: ['error', 'all'],
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
const unfixableErrorCount = lintResult.totalErrorCount - lintResult.totalFixableErrorCount;
|
|
280
|
+
if (unfixableErrorCount > 0) {
|
|
281
|
+
console.log(`LINT: ${unfixableErrorCount} unfixable errors! Please open an issue with your schema!`);
|
|
282
|
+
}
|
|
283
|
+
const unfixedWarningCount = lintResult.totalWarningCount - lintResult.totalFixableWarningCount;
|
|
284
|
+
if (unfixedWarningCount > 0) {
|
|
285
|
+
console.log(`LINT: ${unfixedWarningCount} unfixed warnings! Please open an issue with your schema!`);
|
|
286
|
+
}
|
|
287
|
+
for (const [, result] of lintResult.results) {
|
|
288
|
+
if (result.errorCount > 0 || result.warningCount > 0) {
|
|
289
|
+
console.log(result.message);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (unfixedWarningCount === 0 && unfixableErrorCount === 0) {
|
|
293
|
+
console.log(`LINT: All files linted successfully without warnings and errors!`);
|
|
294
|
+
}
|
|
254
295
|
// -------------------------------------------------------------------------
|
|
255
296
|
// Merge with existing files.
|
|
256
|
-
vfs.copy(generated, './');
|
|
297
|
+
yield vfs.copy(generated, './');
|
|
257
298
|
// Flush to disk.
|
|
258
299
|
// NOTE: We use a special "internal" variable to force regeneration of all files so that
|
|
259
300
|
// the template files are always up to date.
|
|
@@ -21,14 +21,14 @@ function generateBusinessLogicViewService({ models, meta }) {
|
|
|
21
21
|
.map(({ meta }) => `@Inject(forwardRef(() => ${meta.businessLogic.view.serviceClassName})) public readonly ${meta.businessLogic.view.serviceVariableName} :${meta.businessLogic.view.serviceClassName}`)
|
|
22
22
|
.join(',\n');
|
|
23
23
|
return `
|
|
24
|
-
|
|
24
|
+
import { Inject, Injectable, forwardRef } from '@nestjs/common'
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
${imports.generate()}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
@Injectable()
|
|
29
|
+
export class ${meta.businessLogic.view.serviceClassName} {
|
|
30
|
+
constructor(${constructor}) {}
|
|
31
|
+
}
|
|
32
32
|
`;
|
|
33
33
|
}
|
|
34
34
|
exports.generateBusinessLogicViewService = generateBusinessLogicViewService;
|
|
@@ -23,13 +23,15 @@ function generateDataMocker({ models, meta: schemaMeta }) {
|
|
|
23
23
|
.map(({ model, meta }) => `private ${meta.data.dataServiceIdName}Ids = new IdTracker<${model.typeName}>()`)
|
|
24
24
|
.join('\n');
|
|
25
25
|
const addDataFunctions = modelMetas.map(({ model, meta }) => generateAddDataFunction(model, meta)).join('\n');
|
|
26
|
-
// const timeNow = new Date().toLocaleTimeString('en-US', { hour12: false, hour: 'numeric', minute: 'numeric' })
|
|
27
|
-
// const todayDate = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'numeric', day: 'numeric' })
|
|
28
26
|
return `
|
|
27
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
29
28
|
import type { MockData } from '@pxl/data'
|
|
30
|
-
|
|
29
|
+
|
|
31
30
|
${imports.generate()}
|
|
32
31
|
|
|
32
|
+
import { IdTracker } from './id-tracker.class'
|
|
33
|
+
|
|
34
|
+
|
|
33
35
|
export class DataMocker implements MockData {
|
|
34
36
|
${publicVariables}
|
|
35
37
|
|
|
@@ -40,38 +42,46 @@ export class DataMocker implements MockData {
|
|
|
40
42
|
`;
|
|
41
43
|
}
|
|
42
44
|
exports.generateDataMocker = generateDataMocker;
|
|
43
|
-
// Generated time stamp: ${todayDate} ${timeNow}
|
|
44
45
|
function generateAddDataFunction(model, meta) {
|
|
45
46
|
const { fields, idField } = model;
|
|
46
|
-
const relations = fields
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
`
|
|
74
|
-
|
|
47
|
+
const relations = fields
|
|
48
|
+
.filter(schema_1.isFieldRelation)
|
|
49
|
+
.map((field) => (Object.assign(Object.assign({}, field), { meta: (0, meta_1.getModelMetadata)({ model: field.relationToModel }), fieldMeta: (0, meta_1.getFieldMetadata)({ field }), model: field.relationToModel })))
|
|
50
|
+
.map((r) => {
|
|
51
|
+
if (r.isRequired) {
|
|
52
|
+
return `
|
|
53
|
+
if (_item.${r.name}) {
|
|
54
|
+
if (this.${r.meta.data.dataServiceName}.findIndex((x) => x.id === _item.${r.name}) === -1) {
|
|
55
|
+
this.add${r.model.typeName}({ id: _item.${r.name} })
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
if (this.${r.meta.data.dataServiceName}.length === 0) {
|
|
59
|
+
this.add${r.model.typeName}()
|
|
60
|
+
}
|
|
61
|
+
_item.${r.name} = this.${r.meta.data.dataServiceName}[0].id
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
}
|
|
65
|
+
return `
|
|
66
|
+
if (_item.${r.name}) {
|
|
67
|
+
if (this.${r.meta.data.dataServiceName}.findIndex((x) => x.id === _item.${r.name}) === -1) {
|
|
68
|
+
this.add${r.model.typeName}({ id: _item.${r.name} })
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
`;
|
|
72
|
+
});
|
|
73
|
+
// TODO: Move the publicly accessible function's name to the metadata definition!
|
|
74
|
+
return `
|
|
75
|
+
public add${model.typeName}(
|
|
76
|
+
item?: Partial<Omit<${model.typeName}, '${idField.name}'> & { ${idField.name}: ${idField.unbrandedTypeName} }>
|
|
77
|
+
): DataMocker {
|
|
78
|
+
const _stub = stub${model.typeName}(item ?? {})
|
|
79
|
+
const _item = this.${meta.data.dataServiceIdName}Ids.ensureId(_stub)
|
|
80
|
+
|
|
81
|
+
this.${meta.data.dataServiceName}.push(_item)
|
|
82
|
+
|
|
83
|
+
${relations.join('\n')}
|
|
84
|
+
|
|
75
85
|
return this
|
|
76
86
|
}`;
|
|
77
87
|
}
|
|
@@ -33,7 +33,7 @@ import { Action, ResultOfAction } from './actions.types'
|
|
|
33
33
|
export class DispatcherService {
|
|
34
34
|
// as the SeedModule gets instantiated after the ActionsModule, we use this hack to avoid a circular dependency:
|
|
35
35
|
// we set the seedService to a dummy value and then overwrite it in the ${meta.seed.serviceClassName} constructor.
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
|
|
37
37
|
public seedService: ${meta.seed.serviceClassName} = {} as unknown as any
|
|
38
38
|
constructor(
|
|
39
39
|
private readonly updateService: ${meta.businessLogic.update.serviceClassName},
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ESLint } from 'eslint';
|
|
2
|
+
import * as prettier from 'prettier';
|
|
3
|
+
import { VirtualFS as BaseVirtualFS, PathUtils } from '@postxl/lock';
|
|
4
|
+
type FileLintResult = {
|
|
5
|
+
fixableErrorCount: number;
|
|
6
|
+
errorCount: number;
|
|
7
|
+
fixableWarningCount: number;
|
|
8
|
+
warningCount: number;
|
|
9
|
+
message: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A utility class that also contains formatting and linting functionality.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ExtendedVirtualFS extends BaseVirtualFS {
|
|
15
|
+
constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Formats the file system using configuration in the given directory.
|
|
18
|
+
*/
|
|
19
|
+
formatUTF8Files(options?: prettier.Options | null): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Lints the file system using provided configuration and returns the result as a map.
|
|
22
|
+
*
|
|
23
|
+
* NOTE: If the `fix` option is set to `true` in `ESLint.Options`, the files will be modified in-place.
|
|
24
|
+
*/
|
|
25
|
+
lintUTF8Files(options: ESLint.Options): Promise<{
|
|
26
|
+
totalFixableErrorCount: number;
|
|
27
|
+
totalErrorCount: number;
|
|
28
|
+
totalFixableWarningCount: number;
|
|
29
|
+
totalWarningCount: number;
|
|
30
|
+
results: Map<PathUtils.PosixPath, FileLintResult>;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
package/dist/lib/vfs.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
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 (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.ExtendedVirtualFS = void 0;
|
|
36
|
+
const eslint_1 = require("eslint");
|
|
37
|
+
const nodepath = __importStar(require("node:path"));
|
|
38
|
+
const prettier = __importStar(require("prettier"));
|
|
39
|
+
const lock_1 = require("@postxl/lock");
|
|
40
|
+
/**
|
|
41
|
+
* A utility class that also contains formatting and linting functionality.
|
|
42
|
+
*/
|
|
43
|
+
class ExtendedVirtualFS extends lock_1.VirtualFS {
|
|
44
|
+
constructor() {
|
|
45
|
+
super();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Formats the file system using configuration in the given directory.
|
|
49
|
+
*/
|
|
50
|
+
formatUTF8Files(options = null) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
yield this.transformUTF8Files((path, content) => {
|
|
53
|
+
const ext = nodepath.extname(path);
|
|
54
|
+
let parser = undefined;
|
|
55
|
+
switch (ext) {
|
|
56
|
+
case '.js':
|
|
57
|
+
case '.jsx':
|
|
58
|
+
parser = 'babel';
|
|
59
|
+
break;
|
|
60
|
+
case '.ts':
|
|
61
|
+
case '.tsx':
|
|
62
|
+
parser = 'typescript';
|
|
63
|
+
break;
|
|
64
|
+
case '.json':
|
|
65
|
+
parser = 'json';
|
|
66
|
+
break;
|
|
67
|
+
case '.md':
|
|
68
|
+
parser = 'markdown';
|
|
69
|
+
break;
|
|
70
|
+
case '.html':
|
|
71
|
+
parser = 'html';
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (parser == null) {
|
|
75
|
+
return content;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
return prettier.format(content, Object.assign(Object.assign({}, options), { parser }));
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
console.error(`${content}\n\nFailed to format ${path}\n\n`);
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Lints the file system using provided configuration and returns the result as a map.
|
|
89
|
+
*
|
|
90
|
+
* NOTE: If the `fix` option is set to `true` in `ESLint.Options`, the files will be modified in-place.
|
|
91
|
+
*/
|
|
92
|
+
lintUTF8Files(options) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const eslint = new eslint_1.ESLint(options);
|
|
95
|
+
const _results = new Map();
|
|
96
|
+
const formatter = yield eslint.loadFormatter('stylish');
|
|
97
|
+
yield this.transformUTF8Files((path, content) => __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const ext = nodepath.extname(path);
|
|
99
|
+
switch (ext) {
|
|
100
|
+
case '.js':
|
|
101
|
+
case '.jsx':
|
|
102
|
+
case '.ts':
|
|
103
|
+
case '.tsx': {
|
|
104
|
+
try {
|
|
105
|
+
const results = yield eslint.lintText(content, { filePath: path });
|
|
106
|
+
if (results.length !== 1) {
|
|
107
|
+
// https://eslint.org/docs/latest/integrate/nodejs-api#return-value-1
|
|
108
|
+
// NOTE: The docs explicitly state that "This is an array (despite there being
|
|
109
|
+
// only one lint result) in order to keep the interfaces between this and
|
|
110
|
+
// the eslint.lintFiles() method similar.".
|
|
111
|
+
throw new Error(`Expected ESLint to return exactly one result, but got ${results.length} instead.`);
|
|
112
|
+
}
|
|
113
|
+
const message = yield formatter.format(results);
|
|
114
|
+
const [result] = results;
|
|
115
|
+
_results.set(path, {
|
|
116
|
+
fixableErrorCount: result.fixableErrorCount,
|
|
117
|
+
errorCount: result.errorCount,
|
|
118
|
+
fixableWarningCount: result.fixableWarningCount,
|
|
119
|
+
warningCount: result.warningCount,
|
|
120
|
+
message,
|
|
121
|
+
});
|
|
122
|
+
if (result.output) {
|
|
123
|
+
return result.output;
|
|
124
|
+
}
|
|
125
|
+
return content;
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
console.error(`${content}\n\nFailed to format ${path}\n\n`);
|
|
129
|
+
throw err;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
default: {
|
|
133
|
+
return content;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}));
|
|
137
|
+
let totalFixableErrorCount = 0;
|
|
138
|
+
let totalErrorCount = 0;
|
|
139
|
+
let totalFixableWarningCount = 0;
|
|
140
|
+
let totalWarningCount = 0;
|
|
141
|
+
for (const result of _results.values()) {
|
|
142
|
+
totalFixableErrorCount += result.fixableErrorCount;
|
|
143
|
+
totalErrorCount += result.errorCount;
|
|
144
|
+
totalFixableWarningCount += result.fixableWarningCount;
|
|
145
|
+
totalWarningCount += result.warningCount;
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
totalFixableErrorCount,
|
|
149
|
+
totalErrorCount,
|
|
150
|
+
totalFixableWarningCount,
|
|
151
|
+
totalWarningCount,
|
|
152
|
+
results: _results,
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.ExtendedVirtualFS = ExtendedVirtualFS;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postxl/generator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"main": "./dist/generator.js",
|
|
5
5
|
"typings": "./dist/generator.d.ts",
|
|
6
6
|
"bin": {
|
|
@@ -17,15 +17,20 @@
|
|
|
17
17
|
"@faker-js/faker": "7.6.0",
|
|
18
18
|
"@prisma/generator-helper": "^5.2.0",
|
|
19
19
|
"@prisma/internals": "^5.2.0",
|
|
20
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
21
|
+
"@typescript-eslint/parser": "^6.10.0",
|
|
22
|
+
"@typescript-eslint/utils": "^6.10.0",
|
|
23
|
+
"eslint": "^8.53.0",
|
|
20
24
|
"exceljs": "^4.3.0",
|
|
21
25
|
"fast-glob": "^3.2.12",
|
|
22
|
-
"prettier": "^
|
|
26
|
+
"prettier": "^3.0.3",
|
|
23
27
|
"remeda": "1.9.4",
|
|
24
28
|
"zod": "3.21.4",
|
|
25
|
-
"@postxl/lock": "0.
|
|
29
|
+
"@postxl/lock": "1.0.0"
|
|
26
30
|
},
|
|
27
31
|
"devDependencies": {
|
|
28
32
|
"@prisma/client": "^5.2.0",
|
|
33
|
+
"@types/eslint": "^8.44.7",
|
|
29
34
|
"@types/jest": "^29.5.0",
|
|
30
35
|
"@types/node": "18.15.10",
|
|
31
36
|
"jest": "29.5.0",
|