@plastichub/osr-cad
Version:
This is a CLI(CommandLineInterface) toolset to convert 3D files, using Solidworks and other software.
58 lines • 1.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.pack = exports.packFile = void 0;
const path = require("path");
const pMap = require("p-map");
const __1 = require("..");
const index_1 = require("../lib/process/index");
const exists_1 = require("@plastichub/fs/exists");
const sw_util_1 = require("./sw-util");
async function packFile(file, onNode = () => { }, options) {
if (options.dry) {
return Promise.resolve();
}
const target = options.dst;
if (options.cache && (0, exists_1.sync)(target)) {
onNode({
src: file,
target
});
return Promise.resolve();
}
let exe = '' + options.script;
let args = [
`"${file}"`,
`"${target}"`
];
const cwd = (0, sw_util_1.getSWBin)(options.sw);
const bin = path.resolve(`${cwd}/${exe}`);
if (!(0, exists_1.sync)(bin)) {
__1.logger.error(`${bin} doesnt exists in ${cwd}`);
__1.logger.error('__dirname:' + __dirname);
__1.logger.error('options.sw ' + options.sw);
return;
}
options.debug && __1.logger.debug(`Running ${cwd}/${exe} with`, args);
const promise = index_1.Helper.run(cwd, exe, args, options.debug);
promise.then((d) => {
onNode({
...d,
src: file,
target
});
});
return promise;
}
exports.packFile = packFile;
async function pack(options) {
let reports = [];
const onNode = (data) => { reports.push(data); };
options.verbose && __1.logger.info(`Pack ${options.srcInfo.FILES.length} files `);
const ret = await pMap(options.srcInfo.FILES, async (f) => {
__1.logger.debug(`Convert ${f} to `, options.dst);
return packFile(f, onNode, options);
}, { concurrency: 1 });
return ret;
}
exports.pack = pack;
//# sourceMappingURL=sw-pack.js.map