206 lines
7.8 KiB
JavaScript
206 lines
7.8 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.sanitize = exports.sanitizeSingle = exports.defaultOptions = void 0;
|
|
const path = require("path");
|
|
const _1 = require("./");
|
|
const primitives_1 = require("./lib/common/primitives");
|
|
const core_1 = require("@plastichub/core");
|
|
const osr_cli_commons_1 = require("@plastichub/osr-cli-commons");
|
|
const read_1 = require("@plastichub/fs/read");
|
|
// default options for all commands
|
|
exports.defaultOptions = (yargs) => {
|
|
return yargs.option('src', {
|
|
default: './',
|
|
describe: 'The source directory or source file. Glob patters are supported!',
|
|
demandOption: true
|
|
}).option('format', {
|
|
describe: 'The target format. Multiple formats are allowed as well, use --format=pdf --format=jpg'
|
|
}).option('dst', {
|
|
describe: 'Destination folder or file'
|
|
}).option('view', {
|
|
default: 'Isometric',
|
|
describe: 'Sets the target view'
|
|
}).option('Report', {
|
|
describe: 'Optional conversion report. Can be JSON, HTML, CSV or Markdown'
|
|
}).option('debug', {
|
|
default: false,
|
|
describe: 'Enable internal debug messages',
|
|
type: 'boolean'
|
|
}).option('alt', {
|
|
default: false,
|
|
describe: 'Use alternate tokenizer, & instead of $',
|
|
type: 'boolean'
|
|
}).option('skip', {
|
|
default: true,
|
|
describe: 'Skip existing files',
|
|
type: 'boolean'
|
|
}).option('dry', {
|
|
default: false,
|
|
describe: 'Run without conversion',
|
|
type: 'boolean'
|
|
}).option('verbose', {
|
|
default: true,
|
|
describe: 'Show internal messages',
|
|
type: 'boolean'
|
|
}).option('sw', {
|
|
describe: 'Set explicit the path to the Solidworks binaries & scripts.\
|
|
"It assumes SolidWorks.Interop.sldworks.dll and export.cmd at this location!'
|
|
}).option('script', {
|
|
describe: 'Set explicit the path to the Solidworks script'
|
|
}).option('hash', {
|
|
describe: 'To skip already converted files, this option will create a hash file with the extension .hash \
|
|
using --skip==true will disable it again',
|
|
default: true,
|
|
type: 'boolean'
|
|
}).option('bom-config', {
|
|
describe: 'Set the Model Configuration to be used',
|
|
default: 'Default'
|
|
}).option('bom-template', {
|
|
describe: 'Path to the BOM template. Default is osr-cad/sw/bom-all.sldbomtbt'
|
|
}).option('bom-type', {
|
|
describe: 'Bom Type : default = 2 - PartsOnly = 1 | TopLevelOnly = 2 | Indented = 3',
|
|
type: "number",
|
|
default: 2
|
|
}).option('bom-detail', {
|
|
describe: 'Bom Numbering : default = 1 - Type_None = 0 | Type_Detailed = 1 | Type_Flat = 2 | BOMNotSet = 3',
|
|
type: "number",
|
|
default: 1
|
|
}).option('bom-images', {
|
|
describe: 'Add an image in the first colum',
|
|
type: 'boolean',
|
|
default: false
|
|
});
|
|
};
|
|
// Sanitizes faulty user argv options for all commands.
|
|
exports.sanitizeSingle = (argv) => {
|
|
const src = path.resolve('' + argv.src);
|
|
const config = argv.config ? read_1.sync(path.resolve('' + argv.config), 'json') : {};
|
|
const extraVariables = {};
|
|
for (const key in config) {
|
|
if (Object.prototype.hasOwnProperty.call(config, key)) {
|
|
const element = config[key];
|
|
if (typeof element === 'string') {
|
|
extraVariables[key] = element;
|
|
}
|
|
}
|
|
}
|
|
const args = {
|
|
src: src,
|
|
dst: '' + argv.dst,
|
|
report: argv.report ? path.resolve(argv.report) : null,
|
|
debug: argv.debug,
|
|
verbose: argv.verbose,
|
|
dry: argv.dry,
|
|
skip: argv.skip,
|
|
alt: argv.alt,
|
|
glob: argv.glob,
|
|
// sw: argv.sw ? path.resolve(argv.sw as string) : path.resolve(__dirname + '/../sw'),
|
|
script: argv.script || 'pack.exe',
|
|
variables: Object.assign({}, extraVariables),
|
|
args: argv.args || '',
|
|
hash: argv.hash
|
|
};
|
|
if (!args.src) {
|
|
_1.logger.error('Invalid source, abort');
|
|
return process.exit();
|
|
}
|
|
args.srcInfo = osr_cli_commons_1.pathInfo(argv.src);
|
|
if (!args.srcInfo.FILES) {
|
|
_1.logger.error(`Invalid source files, abort`);
|
|
return process.exit();
|
|
}
|
|
for (const key in args.srcInfo) {
|
|
if (Object.prototype.hasOwnProperty.call(args.srcInfo, key)) {
|
|
args.variables['SRC_' + key] = args.srcInfo[key];
|
|
}
|
|
}
|
|
if (argv.dst) {
|
|
args.dst = path.resolve(args.dst);
|
|
args.dstInfo = osr_cli_commons_1.pathInfo(args.dst);
|
|
args.dstInfo.PATH = path.resolve(argv.dst);
|
|
for (const key in args.dstInfo) {
|
|
if (Object.prototype.hasOwnProperty.call(args.dstInfo, key)) {
|
|
args.variables['DST_' + key] = args.dstInfo[key];
|
|
}
|
|
}
|
|
}
|
|
// check for single file direct conversion
|
|
if (!args.dstInfo.IS_GLOB && !args.format && args.dstInfo.IS_GLOB) {
|
|
// args.format = [dstParts.ext.replace('*', '')]
|
|
}
|
|
return args;
|
|
};
|
|
// Sanitizes faulty user argv options for all commands.
|
|
exports.sanitize = (argv) => {
|
|
const src = path.resolve('' + argv.src);
|
|
const config = argv.config ? read_1.sync(path.resolve('' + argv.config), 'json') : {};
|
|
const extraVariables = {};
|
|
for (const key in config) {
|
|
if (Object.prototype.hasOwnProperty.call(config, key)) {
|
|
const element = config[key];
|
|
if (typeof element === 'string') {
|
|
extraVariables[key] = element;
|
|
}
|
|
}
|
|
}
|
|
const args = {
|
|
src: src,
|
|
dst: '' + argv.dst,
|
|
report: argv.report ? path.resolve(argv.report) : null,
|
|
debug: argv.debug,
|
|
verbose: argv.verbose,
|
|
dry: argv.dry,
|
|
skip: argv.skip,
|
|
alt: argv.alt,
|
|
glob: argv.glob,
|
|
// sw: argv.sw ? path.resolve(argv.sw as string) : path.resolve(__dirname + '/../sw'),
|
|
script: argv.script || 'export.cmd',
|
|
variables: Object.assign({}, extraVariables),
|
|
args: argv.args || '',
|
|
hash: argv.hash,
|
|
"bom-config": argv['bom-config'],
|
|
"bom-detail": argv['bom-detail'],
|
|
"bom-template": argv['bom-template'],
|
|
"bom-type": argv['bom-type'],
|
|
"bom-images": argv['bom-images'],
|
|
};
|
|
if (!args.src) {
|
|
_1.logger.error('Invalid source, abort');
|
|
return process.exit();
|
|
}
|
|
if (argv.format) {
|
|
if (typeof argv.format === 'string') {
|
|
args.format = [argv.format];
|
|
}
|
|
else if (argv.source && primitives_1.isArray(argv.format)) {
|
|
args.format = argv.format;
|
|
}
|
|
}
|
|
args.srcInfo = osr_cli_commons_1.pathInfo(argv.src);
|
|
if (!args.srcInfo.FILES) {
|
|
_1.logger.error(`Invalid source files, abort`, args.srcInfo);
|
|
return process.exit();
|
|
}
|
|
for (const key in args.srcInfo) {
|
|
if (Object.prototype.hasOwnProperty.call(args.srcInfo, key)) {
|
|
args.variables['SRC_' + key] = args.srcInfo[key];
|
|
}
|
|
}
|
|
if (argv.dst) {
|
|
args.dst = path.resolve(core_1.substitute(args.dst, args.variables));
|
|
args.dstInfo = osr_cli_commons_1.pathInfo(args.dst);
|
|
args.dstInfo.PATH = argv.dst;
|
|
for (const key in args.dstInfo) {
|
|
if (Object.prototype.hasOwnProperty.call(args.dstInfo, key)) {
|
|
args.variables['DST_' + key] = args.dstInfo[key];
|
|
}
|
|
}
|
|
}
|
|
args.view = argv.view || "Isometric";
|
|
// check for single file direct conversion
|
|
if (!args.dstInfo.IS_GLOB && !args.format && args.dstInfo.IS_GLOB) {
|
|
// args.format = [dstParts.ext.replace('*', '')]
|
|
}
|
|
return args;
|
|
};
|
|
//# sourceMappingURL=argv.js.map
|