mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-12-02 17:53:47 +08:00
Add layout registration, visual editing, and source generation. Preserve embedded pages and wait for asynchronous layout renderers. Add workspace lint and formatting commands.
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
import { statSync } from 'node:fs'
|
|
|
|
export async function applyLintFixes(paths, { explicitFiles = false } = {}) {
|
|
const { ESLint } = await import('eslint')
|
|
const eslint = new ESLint({
|
|
fix: true,
|
|
globInputPaths: false,
|
|
errorOnUnmatchedPattern: explicitFiles,
|
|
})
|
|
let lintablePaths = paths
|
|
|
|
if (explicitFiles) {
|
|
lintablePaths = []
|
|
|
|
for (const file of paths) {
|
|
if (!(await eslint.isPathIgnored(file))) lintablePaths.push(file)
|
|
}
|
|
}
|
|
|
|
if (lintablePaths.length === 0) return 0
|
|
|
|
const results = await eslint.lintFiles(lintablePaths)
|
|
const formatter = await eslint.loadFormatter()
|
|
|
|
await ESLint.outputFixes(results)
|
|
process.stdout.write(await formatter.format(results))
|
|
|
|
return Number(
|
|
results.some(({ errorCount, warningCount }) => errorCount || warningCount),
|
|
)
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
const files = process.argv.slice(process.argv[2] === '--' ? 3 : 2)
|
|
const invalidFile = files.find(
|
|
(file) => !statSync(file, { throwIfNoEntry: false })?.isFile(),
|
|
)
|
|
|
|
if (invalidFile !== void 0) {
|
|
console.error(`Expected an existing file path: ${invalidFile}`)
|
|
process.exit(1)
|
|
}
|
|
|
|
process.exitCode = files.length
|
|
? await applyLintFixes(files, { explicitFiles: true })
|
|
: await applyLintFixes(['.'])
|
|
}
|