@lingui/cli 3.15.0 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +482 -0
  2. package/build/LICENSE +21 -0
  3. package/build/api/catalog.js +582 -0
  4. package/build/api/compile.js +89 -0
  5. package/{api → build/api}/detect.js +23 -9
  6. package/build/api/extract.js +78 -0
  7. package/build/api/extractors/babel.js +51 -0
  8. package/build/api/extractors/index.js +51 -0
  9. package/build/api/extractors/typescript.js +71 -0
  10. package/build/api/formats/csv.js +65 -0
  11. package/{api → build/api}/formats/index.js +8 -5
  12. package/build/api/formats/lingui.js +67 -0
  13. package/build/api/formats/minimal.js +63 -0
  14. package/build/api/formats/po-gettext.js +296 -0
  15. package/build/api/formats/po.js +122 -0
  16. package/{api → build/api}/help.js +6 -18
  17. package/{api → build/api}/index.js +7 -7
  18. package/build/api/locales.js +45 -0
  19. package/{api → build/api}/pseudoLocalize.js +13 -13
  20. package/build/api/stats.js +46 -0
  21. package/{api → build/api}/utils.js +21 -40
  22. package/build/lingui-add-locale.js +11 -0
  23. package/build/lingui-compile.js +192 -0
  24. package/build/lingui-extract-template.js +64 -0
  25. package/build/lingui-extract.js +181 -0
  26. package/{lingui.js → build/lingui.js} +2 -2
  27. package/{services → build/services}/translationIO.js +78 -94
  28. package/build/tests.js +78 -0
  29. package/package.json +18 -12
  30. package/api/catalog.js +0 -778
  31. package/api/compile.js +0 -172
  32. package/api/extract.js +0 -192
  33. package/api/extractors/babel.js +0 -61
  34. package/api/extractors/index.js +0 -130
  35. package/api/extractors/typescript.js +0 -77
  36. package/api/formats/csv.js +0 -71
  37. package/api/formats/lingui.js +0 -64
  38. package/api/formats/minimal.js +0 -63
  39. package/api/formats/po-gettext.js +0 -331
  40. package/api/formats/po.js +0 -130
  41. package/api/locales.js +0 -43
  42. package/api/stats.js +0 -51
  43. package/lingui-add-locale.js +0 -11
  44. package/lingui-compile.js +0 -198
  45. package/lingui-extract-template.js +0 -123
  46. package/lingui-extract.js +0 -286
