restructured build.ts and added a helpcommand
This commit is contained in:
73
lib/main.js
73
lib/main.js
@@ -1,19 +1,76 @@
|
||||
"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.CLIArgs = void 0;
|
||||
const fs_1 = require("fs");
|
||||
const command_line_args_1 = __importDefault(require("command-line-args"));
|
||||
const prettier_1 = require("prettier");
|
||||
const paths_1 = require("./paths");
|
||||
const readmefile_1 = require("./readmefile");
|
||||
const build_1 = __importDefault(require("./build"));
|
||||
const CLIArgs = (0, command_line_args_1.default)([
|
||||
const Path = __importStar(require("path"));
|
||||
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: 's', type: Boolean, defaultValue: false },
|
||||
{ name: 'help', alias: 'h', type: Boolean, defaultValue: false },
|
||||
]);
|
||||
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');
|
||||
@@ -21,14 +78,6 @@ if (!(0, fs_1.existsSync)('package.json') || !(0, fs_1.lstatSync)('package.json'
|
||||
}
|
||||
//delete compiled scripts
|
||||
(0, fs_1.readdirSync)(paths_1.DistBase).forEach(file => (0, fs_1.unlinkSync)(`${paths_1.DistBase}/${file}`));
|
||||
//read prettierrc file and make sure `babel` is the configured parser
|
||||
const PrettierConfig = (() => {
|
||||
let config = prettier_1.resolveConfig.sync(process.cwd()) || {};
|
||||
return {
|
||||
...config,
|
||||
parser: 'babel',
|
||||
};
|
||||
})();
|
||||
//compile scripts
|
||||
let scripts = (0, fs_1.readdirSync)(paths_1.ScriptBase);
|
||||
let scriptMeta = [];
|
||||
@@ -45,11 +94,11 @@ for (let name of scripts) {
|
||||
console.log('WATCH', name, meta.version);
|
||||
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
||||
}
|
||||
let [meta, error] = (0, build_1.default)(name, postWatchUpdate, PrettierConfig, CLIArgs);
|
||||
let [meta, error] = (0, build_1.default)(name, postWatchUpdate);
|
||||
scriptMeta[id] = { meta, error };
|
||||
console.log(name, meta.version);
|
||||
}
|
||||
}
|
||||
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
||||
console.log(`\nFinished Compiling\n${CLIArgs.watch ? 'Listening for Changes\n' : ''}`);
|
||||
console.log(`\nFinished Compiling\n${exports.CLIArgs.watch ? 'Listening for Changes\n' : ''}`);
|
||||
//# sourceMappingURL=main.js.map
|
||||
Reference in New Issue
Block a user