53 lines
2.3 KiB
JavaScript
53 lines
2.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.sanitize = exports.defaultOptions = void 0;
|
|
const path = require("path");
|
|
const osr_commons_1 = require("@plastichub/osr-commons");
|
|
const exists_1 = require("@plastichub/fs/exists");
|
|
const globBase = require('glob-base');
|
|
const find_1 = require("../lib/find");
|
|
// default options for all commands
|
|
const defaultOptions = (yargs) => {
|
|
return yargs.option('src', {
|
|
default: './',
|
|
describe: 'The source directory or source file. Glob patters are supported!',
|
|
demandOption: true
|
|
});
|
|
};
|
|
exports.defaultOptions = defaultOptions;
|
|
// Sanitizes faulty user argv options for all commands.
|
|
const sanitize = (argv, opts = {}) => {
|
|
const args = argv;
|
|
const options = Object.assign({ src: args.src, dst: args.dst, root: args.root, debug: args.debug, alt: args.alt }, opts);
|
|
let variables = Object.assign({}, options.variables);
|
|
let srcInfo;
|
|
if (options.src) {
|
|
options.src = (0, osr_commons_1.resolve)(options.src, options.alt, variables);
|
|
// in case a file with a glob pattern is provided, strip the glob
|
|
// this is a special case, enabling shared scripts in Alt-Tap Salamand
|
|
const glob_base = globBase(options.src);
|
|
const file = options.src.replace(glob_base.glob, '').replace(/\/$/, '');
|
|
if ((0, exists_1.sync)(file) && (0, osr_commons_1.isFile)(file)) {
|
|
options.src = file;
|
|
}
|
|
const src = ((0, osr_commons_1.resolve)(options.src, options.alt, variables));
|
|
srcInfo = (0, find_1.pathInfo)(src);
|
|
if (srcInfo && srcInfo.FILES && srcInfo.FILES.length) {
|
|
options.srcInfo = srcInfo;
|
|
for (const key in srcInfo) {
|
|
if (Object.prototype.hasOwnProperty.call(srcInfo, key)) {
|
|
variables['SRC_' + key] = srcInfo[key];
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
options.src = (0, osr_commons_1.resolve)(options.src, options.alt, variables);
|
|
}
|
|
}
|
|
if (options.dst) {
|
|
options.dst = path.resolve((0, osr_commons_1.resolve)(options.dst, options.alt, variables));
|
|
}
|
|
return options;
|
|
};
|
|
exports.sanitize = sanitize;
|
|
//# sourceMappingURL=argv.js.map
|