@node-cli/static-server 0.0.8 → 1.1.1

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 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 = "-----BEGIN CERTIFICATE-----\nMIICpDCCAYwCCQC8TqYqUGuZJDANBgkqhkiG9w0BAQsFADAUMRIwEAYDVQQDDAls\nb2NhbGhvc3QwHhcNMjMwNTEyMjMxOTU3WhcNMzMwNTA5MjMxOTU3WjAUMRIwEAYD\nVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDy\nc+8Eb+Y/oXvnIgja8nJycczRzDWQvj9Q242yy4M4eRJCnw+aFGkLWvUL4h+p7kKw\nPK9FDv02WK81YDzbfvpAe0PepPChMcGqIiznnu14J+/dJ14ZFnitNwG6hYCXkjNt\nUvGpQgSRe3LEo4FKMqrURk2hhhZAdaC1Qe05ohvbgJBW7UBI/+qrxP8KAjb3Nqke\nhVSRMUCKsBGoNceUgFfrgyVDKiLsIuKdWcjvVb0hrGwZW4chm7EhoJaARnByupuw\nzjRSpkbFmgZjIq0GCLvFi/KJu5OwV0ZaZMLEOmLYoV57LQJ7ZwnXeUT7rZjlUgvx\nknY7y8BMgchO0rNNgqFfAgMBAAEwDQYJKoZIhvcNAQELBQADggEBALvnJX45Zkll\nF1Fj4Rpq4ss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v40XMN6lwSC5HTBy/hxLF7MaUZIj9A7GD\ncv68BENBAoGBAP7RQVsV01zfb1XIv00j/ppmr8oOecOCly2nUTM5wQ9uRGDGAo8V\nnPpyVe3gy41j3KLwXITEWksXAJ8hI5+9IsV+TKwuaTxe3GPa1/vzTplKK/G5Zpf6\nrg306aHuSmBrO2BtDSBWqbzW/hE8N9kCEm/8bLKU2R+TpyehWfv4l6LFAoGBAPOT\n/P2iff8/vZsMyi4tuTHtcSJYc/ziYzotDXGUH/12oHsYmKw6AreY4nzK8VjMEmUa\n+smNAnIROc880vueSfZOdNejrlvmN1E/lQ3OdKA2izekLM9s7uh+RG9fIRH5VG02\nj+MSVyVwgMOB829JQQX7WH0ISqG2VymHz87yDSXTAoGBAO0iVXzrgcgzEow1hnnG\nXoDXwQ37jKs6U3Aj/jf6rkSq7C1W+Dip921Gi9sU0Lkizsg/gQn5JMIuhOCR2XIl\ndD9wOvAdPMf2y4iNt2P72BBlayHH1MbofaP1YJrWhBbYk+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-----";
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 = `-----B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Sq7C1W+Dip921Gi9sU0Lkizsg/gQn5JMIuhOCR2XIl\ndD9wOvAdPMf2y4iNt2P72BBlayHH1MbofaP1YJrWhBbYk+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,OAAO,CAAC;;;;;;;;;;;;;;;;yBAgBI,CAAC,CAAC;AAE3B,OAAO,MAAMC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;6BA0BS,CAAC,CAAC"}
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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b2C7U//i6StymSG3he7p+RAvKKPBFXVFkTT\nM+X+O8oECdPoBmQ6I3Wh2QHkua4waPPdB5Md6DgnSgK/Wd3Fypz+5XakyA+j5LRJ\nCK+IKNdZGb8ICaKKmS2FhaOa860GpdQWM8z6P3FgKRwgQ2k+684oowg=\n-----END RSA PRIVATE KEY-----`;\n"],"names":["cert","key"],"mappings":"AAAA,OAAO,MAAMA,OAAe,CAAC;;;;;;;;;;;;;;;;yBAgBJ,CAAC,CAAC;AAE3B,OAAO,MAAMC,MAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;6BA0BC,CAAC,CAAC"}
@@ -1,10 +1,13 @@
1
- export declare const defaults: {
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 defaults = {
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["export const defaults = {\n\tcache: 0,\n\tcors: false,\n\tgzip: true,\n\thttp2: false,\n\tlogs: false,\n\topen: false,\n\tpath: `${process.cwd()}/`,\n\tport: 8080,\n};\n"],"names":["defaults","cache","cors","gzip","http2","logs","open","path","process","cwd","port"],"mappings":"AAAA,OAAO,MAAMA,WAAW;IACvBC,OAAO;IACPC,MAAM,KAAK;IACXC,MAAM,IAAI;IACVC,OAAO,KAAK;IACZC,MAAM,KAAK;IACXC,MAAM,KAAK;IACXC,MAAM,CAAC,EAAEC,QAAQC,GAAG,GAAG,CAAC,CAAC;IACzBC,MAAM;AACP,EAAE"}
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;IACNC,MAAM;IACNC,MAAM;IACNC,OAAO;IACPC,MAAM;IACNC,MAAM;IACNC,MAAM;AACP,EAAE;AAEF,OAAO,MAAMC,oBAAoB;IAChC,KAAK,CAAC,EAAEC,QAAQC,MAAM,CAAC,CAAC;AACzB,EAAE"}
@@ -0,0 +1,6 @@
1
+ type DirectoriesAndFiles = {
2
+ href: string;
3
+ name: string;
4
+ }[];
5
+ export declare const renderDirectories: (directories: DirectoriesAndFiles, files: DirectoriesAndFiles) => string;
6
+ export {};
@@ -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;IAEA,MAAMC,kBAAkB,CAAC,EAAEF,YACzBG,IACA,CAACC,YACA,CAAC,4BAA4B,EAAEA,UAAUC,KAAK,EAAE,EAAED,UAAUE,KAAK,UAAU,CAAC,EAE7EC,KAAK,QAAQ,CAAC;IAEhB,MAAMC,YAAY,CAAC,EAAEP,MACnBE,IACA,CAACM,OAAS,CAAC,0BAA0B,EAAEA,KAAKJ,KAAK,EAAE,EAAEI,KAAKH,KAAK,SAAS,CAAC,EAEzEC,KAAK,QAAQ,CAAC;IAEhB,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAuGD,EAAEL,gBAAgB;QAClB,EAAEM,UAAU;;;;;;AAMpB,CAAC;AACD,EAAE"}
@@ -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/logs.js.map CHANGED
@@ -1 +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"}
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;IACzCA,QAAQC,QAAQ,cAAc,OAAOC,SAASC;QAC7CD,QAAQE,IAAIC,KACXP,MAAMQ,KAAK,CAAC,EAAEJ,QAAQK,OAAO,CAAC,EAAEL,QAAQM,IAAI,CAAC,EAAEL,MAAMM,WAAW,CAAC;IAEnE;AACD;AAEA,eAAeZ,cAAcE,QAAQ;IACpCC,SAAS;IACTU,MAAM;AACP,GAAG"}
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
- http2?: boolean;
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 { config };
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 { 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
- 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: defaults.cache,
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: defaults.cors,
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: defaults.gzip,
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: defaults.http2,
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: defaults.logs,
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: defaults.open,
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: defaults.port,
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
- const cli = meow(helpText, options);
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 {\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\";\nimport path from \"node:path\";\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\tcustomCfg.path = path.resolve(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","path","helpText","options","flags","cache","shortFlag","default","description","type","cors","gzip","help","http2","logs","open","port","version","parameters","usage","cli","customCfg","input","length","customPath","pathExistsSync","resolve","config"],"mappings":"AAAA,SACCA,oBAAoB,EACpBC,iBAAiB,EACjBC,gBAAgB,EAChBC,YAAY,QACN,iBAAiB;A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C/B,OAAO;QACN9B,qBAAqB;YAAC,CAAC,OAAO,EAAE8B,WAAW,gBAAgB,CAAC;SAAC;IAC9D,CAAC;AACF,CAAC;AAED;;;CAGC,GACD,MAAMG,SASF9B,aAAaC,UAAUuB;AAE3B,SAASM,MAAM,GAAG"}
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;YACtBG,aAAa;YACbC,MAAM;QACP;QACAC,MAAM;YACLJ,WAAW;YACXC,SAASP,aAAaU;YACtBF,aAAa;YACbC,MAAM;QACP;QACAE,MAAM;YACLL,WAAW;YACXC,SAASP,aAAaW;YACtBH,aAAa;YACbC,MAAM;QACP;QACAG,MAAM;YACLN,WAAW;YACXC,SAASP,aAAaY;YACtBJ,aAAa;YACbC,MAAM;QACP;QACAI,MAAM;YACLP,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAK,OAAO;YACNR,WAAW;YACXC,SAASP,aAAac;YACtBN,aAAa;YACbC,MAAM;QACP;QACAM,MAAM;YACLT,WAAW;YACXC,SAASP,aAAae;YACtBP,aAAa;YACbC,MAAM;QACP;QACAO,MAAM;YACLV,WAAW;YACXC,SAASP,aAAagB;YACtBR,aAAa;YACbC,MAAM;QACP;QACAQ,MAAM;YACLX,WAAW;YACXC,SAASP,aAAaiB;YACtBT,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;IACPrB;IACAC;AACD,GAAG"}
package/dist/server.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ import { Logger } from "@node-cli/logger";
3
+ export declare const logger: Logger;
package/dist/server.js CHANGED
@@ -1,21 +1,34 @@
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";
4
- import boxen from "boxen";
5
+ import { Logger } from "@node-cli/logger";
5
6
  import { config } from "./parse.js";
6
7
  import fastifyCache from "@fastify/caching";
7
8
  import fastifyCompress from "@fastify/compress";
8
9
  import fastifyCors from "@fastify/cors";
9
10
  import fastifyLogs from "./logs.js";
10
- import fastifyStatic from "@fastify/static";
11
+ import fs from "fs-extra";
11
12
  import kleur from "kleur";
12
- import { logger } from "./utilities.js";
13
13
  import open from "open";
14
+ import path from "node:path";
14
15
  import portfinder from "portfinder";
16
+ import { renderDirectories } from "./directories.js";
17
+ export const logger = new Logger({
18
+ boring: process.env.NODE_ENV === "test"
19
+ });
20
+ let customPath = config.parameters[0];
21
+ if (fs.pathExistsSync(customPath)) {
22
+ customPath = path.resolve(customPath);
23
+ } else {
24
+ logger.printErrorsAndExit([
25
+ `Folder ${customPath} does not exist!`
26
+ ], 0);
27
+ }
15
28
  const fastifyOptions = {
16
29
  disableRequestLogging: true
17
30
  };
18
- if (config.logs) {
31
+ if (config.flags.logs) {
19
32
  fastifyOptions.logger = {
20
33
  level: "info",
21
34
  transport: {
@@ -28,7 +41,7 @@ if (config.logs) {
28
41
  }
29
42
  };
30
43
  }
31
- if (config.http2) {
44
+ if (config.flags.http2) {
32
45
  fastifyOptions.http2 = true;
33
46
  fastifyOptions.https = {
34
47
  key,
@@ -36,10 +49,10 @@ if (config.http2) {
36
49
  };
37
50
  }
38
51
  const fastify = Fastify(fastifyOptions);
39
- if (config.logs) {
52
+ if (config.flags.logs) {
40
53
  fastify.register(fastifyLogs);
41
54
  }
42
- if (config.gzip) {
55
+ if (config.flags.gzip) {
43
56
  fastify.register(fastifyCompress, {
44
57
  global: true,
45
58
  encodings: [
@@ -50,37 +63,45 @@ if (config.gzip) {
50
63
  ]
51
64
  });
52
65
  }
53
- if (config.cors) {
66
+ if (config.flags.cors) {
54
67
  fastify.register(fastifyCors);
55
68
  }
56
69
  const fastifyCacheOptions = {};
57
- if (config.cache > 0) {
58
- fastifyCacheOptions.expiresIn = config.cache;
59
- fastifyCacheOptions.serverExpiresIn = config.cache;
60
- fastifyCacheOptions.privacy = fastifyCache.privacy.PUBLIC;
70
+ if (config.flags.cache > 0) {
71
+ fastifyCacheOptions.expiresIn = config.flags.cache;
72
+ fastifyCacheOptions.serverExpiresIn = config.flags.cache;
73
+ fastifyCacheOptions.privacy = "public";
61
74
  } else {
62
- fastifyCacheOptions.privacy = fastifyCache.privacy.NOCACHE;
75
+ fastifyCacheOptions.privacy = "no-cache";
63
76
  }
64
77
  fastify.register(fastifyCache, fastifyCacheOptions);
65
- fastify.register(fastifyStatic, {
66
- root: config.path
67
- });
78
+ const staticOptions = {
79
+ root: customPath
80
+ };
81
+ if (config.flags.dirs) {
82
+ staticOptions.index = false;
83
+ staticOptions.list = {
84
+ format: "html",
85
+ render: renderDirectories
86
+ };
87
+ }
88
+ fastify.register(fastifyStatic, staticOptions);
68
89
  /**
69
90
  * Run the server!
70
91
  */ let port, portMessage = "";
71
92
  const start = async ()=>{
72
93
  try {
73
94
  port = await portfinder.getPortPromise({
74
- port: Number(config.port)
95
+ port: Number(config.flags.port)
75
96
  });
76
- if (port !== config.port) {
77
- portMessage = `\n\n${kleur.yellow(`Warning: port ${config.port} was not available!`)}`;
78
- config.port = port;
97
+ if (port !== config.flags.port) {
98
+ portMessage = `\n\n${kleur.yellow(`Warning: port ${config.flags.port} was not available!`)}`;
99
+ config.flags.port = port;
79
100
  }
80
101
  await fastify.listen({
81
- port: config.port
102
+ port: config.flags.port
82
103
  });
83
- const url = `${config.http2 ? "https" : "http"}://localhost:${config.port}`;
104
+ const url = `${config.flags.http2 ? "https" : "http"}://localhost:${config.flags.port}`;
84
105
  const messages = [
85
106
  `${kleur.cyan("Static Server")} is up and running!`,
86
107
  "",
@@ -88,15 +109,11 @@ const start = async ()=>{
88
109
  "",
89
110
  `Hit CTRL+C to shut it down.${portMessage}`
90
111
  ];
91
- logger.log();
92
- logger.log(boxen(messages.join("\n"), {
93
- align: "center",
94
- borderColor: "yellow",
95
- padding: 1
96
- }));
97
- if (config.open) {
112
+ logger.printBox(messages, {
113
+ newLineAfter: false
114
+ });
115
+ if (config.flags.open) {
98
116
  await open(url, {
99
- url: true,
100
117
  wait: false
101
118
  });
102
119
  }
@@ -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 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":";AAEA,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,I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IAAI,EAAE;YACzBC,cAAc,CAAC,IAAI,EAAEhC,MAAMoC,MAAM,CAChC,CAAC,cAAc,EAAE1C,OAAOqC,IAAI,CAAC,mBAAmB,CAAC,EAChD,CAAC;YACHrC,OAAOqC,IAAI,GAAGA;QACf,CAAC;QACD,MAAMf,QAAQqB,MAAM,CAAC;YAAEN,MAAMrC,OAAOqC,IAAI;QAAC;QAEzC,MAAMO,MAAM,CAAC,EAAE5C,OAAOoB,KAAK,GAAG,UAAU,MAAM,CAAC,aAAa,EAAEpB,OAAOqC,IAAI,CAAC,CAAC;QAC3E,MAAMQ,WAAW;YAChB,CAAC,EAAEvC,MAAMwC,IAAI,CAAC,iBAAiB,mBAAmB,CAAC;YACnD;YACA,CAAC,EAAExC,MAAMwC,IAAI,CAACF,KAAK,CAAC;YACpB;YACA,CAAC,2BAA2B,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"}
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 { 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.printBox(messages, { newLineAfter: false });\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","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","printBox","newLineAfter","wait","error","log","exit"],"mapp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AK,CAAC;YACpB;YACA,CAAC,2BAA2B,EAAEN,YAAY,CAAC;SAC3C;QAED1C,OAAOmD,SAASF,UAAU;YAAEG,cAAc;QAAM;QAEhD,IAAI/D,OAAOuB,MAAMhB,MAAM;YACtB,MAAMA,KAAKoD,KAAK;gBACfK,MAAM;YACP;QACD;IACD,EAAE,OAAOC,OAAO;QACf/B,QAAQgC,IAAID,MAAMA;QAClB,mDAAmD;QACnDpD,QAAQsD,KAAK;IACd;AACD;AACAb"}
@@ -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
@@ -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","exitStat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UAAU,EAAED,SAAS,CAAC;QACrCG;IACD;AACD,EAAE;AAEF,OAAO,MAAM6C,mBAAmB,CAAClD,aAG3B;IACL,MAAM,EAAEmD,IAAG,EAAEC,aAAY,EAAE,GAAGpD;IAC9B,IAAI;QACH,IAAImD,IAAIpD,KAAK,CAACsD,IAAI,EAAE;YACnBF,IAAIG,QAAQ;YACZvE,QAAQwE,IAAI,CAAC;QACd,CAAC;IACF,EAAE,OAAM;IACP,6BAA6B;IAC9B;IAEA,IAAI;QACH,IAAIJ,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;IAEA,OAAO,OAAOA,eAAe,aAC1BJ,EAAEK,UAAUH,SAASC,SAASC,cAC9BJ,EAAEM,MAAMJ,SAASC;AACrB,EAAE"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@node-cli/static-server",
3
- "version": "0.0.8",
3
+ "version": "1.1.1",
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/server.d.ts",
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,35 @@
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.2.1",
30
+ "@fastify/compress": "6.3.0",
20
31
  "@fastify/cors": "8.2.1",
21
32
  "@fastify/static": "6.10.1",
22
- "@node-cli/logger": "^0.0.8",
23
- "boxen": "7.1.0",
24
- "cli-table3": "0.6.3",
33
+ "@node-cli/logger": ">=1.0.0",
34
+ "@node-cli/parser": ">=1.0.0",
25
35
  "fastify": "4.17.0",
26
36
  "fastify-plugin": "4.5.0",
27
37
  "fs-extra": "11.1.1",
28
- "kleur": "4.1.4",
38
+ "kleur": "4.1.5",
29
39
  "lodash": "4.17.21",
30
- "meow": "12.0.1",
31
- "open": "7.4.2",
40
+ "open": "9.1.0",
32
41
  "pino-pretty": "10.0.0",
33
42
  "portfinder": "1.0.32"
34
43
  },
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
44
  "publishConfig": {
46
45
  "access": "public"
47
46
  },
48
- "gitHead": "23fe76a185d8ff414348b2867dfddb793c2d3182"
47
+ "gitHead": "d1d89854e385600edfd9c2aead7c9bc568bcc657"
49
48
  }