This commit is contained in:
2022-06-09 10:43:08 -05:00
parent 6d4f4c57bc
commit 6e881ebd6f
6 changed files with 65 additions and 69 deletions

View File

@@ -1,21 +1,21 @@
import { build, BuildFailure, BuildOptions } from 'esbuild'
import { buildSync, BuildFailure, BuildOptions } from 'esbuild'
import { existsSync, writeFileSync, unlinkSync } from 'fs'
import { DistPath, ScriptPath } from './paths'
import { UserScriptMetaFull } from './types'
import readMeta from './readmeta'
export default async function (
export default function (
name: string,
watchCallback:
| ((meta: UserScriptMetaFull, error: string | null) => void)
| false = false
): Promise<[UserScriptMetaFull, string | null]> {
): [UserScriptMetaFull, string | null] {
//read meta file
let [metaJson, metaString] = readMeta(name)
let path = ScriptPath(name)
let pathDist = DistPath(name)
let result = await runEsbuild(
let result = runEsbuild(
{
entryPoints: [ScriptPath(name).main],
outfile: pathDist,
@@ -96,11 +96,11 @@ interface RunEsbuildResult {
errorRaw?: BuildFailure
}
async function runEsbuild(
function runEsbuild(
opts: BuildOptions,
watchCallback: (result: RunEsbuildResult) => void,
toWatch: boolean = false
): Promise<RunEsbuildResult> {
): RunEsbuildResult {
opts.write = false
if (toWatch) {
opts.watch = {
@@ -135,8 +135,9 @@ async function runEsbuild(
},
}
}
try {
let res = await build(opts)
let res = buildSync(opts)
let content = ''
if (res.outputFiles && res.outputFiles.length > 0) {
content = res.outputFiles[0].text