changed watch callback

This commit is contained in:
2022-06-08 16:55:16 -05:00
parent 74904d1c0f
commit 78e9531e83
6 changed files with 33 additions and 22 deletions

View File

@@ -31,14 +31,13 @@ export default async function (
watch: !watchCallback
? false
: {
onRebuild(err, result) {
onRebuild(err, _result) {
let error = null
if (err) {
console.error(name, err)
let error = (err as BuildFailure).message
watchCallback(metaJson, error)
} else {
console.log('watch build succeeded:', result)
error = (err as BuildFailure).message
}
watchCallback(metaJson, error)
},
},

View File

@@ -6,7 +6,7 @@ import {
writeFileSync,
} from 'fs'
import commandLineArgs from 'command-line-args'
import { DistBase, ScriptBase, ScriptPath } from './paths'
import { DistBase, DistPath, ScriptBase, ScriptPath } from './paths'
import { readmeData, updateReadmeFile } from './readmefile'
import runBuild from './build'
import { UserScriptMetaFull } from './types'
@@ -48,19 +48,22 @@ readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`))
error: string | null
) {
scriptMeta[id] = { meta, error }
doErrorFile(path.error, error)
doErrorFile(path.error, DistPath(name), error)
console.log('WATCH', name, meta.version)
updateReadmeFile(scriptMeta)
}
let [meta, error] = await runBuild(name, postWatchUpdate)
let [meta, error] = await runBuild(
name,
CLIArgs.watch ? postWatchUpdate : false
)
scriptMeta[id] = { meta, error }
console.log(name, meta.version)
doErrorFile(path.error, error)
doErrorFile(path.error, DistPath(name), error)
}
}
@@ -70,9 +73,17 @@ readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`))
if (CLIArgs.watch) console.log('Listening for Changes\n')
})()
function doErrorFile(pathError: string, error: string | null) {
function doErrorFile(
pathError: string,
pathOutFile: string,
error: string | null
) {
if (error !== null) {
writeFileSync(pathError, `${new Date().toISOString()}\n\n${error}`)
if (existsSync(pathOutFile)) {
unlinkSync(pathOutFile)
}
} else if (existsSync(pathError)) {
unlinkSync(pathError)
}