@jayfong/x-server 1.8.0 → 1.10.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 +32 -0
- package/lib/cli/cli.js +3 -3
- package/lib/cli/register.d.ts +1 -0
- package/lib/cli/register.js +5 -3
- package/lib/cli/templates/handlers.ts +1 -1
- package/lib/cli/templates/package.json +3 -0
- package/lib/cli/templates/routes.ts +1 -1
- package/lib/core/server.d.ts +3 -0
- package/lib/core/server.js +18 -11
- package/lib/x.d.ts +1 -0
- package/lib/x.js +4 -0
- package/package.json +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,38 @@
|
|
|
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.0](https://github.com/jfWorks/x-server/compare/v1.8.0...v1.10.0) (2022-04-19)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* use esbuild-register ([0b004db](https://github.com/jfWorks/x-server/commit/0b004db9a048d0faaf528c0d8030bf0ccfb8e2b3))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* template ([0f9bd05](https://github.com/jfWorks/x-server/commit/0f9bd0589d101de6f78f13f185ef9220edc887a7))
|
|
16
|
+
* watcher initial ([82511a1](https://github.com/jfWorks/x-server/commit/82511a1bc9d1ccf4d96aa7a8ae7ee3d50a8ec2db))
|
|
17
|
+
|
|
18
|
+
## [1.9.0](https://github.com/jfWorks/x-server/compare/v1.7.2...v1.9.0) (2022-04-18)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* 更改包名为 @jayfong/x-server ([1be9998](https://github.com/jfWorks/x-server/commit/1be9998070cc0960aeef2d333356f66a22bb5766))
|
|
24
|
+
* 移除 cwd 选项 ([12cfa42](https://github.com/jfWorks/x-server/commit/12cfa4222ec8d69d73f2b38a68ea6aa975dbe575))
|
|
25
|
+
* npc ([5d314ea](https://github.com/jfWorks/x-server/commit/5d314ea341a72ae5b09db979d5d2b63ffadf0670))
|
|
26
|
+
* plugins ([1df0cd1](https://github.com/jfWorks/x-server/commit/1df0cd10ccf170d9e7180abf9d27416304856894))
|
|
27
|
+
* service 通过 x 提供 ([a159154](https://github.com/jfWorks/x-server/commit/a1591541e865e755d4d6dbdeb405d5d08b334a4a))
|
|
28
|
+
* templates ([deeb0d6](https://github.com/jfWorks/x-server/commit/deeb0d643bdf04d04533d20bd1d5a068b178347a))
|
|
29
|
+
* use esbuild-register ([0b004db](https://github.com/jfWorks/x-server/commit/0b004db9a048d0faaf528c0d8030bf0ccfb8e2b3))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Bug Fixes
|
|
33
|
+
|
|
34
|
+
* template ([0f9bd05](https://github.com/jfWorks/x-server/commit/0f9bd0589d101de6f78f13f185ef9220edc887a7))
|
|
35
|
+
* test ([994845b](https://github.com/jfWorks/x-server/commit/994845b0e2ac84ce050494de27b705c1e45fb343))
|
|
36
|
+
|
|
5
37
|
## [1.8.0](https://github.com/jfWorks/x-server/compare/v1.7.2...v1.8.0) (2022-04-18)
|
|
6
38
|
|
|
7
39
|
|
package/lib/cli/cli.js
CHANGED
|
@@ -27,9 +27,6 @@ yargs_1.default
|
|
|
27
27
|
type: 'string',
|
|
28
28
|
}), async (argv) => {
|
|
29
29
|
process.env.NODE_ENV = 'development';
|
|
30
|
-
const watcher = chokidar_1.default.watch(['src', '.env'], {
|
|
31
|
-
cwd: process.cwd(),
|
|
32
|
-
});
|
|
33
30
|
let lastRun;
|
|
34
31
|
const run = () => {
|
|
35
32
|
lastRun = (0, execa_1.default)('node', ['-r', require.resolve('./register'), 'src/main.ts'], {
|
|
@@ -52,6 +49,9 @@ yargs_1.default
|
|
|
52
49
|
});
|
|
53
50
|
}
|
|
54
51
|
await template_util_1.TemplateUtil.init(process.cwd());
|
|
52
|
+
const watcher = chokidar_1.default.watch(['src', '.env'], {
|
|
53
|
+
cwd: process.cwd(),
|
|
54
|
+
});
|
|
55
55
|
watcher.on('all', (0, vtils_1.debounce)(async () => {
|
|
56
56
|
await env_util_1.EnvUtil.importFile({
|
|
57
57
|
cwd: process.cwd(),
|
package/lib/cli/register.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/cli/register.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_1 = require("esbuild-register/dist/node");
|
|
4
|
+
(0, node_1.register)({
|
|
5
|
+
hookIgnoreNodeModules: false,
|
|
6
|
+
hookMatcher: filename => filename.includes('/.x/') || !filename.includes('/node_modules/'),
|
|
4
7
|
});
|
|
5
|
-
require('tsconfig-paths/register');
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
// @index('../../src/handlers/**/*.ts', (f, _) => `export * as __${_.pascal(f.path.replace('handlers', ''))}__ from '${f.path}'`)
|
|
1
|
+
// @index('../../src/handlers/**/*.ts', (f, _) => `export * as __${_.pascal(f.path.replace('/src/handlers/', ''))}__ from '${f.path}'`)
|
|
2
2
|
|
|
3
3
|
// @endindex
|
|
@@ -2,7 +2,7 @@ import * as handlers from './handlers'
|
|
|
2
2
|
import { Handler, XServer } from '@jayfong/x-server'
|
|
3
3
|
|
|
4
4
|
const basePathWithHandlers: Array<[string, Record<string, Handler>]> = [
|
|
5
|
-
// @index('../../src/handlers/**/*.ts', (f, _) => `['${('/'+_.snake(f.path.replace('handlers', '')).replace(/_/g, '/')+'/').replace(/\/{2,}/g, '/')}', handlers.__${_.pascal(f.path.replace('handlers', ''))}__ as any],`)
|
|
5
|
+
// @index('../../src/handlers/**/*.ts', (f, _) => `['${('/'+_.snake(f.path.replace('/src/handlers/', '')).replace(/_/g, '/')+'/').replace(/\/{2,}/g, '/')}', handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__ as any],`)
|
|
6
6
|
// @endindex
|
|
7
7
|
]
|
|
8
8
|
|
package/lib/core/server.d.ts
CHANGED
|
@@ -9,8 +9,11 @@ export declare class Server {
|
|
|
9
9
|
close(): Promise<void>;
|
|
10
10
|
private prepareFastify;
|
|
11
11
|
private startFastify;
|
|
12
|
+
private prepareRoutes;
|
|
13
|
+
private applyHooks;
|
|
12
14
|
private applyServices;
|
|
13
15
|
private applyPlugins;
|
|
14
16
|
private applyRoutes;
|
|
17
|
+
private startTasks;
|
|
15
18
|
private applyAutoClose;
|
|
16
19
|
}
|
package/lib/core/server.js
CHANGED
|
@@ -29,27 +29,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.Server = void 0;
|
|
30
30
|
const fastify_1 = __importDefault(require("fastify"));
|
|
31
31
|
const vtils_1 = require("vtils");
|
|
32
|
-
const dispose_1 = require("../services/dispose");
|
|
33
32
|
const http_method_1 = require("./http_method");
|
|
34
33
|
const x_1 = require("../x");
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
const routes_1 = require(".x/routes");
|
|
37
34
|
class Server {
|
|
38
35
|
constructor(options) {
|
|
39
36
|
this.options = options;
|
|
40
|
-
this.routes =
|
|
37
|
+
this.routes = [];
|
|
41
38
|
Server.options = options;
|
|
42
39
|
}
|
|
43
40
|
async start() {
|
|
44
41
|
this.applyServices();
|
|
45
42
|
await this.prepareFastify();
|
|
46
43
|
this.applyPlugins();
|
|
44
|
+
await this.prepareRoutes();
|
|
47
45
|
await this.applyRoutes();
|
|
48
|
-
|
|
49
|
-
await Promise.resolve().then(() => __importStar(require('.x/hooks')));
|
|
46
|
+
await this.applyHooks();
|
|
50
47
|
await this.startFastify();
|
|
51
|
-
|
|
52
|
-
await Promise.resolve().then(() => __importStar(require('.x/tasks')));
|
|
48
|
+
await this.startTasks();
|
|
53
49
|
await this.applyAutoClose();
|
|
54
50
|
}
|
|
55
51
|
async close() {
|
|
@@ -70,10 +66,17 @@ class Server {
|
|
|
70
66
|
port: this.options.port,
|
|
71
67
|
});
|
|
72
68
|
}
|
|
69
|
+
async prepareRoutes() {
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
const { routes } = await Promise.resolve().then(() => __importStar(require('.x/routes')));
|
|
72
|
+
this.routes = routes;
|
|
73
|
+
}
|
|
74
|
+
async applyHooks() {
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
await Promise.resolve().then(() => __importStar(require('.x/hooks')));
|
|
77
|
+
}
|
|
73
78
|
applyServices() {
|
|
74
|
-
x_1.x.register(
|
|
75
|
-
disposeOnExit: true,
|
|
76
|
-
}), ...(this.options.services || []));
|
|
79
|
+
x_1.x.register(...(this.options.services || []));
|
|
77
80
|
}
|
|
78
81
|
applyPlugins() {
|
|
79
82
|
const plugins = this.options.plugins || [];
|
|
@@ -129,6 +132,10 @@ class Server {
|
|
|
129
132
|
});
|
|
130
133
|
}
|
|
131
134
|
}
|
|
135
|
+
async startTasks() {
|
|
136
|
+
// @ts-ignore
|
|
137
|
+
await Promise.resolve().then(() => __importStar(require('.x/tasks')));
|
|
138
|
+
}
|
|
132
139
|
async applyAutoClose() {
|
|
133
140
|
x_1.x.dispose.add(() => this.close());
|
|
134
141
|
}
|
package/lib/x.d.ts
CHANGED
package/lib/x.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.x = void 0;
|
|
4
|
+
const dispose_1 = require("./services/dispose");
|
|
4
5
|
exports.x = {
|
|
5
6
|
register: (...services) => {
|
|
6
7
|
for (const service of services) {
|
|
@@ -9,3 +10,6 @@ exports.x = {
|
|
|
9
10
|
}
|
|
10
11
|
},
|
|
11
12
|
};
|
|
13
|
+
exports.x.register(new dispose_1.DisposeService({
|
|
14
|
+
disposeOnExit: true,
|
|
15
|
+
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayfong/x-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"cuid": "^2.1.8",
|
|
39
39
|
"debug": "^4.3.4",
|
|
40
40
|
"esbuild": "^0.14.36",
|
|
41
|
-
"esbuild-
|
|
41
|
+
"esbuild-register": "^3.3.2",
|
|
42
42
|
"execa": "^5.1.1",
|
|
43
43
|
"exit-hook": "^2.2.1",
|
|
44
44
|
"fast-xml-parser": "^3.21.1",
|
|
@@ -57,7 +57,6 @@
|
|
|
57
57
|
"supports-color": "^8",
|
|
58
58
|
"svg-captcha": "^1.4.0",
|
|
59
59
|
"ts-morph": "^12.2.0",
|
|
60
|
-
"tsconfig-paths": "^3.14.1",
|
|
61
60
|
"utf-8-validate": "^5.0.9",
|
|
62
61
|
"vscode-generate-index-standalone": "^1.6.0",
|
|
63
62
|
"vtils": "^4.60.0",
|