@node-cli/static-server 0.0.6
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/LICENSE +21 -0
- package/README.md +41 -0
- package/dist/certs.d.ts +2 -0
- package/dist/certs.js +46 -0
- package/dist/certs.js.map +1 -0
- package/dist/defaults.d.ts +13 -0
- package/dist/defaults.js +17 -0
- package/dist/defaults.js.map +1 -0
- package/dist/logs.d.ts +3 -0
- package/dist/logs.js +13 -0
- package/dist/logs.js.map +1 -0
- package/dist/parse.d.ts +15 -0
- package/dist/parse.js +92 -0
- package/dist/parse.js.map +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +110 -0
- package/dist/server.js.map +1 -0
- package/dist/utilities.d.ts +44 -0
- package/dist/utilities.js +188 -0
- package/dist/utilities.js.map +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Arno Versini
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Static Server
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
> Static Server is a simple, zero-configuration, command line HTTP server to serve static files locally.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
This command line utility can be installed globally or locally within your project. It does make more sense to have it installed globally though, since it then can be use anywhere by simply starting it to serve the files located in the current folder.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
> npm install -g @node-cli/static-server
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
> static-server [options] [path]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`[path]` defaults to the current folder if it's not provided at the command line prompt.
|
|
22
|
+
|
|
23
|
+
At that point, you should be able to visit `http://localhost:8080` and see the files located in the current folder.
|
|
24
|
+
|
|
25
|
+
### Options
|
|
26
|
+
|
|
27
|
+
| option | default | description |
|
|
28
|
+
| -------------------------- | ------- | ----------------------------------------------------------- |
|
|
29
|
+
| `-c` or `--cache <number>` | 0 | Time in seconds for caching files |
|
|
30
|
+
| `-C` or `--cors` | false | Set CORS headers to \* to allow requests from any origin |
|
|
31
|
+
| `-h` or `--help` | | Display help instructions |
|
|
32
|
+
| `-H` or `--http2` | false | Enable HTTP v2 and SSL (https) |
|
|
33
|
+
| `-l` or `--logs` | false | Log HTTP requests at the prompt |
|
|
34
|
+
| `-o` or `--open` | false | Open in your default browser |
|
|
35
|
+
| `-p` or `--port <n>` | 8080 | Port to listen on - Will try next available if already used |
|
|
36
|
+
| `-g` or `--gzip` | true | Enable GZIP compression |
|
|
37
|
+
| `-v` or `--version` | | Output the current version |
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
41
|
+
MIT © Arno Versini
|
package/dist/certs.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const cert = "-----BEGIN CERTIFICATE-----\nMIICpDCCAYwCCQC8TqYqUGuZJDANBgkqhkiG9w0BAQsFADAUMRIwEAYDVQQDDAls\nb2NhbGhvc3QwHhcNMjMwNTEyMjMxOTU3WhcNMzMwNTA5MjMxOTU3WjAUMRIwEAYD\nVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDy\nc+8Eb+Y/oXvnIgja8nJycczRzDWQvj9Q242yy4M4eRJCnw+aFGkLWvUL4h+p7kKw\nPK9FDv02WK81YDzbfvpAe0PepPChMcGqIiznnu14J+/dJ14ZFnitNwG6hYCXkjNt\nUvGpQgSRe3LEo4FKMqrURk2hhhZAdaC1Qe05ohvbgJBW7UBI/+qrxP8KAjb3Nqke\nhVSRMUCKsBGoNceUgFfrgyVDKiLsIuKdWcjvVb0hrGwZW4chm7EhoJaARnByupuw\nzjRSpkbFmgZjIq0GCLvFi/KJu5OwV0ZaZMLEOmLYoV57LQJ7ZwnXeUT7rZjlUgvx\nknY7y8BMgchO0rNNgqFfAgMBAAEwDQYJKoZIhvcNAQELBQADggEBALvnJX45Zkll\nF1Fj4Rpq4ssYO95Zdp1Le/XWDh6nXJtFFlEINB0iZoha/W7r3kR+FsdkerW4oyGi\nYaNoslgM5KcEV8pDnI2bjAF7J3Id9Hcz+IN1BFIqWWBgp0Rt/5Gb2XbsRUj2lI46\nQ3cqMu6Gf075bVwLyA8QDOxjwME6N/AdXCFXL8RB0P9H9510b3R7CwA/yabiIQrp\nfWqObP4FZsQCzTwFJ3rvvuZ1t+ehtNMO/D3wtewHVBuPmFAdDcISZMWbOaBE24wz\npcgHJy1ujHi4prXPnnFk08k18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Ks6U3Aj/jf6rkSq7C1W+Dip921Gi9sU0Lkizsg/gQn5JMIuhOCR2XIl
|
|
37
|
+
dD9wOvAdPMf2y4iNt2P72BBlayHH1MbofaP1YJrWhBbYk+g3c/i9Tba0KLpnXN2x
|
|
38
|
+
xPC8a3eBd9Gf+fWyfWg0vwC1AoGBALJ/4eeRW9phQLbOgZ+jvFLdWYo83gsVcHgi
|
|
39
|
+
qfZxAZyCgYqT9NZJ0NHxBRFEu+dB7b0QL3bikkc7Xm0Deu4QCs2oozGf7tfD9wfg
|
|
40
|
+
m3+5q3f5YL6O3pPHlbDlT4t6YEbGu9spH/rc5uY18vbTVa1ZNoCGuEswd1jYwjla
|
|
41
|
+
IKzcb0wnAoGADE80xrFwYuy/BJFTPb2C7U//i6StymSG3he7p+RAvKKPBFXVFkTT
|
|
42
|
+
M+X+O8oECdPoBmQ6I3Wh2QHkua4waPPdB5Md6DgnSgK/Wd3Fypz+5XakyA+j5LRJ
|
|
43
|
+
CK+IKNdZGb8ICaKKmS2FhaOa860GpdQWM8z6P3FgKRwgQ2k+684oowg=
|
|
44
|
+
-----END RSA PRIVATE KEY-----`;
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=certs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/certs.ts"],"sourcesContent":["export const cert = `-----BEGIN CERTIFICATE-----\nMIICpDCCAYwCCQC8TqYqUGuZJDANBgkqhkiG9w0BAQsFADAUMRIwEAYDVQQDDAls\nb2NhbGhvc3QwHhcNMjMwNTEyMjMxOTU3WhcNMzMwNTA5MjMxOTU3WjAUMRIwEAYD\nVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDy\nc+8Eb+Y/oXvnIgja8nJycczRzDWQvj9Q242yy4M4eRJCnw+aFGkLWvUL4h+p7kKw\nPK9FDv02WK81YDzbfvpAe0PepPChMcGqIiznnu14J+/dJ14ZFnitNwG6hYCXkjNt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C7U//i6StymSG3he7p+RAvKKPBFXVFkTT\nM+X+O8oECdPoBmQ6I3Wh2QHkua4waPPdB5Md6DgnSgK/Wd3Fypz+5XakyA+j5LRJ\nCK+IKNdZGb8ICaKKmS2FhaOa860GpdQWM8z6P3FgKRwgQ2k+684oowg=\n-----END RSA PRIVATE KEY-----`;\n"],"names":["cert","key"],"mappings":"AAAA,OAAO,MAAMA,OAAO,CAAC;;;;;;;;;;;;;;;;yBAgBI,CAAC,CAAC;AAE3B,OAAO,MAAMC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;6BA0BS,CAAC,CAAC"}
|
package/dist/defaults.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const defaults = {
|
|
2
|
+
cache: 0,
|
|
3
|
+
cors: false,
|
|
4
|
+
gzip: true,
|
|
5
|
+
headers: [
|
|
6
|
+
{
|
|
7
|
+
"X-Powered-By": "Fast Static Server"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
http2: false,
|
|
11
|
+
logs: false,
|
|
12
|
+
open: false,
|
|
13
|
+
path: `${process.cwd()}/`,
|
|
14
|
+
port: 8080
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const defaults = {\n\tcache: 0,\n\tcors: false,\n\tgzip: true,\n\theaders: [{ \"X-Powered-By\": \"Fast Static Server\" }],\n\thttp2: false,\n\tlogs: false,\n\topen: false,\n\tpath: `${process.cwd()}/`,\n\tport: 8080,\n};\n"],"names":["defaults","cache","cors","gzip","headers","http2","logs","open","path","process","cwd","port"],"mappings":"AAAA,OAAO,MAAMA,WAAW;IACvBC,OAAO;IACPC,MAAM,KAAK;IACXC,MAAM,IAAI;IACVC,SAAS;QAAC;YAAE,gBAAgB;QAAqB;KAAE;IACnDC,OAAO,KAAK;IACZC,MAAM,KAAK;IACXC,MAAM,KAAK;IACXC,MAAM,CAAC,EAAEC,QAAQC,GAAG,GAAG,CAAC,CAAC;IACzBC,MAAM;AACP,EAAE"}
|
package/dist/logs.d.ts
ADDED
package/dist/logs.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fastifyPlugin from "fastify-plugin";
|
|
2
|
+
import kleur from "kleur";
|
|
3
|
+
const plugin = async (fastify)=>{
|
|
4
|
+
fastify.addHook("onResponse", async (request, reply)=>{
|
|
5
|
+
request.log.info(kleur.cyan(`${request.method} ${request.url} ${reply.statusCode}`));
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
export default fastifyPlugin(plugin, {
|
|
9
|
+
fastify: "4.x",
|
|
10
|
+
name: "fastify-simple-logger"
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=logs.js.map
|
package/dist/logs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/logs.ts"],"sourcesContent":["import type { FastifyPluginAsync } from \"fastify\";\nimport fastifyPlugin from \"fastify-plugin\";\nimport kleur from \"kleur\";\n\nconst plugin: FastifyPluginAsync = async (fastify): Promise<void> => {\n\tfastify.addHook(\"onResponse\", async (request, reply) => {\n\t\trequest.log.info(\n\t\t\tkleur.cyan(`${request.method} ${request.url} ${reply.statusCode}`)\n\t\t);\n\t});\n};\n\nexport default fastifyPlugin(plugin, {\n\tfastify: \"4.x\",\n\tname: \"fastify-simple-logger\",\n});\n"],"names":["fastifyPlugin","kleur","plugin","fastify","addHook","request","reply","log","info","cyan","method","url","statusCode","name"],"mappings":"AACA,OAAOA,mBAAmB,iBAAiB;AAC3C,OAAOC,WAAW,QAAQ;AAE1B,MAAMC,SAA6B,OAAOC,UAA2B;IACpEA,QAAQC,OAAO,CAAC,cAAc,OAAOC,SAASC,QAAU;QACvDD,QAAQE,GAAG,CAACC,IAAI,CACfP,MAAMQ,IAAI,CAAC,CAAC,EAAEJ,QAAQK,MAAM,CAAC,CAAC,EAAEL,QAAQM,GAAG,CAAC,CAAC,EAAEL,MAAMM,UAAU,CAAC,CAAC;IAEnE;AACD;AAEA,eAAeZ,cAAcE,QAAQ;IACpCC,SAAS;IACTU,MAAM;AACP,GAAG"}
|
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merging default configuration with the
|
|
3
|
+
* preferences shared by the user.
|
|
4
|
+
*/
|
|
5
|
+
declare const config: {
|
|
6
|
+
cache?: number;
|
|
7
|
+
cors?: boolean;
|
|
8
|
+
http2?: boolean;
|
|
9
|
+
gzip?: boolean;
|
|
10
|
+
logs?: boolean;
|
|
11
|
+
open?: boolean;
|
|
12
|
+
path?: string;
|
|
13
|
+
port?: number;
|
|
14
|
+
};
|
|
15
|
+
export { config };
|
package/dist/parse.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { displayErrorMessages, meowOptionsHelper, meowParserHelper, shallowMerge } from "./utilities.js";
|
|
2
|
+
import { defaults } from "./defaults.js";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import meow from "meow";
|
|
5
|
+
const { helpText , options } = meowOptionsHelper({
|
|
6
|
+
flags: {
|
|
7
|
+
cache: {
|
|
8
|
+
shortFlag: "c",
|
|
9
|
+
default: defaults.cache,
|
|
10
|
+
description: "Time in seconds for caching files",
|
|
11
|
+
type: "number"
|
|
12
|
+
},
|
|
13
|
+
cors: {
|
|
14
|
+
shortFlag: "C",
|
|
15
|
+
default: defaults.cors,
|
|
16
|
+
description: "Set CORS headers to * to allow requests from any origin",
|
|
17
|
+
type: "boolean"
|
|
18
|
+
},
|
|
19
|
+
gzip: {
|
|
20
|
+
shortFlag: "g",
|
|
21
|
+
default: defaults.gzip,
|
|
22
|
+
description: "Enable GZIP compression",
|
|
23
|
+
type: "boolean"
|
|
24
|
+
},
|
|
25
|
+
help: {
|
|
26
|
+
shortFlag: "h",
|
|
27
|
+
description: "Display help instructions",
|
|
28
|
+
type: "boolean"
|
|
29
|
+
},
|
|
30
|
+
http2: {
|
|
31
|
+
shortFlag: "H",
|
|
32
|
+
default: defaults.http2,
|
|
33
|
+
description: "Set HTTP to version 2",
|
|
34
|
+
type: "boolean"
|
|
35
|
+
},
|
|
36
|
+
logs: {
|
|
37
|
+
shortFlag: "l",
|
|
38
|
+
default: defaults.logs,
|
|
39
|
+
description: "Log HTTP requests at the prompt",
|
|
40
|
+
type: "boolean"
|
|
41
|
+
},
|
|
42
|
+
open: {
|
|
43
|
+
shortFlag: "o",
|
|
44
|
+
default: defaults.open,
|
|
45
|
+
description: "Open in your default browser",
|
|
46
|
+
type: "boolean"
|
|
47
|
+
},
|
|
48
|
+
port: {
|
|
49
|
+
shortFlag: "p",
|
|
50
|
+
default: defaults.port,
|
|
51
|
+
description: "Port to listen on",
|
|
52
|
+
type: "number"
|
|
53
|
+
},
|
|
54
|
+
version: {
|
|
55
|
+
shortFlag: "v",
|
|
56
|
+
description: "Output the current version",
|
|
57
|
+
type: "boolean"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
parameters: {
|
|
61
|
+
path: {
|
|
62
|
+
default: "current folder",
|
|
63
|
+
description: "the path to serve files from"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
usage: true
|
|
67
|
+
});
|
|
68
|
+
const cli = meow(helpText, options);
|
|
69
|
+
meowParserHelper({
|
|
70
|
+
cli
|
|
71
|
+
});
|
|
72
|
+
const customCfg = cli.flags;
|
|
73
|
+
if (cli.input.length > 0) {
|
|
74
|
+
let customPath = cli.input[0];
|
|
75
|
+
if (fs.pathExistsSync(customPath)) {
|
|
76
|
+
if (!customPath.endsWith("/")) {
|
|
77
|
+
customPath += "/";
|
|
78
|
+
}
|
|
79
|
+
customCfg.path = customPath;
|
|
80
|
+
} else {
|
|
81
|
+
displayErrorMessages([
|
|
82
|
+
`Folder ${customPath} does not exist!`
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Merging default configuration with the
|
|
88
|
+
* preferences shared by the user.
|
|
89
|
+
*/ const config = shallowMerge(defaults, customCfg);
|
|
90
|
+
export { config };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["import {\n\tdisplayErrorMessages,\n\tmeowOptionsHelper,\n\tmeowParserHelper,\n\tshallowMerge,\n} from \"./utilities.js\";\n\nimport { defaults } from \"./defaults.js\";\nimport fs from \"fs-extra\";\nimport meow from \"meow\";\n\nconst { helpText, options } = meowOptionsHelper({\n\tflags: {\n\t\tcache: {\n\t\t\tshortFlag: \"c\",\n\t\t\tdefault: defaults.cache,\n\t\t\tdescription: \"Time in seconds for caching files\",\n\t\t\ttype: \"number\",\n\t\t},\n\t\tcors: {\n\t\t\tshortFlag: \"C\",\n\t\t\tdefault: defaults.cors,\n\t\t\tdescription: \"Set CORS headers to * to allow requests from any origin\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tgzip: {\n\t\t\tshortFlag: \"g\",\n\t\t\tdefault: defaults.gzip,\n\t\t\tdescription: \"Enable GZIP compression\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\thelp: {\n\t\t\tshortFlag: \"h\",\n\t\t\tdescription: \"Display help instructions\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\thttp2: {\n\t\t\tshortFlag: \"H\",\n\t\t\tdefault: defaults.http2,\n\t\t\tdescription: \"Set HTTP to version 2\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tlogs: {\n\t\t\tshortFlag: \"l\",\n\t\t\tdefault: defaults.logs,\n\t\t\tdescription: \"Log HTTP requests at the prompt\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\topen: {\n\t\t\tshortFlag: \"o\",\n\t\t\tdefault: defaults.open,\n\t\t\tdescription: \"Open in your default browser\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tport: {\n\t\t\tshortFlag: \"p\",\n\t\t\tdefault: defaults.port,\n\t\t\tdescription: \"Port to listen on\",\n\t\t\ttype: \"number\",\n\t\t},\n\t\tversion: {\n\t\t\tshortFlag: \"v\",\n\t\t\tdescription: \"Output the current version\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t},\n\tparameters: {\n\t\tpath: {\n\t\t\tdefault: \"current folder\",\n\t\t\tdescription: \"the path to serve files from\",\n\t\t},\n\t},\n\tusage: true,\n});\nconst cli = meow(helpText, options);\nmeowParserHelper({ cli });\n\nconst customCfg = cli.flags;\nif (cli.input.length > 0) {\n\tlet customPath: string = cli.input[0];\n\tif (fs.pathExistsSync(customPath)) {\n\t\tif (!customPath.endsWith(\"/\")) {\n\t\t\tcustomPath += \"/\";\n\t\t}\n\t\tcustomCfg.path = customPath;\n\t} else {\n\t\tdisplayErrorMessages([`Folder ${customPath} does not exist!`]);\n\t}\n}\n\n/**\n * Merging default configuration with the\n * preferences shared by the user.\n */\nconst config: {\n\tcache?: number;\n\tcors?: boolean;\n\thttp2?: boolean;\n\tgzip?: boolean;\n\tlogs?: boolean;\n\topen?: boolean;\n\tpath?: string;\n\tport?: number;\n} = shallowMerge(defaults, customCfg);\n\nexport { config };\n"],"names":["displayErrorMessages","meowOptionsHelper","meowParserHelper","shallowMerge","defaults","fs","meow","helpText","options","flags","cache","shortFlag","default","description","type","cors","gzip","help","http2","logs","open","port","version","parameters","path","usage","cli","customCfg","input","length","customPath","pathExistsSync","endsWith","config"],"mappings":"AAAA,SACCA,oBAAoB,EACpBC,iBAAiB,EACjBC,gBAAgB,EAChBC,YAAY,QACN,iBAAiB;AAExB,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,UAAU,OAAO;AAExB,MAAM,EAAEC,SAAQ,EAAEC,QAAO,EAAE,GAAGP,kBAAkB;IAC/CQ,OAAO;QACNC,OAAO;YACNC,WAAW;YACXC,SAASR,SAASM,KAA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d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { cert, key } from "./certs.js";
|
|
2
|
+
import Fastify from "fastify";
|
|
3
|
+
import boxen from "boxen";
|
|
4
|
+
import { config } from "./parse.js";
|
|
5
|
+
import fastifyCache from "@fastify/caching";
|
|
6
|
+
import fastifyCompress from "@fastify/compress";
|
|
7
|
+
import fastifyCors from "@fastify/cors";
|
|
8
|
+
import fastifyLogs from "./logs.js";
|
|
9
|
+
import fastifyStatic from "@fastify/static";
|
|
10
|
+
import kleur from "kleur";
|
|
11
|
+
import { logger } from "./utilities.js";
|
|
12
|
+
import open from "open";
|
|
13
|
+
import portfinder from "portfinder";
|
|
14
|
+
const fastifyOptions = {
|
|
15
|
+
disableRequestLogging: true
|
|
16
|
+
};
|
|
17
|
+
if (config.logs) {
|
|
18
|
+
fastifyOptions.logger = {
|
|
19
|
+
level: "info",
|
|
20
|
+
transport: {
|
|
21
|
+
target: "pino-pretty",
|
|
22
|
+
options: {
|
|
23
|
+
hideObject: true,
|
|
24
|
+
translateTime: "SYS:standard",
|
|
25
|
+
ignore: "pid,hostname,reqId,resTime,resTimeMs,level"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (config.http2) {
|
|
31
|
+
fastifyOptions.http2 = true;
|
|
32
|
+
fastifyOptions.https = {
|
|
33
|
+
key,
|
|
34
|
+
cert
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const fastify = Fastify(fastifyOptions);
|
|
38
|
+
if (config.logs) {
|
|
39
|
+
fastify.register(fastifyLogs);
|
|
40
|
+
}
|
|
41
|
+
if (config.gzip) {
|
|
42
|
+
fastify.register(fastifyCompress, {
|
|
43
|
+
global: true,
|
|
44
|
+
encodings: [
|
|
45
|
+
"gzip",
|
|
46
|
+
"deflate",
|
|
47
|
+
"br",
|
|
48
|
+
"identity"
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (config.cors) {
|
|
53
|
+
fastify.register(fastifyCors);
|
|
54
|
+
}
|
|
55
|
+
const fastifyCacheOptions = {};
|
|
56
|
+
if (config.cache > 0) {
|
|
57
|
+
fastifyCacheOptions.expiresIn = config.cache;
|
|
58
|
+
fastifyCacheOptions.serverExpiresIn = config.cache;
|
|
59
|
+
fastifyCacheOptions.privacy = fastifyCache.privacy.PUBLIC;
|
|
60
|
+
} else {
|
|
61
|
+
fastifyCacheOptions.privacy = fastifyCache.privacy.NOCACHE;
|
|
62
|
+
}
|
|
63
|
+
fastify.register(fastifyCache, fastifyCacheOptions);
|
|
64
|
+
fastify.register(fastifyStatic, {
|
|
65
|
+
root: config.path
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* Run the server!
|
|
69
|
+
*/ let port, portMessage = "";
|
|
70
|
+
const start = async ()=>{
|
|
71
|
+
try {
|
|
72
|
+
port = await portfinder.getPortPromise({
|
|
73
|
+
port: Number(config.port)
|
|
74
|
+
});
|
|
75
|
+
if (port !== config.port) {
|
|
76
|
+
portMessage = `\n\n${kleur.yellow(`Warning: port ${config.port} was not available!`)}`;
|
|
77
|
+
config.port = port;
|
|
78
|
+
}
|
|
79
|
+
await fastify.listen({
|
|
80
|
+
port: config.port
|
|
81
|
+
});
|
|
82
|
+
const url = `${config.http2 ? "https" : "http"}://localhost:${config.port}`;
|
|
83
|
+
const messages = [
|
|
84
|
+
`${kleur.cyan("Static Server")} is up and running!`,
|
|
85
|
+
"",
|
|
86
|
+
`${kleur.cyan(url)}`,
|
|
87
|
+
"",
|
|
88
|
+
`Hit CTRL+C to shut it down.${portMessage}`
|
|
89
|
+
];
|
|
90
|
+
logger.log();
|
|
91
|
+
logger.log(boxen(messages.join("\n"), {
|
|
92
|
+
align: "center",
|
|
93
|
+
borderColor: "yellow",
|
|
94
|
+
padding: 1
|
|
95
|
+
}));
|
|
96
|
+
if (config.open) {
|
|
97
|
+
await open(url, {
|
|
98
|
+
url: true,
|
|
99
|
+
wait: false
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
fastify.log.error(error);
|
|
104
|
+
// eslint-disable-next-line unicorn/no-process-exit
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
start();
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { cert, key } from \"./certs.js\";\n\nimport Fastify from \"fastify\";\nimport boxen from \"boxen\";\nimport { config } from \"./parse.js\";\nimport fastifyCache from \"@fastify/caching\";\nimport fastifyCompress from \"@fastify/compress\";\nimport fastifyCors from \"@fastify/cors\";\nimport fastifyLogs from \"./logs.js\";\nimport fastifyStatic from \"@fastify/static\";\nimport kleur from \"kleur\";\nimport { logger } from \"./utilities.js\";\nimport open from \"open\";\nimport portfinder from \"portfinder\";\n\nconst fastifyOptions: {\n\tdisableRequestLogging?: boolean;\n\thttp2?: boolean;\n\thttps?: any;\n\tlogger?: any;\n} = {\n\tdisableRequestLogging: true,\n};\n\nif (config.logs) {\n\tfastifyOptions.logger = {\n\t\tlevel: \"info\",\n\t\ttransport: {\n\t\t\ttarget: \"pino-pretty\",\n\t\t\toptions: {\n\t\t\t\thideObject: true,\n\t\t\t\ttranslateTime: \"SYS:standard\",\n\t\t\t\tignore: \"pid,hostname,reqId,resTime,resTimeMs,level\",\n\t\t\t},\n\t\t},\n\t};\n}\n\nif (config.http2) {\n\tfastifyOptions.http2 = true;\n\tfastifyOptions.https = { key, cert };\n}\n\nconst fastify = Fastify(fastifyOptions);\n\nif (config.logs) {\n\tfastify.register(fastifyLogs);\n}\n\nif (config.gzip) {\n\tfastify.register(fastifyCompress, {\n\t\tglobal: true,\n\t\tencodings: [\"gzip\", \"deflate\", \"br\", \"identity\"],\n\t});\n}\n\nif (config.cors) {\n\tfastify.register(fastifyCors);\n}\n\nconst fastifyCacheOptions: {\n\texpiresIn?: number;\n\tserverExpiresIn?: number;\n\tprivacy?: any;\n} = {};\n\nif (config.cache > 0) {\n\tfastifyCacheOptions.expiresIn = config.cache;\n\tfastifyCacheOptions.serverExpiresIn = config.cache;\n\tfastifyCacheOptions.privacy = fastifyCache.privacy.PUBLIC;\n} else {\n\tfastifyCacheOptions.privacy = fastifyCache.privacy.NOCACHE;\n}\n\nfastify.register(fastifyCache, fastifyCacheOptions);\n\nfastify.register(fastifyStatic, {\n\troot: config.path,\n});\n\n/**\n * Run the server!\n */\nlet port: number,\n\tportMessage = \"\";\nconst start = async () => {\n\ttry {\n\t\tport = await portfinder.getPortPromise({ port: Number(config.port) });\n\t\tif (port !== config.port) {\n\t\t\tportMessage = `\\n\\n${kleur.yellow(\n\t\t\t\t`Warning: port ${config.port} was not available!`\n\t\t\t)}`;\n\t\t\tconfig.port = port;\n\t\t}\n\t\tawait fastify.listen({ port: config.port });\n\n\t\tconst url = `${config.http2 ? \"https\" : \"http\"}://localhost:${config.port}`;\n\t\tconst messages = [\n\t\t\t`${kleur.cyan(\"Static Server\")} is up and running!`,\n\t\t\t\"\",\n\t\t\t`${kleur.cyan(url)}`,\n\t\t\t\"\",\n\t\t\t`Hit CTRL+C to shut it down.${portMessage}`,\n\t\t];\n\n\t\tlogger.log();\n\t\tlogger.log(\n\t\t\tboxen(messages.join(\"\\n\"), {\n\t\t\t\talign: \"center\",\n\t\t\t\tborderColor: \"yellow\",\n\t\t\t\tpadding: 1,\n\t\t\t})\n\t\t);\n\n\t\tif (config.open) {\n\t\t\tawait open(url, {\n\t\t\t\turl: true,\n\t\t\t\twait: false,\n\t\t\t});\n\t\t}\n\t} catch (error) {\n\t\tfastify.log.error(error);\n\t\t// eslint-disable-next-line unicorn/no-process-exit\n\t\tprocess.exit(1);\n\t}\n};\nstart();\n"],"names":["cert","key","Fastify","boxen","config","fastifyCache","fastifyCompress","fastifyCors","fastifyLogs","fastifyStatic","kleur","logger","open","portfinder","fastifyOptions","disableRequestLogging","logs","level","transport","target","options","hideObject","translateTime","ignore","http2","https","fastify","register","gzip","global","encodings","cors","fastifyCacheOptions","cache","expiresIn","serverExpiresIn","privacy","PUBLIC","NOCACHE","root","path","port","portMessage","start","getPortPromise","Number","yellow","listen","url","messages","cyan","log","join","align","borderColor","padding","wait","error","process","exit"],"mappings":"AAAA,SAASA,IAAI,EAAEC,GAAG,QAAQ,aAAa;AAEvC,OAAOC,aAAa,UAAU;AAC9B,OAAOC,WAAW,QAAQ;AAC1B,SAASC,MAAM,QAAQ,aAAa;AACpC,OAAOC,kBAAkB,mBAAmB;AAC5C,OAAOC,qBAAqB,oBAAoB;AAChD,OAAOC,iBAAiB,gBAAgB;AACxC,OAAOC,iBAAiB,YAAY;AACpC,OAAOC,mBAAmB,kBAAkB;AAC5C,OAAOC,WAAW,QAAQ;AAC1B,SAASC,MAAM,QAAQ,iBAAiB;AACxC,OAAOC,UAAU,OAAO;AACxB,OAAOC,gBAAgB,aAAa;AAEpC,MAAMC,iBAKF;IACHC,uBAAuB,IAAI;AAC5B;AAEA,IAAIX,OAAOY,IAAI,EAAE;IAChBF,eAAeH,MAAM,GAAG;QACvBM,OAAO;QACPC,WAAW;YACVC,QAAQ;YACRC,SAAS;gBACRC,YAAY,IAAI;gBAChBC,eAAe;gBACfC,QAAQ;YACT;QACD;IACD;AACD,CAAC;AAED,IAAInB,OAAOoB,KAAK,EAAE;IACjBV,eAAeU,KAAK,GAAG,IAAI;IAC3BV,eAAeW,KAAK,GAAG;QAAExB;QAAKD;IAAK;AACpC,CAAC;AAED,MAAM0B,UAAUxB,QAAQY;AAExB,IAAIV,OAAOY,IAAI,EAAE;IAChBU,QAAQC,QAAQ,CAACnB;AAClB,CAAC;AAED,IAAIJ,OAAOwB,IAAI,EAAE;IAChBF,QAAQC,QAAQ,CAACrB,iBAAiB;QACjCuB,QAAQ,IAAI;QACZC,WAAW;YAAC;YAAQ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2B,EAAEN,YAAY,CAAC;SAC3C;QAED/B,OAAOwC,GAAG;QACVxC,OAAOwC,GAAG,CACThD,MAAM8C,SAASG,IAAI,CAAC,OAAO;YAC1BC,OAAO;YACPC,aAAa;YACbC,SAAS;QACV;QAGD,IAAInD,OAAOQ,IAAI,EAAE;YAChB,MAAMA,KAAKoC,KAAK;gBACfA,KAAK,IAAI;gBACTQ,MAAM,KAAK;YACZ;QACD,CAAC;IACF,EAAE,OAAOC,OAAO;QACf/B,QAAQyB,GAAG,CAACM,KAAK,CAACA;QAClB,mDAAmD;QACnDC,QAAQC,IAAI,CAAC;IACd;AACD;AACAhB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Logger } from "@node-cli/logger";
|
|
2
|
+
export declare const logger: Logger;
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper method for lodash `merge()` and `mergeWith()` methods.
|
|
5
|
+
*
|
|
6
|
+
* Without the `customizer` function, this method recursively merges own and inherited
|
|
7
|
+
* enumerable string keyed properties of source objects into the destination object.
|
|
8
|
+
* Source properties that resolve to undefined are skipped if a destination value exists.
|
|
9
|
+
* Array and plain object properties are merged recursively. Other objects and value
|
|
10
|
+
* types are overridden by assignment. Source objects are applied from left to right.
|
|
11
|
+
* Subsequent sources overwrite property assignments of previous sources.
|
|
12
|
+
*
|
|
13
|
+
* With the `customizer` function, the behavior is the same except that `customizer` is
|
|
14
|
+
* invoked to produce the merged values of the destination and source properties.
|
|
15
|
+
* If customizer returns undefined, merging is handled by the `shallowMerge` instead.
|
|
16
|
+
* The customizer is invoked with six arguments: `(objValue, srcValue, key, object,
|
|
17
|
+
* source, stack)`
|
|
18
|
+
* @param {object} objA
|
|
19
|
+
* @param {object} objB
|
|
20
|
+
* @param {function} customizer
|
|
21
|
+
* @returns {object}
|
|
22
|
+
*
|
|
23
|
+
* !! WARNING: this method will mutate objA
|
|
24
|
+
*/
|
|
25
|
+
export declare const shallowMerge: (objectA: any, objectB: any, customizer?: any) => object;
|
|
26
|
+
export declare const meowOptionsHelper: (parameters_: {
|
|
27
|
+
flags?: any;
|
|
28
|
+
parameters?: any;
|
|
29
|
+
usage?: any;
|
|
30
|
+
examples?: any;
|
|
31
|
+
}) => {
|
|
32
|
+
helpText: string;
|
|
33
|
+
options: any;
|
|
34
|
+
};
|
|
35
|
+
export declare const meowParserHelper: (parameters: {
|
|
36
|
+
cli: any;
|
|
37
|
+
restrictions?: any;
|
|
38
|
+
}) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Log multiple error messages at the prompt using `console.error` behind the scenes.
|
|
41
|
+
* @param {string[]} errorMessages array of error message to display line by line
|
|
42
|
+
* @param {number} [exitStatus=0] the process will exit with this value, unless set to false
|
|
43
|
+
*/
|
|
44
|
+
export declare const displayErrorMessages: (errorMessages: any[], exitStatus?: number) => void;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/* eslint-disable unicorn/no-process-exit */ import { Logger } from "@node-cli/logger";
|
|
2
|
+
import Table from "cli-table3";
|
|
3
|
+
import _ from "lodash";
|
|
4
|
+
import kleur from "kleur";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
export const logger = new Logger({
|
|
7
|
+
boring: process.env.NODE_ENV === "test"
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Converts the first character of string to upper case
|
|
11
|
+
* @param {string} str the string to convert
|
|
12
|
+
* @returns {string} the converted string
|
|
13
|
+
*/ const upperFirst = (string_)=>string_[0].toUpperCase() + string_.slice(1);
|
|
14
|
+
/**
|
|
15
|
+
* Wrapper method for lodash `merge()` and `mergeWith()` methods.
|
|
16
|
+
*
|
|
17
|
+
* Without the `customizer` function, this method recursively merges own and inherited
|
|
18
|
+
* enumerable string keyed properties of source objects into the destination object.
|
|
19
|
+
* Source properties that resolve to undefined are skipped if a destination value exists.
|
|
20
|
+
* Array and plain object properties are merged recursively. Other objects and value
|
|
21
|
+
* types are overridden by assignment. Source objects are applied from left to right.
|
|
22
|
+
* Subsequent sources overwrite property assignments of previous sources.
|
|
23
|
+
*
|
|
24
|
+
* With the `customizer` function, the behavior is the same except that `customizer` is
|
|
25
|
+
* invoked to produce the merged values of the destination and source properties.
|
|
26
|
+
* If customizer returns undefined, merging is handled by the `shallowMerge` instead.
|
|
27
|
+
* The customizer is invoked with six arguments: `(objValue, srcValue, key, object,
|
|
28
|
+
* source, stack)`
|
|
29
|
+
* @param {object} objA
|
|
30
|
+
* @param {object} objB
|
|
31
|
+
* @param {function} customizer
|
|
32
|
+
* @returns {object}
|
|
33
|
+
*
|
|
34
|
+
* !! WARNING: this method will mutate objA
|
|
35
|
+
*/ export const shallowMerge = (objectA, objectB, customizer)=>{
|
|
36
|
+
return typeof customizer === "function" ? _.mergeWith(objectA, objectB, customizer) : _.merge(objectA, objectB);
|
|
37
|
+
};
|
|
38
|
+
export const meowOptionsHelper = (parameters_)=>{
|
|
39
|
+
let { usage , flags , parameters , examples } = parameters_;
|
|
40
|
+
let helpText = "", usageText = "";
|
|
41
|
+
const commandPrefix = "> ";
|
|
42
|
+
const options = {
|
|
43
|
+
importMeta: import.meta,
|
|
44
|
+
allowUnknownFlags: false,
|
|
45
|
+
autoHelp: false,
|
|
46
|
+
autoVersion: false,
|
|
47
|
+
description: false,
|
|
48
|
+
flags
|
|
49
|
+
};
|
|
50
|
+
const commonTableConfiguration = {
|
|
51
|
+
chars: {
|
|
52
|
+
bottom: "",
|
|
53
|
+
"bottom-left": "",
|
|
54
|
+
"bottom-mid": "",
|
|
55
|
+
"bottom-right": "",
|
|
56
|
+
left: "",
|
|
57
|
+
"left-mid": "",
|
|
58
|
+
mid: "",
|
|
59
|
+
"mid-mid": "",
|
|
60
|
+
middle: "",
|
|
61
|
+
right: "",
|
|
62
|
+
"right-mid": "",
|
|
63
|
+
top: "",
|
|
64
|
+
"top-left": "",
|
|
65
|
+
"top-mid": "",
|
|
66
|
+
"top-right": ""
|
|
67
|
+
},
|
|
68
|
+
style: {
|
|
69
|
+
"padding-left": 0,
|
|
70
|
+
"padding-right": 2
|
|
71
|
+
},
|
|
72
|
+
wordWrap: true
|
|
73
|
+
};
|
|
74
|
+
if (usage) {
|
|
75
|
+
if (typeof usage === "string") {
|
|
76
|
+
const optionalParameters = usage.match(/\[(.*?)]/g);
|
|
77
|
+
const requiredParameters = usage.match(/<(.*?)>/g);
|
|
78
|
+
if (optionalParameters) {
|
|
79
|
+
for (const item of optionalParameters){
|
|
80
|
+
usage = usage.replace(item, `${kleur.green(item)}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (requiredParameters) {
|
|
84
|
+
for (const item of requiredParameters){
|
|
85
|
+
usage = usage.replace(item, `${kleur.red(item)}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
usageText = ` Usage:\n ${commandPrefix}${usage}`;
|
|
89
|
+
}
|
|
90
|
+
if (typeof usage === "boolean") {
|
|
91
|
+
const processName = path.basename(process.argv[1]);
|
|
92
|
+
usageText = ` Usage:\n ${commandPrefix}${processName}`;
|
|
93
|
+
if (flags) {
|
|
94
|
+
usageText += kleur.green(" [options]");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (flags) {
|
|
99
|
+
const flagsTable = new Table(commonTableConfiguration);
|
|
100
|
+
helpText += "\n\n Options:\n";
|
|
101
|
+
for (const item of Object.keys(flags).sort()){
|
|
102
|
+
const flag = flags[item];
|
|
103
|
+
const aliasCell = flag.shortFlag ? ` ${kleur.blue(`-${flag.shortFlag}, --${item}`)}` : ` ${kleur.blue(` --${item}`)}`;
|
|
104
|
+
const defaultCell = flag.default === undefined ? "" : `${kleur.grey(`(default: ${flag.default})`)}`;
|
|
105
|
+
flagsTable.push([
|
|
106
|
+
aliasCell,
|
|
107
|
+
flag.description,
|
|
108
|
+
defaultCell
|
|
109
|
+
]);
|
|
110
|
+
}
|
|
111
|
+
helpText += flagsTable.toString();
|
|
112
|
+
}
|
|
113
|
+
if (parameters) {
|
|
114
|
+
const parametersTable = new Table(commonTableConfiguration);
|
|
115
|
+
helpText += "\n\n";
|
|
116
|
+
for (const item of Object.keys(parameters).sort()){
|
|
117
|
+
const parameter = parameters[item];
|
|
118
|
+
const headerCell = ` ${upperFirst(item)}:`;
|
|
119
|
+
const defaultCell = parameter.default === undefined ? "" : `${kleur.grey(`(default: ${parameter.default})`)}`;
|
|
120
|
+
parametersTable.push([
|
|
121
|
+
headerCell,
|
|
122
|
+
parameter.description,
|
|
123
|
+
defaultCell
|
|
124
|
+
]);
|
|
125
|
+
if (typeof usage === "boolean") {
|
|
126
|
+
usageText += ` ${kleur.green(`[${item}]`)}`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
helpText += parametersTable.toString();
|
|
130
|
+
}
|
|
131
|
+
if (examples) {
|
|
132
|
+
helpText += "\n\n Examples:\n";
|
|
133
|
+
for (const item of examples){
|
|
134
|
+
helpText += `\n ${kleur.grey(`${item.comment}`)}\n`;
|
|
135
|
+
helpText += ` ${kleur.blue(`${commandPrefix}${item.command}`)}\n`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
helpText: `\n${usageText}${helpText}`,
|
|
140
|
+
options
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
export const meowParserHelper = (parameters)=>{
|
|
144
|
+
const { cli , restrictions } = parameters;
|
|
145
|
+
try {
|
|
146
|
+
if (cli.flags.help) {
|
|
147
|
+
cli.showHelp();
|
|
148
|
+
process.exit(0);
|
|
149
|
+
}
|
|
150
|
+
} catch {
|
|
151
|
+
// nothing to declare officer
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
if (cli.flags.version) {
|
|
155
|
+
cli.showVersion();
|
|
156
|
+
process.exit(0);
|
|
157
|
+
}
|
|
158
|
+
} catch {
|
|
159
|
+
// nothing to declare officer
|
|
160
|
+
}
|
|
161
|
+
if (restrictions && restrictions.length > 0) {
|
|
162
|
+
for (const rule of restrictions){
|
|
163
|
+
if (rule.test(cli.flags)) {
|
|
164
|
+
// eslint-disable-next-line no-console
|
|
165
|
+
console.error(rule.message(cli.flags));
|
|
166
|
+
process.exit(rule.exit);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Log multiple error messages at the prompt using `console.error` behind the scenes.
|
|
173
|
+
* @param {string[]} errorMessages array of error message to display line by line
|
|
174
|
+
* @param {number} [exitStatus=0] the process will exit with this value, unless set to false
|
|
175
|
+
*/ export const displayErrorMessages = (errorMessages, exitStatus = 0)=>{
|
|
176
|
+
if (errorMessages && errorMessages.length > 0) {
|
|
177
|
+
logger.log();
|
|
178
|
+
for (const message of errorMessages){
|
|
179
|
+
logger.error(message);
|
|
180
|
+
}
|
|
181
|
+
logger.log();
|
|
182
|
+
if (typeof exitStatus === "number") {
|
|
183
|
+
process.exit(exitStatus);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
//# sourceMappingURL=utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["/* eslint-disable unicorn/no-process-exit */\n\nimport { Logger } from \"@node-cli/logger\";\nimport Table from \"cli-table3\";\nimport _ from \"lodash\";\nimport boxen from \"boxen\";\nimport kleur from \"kleur\";\nimport open from \"open\";\nimport path from \"node:path\";\nimport portfinder from \"portfinder\";\nexport const logger = new Logger({\n\tboring: process.env.NODE_ENV === \"test\",\n});\n\n/**\n * Converts the first character of string to upper case\n * @param {string} str the string to convert\n * @returns {string} the converted string\n */\nconst upperFirst = (string_: string | any[]): string =>\n\tstring_[0].toUpperCase() + string_.slice(1);\n\n/**\n * Wrapper method for lodash `merge()` and `mergeWith()` methods.\n *\n * Without the `customizer` function, this method recursively merges own and inherited\n * enumerable string keyed properties of source objects into the destination object.\n * Source properties that resolve to undefined are skipped if a destination value exists.\n * Array and plain object properties are merged recursively. Other objects and value\n * types are overridden by assignment. Source objects are applied from left to right.\n * Subsequent sources overwrite property assignments of previous sources.\n *\n * With the `customizer` function, the behavior is the same except that `customizer` is\n * invoked to produce the merged values of the destination and source properties.\n * If customizer returns undefined, merging is handled by the `shallowMerge` instead.\n * The customizer is invoked with six arguments: `(objValue, srcValue, key, object,\n * source, stack)`\n * @param {object} objA\n * @param {object} objB\n * @param {function} customizer\n * @returns {object}\n *\n * !! WARNING: this method will mutate objA\n */\nexport const shallowMerge = (\n\tobjectA: any,\n\tobjectB: any,\n\tcustomizer?: any\n): object => {\n\treturn typeof customizer === \"function\"\n\t\t? _.mergeWith(objectA, objectB, customizer)\n\t\t: _.merge(objectA, objectB);\n};\n\nexport const meowOptionsHelper = (parameters_: {\n\tflags?: any;\n\tparameters?: any;\n\tusage?: any;\n\texamples?: any;\n}) => {\n\tlet { usage, flags, parameters, examples } = parameters_;\n\tlet helpText = \"\",\n\t\tusageText = \"\";\n\tconst commandPrefix = \"> \";\n\tconst options: any = {\n\t\timportMeta: import.meta,\n\t\tallowUnknownFlags: false,\n\t\tautoHelp: false,\n\t\tautoVersion: false,\n\t\tdescription: false,\n\t\tflags,\n\t};\n\tconst commonTableConfiguration = {\n\t\tchars: {\n\t\t\tbottom: \"\",\n\t\t\t\"bottom-left\": \"\",\n\t\t\t\"bottom-mid\": \"\",\n\t\t\t\"bottom-right\": \"\",\n\t\t\tleft: \"\",\n\t\t\t\"left-mid\": \"\",\n\t\t\tmid: \"\",\n\t\t\t\"mid-mid\": \"\",\n\t\t\tmiddle: \"\",\n\t\t\tright: \"\",\n\t\t\t\"right-mid\": \"\",\n\t\t\ttop: \"\",\n\t\t\t\"top-left\": \"\",\n\t\t\t\"top-mid\": \"\",\n\t\t\t\"top-right\": \"\",\n\t\t},\n\t\tstyle: {\n\t\t\t\"padding-left\": 0,\n\t\t\t\"padding-right\": 2,\n\t\t},\n\t\twordWrap: true,\n\t};\n\n\tif (usage) {\n\t\tif (typeof usage === \"string\") {\n\t\t\tconst optionalParameters = usage.match(/\\[(.*?)]/g);\n\t\t\tconst requiredParameters = usage.match(/<(.*?)>/g);\n\t\t\tif (optionalParameters) {\n\t\t\t\tfor (const item of optionalParameters) {\n\t\t\t\t\tusage = usage.replace(item, `${kleur.green(item)}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (requiredParameters) {\n\t\t\t\tfor (const item of requiredParameters) {\n\t\t\t\t\tusage = usage.replace(item, `${kleur.red(item)}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tusageText = ` Usage:\\n ${commandPrefix}${usage}`;\n\t\t}\n\t\tif (typeof usage === \"boolean\") {\n\t\t\tconst processName = path.basename(process.argv[1]);\n\t\t\tusageText = ` Usage:\\n ${commandPrefix}${processName}`;\n\t\t\tif (flags) {\n\t\t\t\tusageText += kleur.green(\" [options]\");\n\t\t\t}\n\t\t}\n\t}\n\n\tif (flags) {\n\t\tconst flagsTable = new Table(commonTableConfiguration);\n\t\thelpText += \"\\n\\n Options:\\n\";\n\n\t\tfor (const item of Object.keys(flags).sort()) {\n\t\t\tconst flag = flags[item];\n\t\t\tconst aliasCell = flag.shortFlag\n\t\t\t\t? ` ${kleur.blue(`-${flag.shortFlag}, --${item}`)}`\n\t\t\t\t: ` ${kleur.blue(` --${item}`)}`;\n\t\t\tconst defaultCell =\n\t\t\t\tflag.default === undefined\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: `${kleur.grey(`(default: ${flag.default})`)}`;\n\t\t\tflagsTable.push([aliasCell, flag.description, defaultCell]);\n\t\t}\n\t\thelpText += flagsTable.toString();\n\t}\n\n\tif (parameters) {\n\t\tconst parametersTable = new Table(commonTableConfiguration);\n\t\thelpText += \"\\n\\n\";\n\n\t\tfor (const item of Object.keys(parameters).sort()) {\n\t\t\tconst parameter = parameters[item];\n\t\t\tconst headerCell = ` ${upperFirst(item)}:`;\n\t\t\tconst defaultCell =\n\t\t\t\tparameter.default === undefined\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: `${kleur.grey(`(default: ${parameter.default})`)}`;\n\t\t\tparametersTable.push([headerCell, parameter.description, defaultCell]);\n\t\t\tif (typeof usage === \"boolean\") {\n\t\t\t\tusageText += ` ${kleur.green(`[${item}]`)}`;\n\t\t\t}\n\t\t}\n\t\thelpText += parametersTable.toString();\n\t}\n\n\tif (examples) {\n\t\thelpText += \"\\n\\n Examples:\\n\";\n\t\tfor (const item of examples) {\n\t\t\thelpText += `\\n ${kleur.grey(`${item.comment}`)}\\n`;\n\t\t\thelpText += ` ${kleur.blue(`${commandPrefix}${item.command}`)}\\n`;\n\t\t}\n\t}\n\n\treturn {\n\t\thelpText: `\\n${usageText}${helpText}`,\n\t\toptions,\n\t};\n};\n\nexport const meowParserHelper = (parameters: {\n\tcli: any;\n\trestrictions?: any;\n}) => {\n\tconst { cli, restrictions } = parameters;\n\ttry {\n\t\tif (cli.flags.help) {\n\t\t\tcli.showHelp();\n\t\t\tprocess.exit(0);\n\t\t}\n\t} catch {\n\t\t// nothing to declare officer\n\t}\n\n\ttry {\n\t\tif (cli.flags.version) {\n\t\t\tcli.showVersion();\n\t\t\tprocess.exit(0);\n\t\t}\n\t} catch {\n\t\t// nothing to declare officer\n\t}\n\n\tif (restrictions && restrictions.length > 0) {\n\t\tfor (const rule of restrictions) {\n\t\t\tif (rule.test(cli.flags)) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.error(rule.message(cli.flags));\n\t\t\t\tprocess.exit(rule.exit);\n\t\t\t}\n\t\t}\n\t}\n};\n\n/**\n * Log multiple error messages at the prompt using `console.error` behind the scenes.\n * @param {string[]} errorMessages array of error message to display line by line\n * @param {number} [exitStatus=0] the process will exit with this value, unless set to false\n */\nexport const displayErrorMessages = (\n\terrorMessages: any[],\n\texitStatus: number = 0\n) => {\n\tif (errorMessages && errorMessages.length > 0) {\n\t\tlogger.log();\n\t\tfor (const message of errorMessages) {\n\t\t\tlogger.error(message);\n\t\t}\n\t\tlogger.log();\n\n\t\tif (typeof exitStatus === \"number\") {\n\t\t\tprocess.exit(exitStatus);\n\t\t}\n\t}\n};\n"],"names":["Logger","Table","_","kleur","path","logger","boring","process","env","NODE_ENV","upperFirst","string_","toUpperCase","slice","shallowMerge","objectA","objectB","customizer","mergeWith","merge","meowOptionsHelper","parameters_","usage","flags","parameters","examples","helpText","usageText","commandPrefix","options","importMeta","allowUnknownFlags","autoHelp","autoVersion","description","commonTableConfiguration","chars","bottom","left","mid","middle","right","top","style","wordWrap","optionalParameters","match","requiredParameters","item","replace","green","red","processName","basename","argv","flagsTable","Object","keys","sort","flag","aliasCell","shortFlag","blue","defaultCell","default","undefined","grey","push","toString","parametersTable","parameter","headerCell","comment","command","meowParserHelper","cli","restrictions","help","showHelp","exit","version","showVersion","length","rule","test","console","error","message","displayErrorMessages","errorMessages","exitStatus","log"],"mappings":"AAAA,0CAA0C,GAE1C,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,WAAW,aAAa;AAC/B,OAAOC,OAAO,SAAS;AAEvB,OAAOC,WAAW,QAAQ;AAE1B,OAAOC,UAAU,YAAY;AAE7B,OAAO,MAAMC,SAAS,IAAIL,OAAO;IAChCM,QAAQC,QAAQC,GAAG,CAACC,QAAQ,KAAK;AAClC,GAAG;AAEH;;;;CAIC,GACD,MAAMC,aAAa,CAACC,UACnBA,OAAO,CAAC,EAAE,CAACC,WAAW,KAAKD,QAAQE,KAAK,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,MAAMC,eAAe,CAC3BC,SACAC,SACAC,aACY;IACZ,OAAO,OAAOA,eAAe,aAC1Bf,EAAEgB,SAAS,CAACH,SAASC,SAASC,cAC9Bf,EAAEiB,KAAK,CAACJ,SAASC,QAAQ;AAC7B,EAAE;AAEF,OAAO,MAAMI,oBAAoB,CAACC,cAK5B;IACL,IAAI,EAAEC,MAAK,EAAEC,MAAK,EAAEC,WAAU,EAAEC,SAAQ,EAAE,GAAGJ;IAC7C,IAAIK,WAAW,IACdC,YAAY;IACb,MAAMC,gBAAgB;IACtB,MAAMC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D,OAAO,MAAMS,uBAAuB,CACnCC,eACAC,aAAqB,CAAC,GAClB;IACJ,IAAID,iBAAiBA,cAAcP,MAAM,GAAG,GAAG;QAC9C7E,OAAOsF,GAAG;QACV,KAAK,MAAMJ,WAAWE,cAAe;YACpCpF,OAAOiF,KAAK,CAACC;QACd;QACAlF,OAAOsF,GAAG;QAEV,IAAI,OAAOD,eAAe,UAAU;YACnCnF,QAAQwE,IAAI,CAACW;QACd,CAAC;IACF,CAAC;AACF,EAAE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@node-cli/static-server",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Arno Versini",
|
|
6
|
+
"description": "A simple, zero-configuration, command line HTTP server to serve static files locally",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"types": "./dist/server.d.ts",
|
|
9
|
+
"exports": "./dist/server.js",
|
|
10
|
+
"bin": {
|
|
11
|
+
"static-server": "dist/server.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"node": ">=16",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@fastify/caching": "8.3.0",
|
|
19
|
+
"@fastify/compress": "6.2.1",
|
|
20
|
+
"@fastify/cors": "8.2.1",
|
|
21
|
+
"@fastify/static": "6.10.1",
|
|
22
|
+
"@node-cli/logger": "^0.0.6",
|
|
23
|
+
"boxen": "7.1.0",
|
|
24
|
+
"cli-table3": "0.6.3",
|
|
25
|
+
"fastify": "4.17.0",
|
|
26
|
+
"fastify-plugin": "4.5.0",
|
|
27
|
+
"fs-extra": "11.1.1",
|
|
28
|
+
"kleur": "4.1.4",
|
|
29
|
+
"lodash": "4.17.21",
|
|
30
|
+
"meow": "12.0.1",
|
|
31
|
+
"open": "7.4.2",
|
|
32
|
+
"pino-pretty": "10.0.0",
|
|
33
|
+
"portfinder": "1.0.32"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "npm-run-all --serial clean build:types build:js",
|
|
37
|
+
"build:js": "swc --source-maps --out-dir dist src --copy-files",
|
|
38
|
+
"build:types": "tsc",
|
|
39
|
+
"clean": "rimraf dist types coverage",
|
|
40
|
+
"lint": "eslint \"src/*.ts\"",
|
|
41
|
+
"test": "jest",
|
|
42
|
+
"test:coverage": "echo 'No coverage available yet'",
|
|
43
|
+
"watch": "swc --watch --out-dir dist src"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"gitHead": "19d2ea42b43364d5208bda01c93b75efc90d36d7"
|
|
49
|
+
}
|