Socket
Socket
Sign inDemoInstall

@lingui/cli

Package Overview
Dependencies
Maintainers
1
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lingui/cli - npm Package Compare versions

Comparing version 3.12.1 to 3.13.0

302

api/catalog.js

@@ -21,2 +21,6 @@ "use strict";

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

@@ -52,2 +56,6 @@

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }

@@ -59,6 +67,2 @@

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
var NAME = "{name}";

@@ -93,28 +97,76 @@ var LOCALE = "{locale}";

key: "make",
value: function make(options) {
var nextCatalog = this.collect(options);
var prevCatalogs = this.readAll();
var catalogs = this.merge(prevCatalogs, nextCatalog, {
overwrite: options.overwrite,
files: options.files
}); // Map over all locales and post-process each catalog
value: function () {
var _make = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(options) {
var nextCatalog, prevCatalogs, catalogs, cleanAndSort, sortedCatalogs;
return _regenerator.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return this.collect(options);
var cleanAndSort = R.map(R.pipe( // Clean obsolete messages
options.clean ? cleanObsolete : R.identity, // Sort messages
order(options.orderBy)));
var sortedCatalogs = cleanAndSort(catalogs);
case 2:
nextCatalog = _context.sent;
prevCatalogs = this.readAll();
catalogs = this.merge(prevCatalogs, nextCatalog, {
overwrite: options.overwrite,
files: options.files
}); // Map over all locales and post-process each catalog
if (options.locale) {
this.write(options.locale, sortedCatalogs[options.locale]);
} else {
this.writeAll(sortedCatalogs);
cleanAndSort = R.map(R.pipe( // Clean obsolete messages
options.clean ? cleanObsolete : R.identity, // Sort messages
order(options.orderBy)));
sortedCatalogs = cleanAndSort(catalogs);
if (options.locale) {
this.write(options.locale, sortedCatalogs[options.locale]);
} else {
this.writeAll(sortedCatalogs);
}
case 8:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
function make(_x) {
return _make.apply(this, arguments);
}
}
return make;
}()
}, {
key: "makeTemplate",
value: function makeTemplate(options) {
var catalog = this.collect(options);
var sort = order(options.orderBy);
this.writeTemplate(sort(catalog));
}
value: function () {
var _makeTemplate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(options) {
var catalog, sort;
return _regenerator.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return this.collect(options);
case 2:
catalog = _context2.sent;
sort = order(options.orderBy);
this.writeTemplate(sort(catalog));
case 5:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
function makeTemplate(_x2) {
return _makeTemplate.apply(this, arguments);
}
return makeTemplate;
}()
/**

@@ -126,62 +178,120 @@ * Collect messages from source paths. Return a raw message catalog as JSON.

key: "collect",
value: function collect(options) {
var _this = this;
value: function () {
var _collect = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(options) {
var tmpDir, paths, regex, _iterator, _step, filename;
var tmpDir = _path.default.join(_os.default.tmpdir(), "lingui-".concat(process.pid));
return _regenerator.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
tmpDir = _path.default.join(_os.default.tmpdir(), "lingui-".concat(process.pid));
if (_fsExtra.default.existsSync(tmpDir)) {
(0, _utils.removeDirectory)(tmpDir, true);
} else {
_fsExtra.default.mkdirSync(tmpDir);
}
if (_fsExtra.default.existsSync(tmpDir)) {
(0, _utils.removeDirectory)(tmpDir, true);
} else {
_fsExtra.default.mkdirSync(tmpDir);
}
try {
var paths = this.sourcePaths;
_context3.prev = 2;
paths = this.sourcePaths;
if (options.files) {
options.files = options.files.map(function (p) {
return (0, _normalizePath.default)(p, false);
});
var regex = new RegExp(options.files.join("|"), "i");
paths = paths.filter(function (path) {
return regex.test(path);
});
}
if (options.files) {
options.files = options.files.map(function (p) {
return (0, _normalizePath.default)(p, false);
});
regex = new RegExp(options.files.join("|"), "i");
paths = paths.filter(function (path) {
return regex.test(path);
});
}
paths.forEach(function (filename) {
return (0, _extractors.default)(filename, tmpDir, {
verbose: options.verbose,
configPath: options.configPath,
babelOptions: _this.config.extractBabelOptions,
extractors: options.extractors,
projectType: options.projectType
});
});
return function traverse(directory) {
return _fsExtra.default.readdirSync(directory).map(function (filename) {
var filepath = _path.default.join(directory, filename);
_iterator = _createForOfIteratorHelper(paths);
_context3.prev = 6;
if (_fsExtra.default.lstatSync(filepath).isDirectory()) {
return traverse(filepath);
_iterator.s();
case 8:
if ((_step = _iterator.n()).done) {
_context3.next = 14;
break;
}
filename = _step.value;
_context3.next = 12;
return (0, _extractors.default)(filename, tmpDir, {
verbose: options.verbose,
configPath: options.configPath,
babelOptions: this.config.extractBabelOptions,
extractors: options.extractors,
projectType: options.projectType
});
case 12:
_context3.next = 8;
break;
case 14:
_context3.next = 19;
break;
case 16:
_context3.prev = 16;
_context3.t0 = _context3["catch"](6);
_iterator.e(_context3.t0);
case 19:
_context3.prev = 19;
_iterator.f();
return _context3.finish(19);
case 22:
return _context3.abrupt("return", function traverse(directory) {
return _fsExtra.default.readdirSync(directory).map(function (filename) {
var filepath = _path.default.join(directory, filename);
if (_fsExtra.default.lstatSync(filepath).isDirectory()) {
return traverse(filepath);
}
if (!filename.endsWith(".json")) return;
try {
return JSON.parse(_fsExtra.default.readFileSync(filepath).toString());
} catch (e) {}
}).filter(Boolean).reduce(function (catalog, messages) {
return R.mergeWithKey(mergeOriginsAndExtractedComments, catalog, messages);
}, {});
}(tmpDir));
case 25:
_context3.prev = 25;
_context3.t1 = _context3["catch"](2);
throw _context3.t1;
case 28:
_context3.prev = 28;
(0, _utils.removeDirectory)(tmpDir);
return _context3.finish(28);
case 31:
case "end":
return _context3.stop();
}
}
}, _callee3, this, [[2, 25, 28, 31], [6, 16, 19, 22]]);
}));
if (!filename.endsWith(".json")) return;
function collect(_x3) {
return _collect.apply(this, arguments);
}
try {
return JSON.parse(_fsExtra.default.readFileSync(filepath).toString());
} catch (e) {}
}).filter(Boolean).reduce(function (catalog, messages) {
return R.mergeWithKey(mergeOriginsAndExtractedComments, catalog, messages);
}, {});
}(tmpDir);
} catch (e) {
throw e;
} finally {
(0, _utils.removeDirectory)(tmpDir);
}
}
return collect;
}()
}, {
key: "merge",
value: function merge(prevCatalogs, nextCatalog, options) {
var _this2 = this;
var _this = this;

@@ -197,3 +307,3 @@ var nextKeys = R.keys(nextCatalog).map(String);

return _objectSpread({
translation: _this2.config.sourceLocale === locale ? message.message || key : ""
translation: _this.config.sourceLocale === locale ? message.message || key : ""
}, message);

@@ -203,4 +313,4 @@ }, R.pick(newKeys, nextCatalog)); // Merge translations from previous catalog

var mergedMessages = mergeKeys.map(function (key) {
var updateFromDefaults = _this2.config.sourceLocale === locale && (prevCatalog[key].translation === prevCatalog[key].message || options.overwrite);
var translation = updateFromDefaults ? nextCatalog[key].message : prevCatalog[key].translation;
var updateFromDefaults = _this.config.sourceLocale === locale && (prevCatalog[key].translation === prevCatalog[key].message || options.overwrite);
var translation = updateFromDefaults ? nextCatalog[key].message || key : prevCatalog[key].translation;
return (0, _defineProperty2.default)({}, key, _objectSpread({

@@ -223,7 +333,7 @@ translation: translation

value: function getTranslations(locale, options) {
var _this3 = this;
var _this2 = this;
var catalogs = this.readAll();
return R.mapObjIndexed(function (_value, key) {
return _this3.getTranslation(catalogs, locale, key, options);
return _this2.getTranslation(catalogs, locale, key, options);
}, catalogs[locale]);

@@ -234,3 +344,3 @@ }

value: function getTranslation(catalogs, locale, key, _ref4) {
var _this4 = this;
var _this3 = this;

@@ -245,3 +355,3 @@ var fallbackLocales = _ref4.fallbackLocales,

var getTranslation = function getTranslation(locale) {
var configLocales = _this4.config.locales.join('", "');
var configLocales = _this3.config.locales.join('", "');

@@ -273,8 +383,8 @@ var localeCatalog = catalogs[locale];

if (Array.isArray(fL)) {
var _iterator = _createForOfIteratorHelper(fL),
_step;
var _iterator2 = _createForOfIteratorHelper(fL),
_step2;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var fallbackLocale = _step.value;
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var fallbackLocale = _step2.value;

@@ -286,5 +396,5 @@ if (catalogs[fallbackLocale]) {

} catch (err) {
_iterator.e(err);
_iterator2.e(err);
} finally {
_iterator.f();
_iterator2.f();
}

@@ -327,6 +437,6 @@ } else {

value: function writeAll(catalogs) {
var _this5 = this;
var _this4 = this;
this.locales.forEach(function (locale) {
return _this5.write(locale, catalogs[locale]);
return _this4.write(locale, catalogs[locale]);
});

@@ -386,6 +496,6 @@ }

value: function readAll() {
var _this6 = this;
var _this5 = this;
return R.mergeAll(this.locales.map(function (locale) {
return (0, _defineProperty2.default)({}, locale, _this6.read(locale));
return (0, _defineProperty2.default)({}, locale, _this5.read(locale));
}));

@@ -521,8 +631,8 @@ }

function getCatalogForFile(file, catalogs) {
var _iterator2 = _createForOfIteratorHelper(catalogs),
_step2;
var _iterator3 = _createForOfIteratorHelper(catalogs),
_step3;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _catalog = _step2.value;
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var _catalog = _step3.value;
var catalogFile = "".concat(_catalog.path).concat(_catalog.format.catalogExtension);

@@ -541,5 +651,5 @@ var catalogGlob = catalogFile.replace(LOCALE, "*");

} catch (err) {
_iterator2.e(err);
_iterator3.e(err);
} finally {
_iterator2.f();
_iterator3.f();
}

@@ -546,0 +656,0 @@

@@ -15,2 +15,4 @@ "use strict";

var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var t = _interopRequireWildcard(require("@babel/types"));

@@ -32,2 +34,14 @@

/**
* Transform a single key/value translation into a Babel expression,
* applying pseudolocalization where necessary.
*/
function compileSingleKey(key, translation, shouldPseudolocalize) {
if (shouldPseudolocalize) {
translation = (0, _pseudoLocalize.default)(key);
}
return t.objectProperty(t.stringLiteral(key), compile(translation));
}
function createCompiledCatalog(locale, messages, options) {

@@ -43,11 +57,18 @@ var _options$strict = options.strict,

pure = _options$pure === void 0 ? false : _options$pure;
var shouldPseudolocalize = locale === pseudoLocale;
var compiledMessages = R.keys(messages).map(function (key) {
// Don't use `key` as a fallback translation in strict mode.
var translation = messages[key] || (!strict ? key : "");
var value = messages[key]; // If the current ID's value is a context object, create a nested
// expression, and assign the current ID to that expression
if (locale === pseudoLocale) {
translation = (0, _pseudoLocalize.default)(translation);
}
if ((0, _typeof2.default)(value) === "object") {
var contextExpression = t.objectExpression(Object.keys(value).map(function (contextKey) {
var contextTranslation = value[contextKey];
return compileSingleKey(contextKey, contextTranslation, shouldPseudolocalize);
}));
return t.objectProperty(t.stringLiteral(key), contextExpression);
} // Don't use `key` as a fallback translation in strict mode.
return t.objectProperty(t.stringLiteral(key), compile(translation));
var translation = messages[key] || (!strict ? key : "");
return compileSingleKey(key, translation, shouldPseudolocalize);
});

@@ -54,0 +75,0 @@ var ast = pure ? t.objectExpression(compiledMessages) : buildExportStatement(t.objectExpression(compiledMessages), namespace);

@@ -13,2 +13,6 @@ "use strict";

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

@@ -28,2 +32,8 @@

function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

@@ -48,21 +58,118 @@

function extract(srcPaths, targetPath) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var _options$ignore = options.ignore,
ignore = _options$ignore === void 0 ? [] : _options$ignore;
var ignorePattern = ignore.length ? new RegExp(ignore.join("|"), "i") : null;
srcPaths.forEach(function (srcFilename) {
if (!_fs.default.existsSync(srcFilename) || ignorePattern && ignorePattern.test(srcFilename)) return;
function extract(_x, _x2) {
return _extract.apply(this, arguments);
}
if (_fs.default.statSync(srcFilename).isDirectory()) {
var subdirs = _fs.default.readdirSync(srcFilename).sort().map(function (filename) {
return _path.default.join(srcFilename, filename);
});
function _extract() {
_extract = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(srcPaths, targetPath) {
var options,
_options$ignore,
ignore,
ignorePattern,
_iterator,
_step,
_loop,
_ret,
_args2 = arguments;
extract(subdirs, targetPath, options);
return;
}
return _regenerator.default.wrap(function _callee$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
options = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
_options$ignore = options.ignore, ignore = _options$ignore === void 0 ? [] : _options$ignore;
ignorePattern = ignore.length ? new RegExp(ignore.join("|"), "i") : null;
_iterator = _createForOfIteratorHelper(srcPaths);
_context2.prev = 4;
_loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
var srcFilename, subdirs;
return _regenerator.default.wrap(function _loop$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
srcFilename = _step.value;
(0, _extractors.default)(srcFilename, targetPath, options);
});
if (!(!_fs.default.existsSync(srcFilename) || ignorePattern && ignorePattern.test(srcFilename))) {
_context.next = 3;
break;
}
return _context.abrupt("return", "continue");
case 3:
if (!_fs.default.statSync(srcFilename).isDirectory()) {
_context.next = 8;
break;
}
subdirs = _fs.default.readdirSync(srcFilename).sort().map(function (filename) {
return _path.default.join(srcFilename, filename);
});
_context.next = 7;
return extract(subdirs, targetPath, options);
case 7:
return _context.abrupt("return", "continue");
case 8:
_context.next = 10;
return (0, _extractors.default)(srcFilename, targetPath, options);
case 10:
case "end":
return _context.stop();
}
}
}, _loop);
});
_iterator.s();
case 7:
if ((_step = _iterator.n()).done) {
_context2.next = 14;
break;
}
return _context2.delegateYield(_loop(), "t0", 9);
case 9:
_ret = _context2.t0;
if (!(_ret === "continue")) {
_context2.next = 12;
break;
}
return _context2.abrupt("continue", 12);
case 12:
_context2.next = 7;
break;
case 14:
_context2.next = 19;
break;
case 16:
_context2.prev = 16;
_context2.t1 = _context2["catch"](4);
_iterator.e(_context2.t1);
case 19:
_context2.prev = 19;
_iterator.f();
return _context2.finish(19);
case 22:
case "end":
return _context2.stop();
}
}
}, _callee, null, [[4, 16, 19, 22]]);
}));
return _extract.apply(this, arguments);
}

