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
|
||||
|
||||
66
src/main.ts
66
src/main.ts
@@ -21,46 +21,42 @@ if (!existsSync('package.json') || !lstatSync('package.json').isFile()) {
|
||||
readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`))
|
||||
|
||||
//compile scripts
|
||||
;(async () => {
|
||||
let scripts = readdirSync(ScriptBase)
|
||||
let scriptMeta: readmeData[] = []
|
||||
let scripts = readdirSync(ScriptBase)
|
||||
let scriptMeta: readmeData[] = []
|
||||
|
||||
for (let name of scripts) {
|
||||
let path = ScriptPath(name)
|
||||
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()
|
||||
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
|
||||
) {
|
||||
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] = await runBuild(
|
||||
name,
|
||||
CLIArgs.watch ? postWatchUpdate : false
|
||||
)
|
||||
scriptMeta[id] = { meta, error }
|
||||
|
||||
console.log(name, meta.version)
|
||||
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)
|
||||
updateReadmeFile(scriptMeta)
|
||||
|
||||
console.log(
|
||||
`\nFinished Compiling\n${
|
||||
CLIArgs.watch ? 'Listening for Changes\n' : ''
|
||||
}`
|
||||
)
|
||||
})()
|
||||
console.log(
|
||||
`\nFinished Compiling\n${CLIArgs.watch ? 'Listening for Changes\n' : ''}`
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user