@node-cli/static-server 0.0.8 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/certs.d.ts +2 -2
- package/dist/certs.js.map +1 -1
- package/dist/defaults.d.ts +5 -2
- package/dist/defaults.js +5 -2
- package/dist/defaults.js.map +1 -1
- package/dist/directories.d.ts +6 -0
- package/dist/directories.js +117 -0
- package/dist/directories.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/parse.d.ts +13 -8
- package/dist/parse.js +19 -34
- package/dist/parse.js.map +1 -1
- package/dist/server.d.ts +2 -1
- package/dist/server.js +44 -23
- package/dist/server.js.map +1 -1
- package/dist/utilities.d.ts +0 -21
- package/dist/utilities.js +0 -160
- package/dist/utilities.js.map +1 -1
- package/package.json +19 -19
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ At that point, you should be able to visit `http://localhost:8080` and see the f
|
|
|
28
28
|
| -------------------------- | ------- | ----------------------------------------------------------- |
|
|
29
29
|
| `-c` or `--cache <number>` | 0 | Time in seconds for caching files |
|
|
30
30
|
| `-C` or `--cors` | false | Set CORS headers to \* to allow requests from any origin |
|
|
31
|
+
| `-d` or `--dirs` | false | List the directory's contents |
|
|
31
32
|
| `-h` or `--help` | | Display help instructions |
|
|
32
33
|
| `-H` or `--http2` | false | Enable HTTP v2 and SSL (https) |
|
|
33
34
|
| `-l` or `--logs` | false | Log HTTP requests at the prompt |
|
package/dist/certs.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const cert
|
|
2
|
-
export declare const key
|
|
1
|
+
export declare const cert: string;
|
|
2
|
+
export declare const key: string;
|
package/dist/certs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/certs.ts"],"sourcesContent":["export const cert = `-----BEGIN CERTIFICATE-----\nMIICpDCCAYwCCQC8TqYqUGuZJDANBgkqhkiG9w0BAQsFADA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2P72BBlayHH1MbofaP1YJrWhBbYk+g3c/i9Tba0KLpnXN2x\nxPC8a3eBd9Gf+fWyfWg0vwC1AoGBALJ/4eeRW9phQLbOgZ+jvFLdWYo83gsVcHgi\nqfZxAZyCgYqT9NZJ0NHxBRFEu+dB7b0QL3bikkc7Xm0Deu4QCs2oozGf7tfD9wfg\nm3+5q3f5YL6O3pPHlbDlT4t6YEbGu9spH/rc5uY18vbTVa1ZNoCGuEswd1jYwjla\nIKzcb0wnAoGADE80xrFwYuy/BJFTPb2C7U//i6StymSG3he7p+RAvKKPBFXVFkTT\nM+X+O8oECdPoBmQ6I3Wh2QHkua4waPPdB5Md6DgnSgK/Wd3Fypz+5XakyA+j5LRJ\nCK+IKNdZGb8ICaKKmS2FhaOa860GpdQWM8z6P3FgKRwgQ2k+684oowg=\n-----END RSA PRIVATE KEY-----`;\n"],"names":["cert","key"],"mappings":"AAAA,OAAO,MAAMA,
|
|
1
|
+
{"version":3,"sources":["../src/certs.ts"],"sourcesContent":["export const cert: string = `-----BEGIN CERTIFICATE-----\nMIICpDCCAYwCCQC8TqYqUGuZJDANBgkqhkiG9w0BAQsFADAUMRIwEAYDVQQDDAls\nb2NhbGhvc3QwHhcNMjMwNTEyMjMxOTU3WhcNMzMwNTA5MjMxOTU3WjAUMRIwEAYD\nVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDy\nc+8Eb+Y/oXvnIgja8nJycczRzDWQvj9Q242yy4M4eRJCnw+aFGkLWvUL4h+p7kKw\nPK9FDv02WK81YDzbfvpAe0PepPChMcGqIiznnu14J+/dJ14ZFnitNwG6hYCXkjNt\nUvGpQgSRe3LEo4FKMqrURk2hhhZAdaC1Qe05ohvbgJBW7UBI/+qrxP8KAjb3Nqke\nhVSRMUCKsBGoNceUgFfrgyVDKiLsIuKdWcjvVb0hrGwZW4chm7EhoJaARnByupuw\nzjRSpkbFmgZjIq0GCLvFi/KJu5OwV0ZaZMLEO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EY-----`;\n"],"names":["cert","key"],"mappings":"AAAA,OAAO,MAAMA,OAAe,CAAC;;;;;;;;;;;;;;;;yBAgBJ,CAAC,CAAC;AAE3B,OAAO,MAAMC,MAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;6BA0BC,CAAC,CAAC"}
|
package/dist/defaults.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const defaultFlags: {
|
|
2
2
|
cache: number;
|
|
3
3
|
cors: boolean;
|
|
4
|
+
dirs: boolean;
|
|
4
5
|
gzip: boolean;
|
|
5
6
|
http2: boolean;
|
|
6
7
|
logs: boolean;
|
|
7
8
|
open: boolean;
|
|
8
|
-
path: string;
|
|
9
9
|
port: number;
|
|
10
10
|
};
|
|
11
|
+
export declare const defaultParameters: {
|
|
12
|
+
"0": string;
|
|
13
|
+
};
|
package/dist/defaults.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const defaultFlags = {
|
|
2
2
|
cache: 0,
|
|
3
3
|
cors: false,
|
|
4
|
+
dirs: false,
|
|
4
5
|
gzip: true,
|
|
5
6
|
http2: false,
|
|
6
7
|
logs: false,
|
|
7
8
|
open: false,
|
|
8
|
-
path: `${process.cwd()}/`,
|
|
9
9
|
port: 8080
|
|
10
10
|
};
|
|
11
|
+
export const defaultParameters = {
|
|
12
|
+
"0": `${process.cwd()}/`
|
|
13
|
+
};
|
|
11
14
|
|
|
12
15
|
//# sourceMappingURL=defaults.js.map
|
package/dist/defaults.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const
|
|
1
|
+
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const defaultFlags = {\n\tcache: 0,\n\tcors: false,\n\tdirs: false,\n\tgzip: true,\n\thttp2: false,\n\tlogs: false,\n\topen: false,\n\tport: 8080,\n};\n\nexport const defaultParameters = {\n\t\"0\": `${process.cwd()}/`,\n};\n"],"names":["defaultFlags","cache","cors","dirs","gzip","http2","logs","open","port","defaultParameters","process","cwd"],"mappings":"AAAA,OAAO,MAAMA,eAAe;IAC3BC,OAAO;IACPC,MAAM,KAAK;IACXC,MAAM,KAAK;IACXC,MAAM,IAAI;IACVC,OAAO,KAAK;IACZC,MAAM,KAAK;IACXC,MAAM,KAAK;IACXC,MAAM;AACP,EAAE;AAEF,OAAO,MAAMC,oBAAoB;IAChC,KAAK,CAAC,EAAEC,QAAQC,GAAG,GAAG,CAAC,CAAC;AACzB,EAAE"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export const renderDirectories = (directories, files)=>{
|
|
2
|
+
const directoriesList = `${directories.map((directory)=>`<li><a class="folder" href="${directory.href}">${directory.name}/</a></li>`).join("\n ")}`;
|
|
3
|
+
const filesList = `${files.map((file)=>`<li><a class="file" href="${file.href}">${file.name}</a></li>`).join("\n ")}`;
|
|
4
|
+
return `
|
|
5
|
+
<!DOCTYPE html>
|
|
6
|
+
<html lang="en">
|
|
7
|
+
<head>
|
|
8
|
+
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
|
|
9
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
10
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
11
|
+
|
|
12
|
+
<title>Static Server Directory Listing</title>
|
|
13
|
+
|
|
14
|
+
<style>
|
|
15
|
+
body {
|
|
16
|
+
-webkit-font-smoothing: antialiased;
|
|
17
|
+
font-family: -apple-system, Calibri, "Helvetica Neue", sans-serif;
|
|
18
|
+
margin: 0;
|
|
19
|
+
padding: 20px;
|
|
20
|
+
}
|
|
21
|
+
main {
|
|
22
|
+
max-width: 900px;
|
|
23
|
+
}
|
|
24
|
+
header {
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-wrap: wrap;
|
|
27
|
+
justify-content: space-between;
|
|
28
|
+
}
|
|
29
|
+
h1 {
|
|
30
|
+
color: #000;
|
|
31
|
+
font-size: 18px;
|
|
32
|
+
font-weight: bold;
|
|
33
|
+
margin-top: 0;
|
|
34
|
+
}
|
|
35
|
+
ul {
|
|
36
|
+
margin: 0 0 0 -2px;
|
|
37
|
+
padding: 20px 0 0 0;
|
|
38
|
+
}
|
|
39
|
+
ul li {
|
|
40
|
+
display: flex;
|
|
41
|
+
font-size: 14px;
|
|
42
|
+
justify-content: space-between;
|
|
43
|
+
list-style: none;
|
|
44
|
+
}
|
|
45
|
+
a {
|
|
46
|
+
text-decoration: none;
|
|
47
|
+
}
|
|
48
|
+
ul a {
|
|
49
|
+
color: #000;
|
|
50
|
+
display: block;
|
|
51
|
+
margin: 0 -5px;
|
|
52
|
+
overflow: hidden;
|
|
53
|
+
padding: 10px 5px;
|
|
54
|
+
text-overflow: ellipsis;
|
|
55
|
+
white-space: nowrap;
|
|
56
|
+
width: 100%;
|
|
57
|
+
}
|
|
58
|
+
svg {
|
|
59
|
+
height: 13px;
|
|
60
|
+
vertical-align: text-bottom;
|
|
61
|
+
}
|
|
62
|
+
ul a::before {
|
|
63
|
+
display: inline-block;
|
|
64
|
+
vertical-align: middle;
|
|
65
|
+
margin-right: 10px;
|
|
66
|
+
width: 24px;
|
|
67
|
+
text-align: center;
|
|
68
|
+
line-height: 12px;
|
|
69
|
+
}
|
|
70
|
+
ul a.file::before {
|
|
71
|
+
content: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='currentColor' viewBox='0 0 16 16'> <path d='M14 4.5V14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h5.5L14 4.5zm-3 0A1.5 1.5 0 0 1 9.5 3V1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V4.5h-2z'/> </svg>");
|
|
72
|
+
}
|
|
73
|
+
ul a:hover {
|
|
74
|
+
text-decoration: underline;
|
|
75
|
+
}
|
|
76
|
+
/* folder-icon */
|
|
77
|
+
ul a.folder::before {
|
|
78
|
+
content: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='22' fill='currentColor' viewBox='0 0 16 16'> <path d='M9.828 3h3.982a2 2 0 0 1 1.992 2.181l-.637 7A2 2 0 0 1 13.174 14H2.825a2 2 0 0 1-1.991-1.819l-.637-7a1.99 1.99 0 0 1 .342-1.31L.5 3a2 2 0 0 1 2-2h3.672a2 2 0 0 1 1.414.586l.828.828A2 2 0 0 0 9.828 3zm-8.322.12C1.72 3.042 1.95 3 2.19 3h5.396l-.707-.707A1 1 0 0 0 6.172 2H2.5a1 1 0 0 0-1 .981l.006.139z'/> </svg>");
|
|
79
|
+
}
|
|
80
|
+
::selection {
|
|
81
|
+
background-color: #fff;
|
|
82
|
+
color: #000;
|
|
83
|
+
}
|
|
84
|
+
@media (min-width: 768px) {
|
|
85
|
+
ul {
|
|
86
|
+
display: flex;
|
|
87
|
+
flex-wrap: wrap;
|
|
88
|
+
}
|
|
89
|
+
ul li {
|
|
90
|
+
width: 230px;
|
|
91
|
+
padding-right: 20px;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
</style>
|
|
95
|
+
</head>
|
|
96
|
+
|
|
97
|
+
<body>
|
|
98
|
+
<main>
|
|
99
|
+
<header>
|
|
100
|
+
<h1>
|
|
101
|
+
Static Server Directory Listing
|
|
102
|
+
</h1>
|
|
103
|
+
</header>
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
<ul id="files">
|
|
107
|
+
${directoriesList}
|
|
108
|
+
${filesList}
|
|
109
|
+
</ul>
|
|
110
|
+
|
|
111
|
+
</main>
|
|
112
|
+
</body>
|
|
113
|
+
</html>
|
|
114
|
+
`;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
//# sourceMappingURL=directories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/directories.ts"],"sourcesContent":["type DirectoriesAndFiles = { href: string; name: string }[];\n\nexport const renderDirectories = (\n\tdirectories: DirectoriesAndFiles,\n\tfiles: DirectoriesAndFiles\n) => {\n\tconst directoriesList = `${directories\n\t\t.map(\n\t\t\t(directory) =>\n\t\t\t\t`<li><a class=\"folder\" href=\"${directory.href}\">${directory.name}/</a></li>`\n\t\t)\n\t\t.join(\"\\n \")}`;\n\n\tconst filesList = `${files\n\t\t.map(\n\t\t\t(file) => `<li><a class=\"file\" href=\"${file.href}\">${file.name}</a></li>`\n\t\t)\n\t\t.join(\"\\n \")}`;\n\n\treturn `\n<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta content=\"text/html;charset=utf-8\" http-equiv=\"Content-Type\"/>\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n\n <title>Static Server Directory Listing</title>\n\n <style>\n\t\tbody {\n\t\t -webkit-font-smoothing: antialiased;\n\t\t font-family: -apple-system, Calibri, \"Helvetica Neue\", sans-serif;\n\t\t margin: 0;\n\t\t padding: 20px;\n\t\t}\n\t\tmain {\n\t\t max-width: 900px;\n\t\t}\n\t\theader {\n\t\t display: flex;\n\t\t flex-wrap: wrap;\n\t\t justify-content: space-between;\n\t\t}\n\t\th1 {\n\t\t color: #000;\n\t\t font-size: 18px;\n\t\t font-weight: bold;\n\t\t margin-top: 0;\n\t\t}\n\t\tul {\n\t\t margin: 0 0 0 -2px;\n\t\t padding: 20px 0 0 0;\n\t\t}\n\t\tul li {\n\t\t display: flex;\n\t\t font-size: 14px;\n\t\t justify-content: space-between;\n\t\t list-style: none;\n\t\t}\n\t\ta {\n\t\t text-decoration: none;\n\t\t}\n\t\tul a {\n\t\t color: #000;\n\t\t display: block;\n\t\t margin: 0 -5px;\n\t\t overflow: hidden;\n\t\t padding: 10px 5px;\n\t\t text-overflow: ellipsis;\n\t\t white-space: nowrap;\n\t\t width: 100%;\n\t\t}\n\t\tsvg {\n\t\t height: 13px;\n\t\t vertical-align: text-bottom;\n\t\t}\n\t\tul a::before {\n\t\t display: inline-block;\n\t\t vertical-align: middle;\n\t\t margin-right: 10px;\n\t\t width: 24px;\n\t\t text-align: center;\n\t\t line-height: 12px;\n\t\t}\n\t\tul a.file::before {\n\t\t content: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='currentColor' viewBox='0 0 16 16'> <path d='M14 4.5V14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h5.5L14 4.5zm-3 0A1.5 1.5 0 0 1 9.5 3V1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V4.5h-2z'/> </svg>\");\n\t\t}\n\t\tul a:hover {\n\t\t text-decoration: underline;\n\t\t}\n\t\t/* folder-icon */\n\t\tul a.folder::before {\n\t\t content: url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='22' fill='currentColor' viewBox='0 0 16 16'> <path d='M9.828 3h3.982a2 2 0 0 1 1.992 2.181l-.637 7A2 2 0 0 1 13.174 14H2.825a2 2 0 0 1-1.991-1.819l-.637-7a1.99 1.99 0 0 1 .342-1.31L.5 3a2 2 0 0 1 2-2h3.672a2 2 0 0 1 1.414.586l.828.828A2 2 0 0 0 9.828 3zm-8.322.12C1.72 3.042 1.95 3 2.19 3h5.396l-.707-.707A1 1 0 0 0 6.172 2H2.5a1 1 0 0 0-1 .981l.006.139z'/> </svg>\");\n\t\t}\n\t\t::selection {\n\t\t background-color: #fff;\n\t\t color: #000;\n\t\t}\n\t\t@media (min-width: 768px) {\n\t\t ul {\n\t\t\t display: flex;\n\t\t\t flex-wrap: wrap;\n\t\t }\n\t\t ul li {\n\t\t\t width: 230px;\n\t\t\t padding-right: 20px;\n\t\t }\n\t\t}\n\t</style>\n </head>\n\n <body>\n <main>\n <header>\n <h1>\n Static Server Directory Listing\n </h1>\n </header>\n\n\n <ul id=\"files\">\n ${directoriesList}\n ${filesList}\n </ul>\n\n\t</main>\n </body>\n</html>\n`;\n};\n"],"names":["renderDirectories","directories","files","directoriesList","map","directory","href","name","join","filesList","file"],"mappings":"AAEA,OAAO,MAAMA,oBAAoB,CAChCC,aACAC,QACI;IACJ,MAAMC,kBAAkB,CAAC,EAAEF,YACzBG,GAAG,CACH,CAACC,YACA,CAAC,4BAA4B,EAAEA,UAAUC,IAAI,CAAC,EAAE,EAAED,UAAUE,IAAI,CAAC,UAAU,CAAC,EAE7EC,IAAI,CAAC,QAAQ,CAAC;IAEhB,MAAMC,YAAY,CAAC,EAAEP,MACnBE,GAAG,CACH,CAACM,OAAS,CAAC,0BAA0B,EAAEA,KAAKJ,IAAI,CAAC,EAAE,EAAEI,KAAKH,IAAI,CAAC,SAAS,CAAC,EAEzEC,IAAI,CAAC,QAAQ,CAAC;IAEhB,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAuGD,EAAEL,gBAAgB;QAClB,EAAEM,UAAU;;;;;;AAMpB,CAAC;AACD,EAAE"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from "./certs";
|
|
6
|
+
export * from "./defaults";
|
|
7
|
+
export * from "./directories";
|
|
8
|
+
export * from "./logs";
|
|
9
|
+
export * from "./parse";
|
|
10
|
+
export * from "./server";
|
|
11
|
+
export * from "./utilities";
|
package/dist/parse.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
* Merging default configuration with the
|
|
3
|
-
* preferences shared by the user.
|
|
4
|
-
*/
|
|
5
|
-
declare const config: {
|
|
1
|
+
export type Flags = {
|
|
6
2
|
cache?: number;
|
|
7
3
|
cors?: boolean;
|
|
8
|
-
|
|
4
|
+
dirs?: boolean;
|
|
9
5
|
gzip?: boolean;
|
|
6
|
+
http2?: boolean;
|
|
10
7
|
logs?: boolean;
|
|
11
8
|
open?: boolean;
|
|
12
|
-
path?: string;
|
|
13
9
|
port?: number;
|
|
14
10
|
};
|
|
15
|
-
export
|
|
11
|
+
export type Parameters = {
|
|
12
|
+
path?: string;
|
|
13
|
+
};
|
|
14
|
+
export type Configuration = {
|
|
15
|
+
flags?: Flags;
|
|
16
|
+
parameters?: Parameters;
|
|
17
|
+
usage?: boolean;
|
|
18
|
+
examples?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const config: Configuration;
|
package/dist/parse.js
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import meow from "meow";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
const { helpText , options } = meowOptionsHelper({
|
|
1
|
+
import { defaultFlags, defaultParameters } from "./defaults.js";
|
|
2
|
+
import { parser } from "@node-cli/parser";
|
|
3
|
+
export const config = parser({
|
|
7
4
|
flags: {
|
|
8
5
|
cache: {
|
|
9
6
|
shortFlag: "c",
|
|
10
|
-
default:
|
|
7
|
+
default: defaultFlags.cache,
|
|
11
8
|
description: "Time in seconds for caching files",
|
|
12
9
|
type: "number"
|
|
13
10
|
},
|
|
14
11
|
cors: {
|
|
15
12
|
shortFlag: "C",
|
|
16
|
-
default:
|
|
13
|
+
default: defaultFlags.cors,
|
|
17
14
|
description: "Set CORS headers to * to allow requests from any origin",
|
|
18
15
|
type: "boolean"
|
|
19
16
|
},
|
|
17
|
+
dirs: {
|
|
18
|
+
shortFlag: "d",
|
|
19
|
+
default: defaultFlags.dirs,
|
|
20
|
+
description: "List the directory's contents",
|
|
21
|
+
type: "boolean"
|
|
22
|
+
},
|
|
20
23
|
gzip: {
|
|
21
24
|
shortFlag: "g",
|
|
22
|
-
default:
|
|
25
|
+
default: defaultFlags.gzip,
|
|
23
26
|
description: "Enable GZIP compression",
|
|
24
27
|
type: "boolean"
|
|
25
28
|
},
|
|
@@ -30,25 +33,25 @@ const { helpText , options } = meowOptionsHelper({
|
|
|
30
33
|
},
|
|
31
34
|
http2: {
|
|
32
35
|
shortFlag: "H",
|
|
33
|
-
default:
|
|
36
|
+
default: defaultFlags.http2,
|
|
34
37
|
description: "Set HTTP to version 2",
|
|
35
38
|
type: "boolean"
|
|
36
39
|
},
|
|
37
40
|
logs: {
|
|
38
41
|
shortFlag: "l",
|
|
39
|
-
default:
|
|
42
|
+
default: defaultFlags.logs,
|
|
40
43
|
description: "Log HTTP requests at the prompt",
|
|
41
44
|
type: "boolean"
|
|
42
45
|
},
|
|
43
46
|
open: {
|
|
44
47
|
shortFlag: "o",
|
|
45
|
-
default:
|
|
48
|
+
default: defaultFlags.open,
|
|
46
49
|
description: "Open in your default browser",
|
|
47
50
|
type: "boolean"
|
|
48
51
|
},
|
|
49
52
|
port: {
|
|
50
53
|
shortFlag: "p",
|
|
51
|
-
default:
|
|
54
|
+
default: defaultFlags.port,
|
|
52
55
|
description: "Port to listen on",
|
|
53
56
|
type: "number"
|
|
54
57
|
},
|
|
@@ -64,27 +67,9 @@ const { helpText , options } = meowOptionsHelper({
|
|
|
64
67
|
description: "the path to serve files from"
|
|
65
68
|
}
|
|
66
69
|
},
|
|
67
|
-
usage: true
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
meowParserHelper({
|
|
71
|
-
cli
|
|
70
|
+
usage: true,
|
|
71
|
+
defaultFlags,
|
|
72
|
+
defaultParameters
|
|
72
73
|
});
|
|
73
|
-
const customCfg = cli.flags;
|
|
74
|
-
if (cli.input.length > 0) {
|
|
75
|
-
let customPath = cli.input[0];
|
|
76
|
-
if (fs.pathExistsSync(customPath)) {
|
|
77
|
-
customCfg.path = path.resolve(customPath);
|
|
78
|
-
} else {
|
|
79
|
-
displayErrorMessages([
|
|
80
|
-
`Folder ${customPath} does not exist!`
|
|
81
|
-
]);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Merging default configuration with the
|
|
86
|
-
* preferences shared by the user.
|
|
87
|
-
*/ const config = shallowMerge(defaults, customCfg);
|
|
88
|
-
export { config };
|
|
89
74
|
|
|
90
75
|
//# sourceMappingURL=parse.js.map
|
package/dist/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["import { defaultFlags, defaultParameters } from \"./defaults.js\";\n\nimport { parser } from \"@node-cli/parser\";\n\nexport type Flags = {\n\tcache?: number;\n\tcors?: boolean;\n\tdirs?: boolean;\n\tgzip?: boolean;\n\thttp2?: boolean;\n\tlogs?: boolean;\n\topen?: boolean;\n\tport?: number;\n};\n\nexport type Parameters = {\n\tpath?: string;\n};\n\nexport type Configuration = {\n\tflags?: Flags;\n\tparameters?: Parameters;\n\tusage?: boolean;\n\texamples?: string;\n};\n\nexport const config: Configuration = parser({\n\tflags: {\n\t\tcache: {\n\t\t\tshortFlag: \"c\",\n\t\t\tdefault: defaultFlags.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: defaultFlags.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\tdirs: {\n\t\t\tshortFlag: \"d\",\n\t\t\tdefault: defaultFlags.dirs,\n\t\t\tdescription: \"List the directory's contents\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tgzip: {\n\t\t\tshortFlag: \"g\",\n\t\t\tdefault: defaultFlags.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: defaultFlags.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: defaultFlags.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: defaultFlags.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: defaultFlags.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\tdefaultFlags,\n\tdefaultParameters,\n});\n"],"names":["defaultFlags","defaultParameters","parser","config","flags","cache","shortFlag","default","description","type","cors","dirs","gzip","help","http2","logs","open","port","version","parameters","path","usage"],"mappings":"AAAA,SAASA,YAAY,EAAEC,iBAAiB,QAAQ,gBAAgB;AAEhE,SAASC,MAAM,QAAQ,mBAAmB;AAwB1C,OAAO,MAAMC,SAAwBD,OAAO;IAC3CE,OAAO;QACNC,OAAO;YACNC,WAAW;YACXC,SAASP,aAAaK,KAAK;YAC3BG,aAAa;YACbC,MAAM;QACP;QACAC,MAAM;YACLJ,WAAW;YACXC,SAASP,aAAaU,IAAI;YAC1BF,aAAa;YACbC,MAAM;QACP;QACAE,MAAM;YACLL,WAAW;YACXC,SAASP,aAAaW,IAAI;YAC1BH,aAAa;YACbC,MAAM;QACP;QACAG,MAAM;YACLN,WAAW;YACXC,SAASP,aAAaY,IAAI;YAC1BJ,aAAa;YACbC,MAAM;QACP;QACAI,MAAM;YACLP,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAK,OAAO;YACNR,WAAW;YACXC,SAASP,aAAac,KAAK;YAC3BN,aAAa;YACbC,MAAM;QACP;QACAM,MAAM;YACLT,WAAW;YACXC,SAASP,aAAae,IAAI;YAC1BP,aAAa;YACbC,MAAM;QACP;QACAO,MAAM;YACLV,WAAW;YACXC,SAASP,aAAagB,IAAI;YAC1BR,aAAa;YACbC,MAAM;QACP;QACAQ,MAAM;YACLX,WAAW;YACXC,SAASP,aAAaiB,IAAI;YAC1BT,aAAa;YACbC,MAAM;QACP;QACAS,SAAS;YACRZ,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;IACD;IACAU,YAAY;QACXC,MAAM;YACLb,SAAS;YACTC,aAAa;QACd;IACD;IACAa,OAAO,IAAI;IACXrB;IACAC;AACD,GAAG"}
|
package/dist/server.d.ts
CHANGED
package/dist/server.js
CHANGED
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { cert, key } from "./certs.js";
|
|
3
|
+
import fastifyStatic from "@fastify/static";
|
|
3
4
|
import Fastify from "fastify";
|
|
5
|
+
import { Logger } from "@node-cli/logger";
|
|
4
6
|
import boxen from "boxen";
|
|
5
7
|
import { config } from "./parse.js";
|
|
6
8
|
import fastifyCache from "@fastify/caching";
|
|
7
9
|
import fastifyCompress from "@fastify/compress";
|
|
8
10
|
import fastifyCors from "@fastify/cors";
|
|
9
11
|
import fastifyLogs from "./logs.js";
|
|
10
|
-
import
|
|
12
|
+
import fs from "fs-extra";
|
|
11
13
|
import kleur from "kleur";
|
|
12
|
-
import { logger } from "./utilities.js";
|
|
13
14
|
import open from "open";
|
|
15
|
+
import path from "node:path";
|
|
14
16
|
import portfinder from "portfinder";
|
|
17
|
+
import { renderDirectories } from "./directories.js";
|
|
18
|
+
export const logger = new Logger({
|
|
19
|
+
boring: process.env.NODE_ENV === "test"
|
|
20
|
+
});
|
|
21
|
+
let customPath = config.parameters[0];
|
|
22
|
+
if (fs.pathExistsSync(customPath)) {
|
|
23
|
+
customPath = path.resolve(customPath);
|
|
24
|
+
} else {
|
|
25
|
+
logger.printErrorsAndExit([
|
|
26
|
+
`Folder ${customPath} does not exist!`
|
|
27
|
+
], 0);
|
|
28
|
+
}
|
|
15
29
|
const fastifyOptions = {
|
|
16
30
|
disableRequestLogging: true
|
|
17
31
|
};
|
|
18
|
-
if (config.logs) {
|
|
32
|
+
if (config.flags.logs) {
|
|
19
33
|
fastifyOptions.logger = {
|
|
20
34
|
level: "info",
|
|
21
35
|
transport: {
|
|
@@ -28,7 +42,7 @@ if (config.logs) {
|
|
|
28
42
|
}
|
|
29
43
|
};
|
|
30
44
|
}
|
|
31
|
-
if (config.http2) {
|
|
45
|
+
if (config.flags.http2) {
|
|
32
46
|
fastifyOptions.http2 = true;
|
|
33
47
|
fastifyOptions.https = {
|
|
34
48
|
key,
|
|
@@ -36,10 +50,10 @@ if (config.http2) {
|
|
|
36
50
|
};
|
|
37
51
|
}
|
|
38
52
|
const fastify = Fastify(fastifyOptions);
|
|
39
|
-
if (config.logs) {
|
|
53
|
+
if (config.flags.logs) {
|
|
40
54
|
fastify.register(fastifyLogs);
|
|
41
55
|
}
|
|
42
|
-
if (config.gzip) {
|
|
56
|
+
if (config.flags.gzip) {
|
|
43
57
|
fastify.register(fastifyCompress, {
|
|
44
58
|
global: true,
|
|
45
59
|
encodings: [
|
|
@@ -50,37 +64,45 @@ if (config.gzip) {
|
|
|
50
64
|
]
|
|
51
65
|
});
|
|
52
66
|
}
|
|
53
|
-
if (config.cors) {
|
|
67
|
+
if (config.flags.cors) {
|
|
54
68
|
fastify.register(fastifyCors);
|
|
55
69
|
}
|
|
56
70
|
const fastifyCacheOptions = {};
|
|
57
|
-
if (config.cache > 0) {
|
|
58
|
-
fastifyCacheOptions.expiresIn = config.cache;
|
|
59
|
-
fastifyCacheOptions.serverExpiresIn = config.cache;
|
|
60
|
-
fastifyCacheOptions.privacy =
|
|
71
|
+
if (config.flags.cache > 0) {
|
|
72
|
+
fastifyCacheOptions.expiresIn = config.flags.cache;
|
|
73
|
+
fastifyCacheOptions.serverExpiresIn = config.flags.cache;
|
|
74
|
+
fastifyCacheOptions.privacy = "public";
|
|
61
75
|
} else {
|
|
62
|
-
fastifyCacheOptions.privacy =
|
|
76
|
+
fastifyCacheOptions.privacy = "no-cache";
|
|
63
77
|
}
|
|
64
78
|
fastify.register(fastifyCache, fastifyCacheOptions);
|
|
65
|
-
|
|
66
|
-
root:
|
|
67
|
-
}
|
|
79
|
+
const staticOptions = {
|
|
80
|
+
root: customPath
|
|
81
|
+
};
|
|
82
|
+
if (config.flags.dirs) {
|
|
83
|
+
staticOptions.index = false;
|
|
84
|
+
staticOptions.list = {
|
|
85
|
+
format: "html",
|
|
86
|
+
render: renderDirectories
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
fastify.register(fastifyStatic, staticOptions);
|
|
68
90
|
/**
|
|
69
91
|
* Run the server!
|
|
70
92
|
*/ let port, portMessage = "";
|
|
71
93
|
const start = async ()=>{
|
|
72
94
|
try {
|
|
73
95
|
port = await portfinder.getPortPromise({
|
|
74
|
-
port: Number(config.port)
|
|
96
|
+
port: Number(config.flags.port)
|
|
75
97
|
});
|
|
76
|
-
if (port !== config.port) {
|
|
77
|
-
portMessage = `\n\n${kleur.yellow(`Warning: port ${config.port} was not available!`)}`;
|
|
78
|
-
config.port = port;
|
|
98
|
+
if (port !== config.flags.port) {
|
|
99
|
+
portMessage = `\n\n${kleur.yellow(`Warning: port ${config.flags.port} was not available!`)}`;
|
|
100
|
+
config.flags.port = port;
|
|
79
101
|
}
|
|
80
102
|
await fastify.listen({
|
|
81
|
-
port: config.port
|
|
103
|
+
port: config.flags.port
|
|
82
104
|
});
|
|
83
|
-
const url = `${config.http2 ? "https" : "http"}://localhost:${config.port}`;
|
|
105
|
+
const url = `${config.flags.http2 ? "https" : "http"}://localhost:${config.flags.port}`;
|
|
84
106
|
const messages = [
|
|
85
107
|
`${kleur.cyan("Static Server")} is up and running!`,
|
|
86
108
|
"",
|
|
@@ -94,9 +116,8 @@ const start = async ()=>{
|
|
|
94
116
|
borderColor: "yellow",
|
|
95
117
|
padding: 1
|
|
96
118
|
}));
|
|
97
|
-
if (config.open) {
|
|
119
|
+
if (config.flags.open) {
|
|
98
120
|
await open(url, {
|
|
99
|
-
url: true,
|
|
100
121
|
wait: false
|
|
101
122
|
});
|
|
102
123
|
}
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { 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
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { cert, key } from \"./certs.js\";\nimport fastifyStatic, { FastifyStaticOptions } from \"@fastify/static\";\n\nimport Fastify from \"fastify\";\nimport { Logger } from \"@node-cli/logger\";\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 fs from \"fs-extra\";\nimport kleur from \"kleur\";\nimport open from \"open\";\nimport path from \"node:path\";\nimport portfinder from \"portfinder\";\nimport { renderDirectories } from \"./directories.js\";\n\nexport const logger = new Logger({\n\tboring: process.env.NODE_ENV === \"test\",\n});\n\nlet customPath = config.parameters[0];\nif (fs.pathExistsSync(customPath)) {\n\tcustomPath = path.resolve(customPath);\n} else {\n\tlogger.printErrorsAndExit([`Folder ${customPath} does not exist!`], 0);\n}\n\nconst fastifyOptions: {\n\tdisableRequestLogging?: boolean;\n\thttp2?: boolean;\n\thttps?: any;\n\tlogger?: any;\n} = {\n\tdisableRequestLogging: true,\n};\n\nif (config.flags.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.flags.http2) {\n\tfastifyOptions.http2 = true;\n\tfastifyOptions.https = { key, cert };\n}\n\nconst fastify = Fastify(fastifyOptions);\n\nif (config.flags.logs) {\n\tfastify.register(fastifyLogs);\n}\n\nif (config.flags.gzip) {\n\tfastify.register(fastifyCompress, {\n\t\tglobal: true,\n\t\tencodings: [\"gzip\", \"deflate\", \"br\", \"identity\"],\n\t});\n}\n\nif (config.flags.cors) {\n\tfastify.register(fastifyCors);\n}\n\nconst fastifyCacheOptions: {\n\texpiresIn?: number;\n\tserverExpiresIn?: number;\n\tprivacy?: any;\n} = {};\n\nif (config.flags.cache > 0) {\n\tfastifyCacheOptions.expiresIn = config.flags.cache;\n\tfastifyCacheOptions.serverExpiresIn = config.flags.cache;\n\tfastifyCacheOptions.privacy = \"public\";\n} else {\n\tfastifyCacheOptions.privacy = \"no-cache\";\n}\n\nfastify.register(fastifyCache, fastifyCacheOptions);\n\nconst staticOptions: FastifyStaticOptions = {\n\troot: customPath,\n};\nif (config.flags.dirs) {\n\tstaticOptions.index = false;\n\tstaticOptions.list = {\n\t\tformat: \"html\",\n\t\trender: renderDirectories,\n\t};\n}\nfastify.register(fastifyStatic, staticOptions);\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.flags.port) });\n\t\tif (port !== config.flags.port) {\n\t\t\tportMessage = `\\n\\n${kleur.yellow(\n\t\t\t\t`Warning: port ${config.flags.port} was not available!`\n\t\t\t)}`;\n\t\t\tconfig.flags.port = port;\n\t\t}\n\t\tawait fastify.listen({ port: config.flags.port });\n\n\t\tconst url = `${config.flags.http2 ? \"https\" : \"http\"}://localhost:${\n\t\t\tconfig.flags.port\n\t\t}`;\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.flags.open) {\n\t\t\tawait open(url, {\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","fastifyStatic","Fastify","Logger","boxen","config","fastifyCache","fastifyCompress","fastifyCors","fastifyLogs","fs","kleur","open","path","portfinder","renderDirectories","logger","boring","process","env","NODE_ENV","customPath","parameters","pathExistsSync","resolve","printErrorsAndExit","fastifyOptions","disableRequestLogging","flags","logs","level","transport","target","options","hideObject","translateTime","ignore","http2","https","fastify","register","gzip","global","encodings","cors","fastifyCacheOptions","cache","expiresIn","serverExpiresIn","privacy","staticOptions","root","dirs","index","list","format","render","port","portMessage","start","getPortPromise","Number","yellow","listen","url","messages","cyan","log","join","align","borderColor","padding","wait","error","exit"],"mappings":";AAEA,SAASA,IAAI,EAAEC,GAAG,QAAQ,aAAa;AACvC,OAAOC,mBAA6C,kBAAkB;AAEtE,OAAOC,aAAa,UAAU;AAC9B,SAASC,MAAM,QAAQ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MpD,OAAOuB,KAAK,CAAC6B,IAAI;QAAC;QAE/C,MAAMO,MAAM,CAAC,EAAE3D,OAAOuB,KAAK,CAACS,KAAK,GAAG,UAAU,MAAM,CAAC,aAAa,EACjEhC,OAAOuB,KAAK,CAAC6B,IAAI,CACjB,CAAC;QACF,MAAMQ,WAAW;YAChB,CAAC,EAAEtD,MAAMuD,IAAI,CAAC,iBAAiB,mBAAmB,CAAC;YACnD;YACA,CAAC,EAAEvD,MAAMuD,IAAI,CAACF,KAAK,CAAC;YACpB;YACA,CAAC,2BAA2B,EAAEN,YAAY,CAAC;SAC3C;QAED1C,OAAOmD,GAAG;QACVnD,OAAOmD,GAAG,CACT/D,MAAM6D,SAASG,IAAI,CAAC,OAAO;YAC1BC,OAAO;YACPC,aAAa;YACbC,SAAS;QACV;QAGD,IAAIlE,OAAOuB,KAAK,CAAChB,IAAI,EAAE;YACtB,MAAMA,KAAKoD,KAAK;gBACfQ,MAAM,KAAK;YACZ;QACD,CAAC;IACF,EAAE,OAAOC,OAAO;QACflC,QAAQ4B,GAAG,CAACM,KAAK,CAACA;QAClB,mDAAmD;QACnDvD,QAAQwD,IAAI,CAAC;IACd;AACD;AACAf"}
|
package/dist/utilities.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Logger } from "@node-cli/logger";
|
|
2
|
-
export declare const logger: Logger;
|
|
3
1
|
/**
|
|
4
2
|
* Wrapper method for lodash `merge()` and `mergeWith()` methods.
|
|
5
3
|
*
|
|
@@ -23,22 +21,3 @@ export declare const logger: Logger;
|
|
|
23
21
|
* !! WARNING: this method will mutate objA
|
|
24
22
|
*/
|
|
25
23
|
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;
|
package/dist/utilities.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
/* eslint-disable unicorn/no-process-exit */ import { Logger } from "@node-cli/logger";
|
|
2
|
-
import Table from "cli-table3";
|
|
3
1
|
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
2
|
/**
|
|
15
3
|
* Wrapper method for lodash `merge()` and `mergeWith()` methods.
|
|
16
4
|
*
|
|
@@ -35,153 +23,5 @@ export const logger = new Logger({
|
|
|
35
23
|
*/ export const shallowMerge = (objectA, objectB, customizer)=>{
|
|
36
24
|
return typeof customizer === "function" ? _.mergeWith(objectA, objectB, customizer) : _.merge(objectA, objectB);
|
|
37
25
|
};
|
|
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
|
-
logger.error(rule.message(cli.flags));
|
|
165
|
-
process.exit(rule.exit);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* Log multiple error messages at the prompt using `console.error` behind the scenes.
|
|
172
|
-
* @param {string[]} errorMessages array of error message to display line by line
|
|
173
|
-
* @param {number} [exitStatus=0] the process will exit with this value, unless set to false
|
|
174
|
-
*/ export const displayErrorMessages = (errorMessages, exitStatus = 0)=>{
|
|
175
|
-
if (errorMessages && errorMessages.length > 0) {
|
|
176
|
-
logger.log();
|
|
177
|
-
for (const message of errorMessages){
|
|
178
|
-
logger.error(message);
|
|
179
|
-
}
|
|
180
|
-
logger.log();
|
|
181
|
-
if (typeof exitStatus === "number") {
|
|
182
|
-
process.exit(exitStatus);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
26
|
|
|
187
27
|
//# sourceMappingURL=utilities.js.map
|
package/dist/utilities.js.map
CHANGED
|
@@ -1 +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 kleur from \"kleur\";\nimport path from \"node:path\";\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\tlogger.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","error","message","displayErrorMessages","errorMessages","exitStatus","log"],"mappings":"AAAA,0CAA0C,GAE1C,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,WAAW,aAAa;AAC/B,OAAOC,OAAO,SAAS;AACvB,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,UAAU,YAAY;AAC7B,OAAO,MAAMC,SAAS,IAAIL,OAAO;IAChCM,QAAQC,QAAQC,GAAG,CAACC,QAAQ,KAAK;AAClC,GAAG;AAEH;;;;CAIC,GACD,MAAMC,aAAa,CAACC,UACnBA,OAAO,CA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,IAAIpD,KAAK,CAACyD,OAAO,EAAE;YACtBL,IAAIM,WAAW;YACf1E,QAAQwE,IAAI,CAAC;QACd,CAAC;IACF,EAAE,OAAM;IACP,6BAA6B;IAC9B;IAEA,IAAIH,gBAAgBA,aAAaM,MAAM,GAAG,GAAG;QAC5C,KAAK,MAAMC,QAAQP,aAAc;YAChC,IAAIO,KAAKC,IAAI,CAACT,IAAIpD,KAAK,GAAG;gBACzBlB,OAAOgF,KAAK,CAACF,KAAKG,OAAO,CAACX,IAAIpD,KAAK;gBACnChB,QAAQwE,IAAI,CAACI,KAAKJ,IAAI;YACvB,CAAC;QACF;IACD,CAAC;AACF,EAAE;AAEF;;;;CAIC,GACD,OAAO,MAAMQ,uBAAuB,CACnCC,eACAC,aAAqB,CAAC,GAClB;IACJ,IAAID,iBAAiBA,cAAcN,MAAM,GAAG,GAAG;QAC9C7E,OAAOqF,GAAG;QACV,KAAK,MAAMJ,WAAWE,cAAe;YACpCnF,OAAOgF,KAAK,CAACC;QACd;QACAjF,OAAOqF,GAAG;QAEV,IAAI,OAAOD,eAAe,UAAU;YACnClF,QAAQwE,IAAI,CAACU;QACd,CAAC;IACF,CAAC;AACF,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import _ from \"lodash\";\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"],"names":["_","shallowMerge","objectA","objectB","customizer","mergeWith","merge"],"mappings":"AAAA,OAAOA,OAAO,SAAS;AAEvB;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,MAAMC,eAAe,CAC3BC,SACAC,SACAC,aACY;IACZ,OAAO,OAAOA,eAAe,aAC1BJ,EAAEK,SAAS,CAACH,SAASC,SAASC,cAC9BJ,EAAEM,KAAK,CAACJ,SAASC,QAAQ;AAC7B,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-cli/static-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"description": "A simple, zero-configuration, command line HTTP server to serve static files locally",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"types": "./dist/
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": "./dist/server.js",
|
|
10
10
|
"bin": {
|
|
11
11
|
"static-server": "dist/server.js"
|
|
@@ -14,36 +14,36 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"node": ">=16",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "yarn run clean && yarn run build:types && yarn run build:js&& yarn run build:barrel",
|
|
19
|
+
"build:barrel": "barrelsby --delete --directory dist --pattern \"**/*.d.ts\" --name \"index.d\"",
|
|
20
|
+
"build:js": "swc --source-maps --out-dir dist src --copy-files",
|
|
21
|
+
"build:types": "tsc",
|
|
22
|
+
"clean": "rimraf dist types coverage",
|
|
23
|
+
"lint": "eslint \"src/*.ts\"",
|
|
24
|
+
"test": "jest",
|
|
25
|
+
"test:coverage": "echo 'No coverage available yet'",
|
|
26
|
+
"watch": "swc --watch --out-dir dist src"
|
|
27
|
+
},
|
|
17
28
|
"dependencies": {
|
|
18
29
|
"@fastify/caching": "8.3.0",
|
|
19
|
-
"@fastify/compress": "6.
|
|
30
|
+
"@fastify/compress": "6.3.0",
|
|
20
31
|
"@fastify/cors": "8.2.1",
|
|
21
32
|
"@fastify/static": "6.10.1",
|
|
22
|
-
"@node-cli/logger": "
|
|
33
|
+
"@node-cli/logger": ">=0.0.8",
|
|
34
|
+
"@node-cli/parser": ">=0.0.8",
|
|
23
35
|
"boxen": "7.1.0",
|
|
24
|
-
"cli-table3": "0.6.3",
|
|
25
36
|
"fastify": "4.17.0",
|
|
26
37
|
"fastify-plugin": "4.5.0",
|
|
27
38
|
"fs-extra": "11.1.1",
|
|
28
|
-
"kleur": "4.1.
|
|
39
|
+
"kleur": "4.1.5",
|
|
29
40
|
"lodash": "4.17.21",
|
|
30
|
-
"
|
|
31
|
-
"open": "7.4.2",
|
|
41
|
+
"open": "9.1.0",
|
|
32
42
|
"pino-pretty": "10.0.0",
|
|
33
43
|
"portfinder": "1.0.32"
|
|
34
44
|
},
|
|
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
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "fe6401830d153ab91166243c2cafd96f6cc0d9b5"
|
|
49
49
|
}
|