nuwax-file-server 1.2.2 → 1.2.3
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/dist/cli.js +1 -1
- package/package.json +28 -28
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as N}from"commander";import g from"path";import y from"os";import u from"fs-extra";import{spawn as D}from"cross-spawn";import{fileURLToPath as T}from"url";import{createRequire as b}from"module";var L=g.dirname(T(import.meta.url)),K=b(import.meta.url),E="1.2.
|
|
2
|
+
import{Command as N}from"commander";import g from"path";import y from"os";import u from"fs-extra";import{spawn as D}from"cross-spawn";import{fileURLToPath as T}from"url";import{createRequire as b}from"module";var L=g.dirname(T(import.meta.url)),K=b(import.meta.url),E="1.2.3",l=new N,$={name:"nuwax-file-server",pidDir:g.join(y.tmpdir(),"nuwax-file-server"),logDir:g.join(y.tmpdir(),"nuwax-file-server","logs"),pidFile:g.join(y.tmpdir(),"nuwax-file-server","server.pid")},d={reset:"\x1B[0m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"};function a(e,o="reset"){console.log(`${d[o]}${e}${d.reset}`)}function f(e){console.error(`${d.red}ERROR: ${e}${d.reset}`)}function r(e){console.log(`${d.green}${e}${d.reset}`)}function s(e){console.log(`${d.blue}${e}${d.reset}`)}function h(){return $.pidFile}function R(){try{let e=h();if(u.existsSync(e)){let o=u.readFileSync(e,"utf8");return JSON.parse(o)}}catch{}return null}function j(e){let o=g.dirname(h());u.ensureDirSync(o),u.writeFileSync(h(),JSON.stringify(e,null,2))}function x(){let e=h();u.existsSync(e)&&u.removeSync(e)}function v(e){try{return process.kill(e,0),!0}catch(o){return o.code==="ESRCH"||o.code==="EPERM",!1}}async function k(e,o=!1){return new Promise(t=>{if(process.platform==="win32"){let i=o?["/F","/PID",String(e)]:["/PID",String(e)],n=D("taskkill",i,{stdio:"pipe"});n.on("error",c=>{f(`\u505C\u6B62\u8FDB\u7A0B\u5931\u8D25: ${c.message}`),t(!1)}),n.on("close",c=>{c===0?(r(`\u8FDB\u7A0B ${e} \u5DF2\u505C\u6B62`),t(!0)):o?D("taskkill",["/F","/PID",String(e)],{stdio:"pipe"}).on("close",m=>{t(m===0)}):t(!1)})}else try{process.kill(-e,o?"SIGKILL":"SIGTERM"),r(`\u8FDB\u7A0B\u7EC4 ${e} \u5DF2\u505C\u6B62`),t(!0)}catch(i){if(i.code==="ESRCH")r(`\u8FDB\u7A0B ${e} \u4E0D\u5B58\u5728\uFF0C\u89C6\u4E3A\u5DF2\u505C\u6B62`),t(!0);else try{process.kill(e,o?"SIGKILL":"SIGTERM"),r(`\u8FDB\u7A0B ${e} \u5DF2\u505C\u6B62`),t(!0)}catch(n){n.code==="ESRCH"?(r(`\u8FDB\u7A0B ${e} \u4E0D\u5B58\u5728\uFF0C\u89C6\u4E3A\u5DF2\u505C\u6B62`),t(!0)):(f(`\u505C\u6B62\u8FDB\u7A0B\u5931\u8D25: ${n.message}`),t(!1))}}})}async function F(e){let{env:o,port:t,config:w}=e,i=new Set(["env","port","config","force","help","version"]);process.argv.slice(2).forEach(p=>{if(p.startsWith("--")&&p.includes("=")){let O=p.indexOf("="),P=p.slice(2,O);if(!i.has(P)){let _=p.slice(O+1);process.env[P]=_,s(`CLI \u53C2\u6570\u8986\u76D6\u73AF\u5883\u53D8\u91CF: ${P}=${_}`)}}}),s(`\u542F\u52A8 ${$.name} \u670D\u52A1...`);let n=R();n&&v(n.pid)&&(f(`\u670D\u52A1\u5DF2\u5728\u8FD0\u884C\u4E2D (PID: ${n.pid})`),s("\u8BF7\u4F7F\u7528 'nuwax-file-server stop' \u505C\u6B62\u73B0\u6709\u670D\u52A1\u540E\u518D\u8BD5"),process.exit(1));let c=o||"production";process.env.NODE_ENV=c,s(`\u4F7F\u7528\u73AF\u5883: ${c}`),t&&(process.env.PORT=t,s(`\u4F7F\u7528\u7AEF\u53E3: ${t}`)),w&&(process.env.CONFIG_FILE=w,s(`\u4F7F\u7528\u914D\u7F6E\u6587\u4EF6: ${w}`)),u.ensureDirSync($.logDir);let I=g.join(L,"server.js"),m=D("node",[I],{env:{...process.env,NODE_ENV:c},stdio:"inherit",detached:!0,cwd:process.cwd(),windowsHide:!0});m.on("error",p=>{f(`\u542F\u52A8\u670D\u52A1\u5931\u8D25: ${p.message}`),process.exit(1)}),await new Promise(p=>setTimeout(p,2e3)),v(m.pid)||(f("\u670D\u52A1\u542F\u52A8\u5931\u8D25"),process.exit(1));let S={pid:m.pid,startedAt:new Date().toISOString(),env:o||"production",port:t||process.env.PORT||"60000",version:E,platform:process.platform};j(S),m.unref(),r(`\u670D\u52A1\u5DF2\u542F\u52A8 (PID: ${m.pid})`),a(`\u670D\u52A1\u8FD0\u884C\u5728: http://localhost:${S.port}`,"cyan"),a(`\u73AF\u5883: ${S.env}`,"cyan"),a(`\u5E73\u53F0: ${S.platform}`,"cyan"),a(`PID \u6587\u4EF6: ${h()}`,"cyan")}async function C(e){let{force:o}=e;s(`\u505C\u6B62 ${$.name} \u670D\u52A1...`);let t=R();t||(f("\u672A\u627E\u5230\u8FD0\u884C\u4E2D\u7684\u670D\u52A1"),s("\u670D\u52A1\u53EF\u80FD\u672A\u542F\u52A8\u6216 PID \u6587\u4EF6\u5DF2\u4E22\u5931"),process.exit(0)),v(t.pid)||(s("\u670D\u52A1\u8FDB\u7A0B\u5DF2\u505C\u6B62\uFF0C\u6E05\u7406 PID \u6587\u4EF6..."),x(),r("\u670D\u52A1\u5DF2\u505C\u6B62"),process.exit(0)),await k(t.pid,o)&&(await new Promise(n=>setTimeout(n,1e3)),v(t.pid)||(x(),r("\u670D\u52A1\u5DF2\u505C\u6B62"),process.exit(0))),o&&(f("\u5F3A\u5236\u505C\u6B62\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u505C\u6B62\u8FDB\u7A0B"),process.exit(1)),s("\u5C1D\u8BD5\u5F3A\u5236\u505C\u6B62..."),await k(t.pid,!0)&&(await new Promise(n=>setTimeout(n,1e3)),v(t.pid)||(x(),r("\u670D\u52A1\u5DF2\u5F3A\u5236\u505C\u6B62"),process.exit(0))),f("\u505C\u6B62\u670D\u52A1\u5931\u8D25"),process.exit(1)}async function A(e){a(`\u91CD\u542F ${$.name} \u670D\u52A1...`,"yellow"),s("\u505C\u6B62\u73B0\u6709\u670D\u52A1...");try{await C({force:!1})}catch{s("\u670D\u52A1\u672A\u8FD0\u884C\u6216\u5DF2\u505C\u6B62")}await new Promise(o=>setTimeout(o,2e3)),s("\u542F\u52A8\u670D\u52A1..."),await F(e),r("\u670D\u52A1\u5DF2\u91CD\u542F")}function G(){s(`${$.name} \u670D\u52A1\u72B6\u6001:`);let e=R();e||(a("\u670D\u52A1\u672A\u8FD0\u884C","yellow"),process.exit(0));let o=v(e.pid);if(console.log(""),console.log(` \u670D\u52A1\u540D\u79F0: ${$.name}`),console.log(` \u8FD0\u884C\u72B6\u6001: ${o?"\u8FD0\u884C\u4E2D":"\u5DF2\u505C\u6B62"}`),console.log(` \u8FDB\u7A0B ID: ${e.pid}`),console.log(` \u73AF\u5883: ${e.env||"production"}`),console.log(` \u7AEF\u53E3: ${e.port||"60000"}`),console.log(` \u7248\u672C: ${e.version||E}`),console.log(` \u5E73\u53F0: ${e.platform||process.platform}`),console.log(` \u542F\u52A8\u65F6\u95F4: ${e.startedAt||"\u672A\u77E5"}`),e.startedAt){let t=new Date(e.startedAt),i=Math.floor((new Date-t)/1e3),n=Math.floor(i/3600),c=Math.floor(i%3600/60),I=i%60;console.log(` \u8FD0\u884C\u65F6\u95F4: ${n}\u5C0F\u65F6 ${c}\u5206 ${I}\u79D2`)}console.log(` PID \u6587\u4EF6: ${h()}`),console.log(""),o?a("\u670D\u52A1\u8FD0\u884C\u6B63\u5E38","green"):(a("\u8B66\u544A: \u670D\u52A1\u8FDB\u7A0B\u4E0D\u5B58\u5728\uFF0C\u4F46 PID \u6587\u4EF6\u4ECD\u5B58\u5728","yellow"),s("\u5EFA\u8BAE\u6267\u884C stop \u547D\u4EE4\u6E05\u7406"))}function H(){l.name("nuwax-file-server").description("\u8DE8\u5E73\u53F0\u6587\u4EF6\u670D\u52A1\u90E8\u7F72\u5DE5\u5177\uFF0C\u652F\u6301 start/stop/restart/status").version(E,"-v, --version","\u663E\u793A\u7248\u672C\u53F7").helpOption("-h, --help","\u663E\u793A\u5E2E\u52A9\u4FE1\u606F"),l.command("start").allowUnknownOption().description("\u542F\u52A8\u670D\u52A1").option("--env <environment>","\u73AF\u5883: development|production|test","production").option("--port <port>","\u670D\u52A1\u7AEF\u53E3\u53F7").option("--config <path>","\u81EA\u5B9A\u4E49\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84").action(F),l.command("stop").description("\u505C\u6B62\u670D\u52A1").option("--force","\u5F3A\u5236\u505C\u6B62").action(C),l.command("restart").allowUnknownOption().description("\u91CD\u542F\u670D\u52A1").option("--env <environment>","\u73AF\u5883: development|production|test","production").option("--port <port>","\u670D\u52A1\u7AEF\u53E3\u53F7").option("--config <path>","\u81EA\u5B9A\u4E49\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84").action(A),l.command("status").description("\u67E5\u770B\u670D\u52A1\u72B6\u6001").action(G),l.command("help").description("\u663E\u793A\u5E2E\u52A9\u4FE1\u606F").action(()=>{l.outputHelp()}),l.parse(process.argv),process.argv.slice(2).length||(l.outputHelp(),process.exit(0))}H();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuwax-file-server",
|
|
3
3
|
"displayName": "nuwax-file-server",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.3",
|
|
5
5
|
"description": "跨平台的文件服务部署工具,支持 start/stop/restart 命令行操作",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "index.js",
|
|
@@ -19,6 +19,32 @@
|
|
|
19
19
|
"linux",
|
|
20
20
|
"win32"
|
|
21
21
|
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"start": "nodemon src/server.js",
|
|
24
|
+
"dev": "nodemon scripts/start-dev.js",
|
|
25
|
+
"test": "nodemon scripts/start-test.js",
|
|
26
|
+
"prod": "node scripts/start-prod.js",
|
|
27
|
+
"test:run": "NODE_OPTIONS='--experimental-vm-modules' jest --coverage",
|
|
28
|
+
"test:watch": "jest --watch",
|
|
29
|
+
"test:unit": "jest --testPathPattern=tests/unit",
|
|
30
|
+
"test:integration": "jest --testPathPattern=tests/integration",
|
|
31
|
+
"start:test": "nodemon scripts/start-test.js",
|
|
32
|
+
"pnpm:check:dev": "NODE_ENV=development node scripts/pnpm-check-wrapper.js",
|
|
33
|
+
"pnpm:check:prod": "NODE_ENV=production node scripts/pnpm-check-wrapper.js",
|
|
34
|
+
"pnpm:check:test": "NODE_ENV=test node scripts/pnpm-check-wrapper.js",
|
|
35
|
+
"pnpm:prune": "pnpm store prune",
|
|
36
|
+
"pnpm:prune:manual": "node scripts/pnpm-prune-manual.js",
|
|
37
|
+
"pnpm:status": "pnpm store status",
|
|
38
|
+
"cli:start": "node src/cli.js start",
|
|
39
|
+
"cli:stop": "node src/cli.js stop",
|
|
40
|
+
"cli:restart": "node src/cli.js restart",
|
|
41
|
+
"cli:status": "node src/cli.js status",
|
|
42
|
+
"cli:start:dev": "node src/cli.js start --env development",
|
|
43
|
+
"cli:start:prod": "node src/cli.js start --env production",
|
|
44
|
+
"cli:start:test": "node src/cli.js start --env test",
|
|
45
|
+
"build": "node scripts/build.js",
|
|
46
|
+
"prepublishOnly": "npm run build"
|
|
47
|
+
},
|
|
22
48
|
"author": "",
|
|
23
49
|
"license": "ISC",
|
|
24
50
|
"keywords": [
|
|
@@ -63,31 +89,5 @@
|
|
|
63
89
|
"jest": "^29.7.0",
|
|
64
90
|
"nodemon": "^3.1.10",
|
|
65
91
|
"supertest": "^6.3.4"
|
|
66
|
-
},
|
|
67
|
-
"scripts": {
|
|
68
|
-
"preinstall": "npx only-allow pnpm",
|
|
69
|
-
"start": "nodemon src/server.js",
|
|
70
|
-
"dev": "nodemon scripts/start-dev.js",
|
|
71
|
-
"test": "nodemon scripts/start-test.js",
|
|
72
|
-
"prod": "node scripts/start-prod.js",
|
|
73
|
-
"test:run": "NODE_OPTIONS='--experimental-vm-modules' jest --coverage",
|
|
74
|
-
"test:watch": "jest --watch",
|
|
75
|
-
"test:unit": "jest --testPathPattern=tests/unit",
|
|
76
|
-
"test:integration": "jest --testPathPattern=tests/integration",
|
|
77
|
-
"start:test": "nodemon scripts/start-test.js",
|
|
78
|
-
"pnpm:check:dev": "NODE_ENV=development node scripts/pnpm-check-wrapper.js",
|
|
79
|
-
"pnpm:check:prod": "NODE_ENV=production node scripts/pnpm-check-wrapper.js",
|
|
80
|
-
"pnpm:check:test": "NODE_ENV=test node scripts/pnpm-check-wrapper.js",
|
|
81
|
-
"pnpm:prune": "pnpm store prune",
|
|
82
|
-
"pnpm:prune:manual": "node scripts/pnpm-prune-manual.js",
|
|
83
|
-
"pnpm:status": "pnpm store status",
|
|
84
|
-
"cli:start": "node src/cli.js start",
|
|
85
|
-
"cli:stop": "node src/cli.js stop",
|
|
86
|
-
"cli:restart": "node src/cli.js restart",
|
|
87
|
-
"cli:status": "node src/cli.js status",
|
|
88
|
-
"cli:start:dev": "node src/cli.js start --env development",
|
|
89
|
-
"cli:start:prod": "node src/cli.js start --env production",
|
|
90
|
-
"cli:start:test": "node src/cli.js start --env test",
|
|
91
|
-
"build": "node scripts/build.js"
|
|
92
92
|
}
|
|
93
|
-
}
|
|
93
|
+
}
|