@lingui/cli 3.16.1 → 3.17.1

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.
@@ -3,35 +3,27 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.removeDirectory = removeDirectory;
7
- exports.prettyOrigin = prettyOrigin;
8
- exports.helpMisspelledCommand = helpMisspelledCommand;
9
- exports.writeFileIfChanged = writeFileIfChanged;
10
6
  exports.hasYarn = hasYarn;
7
+ exports.helpMisspelledCommand = helpMisspelledCommand;
8
+ exports.joinOrigin = void 0;
11
9
  exports.makeInstall = makeInstall;
12
- exports.joinOrigin = exports.splitOrigin = void 0;
13
-
10
+ exports.prettyOrigin = prettyOrigin;
11
+ exports.removeDirectory = removeDirectory;
12
+ exports.splitOrigin = void 0;
13
+ exports.writeFileIfChanged = writeFileIfChanged;
14
14
  var _fs = _interopRequireDefault(require("fs"));
15
-
16
15
  var _path = _interopRequireDefault(require("path"));
17
-
18
16
  var _chalk = _interopRequireDefault(require("chalk"));
19
-
20
17
  var _fuzzaldrin = require("fuzzaldrin");
21
-
22
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
19
  function removeDirectory(dir, onlyContent = false) {
25
20
  if (!_fs.default.existsSync(dir)) return;
26
-
27
21
  const list = _fs.default.readdirSync(dir);
28
-
29
22
  for (let i = 0; i < list.length; i++) {
30
23
  const filename = _path.default.join(dir, list[i]);
31
-
32
24
  const stat = _fs.default.statSync(filename);
33
-
34
- if (filename === "." || filename === "..") {// pass these files
25
+ if (filename === "." || filename === "..") {
26
+ // pass these files
35
27
  } else if (stat.isDirectory()) {
36
28
  // rmdir recursively
37
29
  removeDirectory(filename);
@@ -39,12 +31,10 @@ function removeDirectory(dir, onlyContent = false) {
39
31
  _fs.default.unlinkSync(filename);
40
32
  }
41
33
  }
42
-
43
34
  if (!onlyContent) {
44
35
  _fs.default.rmdirSync(dir);
45
36
  }
46
37
  }
47
-
48
38
  function prettyOrigin(origins) {
49
39
  try {
50
40
  return origins.map(origin => origin.join(":")).join(", ");
@@ -52,6 +42,7 @@ function prettyOrigin(origins) {
52
42
  return "";
53
43
  }
54
44
  }
45
+
55
46
  /**
56
47
  * .. js:function:: helpMisspelledCommand(command [, availableCommands = []])
57
48
  * :param: command - command passed to CLI
@@ -60,39 +51,30 @@ function prettyOrigin(origins) {
60
51
  * If unknown commands is passed to CLI, check it agains all available commands
61
52
  * for possible misspelled letter. Output help with suggestions to console.
62
53
  */
63
-
64
-
65
54
  function helpMisspelledCommand(command, availableCommands = []) {
66
- const commandNames = availableCommands.map(command => command.name()); // if no command is supplied, then commander.js shows help automatically
55
+ const commandNames = availableCommands.map(command => command.name());
67
56
 
57
+ // if no command is supplied, then commander.js shows help automatically
68
58
  if (!command || commandNames.includes(command)) {
69
59
  return;
70
60
  }
71
-
72
61
  const suggestions = commandNames.map(name => ({
73
62
  name,
74
63
  score: (0, _fuzzaldrin.score)(name, command.slice(0, name.length))
75
64
  })).filter(nameScore => nameScore.score > 0).slice(0, 3).map(commandScore => _chalk.default.inverse(commandScore.name)).join(", ");
76
65
  console.log(`lingui: command ${command} is not a lingui command. ` + `See 'lingui --help' for the list of available commands.`);
77
-
78
66
  if (suggestions) {
79
67
  console.log();
80
68
  console.log(`Did you mean: ${suggestions}?`);
81
69
  }
82
70
  }
83
-
84
71
  const splitOrigin = origin => origin.split(":");
85
-
86
72
  exports.splitOrigin = splitOrigin;
87
-
88
73
  const joinOrigin = origin => origin.join(":");
89
-
90
74
  exports.joinOrigin = joinOrigin;
91
-
92
75
  function writeFileIfChanged(filename, newContent) {
93
76
  if (_fs.default.existsSync(filename)) {
94
77
  const raw = _fs.default.readFileSync(filename).toString();
95
-
96
78
  if (newContent !== raw) {
97
79
  _fs.default.writeFileSync(filename, newContent);
98
80
  }
@@ -100,11 +82,9 @@ function writeFileIfChanged(filename, newContent) {
100
82
  _fs.default.writeFileSync(filename, newContent);
101
83
  }
102
84
  }
103
-
104
85
  function hasYarn() {
105
86
  return _fs.default.existsSync(_path.default.resolve("yarn.lock"));
106
87
  }
107
-
108
88
  function makeInstall() {
109
89
  const withYarn = hasYarn();
110
90
  return (packageName, dev = false) => withYarn ? `yarn add ${dev ? "--dev " : ""}${packageName}` : `npm install ${dev ? "--save-dev" : "--save"} ${packageName}`;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  var _chalk = _interopRequireDefault(require("chalk"));
4
-
5
4
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
-
7
5
  if (require.main === module) {
8
- const msg = "lingui add-locale command is deprecated. " + `Please set ${_chalk.default.yellow("'locales'")} in configuration. ` + _chalk.default.underline("https://lingui.js.org/ref/conf.html#locales");
9
-
6
+ const msg = "lingui add-locale command is deprecated. " + `Please set ${_chalk.default.yellow("'locales'")} in configuration. ` + _chalk.default.underline("https://lingui.dev/ref/conf#locales");
10
7
  console.error(msg);
11
8
  }
@@ -1,82 +1,67 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.command = command;
3
7
  var _chalk = _interopRequireDefault(require("chalk"));
4
-
5
8
  var _chokidar = _interopRequireDefault(require("chokidar"));
6
-
7
9
  var _fs = _interopRequireDefault(require("fs"));
8
-
9
10
  var R = _interopRequireWildcard(require("ramda"));
10
-
11
11
  var _commander = _interopRequireDefault(require("commander"));
12
-
13
12
  var plurals = _interopRequireWildcard(require("make-plural"));
14
-
15
13
  var _conf = require("@lingui/conf");
16
-
17
14
  var _catalog = require("./api/catalog");
18
-
19
15
  var _compile = require("./api/compile");
20
-
21
16
  var _help = require("./api/help");
22
-
23
17
  var _api = require("./api");
24
-
25
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
26
-
27
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
28
-
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
-
31
21
  const noMessages = R.pipe(R.map(R.isEmpty), R.values, R.all(R.equals(true)));
32
-
33
22
  function command(config, options) {
34
23
  const catalogs = (0, _catalog.getCatalogs)(config);
35
24
 
25
+ // fixme: this is definitely doesn't work
36
26
  if (noMessages(catalogs)) {
37
27
  console.error("Nothing to compile, message catalogs are empty!\n");
38
28
  console.error(`(use "${_chalk.default.yellow((0, _help.helpRun)("extract"))}" to extract messages from source files)`);
39
29
  return false;
40
- } // Check config.compile.merge if catalogs for current locale are to be merged into a single compiled file
41
-
30
+ }
42
31
 
32
+ // Check config.compile.merge if catalogs for current locale are to be merged into a single compiled file
43
33
  const doMerge = !!config.catalogsMergePath;
44
34
  let mergedCatalogs = {};
45
- console.error("Compiling message catalogs…");
46
- config.locales.forEach(locale => {
35
+ console.log("Compiling message catalogs…");
36
+ for (const locale of config.locales) {
47
37
  const [language] = locale.split(/[_-]/);
48
-
38
+ // todo: this validation should be in @lingui/conf
49
39
  if (locale !== config.pseudoLocale && !plurals[language]) {
50
- console.log(_chalk.default.red(`Error: Invalid locale ${_chalk.default.bold(locale)} (missing plural rules)!`));
40
+ console.error(_chalk.default.red(`Error: Invalid locale ${_chalk.default.bold(locale)} (missing plural rules)!`));
51
41
  console.error();
52
42
  }
53
-
54
- catalogs.forEach(catalog => {
43
+ for (const catalog of catalogs) {
55
44
  const messages = catalog.getTranslations(locale, {
56
45
  fallbackLocales: config.fallbackLocales,
57
46
  sourceLocale: config.sourceLocale
58
47
  });
59
-
60
48
  if (!options.allowEmpty) {
61
49
  const missingMsgIds = R.pipe(R.pickBy(R.isNil), R.keys)(messages);
62
-
63
50
  if (missingMsgIds.length > 0) {
64
51
  console.error(_chalk.default.red(`Error: Failed to compile catalog for locale ${_chalk.default.bold(locale)}!`));
65
-
66
52
  if (options.verbose) {
67
53
  console.error(_chalk.default.red("Missing translations:"));
68
- missingMsgIds.forEach(msgId => console.log(msgId));
54
+ missingMsgIds.forEach(msgId => console.error(msgId));
69
55
  } else {
70
56
  console.error(_chalk.default.red(`Missing ${missingMsgIds.length} translation(s)`));
71
57
  }
72
-
73
58
  console.error();
74
- process.exit(1);
59
+ return false;
75
60
  }
76
61
  }
77
-
78
62
  if (doMerge) {
79
- mergedCatalogs = { ...mergedCatalogs,
63
+ mergedCatalogs = {
64
+ ...mergedCatalogs,
80
65
  ...messages
81
66
  };
82
67
  } else {
@@ -88,20 +73,16 @@ function command(config, options) {
88
73
  compilerBabelOptions: config.compilerBabelOptions
89
74
  });
90
75
  const compiledPath = catalog.writeCompiled(locale, compiledCatalog, namespace);
91
-
92
76
  if (options.typescript) {
93
77
  const typescriptPath = compiledPath.replace(/\.ts?$/, "") + ".d.ts";
94
-
95
78
  _fs.default.writeFileSync(typescriptPath, `import { Messages } from '@lingui/core';
96
79
  declare const messages: Messages;
97
80
  export { messages };
98
81
  `);
99
82
  }
100
-
101
83
  options.verbose && console.error(_chalk.default.green(`${locale} ⇒ ${compiledPath}`));
102
84
  }
103
- });
104
-
85
+ }
105
86
  if (doMerge) {
106
87
  const compileCatalog = (0, _catalog.getCatalogForMerge)(config);
107
88
  const namespace = options.namespace || config.compileNamespace;
@@ -114,10 +95,9 @@ function command(config, options) {
114
95
  const compiledPath = compileCatalog.writeCompiled(locale, compiledCatalog, namespace);
115
96
  options.verbose && console.log(_chalk.default.green(`${locale} ⇒ ${compiledPath}`));
116
97
  }
117
- });
98
+ }
118
99
  return true;
119
100
  }
120
-
121
101
  if (require.main === module) {
122
102
  _commander.default.description("Add compile message catalogs and add language data (plurals) to compiled bundle.").option("--config <path>", "Path to the config file").option("--strict", "Disable defaults for missing translations").option("--verbose", "Verbose output").option("--format <format>", "Format of message catalog").option("--typescript", "Create Typescript definition for compiled bundle").option("--namespace <namespace>", "Specify namespace for compiled bundle. Ex: cjs(default) -> module.exports, es -> export, window.test -> window.test").option("--watch", "Enables Watch Mode").option("--debounce <delay>", "Debounces compilation for given amount of milliseconds").on("--help", function () {
123
103
  console.log("\n Examples:\n");
@@ -129,36 +109,32 @@ if (require.main === module) {
129
109
  console.log(" # default messages or message IDs)");
130
110
  console.log(` $ ${(0, _help.helpRun)("compile --strict")}`);
131
111
  }).parse(process.argv);
132
-
133
112
  const config = (0, _conf.getConfig)({
134
113
  configPath: _commander.default.config
135
114
  });
136
-
137
115
  if (_commander.default.format) {
138
- const msg = "--format option is deprecated and will be removed in @lingui/cli@3.0.0." + " Please set format in configuration https://lingui.js.org/ref/conf.html#format";
116
+ const msg = "--format option is deprecated and will be removed in @lingui/cli@3.0.0." + " Please set format in configuration https://lingui.dev/ref/conf#format";
139
117
  console.warn(msg);
140
118
  config.format = _commander.default.format;
141
119
  }
142
-
143
120
  const compile = () => command(config, {
144
121
  verbose: _commander.default.watch || _commander.default.verbose || false,
145
122
  allowEmpty: !_commander.default.strict,
146
123
  typescript: _commander.default.typescript || config.compileNamespace === "ts" || false,
147
124
  namespace: _commander.default.namespace // we want this to be undefined if user does not specify so default can be used
148
-
149
125
  });
150
126
 
151
127
  let debounceTimer;
152
-
153
128
  const dispatchCompile = () => {
154
129
  // Skip debouncing if not enabled
155
- if (!_commander.default.debounce) return compile(); // CLear the previous timer if there is any, and schedule the next
130
+ if (!_commander.default.debounce) return compile();
156
131
 
132
+ // CLear the previous timer if there is any, and schedule the next
157
133
  debounceTimer && clearTimeout(debounceTimer);
158
134
  debounceTimer = setTimeout(() => compile(), _commander.default.debounce);
159
- }; // Check if Watch Mode is enabled
160
-
135
+ };
161
136
 
137
+ // Check if Watch Mode is enabled
162
138
  if (_commander.default.watch) {
163
139
  console.info(_chalk.default.bold("Initializing Watch Mode..."));
164
140
  const catalogs = (0, _catalog.getCatalogs)(config);
@@ -169,24 +145,19 @@ if (require.main === module) {
169
145
  paths.push(`${catalog.path.replace(/{locale}/g, locale).replace(/{name}/g, "*")}${catalogExtension}`);
170
146
  });
171
147
  });
172
-
173
148
  const watcher = _chokidar.default.watch(paths, {
174
149
  persistent: true
175
150
  });
176
-
177
151
  const onReady = () => {
178
152
  console.info(_chalk.default.green.bold("Watcher is ready!"));
179
153
  watcher.on("add", () => dispatchCompile()).on("change", () => dispatchCompile());
180
154
  };
181
-
182
155
  watcher.on("ready", () => onReady());
183
156
  } else {
184
157
  const results = compile();
185
-
186
158
  if (!results) {
187
159
  process.exit(1);
188
160
  }
189
-
190
161
  console.log("Done!");
191
162
  }
192
163
  }
@@ -4,40 +4,33 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = command;
7
-
8
7
  var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
8
  var _commander = _interopRequireDefault(require("commander"));
11
-
12
9
  var _conf = require("@lingui/conf");
13
-
14
10
  var _catalog = require("./api/catalog");
15
-
16
11
  var _detect = require("./api/detect");
17
-
18
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
13
  async function command(config, options) {
21
14
  // `react-app` babel plugin used by CRA requires either BABEL_ENV or NODE_ENV to be
22
15
  // set. We're setting it here, because lingui macros are going to use them as well.
23
16
  if (!process.env.BABEL_ENV && !process.env.NODE_ENV) {
24
17
  process.env.BABEL_ENV = "development";
25
- } // We need macros to keep imports, so extract-messages plugin know what componets
18
+ }
19
+
20
+ // We need macros to keep imports, so extract-messages plugin know what componets
26
21
  // to collect. Users usually use both BABEN_ENV and NODE_ENV, so it's probably
27
22
  // safer to introduce a new env variable. LINGUI_EXTRACT=1 during `lingui extract`
28
-
29
-
30
23
  process.env.LINGUI_EXTRACT = "1";
31
24
  options.verbose && console.error("Extracting messages from source files…");
32
25
  const catalogs = (0, _catalog.getCatalogs)(config);
33
26
  const catalogStats = {};
34
27
  await Promise.all(catalogs.map(async catalog => {
35
- await catalog.makeTemplate({ ...options,
28
+ await catalog.makeTemplate({
29
+ ...options,
36
30
  orderBy: config.orderBy,
37
31
  projectType: (0, _detect.detect)()
38
32
  });
39
33
  const catalogTemplate = catalog.readTemplate();
40
-
41
34
  if (catalogTemplate !== null && catalogTemplate !== undefined) {
42
35
  catalogStats[catalog.templateFile] = Object.keys(catalogTemplate).length;
43
36
  }
@@ -48,10 +41,8 @@ async function command(config, options) {
48
41
  });
49
42
  return true;
50
43
  }
51
-
52
44
  if (require.main === module) {
53
45
  _commander.default.option("--config <path>", "Path to the config file").option("--verbose", "Verbose output").parse(process.argv);
54
-
55
46
  const config = (0, _conf.getConfig)({
56
47
  configPath: _commander.default.config || process.env.LINGUI_CONFIG
57
48
  });
@@ -4,47 +4,35 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = command;
7
-
8
7
  var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
8
  var _chokidar = _interopRequireDefault(require("chokidar"));
11
-
12
9
  var _commander = _interopRequireDefault(require("commander"));
13
-
14
10
  var _conf = require("@lingui/conf");
15
-
16
11
  var _catalog = require("./api/catalog");
17
-
18
12
  var _stats = require("./api/stats");
19
-
20
13
  var _detect = require("./api/detect");
21
-
22
14
  var _help = require("./api/help");
23
-
24
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
27
-
28
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
-
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
30
18
  async function command(config, options) {
31
19
  // `react-app` babel plugin used by CRA requires either BABEL_ENV or NODE_ENV to be
32
20
  // set. We're setting it here, because lingui macros are going to use them as well.
33
21
  if (!process.env.BABEL_ENV && !process.env.NODE_ENV) {
34
22
  process.env.BABEL_ENV = "development";
35
- } // We need macros to keep imports, so extract-messages plugin know what componets
23
+ }
24
+
25
+ // We need macros to keep imports, so extract-messages plugin know what componets
36
26
  // to collect. Users usually use both BABEN_ENV and NODE_ENV, so it's probably
37
27
  // safer to introduce a new env variable. LINGUI_EXTRACT=1 during `lingui extract`
38
-
39
-
40
28
  process.env.LINGUI_EXTRACT = "1";
41
29
  options.verbose && console.error("Extracting messages from source files…");
42
30
  const catalogs = (0, _catalog.getCatalogs)(config);
43
31
  const catalogStats = {};
44
32
  let commandSuccess = true;
45
-
46
33
  for (let catalog of catalogs) {
47
- const catalogSuccess = await catalog.make({ ...options,
34
+ const catalogSuccess = await catalog.make({
35
+ ...options,
48
36
  orderBy: config.orderBy,
49
37
  extractors: config.extractors,
50
38
  projectType: (0, _detect.detect)()
@@ -52,52 +40,44 @@ async function command(config, options) {
52
40
  catalogStats[catalog.path] = catalog.readAll();
53
41
  commandSuccess && (commandSuccess = catalogSuccess);
54
42
  }
55
-
56
43
  Object.entries(catalogStats).forEach(([key, value]) => {
57
44
  console.log(`Catalog statistics for ${key}: `);
58
45
  console.log((0, _stats.printStats)(config, value).toString());
59
46
  console.log();
60
47
  });
61
-
62
48
  if (!options.watch) {
63
49
  console.error(`(use "${_chalk.default.yellow((0, _help.helpRun)("extract"))}" to update catalogs with new messages)`);
64
50
  console.error(`(use "${_chalk.default.yellow((0, _help.helpRun)("compile"))}" to compile catalogs for production)`);
65
- } // If service key is present in configuration, synchronize with cloud translation platform
66
-
51
+ }
67
52
 
68
- if (typeof config.service === 'object' && config.service.name && config.service.name.length) {
53
+ // If service key is present in configuration, synchronize with cloud translation platform
54
+ if (typeof config.service === "object" && config.service.name && config.service.name.length) {
69
55
  const moduleName = config.service.name.charAt(0).toLowerCase() + config.service.name.slice(1);
70
- Promise.resolve(`./services/${moduleName}`).then(s => _interopRequireWildcard(require(s))).then(module => module.default(config, options)).catch(err => console.error(`Can't load service module ${moduleName}`, err));
56
+ (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`./services/${moduleName}`).then(module => module.default(config, options)).catch(err => console.error(`Can't load service module ${moduleName}`, err));
71
57
  }
72
-
73
58
  return commandSuccess;
74
59
  }
75
-
76
60
  if (require.main === module) {
77
- _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
61
+ _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")
62
+ // Obsolete options
78
63
  .option("--babelOptions", "Babel options passed to transform/extract plugins").option("--format <format>", "Format of message catalogs").parse(process.argv);
79
-
80
64
  const config = (0, _conf.getConfig)({
81
65
  configPath: _commander.default.config || process.env.LINGUI_CONFIG
82
66
  });
83
67
  let hasErrors = false;
84
-
85
68
  if (_commander.default.format) {
86
69
  hasErrors = true;
87
- const msg = "--format option is deprecated." + " Please set format in configuration https://lingui.js.org/ref/conf.html#format";
70
+ const msg = "--format option is deprecated." + " Please set format in configuration https://lingui.dev/ref/conf#format";
88
71
  console.error(msg);
89
72
  console.error();
90
73
  }
91
-
92
74
  if (_commander.default.babelOptions) {
93
75
  hasErrors = true;
94
- const msg = "--babelOptions option is deprecated." + " Please set extractBabelOptions in configuration https://lingui.js.org/ref/conf.html#extractBabelOptions";
76
+ const msg = "--babelOptions option is deprecated." + " Please set extractBabelOptions in configuration https://lingui.dev/ref/conf#extractbabeloptions";
95
77
  console.error(msg);
96
78
  console.error();
97
79
  }
98
-
99
80
  const prevFormat = _commander.default.convertFrom;
100
-
101
81
  if (prevFormat && config.format === prevFormat) {
102
82
  hasErrors = true;
103
83
  console.error("Trying to migrate message catalog to the same format");
@@ -107,15 +87,12 @@ if (require.main === module) {
107
87
  console.log(_chalk.default.yellow((0, _help.helpRun)(`extract --convert-from lingui`)));
108
88
  process.exit(1);
109
89
  }
110
-
111
90
  if (_commander.default.locale && !config.locales.includes(_commander.default.locale)) {
112
91
  hasErrors = true;
113
92
  console.error(`Locale ${_chalk.default.bold(_commander.default.locale)} does not exist.`);
114
93
  console.error();
115
94
  }
116
-
117
95
  if (hasErrors) process.exit(1);
118
-
119
96
  const extract = filePath => {
120
97
  return command(config, {
121
98
  verbose: _commander.default.watch || _commander.default.verbose || false,
@@ -124,28 +101,27 @@ if (require.main === module) {
124
101
  locale: _commander.default.locale,
125
102
  configPath: _commander.default.config || process.env.LINGUI_CONFIG,
126
103
  watch: _commander.default.watch || false,
127
- files: filePath?.length ? filePath : undefined,
104
+ files: filePath !== null && filePath !== void 0 && filePath.length ? filePath : undefined,
128
105
  prevFormat
129
106
  });
130
107
  };
131
-
132
108
  const changedPaths = new Set();
133
109
  let debounceTimer;
134
-
135
110
  const dispatchExtract = filePath => {
136
111
  // Skip debouncing if not enabled
137
112
  if (!_commander.default.debounce) return extract(filePath);
138
- filePath?.forEach(path => changedPaths.add(path)); // CLear the previous timer if there is any, and schedule the next
113
+ filePath === null || filePath === void 0 ? void 0 : filePath.forEach(path => changedPaths.add(path));
139
114
 
115
+ // CLear the previous timer if there is any, and schedule the next
140
116
  debounceTimer && clearTimeout(debounceTimer);
141
117
  debounceTimer = setTimeout(async () => {
142
118
  const filePath = [...changedPaths];
143
119
  changedPaths.clear();
144
120
  await extract(filePath);
145
121
  }, _commander.default.debounce);
146
- }; // Check if Watch Mode is enabled
147
-
122
+ };
148
123
 
124
+ // Check if Watch Mode is enabled
149
125
  if (_commander.default.watch) {
150
126
  console.info(_chalk.default.bold("Initializing Watch Mode..."));
151
127
  const catalogs = (0, _catalog.getCatalogs)(config);
@@ -155,17 +131,14 @@ if (require.main === module) {
155
131
  paths.push(...catalog.include);
156
132
  ignored.push(...catalog.exclude);
157
133
  });
158
-
159
134
  const watcher = _chokidar.default.watch(paths, {
160
135
  ignored: ["/(^|[/\\])../", ...ignored],
161
136
  persistent: true
162
137
  });
163
-
164
138
  const onReady = () => {
165
139
  console.info(_chalk.default.green.bold("Watcher is ready!"));
166
140
  watcher.on("add", path => dispatchExtract([path])).on("change", path => dispatchExtract([path]));
167
141
  };
168
-
169
142
  watcher.on("ready", () => onReady());
170
143
  } else if (_commander.default.args) {
171
144
  // this behaviour occurs when we extract files by his name
package/build/lingui.js CHANGED
@@ -2,16 +2,12 @@
2
2
  "use strict";
3
3
 
4
4
  var _utils = require("./api/utils");
5
-
6
5
  const program = require("commander");
7
-
8
6
  let version;
9
-
10
7
  try {
11
8
  version = require("./package.json").version;
12
9
  } catch (e) {
13
10
  version = "dev";
14
11
  }
15
-
16
12
  program.version(version).command("add-locale", "Deprecated, run it for instructions").command("extract [files...]", "Extracts messages from source files").command("extract-template", "Extracts messages from source files to a .pot template").command("compile", "Compile message catalogs").parse(process.argv);
17
13
  (0, _utils.helpMisspelledCommand)(process.argv[2], program.commands);