@avelonjs/cli 0.8.3 → 0.8.5
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 +6 -0
- package/package.json +1 -1
- package/src/commands.ts +18 -9
- package/src/docs-check.ts +42 -5
- package/src/generate.ts +7 -3
package/README.md
CHANGED
|
@@ -57,6 +57,9 @@ reeve stub:publish
|
|
|
57
57
|
|
|
58
58
|
`stub:publish` ejects templates into `stubs/` so you change generated shape without forking the framework.
|
|
59
59
|
|
|
60
|
+
Generators refuse to overwrite an existing application file. View names are relative paths inside
|
|
61
|
+
`resources/views`, such as `posts/Index`.
|
|
62
|
+
|
|
60
63
|
`reeve make:driver storage r2` scaffolds a package with every capability `false`, methods that throw
|
|
61
64
|
`unimplemented`, a wired conformance suite, and a README that already passes `docs:check`. The
|
|
62
65
|
certification path is `docs/15-driver-authoring.md`.
|
|
@@ -84,6 +87,8 @@ reeve errand:flush
|
|
|
84
87
|
|
|
85
88
|
`migrate:fresh` names what it will destroy and requires typing the environment name when it is not `local`.
|
|
86
89
|
|
|
90
|
+
`db:seed` and route commands exit with an error when a seed or route module fails to load or run.
|
|
91
|
+
|
|
87
92
|
## Doctor and inspect
|
|
88
93
|
|
|
89
94
|
```
|
|
@@ -108,6 +113,7 @@ Waive a section or export with an HTML comment in the README:
|
|
|
108
113
|
|
|
109
114
|
```html
|
|
110
115
|
<!-- docs:check-waiver: section Features -->
|
|
116
|
+
<!-- docs:check-waiver: section Introduction -->
|
|
111
117
|
<!-- docs:check-waiver: export internalHelper -->
|
|
112
118
|
```
|
|
113
119
|
|
package/package.json
CHANGED
package/src/commands.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readdir, writeFile, mkdir } from 'node:fs/promises'
|
|
1
|
+
import { readdir, writeFile, mkdir, stat } from 'node:fs/promises'
|
|
2
2
|
import { join } from 'node:path'
|
|
3
3
|
import { pathToFileURL } from 'node:url'
|
|
4
4
|
import { runSeeds } from '@avelonjs/assay'
|
|
@@ -57,17 +57,23 @@ async function listDir(io: ReeveIO, relative: string): Promise<string[]> {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
async function
|
|
61
|
-
const file = join(io.cwd, 'routes/web.ts')
|
|
60
|
+
async function pathExists(file: string): Promise<boolean> {
|
|
62
61
|
try {
|
|
63
|
-
await
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
await stat(file)
|
|
63
|
+
return true
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return false
|
|
66
|
+
throw error
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
|
|
70
|
+
async function loadRoutes(io: ReeveIO): Promise<void> {
|
|
71
|
+
const file = join(io.cwd, 'routes/web.ts')
|
|
72
|
+
if (!(await pathExists(file))) return
|
|
73
|
+
Route.reset()
|
|
74
|
+
await import(`${pathToFileURL(file).href}?t=${Date.now()}`)
|
|
75
|
+
}
|
|
76
|
+
|
|
71
77
|
function requireName(argv: readonly string[], usage: string): string {
|
|
72
78
|
const name = operand(argv)
|
|
73
79
|
if (name === undefined) throw new Error(usage)
|
|
@@ -148,6 +154,9 @@ export async function runCommand(
|
|
|
148
154
|
}
|
|
149
155
|
case 'make:view': {
|
|
150
156
|
const name = requireName(argv, 'Usage: reeve make:view posts/Index')
|
|
157
|
+
if (name.includes('\\') || name.split('/').some((part) => ['', '.', '..'].includes(part))) {
|
|
158
|
+
throw new Error('View names must be relative paths inside resources/views.')
|
|
159
|
+
}
|
|
151
160
|
const pascal = name
|
|
152
161
|
.split('/')
|
|
153
162
|
.map((part) => studly(part))
|
|
@@ -198,7 +207,7 @@ export async function runCommand(
|
|
|
198
207
|
return runMigrate(command, argv, io)
|
|
199
208
|
case 'db:seed': {
|
|
200
209
|
const dir = join(io.cwd, 'database/seeds')
|
|
201
|
-
const ran = await
|
|
210
|
+
const ran = (await pathExists(dir)) ? await runSeeds(dir) : []
|
|
202
211
|
writeln(io, ran.length === 0 ? 'No seeds.' : `Seeded ${ran.length} file(s).`)
|
|
203
212
|
return 0
|
|
204
213
|
}
|
package/src/docs-check.ts
CHANGED
|
@@ -73,7 +73,7 @@ export async function checkPackageDocs(root: string): Promise<DocsCheckResult> {
|
|
|
73
73
|
})
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
if (!hasIntroduction(readme)) {
|
|
76
|
+
if (!hasIntroduction(readme) && !waivers.sections.has('introduction')) {
|
|
77
77
|
findings.push({
|
|
78
78
|
kind: 'missing-section',
|
|
79
79
|
message:
|
|
@@ -177,7 +177,24 @@ function parseWaivers(readme: string): WaiverSet {
|
|
|
177
177
|
|
|
178
178
|
function markdownHeadings(readme: string): Set<string> {
|
|
179
179
|
const headings = new Set<string>()
|
|
180
|
+
let fence: string | undefined
|
|
180
181
|
for (const line of readme.split(/\r?\n/)) {
|
|
182
|
+
const marker = /^ {0,3}(`{3,}|~{3,})/.exec(line)?.[1]
|
|
183
|
+
if (fence !== undefined) {
|
|
184
|
+
if (
|
|
185
|
+
marker !== undefined &&
|
|
186
|
+
marker[0] === fence[0] &&
|
|
187
|
+
marker.length >= fence.length &&
|
|
188
|
+
line.trim() === marker
|
|
189
|
+
) {
|
|
190
|
+
fence = undefined
|
|
191
|
+
}
|
|
192
|
+
continue
|
|
193
|
+
}
|
|
194
|
+
if (marker !== undefined) {
|
|
195
|
+
fence = marker
|
|
196
|
+
continue
|
|
197
|
+
}
|
|
181
198
|
const match = /^##\s+(.+?)\s*$/.exec(line)
|
|
182
199
|
const title = match?.[1]?.trim()
|
|
183
200
|
if (title !== undefined) headings.add(title)
|
|
@@ -327,6 +344,7 @@ async function collectFromFile(
|
|
|
327
344
|
root: string,
|
|
328
345
|
names: Set<string>,
|
|
329
346
|
seen: Set<string>,
|
|
347
|
+
includeDefault = true,
|
|
330
348
|
): Promise<void> {
|
|
331
349
|
if (seen.has(file)) return
|
|
332
350
|
seen.add(file)
|
|
@@ -346,7 +364,7 @@ async function collectFromFile(
|
|
|
346
364
|
? resolveRelative(file, root, moduleSpecifier.text)
|
|
347
365
|
: undefined
|
|
348
366
|
if (statement.exportClause === undefined) {
|
|
349
|
-
if (resolved !== undefined) await collectFromFile(resolved, root, names, seen)
|
|
367
|
+
if (resolved !== undefined) await collectFromFile(resolved, root, names, seen, false)
|
|
350
368
|
continue
|
|
351
369
|
}
|
|
352
370
|
if (ts.isNamespaceExport(statement.exportClause)) {
|
|
@@ -354,18 +372,22 @@ async function collectFromFile(
|
|
|
354
372
|
continue
|
|
355
373
|
}
|
|
356
374
|
for (const element of statement.exportClause.elements) {
|
|
357
|
-
names.add(element.name.text)
|
|
375
|
+
if (includeDefault || element.name.text !== 'default') names.add(element.name.text)
|
|
358
376
|
}
|
|
359
377
|
continue
|
|
360
378
|
}
|
|
361
379
|
if (ts.isExportAssignment(statement)) {
|
|
362
|
-
names.add('default')
|
|
380
|
+
if (includeDefault) names.add('default')
|
|
363
381
|
continue
|
|
364
382
|
}
|
|
365
383
|
const mods = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) : undefined
|
|
366
384
|
const exported =
|
|
367
385
|
mods?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) === true
|
|
368
386
|
if (!exported) continue
|
|
387
|
+
if (mods?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword)) {
|
|
388
|
+
if (includeDefault) names.add('default')
|
|
389
|
+
continue
|
|
390
|
+
}
|
|
369
391
|
if (ts.isFunctionDeclaration(statement) && statement.name !== undefined) {
|
|
370
392
|
names.add(statement.name.text)
|
|
371
393
|
continue
|
|
@@ -384,16 +406,31 @@ async function collectFromFile(
|
|
|
384
406
|
}
|
|
385
407
|
if (ts.isVariableStatement(statement)) {
|
|
386
408
|
for (const declaration of statement.declarationList.declarations) {
|
|
387
|
-
|
|
409
|
+
collectBindingNames(declaration.name, names)
|
|
388
410
|
}
|
|
389
411
|
}
|
|
390
412
|
}
|
|
391
413
|
}
|
|
392
414
|
|
|
415
|
+
function collectBindingNames(binding: ts.BindingName, names: Set<string>): void {
|
|
416
|
+
if (ts.isIdentifier(binding)) {
|
|
417
|
+
names.add(binding.text)
|
|
418
|
+
return
|
|
419
|
+
}
|
|
420
|
+
for (const element of binding.elements) {
|
|
421
|
+
if (ts.isBindingElement(element)) collectBindingNames(element.name, names)
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
393
425
|
function resolveRelative(fromFile: string, root: string, specifier: string): string | undefined {
|
|
394
426
|
if (!specifier.startsWith('.')) return undefined
|
|
395
427
|
const base = join(dirname(fromFile), specifier)
|
|
428
|
+
const sourceBase = base.replace(/\.[cm]?jsx?$/, '')
|
|
429
|
+
const extension = extname(base)
|
|
430
|
+
const sourceExtensions =
|
|
431
|
+
extension === '.mjs' ? ['.mts'] : extension === '.cjs' ? ['.cts'] : ['.ts', '.tsx']
|
|
396
432
|
const candidates = [
|
|
433
|
+
...(sourceBase === base ? [] : sourceExtensions.map((suffix) => `${sourceBase}${suffix}`)),
|
|
397
434
|
base,
|
|
398
435
|
`${base}.ts`,
|
|
399
436
|
`${base}.tsx`,
|
package/src/generate.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
2
|
-
import { dirname, join } from 'node:path'
|
|
2
|
+
import { dirname, isAbsolute, join, relative as relativePath, resolve, sep } from 'node:path'
|
|
3
3
|
|
|
4
4
|
import { snake, studly, type ReeveIO, writeln } from './io'
|
|
5
5
|
|
|
@@ -242,9 +242,13 @@ export async function writeFromStub(
|
|
|
242
242
|
extra: Record<string, string> = {},
|
|
243
243
|
): Promise<string> {
|
|
244
244
|
const template = await loadTemplate(io, stub)
|
|
245
|
-
const file =
|
|
245
|
+
const file = resolve(io.cwd, relative)
|
|
246
|
+
const withinRoot = relativePath(resolve(io.cwd), file)
|
|
247
|
+
if (withinRoot === '..' || withinRoot.startsWith(`..${sep}`) || isAbsolute(withinRoot)) {
|
|
248
|
+
throw new Error('Generated files must stay inside the project directory.')
|
|
249
|
+
}
|
|
246
250
|
await mkdir(dirname(file), { recursive: true })
|
|
247
|
-
await writeFile(file, apply(template, tokens(name, extra)))
|
|
251
|
+
await writeFile(file, apply(template, tokens(name, extra)), { flag: 'wx' })
|
|
248
252
|
writeln(io, relative)
|
|
249
253
|
return file
|
|
250
254
|
}
|