@@ -69,0 +176,0 @@

@@ -10,2 +10,6 @@ "use strict";

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _ora = _interopRequireDefault(require("ora"));

@@ -15,39 +19,114 @@

function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
var DEFAULT_EXTRACTORS = [_babel.default];
function extract(filename, targetPath, options) {
var _options$extractors;
function extract(_x, _x2, _x3) {
return _extract.apply(this, arguments);
}
var extractorsToExtract = (_options$extractors = options.extractors) !== null && _options$extractors !== void 0 ? _options$extractors : DEFAULT_EXTRACTORS;
return extractorsToExtract.some(function (e) {
var ext = e;
function _extract() {
_extract = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(filename, targetPath, options) {
var _options$extractors;
if (typeof e === "string") {
// in case of the user using require.resolve in their extractors, we require that module
ext = require(e);
}
var extractorsToExtract, _iterator, _step, e, ext, spinner;
if (ext.default) {
ext = ext.default;
}
return _regenerator.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
extractorsToExtract = (_options$extractors = options.extractors) !== null && _options$extractors !== void 0 ? _options$extractors : DEFAULT_EXTRACTORS;
_iterator = _createForOfIteratorHelper(extractorsToExtract);
_context.prev = 2;
if (!ext.match(filename)) return false;
var spinner;
if (options.verbose) spinner = (0, _ora.default)().start(filename);
_iterator.s();
try {
ext.extract(filename, targetPath, options);
} catch (e) {
if (options.verbose && spinner) {
spinner.fail(e.message);
} else {
console.error("Cannot process file ".concat(e.message));
}
case 4:
if ((_step = _iterator.n()).done) {
_context.next = 26;
break;
}
return true;
}
e = _step.value;
ext = e;
if (options.verbose && spinner) spinner.succeed();
return true;
});
if (typeof e === "string") {
// in case of the user using require.resolve in their extractors, we require that module
ext = require(e);
}
if (ext.default) {
ext = ext.default;
}
if (ext.match(filename)) {
_context.next = 11;
break;
}
return _context.abrupt("continue", 24);
case 11:
spinner = void 0;
if (options.verbose) spinner = (0, _ora.default)().start(filename);
_context.prev = 13;
_context.next = 16;
return ext.extract(filename, targetPath, options);
case 16:
_context.next = 22;
break;
case 18:
_context.prev = 18;
_context.t0 = _context["catch"](13);
if (options.verbose && spinner) {
spinner.fail(_context.t0.message);
} else {
console.error("Cannot process file ".concat(_context.t0.message));
}
return _context.abrupt("return", true);
case 22:
if (options.verbose && spinner) spinner.succeed();
return _context.abrupt("return", true);
case 24:
_context.next = 4;
break;
case 26:
_context.next = 31;
break;
case 28:
_context.prev = 28;
_context.t1 = _context["catch"](2);
_iterator.e(_context.t1);
case 31:
_context.prev = 31;
_iterator.f();
return _context.finish(31);
case 34:
return _context.abrupt("return", false);
case 35:
case "end":
return _context.stop();
}
}
}, _callee, null, [[2, 28, 31, 34], [13, 18]]);
}));
return _extract.apply(this, arguments);
}

