no async
This commit is contained in:
15
src/build.ts
15
src/build.ts
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user