phecda-server 5.1.0 → 5.2.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 (176) hide show
  1. package/README.md +10 -10
  2. package/assets/ps.json +25 -0
  3. package/{bin → assets}/schema.json +55 -55
  4. package/assets/tsconfig.json +21 -0
  5. package/bin/cli.mjs +150 -189
  6. package/dist/{chunk-6UQYEBAN.js → chunk-5BVUCNMA.js} +19 -20
  7. package/dist/{chunk-QG4X6H5Y.js → chunk-BSE2DSDK.js} +121 -124
  8. package/dist/{chunk-OTHER3YM.mjs → chunk-CKQW3FDK.mjs} +4 -5
  9. package/dist/{chunk-6W7CGOZC.mjs → chunk-JE6BBDXW.mjs} +64 -67
  10. package/dist/{chunk-5DOVDDO7.mjs → chunk-V3WIKOP3.mjs} +11 -6
  11. package/dist/{chunk-H4N6SHNG.mjs → chunk-VLV3AO3H.mjs} +0 -1
  12. package/dist/{chunk-GHOKWS5V.js → chunk-VMLHTEW3.js} +48 -43
  13. package/dist/{chunk-Z4YJHEXT.js → chunk-ZP7HNASU.js} +0 -1
  14. package/dist/core-7f6d2be6.d.ts +27 -0
  15. package/dist/{helper-fcbf6aa8.d.ts → helper-49c7213c.d.ts} +1 -1
  16. package/dist/{helper-867a598d.d.ts → helper-5d755442.d.ts} +1 -1
  17. package/dist/helper.d.ts +25 -0
  18. package/dist/helper.js +21 -0
  19. package/dist/helper.mjs +21 -0
  20. package/dist/index.d.ts +5 -25
  21. package/dist/index.js +39 -58
  22. package/dist/index.mjs +6 -25
  23. package/dist/rpc/bullmq/index.d.ts +3 -2
  24. package/dist/rpc/bullmq/index.js +12 -13
  25. package/dist/rpc/bullmq/index.mjs +2 -3
  26. package/dist/rpc/kafka/index.d.ts +3 -2
  27. package/dist/rpc/kafka/index.js +10 -11
  28. package/dist/rpc/kafka/index.mjs +2 -3
  29. package/dist/rpc/nats/index.d.ts +3 -2
  30. package/dist/rpc/nats/index.js +11 -12
  31. package/dist/rpc/nats/index.mjs +2 -3
  32. package/dist/rpc/rabbitmq/index.d.ts +3 -2
  33. package/dist/rpc/rabbitmq/index.js +13 -14
  34. package/dist/rpc/rabbitmq/index.mjs +2 -3
  35. package/dist/rpc/redis/index.d.ts +3 -2
  36. package/dist/rpc/redis/index.js +11 -12
  37. package/dist/rpc/redis/index.mjs +2 -3
  38. package/dist/server/elysia/index.d.ts +3 -2
  39. package/dist/server/elysia/index.js +20 -21
  40. package/dist/server/elysia/index.mjs +3 -4
  41. package/dist/server/express/index.d.ts +3 -2
  42. package/dist/server/express/index.js +18 -19
  43. package/dist/server/express/index.mjs +2 -3
  44. package/dist/server/fastify/index.d.ts +3 -2
  45. package/dist/server/fastify/index.js +19 -20
  46. package/dist/server/fastify/index.mjs +3 -4
  47. package/dist/server/h3/index.d.ts +3 -2
  48. package/dist/server/h3/index.js +16 -17
  49. package/dist/server/h3/index.mjs +2 -3
  50. package/dist/server/hono/index.d.ts +3 -2
  51. package/dist/server/hono/index.js +17 -18
  52. package/dist/server/hono/index.mjs +2 -3
  53. package/dist/server/hyper-express/index.d.ts +3 -2
  54. package/dist/server/hyper-express/index.js +17 -18
  55. package/dist/server/hyper-express/index.mjs +2 -3
  56. package/dist/server/koa/index.d.ts +3 -2
  57. package/dist/server/koa/index.js +18 -19
  58. package/dist/server/koa/index.mjs +2 -3
  59. package/dist/test.d.ts +2 -1
  60. package/dist/test.js +6 -7
  61. package/dist/test.mjs +2 -3
  62. package/dist/{core-fd134ffa.d.ts → types-81be0ba3.d.ts} +2 -24
  63. package/package.json +62 -54
  64. package/register/index.mjs +40 -40
  65. package/register/loader.mjs +367 -341
  66. package/register/utils.mjs +56 -81
  67. package/dist/chunk-423JPSEB.js +0 -253
  68. package/dist/chunk-423JPSEB.js.map +0 -1
  69. package/dist/chunk-4R55T3HG.js +0 -253
  70. package/dist/chunk-4R55T3HG.js.map +0 -1
  71. package/dist/chunk-4YVAW3L4.mjs +0 -76
  72. package/dist/chunk-4YVAW3L4.mjs.map +0 -1
  73. package/dist/chunk-5DOVDDO7.mjs.map +0 -1
  74. package/dist/chunk-5WQ2SMIK.js +0 -295
  75. package/dist/chunk-5WQ2SMIK.js.map +0 -1
  76. package/dist/chunk-6MQP6OHU.mjs +0 -295
  77. package/dist/chunk-6MQP6OHU.mjs.map +0 -1
  78. package/dist/chunk-6Q2PCC3A.mjs +0 -295
  79. package/dist/chunk-6Q2PCC3A.mjs.map +0 -1
  80. package/dist/chunk-6UQYEBAN.js.map +0 -1
  81. package/dist/chunk-6W7CGOZC.mjs.map +0 -1
  82. package/dist/chunk-7Y37NSBM.js +0 -88
  83. package/dist/chunk-7Y37NSBM.js.map +0 -1
  84. package/dist/chunk-BQBSVGMG.mjs +0 -253
  85. package/dist/chunk-BQBSVGMG.mjs.map +0 -1
  86. package/dist/chunk-BZP6GKM6.mjs +0 -565
  87. package/dist/chunk-BZP6GKM6.mjs.map +0 -1
  88. package/dist/chunk-C5JAHCS2.mjs +0 -88
  89. package/dist/chunk-C5JAHCS2.mjs.map +0 -1
  90. package/dist/chunk-DTBKDALR.mjs +0 -295
  91. package/dist/chunk-DTBKDALR.mjs.map +0 -1
  92. package/dist/chunk-GHOKWS5V.js.map +0 -1
  93. package/dist/chunk-H4N6SHNG.mjs.map +0 -1
  94. package/dist/chunk-ICYHM4UM.js +0 -565
  95. package/dist/chunk-ICYHM4UM.js.map +0 -1
  96. package/dist/chunk-LOLXPM4J.mjs +0 -529
  97. package/dist/chunk-LOLXPM4J.mjs.map +0 -1
  98. package/dist/chunk-MSS6A2TU.js +0 -585
  99. package/dist/chunk-MSS6A2TU.js.map +0 -1
  100. package/dist/chunk-NEM3FY7C.mjs +0 -537
  101. package/dist/chunk-NEM3FY7C.mjs.map +0 -1
  102. package/dist/chunk-OTHER3YM.mjs.map +0 -1
  103. package/dist/chunk-Q2FYFIEY.js +0 -295
  104. package/dist/chunk-Q2FYFIEY.js.map +0 -1
  105. package/dist/chunk-QG4X6H5Y.js.map +0 -1
  106. package/dist/chunk-QIEZ6YTG.mjs +0 -295
  107. package/dist/chunk-QIEZ6YTG.mjs.map +0 -1
  108. package/dist/chunk-QOAKHCM7.js +0 -295
  109. package/dist/chunk-QOAKHCM7.js.map +0 -1
  110. package/dist/chunk-QVUD6L5X.js +0 -565
  111. package/dist/chunk-QVUD6L5X.js.map +0 -1
  112. package/dist/chunk-RGLTGKAU.js +0 -537
  113. package/dist/chunk-RGLTGKAU.js.map +0 -1
  114. package/dist/chunk-SHRK3TVB.js +0 -295
  115. package/dist/chunk-SHRK3TVB.js.map +0 -1
  116. package/dist/chunk-TCH6S42Z.js +0 -529
  117. package/dist/chunk-TCH6S42Z.js.map +0 -1
  118. package/dist/chunk-UCGRFVHC.mjs +0 -253
  119. package/dist/chunk-UCGRFVHC.mjs.map +0 -1
  120. package/dist/chunk-VOISXWVF.mjs +0 -295
  121. package/dist/chunk-VOISXWVF.mjs.map +0 -1
  122. package/dist/chunk-W6BC5INO.mjs +0 -295
  123. package/dist/chunk-W6BC5INO.mjs.map +0 -1
  124. package/dist/chunk-X5WQRO4R.js +0 -295
  125. package/dist/chunk-X5WQRO4R.js.map +0 -1
  126. package/dist/chunk-XDMCVVD3.mjs +0 -585
  127. package/dist/chunk-XDMCVVD3.mjs.map +0 -1
  128. package/dist/chunk-XNTMYLK6.js +0 -76
  129. package/dist/chunk-XNTMYLK6.js.map +0 -1
  130. package/dist/chunk-Y6LI4FDO.js +0 -537
  131. package/dist/chunk-Y6LI4FDO.js.map +0 -1
  132. package/dist/chunk-YZ2AQ6IL.mjs +0 -537
  133. package/dist/chunk-YZ2AQ6IL.mjs.map +0 -1
  134. package/dist/chunk-Z4YJHEXT.js.map +0 -1
  135. package/dist/chunk-ZE336SKZ.js +0 -295
  136. package/dist/chunk-ZE336SKZ.js.map +0 -1
  137. package/dist/chunk-ZJD235TO.mjs +0 -565
  138. package/dist/chunk-ZJD235TO.mjs.map +0 -1
  139. package/dist/core-39f27fe8.d.ts +0 -131
  140. package/dist/core-930ea883.d.ts +0 -131
  141. package/dist/core-eb646fe5.d.ts +0 -139
  142. package/dist/helper-06d25b37.d.ts +0 -19
  143. package/dist/helper-48454c0b.d.ts +0 -20
  144. package/dist/helper-6133f78f.d.ts +0 -18
  145. package/dist/helper-73e8d2f0.d.ts +0 -18
  146. package/dist/helper-88b19c66.d.ts +0 -12
  147. package/dist/helper-9e206c66.d.ts +0 -12
  148. package/dist/helper-f29f082f.d.ts +0 -19
  149. package/dist/index.js.map +0 -1
  150. package/dist/index.mjs.map +0 -1
  151. package/dist/rpc/bullmq/index.js.map +0 -1
  152. package/dist/rpc/bullmq/index.mjs.map +0 -1
  153. package/dist/rpc/kafka/index.js.map +0 -1
  154. package/dist/rpc/kafka/index.mjs.map +0 -1
  155. package/dist/rpc/nats/index.js.map +0 -1
  156. package/dist/rpc/nats/index.mjs.map +0 -1
  157. package/dist/rpc/rabbitmq/index.js.map +0 -1
  158. package/dist/rpc/rabbitmq/index.mjs.map +0 -1
  159. package/dist/rpc/redis/index.js.map +0 -1
  160. package/dist/rpc/redis/index.mjs.map +0 -1
  161. package/dist/server/elysia/index.js.map +0 -1
  162. package/dist/server/elysia/index.mjs.map +0 -1
  163. package/dist/server/express/index.js.map +0 -1
  164. package/dist/server/express/index.mjs.map +0 -1
  165. package/dist/server/fastify/index.js.map +0 -1
  166. package/dist/server/fastify/index.mjs.map +0 -1
  167. package/dist/server/h3/index.js.map +0 -1
  168. package/dist/server/h3/index.mjs.map +0 -1
  169. package/dist/server/hono/index.js.map +0 -1
  170. package/dist/server/hono/index.mjs.map +0 -1
  171. package/dist/server/hyper-express/index.js.map +0 -1
  172. package/dist/server/hyper-express/index.mjs.map +0 -1
  173. package/dist/server/koa/index.js.map +0 -1
  174. package/dist/server/koa/index.mjs.map +0 -1
  175. package/dist/test.js.map +0 -1
  176. package/dist/test.mjs.map +0 -1
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # phecda-server
2
-
3
- [DOCUMENT](https://fgsreally.github.io/phecda/)
4
-
5
- nodejs server framework that provide IOC/type-reuse/http&rpc-adaptor
6
-
7
- like `nestjs`+ `trpc`, work with `elysia/express/hono/h3/koa/fastify/hyper-express` and `redis/rabbimq/kafka/bullmq/nats`
8
-
9
- Pragmatism , Progressive, Less code and Easy to maintain
10
-
1
+ # phecda-server
2
+
3
+ [DOCUMENT](https://fgsreally.github.io/phecda/)
4
+
5
+ nodejs server framework that provide IOC/type-reuse/http&rpc-adaptor
6
+
7
+ like `nestjs`+ `trpc`, work with `elysia/express/hono/h3/koa/fastify/hyper-express` and `redis/rabbimq/kafka/bullmq/nats`
8
+
9
+ Pragmatism , Progressive, Less code and Easy to maintain
10
+
package/assets/ps.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "$schema": "https://unpkg.com/phecda-server/bin/schema.json",
3
+ "resolve": [
4
+ {
5
+ "source": "controller",
6
+ "importer": "http",
7
+ "path": ".ps/http.js"
8
+ },
9
+ {
10
+ "source": "rpc",
11
+ "importer": "client",
12
+ "path": ".ps/rpc.js"
13
+ }
14
+ ],
15
+ "unimport": {
16
+ "dirs": ["."],
17
+ "dirsScanOptions":{
18
+ "filePatterns":["*.{service,controller,module,rpc,edge,guard,interceptor,extension,pipe,filter,plugin}.ts"]
19
+ }
20
+ },
21
+ "virtualFile":{},
22
+ "moduleFile": []
23
+
24
+ }
25
+
@@ -1,55 +1,55 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "type": "object",
4
- "properties": {
5
- "resolve": {
6
- "type": "array",
7
- "items": {
8
- "type": "object",
9
- "properties": {
10
- "source": {
11
- "type": "string",
12
- "description": "The middle name of the imported file."
13
- },
14
- "importer": {
15
- "type": "string",
16
- "description": "The middle name of the importer file."
17
- },
18
- "path": {
19
- "type": "string",
20
-
21
- "description": "Redirect path"
22
- },
23
- "filename": {
24
- "type": "string",
25
- "optional": true,
26
-
27
- "description": "generate split chunk,only work in vite"
28
- }
29
- },
30
- "required": ["source", "path", "importer"]
31
- },
32
- "description": "Resolve and redirect modules path"
33
- },
34
- "moduleFile": {
35
- "type": "array",
36
- "items": {
37
- "type": "string"
38
- },
39
- "description": "Including the module's file middle name, such as controller mapping to xx.controller.ts"
40
- },
41
- "virtualFile": {
42
- "type": "object",
43
- "additionalProperties": {
44
- "type": "string"
45
- },
46
- "description": "Virtual module, just like in Vite."
47
- },
48
- "unimport": {
49
- "type": "object",
50
- "description": "Includes the arguments passed to unimport and 'dtsPath' that specifies the location for generating type files."
51
- }
52
- },
53
-
54
- "required": ["resolve"]
55
- }
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "resolve": {
6
+ "type": "array",
7
+ "items": {
8
+ "type": "object",
9
+ "properties": {
10
+ "source": {
11
+ "type": "string",
12
+ "description": "The middle name of the imported file."
13
+ },
14
+ "importer": {
15
+ "type": "string",
16
+ "description": "The middle name of the importer file."
17
+ },
18
+ "path": {
19
+ "type": "string",
20
+
21
+ "description": "Redirect path"
22
+ },
23
+ "filename": {
24
+ "type": "string",
25
+ "optional": true,
26
+
27
+ "description": "generate split chunk,only work in vite"
28
+ }
29
+ },
30
+ "required": ["source", "path", "importer"]
31
+ },
32
+ "description": "Resolve and redirect modules path"
33
+ },
34
+ "moduleFile": {
35
+ "type": "array",
36
+ "items": {
37
+ "type": "string"
38
+ },
39
+ "description": "Including the module's file middle name, such as controller mapping to xx.controller.ts"
40
+ },
41
+ "virtualFile": {
42
+ "type": "object",
43
+ "additionalProperties": {
44
+ "type": "string"
45
+ },
46
+ "description": "Virtual module, just like in Vite."
47
+ },
48
+ "unimport": {
49
+ "type": "object",
50
+ "description": "Includes the arguments passed to unimport and 'dtsPath' that specifies the location for generating type files."
51
+ }
52
+ },
53
+
54
+ "required": ["resolve"]
55
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "useDefineForClassFields": false,
5
+ "experimentalDecorators": true,
6
+ "emitDecoratorMetadata": true,
7
+ "module": "esnext",
8
+ "lib": ["esnext", "DOM"],
9
+ "strictPropertyInitialization": false,
10
+ "moduleResolution": "Node",
11
+ "strict": true,
12
+ "resolveJsonModule": true,
13
+ "esModuleInterop": true,
14
+ "noEmit": true,
15
+ "noUnusedLocals": true,
16
+ "noUnusedParameters": true,
17
+ "noImplicitReturns": true,
18
+ "skipLibCheck": true
19
+ },
20
+ "include": [".","./ps.d.ts"]
21
+ }
package/bin/cli.mjs CHANGED
@@ -1,189 +1,150 @@
1
- #! /usr/bin/env node
2
- import { fork } from 'child_process'
3
- import { createRequire } from 'module'
4
- import pc from 'picocolors'
5
- import cac from 'cac'
6
- import fse from 'fs-extra'
7
- import { log } from '../dist/index.mjs'
8
- const cli = cac('phecda').option('-c,--config <config>', 'config file', {
9
- default: 'ps.json',
10
- })
11
- const require = createRequire(import.meta.url)
12
- let child
13
-
14
- let closePromise
15
- const nodeVersion = parseFloat(process.version.slice(1))
16
-
17
- if (nodeVersion < 18.19) {
18
- log(
19
- `Nodejs version less than 18.19(current is ${nodeVersion}) can't support hmr`,
20
- 'yellow',
21
- )
22
- }
23
-
24
- function startChild(file, args) {
25
- child = fork(file, {
26
- env: { NODE_ENV: 'development', ...process.env },
27
- stdio: 'inherit',
28
- execArgv: [
29
- nodeVersion < 18.19
30
- ? '--loader=phecda-server/register/loader.mjs'
31
- : '--import=phecda-server/register',
32
- ...args,
33
- ],
34
- })
35
-
36
- closePromise = new Promise((resolve) => {
37
- child.once('exit', (code) => {
38
- if (code === 4) {
39
- log('only generate code')
40
- process.exit(0)
41
- }
42
- if (code >= 2) {
43
- // for relaunch
44
- log('relaunch...')
45
- startChild(file, args)
46
- }
47
- child = undefined
48
-
49
- resolve()
50
- })
51
- })
52
- }
53
-
54
- function exit() {
55
- log('process exit')
56
-
57
- if (child) {
58
- child.kill()
59
- process.exit(0)
60
- }
61
- else {
62
- process.exit(0)
63
- }
64
- }
65
- process.on('SIGINT', () => {
66
- process.exit()
67
- })
68
-
69
- cli.command('init', 'init config file').action(async (options) => {
70
- if (!fse.existsSync('tsconfig.json')) {
71
- log('init tsconfig.json')
72
-
73
- await fse.outputFile(
74
- 'tsconfig.json',
75
- `{
76
- "compilerOptions": {
77
- "target": "esnext",
78
- "useDefineForClassFields": false,
79
- "experimentalDecorators": true,
80
- "emitDecoratorMetadata": true,
81
- "module": "esnext",
82
- "lib": ["esnext", "DOM"],
83
- "strictPropertyInitialization": false,
84
- "moduleResolution": "Node",
85
- "strict": true,
86
- "resolveJsonModule": true,
87
- "esModuleInterop": true,
88
- "noEmit": true,
89
- "noUnusedLocals": true,
90
- "noUnusedParameters": true,
91
- "noImplicitReturns": true,
92
- "skipLibCheck": true
93
- },
94
- "include": ["src","./ps.d.ts"]
95
- }
96
- `,
97
- )
98
- }
99
-
100
- if (!fse.existsSync(options.config)) {
101
- log(`init ${options.config}`)
102
-
103
- await fse.outputFile(
104
- options.config,
105
- `{
106
- "$schema": "node_modules/phecda-server/bin/schema.json",
107
- "resolve": [
108
- {
109
- "source": "controller",
110
- "importer": "http",
111
- "path": ".ps/http.js"
112
- },
113
- {
114
- "source": "rpc",
115
- "importer": "client",
116
- "path": ".ps/rpc.js"
117
- }
118
- ],
119
- "unimport": {
120
- "dirs": [],
121
- "dirsScanOptions":{
122
- "filePatterns":["*.{service,controller,module,rpc,edge,guard,interceptor,extension,pipe,filter,plugin}.ts"]
123
- }
124
- },
125
- "virtualFile":{},
126
- "moduleFile": []
127
-
128
- }
129
- `,
130
- )
131
- }
132
- })
133
-
134
- cli
135
- .command('[file]', 'run file')
136
- .alias('run')
137
- .action((file, options) => {
138
- process.env.PS_CONFIG_FILE = options.config
139
-
140
- log('process start!')
141
-
142
- startChild(file, options['--'])
143
- console.log(`${pc.green('->')} press ${pc.green('e')} to exit`)
144
- console.log(`${pc.green('->')} press ${pc.green('r')} to relaunch`)
145
-
146
- process.stdin.on('data', async (data) => {
147
- const input = data.toString().trim().toLocaleLowerCase()
148
- if (input === 'r') {
149
- if (child) {
150
- await child.kill()
151
- if (closePromise)
152
- await closePromise
153
- log('relaunch...')
154
- startChild(file, options['--'])
155
- }
156
- else {
157
- log('relaunch...')
158
-
159
- startChild(file, options['--'])
160
- }
161
- }
162
- if (input === 'e')
163
- exit()
164
- })
165
- })
166
-
167
- cli
168
- .command('generate [file]', 'generate code(mainly for ci)')
169
- .action((file, options) => {
170
- process.env.PS_GENERATE = 'true'
171
- process.env.PS_CONFIG_FILE = options.config
172
- startChild(file, options['--'])
173
- })
174
- // if (cmd[0] === 'init') {
175
-
176
- // }
177
- // else if (cmd[0] === 'code') {
178
- // process.env.PS_GENERATE = 'true'
179
- // cmd.splice(0, 1)
180
- // startChild(file,options['--'])
181
- // }
182
- // else {
183
-
184
- // }
185
-
186
- cli.help()
187
- cli.version(require('../package.json').version)
188
-
189
- cli.parse()
1
+ #! /usr/bin/env node
2
+ import { fork } from 'child_process'
3
+ import { createRequire } from 'module'
4
+ import { fileURLToPath } from 'url'
5
+
6
+ import { dirname, join, resolve } from 'path'
7
+ import pc from 'picocolors'
8
+ import cac from 'cac'
9
+ import fse from 'fs-extra'
10
+ import { log } from '../dist/index.mjs'
11
+
12
+ const cli = cac('phecda')
13
+ .option('-c,--config <config>', 'config file', {
14
+ default: 'ps.json',
15
+ })
16
+
17
+ const __dirname = dirname(fileURLToPath(import.meta.url))
18
+
19
+ const require = createRequire(import.meta.url)
20
+ let child
21
+
22
+ let closePromise
23
+ const nodeVersion = parseFloat(process.version.slice(1))
24
+
25
+ if (nodeVersion < 18.19) {
26
+ log(
27
+ `Nodejs version less than 18.19(current is ${nodeVersion}) can't support hmr`,
28
+ 'yellow',
29
+ )
30
+ }
31
+
32
+ function startChild(file, args) {
33
+ child = fork(file, {
34
+ env: { NODE_ENV: 'development', ...process.env },
35
+ stdio: 'inherit',
36
+ execArgv: [
37
+ nodeVersion < 18.19
38
+ ? '--loader=phecda-server/register/loader.mjs'
39
+ : '--import=phecda-server/register',
40
+ ...args,
41
+ ],
42
+ })
43
+
44
+ closePromise = new Promise((resolve) => {
45
+ child.once('exit', (code) => {
46
+ if (code === 4) {
47
+ log('only generate code')
48
+ process.exit(0)
49
+ }
50
+ if (code >= 2) {
51
+ // for relaunch
52
+ log('relaunch...')
53
+ startChild(file, args)
54
+ }
55
+ child = undefined
56
+
57
+ resolve()
58
+ })
59
+ })
60
+ }
61
+
62
+ function exit() {
63
+ log('process exit')
64
+
65
+ if (child) {
66
+ child.kill()
67
+ process.exit(0)
68
+ }
69
+ else {
70
+ process.exit(0)
71
+ }
72
+ }
73
+ process.on('SIGINT', () => {
74
+ process.exit()
75
+ })
76
+
77
+ cli
78
+ .command('init [workdir]', 'init config file')
79
+ .allowUnknownOptions()
80
+ .option('-t,--tsconfig <tsconfig>', 'init tsconfig file', {
81
+ default: 'tsconfig.json',
82
+ })
83
+ .action(async (workdir, options) => {
84
+ const tsconfigPath = join(workdir, options.tsconfig)
85
+ const psconfigPath = join(workdir, options.config)
86
+
87
+ if (!fse.existsSync(tsconfigPath)) {
88
+ log(`create ${tsconfigPath}`)
89
+
90
+ await fse.copyFile(resolve(__dirname, '../assets/tsconfig.json'), tsconfigPath)
91
+ }
92
+
93
+ if (!fse.existsSync(psconfigPath)) {
94
+ log(`create ${psconfigPath}`)
95
+
96
+ await fse.copyFile(resolve(__dirname, '../assets/ps.json'), psconfigPath)
97
+ }
98
+ })
99
+
100
+ cli
101
+ .command('<file> [workdir]', 'run file')
102
+ .allowUnknownOptions()
103
+ .alias('run')
104
+ .action((file, workdir, options) => {
105
+ if (workdir)
106
+ process.env.PS_WORKDIR = workdir
107
+ process.env.PS_CONFIG_FILE = options.config
108
+
109
+ log('process start!')
110
+
111
+ startChild(file, options['--'])
112
+ console.log(`${pc.green('->')} press ${pc.green('e')} to exit`)
113
+ console.log(`${pc.green('->')} press ${pc.green('r')} to relaunch`)
114
+
115
+ process.stdin.on('data', async (data) => {
116
+ const input = data.toString().trim().toLocaleLowerCase()
117
+ if (input === 'r') {
118
+ if (child) {
119
+ await child.kill()
120
+ if (closePromise)
121
+ await closePromise
122
+ log('relaunch...')
123
+ startChild(file, options['--'])
124
+ }
125
+ else {
126
+ log('relaunch...')
127
+
128
+ startChild(file, options['--'])
129
+ }
130
+ }
131
+ if (input === 'e')
132
+ exit()
133
+ })
134
+ })
135
+
136
+ cli
137
+ .command('generate <file> [workdir]', 'generate code(mainly for ci)')
138
+ .allowUnknownOptions()
139
+ .action((file, workdir, options) => {
140
+ if (workdir)
141
+ process.env.PS_WORKDIR = workdir
142
+ process.env.PS_GENERATE = 'true'
143
+ process.env.PS_CONFIG_FILE = options.config
144
+ startChild(file, options['--'])
145
+ })
146
+
147
+ cli.help()
148
+ cli.version(require('../package.json').version)
149
+
150
+ cli.parse()