katabatic 1.0.0 → 1.0.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/package.json +4 -1
- package/src/index.js +36 -20
- package/src/{serve.js → route.js} +2 -3
- package/src/utils/help.js +32 -0
- package/src/utils/argv.js +0 -12
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "katabatic",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"bin": {
|
|
17
17
|
"katabatic": "src/index.js"
|
|
18
18
|
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=20.0.0"
|
|
21
|
+
},
|
|
19
22
|
"dependencies": {
|
|
20
23
|
"@katabatic/compiler": "^1.0.0",
|
|
21
24
|
"@web/dev-server": "^0.4.6"
|
package/src/index.js
CHANGED
|
@@ -1,32 +1,48 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
|
|
3
2
|
import path from 'path'
|
|
4
3
|
import { watch as watchDir, existsSync } from 'fs'
|
|
4
|
+
import { parseArgs } from 'node:util'
|
|
5
5
|
import { startDevServer } from '@web/dev-server'
|
|
6
6
|
import { walkDir } from './utils/files.js'
|
|
7
|
-
import * as argv from './utils/argv.js'
|
|
8
|
-
import { serve } from './serve.js'
|
|
9
|
-
import { buildIndex, buildModule, buildRouter } from './build.js'
|
|
10
7
|
import { hash } from './utils/misc.js'
|
|
8
|
+
import { printHelp, withHelp } from './utils/help.js'
|
|
9
|
+
import { route } from './route.js'
|
|
10
|
+
import { buildIndex, buildModule, buildRouter } from './build.js'
|
|
11
|
+
|
|
12
|
+
const options = {
|
|
13
|
+
root: { type: 'string', short: 'r', description: 'project root directory (default: .)' },
|
|
14
|
+
srcDir: { type: 'string', description: 'src files directory (default .)' },
|
|
15
|
+
outDir: { type: 'string', description: 'out files directory (default .)' },
|
|
16
|
+
routesDir: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
description:
|
|
19
|
+
'page and layout files directory when using the file system router (default ./routes)'
|
|
20
|
+
},
|
|
21
|
+
help: { type: 'boolean', short: 'h', description: 'get help' },
|
|
22
|
+
watch: { type: 'boolean', short: 'w', description: 'watches the file system' },
|
|
23
|
+
serve: { type: 'boolean', short: 's', description: 'starts the development server' },
|
|
24
|
+
rewriteRelativeImportExtensions: {
|
|
25
|
+
type: 'boolean',
|
|
26
|
+
description: 'rewrite imported katabatic files extension (.html or .ktb) in .js'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
11
29
|
|
|
12
|
-
const
|
|
30
|
+
const { values: args } = withHelp(options, () => parseArgs({ options }))
|
|
13
31
|
|
|
14
|
-
const rootPath = path.resolve(
|
|
15
|
-
const srcDirPath = path.join(rootPath,
|
|
16
|
-
const outDirPath = path.join(rootPath,
|
|
17
|
-
const routesDirPath = path.join(srcDirPath,
|
|
32
|
+
const rootPath = path.resolve(args.root ?? '.')
|
|
33
|
+
const srcDirPath = path.join(rootPath, args.srcDir ?? '.')
|
|
34
|
+
const outDirPath = path.join(rootPath, args.outDir ?? '.')
|
|
35
|
+
const routesDirPath = path.join(srcDirPath, args.routesDir ?? './routes')
|
|
18
36
|
const hasRoutes = existsSync(routesDirPath)
|
|
19
37
|
|
|
20
|
-
const rewriteRelativeImportExtensions =
|
|
38
|
+
const rewriteRelativeImportExtensions = args.rewriteRelativeImportExtensions ?? false
|
|
21
39
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
start()
|
|
29
|
-
break
|
|
40
|
+
if (args.help) {
|
|
41
|
+
printHelp(options)
|
|
42
|
+
} else {
|
|
43
|
+
const registry = build()
|
|
44
|
+
if (args.watch) watch(registry)
|
|
45
|
+
if (args.serve) serve()
|
|
30
46
|
}
|
|
31
47
|
|
|
32
48
|
function build() {
|
|
@@ -76,11 +92,11 @@ function watch(registry) {
|
|
|
76
92
|
})
|
|
77
93
|
}
|
|
78
94
|
|
|
79
|
-
function
|
|
95
|
+
function serve() {
|
|
80
96
|
const plugins = []
|
|
81
97
|
|
|
82
98
|
if (hasRoutes) {
|
|
83
|
-
plugins.push(
|
|
99
|
+
plugins.push(route(outDirPath))
|
|
84
100
|
}
|
|
85
101
|
|
|
86
102
|
startDevServer({
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
|
|
3
|
-
export function
|
|
3
|
+
export function route(outDirPath) {
|
|
4
4
|
let router
|
|
5
5
|
|
|
6
6
|
return {
|
|
7
|
-
name: '
|
|
7
|
+
name: 'route',
|
|
8
8
|
async serve({ request }) {
|
|
9
9
|
router ??= await import(path.join(outDirPath, 'router.js'))
|
|
10
|
-
console.log(request.url)
|
|
11
10
|
return router.route(request.url)
|
|
12
11
|
}
|
|
13
12
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function printHelp(options, error) {
|
|
2
|
+
if (error) {
|
|
3
|
+
console.log(error.message)
|
|
4
|
+
console.log('')
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
console.log('usage: katabatic [options]')
|
|
8
|
+
console.log('')
|
|
9
|
+
for (const [name, config] of Object.entries(options)) {
|
|
10
|
+
let line = ''.padEnd(4)
|
|
11
|
+
line += config.short ? `-${config.short}, ` : ''
|
|
12
|
+
line += `--${name}`
|
|
13
|
+
line = line.padEnd(25)
|
|
14
|
+
|
|
15
|
+
if (line.length > 25) {
|
|
16
|
+
console.log(line)
|
|
17
|
+
line = ''.padEnd(25)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
line += config.description ?? ''
|
|
21
|
+
console.log(line)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function withHelp(options, fn) {
|
|
26
|
+
try {
|
|
27
|
+
return fn()
|
|
28
|
+
} catch (error) {
|
|
29
|
+
printHelp(options, error)
|
|
30
|
+
process.exit(1)
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/utils/argv.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function command() {
|
|
2
|
-
return process.argv[2]
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function option(name) {
|
|
6
|
-
const index = process.argv.indexOf(`-${name}`)
|
|
7
|
-
|
|
8
|
-
if (index >= 0) {
|
|
9
|
-
const value = process.argv[index + 1]
|
|
10
|
-
return value && value[0] !== '-' ? value : undefined
|
|
11
|
-
}
|
|
12
|
-
}
|