@jayfong/x-server 2.118.1 → 3.0.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.
Files changed (290) hide show
  1. package/lib/_virtual/_rolldown/runtime.mjs +4 -0
  2. package/lib/cli/api_generator.d.mts +74 -0
  3. package/lib/cli/api_generator.mjs +310 -0
  4. package/lib/cli/build_util.d.mts +17 -0
  5. package/lib/cli/build_util.mjs +156 -0
  6. package/lib/cli/cli.d.mts +1 -0
  7. package/lib/cli/cli.mjs +355 -0
  8. package/lib/cli/css_register.d.mts +1 -0
  9. package/lib/cli/css_register.mjs +7 -0
  10. package/lib/cli/deploy_util.d.mts +23 -0
  11. package/lib/cli/deploy_util.mjs +70 -0
  12. package/lib/cli/dev_util.d.mts +7 -0
  13. package/lib/cli/dev_util.mjs +25 -0
  14. package/lib/cli/env_util.d.mts +45 -0
  15. package/lib/cli/env_util.mjs +207 -0
  16. package/lib/cli/esbuild_register.d.mts +1 -0
  17. package/lib/cli/esbuild_register.mjs +7 -0
  18. package/lib/cli/template_util.d.mts +18 -0
  19. package/lib/cli/template_util.mjs +85 -0
  20. package/lib/cli/templates/crons.ts +1 -1
  21. package/lib/cli/templates/handlers.ts +1 -1
  22. package/lib/cli/templates/hooks.ts +1 -1
  23. package/lib/cli/templates/models.ts +7 -7
  24. package/lib/cli/templates/package.json +11 -1
  25. package/lib/cli/templates/routes.ts +2 -1
  26. package/lib/core/ctx_storage.d.mts +3 -0
  27. package/lib/core/ctx_storage.mjs +4 -0
  28. package/lib/core/define_bus.d.mts +37 -0
  29. package/lib/core/define_bus.mjs +12 -0
  30. package/lib/core/{define_cron.d.ts → define_cron.d.mts} +2 -2
  31. package/lib/core/define_cron.mjs +11 -0
  32. package/lib/core/{define_handler.d.ts → define_handler.d.mts} +19 -19
  33. package/lib/core/define_handler.mjs +44 -0
  34. package/lib/core/define_hook.d.mts +2 -0
  35. package/lib/core/define_hook.mjs +6 -0
  36. package/lib/core/define_server.d.mts +3 -0
  37. package/lib/core/define_server.mjs +8 -0
  38. package/lib/core/{define_task.d.ts → define_task.d.mts} +2 -2
  39. package/lib/core/define_task.mjs +102 -0
  40. package/lib/core/get_handler_url.d.mts +2 -0
  41. package/lib/core/get_handler_url.mjs +7 -0
  42. package/lib/core/handler.d.mts +16 -0
  43. package/lib/core/handler.mjs +132 -0
  44. package/lib/core/http_error.d.mts +2 -0
  45. package/lib/core/http_error.mjs +1 -0
  46. package/lib/core/http_header.d.mts +856 -0
  47. package/lib/core/http_header.mjs +860 -0
  48. package/lib/core/http_method.d.mts +3 -0
  49. package/lib/core/http_method.mjs +10 -0
  50. package/lib/core/http_redirect.d.mts +5 -0
  51. package/lib/core/http_redirect.mjs +10 -0
  52. package/lib/core/server.d.mts +20 -0
  53. package/lib/core/server.mjs +186 -0
  54. package/lib/core/types.d.mts +256 -0
  55. package/lib/exports.d.mts +46 -0
  56. package/lib/exports.mjs +46 -0
  57. package/lib/index.d.mts +48 -0
  58. package/lib/index.mjs +45 -0
  59. package/lib/plugins/base.d.mts +4 -0
  60. package/lib/plugins/compress.d.mts +12 -0
  61. package/lib/plugins/compress.mjs +15 -0
  62. package/lib/plugins/cookie.d.mts +12 -0
  63. package/lib/plugins/cookie.mjs +15 -0
  64. package/lib/plugins/cors.d.mts +22 -0
  65. package/lib/plugins/cors.mjs +34 -0
  66. package/lib/plugins/file_parser.d.mts +15 -0
  67. package/lib/plugins/file_parser.mjs +24 -0
  68. package/lib/plugins/form_body_parser.d.mts +12 -0
  69. package/lib/plugins/form_body_parser.mjs +15 -0
  70. package/lib/plugins/ws_parser.d.mts +12 -0
  71. package/lib/plugins/ws_parser.mjs +15 -0
  72. package/lib/plugins/xml_parser.d.mts +19 -0
  73. package/lib/plugins/xml_parser.mjs +40 -0
  74. package/lib/services/ai.d.mts +31 -0
  75. package/lib/services/ai.mjs +44 -0
  76. package/lib/services/base.d.mts +4 -0
  77. package/lib/services/base.mjs +1 -0
  78. package/lib/services/cache.d.mts +165 -0
  79. package/lib/services/cache.mjs +323 -0
  80. package/lib/services/captcha.d.mts +65 -0
  81. package/lib/services/captcha.mjs +61 -0
  82. package/lib/services/{crypto.js → crypto.d.mts} +19 -78
  83. package/lib/services/crypto.mjs +141 -0
  84. package/lib/services/db_value.d.mts +60 -0
  85. package/lib/services/db_value.mjs +64 -0
  86. package/lib/services/dingtalk.d.mts +39 -0
  87. package/lib/services/dingtalk.mjs +44 -0
  88. package/lib/services/dispose.d.mts +17 -0
  89. package/lib/services/dispose.mjs +18 -0
  90. package/lib/services/emoji.d.mts +10 -0
  91. package/lib/services/emoji.mjs +2025 -0
  92. package/lib/services/file_store.d.mts +49 -0
  93. package/lib/services/file_store.mjs +58 -0
  94. package/lib/services/html.d.mts +11 -0
  95. package/lib/services/html.mjs +12 -0
  96. package/lib/services/jwt.d.mts +33 -0
  97. package/lib/services/jwt.mjs +42 -0
  98. package/lib/services/log.d.mts +37 -0
  99. package/lib/services/log.mjs +99 -0
  100. package/lib/services/mail.d.mts +22 -0
  101. package/lib/services/mail.mjs +28 -0
  102. package/lib/services/pay.d.mts +123 -0
  103. package/lib/services/pay.mjs +157 -0
  104. package/lib/services/random.d.mts +27 -0
  105. package/lib/services/random.mjs +42 -0
  106. package/lib/services/rate_limit.d.mts +37 -0
  107. package/lib/services/rate_limit.mjs +40 -0
  108. package/lib/services/redis.d.mts +11 -0
  109. package/lib/services/redis.mjs +6 -0
  110. package/lib/services/sensitive_words.d.mts +29 -0
  111. package/lib/services/sensitive_words.mjs +37 -0
  112. package/lib/services/sms.d.mts +40 -0
  113. package/lib/services/sms.mjs +30238 -0
  114. package/lib/types/dto.d.mts +30 -0
  115. package/lib/types/dto.mjs +1 -0
  116. package/lib/x.d.mts +11 -0
  117. package/lib/x.mjs +21 -0
  118. package/lib/x_init.d.mts +1 -0
  119. package/lib/x_init.mjs +10 -0
  120. package/package.json +99 -43
  121. package/lib/_cjs/cli/api_generator.js +0 -438
  122. package/lib/_cjs/cli/build_util.js +0 -243
  123. package/lib/_cjs/cli/cli.js +0 -378
  124. package/lib/_cjs/cli/css_register.js +0 -7
  125. package/lib/_cjs/cli/deploy_util.js +0 -76
  126. package/lib/_cjs/cli/dev_util.js +0 -25
  127. package/lib/_cjs/cli/env_util.js +0 -252
  128. package/lib/_cjs/cli/esbuild_register.js +0 -7
  129. package/lib/_cjs/cli/template_util.js +0 -101
  130. package/lib/_cjs/cli/templates/crons.ts +0 -2
  131. package/lib/_cjs/cli/templates/handlers.ts +0 -3
  132. package/lib/_cjs/cli/templates/hooks.ts +0 -2
  133. package/lib/_cjs/cli/templates/models.ts +0 -123
  134. package/lib/_cjs/cli/templates/package.json +0 -3
  135. package/lib/_cjs/cli/templates/routes.ts +0 -68
  136. package/lib/_cjs/core/ctx_storage.js +0 -6
  137. package/lib/_cjs/core/define_bus.js +0 -31
  138. package/lib/_cjs/core/define_cron.js +0 -13
  139. package/lib/_cjs/core/define_handler.js +0 -56
  140. package/lib/_cjs/core/define_hook.js +0 -8
  141. package/lib/_cjs/core/define_server.js +0 -10
  142. package/lib/_cjs/core/define_task.js +0 -113
  143. package/lib/_cjs/core/get_handler_url.js +0 -11
  144. package/lib/_cjs/core/handler.js +0 -216
  145. package/lib/_cjs/core/http_error.js +0 -6
  146. package/lib/_cjs/core/http_header.js +0 -142
  147. package/lib/_cjs/core/http_method.js +0 -12
  148. package/lib/_cjs/core/http_redirect.js +0 -11
  149. package/lib/_cjs/core/server.js +0 -221
  150. package/lib/_cjs/core/types.js +0 -8
  151. package/lib/_cjs/exports.js +0 -273
  152. package/lib/_cjs/index.js +0 -15
  153. package/lib/_cjs/plugins/base.js +0 -3
  154. package/lib/_cjs/plugins/compress.js +0 -18
  155. package/lib/_cjs/plugins/cookie.js +0 -18
  156. package/lib/_cjs/plugins/cors.js +0 -38
  157. package/lib/_cjs/plugins/file_parser.js +0 -28
  158. package/lib/_cjs/plugins/form_body_parser.js +0 -18
  159. package/lib/_cjs/plugins/ws_parser.js +0 -18
  160. package/lib/_cjs/plugins/xml_parser.js +0 -48
  161. package/lib/_cjs/services/ai.js +0 -48
  162. package/lib/_cjs/services/base.js +0 -3
  163. package/lib/_cjs/services/cache.js +0 -400
  164. package/lib/_cjs/services/captcha.js +0 -78
  165. package/lib/_cjs/services/crypto.js +0 -175
  166. package/lib/_cjs/services/db_value.js +0 -77
  167. package/lib/_cjs/services/dingtalk.js +0 -51
  168. package/lib/_cjs/services/dispose.js +0 -23
  169. package/lib/_cjs/services/emoji.js +0 -2034
  170. package/lib/_cjs/services/file_store.js +0 -67
  171. package/lib/_cjs/services/html.js +0 -17
  172. package/lib/_cjs/services/jwt.js +0 -65
  173. package/lib/_cjs/services/log.js +0 -108
  174. package/lib/_cjs/services/mail.js +0 -31
  175. package/lib/_cjs/services/pay.js +0 -191
  176. package/lib/_cjs/services/random.js +0 -51
  177. package/lib/_cjs/services/rate_limit.js +0 -54
  178. package/lib/_cjs/services/redis.js +0 -12
  179. package/lib/_cjs/services/sensitive_words.js +0 -62
  180. package/lib/_cjs/services/sms.js +0 -84
  181. package/lib/_cjs/types/dto.js +0 -3
  182. package/lib/_cjs/x.js +0 -35
  183. package/lib/cli/api_generator.d.ts +0 -74
  184. package/lib/cli/api_generator.js +0 -432
  185. package/lib/cli/build_util.d.ts +0 -17
  186. package/lib/cli/build_util.js +0 -236
  187. package/lib/cli/cli.d.ts +0 -2
  188. package/lib/cli/cli.js +0 -374
  189. package/lib/cli/css_register.js +0 -5
  190. package/lib/cli/deploy_util.d.ts +0 -23
  191. package/lib/cli/deploy_util.js +0 -70
  192. package/lib/cli/dev_util.d.ts +0 -8
  193. package/lib/cli/dev_util.js +0 -19
  194. package/lib/cli/env_util.d.ts +0 -45
  195. package/lib/cli/env_util.js +0 -246
  196. package/lib/cli/esbuild_register.js +0 -5
  197. package/lib/cli/template_util.d.ts +0 -18
  198. package/lib/cli/template_util.js +0 -95
  199. package/lib/core/ctx_storage.d.ts +0 -3
  200. package/lib/core/ctx_storage.js +0 -2
  201. package/lib/core/define_bus.d.ts +0 -37
  202. package/lib/core/define_bus.js +0 -27
  203. package/lib/core/define_cron.js +0 -9
  204. package/lib/core/define_handler.js +0 -48
  205. package/lib/core/define_hook.d.ts +0 -2
  206. package/lib/core/define_hook.js +0 -4
  207. package/lib/core/define_server.d.ts +0 -3
  208. package/lib/core/define_server.js +0 -6
  209. package/lib/core/define_task.js +0 -107
  210. package/lib/core/get_handler_url.d.ts +0 -2
  211. package/lib/core/get_handler_url.js +0 -7
  212. package/lib/core/handler.d.ts +0 -16
  213. package/lib/core/handler.js +0 -209
  214. package/lib/core/http_error.d.ts +0 -2
  215. package/lib/core/http_error.js +0 -2
  216. package/lib/core/http_header.d.ts +0 -856
  217. package/lib/core/http_header.js +0 -139
  218. package/lib/core/http_method.d.ts +0 -3
  219. package/lib/core/http_method.js +0 -8
  220. package/lib/core/http_redirect.d.ts +0 -5
  221. package/lib/core/http_redirect.js +0 -6
  222. package/lib/core/server.d.ts +0 -20
  223. package/lib/core/server.js +0 -215
  224. package/lib/core/types.d.ts +0 -265
  225. package/lib/core/types.js +0 -4
  226. package/lib/exports.d.ts +0 -45
  227. package/lib/exports.js +0 -47
  228. package/lib/index.d.ts +0 -2
  229. package/lib/index.js +0 -3
  230. package/lib/plugins/base.d.ts +0 -4
  231. package/lib/plugins/base.js +0 -1
  232. package/lib/plugins/compress.d.ts +0 -13
  233. package/lib/plugins/compress.js +0 -12
  234. package/lib/plugins/cookie.d.ts +0 -13
  235. package/lib/plugins/cookie.js +0 -12
  236. package/lib/plugins/cors.d.ts +0 -22
  237. package/lib/plugins/cors.js +0 -33
  238. package/lib/plugins/file_parser.d.ts +0 -16
  239. package/lib/plugins/file_parser.js +0 -22
  240. package/lib/plugins/form_body_parser.d.ts +0 -13
  241. package/lib/plugins/form_body_parser.js +0 -12
  242. package/lib/plugins/ws_parser.d.ts +0 -13
  243. package/lib/plugins/ws_parser.js +0 -12
  244. package/lib/plugins/xml_parser.d.ts +0 -19
  245. package/lib/plugins/xml_parser.js +0 -43
  246. package/lib/services/ai.d.ts +0 -31
  247. package/lib/services/ai.js +0 -43
  248. package/lib/services/base.d.ts +0 -4
  249. package/lib/services/base.js +0 -1
  250. package/lib/services/cache.d.ts +0 -173
  251. package/lib/services/cache.js +0 -394
  252. package/lib/services/captcha.d.ts +0 -65
  253. package/lib/services/captcha.js +0 -72
  254. package/lib/services/crypto.d.ts +0 -110
  255. package/lib/services/db_value.d.ts +0 -60
  256. package/lib/services/db_value.js +0 -72
  257. package/lib/services/dingtalk.d.ts +0 -39
  258. package/lib/services/dingtalk.js +0 -45
  259. package/lib/services/dispose.d.ts +0 -17
  260. package/lib/services/dispose.js +0 -17
  261. package/lib/services/emoji.d.ts +0 -10
  262. package/lib/services/emoji.js +0 -2029
  263. package/lib/services/file_store.d.ts +0 -49
  264. package/lib/services/file_store.js +0 -61
  265. package/lib/services/html.d.ts +0 -11
  266. package/lib/services/html.js +0 -12
  267. package/lib/services/jwt.d.ts +0 -34
  268. package/lib/services/jwt.js +0 -59
  269. package/lib/services/log.d.ts +0 -37
  270. package/lib/services/log.js +0 -102
  271. package/lib/services/mail.d.ts +0 -23
  272. package/lib/services/mail.js +0 -25
  273. package/lib/services/pay.d.ts +0 -123
  274. package/lib/services/pay.js +0 -185
  275. package/lib/services/random.d.ts +0 -27
  276. package/lib/services/random.js +0 -45
  277. package/lib/services/rate_limit.d.ts +0 -37
  278. package/lib/services/rate_limit.js +0 -49
  279. package/lib/services/redis.d.ts +0 -12
  280. package/lib/services/redis.js +0 -7
  281. package/lib/services/sensitive_words.d.ts +0 -30
  282. package/lib/services/sensitive_words.js +0 -57
  283. package/lib/services/sms.d.ts +0 -40
  284. package/lib/services/sms.js +0 -78
  285. package/lib/types/dto.d.ts +0 -86
  286. package/lib/types/dto.js +0 -1
  287. package/lib/x.d.ts +0 -17
  288. package/lib/x.js +0 -30
  289. /package/lib/{cli/css_register.d.ts → core/types.mjs} +0 -0
  290. /package/lib/{cli/esbuild_register.d.ts → plugins/base.mjs} +0 -0