@@ -77,7 +77,14 @@ "use strict";

if (message.context) {
item.msgctxt = message.context;
}
if (options.origins !== false) {
if (message.origin && options.lineNumbers === false) {
item.references = message.origin.map(function (msg) {
return msg.slice(0, -1);
}).map(_utils.joinOrigin);
item.references = message.origin.map(function (_ref) {
var _ref2 = (0, _slicedToArray2.default)(_ref, 1),
path = _ref2[0];
return path;
});
} else {

@@ -175,2 +182,3 @@ item.references = message.origin ? message.origin.map(_utils.joinOrigin) : [];

var getTranslatorComments = R.prop("comments");
var getMessageContext = R.prop("msgctxt");
var getOrigins = R.prop("references");

@@ -185,2 +193,3 @@ var getFlags = R.compose(R.map(R.trim), R.keys, R.dissoc("obsolete"), // backward-compatibility, remove in 3.x

comments: R.compose(R.defaultTo([]), getTranslatorComments),
context: R.compose(R.defaultTo(null), getMessageContext),
obsolete: isObsolete,

@@ -187,0 +196,0 @@ origin: R.compose(R.map(_utils.splitOrigin), R.defaultTo([]), getOrigins),

@@ -12,2 +12,4 @@ "use strict";

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _fs = _interopRequireDefault(require("fs"));

@@ -43,7 +45,14 @@

if (message.context) {
item.msgctxt = message.context;
}
if (options.origins !== false) {
if (message.origin && options.lineNumbers === false) {
item.references = message.origin.map(function (msg) {
return msg.slice(0, -1);
}).map(_utils.joinOrigin);
item.references = message.origin.map(function (_ref) {
var _ref2 = (0, _slicedToArray2.default)(_ref, 1),
path = _ref2[0];
return path;
});
} else {

@@ -67,2 +76,3 @@ item.references = message.origin ? message.origin.map(_utils.joinOrigin) : [];

var getTranslatorComments = R.prop("comments");
var getMessageContext = R.prop("msgctxt");
var getOrigins = R.prop("references");

@@ -76,2 +86,3 @@ var getFlags = R.compose(R.map(R.trim), R.keys, R.dissoc("obsolete"), // backward-compatibility, remove in 3.x

comments: R.compose(R.defaultTo([]), getTranslatorComments),
context: R.compose(R.defaultTo(null), getMessageContext),
obsolete: isObsolete,

@@ -78,0 +89,0 @@ origin: R.compose(R.map(_utils.splitOrigin), R.defaultTo([]), getOrigins),

@@ -10,3 +10,3 @@ "use strict";

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

@@ -19,4 +19,8 @@ var _interopRequireWildcard2 = _interopRequireDefault(require("@babel/runtime/helpers/interopRequireWildcard"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _chalk = _interopRequireDefault(require("chalk"));

@@ -42,51 +46,113 @@

function command(config, options) {
// `react-app` babel plugin used by CRA requires either BABEL_ENV or NODE_ENV to be
// set. We're setting it here, because lingui macros are going to use them as well.
if (!process.env.BABEL_ENV && !process.env.NODE_ENV) {
process.env.BABEL_ENV = "development";
} // We need macros to keep imports, so extract-messages plugin know what componets
// to collect. Users usually use both BABEN_ENV and NODE_ENV, so it's probably
// safer to introduce a new env variable. LINGUI_EXTRACT=1 during `lingui extract`
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
process.env.LINGUI_EXTRACT = "1";
options.verbose && console.error("Extracting messages from source files…");
var catalogs = (0, _catalog.getCatalogs)(config);
var catalogStats = {};
catalogs.forEach(function (catalog) {
catalog.make(_objectSpread(_objectSpread({}, options), {}, {
orderBy: config.orderBy,
extractors: config.extractors,
projectType: (0, _detect.detect)()
}));
catalogStats[catalog.path] = catalog.readAll();
});
Object.entries(catalogStats).forEach(function (_ref) {
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
key = _ref2[0],
value = _ref2[1];
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
console.log("Catalog statistics for ".concat(key, ": "));
console.log((0, _stats.printStats)(config, value).toString());
console.log();
});
function command(_x, _x2) {
return _command.apply(this, arguments);
}
if (!options.watch) {
console.error("(use \"".concat(_chalk.default.yellow((0, _help.helpRun)("extract")), "\" to update catalogs with new messages)"));
console.error("(use \"".concat(_chalk.default.yellow((0, _help.helpRun)("compile")), "\" to compile catalogs for production)"));
} // If service key is present in configuration, synchronize with cloud translation platform
function _command() {
_command = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(config, options) {
var catalogs, catalogStats, _iterator, _step, catalog;
return _regenerator.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
// `react-app` babel plugin used by CRA requires either BABEL_ENV or NODE_ENV to be
// set. We're setting it here, because lingui macros are going to use them as well.
if (!process.env.BABEL_ENV && !process.env.NODE_ENV) {
process.env.BABEL_ENV = "development";
} // We need macros to keep imports, so extract-messages plugin know what componets
// to collect. Users usually use both BABEN_ENV and NODE_ENV, so it's probably
// safer to introduce a new env variable. LINGUI_EXTRACT=1 during `lingui extract`
if ((0, _typeof2.default)(config.service) === 'object' && config.service.name && config.service.name.length) {
Promise.resolve("./services/".concat(config.service.name)).then(function (s) {
return (0, _interopRequireWildcard2.default)(require(s));
}).then(function (module) {
return module.default(config, options);
}).catch(function (err) {
return console.error("Can't load service module ".concat(config.service.name), err);
});
}
return true;
process.env.LINGUI_EXTRACT = "1";
options.verbose && console.error("Extracting messages from source files…");
catalogs = (0, _catalog.getCatalogs)(config);
catalogStats = {};
_iterator = _createForOfIteratorHelper(catalogs);
_context2.prev = 6;
_iterator.s();
case 8:
if ((_step = _iterator.n()).done) {
_context2.next = 15;
break;
}
catalog = _step.value;
_context2.next = 12;
return catalog.make(_objectSpread(_objectSpread({}, options), {}, {
orderBy: config.orderBy,
extractors: config.extractors,
projectType: (0, _detect.detect)()
}));
case 12:
catalogStats[catalog.path] = catalog.readAll();
case 13:
_context2.next = 8;
break;
case 15:
_context2.next = 20;
break;
case 17:
_context2.prev = 17;
_context2.t0 = _context2["catch"](6);
_iterator.e(_context2.t0);
case 20:
_context2.prev = 20;
_iterator.f();
return _context2.finish(20);
case 23:
Object.entries(catalogStats).forEach(function (_ref2) {
var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
key = _ref3[0],
value = _ref3[1];
console.log("Catalog statistics for ".concat(key, ": "));
console.log((0, _stats.printStats)(config, value).toString());
console.log();
});
if (!options.watch) {
console.error("(use \"".concat(_chalk.default.yellow((0, _help.helpRun)("extract")), "\" to update catalogs with new messages)"));
console.error("(use \"".concat(_chalk.default.yellow((0, _help.helpRun)("compile")), "\" to compile catalogs for production)"));
} // If service key is present in configuration, synchronize with cloud translation platform
if ((0, _typeof2.default)(config.service) === 'object' && config.service.name && config.service.name.length) {
Promise.resolve("./services/".concat(config.service.name)).then(function (s) {
return (0, _interopRequireWildcard2.default)(require(s));
}).then(function (module) {
return module.default(config, options);
}).catch(function (err) {
return console.error("Can't load service module ".concat(config.service.name), err);
});
}
return _context2.abrupt("return", true);
case 27:
case "end":
return _context2.stop();
}
}
}, _callee2, null, [[6, 17, 20, 23]]);
}));
return _command.apply(this, arguments);
}

@@ -163,7 +229,20 @@

debounceTimer && clearTimeout(debounceTimer);
debounceTimer = setTimeout(function () {
var filePath = (0, _toConsumableArray2.default)(changedPaths);
changedPaths.clear();
extract(filePath);
}, _commander.default.debounce);
debounceTimer = setTimeout( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
var filePath;
return _regenerator.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
filePath = (0, _toConsumableArray2.default)(changedPaths);
changedPaths.clear();
_context.next = 4;
return extract(filePath);
case 4:
case "end":
return _context.stop();
}
}
}, _callee);
})), _commander.default.debounce);
}; // Check if Watch Mode is enabled

