@postxl/generator 0.62.2 → 0.62.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generator.js +10 -19
- package/package.json +3 -9
- package/dist/lib/vfs.d.ts +0 -33
- package/dist/lib/vfs.js +0 -157
package/dist/generator.js
CHANGED
|
@@ -36,9 +36,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.generate = void 0;
|
|
37
37
|
const generator_helper_1 = require("@prisma/generator-helper");
|
|
38
38
|
const internals_1 = require("@prisma/internals");
|
|
39
|
-
const prettier = __importStar(require("prettier"));
|
|
40
39
|
const zod_1 = require("zod");
|
|
41
40
|
const lock_1 = require("@postxl/lock");
|
|
41
|
+
const prettier = __importStar(require("@postxl/prettier"));
|
|
42
42
|
const react_generator_1 = require("./generators/enums/react.generator");
|
|
43
43
|
const types_generator_1 = require("./generators/enums/types.generator");
|
|
44
44
|
const businesslogic_actiontypes_generator_1 = require("./generators/indices/businesslogic-actiontypes.generator");
|
|
@@ -77,7 +77,6 @@ const stub_generator_1 = require("./generators/models/stub.generator");
|
|
|
77
77
|
const types_generator_3 = require("./generators/models/types.generator");
|
|
78
78
|
const meta_1 = require("./lib/meta");
|
|
79
79
|
const types_1 = require("./lib/schema/types");
|
|
80
|
-
const vfs_1 = require("./lib/vfs");
|
|
81
80
|
const client_path_1 = require("./prisma/client-path");
|
|
82
81
|
const parse_1 = require("./prisma/parse");
|
|
83
82
|
// NOTE: This needs to match the constant used in the manager package.
|
|
@@ -165,15 +164,8 @@ function generate({ models, enums, config, prismaClientPath, logger, }) {
|
|
|
165
164
|
if (root == undefined) {
|
|
166
165
|
throw new Error(`Could not find lock file. Make sure you are running the generator in a project folder.`);
|
|
167
166
|
}
|
|
168
|
-
const vfs = yield vfs_1.ExtendedVirtualFS.fromLockFile({
|
|
169
|
-
root,
|
|
170
|
-
namespace: GENERATOR_NAMESPACE,
|
|
171
|
-
// NOTE: We start with a clean slate every time we generate so we can detect
|
|
172
|
-
// which files were not generated in the last run.
|
|
173
|
-
opts: { clean: true },
|
|
174
|
-
});
|
|
175
167
|
const gitignore = lock_1.GitIgnoreUtils.getGitignore(root);
|
|
176
|
-
const generated = new
|
|
168
|
+
const generated = new prettier.ExtendedVirtualFS();
|
|
177
169
|
// Generate Models
|
|
178
170
|
for (const model of models) {
|
|
179
171
|
const meta = (0, meta_1.getModelMetadata)({ model });
|
|
@@ -308,16 +300,15 @@ function generate({ models, enums, config, prismaClientPath, logger, }) {
|
|
|
308
300
|
if (unfixedWarningCount === 0 && unfixableErrorCount === 0) {
|
|
309
301
|
console.log(`LINT: All files linted successfully without warnings and errors!`);
|
|
310
302
|
}
|
|
311
|
-
|
|
312
|
-
const prettierConfigFilePath = yield prettier.resolveConfigFile(process.cwd());
|
|
313
|
-
if (prettierConfigFilePath) {
|
|
314
|
-
prettierConfig = yield prettier.resolveConfig(prettierConfigFilePath);
|
|
315
|
-
}
|
|
316
|
-
if (!prettierConfig) {
|
|
317
|
-
console.warn(`Could not find Prettier configuration! Formatting files with default config!`);
|
|
318
|
-
}
|
|
319
|
-
yield generated.formatUTF8Files(prettierConfig);
|
|
303
|
+
yield generated.formatUTF8Files(prettier.config);
|
|
320
304
|
// -------------------------------------------------------------------------
|
|
305
|
+
const vfs = yield lock_1.VirtualFS.fromLockFile({
|
|
306
|
+
root,
|
|
307
|
+
namespace: GENERATOR_NAMESPACE,
|
|
308
|
+
// NOTE: We start with a clean slate every time we generate so we can detect
|
|
309
|
+
// which files were not generated in the last run.
|
|
310
|
+
opts: { clean: true },
|
|
311
|
+
});
|
|
321
312
|
// Merge with existing files.
|
|
322
313
|
yield vfs.copy(generated, './');
|
|
323
314
|
// Flush to disk.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postxl/generator",
|
|
3
|
-
"version": "0.62.
|
|
3
|
+
"version": "0.62.3",
|
|
4
4
|
"main": "./dist/generator.js",
|
|
5
5
|
"typings": "./dist/generator.d.ts",
|
|
6
6
|
"bin": {
|
|
@@ -17,16 +17,12 @@
|
|
|
17
17
|
"@faker-js/faker": "7.6.0",
|
|
18
18
|
"@prisma/generator-helper": "5.8.1",
|
|
19
19
|
"@prisma/internals": "5.8.1",
|
|
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",
|
|
24
|
-
"eslint-plugin-simple-import-sort": "10.0.0",
|
|
25
20
|
"exceljs": "4.3.0",
|
|
26
21
|
"fast-glob": "3.2.12",
|
|
27
22
|
"remeda": "1.9.4",
|
|
28
23
|
"zod": "3.21.4",
|
|
29
|
-
"@postxl/lock": "1.4.
|
|
24
|
+
"@postxl/lock": "1.4.1",
|
|
25
|
+
"@postxl/prettier": "0.0.1"
|
|
30
26
|
},
|
|
31
27
|
"devDependencies": {
|
|
32
28
|
"@prisma/client": "5.8.1",
|
|
@@ -34,7 +30,6 @@
|
|
|
34
30
|
"@types/jest": "29.5.0",
|
|
35
31
|
"@types/node": "18.15.10",
|
|
36
32
|
"jest": "29.7.0",
|
|
37
|
-
"prettier": "3.0.3",
|
|
38
33
|
"prisma": "5.8.1",
|
|
39
34
|
"ts-jest": "29.0.5",
|
|
40
35
|
"ts-node": "10.9.1",
|
|
@@ -43,7 +38,6 @@
|
|
|
43
38
|
"typescript": "5.2.2"
|
|
44
39
|
},
|
|
45
40
|
"peerDependencies": {
|
|
46
|
-
"prettier": "3.0.3",
|
|
47
41
|
"prisma": "5.8.1"
|
|
48
42
|
},
|
|
49
43
|
"wallaby": {
|
package/dist/lib/vfs.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { ESLint } from 'eslint';
|
|
2
|
-
import * as prettier from 'prettier';
|
|
3
|
-
import { PathUtils, VirtualFS as BaseVirtualFS } 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
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
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) => __awaiter(this, void 0, void 0, function* () {
|
|
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 yield 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;
|