it compiled

This commit is contained in:
2022-06-08 09:07:09 -05:00
parent 1884c2b8e9
commit ffe6969889
12 changed files with 996 additions and 1130 deletions

View File

@@ -6,45 +6,64 @@ 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] = 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}'`,
},
});
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
let content = fs_1.readFileSync(outPath).toString();
fs_1.writeFileSync(outPath, metaString + content);
let content = (0, fs_1.readFileSync)(outPath).toString();
(0, fs_1.writeFileSync)(outPath, metaString + content);
return [metaJson, error];
}
if (!fs_1.lstatSync('package.json').isFile()) {
if (!(0, 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);
(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