@lingui/cli 4.0.0-next.5 → 4.0.0-next.6

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 (66) hide show
  1. package/dist/api/catalog/extractFromFiles.d.ts +5 -0
  2. package/dist/api/catalog/extractFromFiles.js +27 -44
  3. package/dist/api/catalog/getCatalogs.d.ts +14 -0
  4. package/dist/api/catalog/getCatalogs.js +70 -78
  5. package/dist/api/catalog/getTranslationsForCatalog.d.ts +14 -0
  6. package/dist/api/catalog/getTranslationsForCatalog.js +36 -32
  7. package/dist/api/catalog/mergeCatalog.d.ts +3 -0
  8. package/dist/api/catalog/mergeCatalog.js +43 -74
  9. package/dist/api/catalog.d.ts +66 -0
  10. package/dist/api/catalog.js +144 -169
  11. package/dist/api/compile.d.ts +19 -0
  12. package/dist/api/compile.js +60 -87
  13. package/dist/api/extractors/babel.d.ts +3 -0
  14. package/dist/api/extractors/babel.js +43 -100
  15. package/dist/api/extractors/index.d.ts +6 -0
  16. package/dist/api/extractors/index.js +17 -23
  17. package/dist/api/extractors/typescript.d.ts +3 -0
  18. package/dist/api/extractors/typescript.js +7 -11
  19. package/dist/api/formats/formatterWrapper.d.ts +10 -0
  20. package/dist/api/formats/formatterWrapper.js +14 -19
  21. package/dist/api/formats/index.d.ts +5 -0
  22. package/dist/api/formats/index.js +15 -63
  23. package/dist/api/help.d.ts +1 -0
  24. package/dist/api/help.js +12 -13
  25. package/dist/api/index.d.ts +4 -0
  26. package/dist/api/index.js +24 -30
  27. package/dist/api/pseudoLocalize.d.ts +1 -0
  28. package/dist/api/pseudoLocalize.js +23 -27
  29. package/dist/api/rethrownError.d.ts +4 -0
  30. package/dist/api/rethrownError.js +4 -9
  31. package/dist/api/stats.d.ts +6 -0
  32. package/dist/api/stats.js +23 -55
  33. package/dist/api/types.d.ts +5 -0
  34. package/dist/api/types.js +1 -3
  35. package/dist/api/utils.d.ts +22 -0
  36. package/dist/api/utils.js +61 -59
  37. package/dist/extract-experimental/buildExternalizeFilter.d.ts +13 -0
  38. package/dist/extract-experimental/buildExternalizeFilter.js +19 -64
  39. package/dist/extract-experimental/bundleSource.d.ts +2 -0
  40. package/dist/extract-experimental/bundleSource.js +25 -74
  41. package/dist/extract-experimental/constants.d.ts +2 -0
  42. package/dist/extract-experimental/constants.js +4 -15
  43. package/dist/extract-experimental/getEntryPoints.d.ts +1 -0
  44. package/dist/extract-experimental/getEntryPoints.js +8 -16
  45. package/dist/extract-experimental/getExperimentalCatalogs.d.ts +3 -0
  46. package/dist/extract-experimental/getExperimentalCatalogs.js +15 -19
  47. package/dist/extract-experimental/resolveCatalogPath.d.ts +2 -0
  48. package/dist/extract-experimental/resolveCatalogPath.js +13 -24
  49. package/dist/extract-experimental/resolveTemplatePath.d.ts +1 -0
  50. package/dist/extract-experimental/resolveTemplatePath.js +11 -14
  51. package/dist/extract-experimental/writeCatalogs.d.ts +21 -0
  52. package/dist/extract-experimental/writeCatalogs.js +23 -36
  53. package/dist/lingui-compile.d.ts +9 -0
  54. package/dist/lingui-compile.js +94 -82
  55. package/dist/lingui-extract-experimental.d.ts +10 -0
  56. package/dist/lingui-extract-experimental.js +58 -67
  57. package/dist/lingui-extract-template.d.ts +6 -0
  58. package/dist/lingui-extract-template.js +29 -35
  59. package/dist/lingui-extract.d.ts +11 -0
  60. package/dist/lingui-extract.js +81 -117
  61. package/dist/lingui.d.ts +2 -0
  62. package/dist/lingui.js +11 -6
  63. package/dist/services/translationIO.d.ts +3 -0
  64. package/dist/services/translationIO.js +92 -89
  65. package/package.json +23 -14
  66. package/dist/tests.js +0 -137
