@jayfong/x-server 1.10.1 → 1.11.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/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
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.11.0](https://github.com/jfWorks/x-server/compare/v1.10.3...v1.11.0) (2022-04-20)
6
+
7
+
8
+ ### Features
9
+
10
+ * minify & sideEffects ([12cdccd](https://github.com/jfWorks/x-server/commit/12cdccdd23273117e610a1f428f33b735f6b199b))
11
+
12
+ ### [1.10.3](https://github.com/jfWorks/x-server/compare/v1.10.2...v1.10.3) (2022-04-19)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * initModels ([85c6aa7](https://github.com/jfWorks/x-server/commit/85c6aa77d28ded5aeb336e57b2c62de3817a18f3))
18
+
19
+ ### [1.10.2](https://github.com/jfWorks/x-server/compare/v1.10.1...v1.10.2) (2022-04-19)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * api gen ([cc33df1](https://github.com/jfWorks/x-server/commit/cc33df1bf15c2b367b1a62cf920a1a1184c20339))
25
+
5
26
  ### [1.10.1](https://github.com/jfWorks/x-server/compare/v1.10.0...v1.10.1) (2022-04-19)
6
27
 
7
28
  ## [1.10.0](https://github.com/jfWorks/x-server/compare/v1.8.0...v1.10.0) (2022-04-19)
@@ -273,7 +273,7 @@ class ApiGenerator {
273
273
  tsConfigFilePath: node_path_1.default.join(this.cwd, 'tsconfig.json'),
274
274
  });
275
275
  this.debug('加载文件...');
276
- const sourceFile = this.project.getSourceFileOrThrow(node_path_1.default.join(this.cwd, 'src/generated/handlers.ts'));
276
+ const sourceFile = this.project.createSourceFile(node_path_1.default.join(this.cwd, 'src/generated/handlers.ts'), await fs_extra_1.default.readFile(node_path_1.default.join(this.cwd, 'node_modules/.x/handlers.ts'), 'utf-8'));
277
277
  this.debug('导出处理器...');
278
278
  const handlerGroup = sourceFile.getExportSymbols();
279
279
  const handles = [];
@@ -3,6 +3,7 @@ export interface BuildOptions {
3
3
  cwd: string;
4
4
  external?: string[];
5
5
  inlineEnvs?: ParsedEnv[];
6
+ minify?: boolean;
6
7
  }
7
8
  export declare class BuildUtil {
8
9
  static build(options: BuildOptions): Promise<void>;
@@ -65,7 +65,7 @@ class BuildUtil {
65
65
  platform: 'node',
66
66
  target: `node${process.version.slice(1)}`,
67
67
  external: external,
68
- minify: true,
68
+ minify: options.minify ?? true,
69
69
  format: 'cjs',
70
70
  sourcemap: false,
71
71
  treeShaking: true,
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
  });
@@ -93,6 +88,11 @@ yargs_1.default
93
88
  describe: '不应该被打的包',
94
89
  type: 'string',
95
90
  array: true,
91
+ }).positional('minify', {
92
+ alias: 'm',
93
+ describe: '是否压缩',
94
+ type: 'boolean',
95
+ default: true,
96
96
  }), async (argv) => {
97
97
  process.env.NODE_ENV = 'production';
98
98
  const envs = await env_util_1.EnvUtil.parseFile({
@@ -117,6 +117,7 @@ yargs_1.default
117
117
  cwd: process.cwd(),
118
118
  external: argv.external,
119
119
  inlineEnvs: envs,
120
+ minify: argv.minify,
120
121
  });
121
122
  console.log('构建成功');
122
123
  })
@@ -149,29 +150,7 @@ yargs_1.default
149
150
  stdio: 'inherit',
150
151
  });
151
152
  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
- }));
153
+ await template_util_1.TemplateUtil.initModels(process.cwd());
175
154
  }
176
155
  })
177
156
  .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,7 +1,8 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.10.1",
3
+ "version": "1.11.0",
4
4
  "license": "ISC",
5
+ "sideEffects": false,
5
6
  "main": "lib/index.js",
6
7
  "types": "lib/index.d.ts",
7
8
  "bin": {