@mjcctech/meteor-desktop
Version:
Build a Meteor's desktop client with hot code push.
64 lines (53 loc) • 2.27 kB
JavaScript
;var module1=module;module1.export({default:()=>BinaryModulesDetector});var path;module1.link('path',{default(v){path=v}},0);var isBinaryFile;module1.link('isbinaryfile',{default(v){isBinaryFile=v}},1);var shell;module1.link('shelljs',{default(v){shell=v}},2);var Log;module1.link('./log',{default(v){Log=v}},3);
shell.config.fatal = true;
/**
* Experimental module for detecting modules containing binary files.
* Based on the same functionality from electron-builder.
*
* @property {MeteorDesktop} $
* @class
*/
class BinaryModulesDetector {
/**
* @constructor
*/
constructor(nodeModulesPath) {
this.log = new Log('binaryModulesDetector');
this.nodeModulesPath = nodeModulesPath;
}
// TODO: make asynchronous
detect() {
this.log.verbose('detecting node modules with binary files');
const files = shell.ls('-RAl', this.nodeModulesPath);
const extract = [];
files.forEach((file) => {
const pathSplit = file.name.split(path.posix.sep);
const dir = pathSplit[0];
const filename = pathSplit.pop();
if (extract.indexOf(dir) === -1 &&
!BinaryModulesDetector.shouldBeIgnored(dir, filename)
) {
if (file.isFile()) {
let shouldUnpack = false;
if (file.name.endsWith('.dll') || file.name.endsWith('.exe') || file.name.endsWith('.dylib')) {
shouldUnpack = true;
} else if (path.extname(file.name) === '') {
shouldUnpack =
isBinaryFile.sync(path.join(this.nodeModulesPath, file.name));
}
if (shouldUnpack) {
this.log.debug(`binary file: ${file.name}`);
extract.push(dir);
}
}
}
});
if (extract.length > 0) {
this.log.verbose(`detected modules to be extracted: ${extract.join(', ')}`);
}
return extract;
}
static shouldBeIgnored(dir, filename) {
return dir === '.bin' || filename === '.DS_Store' || filename === 'LICENSE' || filename === 'README';
}
}