UNPKG

electron-builder

Version:

A complete solution to package and build a ready for distribution Electron app for MacOS, Windows and Linux with “auto update” support out of the box

104 lines (93 loc) 3.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileMatcher = undefined; exports.deprecatedUserIgnoreFilter = deprecatedUserIgnoreFilter; var _path; function _load_path() { return _path = _interopRequireWildcard(require("path")); } var _filter; function _load_filter() { return _filter = require("./util/filter"); } var _minimatch; function _load_minimatch() { return _minimatch = require("minimatch"); } var _util; function _load_util() { return _util = require("./util/util"); } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } class FileMatcher { constructor(from, to, options, patterns) { this.options = options; this.from = this.expandPattern(from); this.to = this.expandPattern(to); this.patterns = (0, (_util || _load_util()).asArray)(patterns); } addPattern(pattern) { this.patterns.push(pattern); } isEmpty() { return this.patterns.length === 0; } getParsedPatterns(fromDir) { // https://github.com/electron-userland/electron-builder/issues/733 const minimatchOptions = { dot: true }; const parsedPatterns = []; const pathDifference = fromDir ? (_path || _load_path()).relative(fromDir, this.from) : null; for (let i = 0; i < this.patterns.length; i++) { let expandedPattern = this.expandPattern(this.patterns[i]); if (pathDifference) { expandedPattern = (_path || _load_path()).join(pathDifference, expandedPattern); } const parsedPattern = new (_minimatch || _load_minimatch()).Minimatch(expandedPattern, minimatchOptions); parsedPatterns.push(parsedPattern); if (!(0, (_filter || _load_filter()).hasMagic)(parsedPattern)) { // https://github.com/electron-userland/electron-builder/issues/545 // add **/* parsedPatterns.push(new (_minimatch || _load_minimatch()).Minimatch(`${ expandedPattern }/**/*`, minimatchOptions)); } } return parsedPatterns; } createFilter(ignoreFiles, rawFilter, excludePatterns) { return (0, (_filter || _load_filter()).createFilter)(this.from, this.getParsedPatterns(), ignoreFiles, rawFilter, excludePatterns); } expandPattern(pattern) { return pattern.replace(/\$\{arch}/g, this.options.arch).replace(/\$\{os}/g, this.options.os).replace(/\$\{\/\*}/g, "{,/**/*}"); } } exports.FileMatcher = FileMatcher; function deprecatedUserIgnoreFilter(ignore, appDir) { let ignoreFunc; if (typeof ignore === "function") { ignoreFunc = function (file) { return !ignore(file); }; } else { if (!Array.isArray(ignore)) { ignore = [ignore]; } ignoreFunc = function (file) { for (let i = 0; i < ignore.length; i++) { if (file.match(ignore[i])) { return false; } } return true; }; } return function filter(file) { let name = file.split((_path || _load_path()).resolve(appDir))[1]; if ((_path || _load_path()).sep === "\\") { // convert slashes so unix-format ignores work name = name.replace(/\\/g, "/"); } return ignoreFunc(name); }; } //# sourceMappingURL=fileMatcher.js.map