@lingui/cli 4.0.0-next.4 → 4.0.0-next.5
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.js +64 -0
- package/dist/api/catalog/getCatalogs.js +137 -0
- package/dist/api/catalog/getTranslationsForCatalog.js +68 -0
- package/dist/api/catalog/mergeCatalog.js +86 -0
- package/dist/api/catalog.js +286 -0
- package/dist/api/compile.js +115 -0
- package/dist/api/extractors/babel.js +158 -0
- package/dist/api/extractors/index.js +44 -0
- package/dist/api/extractors/typescript.js +15 -0
- package/dist/api/formats/formatterWrapper.js +48 -0
- package/dist/api/formats/index.js +95 -0
- package/dist/api/help.js +41 -0
- package/dist/api/index.js +31 -0
- package/dist/api/pseudoLocalize.js +60 -0
- package/dist/api/rethrownError.js +16 -0
- package/dist/api/stats.js +73 -0
- package/{build → dist}/api/types.js +2 -3
- package/dist/api/utils.js +117 -0
- package/dist/extract-experimental/buildExternalizeFilter.js +83 -0
- package/dist/extract-experimental/bundleSource.js +127 -0
- package/dist/extract-experimental/constants.js +16 -0
- package/dist/extract-experimental/getEntryPoints.js +20 -0
- package/dist/extract-experimental/getExperimentalCatalogs.js +30 -0
- package/dist/extract-experimental/resolveCatalogPath.js +34 -0
- package/dist/extract-experimental/resolveTemplatePath.js +19 -0
- package/dist/extract-experimental/writeCatalogs.js +54 -0
- package/dist/lingui-compile.js +158 -0
- package/dist/lingui-extract-experimental.js +113 -0
- package/dist/lingui-extract-template.js +52 -0
- package/dist/lingui-extract.js +192 -0
- package/dist/lingui.js +8 -0
- package/dist/services/translationIO.js +261 -0
- package/dist/tests.js +137 -0
- package/package.json +19 -13
- 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/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
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
|
-
}
|
package/build/lingui-extract.js
DELETED
|
@@ -1,143 +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 _chokidar = _interopRequireDefault(require("chokidar"));
|
|
9
|
-
var _commander = require("commander");
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
var _conf = require("@lingui/conf");
|
|
12
|
-
var _api = require("./api");
|
|
13
|
-
var _stats = require("./api/stats");
|
|
14
|
-
var _help = require("./api/help");
|
|
15
|
-
var _ora = _interopRequireDefault(require("ora"));
|
|
16
|
-
var _utils = require("./api/utils");
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
|
-
async function command(config, options) {
|
|
21
|
-
options.verbose && console.log("Extracting messages from source files…");
|
|
22
|
-
const catalogs = await (0, _api.getCatalogs)(config);
|
|
23
|
-
const catalogStats = {};
|
|
24
|
-
let commandSuccess = true;
|
|
25
|
-
const spinner = (0, _ora.default)().start();
|
|
26
|
-
for (let catalog of catalogs) {
|
|
27
|
-
const result = await catalog.make({
|
|
28
|
-
...options,
|
|
29
|
-
orderBy: config.orderBy
|
|
30
|
-
});
|
|
31
|
-
catalogStats[(0, _utils.normalizeSlashes)(_path.default.relative(config.rootDir, catalog.path))] = result || {};
|
|
32
|
-
commandSuccess && (commandSuccess = Boolean(result));
|
|
33
|
-
}
|
|
34
|
-
if (commandSuccess) {
|
|
35
|
-
spinner.succeed();
|
|
36
|
-
} else {
|
|
37
|
-
spinner.fail();
|
|
38
|
-
}
|
|
39
|
-
Object.entries(catalogStats).forEach(([key, value]) => {
|
|
40
|
-
console.log(`Catalog statistics for ${key}: `);
|
|
41
|
-
console.log((0, _stats.printStats)(config, value).toString());
|
|
42
|
-
console.log();
|
|
43
|
-
});
|
|
44
|
-
if (!options.watch) {
|
|
45
|
-
console.log(`(use "${_chalk.default.yellow((0, _help.helpRun)("extract"))}" to update catalogs with new messages)`);
|
|
46
|
-
console.log(`(use "${_chalk.default.yellow((0, _help.helpRun)("compile"))}" to compile catalogs for production)`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// If service key is present in configuration, synchronize with cloud translation platform
|
|
50
|
-
if (typeof config.service === "object" && config.service.name && config.service.name.length) {
|
|
51
|
-
const moduleName = config.service.name.charAt(0).toLowerCase() + config.service.name.slice(1);
|
|
52
|
-
await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`./services/${moduleName}`).then(module => module.default(config, options)).catch(err => console.error(`Can't load service module ${moduleName}`, err));
|
|
53
|
-
}
|
|
54
|
-
return commandSuccess;
|
|
55
|
-
}
|
|
56
|
-
if (require.main === module) {
|
|
57
|
-
_commander.program.option("--config <path>", "Path to the config file").option("--locale <locale>", "Only extract the specified locale").option("--overwrite", "Overwrite translations for source locale").option("--clean", "Remove obsolete translations").option("--debounce <delay>", "Debounces extraction for given amount of milliseconds").option("--verbose", "Verbose output").option("--convert-from <format>", "Convert from previous format of message catalogs").option("--watch", "Enables Watch Mode").parse(process.argv);
|
|
58
|
-
const options = _commander.program.opts();
|
|
59
|
-
const config = (0, _conf.getConfig)({
|
|
60
|
-
configPath: options.config
|
|
61
|
-
});
|
|
62
|
-
let hasErrors = false;
|
|
63
|
-
const prevFormat = options.convertFrom;
|
|
64
|
-
if (prevFormat && config.format === prevFormat) {
|
|
65
|
-
hasErrors = true;
|
|
66
|
-
console.error("Trying to migrate message catalog to the same format");
|
|
67
|
-
console.error(`Set ${_chalk.default.bold("new")} format in LinguiJS configuration\n` + ` and ${_chalk.default.bold("previous")} format using --convert-from option.`);
|
|
68
|
-
console.log();
|
|
69
|
-
console.log(`Example: Convert from lingui format to minimal`);
|
|
70
|
-
console.log(_chalk.default.yellow((0, _help.helpRun)(`extract --convert-from lingui`)));
|
|
71
|
-
process.exit(1);
|
|
72
|
-
}
|
|
73
|
-
if (options.locale && !config.locales.includes(options.locale)) {
|
|
74
|
-
hasErrors = true;
|
|
75
|
-
console.error(`Locale ${_chalk.default.bold(options.locale)} does not exist.`);
|
|
76
|
-
console.error();
|
|
77
|
-
}
|
|
78
|
-
if (hasErrors) process.exit(1);
|
|
79
|
-
const extract = filePath => {
|
|
80
|
-
return command(config, {
|
|
81
|
-
verbose: options.watch || options.verbose || false,
|
|
82
|
-
clean: options.watch ? false : options.clean || false,
|
|
83
|
-
overwrite: options.watch || options.overwrite || false,
|
|
84
|
-
locale: options.locale,
|
|
85
|
-
watch: options.watch || false,
|
|
86
|
-
files: filePath !== null && filePath !== void 0 && filePath.length ? filePath : undefined,
|
|
87
|
-
prevFormat
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
const changedPaths = new Set();
|
|
91
|
-
let debounceTimer;
|
|
92
|
-
let previousExtract = Promise.resolve(true);
|
|
93
|
-
const dispatchExtract = filePath => {
|
|
94
|
-
// Skip debouncing if not enabled but still chain them so no racing issue
|
|
95
|
-
// on deleting the tmp folder.
|
|
96
|
-
if (!options.debounce) {
|
|
97
|
-
previousExtract = previousExtract.then(() => extract(filePath));
|
|
98
|
-
return previousExtract;
|
|
99
|
-
}
|
|
100
|
-
filePath === null || filePath === void 0 ? void 0 : filePath.forEach(path => changedPaths.add(path));
|
|
101
|
-
|
|
102
|
-
// CLear the previous timer if there is any, and schedule the next
|
|
103
|
-
debounceTimer && clearTimeout(debounceTimer);
|
|
104
|
-
debounceTimer = setTimeout(async () => {
|
|
105
|
-
const filePath = [...changedPaths];
|
|
106
|
-
changedPaths.clear();
|
|
107
|
-
await extract(filePath);
|
|
108
|
-
}, options.debounce);
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// Check if Watch Mode is enabled
|
|
112
|
-
if (options.watch) {
|
|
113
|
-
console.info(_chalk.default.bold("Initializing Watch Mode..."));
|
|
114
|
-
(async function initWatch() {
|
|
115
|
-
const catalogs = await (0, _api.getCatalogs)(config);
|
|
116
|
-
let paths = [];
|
|
117
|
-
let ignored = [];
|
|
118
|
-
catalogs.forEach(catalog => {
|
|
119
|
-
paths.push(...catalog.include);
|
|
120
|
-
ignored.push(...catalog.exclude);
|
|
121
|
-
});
|
|
122
|
-
const watcher = _chokidar.default.watch(paths, {
|
|
123
|
-
ignored: ["/(^|[/\\])../", ...ignored],
|
|
124
|
-
persistent: true
|
|
125
|
-
});
|
|
126
|
-
const onReady = () => {
|
|
127
|
-
console.info(_chalk.default.green.bold("Watcher is ready!"));
|
|
128
|
-
watcher.on("add", path => dispatchExtract([path])).on("change", path => dispatchExtract([path]));
|
|
129
|
-
};
|
|
130
|
-
watcher.on("ready", () => onReady());
|
|
131
|
-
})();
|
|
132
|
-
} else if (_commander.program.args) {
|
|
133
|
-
// this behaviour occurs when we extract files by his name
|
|
134
|
-
// for ex: lingui extract src/app, this will extract only files included in src/app
|
|
135
|
-
extract(_commander.program.args).then(result => {
|
|
136
|
-
if (!result) process.exit(1);
|
|
137
|
-
});
|
|
138
|
-
} else {
|
|
139
|
-
extract().then(result => {
|
|
140
|
-
if (!result) process.exit(1);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}
|
package/build/lingui.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
var _commander = require("commander");
|
|
5
|
-
var _package = require("../package.json");
|
|
6
|
-
_commander.program.version(_package.version).command("extract [files...]", "Extracts messages from source files").command("extract-experimental", "Extracts messages from source files traversing dependency tree").command("extract-template", "Extracts messages from source files to a .pot template").command("compile", "Compile message catalogs").parse(process.argv);
|