@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/api/workerLogger.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.WorkerLogger = void 0;
|
|
4
|
-
class WorkerLogger {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.errors = [];
|
|
7
|
-
}
|
|
1
|
+
export class WorkerLogger {
|
|
2
|
+
errors = [];
|
|
8
3
|
error(msg) {
|
|
9
4
|
this.errors.push(msg);
|
|
10
5
|
}
|
|
@@ -16,4 +11,3 @@ class WorkerLogger {
|
|
|
16
11
|
};
|
|
17
12
|
}
|
|
18
13
|
}
|
|
19
|
-
exports.WorkerLogger = WorkerLogger;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createWorkerPool } from "./typedPool.js";
|
|
2
|
+
/** @internal */
|
|
3
|
+
export const createExtractWorkerPool = (opts) => createWorkerPool("../workers/extractWorkerWrapper", import.meta.url, opts.poolSize);
|
|
4
|
+
/** @internal */
|
|
5
|
+
export const createExtractExperimentalWorkerPool = (opts) => createWorkerPool("../extract-experimental/workers/extractWorkerWrapper", import.meta.url, opts.poolSize);
|
|
6
|
+
/** @internal */
|
|
7
|
+
export const createCompileWorkerPool = (opts) => createWorkerPool("../workers/compileWorkerWrapper", import.meta.url, opts.poolSize);
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildIncludeDepsFilter = buildIncludeDepsFilter;
|
|
4
1
|
function createPackageRegExp(packageName) {
|
|
5
2
|
return new RegExp("^" + packageName + "(?:\\/.+)?");
|
|
6
3
|
}
|
|
7
|
-
function buildIncludeDepsFilter(includeDeps) {
|
|
4
|
+
export function buildIncludeDepsFilter(includeDeps) {
|
|
8
5
|
const include = includeDeps.map(createPackageRegExp);
|
|
9
6
|
return (id) => include.some((regExp) => regExp.test(id));
|
|
10
7
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
-
|
|
1
|
+
import { ExperimentalExtractorOptions, LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
+
import { Metafile } from "esbuild";
|
|
3
|
+
export declare function bundleSource(linguiConfig: LinguiConfigNormalized, extractorConfig: ExperimentalExtractorOptions, entryPoints: string[], outDir: string, rootDir: string): Promise<Metafile>;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.bundleSource = bundleSource;
|
|
4
|
-
const linguiEsbuildPlugin_1 = require("./linguiEsbuildPlugin");
|
|
5
|
-
const buildIncludeDepsFilter_1 = require("./buildIncludeDepsFilter");
|
|
1
|
+
import { pluginLinguiMacro } from "./linguiEsbuildPlugin.js";
|
|
2
|
+
import { buildIncludeDepsFilter } from "./buildIncludeDepsFilter.js";
|
|
6
3
|
function createExtRegExp(extensions) {
|
|
7
4
|
return new RegExp("\\.(?:" + extensions.join("|") + ")(?:\\?.*)?$");
|
|
8
5
|
}
|
|
9
|
-
async function bundleSource(linguiConfig, entryPoints, outDir, rootDir) {
|
|
6
|
+
export async function bundleSource(linguiConfig, extractorConfig, entryPoints, outDir, rootDir) {
|
|
10
7
|
const esbuild = await import("esbuild");
|
|
11
|
-
const
|
|
12
|
-
const excludeExtensions = config.excludeExtensions || [
|
|
8
|
+
const excludeExtensions = extractorConfig.excludeExtensions || [
|
|
13
9
|
"ico",
|
|
14
10
|
"pot",
|
|
15
11
|
"xliff",
|
|
@@ -44,16 +40,16 @@ async function bundleSource(linguiConfig, entryPoints, outDir, rootDir) {
|
|
|
44
40
|
sourcesContent: false,
|
|
45
41
|
metafile: true,
|
|
46
42
|
plugins: [
|
|
47
|
-
|
|
43
|
+
pluginLinguiMacro({ linguiConfig }),
|
|
48
44
|
{
|
|
49
45
|
name: "externalize-deps",
|
|
50
46
|
setup(build) {
|
|
51
|
-
const shouldInclude =
|
|
47
|
+
const shouldInclude = buildIncludeDepsFilter(extractorConfig.includeDeps || []);
|
|
52
48
|
// considers all import paths that "look like" package imports in the original source code to be package imports.
|
|
53
49
|
// Specifically import paths that don't start with a path segment of / or . or .. are considered to be package imports.
|
|
54
50
|
// The only two exceptions to this rule are subpath imports (which start with a # character) and deps specified in the `includeDeps`
|
|
55
51
|
build.onResolve({ filter: /^[^.#/].*/ }, async (args) => {
|
|
56
|
-
if (shouldInclude(args.path)) {
|
|
52
|
+
if (shouldInclude(args.path) || args.kind === "entry-point") {
|
|
57
53
|
return { external: false };
|
|
58
54
|
}
|
|
59
55
|
return {
|
|
@@ -72,7 +68,8 @@ async function bundleSource(linguiConfig, entryPoints, outDir, rootDir) {
|
|
|
72
68
|
},
|
|
73
69
|
],
|
|
74
70
|
};
|
|
75
|
-
|
|
76
|
-
?
|
|
71
|
+
const bundleResult = await esbuild.build(extractorConfig.resolveEsbuildOptions
|
|
72
|
+
? extractorConfig.resolveEsbuildOptions(esbuildOptions)
|
|
77
73
|
: esbuildOptions);
|
|
74
|
+
return bundleResult.metafile;
|
|
78
75
|
}
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.DEFAULT_TEMPLATE_NAME = exports.ENTRY_NAME_PH = void 0;
|
|
4
|
-
exports.ENTRY_NAME_PH = "{entryName}";
|
|
5
|
-
exports.DEFAULT_TEMPLATE_NAME = "messages";
|
|
1
|
+
export const ENTRY_NAME_PH = "{entryName}";
|
|
2
|
+
export const DEFAULT_TEMPLATE_NAME = "messages";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
-
import { FormatterWrapper } from "../api/formats";
|
|
2
|
+
import { FormatterWrapper } from "../api/formats/index.js";
|
|
3
3
|
export declare function extractFromBundleAndWrite(params: {
|
|
4
4
|
entryPoint: string;
|
|
5
5
|
bundleFile: string;
|
|
@@ -11,9 +11,8 @@ export declare function extractFromBundleAndWrite(params: {
|
|
|
11
11
|
clean: boolean;
|
|
12
12
|
overwrite: boolean;
|
|
13
13
|
}): Promise<{
|
|
14
|
-
success:
|
|
15
|
-
stat?: undefined;
|
|
14
|
+
success: false;
|
|
16
15
|
} | {
|
|
17
|
-
success:
|
|
16
|
+
success: true;
|
|
18
17
|
stat: string;
|
|
19
18
|
}>;
|
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.extractFromBundleAndWrite = extractFromBundleAndWrite;
|
|
7
|
-
const extractFromFiles_1 = require("../api/catalog/extractFromFiles");
|
|
8
|
-
const writeCatalogs_1 = require("./writeCatalogs");
|
|
9
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
|
-
const babel_1 = require("../api/extractors/babel");
|
|
1
|
+
import { mergeExtractedMessage } from "../api/catalog/extractFromFiles.js";
|
|
2
|
+
import { writeCatalogs, writeTemplate } from "./writeCatalogs.js";
|
|
3
|
+
import extract from "../api/extractors/index.js";
|
|
11
4
|
async function extractFromBundle(filename, linguiConfig) {
|
|
12
5
|
const messages = {};
|
|
13
6
|
let success;
|
|
14
7
|
try {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
(0, extractFromFiles_1.mergeExtractedMessage)(msg, messages, linguiConfig);
|
|
19
|
-
}, {
|
|
20
|
-
linguiConfig,
|
|
21
|
-
}, {
|
|
22
|
-
plugins: (0, babel_1.getBabelParserOptions)(filename, parserOptions),
|
|
23
|
-
}, true);
|
|
8
|
+
await extract(filename, (msg) => {
|
|
9
|
+
mergeExtractedMessage(msg, messages, linguiConfig);
|
|
10
|
+
}, linguiConfig);
|
|
24
11
|
success = true;
|
|
25
12
|
}
|
|
26
13
|
catch (e) {
|
|
@@ -30,7 +17,7 @@ async function extractFromBundle(filename, linguiConfig) {
|
|
|
30
17
|
}
|
|
31
18
|
return { success, messages };
|
|
32
19
|
}
|
|
33
|
-
async function extractFromBundleAndWrite(params) {
|
|
20
|
+
export async function extractFromBundleAndWrite(params) {
|
|
34
21
|
const { linguiConfig, entryPoint, format, outputPattern, locales, overwrite, clean, template, } = params;
|
|
35
22
|
const { messages, success } = await extractFromBundle(params.bundleFile, params.linguiConfig);
|
|
36
23
|
if (!success) {
|
|
@@ -38,7 +25,7 @@ async function extractFromBundleAndWrite(params) {
|
|
|
38
25
|
}
|
|
39
26
|
let stat;
|
|
40
27
|
if (template) {
|
|
41
|
-
stat = (await
|
|
28
|
+
stat = (await writeTemplate({
|
|
42
29
|
linguiConfig,
|
|
43
30
|
clean,
|
|
44
31
|
format,
|
|
@@ -48,7 +35,7 @@ async function extractFromBundleAndWrite(params) {
|
|
|
48
35
|
})).statMessage;
|
|
49
36
|
}
|
|
50
37
|
else {
|
|
51
|
-
stat = (await
|
|
38
|
+
stat = (await writeCatalogs({
|
|
52
39
|
locales,
|
|
53
40
|
linguiConfig,
|
|
54
41
|
clean,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
-
import { Catalog } from "../api/catalog";
|
|
3
|
-
|
|
1
|
+
import { ExperimentalExtractorOptions, LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
+
import { Catalog } from "../api/catalog.js";
|
|
3
|
+
import { FormatterWrapper } from "../api/formats/index.js";
|
|
4
|
+
export declare function getExperimentalCatalogs(linguiConfig: LinguiConfigNormalized, format: FormatterWrapper, extractorConfig: ExperimentalExtractorOptions): Promise<Catalog[]>;
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const formats_1 = require("../api/formats");
|
|
9
|
-
async function getExperimentalCatalogs(linguiConfig) {
|
|
10
|
-
const config = linguiConfig.experimental.extractor;
|
|
11
|
-
const entryPoints = (0, getEntryPoints_1.getEntryPoints)(config.entries);
|
|
12
|
-
const format = await (0, formats_1.getFormat)(linguiConfig.format, linguiConfig.formatOptions, linguiConfig.sourceLocale);
|
|
1
|
+
import { globSync } from "node:fs";
|
|
2
|
+
import { resolveCatalogPath } from "./resolveCatalogPath.js";
|
|
3
|
+
import { Catalog } from "../api/catalog.js";
|
|
4
|
+
import { resolveTemplatePath } from "./resolveTemplatePath.js";
|
|
5
|
+
export async function getExperimentalCatalogs(linguiConfig, format, extractorConfig) {
|
|
6
|
+
const config = extractorConfig;
|
|
7
|
+
const entryPoints = globSync(config.entries);
|
|
13
8
|
return entryPoints.map((entryPoint) => {
|
|
14
|
-
const catalogPath =
|
|
15
|
-
const templatePath =
|
|
16
|
-
return new
|
|
9
|
+
const catalogPath = resolveCatalogPath(config.output, entryPoint, linguiConfig.rootDir, undefined, "");
|
|
10
|
+
const templatePath = resolveTemplatePath(entryPoint, config.output, linguiConfig.rootDir, format.getTemplateExtension());
|
|
11
|
+
return new Catalog({
|
|
17
12
|
name: undefined,
|
|
18
13
|
path: catalogPath,
|
|
19
14
|
templatePath,
|
|
@@ -1,36 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const core_1 = require("@babel/core");
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const babel_1 = require("../api/extractors/babel");
|
|
11
|
-
const babel_plugin_lingui_macro_1 = __importDefault(require("@lingui/babel-plugin-lingui-macro"));
|
|
12
|
-
const pluginLinguiMacro = (options) => ({
|
|
1
|
+
import { transformAsync } from "@babel/core";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { babelRe, getBabelParserOptions } from "../api/extractors/babel.js";
|
|
5
|
+
import linguiMacroPlugin from "@lingui/babel-plugin-lingui-macro";
|
|
6
|
+
export const pluginLinguiMacro = (options) => ({
|
|
13
7
|
name: "linguiMacro",
|
|
14
8
|
setup(build) {
|
|
15
|
-
build.onLoad({ filter:
|
|
16
|
-
const filename =
|
|
17
|
-
const contents = await
|
|
9
|
+
build.onLoad({ filter: babelRe, namespace: "" }, async (args) => {
|
|
10
|
+
const filename = path.relative(process.cwd(), args.path);
|
|
11
|
+
const contents = await fs.promises.readFile(args.path, "utf8");
|
|
18
12
|
const hasMacroRe = /from ["']@lingui(\/.+)?\/macro["']/g;
|
|
19
13
|
if (!hasMacroRe.test(contents)) {
|
|
20
14
|
// let esbuild process file as usual
|
|
21
15
|
return undefined;
|
|
22
16
|
}
|
|
23
|
-
const result = await
|
|
17
|
+
const result = await transformAsync(contents, {
|
|
24
18
|
babelrc: false,
|
|
25
19
|
configFile: false,
|
|
26
20
|
filename: filename,
|
|
27
21
|
sourceMaps: "inline",
|
|
28
22
|
parserOpts: {
|
|
29
|
-
plugins:
|
|
23
|
+
plugins: getBabelParserOptions(filename, {}),
|
|
30
24
|
},
|
|
31
25
|
plugins: [
|
|
32
26
|
[
|
|
33
|
-
|
|
27
|
+
linguiMacroPlugin,
|
|
34
28
|
{
|
|
35
29
|
extract: true,
|
|
36
30
|
linguiConfig: options.linguiConfig,
|
|
@@ -42,4 +36,3 @@ const pluginLinguiMacro = (options) => ({
|
|
|
42
36
|
});
|
|
43
37
|
},
|
|
44
38
|
});
|
|
45
|
-
exports.pluginLinguiMacro = pluginLinguiMacro;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function resolveCatalogPath(configOutput: string, entryPath: string, rootDir: string, locale: string, extension: string): string;
|
|
1
|
+
export declare function resolveCatalogPath(configOutput: string, entryPath: string, rootDir: string, locale: string | undefined, extension: string): string;
|
|
2
2
|
export declare function getEntryName(entryPath: string): string;
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.resolveCatalogPath = resolveCatalogPath;
|
|
7
|
-
exports.getEntryName = getEntryName;
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const utils_1 = require("../api/utils");
|
|
10
|
-
function resolveCatalogPath(configOutput, entryPath, rootDir, locale, extension) {
|
|
1
|
+
import nodepath from "path";
|
|
2
|
+
import { replacePlaceholders } from "../api/utils.js";
|
|
3
|
+
export function resolveCatalogPath(configOutput, entryPath, rootDir, locale, extension) {
|
|
11
4
|
const entryName = getEntryName(entryPath);
|
|
12
|
-
const entryDir =
|
|
13
|
-
return
|
|
5
|
+
const entryDir = nodepath.relative(rootDir, nodepath.dirname(entryPath));
|
|
6
|
+
return nodepath.normalize(replacePlaceholders(configOutput, {
|
|
14
7
|
entryName,
|
|
15
8
|
entryDir,
|
|
16
9
|
locale,
|
|
17
10
|
}) + extension);
|
|
18
11
|
}
|
|
19
|
-
function getEntryName(entryPath) {
|
|
20
|
-
const parsedPath =
|
|
12
|
+
export function getEntryName(entryPath) {
|
|
13
|
+
const parsedPath = nodepath.parse(entryPath);
|
|
21
14
|
return parsedPath.name.replace(parsedPath.ext, "");
|
|
22
15
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const resolveCatalogPath_1 = require("./resolveCatalogPath");
|
|
5
|
-
const constants_1 = require("./constants");
|
|
6
|
-
function resolveTemplatePath(entryPoint, output, rootDir, catalogExtension) {
|
|
1
|
+
import { resolveCatalogPath, getEntryName } from "./resolveCatalogPath.js";
|
|
2
|
+
import { DEFAULT_TEMPLATE_NAME, ENTRY_NAME_PH } from "./constants.js";
|
|
3
|
+
export function resolveTemplatePath(entryPoint, output, rootDir, catalogExtension) {
|
|
7
4
|
let templateName;
|
|
8
|
-
if (output.includes(
|
|
9
|
-
templateName =
|
|
5
|
+
if (output.includes(ENTRY_NAME_PH)) {
|
|
6
|
+
templateName = DEFAULT_TEMPLATE_NAME;
|
|
10
7
|
}
|
|
11
8
|
else {
|
|
12
|
-
templateName =
|
|
9
|
+
templateName = getEntryName(entryPoint);
|
|
13
10
|
}
|
|
14
|
-
return
|
|
11
|
+
return resolveCatalogPath(output, entryPoint, rootDir, templateName, catalogExtension);
|
|
15
12
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type ExtractWorkerFunction = typeof extractWorker;
|
|
2
2
|
declare const extractWorker: (linguiConfigPath: string, entryPoint: string, bundleFile: string, outputPattern: string, template: boolean, locales: string[], clean: boolean, overwrite: boolean) => Promise<{
|
|
3
|
-
success:
|
|
4
|
-
|
|
3
|
+
success: false;
|
|
4
|
+
} | {
|
|
5
|
+
success: true;
|
|
6
|
+
stat: string;
|
|
5
7
|
}>;
|
|
6
|
-
export {};
|
|
8
|
+
export { extractWorker };
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const conf_1 = require("@lingui/conf");
|
|
5
|
-
const extractFromBundleAndWrite_1 = require("../extractFromBundleAndWrite");
|
|
6
|
-
const formats_1 = require("../../api/formats");
|
|
1
|
+
import { getConfig } from "@lingui/conf";
|
|
2
|
+
import { extractFromBundleAndWrite } from "../extractFromBundleAndWrite.js";
|
|
3
|
+
import { getFormat } from "../../api/formats/index.js";
|
|
7
4
|
let linguiConfig;
|
|
8
5
|
let format;
|
|
9
6
|
const extractWorker = async (linguiConfigPath, entryPoint, bundleFile, outputPattern, template, locales, clean, overwrite) => {
|
|
10
7
|
if (!linguiConfig) {
|
|
11
8
|
// initialize config once per worker, speed up workers follow execution
|
|
12
|
-
linguiConfig =
|
|
9
|
+
linguiConfig = getConfig({
|
|
13
10
|
configPath: linguiConfigPath,
|
|
14
11
|
skipValidation: true,
|
|
15
12
|
});
|
|
16
13
|
}
|
|
17
14
|
if (!format) {
|
|
18
|
-
format = await
|
|
15
|
+
format = await getFormat(linguiConfig.format, linguiConfig.sourceLocale);
|
|
19
16
|
}
|
|
20
|
-
return await
|
|
17
|
+
return await extractFromBundleAndWrite({
|
|
21
18
|
entryPoint,
|
|
22
19
|
bundleFile,
|
|
23
20
|
outputPattern,
|
|
@@ -29,4 +26,4 @@ const extractWorker = async (linguiConfigPath, entryPoint, bundleFile, outputPat
|
|
|
29
26
|
template,
|
|
30
27
|
});
|
|
31
28
|
};
|
|
32
|
-
|
|
29
|
+
export { extractWorker };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ExtractedCatalogType } from "../api";
|
|
1
|
+
import { ExtractedCatalogType } from "../api/index.js";
|
|
2
2
|
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
3
|
-
import { FormatterWrapper } from "../api/formats";
|
|
3
|
+
import { FormatterWrapper } from "../api/formats/index.js";
|
|
4
4
|
type ExtractTemplateParams = {
|
|
5
5
|
format: FormatterWrapper;
|
|
6
6
|
clean: boolean;
|
|
@@ -1,40 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.writeTemplate = writeTemplate;
|
|
8
|
-
const resolveTemplatePath_1 = require("./resolveTemplatePath");
|
|
9
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
10
|
-
const resolveCatalogPath_1 = require("./resolveCatalogPath");
|
|
11
|
-
const mergeCatalog_1 = require("../api/catalog/mergeCatalog");
|
|
12
|
-
const stats_1 = require("../api/stats");
|
|
13
|
-
const catalog_1 = require("../api/catalog");
|
|
1
|
+
import { resolveTemplatePath } from "./resolveTemplatePath.js";
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
|
+
import { resolveCatalogPath } from "./resolveCatalogPath.js";
|
|
4
|
+
import { mergeCatalog } from "../api/catalog/mergeCatalog.js";
|
|
5
|
+
import { printStats } from "../api/stats.js";
|
|
6
|
+
import { cleanObsolete, order } from "../api/catalog.js";
|
|
14
7
|
function cleanAndSort(catalog, clean, orderBy) {
|
|
15
8
|
if (clean) {
|
|
16
|
-
catalog =
|
|
9
|
+
catalog = cleanObsolete(catalog);
|
|
17
10
|
}
|
|
18
|
-
return
|
|
11
|
+
return order(orderBy, catalog);
|
|
19
12
|
}
|
|
20
|
-
async function writeCatalogs(params) {
|
|
13
|
+
export async function writeCatalogs(params) {
|
|
21
14
|
const { entryPoint, outputPattern, linguiConfig, locales, overwrite, format, clean, messages, } = params;
|
|
22
15
|
const stat = {};
|
|
23
16
|
for (const locale of locales) {
|
|
24
|
-
const catalogOutput =
|
|
25
|
-
const catalog =
|
|
17
|
+
const catalogOutput = resolveCatalogPath(outputPattern, entryPoint, linguiConfig.rootDir, locale, format.getCatalogExtension());
|
|
18
|
+
const catalog = mergeCatalog(await format.read(catalogOutput, locale), messages, locale === linguiConfig.sourceLocale, { overwrite });
|
|
26
19
|
await format.write(catalogOutput, cleanAndSort(catalog, clean, linguiConfig.orderBy), locale);
|
|
27
20
|
stat[locale] = catalog;
|
|
28
21
|
}
|
|
29
22
|
return {
|
|
30
|
-
statMessage:
|
|
23
|
+
statMessage: printStats(linguiConfig, stat).toString(),
|
|
31
24
|
};
|
|
32
25
|
}
|
|
33
|
-
async function writeTemplate(params) {
|
|
26
|
+
export async function writeTemplate(params) {
|
|
34
27
|
const { entryPoint, outputPattern, linguiConfig, format, clean, messages } = params;
|
|
35
|
-
const catalogOutput =
|
|
28
|
+
const catalogOutput = resolveTemplatePath(entryPoint, outputPattern, linguiConfig.rootDir, format.getTemplateExtension());
|
|
36
29
|
await format.write(catalogOutput, cleanAndSort(messages, clean, linguiConfig.orderBy), undefined);
|
|
37
30
|
return {
|
|
38
|
-
statMessage: `${
|
|
31
|
+
statMessage: `${styleText("bold", String(Object.keys(messages).length))} message(s) extracted`,
|
|
39
32
|
};
|
|
40
33
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineConfig = void 0;
|
|
4
|
-
var conf_1 = require("@lingui/conf");
|
|
5
|
-
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return conf_1.defineConfig; } });
|
|
1
|
+
export { defineConfig } from "@lingui/conf";
|
package/dist/lingui-compile.d.ts
CHANGED