This commit is contained in:
Orion Kindel
2024-12-01 17:11:10 -06:00
parent e2018dbbef
commit 3c4f732f2c
24 changed files with 820 additions and 121 deletions

20
scripts/common.js Normal file
View 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
View 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