@@ -202,9 +281,10 @@

// for ex: lingui extract src/app, this will extract only files included in src/app
var result = extract(_commander.default.args);
if (!result) process.exit(1);
extract(_commander.default.args).then(function (result) {
if (!result) process.exit(1);
});
} else {
var _result = extract();
if (!_result) process.exit(1);
extract().then(function (result) {
if (!result) process.exit(1);
});
}
}
{
"name": "@lingui/cli",
"version": "3.12.1",
"version": "3.13.0",
"description": "CLI for working wit message catalogs",

@@ -42,4 +42,4 @@ "keywords": [

"@babel/types": "^7.11.5",
"@lingui/babel-plugin-extract-messages": "^3.12.1",
"@lingui/conf": "^3.12.1",
"@lingui/babel-plugin-extract-messages": "^3.13.0",
"@lingui/conf": "^3.13.0",
"babel-plugin-macros": "^3.0.1",

@@ -49,3 +49,3 @@ "bcp-47": "^1.0.7",

"chokidar": "3.5.1",
"cli-table": "^0.3.1",
"cli-table": "0.3.6",
"commander": "^6.1.0",

@@ -52,0 +52,0 @@ "date-fns": "^2.16.1",

@@ -61,4 +61,5 @@ "use strict";

var sourceLocale = config.sourceLocale || 'en';
var pseudoLocale = config.pseudoLocale || 'pseudo';
var targetLocales = config.locales.filter(function (value) {
return value != sourceLocale;
return value != sourceLocale && value != pseudoLocale;
});

@@ -65,0 +66,0 @@ var paths = poPathsPerLocale(config);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc