@jayfong/x-server 2.79.0 → 2.80.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/lib/_cjs/cli/cli.js +65 -59
- package/lib/_cjs/exports.js +6 -0
- package/lib/_cjs/plugins/compress.js +18 -0
- package/lib/cli/cli.js +65 -59
- package/lib/exports.d.ts +1 -0
- package/lib/exports.js +1 -0
- package/lib/plugins/compress.d.ts +13 -0
- package/lib/plugins/compress.js +12 -0
- package/package.json +5 -2
package/lib/_cjs/cli/cli.js
CHANGED
|
@@ -73,60 +73,63 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
73
73
|
describe: '渠道',
|
|
74
74
|
type: 'string'
|
|
75
75
|
}), async argv => {
|
|
76
|
-
|
|
77
|
-
argv.channel = await _env_util.EnvUtil.chooseChannel(process.cwd());
|
|
78
|
-
}
|
|
79
|
-
process.env.NODE_ENV = 'development';
|
|
80
|
-
let lastRun;
|
|
81
|
-
const run = () => {
|
|
82
|
-
lastRun = _dev_util.DevUtil.runFile({
|
|
83
|
-
file: 'src/main.ts',
|
|
84
|
-
cwd: process.cwd(),
|
|
85
|
-
runner: argv.tsx ? 'tsx' : 'esbuild-register'
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
if (argv.npc) {
|
|
89
|
-
const [server, vkey] = argv.npc.split('@');
|
|
90
|
-
(0, _execa.default)('docker', ['run', '--rm', 'ffdfgdfg/npc:v0.26.9', `-server=${server}`, `-vkey=${vkey}`, '-type=tcp'], {
|
|
91
|
-
cwd: process.cwd(),
|
|
92
|
-
stdio: 'inherit'
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
await _template_util.TemplateUtil.init(process.cwd());
|
|
96
|
-
const xsignoreFile = _path.default.join(process.cwd(), '.xsignore');
|
|
97
|
-
const xsignoreContent = (await _fsExtra.default.pathExists(xsignoreFile)) ? (await _fsExtra.default.readFile(xsignoreFile, 'utf-8')).trim().split(/[\r\n]+/g).filter(v => v && !v.startsWith('#')) : [];
|
|
98
|
-
const watcher = _chokidar.default.watch(['src', '.env', '.env*'], {
|
|
76
|
+
await _env_util.EnvUtil.withChannel({
|
|
99
77
|
cwd: process.cwd(),
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
onSuccess: filePath => {
|
|
118
|
-
console.log(`✔️ 索引文件已更新: ${filePath}`);
|
|
78
|
+
channel: argv.channel,
|
|
79
|
+
cb: async channel => {
|
|
80
|
+
process.env.NODE_ENV = 'development';
|
|
81
|
+
let lastRun;
|
|
82
|
+
const run = () => {
|
|
83
|
+
lastRun = _dev_util.DevUtil.runFile({
|
|
84
|
+
file: 'src/main.ts',
|
|
85
|
+
cwd: process.cwd(),
|
|
86
|
+
runner: argv.tsx ? 'tsx' : 'esbuild-register'
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
if (argv.npc) {
|
|
90
|
+
const [server, vkey] = argv.npc.split('@');
|
|
91
|
+
(0, _execa.default)('docker', ['run', '--rm', 'ffdfgdfg/npc:v0.26.9', `-server=${server}`, `-vkey=${vkey}`, '-type=tcp'], {
|
|
92
|
+
cwd: process.cwd(),
|
|
93
|
+
stdio: 'inherit'
|
|
94
|
+
});
|
|
119
95
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
96
|
+
await _template_util.TemplateUtil.init(process.cwd());
|
|
97
|
+
const xsignoreFile = _path.default.join(process.cwd(), '.xsignore');
|
|
98
|
+
const xsignoreContent = (await _fsExtra.default.pathExists(xsignoreFile)) ? (await _fsExtra.default.readFile(xsignoreFile, 'utf-8')).trim().split(/[\r\n]+/g).filter(v => v && !v.startsWith('#')) : [];
|
|
99
|
+
const watcher = _chokidar.default.watch(['src', '.env', '.env*'], {
|
|
100
|
+
cwd: process.cwd(),
|
|
101
|
+
ignored: ['**/*.test.*', ...xsignoreContent]
|
|
102
|
+
});
|
|
103
|
+
watcher.on('all', (0, _vtils.debounce)(async () => {
|
|
104
|
+
const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, channel);
|
|
105
|
+
await _env_util.EnvUtil.importFile({
|
|
106
|
+
cwd: process.cwd(),
|
|
107
|
+
file: envFiles
|
|
108
|
+
});
|
|
109
|
+
_env_util.EnvUtil.outputTypes({
|
|
110
|
+
cwd: process.cwd(),
|
|
111
|
+
file: envFiles,
|
|
112
|
+
outFile: 'env.d.ts'
|
|
113
|
+
});
|
|
114
|
+
(0, _vscodeGenerateIndexStandalone.generateManyIndex)({
|
|
115
|
+
cwd: process.cwd(),
|
|
116
|
+
patterns: ['src/**/index.ts', 'node_modules/.x/*.ts', '!src/handlers/**/*', ...(argv.index || [])],
|
|
117
|
+
replaceFile: true,
|
|
118
|
+
onSuccess: filePath => {
|
|
119
|
+
console.log(`✔️ 索引文件已更新: ${filePath}`);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
if (lastRun) {
|
|
123
|
+
console.log('==== 重启服务中 ====');
|
|
124
|
+
lastRun.kill();
|
|
125
|
+
setTimeout(run, 0);
|
|
126
|
+
} else {
|
|
127
|
+
console.log('==== 启动服务中 ====');
|
|
128
|
+
run();
|
|
129
|
+
}
|
|
130
|
+
}, 30));
|
|
128
131
|
}
|
|
129
|
-
}
|
|
132
|
+
});
|
|
130
133
|
}).command('build', '构建', _ => _.positional('external', {
|
|
131
134
|
alias: 'e',
|
|
132
135
|
describe: '不应该被打的包',
|
|
@@ -207,16 +210,19 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
207
210
|
describe: '渠道',
|
|
208
211
|
type: 'string'
|
|
209
212
|
}), async argv => {
|
|
210
|
-
|
|
211
|
-
argv.channel = await _env_util.EnvUtil.chooseChannel(process.cwd());
|
|
212
|
-
}
|
|
213
|
-
process.env.NODE_ENV = 'production';
|
|
214
|
-
const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
|
|
215
|
-
await _env_util.EnvUtil.importFile({
|
|
213
|
+
await _env_util.EnvUtil.withChannel({
|
|
216
214
|
cwd: process.cwd(),
|
|
217
|
-
|
|
215
|
+
channel: argv.channel,
|
|
216
|
+
cb: async channel => {
|
|
217
|
+
process.env.NODE_ENV = 'production';
|
|
218
|
+
const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, channel);
|
|
219
|
+
await _env_util.EnvUtil.importFile({
|
|
220
|
+
cwd: process.cwd(),
|
|
221
|
+
file: envFiles
|
|
222
|
+
});
|
|
223
|
+
await new _api_generator.ApiGenerator().start();
|
|
224
|
+
}
|
|
218
225
|
});
|
|
219
|
-
await new _api_generator.ApiGenerator().start();
|
|
220
226
|
}).command('prisma', 'prisma 代理,主要为了注入环境变量', _ => _.positional('production', {
|
|
221
227
|
alias: 'p',
|
|
222
228
|
describe: '是否生产模式',
|
package/lib/_cjs/exports.js
CHANGED
|
@@ -97,6 +97,12 @@ Object.keys(_base).forEach(function (key) {
|
|
|
97
97
|
if (key in exports && exports[key] === _base[key]) return;
|
|
98
98
|
exports[key] = _base[key];
|
|
99
99
|
});
|
|
100
|
+
var _compress = require("./plugins/compress");
|
|
101
|
+
Object.keys(_compress).forEach(function (key) {
|
|
102
|
+
if (key === "default" || key === "__esModule") return;
|
|
103
|
+
if (key in exports && exports[key] === _compress[key]) return;
|
|
104
|
+
exports[key] = _compress[key];
|
|
105
|
+
});
|
|
100
106
|
var _cookie = require("./plugins/cookie");
|
|
101
107
|
Object.keys(_cookie).forEach(function (key) {
|
|
102
108
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.CompressPlugin = void 0;
|
|
6
|
+
var _compress = _interopRequireDefault(require("@fastify/compress"));
|
|
7
|
+
/**
|
|
8
|
+
* 响应压缩插件
|
|
9
|
+
*/
|
|
10
|
+
class CompressPlugin {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
register(fastify) {
|
|
15
|
+
fastify.register(_compress.default, this.options);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.CompressPlugin = CompressPlugin;
|
package/lib/cli/cli.js
CHANGED
|
@@ -71,60 +71,63 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
71
71
|
describe: '渠道',
|
|
72
72
|
type: 'string'
|
|
73
73
|
}), async argv => {
|
|
74
|
-
|
|
75
|
-
argv.channel = await EnvUtil.chooseChannel(process.cwd());
|
|
76
|
-
}
|
|
77
|
-
process.env.NODE_ENV = 'development';
|
|
78
|
-
let lastRun;
|
|
79
|
-
const run = () => {
|
|
80
|
-
lastRun = DevUtil.runFile({
|
|
81
|
-
file: 'src/main.ts',
|
|
82
|
-
cwd: process.cwd(),
|
|
83
|
-
runner: argv.tsx ? 'tsx' : 'esbuild-register'
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
if (argv.npc) {
|
|
87
|
-
const [server, vkey] = argv.npc.split('@');
|
|
88
|
-
execa('docker', ['run', '--rm', 'ffdfgdfg/npc:v0.26.9', `-server=${server}`, `-vkey=${vkey}`, '-type=tcp'], {
|
|
89
|
-
cwd: process.cwd(),
|
|
90
|
-
stdio: 'inherit'
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
await TemplateUtil.init(process.cwd());
|
|
94
|
-
const xsignoreFile = path.join(process.cwd(), '.xsignore');
|
|
95
|
-
const xsignoreContent = (await fs.pathExists(xsignoreFile)) ? (await fs.readFile(xsignoreFile, 'utf-8')).trim().split(/[\r\n]+/g).filter(v => v && !v.startsWith('#')) : [];
|
|
96
|
-
const watcher = chokidar.watch(['src', '.env', '.env*'], {
|
|
74
|
+
await EnvUtil.withChannel({
|
|
97
75
|
cwd: process.cwd(),
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
onSuccess: filePath => {
|
|
116
|
-
console.log(`✔️ 索引文件已更新: ${filePath}`);
|
|
76
|
+
channel: argv.channel,
|
|
77
|
+
cb: async channel => {
|
|
78
|
+
process.env.NODE_ENV = 'development';
|
|
79
|
+
let lastRun;
|
|
80
|
+
const run = () => {
|
|
81
|
+
lastRun = DevUtil.runFile({
|
|
82
|
+
file: 'src/main.ts',
|
|
83
|
+
cwd: process.cwd(),
|
|
84
|
+
runner: argv.tsx ? 'tsx' : 'esbuild-register'
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
if (argv.npc) {
|
|
88
|
+
const [server, vkey] = argv.npc.split('@');
|
|
89
|
+
execa('docker', ['run', '--rm', 'ffdfgdfg/npc:v0.26.9', `-server=${server}`, `-vkey=${vkey}`, '-type=tcp'], {
|
|
90
|
+
cwd: process.cwd(),
|
|
91
|
+
stdio: 'inherit'
|
|
92
|
+
});
|
|
117
93
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
94
|
+
await TemplateUtil.init(process.cwd());
|
|
95
|
+
const xsignoreFile = path.join(process.cwd(), '.xsignore');
|
|
96
|
+
const xsignoreContent = (await fs.pathExists(xsignoreFile)) ? (await fs.readFile(xsignoreFile, 'utf-8')).trim().split(/[\r\n]+/g).filter(v => v && !v.startsWith('#')) : [];
|
|
97
|
+
const watcher = chokidar.watch(['src', '.env', '.env*'], {
|
|
98
|
+
cwd: process.cwd(),
|
|
99
|
+
ignored: ['**/*.test.*', ...xsignoreContent]
|
|
100
|
+
});
|
|
101
|
+
watcher.on('all', debounce(async () => {
|
|
102
|
+
const envFiles = EnvUtil.getFile(process.env.NODE_ENV, channel);
|
|
103
|
+
await EnvUtil.importFile({
|
|
104
|
+
cwd: process.cwd(),
|
|
105
|
+
file: envFiles
|
|
106
|
+
});
|
|
107
|
+
EnvUtil.outputTypes({
|
|
108
|
+
cwd: process.cwd(),
|
|
109
|
+
file: envFiles,
|
|
110
|
+
outFile: 'env.d.ts'
|
|
111
|
+
});
|
|
112
|
+
generateManyIndex({
|
|
113
|
+
cwd: process.cwd(),
|
|
114
|
+
patterns: ['src/**/index.ts', 'node_modules/.x/*.ts', '!src/handlers/**/*', ...(argv.index || [])],
|
|
115
|
+
replaceFile: true,
|
|
116
|
+
onSuccess: filePath => {
|
|
117
|
+
console.log(`✔️ 索引文件已更新: ${filePath}`);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
if (lastRun) {
|
|
121
|
+
console.log('==== 重启服务中 ====');
|
|
122
|
+
lastRun.kill();
|
|
123
|
+
setTimeout(run, 0);
|
|
124
|
+
} else {
|
|
125
|
+
console.log('==== 启动服务中 ====');
|
|
126
|
+
run();
|
|
127
|
+
}
|
|
128
|
+
}, 30));
|
|
126
129
|
}
|
|
127
|
-
}
|
|
130
|
+
});
|
|
128
131
|
}).command('build', '构建', _ => _.positional('external', {
|
|
129
132
|
alias: 'e',
|
|
130
133
|
describe: '不应该被打的包',
|
|
@@ -205,16 +208,19 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
205
208
|
describe: '渠道',
|
|
206
209
|
type: 'string'
|
|
207
210
|
}), async argv => {
|
|
208
|
-
|
|
209
|
-
argv.channel = await EnvUtil.chooseChannel(process.cwd());
|
|
210
|
-
}
|
|
211
|
-
process.env.NODE_ENV = 'production';
|
|
212
|
-
const envFiles = EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
|
|
213
|
-
await EnvUtil.importFile({
|
|
211
|
+
await EnvUtil.withChannel({
|
|
214
212
|
cwd: process.cwd(),
|
|
215
|
-
|
|
213
|
+
channel: argv.channel,
|
|
214
|
+
cb: async channel => {
|
|
215
|
+
process.env.NODE_ENV = 'production';
|
|
216
|
+
const envFiles = EnvUtil.getFile(process.env.NODE_ENV, channel);
|
|
217
|
+
await EnvUtil.importFile({
|
|
218
|
+
cwd: process.cwd(),
|
|
219
|
+
file: envFiles
|
|
220
|
+
});
|
|
221
|
+
await new ApiGenerator().start();
|
|
222
|
+
}
|
|
216
223
|
});
|
|
217
|
-
await new ApiGenerator().start();
|
|
218
224
|
}).command('prisma', 'prisma 代理,主要为了注入环境变量', _ => _.positional('production', {
|
|
219
225
|
alias: 'p',
|
|
220
226
|
describe: '是否生产模式',
|
package/lib/exports.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './core/http_redirect';
|
|
|
14
14
|
export * from './core/server';
|
|
15
15
|
export * from './core/types';
|
|
16
16
|
export * from './plugins/base';
|
|
17
|
+
export * from './plugins/compress';
|
|
17
18
|
export * from './plugins/cookie';
|
|
18
19
|
export * from './plugins/cors';
|
|
19
20
|
export * from './plugins/file_parser';
|
package/lib/exports.js
CHANGED
|
@@ -15,6 +15,7 @@ export * from "./core/http_redirect";
|
|
|
15
15
|
export * from "./core/server";
|
|
16
16
|
export * from "./core/types";
|
|
17
17
|
export * from "./plugins/base";
|
|
18
|
+
export * from "./plugins/compress";
|
|
18
19
|
export * from "./plugins/cookie";
|
|
19
20
|
export * from "./plugins/cors";
|
|
20
21
|
export * from "./plugins/file_parser";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FastifyCompressOptions } from '@fastify/compress';
|
|
2
|
+
import { FastifyInstance } from 'fastify';
|
|
3
|
+
import { BasePlugin } from './base';
|
|
4
|
+
export interface CompressPluginOptions extends FastifyCompressOptions {
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 响应压缩插件
|
|
8
|
+
*/
|
|
9
|
+
export declare class CompressPlugin implements BasePlugin {
|
|
10
|
+
private options?;
|
|
11
|
+
constructor(options?: CompressPluginOptions | undefined);
|
|
12
|
+
register(fastify: FastifyInstance<any, any, any, any, any>): void;
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayfong/x-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.80.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "lib/_cjs/index.js",
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"bin": {
|
|
10
10
|
"xs": "lib/_cjs/cli/cli.js"
|
|
11
11
|
},
|
|
12
|
-
"files": [
|
|
12
|
+
"files": [
|
|
13
|
+
"lib"
|
|
14
|
+
],
|
|
13
15
|
"scripts": {
|
|
14
16
|
"build": "haoma compile",
|
|
15
17
|
"build_test_pkg": "tyn build && rm -rf ./lib_test && mkdir -p ./lib_test && cp -r ./lib ./lib_test/lib && cp ./package.json ./lib_test/package.json && cd ./tests/app && tyn add file:../../lib_test",
|
|
@@ -19,6 +21,7 @@
|
|
|
19
21
|
"test_api_qiqi": "cd /Users/admin/Documents/jfWorks/qiqi-server && DEBUG=api tsx /Users/admin/Documents/jfWorks/x/packages/x-server/src/cli/cli.ts api"
|
|
20
22
|
},
|
|
21
23
|
"dependencies": {
|
|
24
|
+
"@fastify/compress": "^8.0.1",
|
|
22
25
|
"@fastify/cookie": "^9.4.0",
|
|
23
26
|
"@fastify/cors": "^8.3.0",
|
|
24
27
|
"@fastify/formbody": "^7.4.0",
|