"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const esbuild_1 = require("esbuild"); const fs_1 = require("fs"); const paths_1 = require("./paths"); const readmeta_1 = __importDefault(require("./readmeta")); async function compileProject(name) { //read meta file let [metaJson, metaString] = readmeta_1.default(name); let outPath = paths_1.DistPath(name); await esbuild_1.build({ entryPoints: [paths_1.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 = fs_1.readFileSync(outPath).toString(); fs_1.writeFileSync(outPath, metaString + content); } if (!fs_1.lstatSync('package.json').isFile()) { console.error('package.json not found, unwilling to run'); process.exit(1); } //delete compiled scripts fs_1.readdirSync(paths_1.DistBase).forEach(file => fs_1.unlinkSync(`${paths_1.DistBase}/${file}`)); //compile scripts fs_1.readdirSync(paths_1.ScriptBase).forEach(name => { let path = paths_1.ScriptPath(name); if (!name.endsWith('_') && fs_1.lstatSync(path.dir).isDirectory() && fs_1.lstatSync(path.main).isFile()) { compileProject(name); } }); //# sourceMappingURL=main.js.map