114 lines
4.5 KiB
JavaScript
114 lines
4.5 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.AllPaths = exports.CLIArgs = void 0;
|
|
const fs_1 = require("fs");
|
|
const command_line_args_1 = __importDefault(require("command-line-args"));
|
|
const readmefile_1 = require("./readmefile");
|
|
const build_1 = __importDefault(require("./build"));
|
|
const Path = __importStar(require("path"));
|
|
const paths_1 = __importDefault(require("./paths"));
|
|
exports.CLIArgs = (0, command_line_args_1.default)([
|
|
{ name: 'watch', alias: 'w', type: Boolean, defaultValue: false },
|
|
{ name: 'minify', alias: 'm', type: Boolean, defaultValue: false },
|
|
{ name: 'prettier', alias: 'p', type: Boolean, defaultValue: false },
|
|
{ name: 'srccomment', alias: 'c', type: Boolean, defaultValue: false },
|
|
{ name: 'baseurl', alias: 'u', type: String, defaultValue: '' },
|
|
{ name: 'remotebranch', alias: 'b', type: String, defaultValue: 'main' },
|
|
{ name: 'scriptsdir', alias: 's', type: String, defaultValue: 'scripts' },
|
|
{ name: 'distdir', alias: 'd', type: String, defaultValue: 'dist' },
|
|
{ name: 'help', alias: 'h', type: Boolean },
|
|
]);
|
|
exports.AllPaths = (0, paths_1.default)({
|
|
baseURL: exports.CLIArgs.baseurl || '',
|
|
remoteBranch: exports.CLIArgs.remotebranch || 'main',
|
|
scriptBase: exports.CLIArgs.scriptpath || 'scripts',
|
|
distBase: exports.CLIArgs.distpath || 'dist',
|
|
});
|
|
if (exports.CLIArgs.help) {
|
|
let command = '<command>';
|
|
if (process.argv.length > 0) {
|
|
command = Path.parse(process.argv[0]).name;
|
|
}
|
|
if (command.toLowerCase() === 'node' && process.argv.length > 1) {
|
|
let path = Path.relative(process.cwd(), process.argv[1]) || '.';
|
|
command = `${command} ${path}`;
|
|
}
|
|
console.log(`
|
|
Usage: ${command} [options]
|
|
|
|
options:
|
|
--watch
|
|
alias: -w
|
|
automatically recompile on save
|
|
--minify
|
|
alias: -m
|
|
minify output files
|
|
--prettier
|
|
alias: -p
|
|
prettify output files
|
|
--srccomment
|
|
alias: -s
|
|
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
|
--help
|
|
alias: -h
|
|
show this help message
|
|
`);
|
|
process.exit(0);
|
|
}
|
|
//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)(exports.AllPaths.base.dist).forEach(file => (0, fs_1.unlinkSync)(`${exports.AllPaths.base.dist}/${file}`));
|
|
//compile scripts
|
|
let scripts = (0, fs_1.readdirSync)(exports.AllPaths.base.script);
|
|
let scriptMeta = [];
|
|
for (let name of scripts) {
|
|
let path = exports.AllPaths.script(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 update(result) {
|
|
console.log('WATCH', name, result.meta.version);
|
|
scriptMeta[id] = result;
|
|
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
|
}
|
|
let result = (0, build_1.default)(name, update);
|
|
console.log(name, result.meta.version);
|
|
scriptMeta[id] = result;
|
|
}
|
|
}
|
|
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
|
console.log(`\nFinished Compiling\n${exports.CLIArgs.watch ? 'Listening for Changes\n' : ''}`);
|
|
//# sourceMappingURL=main.js.map
|