@lingui/cli 5.9.3 → 6.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.
- package/dist/api/ProgramExit.js +1 -5
- package/dist/api/catalog/extractFromFiles.d.ts +4 -4
- package/dist/api/catalog/extractFromFiles.js +38 -32
- package/dist/api/catalog/getCatalogDependentFiles.d.ts +1 -1
- package/dist/api/catalog/getCatalogDependentFiles.js +8 -47
- package/dist/api/catalog/getCatalogs.d.ts +2 -2
- package/dist/api/catalog/getCatalogs.js +35 -44
- package/dist/api/catalog/getFallbackListForLocale.js +5 -8
- package/dist/api/catalog/getTranslationsForCatalog.d.ts +1 -1
- package/dist/api/catalog/getTranslationsForCatalog.js +9 -13
- package/dist/api/catalog/mergeCatalog.d.ts +3 -3
- package/dist/api/catalog/mergeCatalog.js +13 -21
- package/dist/api/catalog.d.ts +15 -15
- package/dist/api/catalog.js +48 -45
- package/dist/api/compile/compileLocale.d.ts +3 -3
- package/dist/api/compile/compileLocale.js +28 -33
- package/dist/api/compile.js +13 -49
- package/dist/api/extractors/babel.d.ts +20 -4
- package/dist/api/extractors/babel.js +66 -56
- package/dist/api/extractors/index.js +16 -13
- package/dist/api/formats/formatterWrapper.d.ts +2 -2
- package/dist/api/formats/formatterWrapper.js +10 -12
- package/dist/api/formats/index.d.ts +3 -4
- package/dist/api/formats/index.js +5 -44
- package/dist/api/getPathsForCompileWatcher.d.ts +7 -0
- package/dist/api/getPathsForCompileWatcher.js +15 -0
- package/dist/api/getPathsForExtractWatcher.d.ts +8 -0
- package/dist/api/getPathsForExtractWatcher.js +14 -0
- package/dist/api/help.js +5 -7
- package/dist/api/index.d.ts +7 -7
- package/dist/api/index.js +7 -36
- package/dist/api/logger.d.ts +1 -1
- package/dist/api/logger.js +1 -2
- package/dist/api/messages.d.ts +2 -2
- package/dist/api/messages.js +5 -12
- package/dist/api/pseudoLocalize.js +3 -9
- package/dist/api/resolveWorkersOptions.js +3 -9
- package/dist/api/rethrownError.js +2 -5
- package/dist/api/stats.d.ts +3 -2
- package/dist/api/stats.js +7 -16
- package/dist/api/typedPool.d.ts +6 -0
- package/dist/api/typedPool.js +16 -0
- package/dist/api/types.js +1 -2
- package/dist/api/utils.d.ts +2 -2
- package/dist/api/utils.js +24 -41
- package/dist/api/workerLogger.d.ts +2 -2
- package/dist/api/workerLogger.js +2 -8
- package/dist/api/workerPools.d.ts +3 -0
- package/dist/api/workerPools.js +7 -0
- package/dist/extract-experimental/buildIncludeDepsFilter.js +1 -4
- package/dist/extract-experimental/bundleSource.d.ts +3 -2
- package/dist/extract-experimental/bundleSource.js +10 -13
- package/dist/extract-experimental/constants.js +2 -5
- package/dist/extract-experimental/extractFromBundleAndWrite.d.ts +3 -4
- package/dist/extract-experimental/extractFromBundleAndWrite.js +9 -22
- package/dist/extract-experimental/getExperimentalCatalogs.d.ts +4 -3
- package/dist/extract-experimental/getExperimentalCatalogs.js +10 -15
- package/dist/extract-experimental/linguiEsbuildPlugin.js +12 -19
- package/dist/extract-experimental/resolveCatalogPath.d.ts +1 -1
- package/dist/extract-experimental/resolveCatalogPath.js +7 -14
- package/dist/extract-experimental/resolveTemplatePath.js +7 -10
- package/dist/extract-experimental/workers/extractWorker.d.ts +5 -3
- package/dist/extract-experimental/workers/extractWorker.js +7 -10
- package/dist/extract-experimental/workers/extractWorkerWrapper.prod.d.ts +8 -0
- package/dist/extract-experimental/workers/extractWorkerWrapper.prod.js +2 -0
- package/dist/extract-experimental/writeCatalogs.d.ts +2 -2
- package/dist/extract-experimental/writeCatalogs.js +15 -22
- package/dist/index.js +1 -5
- package/dist/lingui-compile.d.ts +1 -1
- package/dist/lingui-compile.js +45 -59
- package/dist/lingui-extract-experimental.d.ts +3 -2
- package/dist/lingui-extract-experimental.js +58 -62
- package/dist/lingui-extract-template.d.ts +5 -4
- package/dist/lingui-extract-template.js +25 -27
- package/dist/lingui-extract.d.ts +3 -4
- package/dist/lingui-extract.js +62 -69
- package/dist/lingui.js +5 -10
- package/dist/services/translationIO/segment-converters.d.ts +1 -1
- package/dist/services/translationIO/segment-converters.js +16 -20
- package/dist/services/translationIO/translationio-api.d.ts +11 -7
- package/dist/services/translationIO/translationio-api.js +2 -19
- package/dist/services/translationIO.d.ts +4 -4
- package/dist/services/translationIO.js +28 -35
- package/dist/workers/compileWorker.d.ts +8 -11
- package/dist/workers/compileWorker.js +30 -36
- package/dist/workers/compileWorkerWrapper.prod.d.ts +7 -0
- package/dist/workers/compileWorkerWrapper.prod.js +2 -0
- package/dist/workers/extractWorker.d.ts +2 -3
- package/dist/workers/extractWorker.js +5 -12
- package/dist/workers/extractWorkerWrapper.prod.d.ts +6 -0
- package/dist/workers/extractWorkerWrapper.prod.js +2 -0
- package/package.json +26 -43
- package/dist/api/extractWorkerPool.d.ts +0 -1
- package/dist/api/extractWorkerPool.js +0 -8
- package/dist/api/extractors/typescript.d.ts +0 -3
- package/dist/api/extractors/typescript.js +0 -11
- package/dist/extract-experimental/getEntryPoints.d.ts +0 -1
- package/dist/extract-experimental/getEntryPoints.js +0 -7
package/dist/lingui-compile.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const compileLocale_1 = require("./api/compile/compileLocale");
|
|
14
|
-
const threads_1 = require("threads");
|
|
15
|
-
const resolveWorkersOptions_1 = require("./api/resolveWorkersOptions");
|
|
16
|
-
const ms_1 = __importDefault(require("ms"));
|
|
17
|
-
async function command(config, options) {
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
import chokidar from "chokidar";
|
|
3
|
+
import { program } from "commander";
|
|
4
|
+
import { getConfig } from "@lingui/conf";
|
|
5
|
+
import { helpRun } from "./api/help.js";
|
|
6
|
+
import { getCatalogs } from "./api/index.js";
|
|
7
|
+
import { compileLocale } from "./api/compile/compileLocale.js";
|
|
8
|
+
import { createCompileWorkerPool } from "./api/workerPools.js";
|
|
9
|
+
import { resolveWorkersOptions, } from "./api/resolveWorkersOptions.js";
|
|
10
|
+
import ms from "ms";
|
|
11
|
+
import { getPathsForCompileWatcher } from "./api/getPathsForCompileWatcher.js";
|
|
12
|
+
export async function command(config, options) {
|
|
18
13
|
const startTime = Date.now();
|
|
19
14
|
// Check config.compile.merge if catalogs for current locale are to be merged into a single compiled file
|
|
20
15
|
const doMerge = !!config.catalogsMergePath;
|
|
@@ -22,10 +17,10 @@ async function command(config, options) {
|
|
|
22
17
|
let errored = false;
|
|
23
18
|
if (!options.workersOptions.poolSize) {
|
|
24
19
|
// single threaded
|
|
25
|
-
const catalogs = await
|
|
20
|
+
const catalogs = await getCatalogs(config);
|
|
26
21
|
for (const locale of config.locales) {
|
|
27
22
|
try {
|
|
28
|
-
await
|
|
23
|
+
await compileLocale(catalogs, locale, options, config, doMerge, console);
|
|
29
24
|
}
|
|
30
25
|
catch (err) {
|
|
31
26
|
if (err.name === "ProgramExit") {
|
|
@@ -38,39 +33,39 @@ async function command(config, options) {
|
|
|
38
33
|
}
|
|
39
34
|
}
|
|
40
35
|
else {
|
|
41
|
-
|
|
36
|
+
const resolvedConfigPath = config.resolvedConfigPath;
|
|
37
|
+
if (!resolvedConfigPath) {
|
|
42
38
|
throw new Error("Multithreading is only supported when lingui config loaded from file system, not passed by API");
|
|
43
39
|
}
|
|
44
40
|
options.verbose &&
|
|
45
41
|
console.log(`Use worker pool of size ${options.workersOptions.poolSize}`);
|
|
46
|
-
const pool = (
|
|
42
|
+
const pool = createCompileWorkerPool({
|
|
43
|
+
poolSize: options.workersOptions.poolSize,
|
|
44
|
+
});
|
|
47
45
|
try {
|
|
48
|
-
|
|
49
|
-
pool.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
await pool.completed(true);
|
|
46
|
+
await Promise.all(config.locales.map(async (locale) => {
|
|
47
|
+
const { logs, error, exitProgram } = await pool.run(locale, options, doMerge, resolvedConfigPath);
|
|
48
|
+
if (logs.errors) {
|
|
49
|
+
console.error(logs.errors);
|
|
50
|
+
}
|
|
51
|
+
if (exitProgram) {
|
|
52
|
+
errored = true;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (error) {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
64
59
|
}
|
|
65
60
|
finally {
|
|
66
|
-
await pool.
|
|
61
|
+
await pool.destroy();
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
|
-
console.log(`Done in ${(
|
|
64
|
+
console.log(`Done in ${ms(Date.now() - startTime)}`);
|
|
70
65
|
return !errored;
|
|
71
66
|
}
|
|
72
|
-
if (
|
|
73
|
-
|
|
67
|
+
if (import.meta.main) {
|
|
68
|
+
program
|
|
74
69
|
.description("Compile message catalogs to compiled bundle.")
|
|
75
70
|
.option("--config <path>", "Path to the config file")
|
|
76
71
|
.option("--strict", "Disable defaults for missing translations")
|
|
@@ -84,23 +79,23 @@ if (require.main === module) {
|
|
|
84
79
|
.on("--help", function () {
|
|
85
80
|
console.log("\n Examples:\n");
|
|
86
81
|
console.log(" # Compile translations and use defaults or message IDs for missing translations");
|
|
87
|
-
console.log(` $ ${
|
|
82
|
+
console.log(` $ ${helpRun("compile")}`);
|
|
88
83
|
console.log("");
|
|
89
84
|
console.log(" # Compile translations but fail when there are missing");
|
|
90
85
|
console.log(" # translations (don't replace missing translations with");
|
|
91
86
|
console.log(" # default messages or message IDs)");
|
|
92
|
-
console.log(` $ ${
|
|
87
|
+
console.log(` $ ${helpRun("compile --strict")}`);
|
|
93
88
|
})
|
|
94
89
|
.parse(process.argv);
|
|
95
|
-
const options =
|
|
96
|
-
const config =
|
|
90
|
+
const options = program.opts();
|
|
91
|
+
const config = getConfig({ configPath: options.config });
|
|
97
92
|
let previousRun = Promise.resolve(true);
|
|
98
93
|
const compile = () => {
|
|
99
94
|
previousRun = previousRun.then(() => command(config, {
|
|
100
95
|
verbose: options.watch || options.verbose || false,
|
|
101
96
|
allowEmpty: !options.strict,
|
|
102
97
|
failOnCompileError: !!options.strict,
|
|
103
|
-
workersOptions:
|
|
98
|
+
workersOptions: resolveWorkersOptions(options),
|
|
104
99
|
typescript: options.typescript || config.compileNamespace === "ts" || false,
|
|
105
100
|
namespace: options.namespace, // we want this to be undefined if user does not specify so default can be used
|
|
106
101
|
outputPrefix: options.outputPrefix,
|
|
@@ -118,23 +113,14 @@ if (require.main === module) {
|
|
|
118
113
|
};
|
|
119
114
|
// Check if Watch Mode is enabled
|
|
120
115
|
if (options.watch) {
|
|
121
|
-
console.info(
|
|
116
|
+
console.info(styleText("bold", "Initializing Watch Mode..."));
|
|
122
117
|
(async function initWatch() {
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
const paths = [];
|
|
126
|
-
config.locales.forEach((locale) => {
|
|
127
|
-
catalogs.forEach((catalog) => {
|
|
128
|
-
paths.push(`${catalog.path
|
|
129
|
-
.replace(/{locale}/g, locale)
|
|
130
|
-
.replace(/{name}/g, "*")}${format.getCatalogExtension()}`);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
const watcher = chokidar_1.default.watch(paths, {
|
|
118
|
+
const { paths } = await getPathsForCompileWatcher(config);
|
|
119
|
+
const watcher = chokidar.watch(paths, {
|
|
134
120
|
persistent: true,
|
|
135
121
|
});
|
|
136
122
|
const onReady = () => {
|
|
137
|
-
console.info(
|
|
123
|
+
console.info(styleText(["green", "bold"], "Watcher is ready!"));
|
|
138
124
|
watcher
|
|
139
125
|
.on("add", () => dispatchCompile())
|
|
140
126
|
.on("change", () => dispatchCompile());
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
-
import { WorkersOptions } from "./api/resolveWorkersOptions";
|
|
3
|
-
|
|
2
|
+
import { WorkersOptions } from "./api/resolveWorkersOptions.js";
|
|
3
|
+
type CliExtractTemplateOptions = {
|
|
4
4
|
verbose?: boolean;
|
|
5
5
|
files?: string[];
|
|
6
6
|
template?: boolean;
|
|
@@ -10,3 +10,4 @@ export type CliExtractTemplateOptions = {
|
|
|
10
10
|
workersOptions: WorkersOptions;
|
|
11
11
|
};
|
|
12
12
|
export default function command(linguiConfig: LinguiConfigNormalized, options: CliExtractTemplateOptions): Promise<boolean>;
|
|
13
|
+
export {};
|
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const bundleSource_1 = require("./extract-experimental/bundleSource");
|
|
15
|
-
const getEntryPoints_1 = require("./extract-experimental/getEntryPoints");
|
|
16
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
17
|
-
const threads_1 = require("threads");
|
|
18
|
-
const resolveWorkersOptions_1 = require("./api/resolveWorkersOptions");
|
|
19
|
-
const extractFromBundleAndWrite_1 = require("./extract-experimental/extractFromBundleAndWrite");
|
|
20
|
-
async function command(linguiConfig, options) {
|
|
21
|
-
var _a;
|
|
1
|
+
import { program } from "commander";
|
|
2
|
+
import { getConfig } from "@lingui/conf";
|
|
3
|
+
import nodepath from "path";
|
|
4
|
+
import { getFormat } from "./api/formats/index.js";
|
|
5
|
+
import fs from "fs/promises";
|
|
6
|
+
import normalizePath from "normalize-path";
|
|
7
|
+
import { bundleSource } from "./extract-experimental/bundleSource.js";
|
|
8
|
+
import { globSync } from "node:fs";
|
|
9
|
+
import { styleText } from "node:util";
|
|
10
|
+
import { resolveWorkersOptions, } from "./api/resolveWorkersOptions.js";
|
|
11
|
+
import { extractFromBundleAndWrite } from "./extract-experimental/extractFromBundleAndWrite.js";
|
|
12
|
+
import { createExtractExperimentalWorkerPool } from "./api/workerPools.js";
|
|
13
|
+
export default async function command(linguiConfig, options) {
|
|
22
14
|
options.verbose && console.log("Extracting messages from source files…");
|
|
23
|
-
const
|
|
24
|
-
if (!
|
|
15
|
+
const extractorConfig = linguiConfig.experimental?.extractor;
|
|
16
|
+
if (!extractorConfig) {
|
|
25
17
|
throw new Error("The configuration for experimental extractor is empty. Please read the docs.");
|
|
26
18
|
}
|
|
27
|
-
console.log(
|
|
19
|
+
console.log(styleText("yellow", [
|
|
28
20
|
"You have using an experimental feature",
|
|
29
21
|
"Experimental features are not covered by semver, and may cause unexpected or broken application behavior." +
|
|
30
22
|
" Use at your own risk.",
|
|
@@ -37,61 +29,65 @@ async function command(linguiConfig, options) {
|
|
|
37
29
|
// sourcemaps itself doesn't allow to have absolute windows path, because they are not URL compatible.
|
|
38
30
|
// that's why we store esbuild bundles in .lingui folder
|
|
39
31
|
const tmpPrefix = ".lingui/";
|
|
40
|
-
await
|
|
41
|
-
const tempDir = await
|
|
42
|
-
await
|
|
43
|
-
const bundleResult = await
|
|
32
|
+
await fs.mkdir(tmpPrefix, { recursive: true });
|
|
33
|
+
const tempDir = await fs.mkdtemp(tmpPrefix);
|
|
34
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
35
|
+
const bundleResult = await bundleSource(linguiConfig, extractorConfig, globSync(extractorConfig.entries), tempDir, linguiConfig.rootDir);
|
|
44
36
|
const stats = [];
|
|
45
37
|
let commandSuccess = true;
|
|
46
38
|
if (options.workersOptions.poolSize) {
|
|
47
|
-
|
|
39
|
+
const resolvedConfigPath = linguiConfig.resolvedConfigPath;
|
|
40
|
+
if (!resolvedConfigPath) {
|
|
48
41
|
throw new Error("Multithreading is only supported when lingui config loaded from file system, not passed by API");
|
|
49
42
|
}
|
|
50
43
|
options.verbose &&
|
|
51
44
|
console.log(`Use worker pool of size ${options.workersOptions.poolSize}`);
|
|
52
|
-
const pool = (
|
|
45
|
+
const pool = createExtractExperimentalWorkerPool({
|
|
46
|
+
poolSize: options.workersOptions.poolSize,
|
|
47
|
+
});
|
|
53
48
|
try {
|
|
54
|
-
|
|
55
|
-
const { entryPoint } = bundleResult.
|
|
56
|
-
pool.
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
await Promise.all(Object.keys(bundleResult.outputs).map(async (outFile) => {
|
|
50
|
+
const { entryPoint } = bundleResult.outputs[outFile];
|
|
51
|
+
const result = await pool.run(resolvedConfigPath, entryPoint, outFile, extractorConfig.output, options.template || false, options.locales || linguiConfig.locales, options.clean || false, options.overwrite || false);
|
|
52
|
+
commandSuccess &&= result.success;
|
|
53
|
+
if (result.success) {
|
|
59
54
|
stats.push({
|
|
60
|
-
entry: (
|
|
61
|
-
content: stat,
|
|
55
|
+
entry: normalizePath(nodepath.relative(linguiConfig.rootDir, entryPoint)),
|
|
56
|
+
content: result.stat,
|
|
62
57
|
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
await pool.completed();
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
66
60
|
}
|
|
67
61
|
finally {
|
|
68
|
-
await pool.
|
|
62
|
+
await pool.destroy();
|
|
69
63
|
}
|
|
70
64
|
}
|
|
71
65
|
else {
|
|
72
|
-
const format = await
|
|
73
|
-
for (const outFile of Object.keys(bundleResult.
|
|
74
|
-
const { entryPoint } = bundleResult.
|
|
75
|
-
const
|
|
76
|
-
entryPoint,
|
|
66
|
+
const format = await getFormat(linguiConfig.format, linguiConfig.sourceLocale);
|
|
67
|
+
for (const outFile of Object.keys(bundleResult.outputs)) {
|
|
68
|
+
const { entryPoint } = bundleResult.outputs[outFile];
|
|
69
|
+
const result = await extractFromBundleAndWrite({
|
|
70
|
+
entryPoint: entryPoint,
|
|
77
71
|
bundleFile: outFile,
|
|
78
|
-
outputPattern:
|
|
72
|
+
outputPattern: extractorConfig.output,
|
|
79
73
|
format,
|
|
80
74
|
linguiConfig,
|
|
81
75
|
locales: options.locales || linguiConfig.locales,
|
|
82
|
-
overwrite: options.overwrite,
|
|
83
|
-
clean: options.clean,
|
|
84
|
-
template: options.template,
|
|
85
|
-
});
|
|
86
|
-
commandSuccess && (commandSuccess = success);
|
|
87
|
-
stats.push({
|
|
88
|
-
entry: (0, normalize_path_1.default)(path_1.default.relative(linguiConfig.rootDir, entryPoint)),
|
|
89
|
-
content: stat,
|
|
76
|
+
overwrite: options.overwrite || false,
|
|
77
|
+
clean: options.clean || false,
|
|
78
|
+
template: options.template || false,
|
|
90
79
|
});
|
|
80
|
+
commandSuccess &&= result.success;
|
|
81
|
+
if (result.success) {
|
|
82
|
+
stats.push({
|
|
83
|
+
entry: normalizePath(nodepath.relative(linguiConfig.rootDir, entryPoint)),
|
|
84
|
+
content: result.stat,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
91
87
|
}
|
|
92
88
|
}
|
|
93
89
|
// cleanup temp directory
|
|
94
|
-
await
|
|
90
|
+
await fs.rm(tempDir, { recursive: true, force: true });
|
|
95
91
|
stats
|
|
96
92
|
.sort((a, b) => a.entry.localeCompare(b.entry))
|
|
97
93
|
.forEach(({ entry, content }) => {
|
|
@@ -99,8 +95,8 @@ async function command(linguiConfig, options) {
|
|
|
99
95
|
});
|
|
100
96
|
return commandSuccess;
|
|
101
97
|
}
|
|
102
|
-
if (
|
|
103
|
-
|
|
98
|
+
if (import.meta.main) {
|
|
99
|
+
program
|
|
104
100
|
.option("--config <path>", "Path to the config file")
|
|
105
101
|
.option("--template", "Extract to template")
|
|
106
102
|
.option("--overwrite", "Overwrite translations for source locale")
|
|
@@ -109,17 +105,17 @@ if (require.main === module) {
|
|
|
109
105
|
.option("--verbose", "Verbose output")
|
|
110
106
|
.option("--workers <n>", "Number of worker threads to use (default: CPU count - 1, capped at 8). Pass `--workers 1` to disable worker threads and run everything in a single process")
|
|
111
107
|
.parse(process.argv);
|
|
112
|
-
const options =
|
|
113
|
-
const config =
|
|
108
|
+
const options = program.opts();
|
|
109
|
+
const config = getConfig({
|
|
114
110
|
configPath: options.config,
|
|
115
111
|
});
|
|
116
112
|
const result = command(config, {
|
|
117
113
|
verbose: options.verbose || false,
|
|
118
114
|
template: options.template,
|
|
119
|
-
locales:
|
|
115
|
+
locales: options.locale?.split(","),
|
|
120
116
|
overwrite: options.overwrite,
|
|
121
117
|
clean: options.clean,
|
|
122
|
-
workersOptions:
|
|
118
|
+
workersOptions: resolveWorkersOptions(options),
|
|
123
119
|
}).then(() => {
|
|
124
120
|
if (!result)
|
|
125
121
|
process.exit(1);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
-
import { WorkersOptions } from "./api/resolveWorkersOptions";
|
|
3
|
-
|
|
4
|
-
verbose
|
|
2
|
+
import { WorkersOptions } from "./api/resolveWorkersOptions.js";
|
|
3
|
+
type CliExtractTemplateOptions = {
|
|
4
|
+
verbose?: boolean;
|
|
5
5
|
files?: string[];
|
|
6
6
|
workersOptions: WorkersOptions;
|
|
7
7
|
};
|
|
8
|
-
export default function command(config: LinguiConfigNormalized, options:
|
|
8
|
+
export default function command(config: LinguiConfigNormalized, options: CliExtractTemplateOptions): Promise<boolean>;
|
|
9
|
+
export {};
|
|
@@ -1,61 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const api_1 = require("./api");
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const normalize_path_1 = __importDefault(require("normalize-path"));
|
|
13
|
-
const extractWorkerPool_1 = require("./api/extractWorkerPool");
|
|
14
|
-
const resolveWorkersOptions_1 = require("./api/resolveWorkersOptions");
|
|
15
|
-
async function command(config, options) {
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
import { program } from "commander";
|
|
3
|
+
import { getConfig } from "@lingui/conf";
|
|
4
|
+
import { getCatalogs } from "./api/index.js";
|
|
5
|
+
import nodepath from "path";
|
|
6
|
+
import normalizePath from "normalize-path";
|
|
7
|
+
import { createExtractWorkerPool, } from "./api/workerPools.js";
|
|
8
|
+
import { resolveWorkersOptions, } from "./api/resolveWorkersOptions.js";
|
|
9
|
+
export default async function command(config, options) {
|
|
16
10
|
options.verbose && console.log("Extracting messages from source files…");
|
|
17
|
-
const catalogs = await
|
|
11
|
+
const catalogs = await getCatalogs(config);
|
|
18
12
|
const catalogStats = {};
|
|
19
13
|
let commandSuccess = true;
|
|
20
14
|
let workerPool;
|
|
21
15
|
if (options.workersOptions.poolSize) {
|
|
22
16
|
options.verbose &&
|
|
23
17
|
console.log(`Use worker pool of size ${options.workersOptions.poolSize}`);
|
|
24
|
-
workerPool =
|
|
18
|
+
workerPool = createExtractWorkerPool(options.workersOptions);
|
|
25
19
|
}
|
|
26
20
|
try {
|
|
27
21
|
await Promise.all(catalogs.map(async (catalog) => {
|
|
28
|
-
const result = await catalog.makeTemplate(
|
|
22
|
+
const result = await catalog.makeTemplate({
|
|
23
|
+
...options,
|
|
24
|
+
orderBy: config.orderBy,
|
|
25
|
+
workerPool,
|
|
26
|
+
});
|
|
29
27
|
if (result) {
|
|
30
|
-
catalogStats[(
|
|
28
|
+
catalogStats[normalizePath(nodepath.relative(config.rootDir, catalog.templateFile))] = Object.keys(result).length;
|
|
31
29
|
}
|
|
32
|
-
commandSuccess
|
|
30
|
+
commandSuccess &&= Boolean(result);
|
|
33
31
|
}));
|
|
34
32
|
}
|
|
35
33
|
finally {
|
|
36
34
|
if (workerPool) {
|
|
37
|
-
await workerPool.
|
|
35
|
+
await workerPool.destroy();
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
38
|
Object.entries(catalogStats).forEach(([key, value]) => {
|
|
41
|
-
console.log(`Catalog statistics for ${
|
|
39
|
+
console.log(`Catalog statistics for ${styleText("bold", key)}: ${styleText("green", String(value))} messages`);
|
|
42
40
|
console.log();
|
|
43
41
|
});
|
|
44
42
|
return commandSuccess;
|
|
45
43
|
}
|
|
46
|
-
if (
|
|
47
|
-
|
|
44
|
+
if (import.meta.main) {
|
|
45
|
+
program
|
|
48
46
|
.option("--config <path>", "Path to the config file")
|
|
49
47
|
.option("--verbose", "Verbose output")
|
|
50
48
|
.option("--workers <n>", "Number of worker threads to use (default: CPU count - 1, capped at 8). Pass `--workers 1` to disable worker threads and run everything in a single process")
|
|
51
49
|
.parse(process.argv);
|
|
52
|
-
const options =
|
|
53
|
-
const config =
|
|
50
|
+
const options = program.opts();
|
|
51
|
+
const config = getConfig({
|
|
54
52
|
configPath: options.config,
|
|
55
53
|
});
|
|
56
54
|
const result = command(config, {
|
|
57
55
|
verbose: options.verbose || false,
|
|
58
|
-
workersOptions:
|
|
56
|
+
workersOptions: resolveWorkersOptions(options),
|
|
59
57
|
}).then(() => {
|
|
60
58
|
if (!result)
|
|
61
59
|
process.exit(1);
|
package/dist/lingui-extract.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
-
import { WorkersOptions } from "./api/resolveWorkersOptions";
|
|
2
|
+
import { WorkersOptions } from "./api/resolveWorkersOptions.js";
|
|
3
3
|
export type CliExtractOptions = {
|
|
4
4
|
verbose: boolean;
|
|
5
5
|
files?: string[];
|
|
6
6
|
clean: boolean;
|
|
7
7
|
overwrite: boolean;
|
|
8
|
-
locale
|
|
9
|
-
prevFormat: string | null;
|
|
8
|
+
locale?: string[];
|
|
10
9
|
watch?: boolean;
|
|
11
10
|
workersOptions: WorkersOptions;
|
|
12
11
|
};
|
|
13
|
-
export default function command(config: LinguiConfigNormalized, options:
|
|
12
|
+
export default function command(config: LinguiConfigNormalized, options: CliExtractOptions): Promise<boolean>;
|