63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import { existsSync, lstatSync, readdirSync, unlinkSync } from 'fs'
|
|
import commandLineArgs from 'command-line-args'
|
|
import { DistBase, ScriptBase, ScriptPath } from './paths'
|
|
import { readmeData, updateReadmeFile } from './readmefile'
|
|
import runBuild from './build'
|
|
import { UserScriptMetaFull } from './types'
|
|
|
|
const CLIArgs = commandLineArgs([
|
|
{ name: 'watch', alias: 'w', type: Boolean },
|
|
]) as {
|
|
watch: boolean
|
|
}
|
|
|
|
//if package.json doesn't exist then there is no point in continuing
|
|
if (!existsSync('package.json') || !lstatSync('package.json').isFile()) {
|
|
console.error('package.json not found, unwilling to run')
|
|
process.exit(1)
|
|
}
|
|
|
|
//delete compiled scripts
|
|
readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`))
|
|
|
|
//compile scripts
|
|
let scripts = readdirSync(ScriptBase)
|
|
let scriptMeta: readmeData[] = []
|
|
|
|
for (let name of scripts) {
|
|
let path = ScriptPath(name)
|
|
|
|
if (
|
|
!name.endsWith('_') &&
|
|
existsSync(path.dir) &&
|
|
lstatSync(path.dir).isDirectory() &&
|
|
existsSync(path.main) &&
|
|
lstatSync(path.main).isFile()
|
|
) {
|
|
let id = scriptMeta.length
|
|
|
|
function postWatchUpdate(
|
|
meta: UserScriptMetaFull,
|
|
error: string | null
|
|
) {
|
|
scriptMeta[id] = { meta, error }
|
|
console.log('WATCH', name, meta.version)
|
|
updateReadmeFile(scriptMeta)
|
|
}
|
|
|
|
let [meta, error] = runBuild(
|
|
name,
|
|
CLIArgs.watch ? postWatchUpdate : false
|
|
)
|
|
scriptMeta[id] = { meta, error }
|
|
|
|
console.log(name, meta.version)
|
|
}
|
|
}
|
|
|
|
updateReadmeFile(scriptMeta)
|
|
|
|
console.log(
|
|
`\nFinished Compiling\n${CLIArgs.watch ? 'Listening for Changes\n' : ''}`
|
|
)
|