updated cli args and help screen
This commit is contained in:
68
lib/main.js
68
lib/main.js
@@ -38,17 +38,20 @@ exports.CLIArgs = (0, command_line_args_1.default)([
|
||||
{ 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: 'readme', alias: 'r', type: Boolean, defaultValue: false },
|
||||
{ name: 'url', alias: 'u', type: String, defaultValue: '' },
|
||||
{ name: 'supporturl', alias: 's', type: String, defaultValue: '' },
|
||||
{ name: 'remotebranch', alias: 'b', type: String, defaultValue: '' },
|
||||
{ name: 'in', alias: 'i', type: String, defaultValue: 'scripts' },
|
||||
{ name: 'out', alias: 'o', 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',
|
||||
baseUrl: exports.CLIArgs.url || '',
|
||||
supportUrl: exports.CLIArgs.supporturl || '',
|
||||
remoteBranch: exports.CLIArgs.remotebranch || '',
|
||||
inBase: exports.CLIArgs.in || 'scripts',
|
||||
outBase: exports.CLIArgs.out || 'dist',
|
||||
});
|
||||
if (exports.CLIArgs.help) {
|
||||
let command = '<command>';
|
||||
@@ -65,16 +68,46 @@ Usage: ${command} [options]
|
||||
options:
|
||||
--watch
|
||||
alias: -w
|
||||
default: false
|
||||
automatically recompile on save
|
||||
--minify
|
||||
alias: -m
|
||||
default: false
|
||||
minify output files
|
||||
--prettier
|
||||
alias: -p
|
||||
default: false
|
||||
prettify output files
|
||||
--srccomment
|
||||
alias: -s
|
||||
alias: -c
|
||||
default: false
|
||||
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||
--readme
|
||||
alias: -r
|
||||
default: false
|
||||
update the readme.md file in your directory to include links to each userscript
|
||||
|
||||
--url <url>
|
||||
alias: -u <url>
|
||||
default: ""
|
||||
the base for urls used in the meta comments
|
||||
--supporturl <url>
|
||||
alias: -s <url>
|
||||
default: ""
|
||||
the support url used in the meta comments
|
||||
--remotebranch <name>
|
||||
alias: -b <name>
|
||||
default: ""
|
||||
if included, the included base url will be treated as a git repo, and the support url is not required
|
||||
--in
|
||||
alias: -i
|
||||
default: "scripts"
|
||||
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||
--out
|
||||
alias: -o
|
||||
default: "dist"
|
||||
include src file path comments in the output files, i.e. // scripts/example/main.ts
|
||||
|
||||
--help
|
||||
alias: -h
|
||||
show this help message
|
||||
@@ -86,11 +119,16 @@ if (!(0, fs_1.existsSync)('package.json') || !(0, fs_1.lstatSync)('package.json'
|
||||
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}`));
|
||||
//delete compiled scripts or create output folder if it doesnt exist
|
||||
if (!(0, fs_1.existsSync)(exports.AllPaths.base.out)) {
|
||||
(0, fs_1.mkdirSync)(exports.AllPaths.base.out);
|
||||
}
|
||||
else {
|
||||
(0, fs_1.readdirSync)(exports.AllPaths.base.out).forEach(file => (0, fs_1.unlinkSync)(`${exports.AllPaths.base.out}/${file}`));
|
||||
}
|
||||
//compile scripts
|
||||
async function doCompile() {
|
||||
let scripts = (0, fs_1.readdirSync)(exports.AllPaths.base.script);
|
||||
let scripts = (0, fs_1.readdirSync)(exports.AllPaths.base.in);
|
||||
let scriptMeta = [];
|
||||
for (let name of scripts) {
|
||||
let path = exports.AllPaths.script(name);
|
||||
@@ -103,7 +141,8 @@ async function doCompile() {
|
||||
function update(result) {
|
||||
console.log('WATCH', name, result.meta.version);
|
||||
scriptMeta[id] = result;
|
||||
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
||||
if (exports.CLIArgs.readme)
|
||||
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
||||
}
|
||||
let result = await (0, build_1.default)(name, update);
|
||||
console.log(name, result.meta.version);
|
||||
@@ -113,7 +152,8 @@ async function doCompile() {
|
||||
return scriptMeta;
|
||||
}
|
||||
doCompile().then(scriptMeta => {
|
||||
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
||||
if (exports.CLIArgs.readme)
|
||||
(0, readmefile_1.updateReadmeFile)(scriptMeta);
|
||||
console.log(`\nFinished Compiling\n${exports.CLIArgs.watch ? 'Listening for Changes\n' : ''}`);
|
||||
});
|
||||
//# sourceMappingURL=main.js.map
|
||||
Reference in New Issue
Block a user