updated dependencies

This commit is contained in:
zomo
2024-06-19 09:47:25 -05:00
parent ec24ba6c3e
commit 9c4fe7d3ea
10 changed files with 454 additions and 469 deletions

View File

@@ -1,9 +1,9 @@
import { BuildFailure, BuildOptions, BuildResult, build } from 'esbuild'
import { existsSync, writeFileSync, unlinkSync } from 'fs'
import { UserScriptMetaFull } from './types'
import readMeta from './readmeta'
import { format, resolveConfig } from 'prettier'
import { AllPaths, CLIArgs } from './main'
import { writeFile, stat, unlink } from 'fs/promises'
export interface runBuildResult {
meta: UserScriptMetaFull
@@ -37,7 +37,7 @@ export default async function runBuild(name: string) {
},
})
let error = postBuild(name, result, metaString)
let error = await postBuild(name, result, metaString)
return {
meta,
@@ -98,11 +98,15 @@ function clearFilenameComments(content: string): string {
return content.replace(regexp, '')
}
function postBuild(name: string, result: RunEsbuildResult, metaString: string) {
async function postBuild(
name: string,
result: RunEsbuildResult,
metaString: string
) {
let error: string | null = null
let paths = AllPaths.script(name)
let PrettierConfig = resolveConfig.sync(paths.dir) || {}
let PrettierConfig = (await resolveConfig(paths.dir)) ?? {}
if (result.error) {
console.error(name, result.errorRaw || result.error)
@@ -110,32 +114,40 @@ function postBuild(name: string, result: RunEsbuildResult, metaString: string) {
} else if (result.content) {
let content = metaString + result.content
if (CLIArgs.prettier) {
content = format(content, {
content = await format(content, {
...PrettierConfig,
parser: 'babel',
})
}
writeFileSync(paths.dist, content)
await writeFile(paths.dist, content)
} else {
console.error(name, 'No output')
}
doErrorFile(name, error)
await doErrorFile(name, error)
return error
}
function doErrorFile(name: string, error: string | null) {
async function doErrorFile(name: string, error: string | null) {
let paths = AllPaths.script(name)
let content = `${new Date().toISOString()}\n\n${error}`
if (error !== null) {
writeFileSync(paths.error, content)
if (existsSync(paths.dist)) {
unlinkSync(paths.dist)
await writeFile(paths.error, content)
if (await existsFile(paths.dist)) {
await unlink(paths.dist)
}
} else if (existsSync(paths.error)) {
unlinkSync(paths.error)
} else if (await existsFile(paths.error)) {
await unlink(paths.error)
}
}
function existsFile(path: string): Promise<boolean> {
return new Promise(resolve => {
stat(path)
.then(() => resolve(true))
.catch(() => resolve(false))
})
}