76 lines
2.6 KiB
JavaScript
76 lines
2.6 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 readmefile_1 = require("./readmefile");
|
|
const readmeta_1 = __importDefault(require("./readmeta"));
|
|
async function compileProject(name) {
|
|
//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,
|
|
define: {
|
|
UserScriptName: `'${metaJson.name}'`,
|
|
UserScriptNamespace: `'${metaJson.namespace}'`,
|
|
UserScriptVersion: `'${metaJson.version}'`,
|
|
UserScriptDownloadURL: `'${metaJson.downloadURL}'`,
|
|
UserScriptSupportURL: `'${metaJson.supportURL}'`,
|
|
UserScriptHomepageURL: `'${metaJson.homepageURL}'`,
|
|
},
|
|
});
|
|
}
|
|
catch (e) {
|
|
error = e.message;
|
|
}
|
|
//add UserScript header
|
|
if ((0, fs_1.lstatSync)(outPath).isFile()) {
|
|
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];
|
|
}
|
|
if (!(0, fs_1.lstatSync)('package.json').isFile()) {
|
|
console.error('package.json not found, unwilling to run');
|
|
process.exit(1);
|
|
}
|
|
//delete compiled scripts
|
|
(0, fs_1.readdirSync)(paths_1.DistBase).forEach(file => (0, fs_1.unlinkSync)(`${paths_1.DistBase}/${file}`));
|
|
(async () => {
|
|
let scripts = (0, fs_1.readdirSync)(paths_1.ScriptBase);
|
|
// let scriptMeta: {
|
|
// [name: string]: [UserScriptMetaFull, string | null]
|
|
// } = {}
|
|
let scriptMeta = [];
|
|
for (let name of scripts) {
|
|
let path = (0, paths_1.ScriptPath)(name);
|
|
if (!name.endsWith('_') &&
|
|
(0, fs_1.lstatSync)(path.dir).isDirectory() &&
|
|
(0, fs_1.lstatSync)(path.main).isFile()) {
|
|
let [meta, error] = await compileProject(name);
|
|
scriptMeta.push({
|
|
meta,
|
|
error,
|
|
});
|
|
}
|
|
}
|
|
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
|
})();
|
|
//# sourceMappingURL=main.js.map
|