package/lingui-extract.js DELETED
@@ -1,286 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = command;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _interopRequireWildcard2 = _interopRequireDefault(require("@babel/runtime/helpers/interopRequireWildcard"));
13
-
14
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
15
-
16
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
-
18
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
19
-
20
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
21
-
22
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
23
-
24
- var _chalk = _interopRequireDefault(require("chalk"));
25
-
26
- var _chokidar = _interopRequireDefault(require("chokidar"));
27
-
28
- var _commander = _interopRequireDefault(require("commander"));
29
-
30
- var _conf = require("@lingui/conf");
31
-
32
- var _catalog = require("./api/catalog");
33
-
34
- var _stats = require("./api/stats");
35
-
36
- var _detect = require("./api/detect");
37
-
38
- var _help = require("./api/help");
39
-
40
- 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; }
41
-
42
- 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; }
43
-
44
- 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; } } }; }
45
-
46
- 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); }
47
-
48
- 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; }
49
-
50
- function command(_x, _x2) {
51
- return _command.apply(this, arguments);
52
- }
53
-
54
- function _command() {
55
- _command = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(config, options) {
56
- var catalogs, catalogStats, _iterator, _step, catalog, moduleName;
57
-
58
- return _regenerator.default.wrap(function _callee2$(_context2) {
59
- while (1) {
60
- switch (_context2.prev = _context2.next) {
61
- case 0:
62
- // `react-app` babel plugin used by CRA requires either BABEL_ENV or NODE_ENV to be
63
- // set. We're setting it here, because lingui macros are going to use them as well.
64
- if (!process.env.BABEL_ENV && !process.env.NODE_ENV) {
65
- process.env.BABEL_ENV = "development";
66
- } // We need macros to keep imports, so extract-messages plugin know what componets
67
- // to collect. Users usually use both BABEN_ENV and NODE_ENV, so it's probably
68
- // safer to introduce a new env variable. LINGUI_EXTRACT=1 during `lingui extract`
69
-
70
-
71
- process.env.LINGUI_EXTRACT = "1";
72
- options.verbose && console.error("Extracting messages from source files…");
73
- catalogs = (0, _catalog.getCatalogs)(config);
74
- catalogStats = {};
75
- _iterator = _createForOfIteratorHelper(catalogs);
76
- _context2.prev = 6;
77
-
78
- _iterator.s();
79
-
80
- case 8:
81
- if ((_step = _iterator.n()).done) {
82
- _context2.next = 15;
83
- break;
84
- }
85
-
86
- catalog = _step.value;
87
- _context2.next = 12;
88
- return catalog.make(_objectSpread(_objectSpread({}, options), {}, {
89
- orderBy: config.orderBy,
90
- extractors: config.extractors,
91
- projectType: (0, _detect.detect)()
92
- }));
93
-
94
- case 12:
95
- catalogStats[catalog.path] = catalog.readAll();
96
-
97
- case 13:
98
- _context2.next = 8;
99
- break;
100
-
101
- case 15:
102
- _context2.next = 20;
103
- break;
104
-
105
- case 17:
106
- _context2.prev = 17;
107
- _context2.t0 = _context2["catch"](6);
108
-
109
- _iterator.e(_context2.t0);
110
-
111
- case 20:
112
- _context2.prev = 20;
113
-
114
- _iterator.f();
115
-
116
- return _context2.finish(20);
117
-
118
- case 23:
119
- Object.entries(catalogStats).forEach(function (_ref2) {
120
- var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
121
- key = _ref3[0],
122
- value = _ref3[1];
123
-
124
- console.log("Catalog statistics for ".concat(key, ": "));
125
- console.log((0, _stats.printStats)(config, value).toString());
126
- console.log();
127
- });
128
-
129
- if (!options.watch) {
130
- console.error("(use \"".concat(_chalk.default.yellow((0, _help.helpRun)("extract")), "\" to update catalogs with new messages)"));
131
- console.error("(use \"".concat(_chalk.default.yellow((0, _help.helpRun)("compile")), "\" to compile catalogs for production)"));
132
- } // If service key is present in configuration, synchronize with cloud translation platform
133
-
134
-
135
- if ((0, _typeof2.default)(config.service) === 'object' && config.service.name && config.service.name.length) {
136
- moduleName = config.service.name.charAt(0).toLowerCase() + config.service.name.slice(1);
137
- Promise.resolve("./services/".concat(moduleName)).then(function (s) {
138
- return (0, _interopRequireWildcard2.default)(require(s));
139
- }).then(function (module) {
140
- return module.default(config, options);
141
- }).catch(function (err) {
142
- return console.error("Can't load service module ".concat(moduleName), err);
143
- });
144
- }
145
-
146
- return _context2.abrupt("return", true);
147
-
148
- case 27:
149
- case "end":
150
- return _context2.stop();
151
- }
152
- }
153
- }, _callee2, null, [[6, 17, 20, 23]]);
154
- }));
155
- return _command.apply(this, arguments);
156
- }
157
-
158
- if (require.main === module) {
159
- _commander.default.option("--config <path>", "Path to the config file").option("--locale <locale>", "Only extract the specified locale").option("--overwrite", "Overwrite translations for source locale").option("--clean", "Remove obsolete translations").option("--debounce <delay>", "Debounces extraction for given amount of milliseconds").option("--verbose", "Verbose output").option("--convert-from <format>", "Convert from previous format of message catalogs").option("--watch", "Enables Watch Mode") // Obsolete options
160
- .option("--babelOptions", "Babel options passed to transform/extract plugins").option("--format <format>", "Format of message catalogs").parse(process.argv);
161
-
162
- var config = (0, _conf.getConfig)({
163
- configPath: _commander.default.config || process.env.LINGUI_CONFIG
164
- });
165
- var hasErrors = false;
166
-
167
- if (_commander.default.format) {
168
- hasErrors = true;
169
- var msg = "--format option is deprecated." + " Please set format in configuration https://lingui.js.org/ref/conf.html#format";
170
- console.error(msg);
171
- console.error();
172
- }
173
-
174
- if (_commander.default.babelOptions) {
175
- hasErrors = true;
176
-
177
- var _msg = "--babelOptions option is deprecated." + " Please set extractBabelOptions in configuration https://lingui.js.org/ref/conf.html#extractBabelOptions";
178
-
179
- console.error(_msg);
180
- console.error();
181
- }
182
-
183
- var prevFormat = _commander.default.convertFrom;
184
-
185
- if (prevFormat && config.format === prevFormat) {
186
- hasErrors = true;
187
- console.error("Trying to migrate message catalog to the same format");
188
- console.error("Set ".concat(_chalk.default.bold("new"), " format in LinguiJS configuration\n") + " and ".concat(_chalk.default.bold("previous"), " format using --convert-from option."));
189
- console.log();
190
- console.log("Example: Convert from lingui format to minimal");
191
- console.log(_chalk.default.yellow((0, _help.helpRun)("extract --convert-from lingui")));
192
- process.exit(1);
193
- }
194
-
195
- if (_commander.default.locale && !config.locales.includes(_commander.default.locale)) {
196
- hasErrors = true;
197
- console.error("Locale ".concat(_chalk.default.bold(_commander.default.locale), " does not exist."));
198
- console.error();
199
- }
200
-
201
- if (hasErrors) process.exit(1);
202
-
203
- var extract = function extract(filePath) {
204
- return command(config, {
205
- verbose: _commander.default.watch || _commander.default.verbose || false,
206
- clean: _commander.default.watch ? false : _commander.default.clean || false,
207
- overwrite: _commander.default.watch || _commander.default.overwrite || false,
208
- locale: _commander.default.locale,
209
- configPath: _commander.default.config || process.env.LINGUI_CONFIG,
210
- watch: _commander.default.watch || false,
211
- files: (filePath === null || filePath === void 0 ? void 0 : filePath.length) ? filePath : undefined,
212
- prevFormat: prevFormat
213
- });
214
- };
215
-
216
- var changedPaths = new Set();
217
- var debounceTimer;
218
-
219
- var dispatchExtract = function dispatchExtract(filePath) {
220
- // Skip debouncing if not enabled
221
- if (!_commander.default.debounce) return extract(filePath);
222
- filePath === null || filePath === void 0 ? void 0 : filePath.forEach(function (path) {
223
- return changedPaths.add(path);
224
- }); // CLear the previous timer if there is any, and schedule the next
225
-
226
- debounceTimer && clearTimeout(debounceTimer);
227
- debounceTimer = setTimeout( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
228
- var filePath;
229
- return _regenerator.default.wrap(function _callee$(_context) {
230
- while (1) {
231
- switch (_context.prev = _context.next) {
232
- case 0:
233
- filePath = (0, _toConsumableArray2.default)(changedPaths);
234
- changedPaths.clear();
235
- _context.next = 4;
236
- return extract(filePath);
237
-
238
- case 4:
239
- case "end":
240
- return _context.stop();
241
- }
242
- }
243
- }, _callee);
244
- })), _commander.default.debounce);
245
- }; // Check if Watch Mode is enabled
246
-
247
-
248
- if (_commander.default.watch) {
249
- console.info(_chalk.default.bold("Initializing Watch Mode..."));
250
- var catalogs = (0, _catalog.getCatalogs)(config);
251
- var paths = [];
252
- var ignored = [];
253
- catalogs.forEach(function (catalog) {
254
- paths.push.apply(paths, (0, _toConsumableArray2.default)(catalog.include));
255
- ignored.push.apply(ignored, (0, _toConsumableArray2.default)(catalog.exclude));
256
- });
257
-
258
- var watcher = _chokidar.default.watch(paths, {
259
- ignored: ["/(^|[/\\])../"].concat(ignored),
260
- persistent: true
261
- });
262
-
263
- var onReady = function onReady() {
264
- console.info(_chalk.default.green.bold("Watcher is ready!"));
265
- watcher.on("add", function (path) {
266
- return dispatchExtract([path]);
267
- }).on("change", function (path) {
268
- return dispatchExtract([path]);
269
- });
270
- };
271
-
272
- watcher.on("ready", function () {
273
- return onReady();
274
- });
275
- } else if (_commander.default.args) {
276
- // this behaviour occurs when we extract files by his name
277
- // for ex: lingui extract src/app, this will extract only files included in src/app
278
- extract(_commander.default.args).then(function (result) {
279
- if (!result) process.exit(1);
280
- });
281
- } else {
282
- extract().then(function (result) {
283
- if (!result) process.exit(1);
284
- });
285
- }
286
- }