@lingui/cli 3.17.2 → 4.0.0-next.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.
@@ -6,39 +6,35 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = command;
7
7
  var _chalk = _interopRequireDefault(require("chalk"));
8
8
  var _chokidar = _interopRequireDefault(require("chokidar"));
9
- var _commander = _interopRequireDefault(require("commander"));
9
+ var _commander = require("commander");
10
+ var _path = _interopRequireDefault(require("path"));
10
11
  var _conf = require("@lingui/conf");
11
- var _catalog = require("./api/catalog");
12
+ var _api = require("./api");
12
13
  var _stats = require("./api/stats");
13
- var _detect = require("./api/detect");
14
14
  var _help = require("./api/help");
15
+ var _ora = _interopRequireDefault(require("ora"));
16
+ var _utils = require("./api/utils");
15
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
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); }
17
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; }
18
20
  async function command(config, options) {
19
- // `react-app` babel plugin used by CRA requires either BABEL_ENV or NODE_ENV to be
20
- // set. We're setting it here, because lingui macros are going to use them as well.
21
- if (!process.env.BABEL_ENV && !process.env.NODE_ENV) {
22
- process.env.BABEL_ENV = "development";
23
- }
24
-
25
- // We need macros to keep imports, so extract-messages plugin know what componets
26
- // to collect. Users usually use both BABEN_ENV and NODE_ENV, so it's probably
27
- // safer to introduce a new env variable. LINGUI_EXTRACT=1 during `lingui extract`
28
- process.env.LINGUI_EXTRACT = "1";
29
- options.verbose && console.error("Extracting messages from source files…");
30
- const catalogs = (0, _catalog.getCatalogs)(config);
21
+ options.verbose && console.log("Extracting messages from source files…");
22
+ const catalogs = (0, _api.getCatalogs)(config);
31
23
  const catalogStats = {};
32
24
  let commandSuccess = true;
25
+ const spinner = (0, _ora.default)().start();
33
26
  for (let catalog of catalogs) {
34
- const catalogSuccess = await catalog.make({
27
+ const result = await catalog.make({
35
28
  ...options,
36
- orderBy: config.orderBy,
37
- extractors: config.extractors,
38
- projectType: (0, _detect.detect)()
29
+ orderBy: config.orderBy
39
30
  });
40
- catalogStats[catalog.path] = catalog.readAll();
41
- commandSuccess && (commandSuccess = catalogSuccess);
31
+ catalogStats[(0, _utils.normalizeSlashes)(_path.default.relative(config.rootDir, catalog.path))] = result || {};
32
+ commandSuccess && (commandSuccess = Boolean(result));
33
+ }
34
+ if (commandSuccess) {
35
+ spinner.succeed();
36
+ } else {
37
+ spinner.fail();
42
38
  }
43
39
  Object.entries(catalogStats).forEach(([key, value]) => {
44
40
  console.log(`Catalog statistics for ${key}: `);
@@ -46,8 +42,8 @@ async function command(config, options) {
46
42
  console.log();
47
43
  });
48
44
  if (!options.watch) {
49
- console.error(`(use "${_chalk.default.yellow((0, _help.helpRun)("extract"))}" to update catalogs with new messages)`);
50
- console.error(`(use "${_chalk.default.yellow((0, _help.helpRun)("compile"))}" to compile catalogs for production)`);
45
+ console.log(`(use "${_chalk.default.yellow((0, _help.helpRun)("extract"))}" to update catalogs with new messages)`);
46
+ console.log(`(use "${_chalk.default.yellow((0, _help.helpRun)("compile"))}" to compile catalogs for production)`);
51
47
  }
52
48
 
53
49
  // If service key is present in configuration, synchronize with cloud translation platform
@@ -58,26 +54,13 @@ async function command(config, options) {
58
54
  return commandSuccess;
59
55
  }
60
56
  if (require.main === module) {
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
63
- .option("--babelOptions", "Babel options passed to transform/extract plugins").option("--format <format>", "Format of message catalogs").parse(process.argv);
57
+ _commander.program.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").parse(process.argv);
58
+ const options = _commander.program.opts();
64
59
  const config = (0, _conf.getConfig)({
65
- configPath: _commander.default.config || process.env.LINGUI_CONFIG
60
+ configPath: options.config
66
61
  });
67
62
  let hasErrors = false;
68
- if (_commander.default.format) {
69
- hasErrors = true;
70
- const msg = "--format option is deprecated." + " Please set format in configuration https://lingui.dev/ref/conf#format";
71
- console.error(msg);
72
- console.error();
73
- }
74
- if (_commander.default.babelOptions) {
75
- hasErrors = true;
76
- const msg = "--babelOptions option is deprecated." + " Please set extractBabelOptions in configuration https://lingui.dev/ref/conf#extractbabeloptions";
77
- console.error(msg);
78
- console.error();
79
- }
80
- const prevFormat = _commander.default.convertFrom;
63
+ const prevFormat = options.convertFrom;
81
64
  if (prevFormat && config.format === prevFormat) {
82
65
  hasErrors = true;
83
66
  console.error("Trying to migrate message catalog to the same format");
@@ -87,20 +70,19 @@ if (require.main === module) {
87
70
  console.log(_chalk.default.yellow((0, _help.helpRun)(`extract --convert-from lingui`)));
88
71
  process.exit(1);
89
72
  }
90
- if (_commander.default.locale && !config.locales.includes(_commander.default.locale)) {
73
+ if (options.locale && !config.locales.includes(options.locale)) {
91
74
  hasErrors = true;
92
- console.error(`Locale ${_chalk.default.bold(_commander.default.locale)} does not exist.`);
75
+ console.error(`Locale ${_chalk.default.bold(options.locale)} does not exist.`);
93
76
  console.error();
94
77
  }
95
78
  if (hasErrors) process.exit(1);
96
79
  const extract = filePath => {
97
80
  return command(config, {
98
- verbose: _commander.default.watch || _commander.default.verbose || false,
99
- clean: _commander.default.watch ? false : _commander.default.clean || false,
100
- overwrite: _commander.default.watch || _commander.default.overwrite || false,
101
- locale: _commander.default.locale,
102
- configPath: _commander.default.config || process.env.LINGUI_CONFIG,
103
- watch: _commander.default.watch || false,
81
+ verbose: options.watch || options.verbose || false,
82
+ clean: options.watch ? false : options.clean || false,
83
+ overwrite: options.watch || options.overwrite || false,
84
+ locale: options.locale,
85
+ watch: options.watch || false,
104
86
  files: filePath !== null && filePath !== void 0 && filePath.length ? filePath : undefined,
105
87
  prevFormat
106
88
  });
@@ -111,7 +93,7 @@ if (require.main === module) {
111
93
  const dispatchExtract = filePath => {
112
94
  // Skip debouncing if not enabled but still chain them so no racing issue
113
95
  // on deleting the tmp folder.
114
- if (!_commander.default.debounce) {
96
+ if (!options.debounce) {
115
97
  previousExtract = previousExtract.then(() => extract(filePath));
116
98
  return previousExtract;
117
99
  }
@@ -123,13 +105,13 @@ if (require.main === module) {
123
105
  const filePath = [...changedPaths];
124
106
  changedPaths.clear();
125
107
  await extract(filePath);
126
- }, _commander.default.debounce);
108
+ }, options.debounce);
127
109
  };
128
110
 
129
111
  // Check if Watch Mode is enabled
130
- if (_commander.default.watch) {
112
+ if (options.watch) {
131
113
  console.info(_chalk.default.bold("Initializing Watch Mode..."));
132
- const catalogs = (0, _catalog.getCatalogs)(config);
114
+ const catalogs = (0, _api.getCatalogs)(config);
133
115
  let paths = [];
134
116
  let ignored = [];
135
117
  catalogs.forEach(catalog => {
@@ -145,10 +127,10 @@ if (require.main === module) {
145
127
  watcher.on("add", path => dispatchExtract([path])).on("change", path => dispatchExtract([path]));
146
128
  };
147
129
  watcher.on("ready", () => onReady());
148
- } else if (_commander.default.args) {
130
+ } else if (_commander.program.args) {
149
131
  // this behaviour occurs when we extract files by his name
150
132
  // for ex: lingui extract src/app, this will extract only files included in src/app
151
- extract(_commander.default.args).then(result => {
133
+ extract(_commander.program.args).then(result => {
152
134
  if (!result) process.exit(1);
153
135
  });
154
136
  } else {
package/build/lingui.js CHANGED
@@ -1,9 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
 
4
- var _utils = require("./api/utils");
5
- var _commander = _interopRequireDefault(require("commander"));
4
+ var _commander = require("commander");
6
5
  var _package = require("../package.json");
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
- _commander.default.version(_package.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);
9
- (0, _utils.helpMisspelledCommand)(process.argv[2], _commander.default.commands);
6
+ _commander.program.version(_package.version).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);
@@ -19,6 +19,11 @@ const getCreateHeaders = language => ({
19
19
  "X-Generator": "@lingui/cli",
20
20
  Language: language
21
21
  });
22
+ const getTargetLocales = config => {
23
+ const sourceLocale = config.sourceLocale || "en";
24
+ const pseudoLocale = config.pseudoLocale || "pseudo";
25
+ return config.locales.filter(value => value != sourceLocale && value != pseudoLocale);
26
+ };
22
27
 
23
28
  // Main sync method, call "Init" or "Sync" depending on the project context
24
29
  function syncProcess(config, options) {
@@ -45,8 +50,7 @@ function syncProcess(config, options) {
45
50
  // Cf. https://translation.io/docs/create-library#initialization
46
51
  function init(config, options, successCallback, failCallback) {
47
52
  const sourceLocale = config.sourceLocale || "en";
48
- const pseudoLocale = config.pseudoLocale || "pseudo";
49
- const targetLocales = config.locales.filter(value => value != sourceLocale && value != pseudoLocale);
53
+ const targetLocales = getTargetLocales(config);
50
54
  const paths = poPathsPerLocale(config);
51
55
  let segments = {};
52
56
  targetLocales.forEach(targetLocale => {
@@ -98,7 +102,7 @@ function init(config, options, successCallback, failCallback) {
98
102
  // Cf. https://translation.io/docs/create-library#synchronization
99
103
  function sync(config, options, successCallback, failCallback) {
100
104
  const sourceLocale = config.sourceLocale || "en";
101
- const targetLocales = config.locales.filter(value => value != sourceLocale);
105
+ const targetLocales = getTargetLocales(config);
102
106
  const paths = poPathsPerLocale(config);
103
107
  let segments = [];
104
108
 
package/build/tests.js CHANGED
@@ -4,19 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.copyFixture = copyFixture;
7
- exports.makeCatalog = exports.defaultMergeOptions = exports.defaultMakeTemplateOptions = exports.defaultMakeOptions = void 0;
7
+ exports.defaultMergeOptions = exports.defaultMakeTemplateOptions = exports.defaultMakeOptions = void 0;
8
+ exports.listingToHumanReadable = listingToHumanReadable;
9
+ exports.makeCatalog = void 0;
8
10
  exports.makeNextMessage = makeNextMessage;
9
11
  exports.makePrevMessage = makePrevMessage;
12
+ exports.normalizeLineEndings = void 0;
13
+ exports.readFsToJson = readFsToJson;
10
14
  var _os = _interopRequireDefault(require("os"));
11
- var _fsExtra = _interopRequireDefault(require("fs-extra"));
12
15
  var _path = _interopRequireDefault(require("path"));
13
- var _jestMocks = require("@lingui/jest-mocks");
16
+ var _fs = _interopRequireDefault(require("fs"));
14
17
  var _catalog = require("./api/catalog");
18
+ var _conf = require("@lingui/conf");
15
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
- function copyFixture(fixtureDir) {
17
- const tmpDir = _fsExtra.default.mkdtempSync(_path.default.join(_os.default.tmpdir(), `lingui-test-${process.pid}`));
18
- if (_fsExtra.default.existsSync(fixtureDir)) {
19
- _fsExtra.default.copySync(fixtureDir, tmpDir);
20
+ async function copyFixture(fixtureDir) {
21
+ const tmpDir = await _fs.default.promises.mkdtemp(_path.default.join(_os.default.tmpdir(), `lingui-test-${process.pid}`));
22
+ try {
23
+ await _fs.default.promises.cp(fixtureDir, tmpDir, {
24
+ recursive: true
25
+ });
26
+ } catch (err) {
27
+ if (err.code != "ENOENT") {
28
+ throw err;
29
+ }
20
30
  }
21
31
  return tmpDir;
22
32
  }
@@ -26,27 +36,32 @@ const defaultMakeOptions = {
26
36
  overwrite: false,
27
37
  locale: null,
28
38
  prevFormat: null,
29
- configPath: null,
30
39
  orderBy: "messageId"
31
40
  };
32
41
  exports.defaultMakeOptions = defaultMakeOptions;
33
42
  const defaultMakeTemplateOptions = {
34
43
  verbose: false,
35
- configPath: null,
36
44
  orderBy: "messageId"
37
45
  };
38
46
  exports.defaultMakeTemplateOptions = defaultMakeTemplateOptions;
39
47
  const defaultMergeOptions = {
40
48
  overwrite: false
41
49
  };
50
+
51
+ // on windows line endings are different,
52
+ // so direct comparison to snapshot would file if not normalized
42
53
  exports.defaultMergeOptions = defaultMergeOptions;
54
+ const normalizeLineEndings = str => str.replace(/\r?\n/g, "\r\n");
55
+ exports.normalizeLineEndings = normalizeLineEndings;
43
56
  const makeCatalog = (config = {}) => {
44
57
  return new _catalog.Catalog({
45
58
  name: "messages",
46
59
  path: "{locale}/messages",
47
60
  include: [],
48
61
  exclude: []
49
- }, (0, _jestMocks.mockConfig)(config));
62
+ }, (0, _conf.makeConfig)(config, {
63
+ skipValidation: true
64
+ }));
50
65
  };
51
66
  exports.makeCatalog = makeCatalog;
52
67
  function makePrevMessage(message = {}) {
@@ -61,4 +76,34 @@ function makeNextMessage(message = {}) {
61
76
  obsolete: false,
62
77
  ...message
63
78
  };
79
+ }
80
+ function listingToHumanReadable(listing) {
81
+ const output = [];
82
+ Object.entries(listing).forEach(([filename, value]) => {
83
+ if (typeof value === "string") {
84
+ output.push("#######################");
85
+ output.push(`Filename: ${filename}`);
86
+ output.push("#######################");
87
+ output.push("");
88
+ output.push(normalizeLineEndings(value));
89
+ output.push("");
90
+ } else {
91
+ output.push(...listingToHumanReadable(value));
92
+ }
93
+ });
94
+ return output.join("\n");
95
+ }
96
+ function readFsToJson(directory, filter) {
97
+ const out = {};
98
+ _fs.default.readdirSync(directory).map(filename => {
99
+ const filepath = _path.default.join(directory, filename);
100
+ if (_fs.default.lstatSync(filepath).isDirectory()) {
101
+ out[filename] = readFsToJson(filepath);
102
+ return out;
103
+ }
104
+ if (!filter || filter(filename)) {
105
+ out[filename] = _fs.default.readFileSync(filepath).toString();
106
+ }
107
+ });
108
+ return out;
64
109
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/cli",
3
- "version": "3.17.2",
3
+ "version": "4.0.0-next.1",
4
4
  "description": "CLI for working wit message catalogs",
5
5
  "keywords": [
6
6
  "cli",
@@ -37,7 +37,7 @@
37
37
  }
38
38
  },
39
39
  "engines": {
40
- "node": ">=14.0.0"
40
+ "node": ">=16.0.0"
41
41
  },
42
42
  "files": [
43
43
  "LICENSE",
@@ -45,51 +45,46 @@
45
45
  "build/"
46
46
  ],
47
47
  "dependencies": {
48
+ "@babel/core": "^7.20.12",
48
49
  "@babel/generator": "^7.20.14",
49
50
  "@babel/parser": "^7.20.15",
50
51
  "@babel/plugin-syntax-jsx": "^7.18.6",
51
52
  "@babel/runtime": "^7.20.13",
52
53
  "@babel/types": "^7.20.7",
53
- "@lingui/babel-plugin-extract-messages": "3.17.2",
54
- "@lingui/conf": "3.17.2",
55
- "@lingui/core": "3.17.2",
54
+ "@lingui/babel-plugin-extract-messages": "^4.0.0-next.1",
55
+ "@lingui/conf": "^4.0.0-next.1",
56
+ "@lingui/core": "^4.0.0-next.1",
56
57
  "@messageformat/parser": "^5.0.0",
57
58
  "babel-plugin-macros": "^3.0.1",
58
- "bcp-47": "^1.0.7",
59
59
  "chalk": "^4.1.0",
60
60
  "chokidar": "3.5.1",
61
61
  "cli-table": "0.3.6",
62
- "commander": "^6.1.0",
62
+ "commander": "^10.0.0",
63
+ "convert-source-map": "^2.0.0",
63
64
  "date-fns": "^2.16.1",
64
- "fs-extra": "^9.0.1",
65
- "fuzzaldrin": "^2.1.0",
66
65
  "glob": "^7.1.4",
67
66
  "inquirer": "^7.3.3",
68
- "make-plural": "^6.2.2",
69
67
  "micromatch": "4.0.2",
70
68
  "mkdirp": "^1.0.4",
71
69
  "node-gettext": "^3.0.0",
72
70
  "normalize-path": "^3.0.0",
73
71
  "ora": "^5.1.0",
74
72
  "papaparse": "^5.3.0",
75
- "pkg-up": "^3.1.0",
76
73
  "plurals-cldr": "^1.0.4",
77
- "pofile": "^1.1.0",
74
+ "pofile": "^1.1.4",
78
75
  "pseudolocale": "^1.1.0",
79
- "ramda": "^0.27.1"
76
+ "ramda": "^0.27.1",
77
+ "source-map": "^0.8.0-beta.0"
80
78
  },
81
79
  "devDependencies": {
80
+ "@lingui/jest-mocks": "^3.0.3",
81
+ "@types/convert-source-map": "^2.0.0",
82
82
  "@types/micromatch": "^4.0.1",
83
83
  "@types/normalize-path": "^3.0.0",
84
84
  "@types/papaparse": "^5.2.3",
85
85
  "@types/plurals-cldr": "^1.0.1",
86
- "mockdate": "^3.0.2",
87
- "typescript": "^4.9.5"
86
+ "mock-fs": "^5.2.0",
87
+ "mockdate": "^3.0.2"
88
88
  },
89
- "peerDependencies": {
90
- "@babel/core": "^7.0.0",
91
- "babel-plugin-macros": "2 || 3",
92
- "typescript": "2 || 3 || 4"
93
- },
94
- "gitHead": "31dcab5a9a8f88bfa8b3a2c7cd12aa2d908a1d80"
89
+ "gitHead": "27ee8e213ff6d0c7a0cd2b21c573d7f6da43fd85"
95
90
  }