import { build } from 'esbuild'; import { lstatSync, readdirSync, readFileSync, unlinkSync, writeFileSync, } from 'fs'; import { DistBase, DistPath, ScriptBase, ScriptPath } from './paths'; import readMeta from './readmeta'; async function compileProject(name) { //read meta file let [metaJson, metaString] = readMeta(name); let outPath = DistPath(name); await build({ entryPoints: [ScriptPath(name).main], outfile: outPath, target: 'esnext', platform: 'node', format: 'esm', bundle: true, minify: false, define: { UserScriptName: `'${metaJson.name}'`, UserScriptNamespace: `'${metaJson.namespace}'`, UserScriptVersion: `'${metaJson.version}'`, UserScriptDownloadURL: `'${metaJson.downloadURL}'`, UserScriptSupportURL: `'${metaJson.supportURL}'`, UserScriptHomepageURL: `'${metaJson.homepageURL}'`, }, }); //add UserScript header let content = readFileSync(outPath).toString(); writeFileSync(outPath, metaString + content); } if (!lstatSync('package.json').isFile()) { console.error('package.json not found, unwilling to run'); process.exit(1); } //delete compiled scripts readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`)); //compile scripts readdirSync(ScriptBase).forEach(name => { let path = ScriptPath(name); if (!name.endsWith('_') && lstatSync(path.dir).isDirectory() && lstatSync(path.main).isFile()) { compileProject(name); } }); //# sourceMappingURL=main.js.map