@@ -1,154 +1,166 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "command", {
6
- enumerable: true,
7
- get: ()=>command
8
- });
9
- const _chalk = /*#__PURE__*/ _interopRequireDefault(require("chalk"));
10
- const _chokidar = /*#__PURE__*/ _interopRequireDefault(require("chokidar"));
11
- const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
12
- const _commander = require("commander");
13
- const _conf = require("@lingui/conf");
14
- const _compile = require("./api/compile");
15
- const _help = require("./api/help");
16
- const _api = require("./api");
17
- const _getCatalogs = require("./api/catalog/getCatalogs");
18
- const _utils = require("./api/utils");
19
- const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
20
- function _interopRequireDefault(obj) {
21
- return obj && obj.__esModule ? obj : {
22
- default: obj
23
- };
24
- }
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.command = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const chokidar_1 = __importDefault(require("chokidar"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const commander_1 = require("commander");
11
+ const conf_1 = require("@lingui/conf");
12
+ const compile_1 = require("./api/compile");
13
+ const help_1 = require("./api/help");
14
+ const api_1 = require("./api");
15
+ const getCatalogs_1 = require("./api/catalog/getCatalogs");
16
+ const utils_1 = require("./api/utils");
17
+ const path_1 = __importDefault(require("path"));
25
18
  async function command(config, options) {
26
- const catalogs = await (0, _api.getCatalogs)(config);
19
+ const catalogs = await (0, api_1.getCatalogs)(config);
27
20
  // Check config.compile.merge if catalogs for current locale are to be merged into a single compiled file
28
21
  const doMerge = !!config.catalogsMergePath;
29
22
  let mergedCatalogs = {};
30
23
  console.log("Compiling message catalogs…");
31
- for (const locale of config.locales){
32
- for (const catalog of catalogs){
24
+ for (const locale of config.locales) {
25
+ for (const catalog of catalogs) {
33
26
  const missingMessages = [];
34
27
  const messages = await catalog.getTranslations(locale, {
35
28
  fallbackLocales: config.fallbackLocales,
36
29
  sourceLocale: config.sourceLocale,
37
- onMissing: (missing)=>{
30
+ onMissing: (missing) => {
38
31
  missingMessages.push(missing);
39
- }
32
+ },
40
33
  });
41
34
  if (!options.allowEmpty && missingMessages.length > 0) {
42
- console.error(_chalk.default.red(`Error: Failed to compile catalog for locale ${_chalk.default.bold(locale)}!`));
35
+ console.error(chalk_1.default.red(`Error: Failed to compile catalog for locale ${chalk_1.default.bold(locale)}!`));
43
36
  if (options.verbose) {
44
- console.error(_chalk.default.red("Missing translations:"));
45
- missingMessages.forEach((missing)=>{
46
- const source = missing.source || missing.source === missing.id ? `: (${missing.source})` : "";
37
+ console.error(chalk_1.default.red("Missing translations:"));
38
+ missingMessages.forEach((missing) => {
39
+ const source = missing.source || missing.source === missing.id
40
+ ? `: (${missing.source})`
41
+ : "";
47
42
  console.error(`${missing.id}${source}`);
48
43
  });
49
- } else {
50
- console.error(_chalk.default.red(`Missing ${missingMessages.length} translation(s)`));
44
+ }
45
+ else {
46
+ console.error(chalk_1.default.red(`Missing ${missingMessages.length} translation(s)`));
51
47
  }
52
48
  console.error();
53
49
  return false;
54
50
  }
55
51
  if (doMerge) {
56
- mergedCatalogs = {
57
- ...mergedCatalogs,
58
- ...messages
59
- };
60
- } else {
61
- const namespace = options.typescript ? "ts" : options.namespace || config.compileNamespace;
62
- const compiledCatalog = (0, _compile.createCompiledCatalog)(locale, messages, {
52
+ mergedCatalogs = Object.assign(Object.assign({}, mergedCatalogs), messages);
53
+ }
54
+ else {
55
+ const namespace = options.typescript
56
+ ? "ts"
57
+ : options.namespace || config.compileNamespace;
58
+ const compiledCatalog = (0, compile_1.createCompiledCatalog)(locale, messages, {
63
59
  strict: false,
64
60
  namespace,
65
61
  pseudoLocale: config.pseudoLocale,
66
- compilerBabelOptions: config.compilerBabelOptions
62
+ compilerBabelOptions: config.compilerBabelOptions,
67
63
  });
68
64
  let compiledPath = await catalog.writeCompiled(locale, compiledCatalog, namespace);
69
65
  if (options.typescript) {
70
66
  const typescriptPath = compiledPath.replace(/\.ts?$/, "") + ".d.ts";
71
- _fs.default.writeFileSync(typescriptPath, `import { Messages } from '@lingui/core';
67
+ fs_1.default.writeFileSync(typescriptPath, `import { Messages } from '@lingui/core';
72
68
  declare const messages: Messages;
73
69
  export { messages };
74
70
  `);
75
71
  }
76
- compiledPath = (0, _utils.normalizeSlashes)(_path.default.relative(config.rootDir, compiledPath));
77
- options.verbose && console.error(_chalk.default.green(`${locale} ⇒ ${compiledPath}`));
72
+ compiledPath = (0, utils_1.normalizeSlashes)(path_1.default.relative(config.rootDir, compiledPath));
73
+ options.verbose &&
74
+ console.error(chalk_1.default.green(`${locale} ⇒ ${compiledPath}`));
78
75
  }
79
76
  }
80
77
  if (doMerge) {
81
- const compileCatalog = await (0, _getCatalogs.getCatalogForMerge)(config);
78
+ const compileCatalog = await (0, getCatalogs_1.getCatalogForMerge)(config);
82
79
  const namespace = options.namespace || config.compileNamespace;
83
- const compiledCatalog = (0, _compile.createCompiledCatalog)(locale, mergedCatalogs, {
80
+ const compiledCatalog = (0, compile_1.createCompiledCatalog)(locale, mergedCatalogs, {
84
81
  strict: false,
85
82
  namespace: namespace,
86
83
  pseudoLocale: config.pseudoLocale,
87
- compilerBabelOptions: config.compilerBabelOptions
84
+ compilerBabelOptions: config.compilerBabelOptions,
88
85
  });
89
86
  let compiledPath = await compileCatalog.writeCompiled(locale, compiledCatalog, namespace);
90
- compiledPath = (0, _utils.normalizeSlashes)(_path.default.relative(config.rootDir, compiledPath));
91
- options.verbose && console.log(_chalk.default.green(`${locale} ⇒ ${compiledPath}`));
87
+ compiledPath = (0, utils_1.normalizeSlashes)(path_1.default.relative(config.rootDir, compiledPath));
88
+ options.verbose && console.log(chalk_1.default.green(`${locale} ⇒ ${compiledPath}`));
92
89
  }
93
90
  }
94
91
  return true;
95
92
  }
93
+ exports.command = command;
96
94
  if (require.main === module) {
97
- _commander.program.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("--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() {
95
+ commander_1.program
96
+ .description("Add compile message catalogs and add language data (plurals) to compiled bundle.")
97
+ .option("--config <path>", "Path to the config file")
98
+ .option("--strict", "Disable defaults for missing translations")
99
+ .option("--verbose", "Verbose output")
100
+ .option("--typescript", "Create Typescript definition for compiled bundle")
101
+ .option("--namespace <namespace>", "Specify namespace for compiled bundle. Ex: cjs(default) -> module.exports, es -> export, window.test -> window.test")
102
+ .option("--watch", "Enables Watch Mode")
103
+ .option("--debounce <delay>", "Debounces compilation for given amount of milliseconds")
104
+ .on("--help", function () {
98
105
  console.log("\n Examples:\n");
99
106
  console.log(" # Compile translations and use defaults or message IDs for missing translations");
100
- console.log(` $ ${(0, _help.helpRun)("compile")}`);
107
+ console.log(` $ ${(0, help_1.helpRun)("compile")}`);
101
108
  console.log("");
102
109
  console.log(" # Compile translations but fail when there are missing");
103
110
  console.log(" # translations (don't replace missing translations with");
104
111
  console.log(" # default messages or message IDs)");
105
- console.log(` $ ${(0, _help.helpRun)("compile --strict")}`);
106
- }).parse(process.argv);
107
- const options = _commander.program.opts();
108
- const config = (0, _conf.getConfig)({
109
- configPath: options.config
110
- });
112
+ console.log(` $ ${(0, help_1.helpRun)("compile --strict")}`);
113
+ })
114
+ .parse(process.argv);
115
+ const options = commander_1.program.opts();
116
+ const config = (0, conf_1.getConfig)({ configPath: options.config });
111
117
  let previousRun = Promise.resolve(true);
112
- const compile = ()=>{
113
- previousRun = previousRun.then(()=>command(config, {
114
- verbose: options.watch || options.verbose || false,
115
- allowEmpty: !options.strict,
116
- typescript: options.typescript || config.compileNamespace === "ts" || false,
117
- namespace: options.namespace
118
- }));
118
+ const compile = () => {
119
+ previousRun = previousRun.then(() => command(config, {
120
+ verbose: options.watch || options.verbose || false,
121
+ allowEmpty: !options.strict,
122
+ typescript: options.typescript || config.compileNamespace === "ts" || false,
123
+ namespace: options.namespace, // we want this to be undefined if user does not specify so default can be used
124
+ }));
119
125
  return previousRun;
120
126
  };
121
127
  let debounceTimer;
122
- const dispatchCompile = ()=>{
128
+ const dispatchCompile = () => {
123
129
  // Skip debouncing if not enabled
124
- if (!options.debounce) compile();
130
+ if (!options.debounce)
131
+ compile();
125
132
  // CLear the previous timer if there is any, and schedule the next
126
133
  debounceTimer && clearTimeout(debounceTimer);
127
- debounceTimer = setTimeout(()=>compile(), options.debounce);
134
+ debounceTimer = setTimeout(() => compile(), options.debounce);
128
135
  };
129
136
  // Check if Watch Mode is enabled
130
137
  if (options.watch) {
131
- console.info(_chalk.default.bold("Initializing Watch Mode..."));
138
+ console.info(chalk_1.default.bold("Initializing Watch Mode..."));
132
139
  (async function initWatch() {
133
- const format = await (0, _api.getFormat)(config.format, config.formatOptions, config.sourceLocale);
134
- const catalogs = await (0, _api.getCatalogs)(config);
140
+ const format = await (0, api_1.getFormat)(config.format, config.formatOptions, config.sourceLocale);
141
+ const catalogs = await (0, api_1.getCatalogs)(config);
135
142
  const paths = [];
136
- config.locales.forEach((locale)=>{
137
- catalogs.forEach((catalog)=>{
138
- paths.push(`${catalog.path.replace(/{locale}/g, locale).replace(/{name}/g, "*")}${format.getCatalogExtension()}`);
143
+ config.locales.forEach((locale) => {
144
+ catalogs.forEach((catalog) => {
145
+ paths.push(`${catalog.path
146
+ .replace(/{locale}/g, locale)
147
+ .replace(/{name}/g, "*")}${format.getCatalogExtension()}`);
139
148
  });
140
149
  });
141
- const watcher = _chokidar.default.watch(paths, {
142
- persistent: true
150
+ const watcher = chokidar_1.default.watch(paths, {
151
+ persistent: true,
143
152
  });
144
- const onReady = ()=>{
145
- console.info(_chalk.default.green.bold("Watcher is ready!"));
146
- watcher.on("add", ()=>dispatchCompile()).on("change", ()=>dispatchCompile());
153
+ const onReady = () => {
154
+ console.info(chalk_1.default.green.bold("Watcher is ready!"));
155
+ watcher
156
+ .on("add", () => dispatchCompile())
157
+ .on("change", () => dispatchCompile());
147
158
  };
148
- watcher.on("ready", ()=>onReady());
159
+ watcher.on("ready", () => onReady());
149
160
  })();
150
- } else {
151
- compile().then((results)=>{
161
+ }
162
+ else {
163
+ compile().then((results) => {
152
164
  if (!results) {
153
165
  process.exit(1);
154
166
  }
@@ -0,0 +1,10 @@
1
+ import { LinguiConfigNormalized } from "@lingui/conf";
2
+ export type CliExtractTemplateOptions = {
3
+ verbose: boolean;
4
+ files?: string[];
5
+ template?: boolean;
6
+ locales?: string[];
7
+ overwrite?: boolean;
8
+ clean?: boolean;
9
+ };
10
+ export default function command(linguiConfig: LinguiConfigNormalized, options: Partial<CliExtractTemplateOptions>): Promise<boolean>;
@@ -1,70 +1,60 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: ()=>command
8
- });
9
- const _commander = require("commander");
10
- const _conf = require("@lingui/conf");
11
- const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
12
- const _os = /*#__PURE__*/ _interopRequireDefault(require("os"));
13
- const _formats = require("./api/formats");
14
- const _promises = /*#__PURE__*/ _interopRequireDefault(require("fs/promises"));
15
- const _extractFromFiles = require("./api/catalog/extractFromFiles");
16
- const _utils = require("./api/utils");
17
- const _bundleSource = require("./extract-experimental/bundleSource");
18
- const _writeCatalogs = require("./extract-experimental/writeCatalogs");
19
- const _getEntryPoints = require("./extract-experimental/getEntryPoints");
20
- const _chalk = /*#__PURE__*/ _interopRequireDefault(require("chalk"));
21
- function _interopRequireDefault(obj) {
22
- return obj && obj.__esModule ? obj : {
23
- default: obj
24
- };
25
- }
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var _a;
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const commander_1 = require("commander");
8
+ const conf_1 = require("@lingui/conf");
9
+ const path_1 = __importDefault(require("path"));
10
+ const os_1 = __importDefault(require("os"));
11
+ const formats_1 = require("./api/formats");
12
+ const promises_1 = __importDefault(require("fs/promises"));
13
+ const extractFromFiles_1 = require("./api/catalog/extractFromFiles");
14
+ const utils_1 = require("./api/utils");
15
+ const bundleSource_1 = require("./extract-experimental/bundleSource");
16
+ const writeCatalogs_1 = require("./extract-experimental/writeCatalogs");
17
+ const getEntryPoints_1 = require("./extract-experimental/getEntryPoints");
18
+ const chalk_1 = __importDefault(require("chalk"));
26
19
  async function command(linguiConfig, options) {
27
- var _linguiConfig_experimental;
20
+ var _a;
28
21
  options.verbose && console.log("Extracting messages from source files…");
29
- const config = (_linguiConfig_experimental = linguiConfig.experimental) === null || _linguiConfig_experimental === void 0 ? void 0 : _linguiConfig_experimental.extractor;
22
+ const config = (_a = linguiConfig.experimental) === null || _a === void 0 ? void 0 : _a.extractor;
30
23
  if (!config) {
31
24
  throw new Error("The configuration for experimental extractor is empty. Please read the docs.");
32
25
  }
33
- console.log(_chalk.default.yellow([
26
+ console.log(chalk_1.default.yellow([
34
27
  "You have using an experimental feature",
35
- "Experimental features are not covered by semver, and may cause unexpected or broken application behavior." + " Use at your own risk.",
36
- ""
28
+ "Experimental features are not covered by semver, and may cause unexpected or broken application behavior." +
29
+ " Use at your own risk.",
30
+ "",
37
31
  ].join("\n")));
38
- const tempDir = await _promises.default.mkdtemp(_path.default.join(_os.default.tmpdir(), "js-lingui-extract-"));
39
- await _promises.default.rm(tempDir, {
40
- recursive: true,
41
- force: true
42
- });
43
- const bundleResult = await (0, _bundleSource.bundleSource)(config, (0, _getEntryPoints.getEntryPoints)(config.entries), tempDir, linguiConfig.rootDir);
32
+ const tempDir = await promises_1.default.mkdtemp(path_1.default.join(os_1.default.tmpdir(), "js-lingui-extract-"));
33
+ await promises_1.default.rm(tempDir, { recursive: true, force: true });
34
+ const bundleResult = await (0, bundleSource_1.bundleSource)(config, (0, getEntryPoints_1.getEntryPoints)(config.entries), tempDir, linguiConfig.rootDir);
44
35
  const stats = [];
45
36
  let commandSuccess = true;
46
- const format = await (0, _formats.getFormat)(linguiConfig.format, linguiConfig.formatOptions, linguiConfig.sourceLocale);
47
- for (const outFile of Object.keys(bundleResult.metafile.outputs)){
48
- const messages = await (0, _extractFromFiles.extractFromFiles)([
49
- outFile
50
- ], linguiConfig);
51
- const { entryPoint } = bundleResult.metafile.outputs[outFile];
37
+ const format = await (0, formats_1.getFormat)(linguiConfig.format, linguiConfig.formatOptions, linguiConfig.sourceLocale);
38
+ for (const outFile of Object.keys(bundleResult.metafile.outputs)) {
39
+ const messages = await (0, extractFromFiles_1.extractFromFiles)([outFile], linguiConfig);
40
+ const { entryPoint } = bundleResult.metafile.outputs[outFile];
52
41
  let output;
53
42
  if (!messages) {
54
43
  commandSuccess = false;
55
44
  continue;
56
45
  }
57
46
  if (options.template) {
58
- output = (await (0, _writeCatalogs.writeTemplate)({
47
+ output = (await (0, writeCatalogs_1.writeTemplate)({
59
48
  linguiConfig,
60
49
  clean: options.clean,
61
50
  format,
62
51
  messages,
63
52
  entryPoint,
64
- outputPattern: config.output
53
+ outputPattern: config.output,
65
54
  })).statMessage;
66
- } else {
67
- output = (await (0, _writeCatalogs.writeCatalogs)({
55
+ }
56
+ else {
57
+ output = (await (0, writeCatalogs_1.writeCatalogs)({
68
58
  locales: options.locales || linguiConfig.locales,
69
59
  linguiConfig,
70
60
  clean: options.clean,
@@ -72,42 +62,43 @@ async function command(linguiConfig, options) {
72
62
  messages,
73
63
  entryPoint,
74
64
  overwrite: options.overwrite,
75
- outputPattern: config.output
65
+ outputPattern: config.output,
76
66
  })).statMessage;
77
67
  }
78
68
  stats.push({
79
- entry: (0, _utils.normalizeSlashes)(_path.default.relative(linguiConfig.rootDir, entryPoint)),
80
- content: output
69
+ entry: (0, utils_1.normalizeSlashes)(path_1.default.relative(linguiConfig.rootDir, entryPoint)),
70
+ content: output,
81
71
  });
82
72
  }
83
73
  // cleanup temp directory
84
- await _promises.default.rm(tempDir, {
85
- recursive: true,
86
- force: true
87
- });
88
- stats.forEach(({ entry , content })=>{
89
- console.log([
90
- `Catalog statistics for ${entry}:`,
91
- content,
92
- ""
93
- ].join("\n"));
74
+ await promises_1.default.rm(tempDir, { recursive: true, force: true });
75
+ stats.forEach(({ entry, content }) => {
76
+ console.log([`Catalog statistics for ${entry}:`, content, ""].join("\n"));
94
77
  });
95
78
  return commandSuccess;
96
79
  }
80
+ exports.default = command;
97
81
  if (require.main === module) {
98
- var _options_locale;
99
- _commander.program.option("--config <path>", "Path to the config file").option("--template", "Extract to template").option("--overwrite", "Overwrite translations for source locale").option("--clean", "Remove obsolete translations").option("--locale <locale, [...]>", "Only extract the specified locales").option("--verbose", "Verbose output").parse(process.argv);
100
- const options = _commander.program.opts();
101
- const config = (0, _conf.getConfig)({
102
- configPath: options.config
82
+ commander_1.program
83
+ .option("--config <path>", "Path to the config file")
84
+ .option("--template", "Extract to template")
85
+ .option("--overwrite", "Overwrite translations for source locale")
86
+ .option("--clean", "Remove obsolete translations")
87
+ .option("--locale <locale, [...]>", "Only extract the specified locales")
88
+ .option("--verbose", "Verbose output")
89
+ .parse(process.argv);
90
+ const options = commander_1.program.opts();
91
+ const config = (0, conf_1.getConfig)({
92
+ configPath: options.config,
103
93
  });
104
94
  const result = command(config, {
105
95
  verbose: options.verbose || false,
106
96
  template: options.template,
107
- locales: (_options_locale = options.locale) === null || _options_locale === void 0 ? void 0 : _options_locale.split(","),
97
+ locales: (_a = options.locale) === null || _a === void 0 ? void 0 : _a.split(","),
108
98
  overwrite: options.overwrite,
109
- clean: options.clean
110
- }).then(()=>{
111
- if (!result) process.exit(1);
99
+ clean: options.clean,
100
+ }).then(() => {
101
+ if (!result)
102
+ process.exit(1);
112
103
  });
113
104
  }
@@ -0,0 +1,6 @@
1
+ import { LinguiConfigNormalized } from "@lingui/conf";
2
+ export type CliExtractTemplateOptions = {
3
+ verbose: boolean;
4
+ files?: string[];
5
+ };
6
+ export default function command(config: LinguiConfigNormalized, options: Partial<CliExtractTemplateOptions>): Promise<boolean>;
@@ -1,52 +1,46 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: ()=>command
8
- });
9
- const _chalk = /*#__PURE__*/ _interopRequireDefault(require("chalk"));
10
- const _commander = require("commander");
11
- const _conf = require("@lingui/conf");
12
- const _api = require("./api");
13
- const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
14
- const _utils = require("./api/utils");
15
- function _interopRequireDefault(obj) {
16
- return obj && obj.__esModule ? obj : {
17
- default: obj
18
- };
19
- }
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const chalk_1 = __importDefault(require("chalk"));
7
+ const commander_1 = require("commander");
8
+ const conf_1 = require("@lingui/conf");
9
+ const api_1 = require("./api");
10
+ const path_1 = __importDefault(require("path"));
11
+ const utils_1 = require("./api/utils");
20
12
  async function command(config, options) {
21
13
  options.verbose && console.log("Extracting messages from source files…");
22
- const catalogs = await (0, _api.getCatalogs)(config);
14
+ const catalogs = await (0, api_1.getCatalogs)(config);
23
15
  const catalogStats = {};
24
16
  let commandSuccess = true;
25
- await Promise.all(catalogs.map(async (catalog)=>{
26
- const result = await catalog.makeTemplate({
27
- ...options,
28
- orderBy: config.orderBy
29
- });
17
+ await Promise.all(catalogs.map(async (catalog) => {
18
+ const result = await catalog.makeTemplate(Object.assign(Object.assign({}, options), { orderBy: config.orderBy }));
30
19
  if (result) {
31
- catalogStats[(0, _utils.normalizeSlashes)(_path.default.relative(config.rootDir, catalog.templateFile))] = Object.keys(result).length;
20
+ catalogStats[(0, utils_1.normalizeSlashes)(path_1.default.relative(config.rootDir, catalog.templateFile))] = Object.keys(result).length;
32
21
  }
33
- commandSuccess &&= Boolean(result);
22
+ commandSuccess && (commandSuccess = Boolean(result));
34
23
  }));
35
- Object.entries(catalogStats).forEach(([key, value])=>{
36
- console.log(`Catalog statistics for ${_chalk.default.bold(key)}: ${_chalk.default.green(value)} messages`);
24
+ Object.entries(catalogStats).forEach(([key, value]) => {
25
+ console.log(`Catalog statistics for ${chalk_1.default.bold(key)}: ${chalk_1.default.green(value)} messages`);
37
26
  console.log();
38
27
  });
39
28
  return commandSuccess;
40
29
  }
30
+ exports.default = command;
41
31
  if (require.main === module) {
42
- _commander.program.option("--config <path>", "Path to the config file").option("--verbose", "Verbose output").parse(process.argv);
43
- const options = _commander.program.opts();
44
- const config = (0, _conf.getConfig)({
45
- configPath: options.config
32
+ commander_1.program
33
+ .option("--config <path>", "Path to the config file")
34
+ .option("--verbose", "Verbose output")
35
+ .parse(process.argv);
36
+ const options = commander_1.program.opts();
37
+ const config = (0, conf_1.getConfig)({
38
+ configPath: options.config,
46
39
  });
47
40
  const result = command(config, {
48
- verbose: options.verbose || false
49
- }).then(()=>{
50
- if (!result) process.exit(1);
41
+ verbose: options.verbose || false,
42
+ }).then(() => {
43
+ if (!result)
44
+ process.exit(1);
51
45
  });
52
46
  }
@@ -0,0 +1,11 @@
1
+ import { LinguiConfigNormalized } from "@lingui/conf";
2
+ export type CliExtractOptions = {
3
+ verbose: boolean;
4
+ files?: string[];
5
+ clean: boolean;
6
+ overwrite: boolean;
7
+ locale: string;
8
+ prevFormat: string | null;
9
+ watch?: boolean;
10
+ };
11
+ export default function command(config: LinguiConfigNormalized, options: Partial<CliExtractOptions>): Promise<boolean>;