@jayfong/x-server 1.10.2 → 1.10.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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.10.3](https://github.com/jfWorks/x-server/compare/v1.10.2...v1.10.3) (2022-04-19)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * initModels ([85c6aa7](https://github.com/jfWorks/x-server/commit/85c6aa77d28ded5aeb336e57b2c62de3817a18f3))
11
+
5
12
  ### [1.10.2](https://github.com/jfWorks/x-server/compare/v1.10.1...v1.10.2) (2022-04-19)
6
13
 
7
14
 
package/lib/cli/cli.js CHANGED
@@ -6,8 +6,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const chokidar_1 = __importDefault(require("chokidar"));
8
8
  const execa_1 = __importDefault(require("execa"));
9
- const fs_extra_1 = __importDefault(require("fs-extra"));
10
- const node_path_1 = __importDefault(require("node:path"));
11
9
  const yargs_1 = __importDefault(require("yargs"));
12
10
  const api_generator_1 = require("./api_generator");
13
11
  const build_util_1 = require("./build_util");
@@ -48,10 +46,7 @@ yargs_1.default
48
46
  stdio: 'inherit',
49
47
  });
50
48
  }
51
- await Promise.all([
52
- template_util_1.TemplateUtil.initHelperPackage(process.cwd()),
53
- template_util_1.TemplateUtil.initModels(process.cwd()),
54
- ]);
49
+ await template_util_1.TemplateUtil.initHelperPackage(process.cwd());
55
50
  const watcher = chokidar_1.default.watch(['src', '.env'], {
56
51
  cwd: process.cwd(),
57
52
  });
@@ -149,29 +144,7 @@ yargs_1.default
149
144
  stdio: 'inherit',
150
145
  });
151
146
  if (!argv.production) {
152
- const modelsDir = node_path_1.default.join(process.cwd(), 'src/models');
153
- const baseModelFile = node_path_1.default.join(modelsDir, '_.ts');
154
- await (0, vscode_generate_index_standalone_1.generateIndex)({
155
- filePath: baseModelFile,
156
- replaceFile: true,
157
- });
158
- const baseModelContent = await fs_extra_1.default.readFile(baseModelFile, 'utf-8');
159
- const modelNames = [
160
- ...baseModelContent.matchAll(/makeBaseModel\('(\w+?)'\)/g),
161
- ].map(match => (0, vtils_1.snakeCase)(match[1]));
162
- await Promise.all(modelNames.map(async (modelName) => {
163
- const modelFile = node_path_1.default.join(modelsDir, `${modelName}.ts`);
164
- if (!(await fs_extra_1.default.pathExists(modelFile))) {
165
- const ModelName = (0, vtils_1.pascalCase)(modelName);
166
- await fs_extra_1.default.writeFile(modelFile, (0, vtils_1.dedent) `
167
- import { ${ModelName}BaseModel } from './_'
168
-
169
- export class ${ModelName}Model extends ${ModelName}BaseModel {}
170
-
171
- export const ${(0, vtils_1.camelCase)(modelName)}Model = new ${ModelName}Model()
172
- `);
173
- }
174
- }));
147
+ await template_util_1.TemplateUtil.initModels(process.cwd());
175
148
  }
176
149
  })
177
150
  .command('run [script]', '执行脚本', _ => _.positional('script', {
@@ -7,6 +7,7 @@ exports.TemplateUtil = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const vtils_1 = require("vtils");
10
+ const vscode_generate_index_standalone_1 = require("vscode-generate-index-standalone");
10
11
  class TemplateUtil {
11
12
  /**
12
13
  * 初始化辅助包。
@@ -24,12 +25,7 @@ class TemplateUtil {
24
25
  static async initModels(cwd) {
25
26
  const modelsDir = path_1.default.join(cwd, 'src/models');
26
27
  const indexFile = path_1.default.join(modelsDir, 'index.ts');
27
- if (!(await fs_extra_1.default.pathExists(indexFile))) {
28
- await fs_extra_1.default.outputFile(indexFile, (0, vtils_1.dedent) `
29
- // @index(['./**/*.ts', '!**/*.test.ts', '!**/_*'], f => \`export * from '\${f.path}'\`)
30
- // @endindex
31
- `);
32
- }
28
+ const indexFile2 = path_1.default.join(cwd, 'node_modules/.x/models.ts');
33
29
  const prismaClientFile = path_1.default.join(cwd, 'node_modules/.prisma/client/index.d.ts');
34
30
  const prismaClientFileContent = await fs_extra_1.default.readFile(prismaClientFile, 'utf8');
35
31
  const modelNames = [
@@ -51,6 +47,16 @@ class TemplateUtil {
51
47
  `);
52
48
  }
53
49
  }));
50
+ if (!(await fs_extra_1.default.pathExists(indexFile))) {
51
+ await fs_extra_1.default.outputFile(indexFile, (0, vtils_1.dedent) `
52
+ // @index(['./**/*.ts', '!**/*.test.ts', '!**/_*'], f => \`export * from '\${f.path}'\`)
53
+ // @endindex
54
+ `);
55
+ }
56
+ await (0, vscode_generate_index_standalone_1.generateManyIndex)({
57
+ patterns: [indexFile, indexFile2],
58
+ replaceFile: true,
59
+ });
54
60
  }
55
61
  }
56
62
  exports.TemplateUtil = TemplateUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.10.2",
3
+ "version": "1.10.3",
4
4
  "license": "ISC",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",