60 lines
2.5 KiB
JavaScript
60 lines
2.5 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 fs_1 = require("fs");
|
|
const command_line_args_1 = __importDefault(require("command-line-args"));
|
|
const paths_1 = require("./paths");
|
|
const readmefile_1 = require("./readmefile");
|
|
const build_1 = __importDefault(require("./build"));
|
|
const CLIArgs = (0, command_line_args_1.default)([
|
|
{ name: 'watch', alias: 'w', type: Boolean },
|
|
]);
|
|
//if package.json doesn't exist then there is no point in continuing
|
|
if (!(0, fs_1.existsSync)('package.json') || !(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 = [];
|
|
for (let name of scripts) {
|
|
let path = (0, paths_1.ScriptPath)(name);
|
|
if (!name.endsWith('_') &&
|
|
(0, fs_1.existsSync)(path.dir) &&
|
|
(0, fs_1.lstatSync)(path.dir).isDirectory() &&
|
|
(0, fs_1.existsSync)(path.main) &&
|
|
(0, fs_1.lstatSync)(path.main).isFile()) {
|
|
let id = scriptMeta.length;
|
|
function postWatchUpdate(meta, error) {
|
|
scriptMeta[id] = { meta, error };
|
|
doErrorFile(path.error, (0, paths_1.DistPath)(name), error);
|
|
console.log('WATCH', name, meta.version);
|
|
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
|
}
|
|
let [meta, error] = await (0, build_1.default)(name, CLIArgs.watch ? postWatchUpdate : false);
|
|
scriptMeta[id] = { meta, error };
|
|
console.log(name, meta.version);
|
|
doErrorFile(path.error, (0, paths_1.DistPath)(name), error);
|
|
}
|
|
}
|
|
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
|
console.log('\nFinished Compiling\n');
|
|
if (CLIArgs.watch)
|
|
console.log('Listening for Changes\n');
|
|
})();
|
|
function doErrorFile(pathError, pathOutFile, error) {
|
|
if (error !== null) {
|
|
(0, fs_1.writeFileSync)(pathError, `${new Date().toISOString()}\n\n${error}`);
|
|
if ((0, fs_1.existsSync)(pathOutFile)) {
|
|
(0, fs_1.unlinkSync)(pathOutFile);
|
|
}
|
|
}
|
|
else if ((0, fs_1.existsSync)(pathError)) {
|
|
(0, fs_1.unlinkSync)(pathError);
|
|
}
|
|
}
|
|
//# sourceMappingURL=main.js.map
|