@lingui/cli 4.0.0-next.4 → 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.
- package/dist/api/catalog/extractFromFiles.d.ts +5 -0
- package/dist/api/catalog/extractFromFiles.js +47 -0
- package/dist/api/catalog/getCatalogs.d.ts +14 -0
- package/dist/api/catalog/getCatalogs.js +129 -0
- package/dist/api/catalog/getTranslationsForCatalog.d.ts +14 -0
- package/dist/api/catalog/getTranslationsForCatalog.js +72 -0
- package/dist/api/catalog/mergeCatalog.d.ts +3 -0
- package/dist/api/catalog/mergeCatalog.js +55 -0
- package/dist/api/catalog.d.ts +66 -0
- package/dist/api/catalog.js +261 -0
- package/dist/api/compile.d.ts +19 -0
- package/dist/api/compile.js +88 -0
- package/dist/api/extractors/babel.d.ts +3 -0
- package/dist/api/extractors/babel.js +101 -0
- package/dist/api/extractors/index.d.ts +6 -0
- package/dist/api/extractors/index.js +38 -0
- package/dist/api/extractors/typescript.d.ts +3 -0
- package/dist/api/extractors/typescript.js +11 -0
- package/dist/api/formats/formatterWrapper.d.ts +10 -0
- package/dist/api/formats/formatterWrapper.js +43 -0
- package/dist/api/formats/index.d.ts +5 -0
- package/dist/api/formats/index.js +47 -0
- package/dist/api/help.d.ts +1 -0
- package/dist/api/help.js +40 -0
- package/dist/api/index.d.ts +4 -0
- package/dist/api/index.js +25 -0
- package/dist/api/pseudoLocalize.d.ts +1 -0
- package/dist/api/pseudoLocalize.js +56 -0
- package/dist/api/rethrownError.d.ts +4 -0
- package/dist/api/rethrownError.js +11 -0
- package/dist/api/stats.d.ts +6 -0
- package/dist/api/stats.js +41 -0
- package/dist/api/types.d.ts +5 -0
- package/dist/api/types.js +2 -0
- package/dist/api/utils.d.ts +22 -0
- package/dist/api/utils.js +119 -0
- package/dist/extract-experimental/buildExternalizeFilter.d.ts +13 -0
- package/dist/extract-experimental/buildExternalizeFilter.js +38 -0
- package/dist/extract-experimental/bundleSource.d.ts +2 -0
- package/dist/extract-experimental/bundleSource.js +78 -0
- package/dist/extract-experimental/constants.d.ts +2 -0
- package/dist/extract-experimental/constants.js +5 -0
- package/dist/extract-experimental/getEntryPoints.d.ts +1 -0
- package/dist/extract-experimental/getEntryPoints.js +12 -0
- package/dist/extract-experimental/getExperimentalCatalogs.d.ts +3 -0
- package/dist/extract-experimental/getExperimentalCatalogs.js +26 -0
- package/dist/extract-experimental/resolveCatalogPath.d.ts +2 -0
- package/dist/extract-experimental/resolveCatalogPath.js +23 -0
- package/dist/extract-experimental/resolveTemplatePath.d.ts +1 -0
- package/dist/extract-experimental/resolveTemplatePath.js +16 -0
- package/dist/extract-experimental/writeCatalogs.d.ts +21 -0
- package/dist/extract-experimental/writeCatalogs.js +41 -0
- package/dist/lingui-compile.d.ts +9 -0
- package/dist/lingui-compile.js +170 -0
- package/dist/lingui-extract-experimental.d.ts +10 -0
- package/dist/lingui-extract-experimental.js +104 -0
- package/dist/lingui-extract-template.d.ts +6 -0
- package/dist/lingui-extract-template.js +46 -0
- package/dist/lingui-extract.d.ts +11 -0
- package/dist/lingui-extract.js +156 -0
- package/dist/lingui.d.ts +2 -0
- package/dist/lingui.js +13 -0
- package/dist/services/translationIO.d.ts +3 -0
- package/dist/services/translationIO.js +264 -0
- package/package.json +29 -14
- package/build/LICENSE +0 -21
- package/build/api/catalog/extractFromFiles.js +0 -45
- package/build/api/catalog/getCatalogs.js +0 -138
- package/build/api/catalog/getTranslationsForCatalog.js +0 -77
- package/build/api/catalog/mergeCatalog.js +0 -44
- package/build/api/catalog.js +0 -245
- package/build/api/compile.js +0 -72
- package/build/api/extractors/babel.js +0 -92
- package/build/api/extractors/index.js +0 -36
- package/build/api/extractors/typescript.js +0 -14
- package/build/api/formats/formatterWrapper.js +0 -45
- package/build/api/formats/index.js +0 -57
- package/build/api/generateMessageId.js +0 -12
- package/build/api/help.js +0 -42
- package/build/api/index.js +0 -58
- package/build/api/pseudoLocalize.js +0 -60
- package/build/api/rethrownError.js +0 -14
- package/build/api/stats.js +0 -40
- package/build/api/types.js +0 -5
- package/build/api/utils.js +0 -117
- package/build/extract-experimental/buildExternalizeFilter.js +0 -39
- package/build/extract-experimental/bundleSource.js +0 -69
- package/build/extract-experimental/constants.js +0 -10
- package/build/extract-experimental/getEntryPoints.js +0 -14
- package/build/extract-experimental/getExperimentalCatalogs.js +0 -28
- package/build/extract-experimental/resolveCatalogPath.js +0 -23
- package/build/extract-experimental/resolveTemplatePath.js +0 -17
- package/build/extract-experimental/writeCatalogs.js +0 -59
- package/build/lingui-compile.js +0 -156
- package/build/lingui-extract-experimental.js +0 -103
- package/build/lingui-extract-template.js +0 -46
- package/build/lingui-extract.js +0 -143
- package/build/lingui.js +0 -6
- package/build/services/translationIO.js +0 -266
- package/build/tests.js +0 -133
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.buildExternalizeFilter = buildExternalizeFilter;
|
|
7
|
-
exports.getPackageJson = getPackageJson;
|
|
8
|
-
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); }
|
|
9
|
-
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; }
|
|
10
|
-
function createPackageRegExp(packageName) {
|
|
11
|
-
return new RegExp("^" + packageName + "(?:\\/.+)?");
|
|
12
|
-
}
|
|
13
|
-
function packages(packages, includeDeps) {
|
|
14
|
-
return Object.keys(packages || {}).filter(packageName => {
|
|
15
|
-
return !includeDeps.some(incl => packageName.startsWith(incl));
|
|
16
|
-
}).map(createPackageRegExp);
|
|
17
|
-
}
|
|
18
|
-
function buildExternalizeFilter({
|
|
19
|
-
includeDeps,
|
|
20
|
-
excludeDeps,
|
|
21
|
-
packageJson
|
|
22
|
-
}) {
|
|
23
|
-
const external = [...packages(packageJson.dependencies, includeDeps), ...packages(packageJson.devDependencies, includeDeps), ...packages(packageJson.peerDependencies, includeDeps), ...packages(packageJson.optionalDependencies, includeDeps), ...excludeDeps.map(createPackageRegExp)];
|
|
24
|
-
return id => external.some(regExp => {
|
|
25
|
-
return regExp.test(id);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
async function getPackageJson(rootDir) {
|
|
29
|
-
const {
|
|
30
|
-
default: pkgUp
|
|
31
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require("pkg-up")));
|
|
32
|
-
const packageJsonPath = await pkgUp({
|
|
33
|
-
cwd: rootDir
|
|
34
|
-
});
|
|
35
|
-
if (!packageJsonPath) {
|
|
36
|
-
throw new Error("We could not able to find your package.json file. " + "Check that `rootDir` is pointing to the folder with package.json");
|
|
37
|
-
}
|
|
38
|
-
return await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(packageJsonPath);
|
|
39
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.bundleSource = bundleSource;
|
|
7
|
-
var _buildExternalizeFilter = require("./buildExternalizeFilter");
|
|
8
|
-
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); }
|
|
9
|
-
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; }
|
|
10
|
-
function createExtRegExp(extensions) {
|
|
11
|
-
return new RegExp("\\.(?:" + extensions.join("|") + ")(?:\\?.*)?$");
|
|
12
|
-
}
|
|
13
|
-
async function bundleSource(config, entryPoints, outDir, rootDir) {
|
|
14
|
-
const esbuild = await Promise.resolve().then(() => _interopRequireWildcard(require("esbuild")));
|
|
15
|
-
const excludeExtensions = config.excludeExtensions || ["ico", "pot", "xliff", "woff2", "woff", "eot", "gif", "otf", "ttf", "mp4", "svg", "png", "css", "sass", "less", "jpg"];
|
|
16
|
-
const packageJson = await (0, _buildExternalizeFilter.getPackageJson)(rootDir);
|
|
17
|
-
const esbuildOptions = {
|
|
18
|
-
entryPoints: entryPoints,
|
|
19
|
-
outExtension: {
|
|
20
|
-
".js": ".jsx"
|
|
21
|
-
},
|
|
22
|
-
jsx: "preserve",
|
|
23
|
-
bundle: true,
|
|
24
|
-
platform: "node",
|
|
25
|
-
target: ["esnext"],
|
|
26
|
-
format: "esm",
|
|
27
|
-
splitting: false,
|
|
28
|
-
treeShaking: true,
|
|
29
|
-
outdir: outDir,
|
|
30
|
-
sourcemap: "inline",
|
|
31
|
-
sourceRoot: outDir,
|
|
32
|
-
sourcesContent: false,
|
|
33
|
-
outbase: rootDir,
|
|
34
|
-
metafile: true,
|
|
35
|
-
plugins: [{
|
|
36
|
-
name: "externalize-deps",
|
|
37
|
-
setup(build) {
|
|
38
|
-
const isExternal = (0, _buildExternalizeFilter.buildExternalizeFilter)({
|
|
39
|
-
includeDeps: config.includeDeps || [],
|
|
40
|
-
excludeDeps: config.excludeDeps || [],
|
|
41
|
-
packageJson
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// externalize bare imports
|
|
45
|
-
build.onResolve({
|
|
46
|
-
filter: /^[^.].*/
|
|
47
|
-
}, async ({
|
|
48
|
-
path: id
|
|
49
|
-
}) => {
|
|
50
|
-
if (isExternal(id)) {
|
|
51
|
-
return {
|
|
52
|
-
external: true
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}, {
|
|
58
|
-
name: "externalize-files",
|
|
59
|
-
setup(build) {
|
|
60
|
-
build.onResolve({
|
|
61
|
-
filter: createExtRegExp(excludeExtensions)
|
|
62
|
-
}, () => ({
|
|
63
|
-
external: true
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
}]
|
|
67
|
-
};
|
|
68
|
-
return await esbuild.build(config.resolveEsbuildOptions ? config.resolveEsbuildOptions(esbuildOptions) : esbuildOptions);
|
|
69
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ENTRY_NAME_PH = exports.DEFAULT_TEMPLATE_NAME = void 0;
|
|
7
|
-
const ENTRY_NAME_PH = "{entryName}";
|
|
8
|
-
exports.ENTRY_NAME_PH = ENTRY_NAME_PH;
|
|
9
|
-
const DEFAULT_TEMPLATE_NAME = "messages";
|
|
10
|
-
exports.DEFAULT_TEMPLATE_NAME = DEFAULT_TEMPLATE_NAME;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getEntryPoints = getEntryPoints;
|
|
7
|
-
var _glob = _interopRequireDefault(require("glob"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
function getEntryPoints(entries) {
|
|
10
|
-
const patterns = entries.length > 1 ? `{${entries.join(",")}}` : entries[0];
|
|
11
|
-
return _glob.default.sync(patterns, {
|
|
12
|
-
mark: true
|
|
13
|
-
});
|
|
14
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getExperimentalCatalogs = getExperimentalCatalogs;
|
|
7
|
-
var _getEntryPoints = require("./getEntryPoints");
|
|
8
|
-
var _resolveCatalogPath = require("./resolveCatalogPath");
|
|
9
|
-
var _catalog = require("../api/catalog");
|
|
10
|
-
var _resolveTemplatePath = require("./resolveTemplatePath");
|
|
11
|
-
var _api = require("@lingui/cli/api");
|
|
12
|
-
async function getExperimentalCatalogs(linguiConfig) {
|
|
13
|
-
const config = linguiConfig.experimental.extractor;
|
|
14
|
-
const entryPoints = (0, _getEntryPoints.getEntryPoints)(config.entries);
|
|
15
|
-
const format = await (0, _api.getFormat)(linguiConfig.format, linguiConfig.formatOptions, linguiConfig.sourceLocale);
|
|
16
|
-
return entryPoints.map(entryPoint => {
|
|
17
|
-
const catalogPath = (0, _resolveCatalogPath.resolveCatalogPath)(config.output, entryPoint, linguiConfig.rootDir, undefined, "");
|
|
18
|
-
const templatePath = (0, _resolveTemplatePath.resolveTemplatePath)(entryPoint, config.output, linguiConfig.rootDir, format.getTemplateExtension());
|
|
19
|
-
return new _catalog.Catalog({
|
|
20
|
-
name: undefined,
|
|
21
|
-
path: catalogPath,
|
|
22
|
-
templatePath,
|
|
23
|
-
include: [],
|
|
24
|
-
exclude: [],
|
|
25
|
-
format
|
|
26
|
-
}, linguiConfig);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getEntryName = getEntryName;
|
|
7
|
-
exports.resolveCatalogPath = resolveCatalogPath;
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
var _utils = require("../api/utils");
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function resolveCatalogPath(configOutput, entryPath, rootDir, locale, extension) {
|
|
12
|
-
const entryName = getEntryName(entryPath);
|
|
13
|
-
const entryDir = _path.default.relative(rootDir, _path.default.dirname(entryPath));
|
|
14
|
-
return _path.default.normalize((0, _utils.replacePlaceholders)(configOutput, {
|
|
15
|
-
entryName,
|
|
16
|
-
entryDir,
|
|
17
|
-
locale
|
|
18
|
-
}) + extension);
|
|
19
|
-
}
|
|
20
|
-
function getEntryName(entryPath) {
|
|
21
|
-
const parsedPath = _path.default.parse(entryPath);
|
|
22
|
-
return parsedPath.name.replace(parsedPath.ext, "");
|
|
23
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.resolveTemplatePath = resolveTemplatePath;
|
|
7
|
-
var _resolveCatalogPath = require("./resolveCatalogPath");
|
|
8
|
-
var _constants = require("./constants");
|
|
9
|
-
function resolveTemplatePath(entryPoint, output, rootDir, catalogExtension) {
|
|
10
|
-
let templateName;
|
|
11
|
-
if (output.includes(_constants.ENTRY_NAME_PH)) {
|
|
12
|
-
templateName = _constants.DEFAULT_TEMPLATE_NAME;
|
|
13
|
-
} else {
|
|
14
|
-
templateName = (0, _resolveCatalogPath.getEntryName)(entryPoint);
|
|
15
|
-
}
|
|
16
|
-
return (0, _resolveCatalogPath.resolveCatalogPath)(output, entryPoint, rootDir, templateName, catalogExtension);
|
|
17
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.writeCatalogs = writeCatalogs;
|
|
7
|
-
exports.writeTemplate = writeTemplate;
|
|
8
|
-
var _resolveTemplatePath = require("./resolveTemplatePath");
|
|
9
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
10
|
-
var _resolveCatalogPath = require("./resolveCatalogPath");
|
|
11
|
-
var _mergeCatalog = require("../api/catalog/mergeCatalog");
|
|
12
|
-
var _stats = require("../api/stats");
|
|
13
|
-
var _catalog = require("../api/catalog");
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
function cleanAndSort(catalog, clean, orderBy) {
|
|
16
|
-
if (clean) {
|
|
17
|
-
catalog = (0, _catalog.cleanObsolete)(catalog);
|
|
18
|
-
}
|
|
19
|
-
return (0, _catalog.order)(orderBy)(catalog);
|
|
20
|
-
}
|
|
21
|
-
async function writeCatalogs(params) {
|
|
22
|
-
const {
|
|
23
|
-
entryPoint,
|
|
24
|
-
outputPattern,
|
|
25
|
-
linguiConfig,
|
|
26
|
-
locales,
|
|
27
|
-
overwrite,
|
|
28
|
-
format,
|
|
29
|
-
clean,
|
|
30
|
-
messages
|
|
31
|
-
} = params;
|
|
32
|
-
const stat = {};
|
|
33
|
-
for (const locale of locales) {
|
|
34
|
-
const catalogOutput = (0, _resolveCatalogPath.resolveCatalogPath)(outputPattern, entryPoint, linguiConfig.rootDir, locale, format.getCatalogExtension());
|
|
35
|
-
const catalog = (0, _mergeCatalog.mergeCatalog)(await format.read(catalogOutput, locale), messages, locale === linguiConfig.sourceLocale, {
|
|
36
|
-
overwrite
|
|
37
|
-
});
|
|
38
|
-
await format.write(catalogOutput, cleanAndSort(catalog, clean, linguiConfig.orderBy), locale);
|
|
39
|
-
stat[locale] = catalog;
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
statMessage: (0, _stats.printStats)(linguiConfig, stat).toString()
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
async function writeTemplate(params) {
|
|
46
|
-
const {
|
|
47
|
-
entryPoint,
|
|
48
|
-
outputPattern,
|
|
49
|
-
linguiConfig,
|
|
50
|
-
format,
|
|
51
|
-
clean,
|
|
52
|
-
messages
|
|
53
|
-
} = params;
|
|
54
|
-
const catalogOutput = (0, _resolveTemplatePath.resolveTemplatePath)(entryPoint, outputPattern, linguiConfig.rootDir, format.getTemplateExtension());
|
|
55
|
-
await format.write(catalogOutput, cleanAndSort(messages, clean, linguiConfig.orderBy), undefined);
|
|
56
|
-
return {
|
|
57
|
-
statMessage: `${_chalk.default.bold(Object.keys(messages).length)} message(s) extracted`
|
|
58
|
-
};
|
|
59
|
-
}
|
package/build/lingui-compile.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.command = command;
|
|
7
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
8
|
-
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
9
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
10
|
-
var _commander = require("commander");
|
|
11
|
-
var _conf = require("@lingui/conf");
|
|
12
|
-
var _compile = require("./api/compile");
|
|
13
|
-
var _help = require("./api/help");
|
|
14
|
-
var _api = require("./api");
|
|
15
|
-
var _getCatalogs = require("./api/catalog/getCatalogs");
|
|
16
|
-
var _utils = require("./api/utils");
|
|
17
|
-
var _path = _interopRequireDefault(require("path"));
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
async function command(config, options) {
|
|
20
|
-
const catalogs = await (0, _api.getCatalogs)(config);
|
|
21
|
-
|
|
22
|
-
// Check config.compile.merge if catalogs for current locale are to be merged into a single compiled file
|
|
23
|
-
const doMerge = !!config.catalogsMergePath;
|
|
24
|
-
let mergedCatalogs = {};
|
|
25
|
-
console.log("Compiling message catalogs…");
|
|
26
|
-
for (const locale of config.locales) {
|
|
27
|
-
for (const catalog of catalogs) {
|
|
28
|
-
const missingMessages = [];
|
|
29
|
-
const messages = await catalog.getTranslations(locale, {
|
|
30
|
-
fallbackLocales: config.fallbackLocales,
|
|
31
|
-
sourceLocale: config.sourceLocale,
|
|
32
|
-
onMissing: missing => {
|
|
33
|
-
missingMessages.push(missing);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
if (!options.allowEmpty && missingMessages.length > 0) {
|
|
37
|
-
console.error(_chalk.default.red(`Error: Failed to compile catalog for locale ${_chalk.default.bold(locale)}!`));
|
|
38
|
-
if (options.verbose) {
|
|
39
|
-
console.error(_chalk.default.red("Missing translations:"));
|
|
40
|
-
missingMessages.forEach(missing => {
|
|
41
|
-
const source = missing.source || missing.source === missing.id ? `: (${missing.source})` : "";
|
|
42
|
-
console.error(`${missing.id}${source}`);
|
|
43
|
-
});
|
|
44
|
-
} else {
|
|
45
|
-
console.error(_chalk.default.red(`Missing ${missingMessages.length} translation(s)`));
|
|
46
|
-
}
|
|
47
|
-
console.error();
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
if (doMerge) {
|
|
51
|
-
mergedCatalogs = {
|
|
52
|
-
...mergedCatalogs,
|
|
53
|
-
...messages
|
|
54
|
-
};
|
|
55
|
-
} else {
|
|
56
|
-
const namespace = options.typescript ? "ts" : options.namespace || config.compileNamespace;
|
|
57
|
-
const compiledCatalog = (0, _compile.createCompiledCatalog)(locale, messages, {
|
|
58
|
-
strict: false,
|
|
59
|
-
namespace,
|
|
60
|
-
pseudoLocale: config.pseudoLocale,
|
|
61
|
-
compilerBabelOptions: config.compilerBabelOptions
|
|
62
|
-
});
|
|
63
|
-
let compiledPath = await catalog.writeCompiled(locale, compiledCatalog, namespace);
|
|
64
|
-
if (options.typescript) {
|
|
65
|
-
const typescriptPath = compiledPath.replace(/\.ts?$/, "") + ".d.ts";
|
|
66
|
-
_fs.default.writeFileSync(typescriptPath, `import { Messages } from '@lingui/core';
|
|
67
|
-
declare const messages: Messages;
|
|
68
|
-
export { messages };
|
|
69
|
-
`);
|
|
70
|
-
}
|
|
71
|
-
compiledPath = (0, _utils.normalizeSlashes)(_path.default.relative(config.rootDir, compiledPath));
|
|
72
|
-
options.verbose && console.error(_chalk.default.green(`${locale} ⇒ ${compiledPath}`));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (doMerge) {
|
|
76
|
-
const compileCatalog = await (0, _getCatalogs.getCatalogForMerge)(config);
|
|
77
|
-
const namespace = options.namespace || config.compileNamespace;
|
|
78
|
-
const compiledCatalog = (0, _compile.createCompiledCatalog)(locale, mergedCatalogs, {
|
|
79
|
-
strict: false,
|
|
80
|
-
namespace: namespace,
|
|
81
|
-
pseudoLocale: config.pseudoLocale,
|
|
82
|
-
compilerBabelOptions: config.compilerBabelOptions
|
|
83
|
-
});
|
|
84
|
-
let compiledPath = await compileCatalog.writeCompiled(locale, compiledCatalog, namespace);
|
|
85
|
-
compiledPath = (0, _utils.normalizeSlashes)(_path.default.relative(config.rootDir, compiledPath));
|
|
86
|
-
options.verbose && console.log(_chalk.default.green(`${locale} ⇒ ${compiledPath}`));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
if (require.main === module) {
|
|
92
|
-
_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 () {
|
|
93
|
-
console.log("\n Examples:\n");
|
|
94
|
-
console.log(" # Compile translations and use defaults or message IDs for missing translations");
|
|
95
|
-
console.log(` $ ${(0, _help.helpRun)("compile")}`);
|
|
96
|
-
console.log("");
|
|
97
|
-
console.log(" # Compile translations but fail when there are missing");
|
|
98
|
-
console.log(" # translations (don't replace missing translations with");
|
|
99
|
-
console.log(" # default messages or message IDs)");
|
|
100
|
-
console.log(` $ ${(0, _help.helpRun)("compile --strict")}`);
|
|
101
|
-
}).parse(process.argv);
|
|
102
|
-
const options = _commander.program.opts();
|
|
103
|
-
const config = (0, _conf.getConfig)({
|
|
104
|
-
configPath: options.config
|
|
105
|
-
});
|
|
106
|
-
let previousRun = Promise.resolve(true);
|
|
107
|
-
const compile = () => {
|
|
108
|
-
previousRun = previousRun.then(() => command(config, {
|
|
109
|
-
verbose: options.watch || options.verbose || false,
|
|
110
|
-
allowEmpty: !options.strict,
|
|
111
|
-
typescript: options.typescript || config.compileNamespace === "ts" || false,
|
|
112
|
-
namespace: options.namespace // we want this to be undefined if user does not specify so default can be used
|
|
113
|
-
}));
|
|
114
|
-
|
|
115
|
-
return previousRun;
|
|
116
|
-
};
|
|
117
|
-
let debounceTimer;
|
|
118
|
-
const dispatchCompile = () => {
|
|
119
|
-
// Skip debouncing if not enabled
|
|
120
|
-
if (!options.debounce) compile();
|
|
121
|
-
|
|
122
|
-
// CLear the previous timer if there is any, and schedule the next
|
|
123
|
-
debounceTimer && clearTimeout(debounceTimer);
|
|
124
|
-
debounceTimer = setTimeout(() => compile(), options.debounce);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
// Check if Watch Mode is enabled
|
|
128
|
-
if (options.watch) {
|
|
129
|
-
console.info(_chalk.default.bold("Initializing Watch Mode..."));
|
|
130
|
-
(async function initWatch() {
|
|
131
|
-
const format = await (0, _api.getFormat)(config.format, config.formatOptions, config.sourceLocale);
|
|
132
|
-
const catalogs = await (0, _api.getCatalogs)(config);
|
|
133
|
-
const paths = [];
|
|
134
|
-
config.locales.forEach(locale => {
|
|
135
|
-
catalogs.forEach(catalog => {
|
|
136
|
-
paths.push(`${catalog.path.replace(/{locale}/g, locale).replace(/{name}/g, "*")}${format.getCatalogExtension()}`);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
const watcher = _chokidar.default.watch(paths, {
|
|
140
|
-
persistent: true
|
|
141
|
-
});
|
|
142
|
-
const onReady = () => {
|
|
143
|
-
console.info(_chalk.default.green.bold("Watcher is ready!"));
|
|
144
|
-
watcher.on("add", () => dispatchCompile()).on("change", () => dispatchCompile());
|
|
145
|
-
};
|
|
146
|
-
watcher.on("ready", () => onReady());
|
|
147
|
-
})();
|
|
148
|
-
} else {
|
|
149
|
-
compile().then(results => {
|
|
150
|
-
if (!results) {
|
|
151
|
-
process.exit(1);
|
|
152
|
-
}
|
|
153
|
-
console.log("Done!");
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = command;
|
|
7
|
-
var _commander = require("commander");
|
|
8
|
-
var _conf = require("@lingui/conf");
|
|
9
|
-
var _path = _interopRequireDefault(require("path"));
|
|
10
|
-
var _os = _interopRequireDefault(require("os"));
|
|
11
|
-
var _formats = require("./api/formats");
|
|
12
|
-
var _promises = _interopRequireDefault(require("fs/promises"));
|
|
13
|
-
var _extractFromFiles = require("./api/catalog/extractFromFiles");
|
|
14
|
-
var _utils = require("./api/utils");
|
|
15
|
-
var _bundleSource = require("./extract-experimental/bundleSource");
|
|
16
|
-
var _writeCatalogs = require("./extract-experimental/writeCatalogs");
|
|
17
|
-
var _getEntryPoints = require("./extract-experimental/getEntryPoints");
|
|
18
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
19
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
async function command(linguiConfig, options) {
|
|
21
|
-
var _linguiConfig$experim;
|
|
22
|
-
options.verbose && console.log("Extracting messages from source files…");
|
|
23
|
-
const config = (_linguiConfig$experim = linguiConfig.experimental) === null || _linguiConfig$experim === void 0 ? void 0 : _linguiConfig$experim.extractor;
|
|
24
|
-
if (!config) {
|
|
25
|
-
throw new Error("The configuration for experimental extractor is empty. Please read the docs.");
|
|
26
|
-
}
|
|
27
|
-
console.log(_chalk.default.yellow(["You have using an experimental feature", "Experimental features are not covered by semver, and may cause unexpected or broken application behavior." + " Use at your own risk.", ""].join("\n")));
|
|
28
|
-
const tempDir = await _promises.default.mkdtemp(_path.default.join(_os.default.tmpdir(), "js-lingui-extract-"));
|
|
29
|
-
await _promises.default.rm(tempDir, {
|
|
30
|
-
recursive: true,
|
|
31
|
-
force: true
|
|
32
|
-
});
|
|
33
|
-
const bundleResult = await (0, _bundleSource.bundleSource)(config, (0, _getEntryPoints.getEntryPoints)(config.entries), tempDir, linguiConfig.rootDir);
|
|
34
|
-
const stats = [];
|
|
35
|
-
let commandSuccess = true;
|
|
36
|
-
const format = await (0, _formats.getFormat)(linguiConfig.format, linguiConfig.formatOptions, linguiConfig.sourceLocale);
|
|
37
|
-
for (const outFile of Object.keys(bundleResult.metafile.outputs)) {
|
|
38
|
-
const messages = await (0, _extractFromFiles.extractFromFiles)([outFile], linguiConfig);
|
|
39
|
-
const {
|
|
40
|
-
entryPoint
|
|
41
|
-
} = bundleResult.metafile.outputs[outFile];
|
|
42
|
-
let output;
|
|
43
|
-
if (!messages) {
|
|
44
|
-
commandSuccess = false;
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
if (options.template) {
|
|
48
|
-
output = (await (0, _writeCatalogs.writeTemplate)({
|
|
49
|
-
linguiConfig,
|
|
50
|
-
clean: options.clean,
|
|
51
|
-
format,
|
|
52
|
-
messages,
|
|
53
|
-
entryPoint,
|
|
54
|
-
outputPattern: config.output
|
|
55
|
-
})).statMessage;
|
|
56
|
-
} else {
|
|
57
|
-
output = (await (0, _writeCatalogs.writeCatalogs)({
|
|
58
|
-
locales: options.locales || linguiConfig.locales,
|
|
59
|
-
linguiConfig,
|
|
60
|
-
clean: options.clean,
|
|
61
|
-
format,
|
|
62
|
-
messages,
|
|
63
|
-
entryPoint,
|
|
64
|
-
overwrite: options.overwrite,
|
|
65
|
-
outputPattern: config.output
|
|
66
|
-
})).statMessage;
|
|
67
|
-
}
|
|
68
|
-
stats.push({
|
|
69
|
-
entry: (0, _utils.normalizeSlashes)(_path.default.relative(linguiConfig.rootDir, entryPoint)),
|
|
70
|
-
content: output
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// cleanup temp directory
|
|
75
|
-
await _promises.default.rm(tempDir, {
|
|
76
|
-
recursive: true,
|
|
77
|
-
force: true
|
|
78
|
-
});
|
|
79
|
-
stats.forEach(({
|
|
80
|
-
entry,
|
|
81
|
-
content
|
|
82
|
-
}) => {
|
|
83
|
-
console.log([`Catalog statistics for ${entry}:`, content, ""].join("\n"));
|
|
84
|
-
});
|
|
85
|
-
return commandSuccess;
|
|
86
|
-
}
|
|
87
|
-
if (require.main === module) {
|
|
88
|
-
var _options$locale;
|
|
89
|
-
_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);
|
|
90
|
-
const options = _commander.program.opts();
|
|
91
|
-
const config = (0, _conf.getConfig)({
|
|
92
|
-
configPath: options.config
|
|
93
|
-
});
|
|
94
|
-
const result = command(config, {
|
|
95
|
-
verbose: options.verbose || false,
|
|
96
|
-
template: options.template,
|
|
97
|
-
locales: (_options$locale = options.locale) === null || _options$locale === void 0 ? void 0 : _options$locale.split(","),
|
|
98
|
-
overwrite: options.overwrite,
|
|
99
|
-
clean: options.clean
|
|
100
|
-
}).then(() => {
|
|
101
|
-
if (!result) process.exit(1);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = command;
|
|
7
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
8
|
-
var _commander = require("commander");
|
|
9
|
-
var _conf = require("@lingui/conf");
|
|
10
|
-
var _api = require("./api");
|
|
11
|
-
var _path = _interopRequireDefault(require("path"));
|
|
12
|
-
var _utils = require("./api/utils");
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
async function command(config, options) {
|
|
15
|
-
options.verbose && console.log("Extracting messages from source files…");
|
|
16
|
-
const catalogs = await (0, _api.getCatalogs)(config);
|
|
17
|
-
const catalogStats = {};
|
|
18
|
-
let commandSuccess = true;
|
|
19
|
-
await Promise.all(catalogs.map(async catalog => {
|
|
20
|
-
const result = await catalog.makeTemplate({
|
|
21
|
-
...options,
|
|
22
|
-
orderBy: config.orderBy
|
|
23
|
-
});
|
|
24
|
-
if (result) {
|
|
25
|
-
catalogStats[(0, _utils.normalizeSlashes)(_path.default.relative(config.rootDir, catalog.templateFile))] = Object.keys(result).length;
|
|
26
|
-
}
|
|
27
|
-
commandSuccess && (commandSuccess = Boolean(result));
|
|
28
|
-
}));
|
|
29
|
-
Object.entries(catalogStats).forEach(([key, value]) => {
|
|
30
|
-
console.log(`Catalog statistics for ${_chalk.default.bold(key)}: ${_chalk.default.green(value)} messages`);
|
|
31
|
-
console.log();
|
|
32
|
-
});
|
|
33
|
-
return commandSuccess;
|
|
34
|
-
}
|
|
35
|
-
if (require.main === module) {
|
|
36
|
-
_commander.program.option("--config <path>", "Path to the config file").option("--verbose", "Verbose output").parse(process.argv);
|
|
37
|
-
const options = _commander.program.opts();
|
|
38
|
-
const config = (0, _conf.getConfig)({
|
|
39
|
-
configPath: options.config
|
|
40
|
-
});
|
|
41
|
-
const result = command(config, {
|
|
42
|
-
verbose: options.verbose || false
|
|
43
|
-
}).then(() => {
|
|
44
|
-
if (!result) process.exit(1);
|
|
45
|
-
});
|
|
46
|
-
}
|