@jayfong/x-server 1.26.8 → 1.27.1

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.27.1](https://github.com/jfWorks/x-server/compare/v1.27.0...v1.27.1) (2022-05-08)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * api ([d30109c](https://github.com/jfWorks/x-server/commit/d30109ce90db1f3f9c513b9867be6123bc6373e6))
11
+
12
+ ## [1.27.0](https://github.com/jfWorks/x-server/compare/v1.26.9...v1.27.0) (2022-05-07)
13
+
14
+
15
+ ### Features
16
+
17
+ * 添加 fastifyOptions ([0be0509](https://github.com/jfWorks/x-server/commit/0be0509adb2bfcc24ff0122b1f5d52a155370738))
18
+
19
+ ### [1.26.9](https://github.com/jfWorks/x-server/compare/v1.26.8...v1.26.9) (2022-05-07)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * initTasks ([3e1984d](https://github.com/jfWorks/x-server/commit/3e1984da3ad0cb99b858f88e211c68c8a6eab8c1))
25
+
5
26
  ### [1.26.8](https://github.com/jfWorks/x-server/compare/v1.26.7...v1.26.8) (2022-05-07)
6
27
 
7
28
 
@@ -241,7 +241,7 @@ class ApiGenerator {
241
241
 
242
242
  for (const handlerList of handlerGroup) {
243
243
  const handlerListSourceFile = this.getTypeBySymbol(handlerList).getProperties()[0].getDeclarations()[0].getSourceFile();
244
- const basePath = `/${(0, _vtils.snakeCase)(handlerListSourceFile.getFilePath().replace('.ts', '').split('/src/handlers/')[1]).replace(/_/g, '/')}/`.replace(/\/{2,}/g, '/');
244
+ const basePath = `/${handlerListSourceFile.getFilePath().replace('.ts', '').split('/src/handlers/')[1].replace(/(^|\/)index$/, '/').split('/').map(v => (0, _vtils.snakeCase)(v)).join('/')}/`.replace(/\/{2,}/g, '/');
245
245
 
246
246
  for (const handler of handlerListSourceFile.getVariableStatements().filter(item => item.isExported())) {
247
247
  // 重要:这一步必须,先调一遍 getText 获取看到的对象,后续对于复杂定义才不会报错
@@ -259,7 +259,7 @@ class ApiGenerator {
259
259
  continue;
260
260
  }
261
261
 
262
- const handlerCategory = (0, _vtils.pascalCase)(basePath) || 'ROOT';
262
+ const handlerCategory = (0, _vtils.pascalCase)(basePath) || 'Index';
263
263
  const handlerName = handlerComment.description || handlerPath;
264
264
  const handlerMethod = methodType.getLiteralValueOrThrow();
265
265
  const serverMethod = _http_method.HandlerMethodToHttpMethod[handlerMethod];
@@ -45,12 +45,12 @@ class TemplateUtil {
45
45
 
46
46
 
47
47
  static async initTasks(cwd) {
48
- const tasksDir = _path.default.join(cwd, 'tasks');
48
+ const tasksDir = _path.default.join(cwd, 'src/tasks');
49
49
 
50
50
  const tasksIndexFile = _path.default.join(tasksDir, 'index.ts');
51
51
 
52
52
  if (!(await _fsExtra.default.pathExists(tasksIndexFile))) {
53
- await _fsExtra.default.writeFile(tasksIndexFile, (0, _vtils.dedent)`
53
+ await _fsExtra.default.outputFile(tasksIndexFile, (0, _vtils.dedent)`
54
54
  // @index(['./**/*.ts', '!**/*.test.ts', '!**/_*'], f => \`export * from '\${f.path}'\`)
55
55
  // @endindex
56
56
  `);
@@ -45,7 +45,8 @@ class Server {
45
45
  this.fastify = (0, _fastify.default)({
46
46
  logger: process.env.NODE_ENV === 'development' ? {
47
47
  prettyPrint: true
48
- } : false
48
+ } : false,
49
+ ...this.options.fastifyOptions
49
50
  });
50
51
  }
51
52
 
@@ -225,7 +225,7 @@ export class ApiGenerator {
225
225
 
226
226
  for (const handlerList of handlerGroup) {
227
227
  const handlerListSourceFile = this.getTypeBySymbol(handlerList).getProperties()[0].getDeclarations()[0].getSourceFile();
228
- const basePath = `/${snakeCase(handlerListSourceFile.getFilePath().replace('.ts', '').split('/src/handlers/')[1]).replace(/_/g, '/')}/`.replace(/\/{2,}/g, '/');
228
+ const basePath = `/${handlerListSourceFile.getFilePath().replace('.ts', '').split('/src/handlers/')[1].replace(/(^|\/)index$/, '/').split('/').map(v => snakeCase(v)).join('/')}/`.replace(/\/{2,}/g, '/');
229
229
 
230
230
  for (const handler of handlerListSourceFile.getVariableStatements().filter(item => item.isExported())) {
231
231
  // 重要:这一步必须,先调一遍 getText 获取看到的对象,后续对于复杂定义才不会报错
@@ -243,7 +243,7 @@ export class ApiGenerator {
243
243
  continue;
244
244
  }
245
245
 
246
- const handlerCategory = pascalCase(basePath) || 'ROOT';
246
+ const handlerCategory = pascalCase(basePath) || 'Index';
247
247
  const handlerName = handlerComment.description || handlerPath;
248
248
  const handlerMethod = methodType.getLiteralValueOrThrow();
249
249
  const serverMethod = HandlerMethodToHttpMethod[handlerMethod];
@@ -32,11 +32,11 @@ export class TemplateUtil {
32
32
 
33
33
 
34
34
  static async initTasks(cwd) {
35
- const tasksDir = path.join(cwd, 'tasks');
35
+ const tasksDir = path.join(cwd, 'src/tasks');
36
36
  const tasksIndexFile = path.join(tasksDir, 'index.ts');
37
37
 
38
38
  if (!(await fs.pathExists(tasksIndexFile))) {
39
- await fs.writeFile(tasksIndexFile, dedent`
39
+ await fs.outputFile(tasksIndexFile, dedent`
40
40
  // @index(['./**/*.ts', '!**/*.test.ts', '!**/_*'], f => \`export * from '\${f.path}'\`)
41
41
  // @endindex
42
42
  `);
@@ -32,7 +32,8 @@ export class Server {
32
32
  this.fastify = Fastify({
33
33
  logger: process.env.NODE_ENV === 'development' ? {
34
34
  prettyPrint: true
35
- } : false
35
+ } : false,
36
+ ...this.options.fastifyOptions
36
37
  });
37
38
  }
38
39
 
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { BasePlugin } from '../plugins/base';
3
3
  import { BaseService } from '../services/base';
4
- import { FastifyReply, FastifyRequest } from 'fastify';
4
+ import { FastifyReply, FastifyRequest, FastifyServerOptions } from 'fastify';
5
5
  import { yup } from 'vtils/validator';
6
6
  import type { AsyncOrSync, LiteralUnion, OneOrMore, RequiredDeep } from 'vtils/types';
7
7
  import type { DisposeService } from '../services/dispose';
@@ -31,6 +31,10 @@ export declare namespace XServer {
31
31
  * 监听端口
32
32
  */
33
33
  port: number;
34
+ /**
35
+ * 透传给 Fastify 的选项
36
+ */
37
+ fastifyOptions?: FastifyServerOptions;
34
38
  /**
35
39
  * 服务列表
36
40
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.26.8",
3
+ "version": "1.27.1",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",