UNPKG

@plastichub/osr-cad

Version:

This is a CLI(CommandLineInterface) toolset to convert 3D files, using Solidworks and other software.

93 lines 3.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.equalFiles = exports.removeEmptyValues = exports.closeAppByName = exports.getSWBin = exports.fileAsBuffer = exports.swProcMessage = void 0; const fs = require("fs"); const path = require("path"); const child_process_1 = require("child_process"); const exists_1 = require("@plastichub/fs/exists"); const read_1 = require("@plastichub/fs/read"); const constants_1 = require("../constants"); const swProcMessage = (log) => { const regex = /<<(\w+)::(.*?)>>/; const match = log.match(regex); if (match) { return { logLevel: match[1], message: match[2] }; } }; exports.swProcMessage = swProcMessage; const fileAsBuffer = (path) => (0, read_1.sync)(path, 'buffer') || Buffer.from("-"); exports.fileAsBuffer = fileAsBuffer; const getSWBin = (argv) => { const swVersion = parseInt(argv); if (swVersion) { return path.resolve(__dirname + `/../sw/${swVersion}`); } else { return path.resolve(argv); } }; exports.getSWBin = getSWBin; function closeAppByName(appName) { try { const command = `tasklist /FI "IMAGENAME eq ${appName}.exe" /NH`; const output = (0, child_process_1.execSync)(command).toString(); const lines = output.split('\n'); const processIdLine = lines.find(line => line.includes(appName)); if (!processIdLine) { return; } const processId = parseInt(processIdLine.split(/\s+/)[1], 10); (0, child_process_1.execSync)(`taskkill /F /PID ${processId}`); } catch (error) { } } exports.closeAppByName = closeAppByName; function removeEmptyValues(obj) { for (const key in obj) { const value = obj[key]; if (!value || typeof value !== 'number' || typeof value !== 'boolean' || typeof value !== 'string') { delete obj[key]; } } return obj; } exports.removeEmptyValues = removeEmptyValues; const equalFiles = (pathA, pathB) => { if (!(0, exists_1.sync)(pathA) || !(0, exists_1.sync)(pathB)) { return false; } let statA = fs.lstatSync(pathA); let statB = fs.lstatSync(pathB); if (statA.size !== statB.size) { return false; } ; let fdA = fs.openSync(pathA, 'r'); let fdB = fs.openSync(pathB, 'r'); let bufA = Buffer.alloc(constants_1.BUF_SIZE_CMP); let bufB = Buffer.alloc(constants_1.BUF_SIZE_CMP); let readA = 1; let readB = 1; while (readA > 0) { readA = fs.readSync(fdA, bufA, 0, bufA.length, null); readB = fs.readSync(fdB, bufB, 0, bufB.length, null); if (readA !== readB) { return false; } for (let i = 0; i < readA; i++) { if (bufA[i] !== bufB[i]) { return false; } } } fs.closeSync(fdA); fs.closeSync(fdB); return true; }; exports.equalFiles = equalFiles; //# sourceMappingURL=sw-util.js.map