@michaelthielemann/kestrel 1.4.0 → 1.4.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 +2 -2
- package/nuxt.config.ts +18 -15
- package/package.json +1 -1
- package/scripts/hash-password.mjs +12 -0
- package/scripts/kestrel.mjs +4 -9
- package/scripts/lib/cli.mjs +44 -29
- package/templates/starter/README.md +1 -1
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ static host. It is deliberately **not**:
|
|
|
36
36
|
## Features
|
|
37
37
|
|
|
38
38
|
- **Runnable in one command** — `pnpm create kestrel` scaffolds a project that boots with a working
|
|
39
|
-
`/admin`,
|
|
39
|
+
`/admin`, asking you to choose the admin password and writing its hash; `kestrel init` does the same to an
|
|
40
40
|
existing project without clobbering it, and `kestrel doctor` names whatever is still missing.
|
|
41
41
|
- **Collection-driven** — declare collections + fields in TypeScript; Kestrel derives the SQLite tables, a
|
|
42
42
|
typed CRUD REST API, and the full admin UI. The schema **migrates itself** (additive in dev; explicit
|
|
@@ -66,7 +66,7 @@ pnpm create kestrel my-site
|
|
|
66
66
|
cd my-site && pnpm install && pnpm dev
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
It asks
|
|
69
|
+
It asks you to choose an admin password and writes a project that runs as-is: `nuxt.config.ts` extending the
|
|
70
70
|
meta-layer, an `app.vue` that renders, a `.env` holding a fresh session secret and the scrypt hash of
|
|
71
71
|
your password, and one example block. Sign in at <http://localhost:3000/admin>.
|
|
72
72
|
|
package/nuxt.config.ts
CHANGED
|
@@ -83,22 +83,25 @@ export default defineNuxtConfig({
|
|
|
83
83
|
vite: {
|
|
84
84
|
build: { rollupOptions: { onwarn } },
|
|
85
85
|
optimizeDeps: {
|
|
86
|
-
// Nested "
|
|
87
|
-
//
|
|
88
|
-
// are
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
//
|
|
86
|
+
// Nested "<pkg> > dep" form: Vite resolves each dep from THIS package's directory rather than from
|
|
87
|
+
// the consumer's project root. It has to be the published name — under pnpm these are kestrel's
|
|
88
|
+
// transitive deps and are not hoisted into a consumer's top-level node_modules, so resolving from
|
|
89
|
+
// the root finds nothing. An unresolvable prefix is swallowed (`resolvePackageData(…)?.dir ||
|
|
90
|
+
// basedir`), and the entry then degrades to a bare lookup from the root: fine in-repo and for a
|
|
91
|
+
// hoisted npm/yarn consumer, silently unbundled for a pnpm one — which is why a stale prefix shows
|
|
92
|
+
// up only in a consumer's terminal. In-repo the name is likewise unresolvable and that same
|
|
93
|
+
// fallback lands on the repo root, where the deps ARE hoisted. The runtime `import('@tiptap/...')`
|
|
94
|
+
// still reuses the pre-bundle (tryOptimizedResolve matches the "> dep" id + src dir).
|
|
95
|
+
// `test/package.test.ts` pins the prefix to package.json's `name`.
|
|
93
96
|
include: [
|
|
94
|
-
'kestrel > @internationalized/date',
|
|
95
|
-
'kestrel > @tiptap/extension-highlight',
|
|
96
|
-
'kestrel > @tiptap/extension-subscript',
|
|
97
|
-
'kestrel > @tiptap/extension-superscript',
|
|
98
|
-
'kestrel > @tiptap/extension-text-align',
|
|
99
|
-
'kestrel > @tiptap/starter-kit',
|
|
100
|
-
'kestrel > @tiptap/vue-3',
|
|
101
|
-
'kestrel > reka-ui',
|
|
97
|
+
'@michaelthielemann/kestrel > @internationalized/date',
|
|
98
|
+
'@michaelthielemann/kestrel > @tiptap/extension-highlight',
|
|
99
|
+
'@michaelthielemann/kestrel > @tiptap/extension-subscript',
|
|
100
|
+
'@michaelthielemann/kestrel > @tiptap/extension-superscript',
|
|
101
|
+
'@michaelthielemann/kestrel > @tiptap/extension-text-align',
|
|
102
|
+
'@michaelthielemann/kestrel > @tiptap/starter-kit',
|
|
103
|
+
'@michaelthielemann/kestrel > @tiptap/vue-3',
|
|
104
|
+
'@michaelthielemann/kestrel > reka-ui',
|
|
102
105
|
],
|
|
103
106
|
},
|
|
104
107
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@michaelthielemann/kestrel",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "A slim, collection-driven Nuxt 4 CMS meta-layer with a runtime schema engine. Add `extends: ['@michaelthielemann/kestrel']`, define collections, and the database migrates itself.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Michael Thielemann <283621694+MichaelThielemann@users.noreply.github.com>",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createInterface } from 'node:readline'
|
|
2
2
|
import { hashPassword } from './lib/password.mjs'
|
|
3
|
+
import { Cancelled, promptPassword } from './lib/cli.mjs'
|
|
3
4
|
|
|
4
5
|
// Not used at runtime: this prints a value an operator pastes into KESTREL_ADMIN_PASSWORD_HASH. Kept as a
|
|
5
6
|
// standalone entry point because docs/consuming-kestrel.md tells consumers to run it straight out of
|
|
@@ -7,7 +8,18 @@ import { hashPassword } from './lib/password.mjs'
|
|
|
7
8
|
const arg = process.argv[2]
|
|
8
9
|
if (arg) {
|
|
9
10
|
process.stdout.write(hashPassword(arg) + '\n')
|
|
11
|
+
} else if (process.stdin.isTTY) {
|
|
12
|
+
// Only the hash may reach stdout — an operator pipes it straight into a secret store.
|
|
13
|
+
try {
|
|
14
|
+
process.stdout.write(hashPassword(await promptPassword({ output: process.stderr })) + '\n')
|
|
15
|
+
} catch (err) {
|
|
16
|
+
if (!(err instanceof Cancelled)) throw err
|
|
17
|
+
process.stderr.write('cancelled\n')
|
|
18
|
+
process.exitCode = 1
|
|
19
|
+
}
|
|
10
20
|
} else {
|
|
21
|
+
// `terminal: false` keeps the piped form (`echo pw | node hash-password.mjs`) working; it is only safe
|
|
22
|
+
// because stdin is not a tty here, so there is no line discipline echoing the password onto a screen.
|
|
11
23
|
const rl = createInterface({ input: process.stdin, terminal: false })
|
|
12
24
|
process.stderr.write('Enter password, then press Enter:\n')
|
|
13
25
|
rl.on('line', (line) => {
|
package/scripts/kestrel.mjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync } from 'node:fs'
|
|
3
3
|
import { join, resolve, basename, relative } from 'node:path'
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
|
-
import { createInterface } from 'node:readline/promises'
|
|
6
5
|
import { hashPassword, sessionSecret } from './lib/password.mjs'
|
|
7
6
|
import { PACKAGE_NAME, diagnoseProject, mergeEnv, mergePackageJson, renderTemplate, targetName, toPackageName } from './lib/scaffold.mjs'
|
|
8
7
|
import { Cancelled, MIN_PASSWORD_LENGTH, makePaint, out, parseArgs, promptPassword, readIf, readStdin, walk, write } from './lib/cli.mjs'
|
|
@@ -71,15 +70,12 @@ async function init(positional, flags) {
|
|
|
71
70
|
out()
|
|
72
71
|
|
|
73
72
|
if (password === undefined && !flags.yes && process.stdin.isTTY) {
|
|
74
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout })
|
|
75
73
|
try {
|
|
76
|
-
password = await promptPassword(
|
|
74
|
+
password = await promptPassword({ warn: (m) => out(yellow(m)), note: (m) => out(dim(m)) })
|
|
77
75
|
} catch (err) {
|
|
78
|
-
rl.close()
|
|
79
76
|
if (err instanceof Cancelled) fail('cancelled')
|
|
80
77
|
throw err
|
|
81
78
|
}
|
|
82
|
-
rl.close()
|
|
83
79
|
out()
|
|
84
80
|
}
|
|
85
81
|
|
|
@@ -170,15 +166,14 @@ async function hashPasswordCommand(positional) {
|
|
|
170
166
|
let password = positional[0]
|
|
171
167
|
if (password === undefined) {
|
|
172
168
|
if (process.stdin.isTTY) {
|
|
173
|
-
|
|
169
|
+
// Only the hash may reach stdout — an operator redirects it straight into a secret store.
|
|
170
|
+
const ask = (m) => process.stderr.write(`${m}\n`)
|
|
174
171
|
try {
|
|
175
|
-
password = await promptPassword(
|
|
172
|
+
password = await promptPassword({ output: process.stderr, warn: (m) => ask(yellow(m)), note: (m) => ask(dim(m)) })
|
|
176
173
|
} catch (err) {
|
|
177
|
-
rl.close()
|
|
178
174
|
if (err instanceof Cancelled) fail('cancelled')
|
|
179
175
|
throw err
|
|
180
176
|
}
|
|
181
|
-
rl.close()
|
|
182
177
|
} else password = await readStdin()
|
|
183
178
|
}
|
|
184
179
|
if (!password) fail('no password given')
|
package/scripts/lib/cli.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync, chmodSync } from 'node:fs'
|
|
2
2
|
import { dirname, join, relative } from 'node:path'
|
|
3
|
+
import { createInterface } from 'node:readline/promises'
|
|
3
4
|
|
|
4
5
|
export const MIN_PASSWORD_LENGTH = 8
|
|
5
6
|
|
|
@@ -65,44 +66,58 @@ export function walk(dir, base = dir) {
|
|
|
65
66
|
return found
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
* chunk that ends in a newline and would otherwise be left on screen and in the scrollback.
|
|
72
|
-
*/
|
|
73
|
-
async function askHidden(rl, question) {
|
|
74
|
-
const repaint = () => process.stdout.write(`\u001b[2K\u001b[200D${question}`)
|
|
75
|
-
process.stdin.on('data', repaint)
|
|
69
|
+
/** Reads a line the interface is configured never to echo, so the prompt is ours to draw and to close. */
|
|
70
|
+
async function askHidden(rl, question, write) {
|
|
71
|
+
write(question)
|
|
76
72
|
try {
|
|
77
|
-
return (await rl.question(
|
|
73
|
+
return (await rl.question('')).trim()
|
|
78
74
|
} finally {
|
|
79
|
-
|
|
80
|
-
repaint()
|
|
81
|
-
process.stdout.write('\n')
|
|
75
|
+
write('\n')
|
|
82
76
|
}
|
|
83
77
|
}
|
|
84
78
|
|
|
85
79
|
export class Cancelled extends Error {}
|
|
86
80
|
|
|
87
|
-
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Owns its readline interface, because the two options that keep the secret off the screen can only be
|
|
83
|
+
* set at construction: `output: null` makes readline write nothing at all, and `terminal: true` still
|
|
84
|
+
* gives it the keypress handling (backspace, Ctrl-C, Ctrl-D) that would otherwise fall to the tty's own
|
|
85
|
+
* echoing line discipline. Erasing readline's echo afterwards cannot match that — a pasted secret arrives
|
|
86
|
+
* as one chunk that is echoed AND newlined in a single write, stranding the cleartext on a line no
|
|
87
|
+
* repaint can still reach, and a redirected stdout leaves `terminal` false with nothing to suppress.
|
|
88
|
+
*
|
|
89
|
+
* Throws `Cancelled` on Ctrl-C / Ctrl-D so a caller can exit cleanly instead of on an AbortError stack.
|
|
90
|
+
*/
|
|
91
|
+
export async function promptPassword({
|
|
92
|
+
input = process.stdin,
|
|
93
|
+
output = process.stdout,
|
|
94
|
+
warn = (m) => output.write(`${m}\n`),
|
|
95
|
+
note = (m) => output.write(`${m}\n`),
|
|
96
|
+
} = {}) {
|
|
97
|
+
const draw = (s) => output.write(s)
|
|
98
|
+
const rl = createInterface({ input, output: null, terminal: true })
|
|
99
|
+
note(`Choose a password for /admin — at least ${MIN_PASSWORD_LENGTH} characters, kept only as a scrypt hash.`)
|
|
100
|
+
try {
|
|
101
|
+
for (;;) {
|
|
102
|
+
let first
|
|
103
|
+
try {
|
|
104
|
+
first = await askHidden(rl, 'New admin password: ', draw)
|
|
105
|
+
if (first.length < MIN_PASSWORD_LENGTH) {
|
|
106
|
+
warn(` too short — at least ${MIN_PASSWORD_LENGTH} characters`)
|
|
107
|
+
continue
|
|
108
|
+
}
|
|
109
|
+
if (first !== (await askHidden(rl, 'Repeat password: ', draw))) {
|
|
110
|
+
warn(' the two entries differ — try again')
|
|
111
|
+
continue
|
|
112
|
+
}
|
|
113
|
+
} catch (err) {
|
|
114
|
+
throw err?.code === 'ABORT_ERR' ? new Cancelled() : err
|
|
100
115
|
}
|
|
101
|
-
|
|
102
|
-
|
|
116
|
+
if (first === undefined) throw new Cancelled()
|
|
117
|
+
return first
|
|
103
118
|
}
|
|
104
|
-
|
|
105
|
-
|
|
119
|
+
} finally {
|
|
120
|
+
rl.close()
|
|
106
121
|
}
|
|
107
122
|
}
|
|
108
123
|
|
|
@@ -8,7 +8,7 @@ pnpm install
|
|
|
8
8
|
pnpm dev
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Admin: <http://localhost:3000/admin> — sign in with the password you chose
|
|
11
|
+
Admin: <http://localhost:3000/admin> — sign in with the password you chose while scaffolding.
|
|
12
12
|
Forgot it? `pnpm hash-password` prints a fresh hash for `KESTREL_ADMIN_PASSWORD_HASH` in `.env`.
|
|
13
13
|
|
|
14
14
|
## What is here
|