@eighty4/dank 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Adam McKee Bennett
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/lib/bin.ts CHANGED
@@ -15,10 +15,10 @@ function printHelp(task?: 'build' | 'serve'): never {
15
15
  )
16
16
  }
17
17
  console.log('\nOPTIONS:')
18
+ if (!task || task === 'serve')
19
+ console.log(' --log-http print access logs')
18
20
  console.log(' --minify minify sources')
19
- // if (!task || task === 'serve') {
20
- // console.log(' --preview pre-bundle and build ServiceWorker')
21
- // }
21
+ // if (!task || task === 'serve') console.log(' --preview pre-bundle and build ServiceWorker')
22
22
  console.log(' --production build for production release')
23
23
  if (task) {
24
24
  console.log()
package/lib/flags.ts CHANGED
@@ -1,3 +1,7 @@
1
+ // `dank serve` will print http access logs to console
2
+ export const isLogHttp = () =>
3
+ process.env.LOG_HTTP === 'true' || process.argv.includes('--log-http')
4
+
1
5
  // `dank serve` will pre-bundle and use service worker
2
6
  export const isPreviewBuild = () =>
3
7
  process.env.PREVIEW === 'true' || process.argv.includes('--preview')
package/lib/http.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  } from 'node:http'
10
10
  import { extname, join } from 'node:path'
11
11
  import mime from 'mime'
12
+ import { isLogHttp } from './flags.ts'
12
13
 
13
14
  export type FrontendFetcher = (
14
15
  url: URL,
@@ -21,7 +22,7 @@ export function createWebServer(
21
22
  frontendFetcher: FrontendFetcher,
22
23
  ): ReturnType<typeof createServer> {
23
24
  const serverAddress = 'http://localhost:' + port
24
- return createServer((req: IncomingMessage, res: ServerResponse) => {
25
+ const handler = (req: IncomingMessage, res: ServerResponse) => {
25
26
  if (!req.url || !req.method) {
26
27
  res.end()
27
28
  } else {
@@ -33,7 +34,19 @@ export function createWebServer(
33
34
  frontendFetcher(url, convertHeadersToFetch(req.headers), res)
34
35
  }
35
36
  }
36
- })
37
+ }
38
+ return createServer(isLogHttp() ? createLogWrapper(handler) : handler)
39
+ }
40
+
41
+ type RequestListener = (req: IncomingMessage, res: ServerResponse) => void
42
+ function createLogWrapper(handler: RequestListener): RequestListener {
43
+ return (req, res) => {
44
+ console.log(' > ', req.method, req.url)
45
+ res.on('close', () => {
46
+ console.log('', res.statusCode, req.method, req.url)
47
+ })
48
+ handler(req, res)
49
+ }
37
50
  }
38
51
 
39
52
  export function createBuiltDistFilesFetcher(
@@ -72,7 +85,7 @@ export function createDevServeFilesFetcher(
72
85
  const proxyAddress = 'http://127.0.0.1:' + opts.proxyPort
73
86
  return (url: URL, _headers: Headers, res: ServerResponse) => {
74
87
  if (opts.pages[url.pathname]) {
75
- streamFile(join(opts.pagesDir, url.pathname + 'index.html'), res)
88
+ streamFile(join(opts.pagesDir, url.pathname, 'index.html'), res)
76
89
  } else {
77
90
  const maybePublicPath = join(opts.publicDir, url.pathname)
78
91
  exists(join(opts.publicDir, url.pathname)).then(fromPublic => {
package/lib_js/bin.js CHANGED
@@ -12,10 +12,10 @@ function printHelp(task) {
12
12
  'dank serve [--minify] [--production]');
13
13
  }
14
14
  console.log('\nOPTIONS:');
15
+ if (!task || task === 'serve')
16
+ console.log(' --log-http print access logs');
15
17
  console.log(' --minify minify sources');
16
- // if (!task || task === 'serve') {
17
- // console.log(' --preview pre-bundle and build ServiceWorker')
18
- // }
18
+ // if (!task || task === 'serve') console.log(' --preview pre-bundle and build ServiceWorker')
19
19
  console.log(' --production build for production release');
20
20
  if (task) {
21
21
  console.log();
package/lib_js/flags.js CHANGED
@@ -1,3 +1,5 @@
1
+ // `dank serve` will print http access logs to console
2
+ export const isLogHttp = () => process.env.LOG_HTTP === 'true' || process.argv.includes('--log-http');
1
3
  // `dank serve` will pre-bundle and use service worker
2
4
  export const isPreviewBuild = () => process.env.PREVIEW === 'true' || process.argv.includes('--preview');
3
5
  // `dank build` will minify sources and append git release tag to build tag
package/lib_js/http.js CHANGED
@@ -3,9 +3,10 @@ import { stat } from 'node:fs/promises';
3
3
  import { createServer, } from 'node:http';
4
4
  import { extname, join } from 'node:path';
5
5
  import mime from 'mime';
6
+ import { isLogHttp } from "./flags.js";
6
7
  export function createWebServer(port, frontendFetcher) {
7
8
  const serverAddress = 'http://localhost:' + port;
8
- return createServer((req, res) => {
9
+ const handler = (req, res) => {
9
10
  if (!req.url || !req.method) {
10
11
  res.end();
11
12
  }
@@ -19,7 +20,17 @@ export function createWebServer(port, frontendFetcher) {
19
20
  frontendFetcher(url, convertHeadersToFetch(req.headers), res);
20
21
  }
21
22
  }
22
- });
23
+ };
24
+ return createServer(isLogHttp() ? createLogWrapper(handler) : handler);
25
+ }
26
+ function createLogWrapper(handler) {
27
+ return (req, res) => {
28
+ console.log(' > ', req.method, req.url);
29
+ res.on('close', () => {
30
+ console.log('', res.statusCode, req.method, req.url);
31
+ });
32
+ handler(req, res);
33
+ };
23
34
  }
24
35
  export function createBuiltDistFilesFetcher(dir, files) {
25
36
  return (url, _headers, res) => {
@@ -39,7 +50,7 @@ export function createDevServeFilesFetcher(opts) {
39
50
  const proxyAddress = 'http://127.0.0.1:' + opts.proxyPort;
40
51
  return (url, _headers, res) => {
41
52
  if (opts.pages[url.pathname]) {
42
- streamFile(join(opts.pagesDir, url.pathname + 'index.html'), res);
53
+ streamFile(join(opts.pagesDir, url.pathname, 'index.html'), res);
43
54
  }
44
55
  else {
45
56
  const maybePublicPath = join(opts.publicDir, url.pathname);
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@eighty4/dank",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
+ "license": "MIT",
6
+ "author": "Adam McKee Bennett <adam.be.g84d@gmail.com>",
5
7
  "description": "Multi-page development system for CDN-deployed websites",
6
8
  "keywords": [
7
9
  "frontend",