@nuasite/cli 0.50.1 → 0.52.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 +36 -1
- package/dist/index.js +2967 -2689
- package/dist/types/check.d.ts +18 -0
- package/dist/types/check.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/check.ts +80 -0
- package/src/index.ts +12 -0
- package/src/tsconfig.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuasite/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"prepack": "bun run ../../scripts/workspace-deps/resolve-deps.ts"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@nuasite/cms": "0.
|
|
26
|
+
"@nuasite/cms": "0.52.0",
|
|
27
|
+
"@nuasite/cms-core": "0.52.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@types/bun": "1.3.11"
|
package/src/check.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { checkContent, type CheckReport, createNodeFs, formatCheckReport } from '@nuasite/cms-core'
|
|
2
|
+
import { existsSync, readdirSync } from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
export interface CheckOptions {
|
|
6
|
+
cwd: string
|
|
7
|
+
json: boolean
|
|
8
|
+
/** Treat warnings as failures too. Off by default: a dangling reference builds fine. */
|
|
9
|
+
strict: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ASTRO_CONFIG_NAMES = ['astro.config.ts', 'astro.config.mts', 'astro.config.mjs', 'astro.config.js']
|
|
13
|
+
|
|
14
|
+
const hasAstroConfig = (dir: string): boolean => ASTRO_CONFIG_NAMES.some(name => existsSync(path.join(dir, name)))
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The Astro apps to check, relative to `cwd`.
|
|
18
|
+
*
|
|
19
|
+
* Running this at a monorepo root has to work: that is where an agent's workspace and a
|
|
20
|
+
* developer's shell both start, and `bun run build` there builds something else entirely
|
|
21
|
+
* (admin, api, worker). Every `packages/*` app is checked, not just the first — a repo with
|
|
22
|
+
* two sites must not have one of them silently skipped.
|
|
23
|
+
*/
|
|
24
|
+
export function astroRoots(cwd: string): string[] {
|
|
25
|
+
if (hasAstroConfig(cwd)) return ['.']
|
|
26
|
+
|
|
27
|
+
const packagesDir = path.join(cwd, 'packages')
|
|
28
|
+
if (!existsSync(packagesDir)) return []
|
|
29
|
+
|
|
30
|
+
return readdirSync(packagesDir, { withFileTypes: true })
|
|
31
|
+
.filter(entry => entry.isDirectory())
|
|
32
|
+
.map(entry => entry.name)
|
|
33
|
+
.sort()
|
|
34
|
+
.filter(name => hasAstroConfig(path.join(packagesDir, name)))
|
|
35
|
+
.map(name => path.join('packages', name))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Re-root a sub-project's findings on the directory the command was run from. */
|
|
39
|
+
function prefixed(report: CheckReport, root: string): CheckReport {
|
|
40
|
+
if (root === '.') return report
|
|
41
|
+
return {
|
|
42
|
+
...report,
|
|
43
|
+
findings: report.findings.map(finding => ({ ...finding, file: path.join(root, finding.file) })),
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Validate the content collections and return the process exit code. */
|
|
48
|
+
export async function check(options: CheckOptions): Promise<number> {
|
|
49
|
+
const roots = astroRoots(options.cwd)
|
|
50
|
+
|
|
51
|
+
if (roots.length === 0) {
|
|
52
|
+
console.error(`No astro.config.* found in ${options.cwd} or its packages/*. Run this in an Astro project.`)
|
|
53
|
+
return 1
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const reports = await Promise.all(
|
|
57
|
+
roots.map(async root => prefixed(await checkContent(createNodeFs(path.join(options.cwd, root))), root)),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
const report: CheckReport = {
|
|
61
|
+
findings: reports.flatMap(one => one.findings),
|
|
62
|
+
collections: reports.reduce((total, one) => total + one.collections, 0),
|
|
63
|
+
entries: reports.reduce((total, one) => total + one.entries, 0),
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const errors = report.findings.filter(finding => finding.severity === 'error').length
|
|
67
|
+
const warnings = report.findings.length - errors
|
|
68
|
+
|
|
69
|
+
if (options.json) {
|
|
70
|
+
console.log(JSON.stringify({ ...report, roots }, null, 2))
|
|
71
|
+
} else {
|
|
72
|
+
const formatted = formatCheckReport(report)
|
|
73
|
+
if (formatted) console.log(formatted + '\n')
|
|
74
|
+
const where = roots.length === 1 && roots[0] === '.' ? '' : ` in ${roots.join(', ')}`
|
|
75
|
+
const counts = `${report.collections} collection(s), ${report.entries} entries${where}`
|
|
76
|
+
console.log(errors === 0 && warnings === 0 ? `${counts} — no problems found` : `${counts} — ${errors} error(s), ${warnings} warning(s)`)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return errors > 0 || (options.strict && warnings > 0) ? 1 : 0
|
|
80
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -25,6 +25,7 @@ function printUsage() {
|
|
|
25
25
|
console.log(' build Run astro build with the Nua defaults')
|
|
26
26
|
console.log(' dev Run astro dev with the Nua defaults')
|
|
27
27
|
console.log(' preview Run astro preview with the Nua defaults')
|
|
28
|
+
console.log(' check Validate the content collections (no build). --json, --strict')
|
|
28
29
|
console.log(' init Convert a standard Astro project to use Nua')
|
|
29
30
|
console.log(' clean Eject to a standard Astro project (remove @nuasite/* deps)')
|
|
30
31
|
console.log(' migrate <target> Run a content migration. Targets: astro-image')
|
|
@@ -36,6 +37,17 @@ if (command && ['build', 'dev', 'preview'].includes(command)) {
|
|
|
36
37
|
proxyToAstroCLI(command, args)
|
|
37
38
|
} else {
|
|
38
39
|
switch (command) {
|
|
40
|
+
case 'check': {
|
|
41
|
+
const { check } = await import('./check')
|
|
42
|
+
process.exit(
|
|
43
|
+
await check({
|
|
44
|
+
cwd: process.cwd(),
|
|
45
|
+
json: args.includes('--json'),
|
|
46
|
+
strict: args.includes('--strict'),
|
|
47
|
+
}),
|
|
48
|
+
)
|
|
49
|
+
break
|
|
50
|
+
}
|
|
39
51
|
case 'init': {
|
|
40
52
|
const { init } = await import('./init')
|
|
41
53
|
await init({
|
package/src/tsconfig.json
CHANGED