Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const cheerio = require('cheerio');
const _ = require('lodash');
const i18n = require('i18next');
const path = require('path');
const glob = require('glob');
const { glob } = require('glob');
const yaml = require('js-yaml');
const Promise = require('bluebird');

Expand Down Expand Up @@ -60,6 +60,25 @@ function promisify(func, ignoreError) {
};
}

function asyncPromisify(asyncFunc, ignoreError) {
return function () {
const args = Array.prototype.slice.call(arguments);
return new Promise((resolve, reject) => {
args.push(function (err, result) {
err && !ignoreError ? reject(err) : resolve(result);
});

asyncFunc.apply(asyncFunc, args)
.then(result => resolve(result))
.catch(err => {
if (ignoreError) resolve(null);

reject(err);
});
});
};
}

function parseTranslations(format, rawTranslations, localeRootKey, locale) {
try {
switch (format) {
Expand Down Expand Up @@ -378,7 +397,10 @@ exports.processDir = function(dir, options) {
options.baseDir = dir;
}
const pattern = options.files || defaults.files;
return promisify(glob)(path.join(dir, pattern))

const getFilesPath = async pathPattern => await glob(pathPattern)

return asyncPromisify(getFilesPath)(path.join(dir, pattern))
.then((files) => _.reject(files, (f) => shouldExcludeFile(f, options)))
.mapSeries((file) =>
exports.processFile(file, options).then((r) => [file, r])
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
},
"homepage": "https://github.com/claudetech/node-static-i18n",
"devDependencies": {
"eslint": "^4.17.0",
"eslint": "^8.56.0",
"expect.js": "^0.3.1",
"nyc": "^11.4.1",
"tmp": "^0.0.33"
"nyc": "^15.1.0",
"tmp": "^0.2.1"
},
"dependencies": {
"bluebird": "^3.5.1",
"bluebird": "^3.7.2",
"cheerio": "^0.22.0",
"fs-extra": "^5.0.0",
"glob": "^7.1.2",
"i18next": "^11.2.3",
"js-yaml": "^3.10.0",
"lodash": "^4.17.5",
"minimist": "^1.1.0",
"mocha": "^5.0.1"
"fs-extra": "^11.2.0",
"glob": "^10.3.10",
"i18next": "^23.10.0",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"minimist": "^1.2.8",
"mocha": "^10.3.0"
},
"prettier": {
"singleQuote": true
Expand Down
Loading