electron-packager-languages
Advanced tools
Comparing version 0.1.0 to 0.3.0
@@ -7,35 +7,62 @@ 'use strict'; | ||
function getResourcePath(givenPath) { | ||
return path.resolve(givenPath, '..'); | ||
function getLanguageFolderPath(givenPath, platform) { | ||
switch (platform) { | ||
case 'darwin': | ||
case 'mas': | ||
return path.resolve(givenPath, '..'); | ||
case 'win32': | ||
case 'linux': | ||
return path.resolve(givenPath, '..', '..', 'locales'); | ||
default: | ||
return path.resolve(givenPath); | ||
} | ||
} | ||
function walkDir(dir) { | ||
var regex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : /./g; | ||
return fs.readdirSync(dir).filter(function (currentPath) { | ||
return fs.statSync(path.resolve(dir, currentPath)).isDirectory() && regex.test(currentPath); | ||
}); | ||
function getLanguageFileExtension(platform) { | ||
switch (platform) { | ||
case 'darwin': | ||
case 'mas': | ||
return 'lproj'; | ||
case 'win32': | ||
case 'linux': | ||
return 'pak'; | ||
default: | ||
return ''; | ||
} | ||
} | ||
// eslint-disable-next-line max-params | ||
module.exports = function languages(languages) { | ||
return function (buildPath, electronVersion, platform, arch, callback) { | ||
// eslint-disable-next-line | ||
if (['darwin', 'mas'].includes(platform)) { | ||
var resourcePath = getResourcePath(buildPath); | ||
var excludedLanguages = languages.map(function (l) { | ||
return l + '.lproj'; | ||
}); | ||
var languageFolderFilter = new RegExp('.(lproj)$'); | ||
function walkLanguagePaths(dir, platform) { | ||
var regex = new RegExp('.(' + getLanguageFileExtension(platform) + ')$'); | ||
var paths = fs.readdirSync(dir); | ||
var languageFolders = walkDir(resourcePath, languageFolderFilter); | ||
languageFolders.filter(function (langFolder) { | ||
return !excludedLanguages.includes(langFolder); | ||
}).forEach(function (langFolder) { | ||
rimraf.sync(path.resolve(resourcePath, langFolder)); | ||
switch (platform) { | ||
case 'darwin': | ||
case 'mas': | ||
return paths.filter(function (currentPath) { | ||
return fs.statSync(path.resolve(dir, currentPath)).isDirectory() && regex.test(currentPath); | ||
}); | ||
} | ||
case 'win32': | ||
case 'linux': | ||
return paths; | ||
default: | ||
return []; | ||
} | ||
} | ||
module.exports = function setLanguages(languages) { | ||
return function electronPackagerLanguages(buildPath, electronVersion, platform, arch, callback) { | ||
var resourcePath = getLanguageFolderPath(buildPath, platform); | ||
var excludedLanguages = languages.map(function (l) { | ||
return l + '.' + getLanguageFileExtension(platform); | ||
}); | ||
var languageFolders = walkLanguagePaths(resourcePath, platform); | ||
languageFolders.filter(function (langFolder) { | ||
return !excludedLanguages.includes(langFolder); | ||
}).forEach(function (langFolder) { | ||
return rimraf.sync(path.resolve(resourcePath, langFolder)); | ||
}); | ||
callback(); | ||
}; | ||
}; |
{ | ||
"name": "electron-packager-languages", | ||
"version": "0.1.0", | ||
"version": "0.3.0", | ||
"main": "dist/index.js", | ||
@@ -10,13 +10,24 @@ "repository": "git@github.com:barinali/electron-packager-languages.git", | ||
"author": "Ali BARIN <ali.barin53@gmail.com>", | ||
"license": "BSD-2-Clause", | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=4.0.0" | ||
}, | ||
"scripts": { | ||
"build": "babel src --out-dir dist", | ||
"test": "node test/specs/main" | ||
"lint": "eslint .", | ||
"prepublish": "npm run build", | ||
"test": "babel-node test/specs/main" | ||
}, | ||
"dependencies": { | ||
"rimraf": "^2.6.2" | ||
}, | ||
"devDependencies": { | ||
"babel": "^6.23.0", | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-env": "^1.6.1", | ||
"electron-packager": "^10.1.0", | ||
"rimraf": "^2.6.2" | ||
"eslint": "^4.19.1", | ||
"eslint-config-airbnb-base": "^12.1.0", | ||
"eslint-plugin-import": "^2.10.0", | ||
"husky": "^0.15.0-rc.13" | ||
}, | ||
@@ -27,6 +38,14 @@ "files": [ | ||
"babel": { | ||
"plugins": [ | ||
"transform-object-rest-spread" | ||
], | ||
"presets": [ | ||
"es2015" | ||
"env" | ||
] | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "npm run lint" | ||
} | ||
} | ||
} |
Electron Packager Plugin: Languages | ||
--------------------------- | ||
[![GitHub license](https://img.shields.io/github/license/barinali/electron-packager-languages.svg)](https://github.com/barinali/electron-packager-languages/blob/master/LICENSE) | ||
[![Travis CI](https://img.shields.io/travis/barinali/electron-packager-languages.svg)](https://travis-ci.org/barinali/electron-packager-languages/) | ||
[![NPM Download Count](https://img.shields.io/npm/dt/electron-packager-languages.svg)](https://www.npmjs.com/package/electron-packager-languages) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/barinali/electron-packager-languages/badge.svg?targetFile=package.json)](https://snyk.io/test/github/barinali/electron-packager-languages?targetFile=package.json) | ||
# Reason | ||
@@ -20,2 +24,2 @@ | ||
}) | ||
``` | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5293
58
25
1
8
+ Addedrimraf@^2.6.2
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedwrappy@1.0.2(transitive)