fmt
This commit is contained in:
20
scripts/common.js
Normal file
20
scripts/common.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import Fs from 'fs/promises'
|
||||
import Path from 'path'
|
||||
|
||||
export const rootDir = Path.resolve(__dirname, '..')
|
||||
|
||||
export const packageDirs = async () => ['./src']
|
||||
|
||||
export const packageSources = async () => {
|
||||
const packages = await packageDirs()
|
||||
const sources = []
|
||||
for (const p of packages) {
|
||||
const files = await Fs.readdir(p, { recursive: true, withFileTypes: true })
|
||||
sources.push(
|
||||
...files.flatMap(e =>
|
||||
e.isFile() ? [Path.resolve(rootDir, e.path, e.name)] : [],
|
||||
),
|
||||
)
|
||||
}
|
||||
return sources
|
||||
}
|
||||
38
scripts/fmt.js
Normal file
38
scripts/fmt.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import { $ } from 'bun'
|
||||
import { packageSources } from './common.js'
|
||||
|
||||
const check = process.argv.includes('--check')
|
||||
|
||||
const sources = await packageSources()
|
||||
const purs = sources.filter(f => f.endsWith('.purs'))
|
||||
const js = sources
|
||||
.filter(f => f.endsWith('.js'))
|
||||
.concat(['./scripts/**/*.js', '.prettierrc.cjs'])
|
||||
const json = ['package.json', 'jsconfig.json']
|
||||
const yml = sources.filter(f => f.endsWith('.yaml')).concat(['spago.yaml'])
|
||||
|
||||
/** @type {(parser: string, ps: string[]) => import("bun").ShellPromise} */
|
||||
const prettier = (parser, ps) =>
|
||||
$`bun x prettier ${check ? '--check' : '--write'} '--parser' ${parser} ${ps}`
|
||||
|
||||
const procs = [
|
||||
() => prettier('babel', js),
|
||||
() => prettier('json', json),
|
||||
() => prettier('yaml', yml),
|
||||
() =>
|
||||
prettier(
|
||||
'markdown',
|
||||
sources.filter(f => f.endsWith('.md')).concat(['README.md']),
|
||||
),
|
||||
() => $`bun x purs-tidy ${check ? 'check' : 'format-in-place'} ${purs}`,
|
||||
]
|
||||
.map(go => async () => {
|
||||
const p = await go().nothrow().quiet()
|
||||
if (p.exitCode === 0) return
|
||||
process.stdout.write(p.stdout)
|
||||
process.stderr.write(p.stderr)
|
||||
process.exit(1)
|
||||
})
|
||||
.reduce((acc, go) => acc.then(() => go()), Promise.resolve())
|
||||
|
||||
await procs
|
||||
Reference in New Issue
Block a user