@avelonjs/cli 0.8.7 → 0.9.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 +21 -1
- package/package.json +6 -5
- package/src/commands.ts +13 -7
- package/src/help.ts +87 -0
- package/src/index.ts +32 -7
- package/src/menu.ts +215 -46
- package/src/new-app.ts +85 -0
- package/src/route-check.ts +56 -0
- package/src/tui.tsx +52 -20
- package/templates/app/.gitignore.stub +12 -0
- package/templates/app/README.md.stub +33 -0
- package/templates/app/app/Actions/slug.ts.stub +10 -0
- package/templates/app/app/Http/Controllers/PreviewController.ts.stub +22 -0
- package/templates/app/app/Http/Requests/PreviewRequest.ts.stub +21 -0
- package/templates/app/avelon.config.ts.stub +6 -0
- package/templates/app/next.config.ts.stub +8 -0
- package/templates/app/package.json.stub +29 -0
- package/templates/app/resources/actions/submitTitle.ts.stub +20 -0
- package/templates/app/resources/css/app.css.stub +163 -0
- package/templates/app/resources/views/PreviewPage.tsx.stub +21 -0
- package/templates/app/resources/views/TitleForm.tsx.stub +33 -0
- package/templates/app/resources/views/TitlePage.tsx.stub +17 -0
- package/templates/app/resources/views/layouts/AppLayout.tsx.stub +28 -0
- package/templates/app/routes/web.ts.stub +6 -0
- package/templates/app/tests/preview.test.ts.stub +39 -0
- package/templates/app/tsconfig.json.stub +24 -0
package/README.md
CHANGED
|
@@ -27,13 +27,31 @@ resolve the local `reeve` binary:
|
|
|
27
27
|
## Basic Usage
|
|
28
28
|
|
|
29
29
|
```sh
|
|
30
|
+
reeve help make:model
|
|
30
31
|
reeve make:model Post -mfcpw
|
|
31
32
|
reeve route:sync
|
|
33
|
+
reeve route:sync --check
|
|
32
34
|
reeve bailiff --explain no-orphan-query
|
|
33
35
|
reeve doctor
|
|
34
36
|
```
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
In the TUI, press `/` to search and `?` to see a command's usage. Commands that need a name or path show an example when selected. Use `reeve <command> --help` for the same information in a script.
|
|
39
|
+
|
|
40
|
+
## Create an app
|
|
41
|
+
|
|
42
|
+
`reeve new <directory>` creates a standalone TypeScript app with a working form and tests.
|
|
43
|
+
From this checkout, use `bun run create:app ../my-app`. With a packaged CLI that lists `new`
|
|
44
|
+
in its help, you can run it without a checkout:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
bunx --package @avelonjs/cli reeve new my-app
|
|
48
|
+
cd my-app
|
|
49
|
+
bun install
|
|
50
|
+
bun run dev
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The target must be new or empty (`.` works). Generated dependencies use the CLI's package scope
|
|
54
|
+
and version. The command leaves installation and server startup to you.
|
|
37
55
|
|
|
38
56
|
## Generators
|
|
39
57
|
|
|
@@ -90,6 +108,8 @@ reeve errand:flush
|
|
|
90
108
|
`migrate:fresh` names what it will destroy and requires typing the environment name when it is not `local`.
|
|
91
109
|
|
|
92
110
|
`db:seed` and route commands exit with an error when a seed or route module fails to load or run.
|
|
111
|
+
`reeve route:sync --check` compares the router with `routes/web.ts` and lists missing, changed,
|
|
112
|
+
or stale paths. It exits 1 on drift without rewriting files. Run `reeve route:sync` to repair them.
|
|
93
113
|
|
|
94
114
|
## Doctor and inspect
|
|
95
115
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avelonjs/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "reeve CLI and TUI for generating and administering Avelon applications.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"src",
|
|
29
|
+
"templates",
|
|
29
30
|
"README.md",
|
|
30
31
|
"LICENSE"
|
|
31
32
|
],
|
|
@@ -40,10 +41,10 @@
|
|
|
40
41
|
"typecheck": "tsc --noEmit"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
43
|
-
"@avelonjs/assay": "0.
|
|
44
|
-
"@avelonjs/bailiff": "0.
|
|
45
|
-
"@avelonjs/core": "0.
|
|
46
|
-
"@avelonjs/next": "0.
|
|
44
|
+
"@avelonjs/assay": "0.9.0",
|
|
45
|
+
"@avelonjs/bailiff": "0.9.0",
|
|
46
|
+
"@avelonjs/core": "0.9.0",
|
|
47
|
+
"@avelonjs/next": "0.9.0",
|
|
47
48
|
"ink": "5.2.1",
|
|
48
49
|
"react": "18.3.1"
|
|
49
50
|
},
|
package/src/commands.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { readdir, writeFile, mkdir, stat } from 'node:fs/promises'
|
|
2
|
-
import { join } from 'node:path'
|
|
3
|
-
import { pathToFileURL } from 'node:url'
|
|
2
|
+
import { join, resolve } from 'node:path'
|
|
4
3
|
import { runSeeds } from '@avelonjs/assay'
|
|
5
4
|
import { parseBailiffArgs, runBailiff } from '@avelonjs/bailiff'
|
|
6
5
|
import {
|
|
@@ -14,6 +13,7 @@ import {
|
|
|
14
13
|
} from '@avelonjs/core'
|
|
15
14
|
import { NextAdapter, Route } from '@avelonjs/next'
|
|
16
15
|
|
|
16
|
+
import { createApp } from './new-app'
|
|
17
17
|
import { makeDriver } from './driver-scaffold'
|
|
18
18
|
import { runDocsCheck } from './docs-check'
|
|
19
19
|
import {
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
type GenerateOptions,
|
|
25
25
|
} from './generate'
|
|
26
26
|
import { headerBits, snake, studly, writeln, type ReeveIO } from './io'
|
|
27
|
+
import { checkAppRouter, MISSING_ROUTES } from './route-check'
|
|
27
28
|
|
|
28
29
|
function flags(argv: readonly string[]): GenerateOptions {
|
|
29
30
|
const blob = argv.filter((arg) => arg.startsWith('-') && !arg.startsWith('--')).join('')
|
|
@@ -67,11 +68,12 @@ async function pathExists(file: string): Promise<boolean> {
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
async function loadRoutes(io: ReeveIO): Promise<
|
|
71
|
-
const file =
|
|
72
|
-
if (!(await pathExists(file))) return
|
|
71
|
+
async function loadRoutes(io: ReeveIO): Promise<boolean> {
|
|
72
|
+
const file = resolve(io.cwd, 'routes/web.ts')
|
|
73
|
+
if (!(await pathExists(file))) return false
|
|
73
74
|
Route.reset()
|
|
74
|
-
await import(`${
|
|
75
|
+
await import(`${file}?t=${crypto.randomUUID()}`)
|
|
76
|
+
return true
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
function requireName(argv: readonly string[], usage: string): string {
|
|
@@ -88,6 +90,8 @@ export async function runCommand(
|
|
|
88
90
|
): Promise<number> {
|
|
89
91
|
const options = flags(argv)
|
|
90
92
|
switch (command) {
|
|
93
|
+
case 'new':
|
|
94
|
+
return createApp(argv, io)
|
|
91
95
|
case 'make:model':
|
|
92
96
|
await makeModel(io, requireName(argv, 'Usage: reeve make:model Name [-mfcpw]'), options)
|
|
93
97
|
return 0
|
|
@@ -261,7 +265,9 @@ export async function runCommand(
|
|
|
261
265
|
return 0
|
|
262
266
|
}
|
|
263
267
|
case 'route:sync': {
|
|
264
|
-
|
|
268
|
+
if (argv.length === 1 && argv[0] === '--check') return checkAppRouter(io)
|
|
269
|
+
if (argv.length !== 0) throw new Error('Usage: reeve route:sync [--check]')
|
|
270
|
+
if (!(await loadRoutes(io)) && Route.all().length === 0) throw new Error(MISSING_ROUTES)
|
|
265
271
|
const adapter = new NextAdapter({ root: io.cwd })
|
|
266
272
|
const result = await adapter.mount(Route.manifest(), { kernel: createKernel() })
|
|
267
273
|
writeln(
|
package/src/help.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { COMMANDS, TOPICS, type CommandTopic } from './menu'
|
|
2
|
+
|
|
3
|
+
function invocation(topic: CommandTopic): string {
|
|
4
|
+
return [topic.command, topic.requiredArgs, topic.optionalArgs].filter(Boolean).join(' ')
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function globalHelp(): string {
|
|
8
|
+
const lines = [
|
|
9
|
+
'Usage: reeve <command> [arguments] [flags]',
|
|
10
|
+
' reeve help [command]',
|
|
11
|
+
' reeve <command> --help',
|
|
12
|
+
'',
|
|
13
|
+
'Run reeve without arguments in a terminal to browse commands.',
|
|
14
|
+
'',
|
|
15
|
+
'Global flags:',
|
|
16
|
+
' -h, --help Show help and exit.',
|
|
17
|
+
' --no-tui Use plain output.',
|
|
18
|
+
]
|
|
19
|
+
const width = Math.max(...TOPICS.map((topic) => invocation(topic).length))
|
|
20
|
+
let group: string | undefined
|
|
21
|
+
for (const topic of TOPICS) {
|
|
22
|
+
if (topic.group !== group) {
|
|
23
|
+
group = topic.group
|
|
24
|
+
lines.push('', `${group}:`)
|
|
25
|
+
}
|
|
26
|
+
lines.push(` ${invocation(topic).padEnd(width)} ${topic.summary}`)
|
|
27
|
+
}
|
|
28
|
+
lines.push(
|
|
29
|
+
'',
|
|
30
|
+
'Examples:',
|
|
31
|
+
' reeve new my-app',
|
|
32
|
+
' reeve route:sync --check',
|
|
33
|
+
' reeve help make:model',
|
|
34
|
+
)
|
|
35
|
+
return lines.join('\n')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function commandHelp(topic: CommandTopic): string {
|
|
39
|
+
const flags = Object.entries(topic.flags ?? {})
|
|
40
|
+
const usage = [invocation(topic), ...flags.map(([name]) => `[${name.split(', ')[0]}]`)]
|
|
41
|
+
const lines = [`Usage: reeve ${usage.join(' ')}`, '', topic.summary]
|
|
42
|
+
if (topic.details) lines.push('', topic.details)
|
|
43
|
+
if (flags.length > 0) {
|
|
44
|
+
lines.push('', 'Flags:')
|
|
45
|
+
const width = Math.max(...flags.map(([name]) => name.length))
|
|
46
|
+
for (const [name, description] of flags) lines.push(` ${name.padEnd(width)} ${description}`)
|
|
47
|
+
}
|
|
48
|
+
lines.push(
|
|
49
|
+
'',
|
|
50
|
+
'Examples:',
|
|
51
|
+
` reeve ${[topic.command, topic.exampleArgs].filter(Boolean).join(' ')}`,
|
|
52
|
+
)
|
|
53
|
+
return lines.join('\n')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function editDistance(input: string, name: string): number {
|
|
57
|
+
const row = Array.from(name, (_, i) => i + 1)
|
|
58
|
+
for (let i = 0; i < input.length; i++) {
|
|
59
|
+
let diagonal = i
|
|
60
|
+
let left = i + 1
|
|
61
|
+
for (const [j, above] of row.entries()) {
|
|
62
|
+
left = Math.min(left + 1, above + 1, diagonal + Number(input[i] !== name[j]))
|
|
63
|
+
row[j] = left
|
|
64
|
+
diagonal = above
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return row.at(-1) ?? input.length
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function unknownCommand(input: string): string {
|
|
71
|
+
const needle = input.toLowerCase()
|
|
72
|
+
const limit = needle.length < 8 ? 2 : 3
|
|
73
|
+
let best = limit + 1
|
|
74
|
+
let suggestion: string | undefined
|
|
75
|
+
for (const name of COMMANDS.toSorted()) {
|
|
76
|
+
if (Math.abs(needle.length - name.length) > limit) continue
|
|
77
|
+
const distance = editDistance(needle, name)
|
|
78
|
+
if (distance < best) {
|
|
79
|
+
suggestion = name
|
|
80
|
+
best = distance
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const message = [`Unknown command '${input}'.`]
|
|
84
|
+
if (suggestion) message.push(`Did you mean '${suggestion}'?`)
|
|
85
|
+
message.push("Run 'reeve help' to list commands.")
|
|
86
|
+
return message.join('\n')
|
|
87
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { commandHelp, globalHelp, unknownCommand } from './help'
|
|
2
2
|
import { processIO, shouldUseTui, writeln, type ReeveIO } from './io'
|
|
3
|
-
import {
|
|
3
|
+
import { TOPICS } from './menu'
|
|
4
4
|
|
|
5
5
|
export { COMMANDS, MENU } from './menu'
|
|
6
6
|
export { shouldUseTui, processIO, type ReeveIO } from './io'
|
|
7
|
-
export { runCommand } from './commands'
|
|
8
7
|
export {
|
|
9
8
|
checkPackageDocs,
|
|
10
9
|
runDocsCheck,
|
|
@@ -13,6 +12,33 @@ export {
|
|
|
13
12
|
} from './docs-check'
|
|
14
13
|
export { makeDriver, DRIVER_CONTRACTS, type DriverContractSpec } from './driver-scaffold'
|
|
15
14
|
|
|
15
|
+
function isHelpFlag(arg: string): boolean {
|
|
16
|
+
return arg === '--help' || arg === '-h'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function runCommand(
|
|
20
|
+
command: string,
|
|
21
|
+
argv: readonly string[],
|
|
22
|
+
io: ReeveIO,
|
|
23
|
+
): Promise<number> {
|
|
24
|
+
if (isHelpFlag(command) || (command === 'help' && argv.length === 0)) {
|
|
25
|
+
writeln(io, globalHelp())
|
|
26
|
+
return 0
|
|
27
|
+
}
|
|
28
|
+
const name = command === 'help' ? (argv.find((arg) => !isHelpFlag(arg)) ?? 'help') : command
|
|
29
|
+
const topic = TOPICS.find((entry) => entry.command === name)
|
|
30
|
+
if (!topic) {
|
|
31
|
+
writeln(io, unknownCommand(name))
|
|
32
|
+
return 1
|
|
33
|
+
}
|
|
34
|
+
if (command === 'help' || argv.some(isHelpFlag)) {
|
|
35
|
+
writeln(io, commandHelp(topic))
|
|
36
|
+
return 0
|
|
37
|
+
}
|
|
38
|
+
const { runCommand: dispatch } = await import('./commands')
|
|
39
|
+
return dispatch(command, argv, io)
|
|
40
|
+
}
|
|
41
|
+
|
|
16
42
|
/**
|
|
17
43
|
* Runs `reeve`. Bare invocation opens the TUI when stdout is a TTY. Any subcommand with arguments
|
|
18
44
|
* skips the TUI entirely. `--no-tui` and a non-TTY stdout force plain mode.
|
|
@@ -29,10 +55,9 @@ export async function runReeve(
|
|
|
29
55
|
}
|
|
30
56
|
const args = argv.filter((arg) => arg !== '--no-tui')
|
|
31
57
|
const command = args[0]
|
|
32
|
-
if (command === undefined
|
|
33
|
-
writeln(io,
|
|
34
|
-
|
|
35
|
-
return command === undefined ? 1 : 0
|
|
58
|
+
if (command === undefined) {
|
|
59
|
+
writeln(io, globalHelp())
|
|
60
|
+
return 1
|
|
36
61
|
}
|
|
37
62
|
return await runCommand(command, args.slice(1), io)
|
|
38
63
|
} catch (error) {
|
package/src/menu.ts
CHANGED
|
@@ -1,53 +1,222 @@
|
|
|
1
|
-
|
|
1
|
+
import { DRIVER_CONTRACTS } from './driver-scaffold'
|
|
2
|
+
|
|
2
3
|
export interface MenuItem {
|
|
3
4
|
group: string
|
|
4
5
|
label: string
|
|
5
6
|
command: string
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
9
|
+
interface CommandDetails {
|
|
10
|
+
summary: string
|
|
11
|
+
requiredArgs?: string
|
|
12
|
+
optionalArgs?: string
|
|
13
|
+
flags?: Record<string, string>
|
|
14
|
+
exampleArgs?: string
|
|
15
|
+
details?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type CommandTopic = MenuItem & CommandDetails
|
|
19
|
+
|
|
20
|
+
const groups: Record<string, Record<string, CommandDetails>> = {
|
|
21
|
+
Project: {
|
|
22
|
+
new: {
|
|
23
|
+
requiredArgs: '<directory>',
|
|
24
|
+
summary: 'Create an Avelon app in a new or empty directory.',
|
|
25
|
+
exampleArgs: 'my-app',
|
|
26
|
+
},
|
|
27
|
+
help: {
|
|
28
|
+
optionalArgs: '[command]',
|
|
29
|
+
summary: 'List commands or show usage, flags, and examples for one command.',
|
|
30
|
+
exampleArgs: 'route:sync',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
Make: {
|
|
34
|
+
'make:model': {
|
|
35
|
+
requiredArgs: '<name>',
|
|
36
|
+
summary: 'Generate a model in app/Models.',
|
|
37
|
+
flags: {
|
|
38
|
+
'-m, --migration': 'Generate a migration.',
|
|
39
|
+
'-f, --factory': 'Generate a factory.',
|
|
40
|
+
'-c, --controller': 'Generate a controller.',
|
|
41
|
+
'-p, --policy': 'Generate a policy.',
|
|
42
|
+
'-w, --ward': 'Generate a ward.',
|
|
43
|
+
'--resource': 'Use resource actions for the generated controller (with -c).',
|
|
44
|
+
},
|
|
45
|
+
exampleArgs: 'Post -mfcpw --resource',
|
|
46
|
+
},
|
|
47
|
+
'make:controller': {
|
|
48
|
+
requiredArgs: '<name>',
|
|
49
|
+
summary: 'Generate an HTTP controller.',
|
|
50
|
+
flags: { '--resource': 'Include resource actions.' },
|
|
51
|
+
exampleArgs: 'PostController --resource',
|
|
52
|
+
},
|
|
53
|
+
'make:request': {
|
|
54
|
+
requiredArgs: '<name>',
|
|
55
|
+
summary: 'Generate a request in app/Http/Requests.',
|
|
56
|
+
exampleArgs: 'StorePostRequest',
|
|
57
|
+
},
|
|
58
|
+
'make:policy': {
|
|
59
|
+
requiredArgs: '<name>',
|
|
60
|
+
summary: 'Generate an authorization policy.',
|
|
61
|
+
flags: { '--model=<name>': 'Set the model name in the policy stub.' },
|
|
62
|
+
exampleArgs: 'PostPolicy --model=Post',
|
|
63
|
+
},
|
|
64
|
+
'make:ward': {
|
|
65
|
+
requiredArgs: '<name>',
|
|
66
|
+
summary: 'Generate a ward in app/Wards.',
|
|
67
|
+
flags: { '--model=<name>': 'Set the model name in the ward stub.' },
|
|
68
|
+
exampleArgs: 'PostWard --model=Post',
|
|
69
|
+
},
|
|
70
|
+
'make:event': {
|
|
71
|
+
requiredArgs: '<name>',
|
|
72
|
+
summary: 'Generate a domain event.',
|
|
73
|
+
exampleArgs: 'PostPublished',
|
|
74
|
+
},
|
|
75
|
+
'make:listener': {
|
|
76
|
+
requiredArgs: '<name>',
|
|
77
|
+
summary: 'Generate an event listener.',
|
|
78
|
+
flags: {
|
|
79
|
+
'--event=<name>': 'Set the event name in the listener stub.',
|
|
80
|
+
'--queued': 'Use queued delivery instead of synchronous delivery.',
|
|
81
|
+
},
|
|
82
|
+
exampleArgs: 'NotifySubscribers --event=PostPublished --queued',
|
|
83
|
+
},
|
|
84
|
+
'make:errand': {
|
|
85
|
+
requiredArgs: '<name>',
|
|
86
|
+
summary: 'Generate a queued errand.',
|
|
87
|
+
exampleArgs: 'GenerateThumbnail',
|
|
88
|
+
},
|
|
89
|
+
'make:action': {
|
|
90
|
+
requiredArgs: '<name>',
|
|
91
|
+
summary: 'Generate an action in app/Actions.',
|
|
92
|
+
exampleArgs: 'PublishPost',
|
|
93
|
+
},
|
|
94
|
+
'make:command': {
|
|
95
|
+
requiredArgs: '<name>',
|
|
96
|
+
summary: 'Generate a command stub in app/Commands.',
|
|
97
|
+
exampleArgs: 'PruneDrafts',
|
|
98
|
+
},
|
|
99
|
+
'make:middleware': {
|
|
100
|
+
requiredArgs: '<name>',
|
|
101
|
+
summary: 'Generate HTTP middleware.',
|
|
102
|
+
exampleArgs: 'EnsureSubscribed',
|
|
103
|
+
},
|
|
104
|
+
'make:view': {
|
|
105
|
+
requiredArgs: '<path>',
|
|
106
|
+
summary: 'Generate a view reference at a path relative to resources/views.',
|
|
107
|
+
exampleArgs: 'posts/Index',
|
|
108
|
+
},
|
|
109
|
+
'make:driver': {
|
|
110
|
+
requiredArgs: '<contract> <slug>',
|
|
111
|
+
summary: 'Generate a driver package with a conformance test.',
|
|
112
|
+
details: `Contracts: ${DRIVER_CONTRACTS.join(', ')}.`,
|
|
113
|
+
exampleArgs: 'storage r2',
|
|
114
|
+
},
|
|
115
|
+
'make:package': {
|
|
116
|
+
requiredArgs: '<slug>',
|
|
117
|
+
summary: 'Generate a package README under packages/.',
|
|
118
|
+
exampleArgs: 'billing',
|
|
119
|
+
},
|
|
120
|
+
'make:auth': { summary: 'Generate a session controller, sign-in request, and view stub.' },
|
|
121
|
+
'make:migration': {
|
|
122
|
+
requiredArgs: '<name>',
|
|
123
|
+
summary: 'Generate a dated migration in database/migrations.',
|
|
124
|
+
exampleArgs: 'create_posts_table',
|
|
125
|
+
},
|
|
126
|
+
'stub:publish': { summary: 'Copy the built-in generator templates into stubs/.' },
|
|
127
|
+
},
|
|
128
|
+
Database: {
|
|
129
|
+
migrate: { summary: 'Apply pending migrations with the configured database driver.' },
|
|
130
|
+
'migrate:status': { summary: 'Print migration status from the configured database driver.' },
|
|
131
|
+
'migrate:rollback': { summary: 'Roll back the latest applied migration.' },
|
|
132
|
+
'migrate:fresh': {
|
|
133
|
+
summary: 'Roll back up to 100 migrations, then apply pending migrations.',
|
|
134
|
+
flags: {
|
|
135
|
+
'--seed': 'Run database seeds after applying migrations.',
|
|
136
|
+
'--confirm=<environment>': 'Confirm the environment name when running outside local.',
|
|
137
|
+
},
|
|
138
|
+
exampleArgs: '--seed',
|
|
139
|
+
},
|
|
140
|
+
'db:seed': { summary: 'Run the seeds in database/seeds.' },
|
|
141
|
+
'schema:pull': { summary: 'Write an empty Database interface to database/types.ts.' },
|
|
142
|
+
},
|
|
143
|
+
Wards: {
|
|
144
|
+
'ward:list': { summary: 'List model and ward filenames.' },
|
|
145
|
+
'ward:sync': { summary: 'Print instructions for compiling wards with a database driver.' },
|
|
146
|
+
'ward:check': { summary: 'Check that each model has a matching ward file.' },
|
|
147
|
+
'ward:explain': {
|
|
148
|
+
optionalArgs: '[model] [action]',
|
|
149
|
+
summary: 'Print where to inspect ward rules for an action (default: read).',
|
|
150
|
+
exampleArgs: 'Post read',
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
Routes: {
|
|
154
|
+
'route:list': { summary: 'List registered routes, controllers, and middleware.' },
|
|
155
|
+
'route:sync': {
|
|
156
|
+
summary: 'Generate Next router files from the route manifest.',
|
|
157
|
+
flags: {
|
|
158
|
+
'--check':
|
|
159
|
+
'Report missing, changed, or stale router files without writing files. Exit 1 on drift.',
|
|
160
|
+
},
|
|
161
|
+
exampleArgs: '--check',
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
Errands: {
|
|
165
|
+
'errand:work': { summary: 'Drain queued errands.' },
|
|
166
|
+
'errand:failed': { summary: 'List failed jobs.' },
|
|
167
|
+
'errand:retry': {
|
|
168
|
+
optionalArgs: '[id|all]',
|
|
169
|
+
summary: 'Retry a failed job by ID. Omit the ID or use all to retry every failed job.',
|
|
170
|
+
exampleArgs: 'all',
|
|
171
|
+
},
|
|
172
|
+
'errand:flush': { summary: 'Clear pending and failed jobs and reset the errand registry.' },
|
|
173
|
+
},
|
|
174
|
+
Inspect: {
|
|
175
|
+
'event:list': { summary: 'Print where to find event providers and listeners.' },
|
|
176
|
+
'config:show': { summary: 'Print the configured app name and driver keys.' },
|
|
177
|
+
capabilities: { summary: 'Print the capability matrix for configured drivers.' },
|
|
178
|
+
about: { summary: 'Show the app, database, adapter, environment, and package names.' },
|
|
179
|
+
tinker: {
|
|
180
|
+
summary: 'Evaluate an expression and print its result.',
|
|
181
|
+
flags: { '--execute <expression>': 'Evaluate the supplied JavaScript.' },
|
|
182
|
+
exampleArgs: "--execute '1 + 1'",
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
Doctor: {
|
|
186
|
+
bailiff: {
|
|
187
|
+
optionalArgs: '[paths...]',
|
|
188
|
+
summary: 'Lint project files with Bailiff.',
|
|
189
|
+
flags: {
|
|
190
|
+
'--fix': 'Apply available fixes.',
|
|
191
|
+
'--explain <rule>, --explain=<rule>': 'Explain a rule and skip linting.',
|
|
192
|
+
},
|
|
193
|
+
exampleArgs: '--explain no-orphan-query',
|
|
194
|
+
},
|
|
195
|
+
'docs:check': {
|
|
196
|
+
optionalArgs: '[directories...]',
|
|
197
|
+
summary: 'Check package READMEs against the documentation conventions.',
|
|
198
|
+
flags: { '--workspace': 'Check every package under packages/.' },
|
|
199
|
+
exampleArgs: '--workspace',
|
|
200
|
+
},
|
|
201
|
+
doctor: {
|
|
202
|
+
summary: 'Run Bailiff and ward checks; show the environment and driver capabilities.',
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export const TOPICS: readonly CommandTopic[] = Object.entries(groups).flatMap(([group, commands]) =>
|
|
208
|
+
Object.entries(commands).map(([command, details]) => ({
|
|
209
|
+
group,
|
|
210
|
+
label: command.replace(/^(make|migrate|db|ward|route|errand):/, ''),
|
|
211
|
+
command,
|
|
212
|
+
...details,
|
|
213
|
+
})),
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
export const MENU: readonly MenuItem[] = TOPICS.map(({ group, label, command }) => ({
|
|
217
|
+
group,
|
|
218
|
+
label,
|
|
219
|
+
command,
|
|
220
|
+
}))
|
|
51
221
|
|
|
52
|
-
|
|
53
|
-
export const COMMANDS = [...new Set(MENU.map((item) => item.command))]
|
|
222
|
+
export const COMMANDS = MENU.map((item) => item.command)
|
package/src/new-app.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { lstat, mkdir, readdir, readFile, rmdir, unlink, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { basename, dirname, join, resolve } from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import manifest from '../package.json' with { type: 'json' }
|
|
5
|
+
import { writeln, type ReeveIO } from './io'
|
|
6
|
+
|
|
7
|
+
const templateRoot = fileURLToPath(new URL('../templates/app/', import.meta.url))
|
|
8
|
+
|
|
9
|
+
async function readTemplates(relative = ''): Promise<[string, string][]> {
|
|
10
|
+
const files: [string, string][] = []
|
|
11
|
+
for (const entry of await readdir(join(templateRoot, relative), { withFileTypes: true })) {
|
|
12
|
+
const path = join(relative, entry.name)
|
|
13
|
+
if (entry.isDirectory()) files.push(...(await readTemplates(path)))
|
|
14
|
+
else if (entry.isFile() && path.endsWith('.stub')) {
|
|
15
|
+
files.push([path.slice(0, -'.stub'.length), await readFile(join(templateRoot, path), 'utf8')])
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return files
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function shellPath(path: string): string {
|
|
22
|
+
return /^[a-z\d_./-]+$/i.test(path) ? path : `'${path.replaceAll("'", "'\\''")}'`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function createApp(args: readonly string[], io: ReeveIO): Promise<number> {
|
|
26
|
+
const [target] = args
|
|
27
|
+
if (args.length !== 1 || !target?.trim() || target.startsWith('-')) {
|
|
28
|
+
throw new Error('Usage: reeve new <directory>\nExample: reeve new my-app')
|
|
29
|
+
}
|
|
30
|
+
const root = resolve(io.cwd, target)
|
|
31
|
+
const info = await lstat(root).catch((error: NodeJS.ErrnoException) => {
|
|
32
|
+
if (error.code !== 'ENOENT') throw error
|
|
33
|
+
return undefined
|
|
34
|
+
})
|
|
35
|
+
if (info && (!info.isDirectory() || (await readdir(root)).length > 0)) {
|
|
36
|
+
throw new Error(`Choose a new or empty directory: ${root}. No files were written.`)
|
|
37
|
+
}
|
|
38
|
+
const name =
|
|
39
|
+
basename(root)
|
|
40
|
+
.toLowerCase()
|
|
41
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
42
|
+
.slice(0, 214)
|
|
43
|
+
.replace(/^-|-$/g, '') || 'avelon-app'
|
|
44
|
+
const scope = manifest.name.slice(0, manifest.name.indexOf('/'))
|
|
45
|
+
const templates = await readTemplates()
|
|
46
|
+
if (!templates.some(([file]) => file === 'package.json'))
|
|
47
|
+
throw new Error('The installed CLI is missing its app template.')
|
|
48
|
+
|
|
49
|
+
const directories = new Set<string>()
|
|
50
|
+
const files: string[] = []
|
|
51
|
+
async function createDir(path: string): Promise<void> {
|
|
52
|
+
if (path === root || directories.has(path)) return
|
|
53
|
+
await createDir(dirname(path))
|
|
54
|
+
await mkdir(path)
|
|
55
|
+
directories.add(path)
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
if (!info) {
|
|
59
|
+
await mkdir(dirname(root), { recursive: true })
|
|
60
|
+
await mkdir(root)
|
|
61
|
+
directories.add(root)
|
|
62
|
+
}
|
|
63
|
+
for (const [file, template] of templates) {
|
|
64
|
+
const path = join(root, file)
|
|
65
|
+
const source = template
|
|
66
|
+
.replaceAll('__APP_NAME__', name)
|
|
67
|
+
.replaceAll('__AVELON_SCOPE__', scope)
|
|
68
|
+
.replaceAll('__AVELON_VERSION__', manifest.version)
|
|
69
|
+
await createDir(dirname(path))
|
|
70
|
+
await writeFile(path, source, { flag: 'wx' })
|
|
71
|
+
files.push(path)
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
for (const path of files.reverse()) await unlink(path).catch(() => {})
|
|
75
|
+
for (const path of [...directories].reverse()) await rmdir(path).catch(() => {})
|
|
76
|
+
throw error
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
writeln(io, `Created ${name} in ${root}\n`)
|
|
80
|
+
if (root !== resolve(io.cwd)) writeln(io, ` cd ${shellPath(target)}`)
|
|
81
|
+
writeln(io, ' bun install')
|
|
82
|
+
writeln(io, ' bun run dev\n')
|
|
83
|
+
writeln(io, 'Open http://localhost:3000. Run bun run check to test your app.')
|
|
84
|
+
return 0
|
|
85
|
+
}
|