63 lines
2.2 KiB
JavaScript
63 lines
2.2 KiB
JavaScript
"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 default_1(name, watchCallback = false) {
|
|
//read meta file
|
|
let [metaJson, metaString] = (0, readmeta_1.default)(name);
|
|
let outPath = (0, paths_1.DistPath)(name);
|
|
let error = null;
|
|
try {
|
|
await (0, esbuild_1.build)({
|
|
entryPoints: [(0, paths_1.ScriptPath)(name).main],
|
|
outfile: outPath,
|
|
target: 'esnext',
|
|
platform: 'node',
|
|
format: 'esm',
|
|
bundle: true,
|
|
minify: false,
|
|
watch: !watchCallback
|
|
? false
|
|
: {
|
|
onRebuild(err, _result) {
|
|
let error = null;
|
|
if (err) {
|
|
console.error(name, err);
|
|
error = err.message;
|
|
}
|
|
watchCallback(metaJson, error);
|
|
},
|
|
},
|
|
define: {
|
|
UserScriptName: `'${metaJson.name}'`,
|
|
UserScriptNamespace: `'${metaJson.namespace}'`,
|
|
UserScriptVersion: `'${metaJson.version}'`,
|
|
UserScriptDownloadURL: `'${metaJson.downloadURL}'`,
|
|
UserScriptSupportURL: `'${metaJson.supportURL}'`,
|
|
UserScriptHomepageURL: `'${metaJson.homepageURL}'`,
|
|
},
|
|
});
|
|
}
|
|
catch (err) {
|
|
console.error(name, err);
|
|
error = err.message;
|
|
}
|
|
//add UserScript header
|
|
if ((0, fs_1.existsSync)(outPath)) {
|
|
if (!error) {
|
|
let content = (0, fs_1.readFileSync)(outPath).toString();
|
|
(0, fs_1.writeFileSync)(outPath, metaString + content);
|
|
}
|
|
else {
|
|
(0, fs_1.unlinkSync)(outPath);
|
|
}
|
|
}
|
|
return [metaJson, error];
|
|
}
|
|
exports.default = default_1;
|
|
//# sourceMappingURL=build.js.map
|