@@ -1,378 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
- var _nodePath = _interopRequireDefault(require("node:path"));
7
- var _chokidar = _interopRequireDefault(require("chokidar"));
8
- var _execa = _interopRequireDefault(require("execa"));
9
- var _fsExtra = _interopRequireDefault(require("fs-extra"));
10
- var _vscodeGenerateIndexStandalone = require("vscode-generate-index-standalone");
11
- var _vtils = _interopRequireWildcard(require("vtils"));
12
- var vtils = _vtils;
13
- var _yargs = _interopRequireDefault(require("yargs"));
14
- var _api_generator = require("./api_generator");
15
- var _build_util = require("./build_util");
16
- var _deploy_util = require("./deploy_util");
17
- var _dev_util = require("./dev_util");
18
- var _env_util = require("./env_util");
19
- var _template_util = require("./template_util");
20
- async function deploy(argv) {
21
- await _env_util.EnvUtil.withChannel({
22
- cwd: process.cwd(),
23
- channel: argv.channel,
24
- cb: async channel => {
25
- const deployEnvFiles = _env_util.EnvUtil.getFile('deploy', channel, true);
26
- const deployEnv = await _env_util.EnvUtil.parseFileAsMap({
27
- cwd: process.cwd(),
28
- file: deployEnvFiles,
29
- channel: channel
30
- });
31
- if (argv.type === 'env') {
32
- const appEnvFiles = _env_util.EnvUtil.getFile('production', channel);
33
- const appEnv = await _env_util.EnvUtil.parseFileAsMap({
34
- cwd: process.cwd(),
35
- file: appEnvFiles,
36
- channel: channel
37
- });
38
- await _deploy_util.DeployUtil.deployEnv({
39
- host: deployEnv.HOST,
40
- user: deployEnv.USER,
41
- key: deployEnv.KEY,
42
- pass: deployEnv.PASSWORD,
43
- token: appEnv.APP_TOKEN,
44
- port: appEnv.APP_PORT,
45
- env: appEnv
46
- });
47
- } else {
48
- await _deploy_util.DeployUtil.deploy({
49
- cwd: process.cwd(),
50
- host: deployEnv.HOST,
51
- user: deployEnv.USER,
52
- key: deployEnv.KEY,
53
- pass: deployEnv.PASSWORD,
54
- dir: deployEnv.DIR,
55
- cmd: deployEnv.CMD,
56
- channel: channel
57
- });
58
- }
59
- }
60
- });
61
- }
62
- _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
63
- alias: 'i',
64
- describe: '额外需要生成的索引文件',
65
- type: 'string',
66
- array: true
67
- }).positional('npc', {
68
- describe: 'npc 地址及密钥,格式:地址@密钥',
69
- type: 'string'
70
- }).positional('tsx', {
71
- describe: '使用 tsx 运行',
72
- type: 'boolean'
73
- }).positional('channel', {
74
- alias: 'h',
75
- describe: '渠道',
76
- type: 'string'
77
- }), async argv => {
78
- await _env_util.EnvUtil.withChannel({
79
- cwd: process.cwd(),
80
- channel: argv.channel,
81
- cb: async channel => {
82
- process.env.NODE_ENV = 'development';
83
- let lastRun;
84
- const run = () => {
85
- lastRun = _dev_util.DevUtil.runFile({
86
- file: 'src/main.ts',
87
- cwd: process.cwd(),
88
- runner: argv.tsx ? 'tsx' : 'esbuild-register'
89
- });
90
- };
91
- if (argv.npc) {
92
- const [server, vkey] = argv.npc.split('@');
93
- (0, _execa.default)('docker', ['run', '--rm', 'ffdfgdfg/npc:v0.26.9', `-server=${server}`, `-vkey=${vkey}`, '-type=tcp'], {
94
- cwd: process.cwd(),
95
- stdio: 'inherit'
96
- });
97
- }
98
- await _template_util.TemplateUtil.init(process.cwd());
99
- const xsignoreFile = _nodePath.default.join(process.cwd(), '.xsignore');
100
- const xsignoreContent = (await _fsExtra.default.pathExists(xsignoreFile)) ? (await _fsExtra.default.readFile(xsignoreFile, 'utf-8')).trim().split(/[\r\n]+/g).filter(v => v && !v.startsWith('#')) : [];
101
- const watcher = _chokidar.default.watch(['src', '.env', '.env*'], {
102
- cwd: process.cwd(),
103
- ignored: ['**/*.test.*', ...xsignoreContent]
104
- });
105
- watcher.on('all', (0, _vtils.debounce)(async () => {
106
- const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, channel);
107
- await _env_util.EnvUtil.importFile({
108
- cwd: process.cwd(),
109
- file: envFiles,
110
- channel: channel
111
- });
112
- _env_util.EnvUtil.outputTypes({
113
- cwd: process.cwd(),
114
- file: envFiles,
115
- outFile: 'env.d.ts',
116
- channel: channel
117
- });
118
- (0, _vscodeGenerateIndexStandalone.generateManyIndex)({
119
- cwd: process.cwd(),
120
- patterns: ['src/**/index.ts', 'node_modules/.x/*.ts', '!src/handlers/**/*', ...(argv.index || [])],
121
- replaceFile: true,
122
- onSuccess: filePath => {
123
- console.log(`✔️ 索引文件已更新: ${filePath}`);
124
- }
125
- });
126
- if (lastRun) {
127
- console.log('==== 重启服务中 ====');
128
- lastRun.kill();
129
- setTimeout(run, 0);
130
- } else {
131
- console.log('==== 启动服务中 ====');
132
- run();
133
- }
134
- }, 30));
135
- }
136
- });
137
- }).command('build', '构建', _ => _.positional('external', {
138
- alias: 'e',
139
- describe: '不应该被打的包',
140
- type: 'string',
141
- array: true
142
- }).positional('minify', {
143
- alias: 'm',
144
- describe: '是否压缩',
145
- type: 'boolean',
146
- default: true
147
- }).positional('local-install', {
148
- describe: '是否本地安装外部依赖',
149
- type: 'boolean',
150
- default: true
151
- }).positional('channel', {
152
- alias: 'h',
153
- describe: '渠道',
154
- type: 'string'
155
- }).positional('deploy', {
156
- alias: 'd',
157
- describe: '构建完是否部署',
158
- type: 'boolean',
159
- default: false
160
- }).positional('concurrency', {
161
- alias: 'c',
162
- describe: '同时构建的数量',
163
- type: 'number',
164
- default: 1
165
- }).positional('exclude', {
166
- alias: 'x',
167
- describe: '构建时排除的文件',
168
- type: 'string',
169
- array: true
170
- }).positional('empty-dist-dir', {
171
- describe: '是否清空构建目录',
172
- type: 'boolean',
173
- default: true
174
- }), async argv => {
175
- await _env_util.EnvUtil.withChannel({
176
- cwd: process.cwd(),
177
- channel: argv.channel,
178
- concurrency: argv.concurrency,
179
- cb: async channel => {
180
- process.env.NODE_ENV = 'production';
181
- const externals = (0, _vtils.castArray)(argv.external || []).flatMap(item => item.split(',')).filter(Boolean);
182
- const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, channel);
183
- const envMap = await _env_util.EnvUtil.parseFileAsMap({
184
- cwd: process.cwd(),
185
- file: envFiles,
186
- channel: channel
187
- });
188
- envMap.NODE_ENV = 'production';
189
- const deployEnvFiles = _env_util.EnvUtil.getFile('deploy', channel, true);
190
- const deployEnv = await _env_util.EnvUtil.parseFileAsMap({
191
- cwd: process.cwd(),
192
- file: deployEnvFiles,
193
- channel: channel
194
- });
195
- await _template_util.TemplateUtil.init(process.cwd());
196
- await (0, _vscodeGenerateIndexStandalone.generateManyIndex)({
197
- cwd: process.cwd(),
198
- patterns: ['src/.x/*.ts'],
199
- replaceFile: true,
200
- onSuccess: filePath => {
201
- console.log(`✔️ 索引文件已更新: ${filePath}`);
202
- }
203
- });
204
- await _build_util.BuildUtil.build({
205
- appId: envMap.APP_ID,
206
- cwd: process.cwd(),
207
- external: externals,
208
- inlineEnvs: envMap,
209
- minify: argv.minify,
210
- noInstall: argv['local-install'] === false,
211
- channel: channel,
212
- excludeFiles: (argv.exclude ? (0, _vtils.castArray)(argv.exclude) : []).map(item => {
213
- return _vtils.StringTemplate.render(item, {
214
- ...envMap,
215
- _: vtils,
216
- __: vtils.escapeRegExp
217
- }, {
218
- code: true,
219
- onlyCode: true
220
- });
221
- }),
222
- noEmptyDistDir: argv['empty-dist-dir'] === false,
223
- pm2MaxMemoryRestart: deployEnv.MEMORY,
224
- pm2CronRestart: deployEnv.CRON,
225
- pm2NodeArgs: deployEnv.NODE_ARGS
226
- });
227
- console.log('构建成功');
228
- if (argv.deploy) {
229
- await deploy({
230
- ...argv,
231
- channel
232
- });
233
- }
234
- }
235
- });
236
- }).command('api', '生成 API', _ => _.positional('channel', {
237
- alias: 'h',
238
- describe: '渠道',
239
- type: 'string'
240
- }).positional('include', {
241
- alias: 'i',
242
- describe: '包括',
243
- type: 'string',
244
- array: true
245
- }).positional('exclude', {
246
- alias: 'e',
247
- describe: '排除',
248
- type: 'string',
249
- array: true
250
- }).positional('name', {
251
- alias: 'n',
252
- describe: '名称',
253
- type: 'string'
254
- }), async argv => {
255
- await _env_util.EnvUtil.withChannel({
256
- cwd: process.cwd(),
257
- channel: argv.channel,
258
- cb: async channel => {
259
- process.env.NODE_ENV = 'production';
260
- const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, channel);
261
- await _env_util.EnvUtil.importFile({
262
- cwd: process.cwd(),
263
- file: envFiles,
264
- channel: channel
265
- });
266
- await new _api_generator.ApiGenerator({
267
- cwd: process.cwd(),
268
- include: argv.include && (0, _vtils.castArray)(argv.include).flatMap(v => v.split(',')),
269
- exclude: argv.exclude && (0, _vtils.castArray)(argv.exclude).flatMap(v => v.split(',')),
270
- name: argv.name
271
- }).start();
272
- }
273
- });
274
- }).command('prisma', 'prisma 代理,主要为了注入环境变量', _ => _.positional('production', {
275
- alias: 'p',
276
- describe: '是否生产模式',
277
- type: 'boolean',
278
- default: false
279
- }).positional('channel', {
280
- alias: 'h',
281
- describe: '渠道',
282
- type: 'string'
283
- }), async argv => {
284
- await _env_util.EnvUtil.withChannel({
285
- cwd: process.cwd(),
286
- channel: argv.channel,
287
- cb: async channel => {
288
- process.env.NODE_ENV = argv.production ? 'production' : 'development';
289
- const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, channel);
290
- await _env_util.EnvUtil.importFile({
291
- cwd: process.cwd(),
292
- file: envFiles,
293
- channel: channel
294
- });
295
- // 之所以能成功是因为 Prisma 用的 dotenv 默认不会覆盖已经设置的环境变量
296
- // https://github.com/motdotla/dotenv#override
297
- process.env.DATABASE_URL = process.env.DATABASE_ACTION_URL || process.env.DATABASE_URL;
298
-
299
- // 多 schema 文件兼容
300
- // https://www.prisma.io/docs/orm/prisma-schema/overview/location#how-to-use-existing-prisma-cli-commands-with-multiple-prisma-schema-files
301
- const schemaDir = _nodePath.default.join(process.cwd(), 'src/db/schema');
302
- const isMultipleFiles = await _fsExtra.default.pathExists(schemaDir);
303
- const schemaArg = isMultipleFiles ? 'src/db' : 'src/db/schema.prisma';
304
- const prismaArgs = argv._.slice(1);
305
- await (0, _execa.default)('tnpx', ['prisma', ...prismaArgs, '--schema', schemaArg], {
306
- cwd: process.cwd(),
307
- stdio: 'inherit'
308
- });
309
- if (!argv.production && prismaArgs[0] === 'generate') {
310
- await _template_util.TemplateUtil.initModels(process.cwd());
311
- }
312
- }
313
- });
314
- }).command('run [script]', '执行脚本', _ => _.positional('script', {
315
- describe: '脚本',
316
- type: 'string'
317
- }).positional('production', {
318
- alias: 'p',
319
- describe: '是否生产模式',
320
- type: 'boolean',
321
- default: false
322
- }).positional('channel', {
323
- alias: 'h',
324
- describe: '渠道',
325
- type: 'string'
326
- }).positional('tsx', {
327
- describe: '使用 tsx 运行',
328
- type: 'boolean'
329
- }), async argv => {
330
- await _env_util.EnvUtil.withChannel({
331
- cwd: process.cwd(),
332
- channel: argv.channel,
333
- cb: async channel => {
334
- process.env.NODE_ENV = argv.production ? 'production' : 'development';
335
- const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, channel);
336
- await _env_util.EnvUtil.importFile({
337
- cwd: process.cwd(),
338
- file: envFiles,
339
- channel: channel
340
- });
341
- process.env.DATABASE_URL = process.env.DATABASE_ACTION_URL || process.env.DATABASE_URL;
342
- if (!argv.script) {
343
- await (0, _execa.default)('tnpx', ['select-run'], {
344
- cwd: process.cwd(),
345
- stdio: 'inherit'
346
- });
347
- } else {
348
- await _dev_util.DevUtil.runFile({
349
- file: argv.script,
350
- cwd: process.cwd(),
351
- runner: argv.tsx ? 'tsx' : 'esbuild-register'
352
- });
353
- }
354
- }
355
- });
356
- }).command('deploy [type]', '部署', _ => _.positional('type', {
357
- describe: '类型',
358
- type: 'string',
359
- choices: ['env']
360
- }).positional('channel', {
361
- alias: 'h',
362
- describe: '渠道',
363
- type: 'string'
364
- }), deploy).command('get-channel [file]', '获取渠道', _ => _.positional('file', {
365
- describe: '写入文件',
366
- type: 'string'
367
- }), async argv => {
368
- await _env_util.EnvUtil.withChannel({
369
- cwd: process.cwd(),
370
- channel: '_',
371
- cb: async channel => {
372
- if (channel && argv.file) {
373
- await _fsExtra.default.writeFile(_nodePath.default.join(process.cwd(), argv.file), channel);
374
- }
375
- console.log(channel || '');
376
- }
377
- });
378
- }).parse();
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- var _pirates = require("pirates");
4
- (0, _pirates.addHook)(() => 'module.exports = {};', {
5
- exts: ['.css'],
6
- ignoreNodeModules: false
7
- });
@@ -1,76 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- exports.__esModule = true;
5
- exports.DeployUtil = void 0;
6
- var _nodePath = _interopRequireDefault(require("node:path"));
7
- var _fsExtra = _interopRequireDefault(require("fs-extra"));
8
- var _nodeSsh = require("node-ssh");
9
- var _vtils = require("vtils");
10
- class DeployUtil {
11
- static async deploy(options) {
12
- const pkgContent = await _fsExtra.default.readJson(_nodePath.default.join(options.cwd, 'package.json'));
13
- const appFile = _nodePath.default.join(options.cwd, `temp${options.channel ? `/${options.channel}` : ''}/app.${pkgContent.version}.tgz`);
14
- if (!(await _fsExtra.default.pathExists(appFile))) {
15
- throw new Error('请先构建');
16
- }
17
- const ssh = new _nodeSsh.NodeSSH();
18
- await ssh.connect({
19
- host: options.host,
20
- username: options.user,
21
- privateKey: options.key,
22
- password: options.pass
23
- });
24
- const appName = pkgContent.name;
25
- const appDir = `./${appName}`;
26
- await ssh.execCommand((0, _vtils.dedent)`
27
- set -ex
28
- mkdir -p ./app_files/${appName}/${options.channel || 'dist'}
29
- mkdir -p ${appDir}
30
- `, {
31
- cwd: options.dir,
32
- onStdout: buf => console.log(buf.toString()),
33
- onStderr: buf => console.log(buf.toString())
34
- });
35
- const remoteAppFile = `${options.dir}/app_files/${appName}/${options.channel || 'dist'}/${_nodePath.default.basename(appFile)}`;
36
- await ssh.putFile(appFile, remoteAppFile);
37
- await ssh.execCommand((0, _vtils.dedent)`
38
- set -ex
39
- tar -zxf ${remoteAppFile} -C ${appDir}
40
- cd "${appDir}/${options.channel || 'dist'}"
41
- [ -f no_install.lock ] && yarn_disable_self_update_check=true tyn
42
- ${options.cmd || ''}
43
- pm2 startOrReload pm2.config.js
44
- `, {
45
- cwd: options.dir,
46
- onStdout: buf => console.log(buf.toString()),
47
- onStderr: buf => console.log(buf.toString())
48
- });
49
- ssh.dispose();
50
- }
51
- static async deployEnv(options) {
52
- const ssh = new _nodeSsh.NodeSSH();
53
- await ssh.connect({
54
- host: options.host,
55
- username: options.user,
56
- privateKey: options.key,
57
- password: options.pass
58
- });
59
- await ssh.execCommand((0, _vtils.dedent)`
60
- set -ex
61
- curl --silent --header "Content-Type: application/json" \\
62
- --request "POST" \\
63
- --data ${JSON.stringify(JSON.stringify({
64
- token: options.token,
65
- type: 'updateEnv',
66
- data: options.env
67
- }))} \\
68
- "http://localhost:${options.port}/$"
69
- `, {
70
- onStdout: buf => console.log(buf.toString()),
71
- onStderr: buf => console.log(buf.toString())
72
- });
73
- ssh.dispose();
74
- }
75
- }
76
- exports.DeployUtil = DeployUtil;
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- exports.__esModule = true;
5
- exports.DevUtil = void 0;
6
- var _nodeFs = _interopRequireDefault(require("node:fs"));
7
- var _execa = _interopRequireDefault(require("execa"));
8
- var _vtils = require("vtils");
9
- class DevUtil {
10
- static runFile(options) {
11
- return options.runner === 'tsx' ? (0, _execa.default)('node', ['-r', require.resolve("./css_register"), (0, _vtils.ii)(() => {
12
- const tsxPkgFile = require.resolve('tsx/package.json');
13
- const tsxJsFile = tsxPkgFile.replace('/package.json', '/dist/cli.js');
14
- const tsxCjsFile = tsxPkgFile.replace('/package.json', '/dist/cli.cjs');
15
- return _nodeFs.default.existsSync(tsxCjsFile) ? tsxCjsFile : tsxJsFile;
16
- }), options.file], {
17
- cwd: options.cwd,
18
- stdio: 'inherit'
19
- }) : (0, _execa.default)('node', ['-r', require.resolve("./esbuild_register"), '-r', require.resolve("./css_register"), options.file], {
20
- cwd: options.cwd,
21
- stdio: 'inherit'
22
- });
23
- }
24
- }
25
- exports.DevUtil = DevUtil;