@esgettext/tools 1.0.0 → 1.2.0
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/LICENSE +1 -1
- package/README.md +197 -22
- package/dist/command.js +2 -0
- package/dist/commands/convert.js +286 -0
- package/dist/commands/install.js +257 -0
- package/dist/commands/msgfmt-all.js +219 -0
- package/dist/commands/msgmerge-all.js +230 -0
- package/dist/commands/xgettext/file-resolver.js +20 -0
- package/dist/commands/xgettext/files-collector.js +39 -0
- package/dist/commands/xgettext.js +534 -0
- package/dist/configuration.js +277 -0
- package/dist/esgettext-package-json.js +2 -0
- package/dist/index.js +135 -0
- package/dist/package.js +10 -12
- package/dist/parser/javascript.js +9 -28
- package/dist/parser/parser.js +176 -148
- package/dist/parser/po.js +144 -128
- package/dist/parser/typescript.js +10 -28
- package/dist/pot/catalog.js +134 -83
- package/dist/pot/entry.js +173 -115
- package/dist/pot/keyword.js +66 -92
- package/package.json +38 -25
- package/bin/esgettext-install.js +0 -5
- package/bin/esgettext-mo2json.js +0 -5
- package/bin/esgettext-msgfmt-all.js +0 -5
- package/bin/esgettext-msgmerge-all.js +0 -5
- package/bin/esgettext-xgettext.js +0 -5
- package/dist/cli/getopt.d.ts +0 -34
- package/dist/cli/getopt.js +0 -150
- package/dist/cli/getopt.js.map +0 -1
- package/dist/cli/getopt.spec.d.ts +0 -1
- package/dist/cli/getopt.spec.js +0 -164
- package/dist/cli/getopt.spec.js.map +0 -1
- package/dist/cli/install.d.ts +0 -1
- package/dist/cli/install.js +0 -91
- package/dist/cli/install.js.map +0 -1
- package/dist/cli/mo2json-cli.d.ts +0 -1
- package/dist/cli/mo2json-cli.js +0 -48
- package/dist/cli/mo2json-cli.js.map +0 -1
- package/dist/cli/msgfmt-all.d.ts +0 -1
- package/dist/cli/msgfmt-all.js +0 -99
- package/dist/cli/msgfmt-all.js.map +0 -1
- package/dist/cli/msgmerge-all.d.ts +0 -1
- package/dist/cli/msgmerge-all.js +0 -85
- package/dist/cli/msgmerge-all.js.map +0 -1
- package/dist/cli/xgettext-cli.d.ts +0 -1
- package/dist/cli/xgettext-cli.js +0 -303
- package/dist/cli/xgettext-cli.js.map +0 -1
- package/dist/install/install.d.ts +0 -10
- package/dist/install/install.js +0 -157
- package/dist/install/install.js.map +0 -1
- package/dist/msgfmt-all/msgfmt-all.d.ts +0 -8
- package/dist/msgfmt-all/msgfmt-all.js +0 -142
- package/dist/msgfmt-all/msgfmt-all.js.map +0 -1
- package/dist/msgmerge-all/msgmerge-all.d.ts +0 -9
- package/dist/msgmerge-all/msgmerge-all.js +0 -157
- package/dist/msgmerge-all/msgmerge-all.js.map +0 -1
- package/dist/package.d.ts +0 -4
- package/dist/package.js.map +0 -1
- package/dist/parser/__snapshots__/javascript.spec.js.snap +0 -56
- package/dist/parser/__snapshots__/po.spec.js.snap +0 -176
- package/dist/parser/javascript.d.ts +0 -4
- package/dist/parser/javascript.js.map +0 -1
- package/dist/parser/javascript.spec.d.ts +0 -1
- package/dist/parser/javascript.spec.js +0 -436
- package/dist/parser/javascript.spec.js.map +0 -1
- package/dist/parser/parser.d.ts +0 -45
- package/dist/parser/parser.js.map +0 -1
- package/dist/parser/po.d.ts +0 -22
- package/dist/parser/po.js.map +0 -1
- package/dist/parser/po.spec.d.ts +0 -1
- package/dist/parser/po.spec.js +0 -296
- package/dist/parser/po.spec.js.map +0 -1
- package/dist/parser/typescript.d.ts +0 -4
- package/dist/parser/typescript.js.map +0 -1
- package/dist/parser/typescript.spec.d.ts +0 -1
- package/dist/parser/typescript.spec.js +0 -106
- package/dist/parser/typescript.spec.js.map +0 -1
- package/dist/pot/__snapshots__/catalog.spec.js.snap +0 -591
- package/dist/pot/catalog.d.ts +0 -26
- package/dist/pot/catalog.js.map +0 -1
- package/dist/pot/catalog.spec.d.ts +0 -1
- package/dist/pot/catalog.spec.js +0 -240
- package/dist/pot/catalog.spec.js.map +0 -1
- package/dist/pot/entry.d.ts +0 -35
- package/dist/pot/entry.js.map +0 -1
- package/dist/pot/entry.spec.d.ts +0 -1
- package/dist/pot/entry.spec.js +0 -317
- package/dist/pot/entry.spec.js.map +0 -1
- package/dist/pot/keyword.d.ts +0 -17
- package/dist/pot/keyword.js.map +0 -1
- package/dist/pot/keyword.spec.d.ts +0 -1
- package/dist/pot/keyword.spec.js +0 -54
- package/dist/pot/keyword.spec.js.map +0 -1
- package/dist/xgettext/__snapshots__/xgettext.spec.js.snap +0 -462
- package/dist/xgettext/file-resolver.d.ts +0 -5
- package/dist/xgettext/file-resolver.js +0 -23
- package/dist/xgettext/file-resolver.js.map +0 -1
- package/dist/xgettext/file-resolver.spec.d.ts +0 -1
- package/dist/xgettext/file-resolver.spec.js +0 -22
- package/dist/xgettext/file-resolver.spec.js.map +0 -1
- package/dist/xgettext/files-collector.d.ts +0 -5
- package/dist/xgettext/files-collector.js +0 -41
- package/dist/xgettext/files-collector.js.map +0 -1
- package/dist/xgettext/files-collector.spec.d.ts +0 -1
- package/dist/xgettext/files-collector.spec.js +0 -78
- package/dist/xgettext/files-collector.spec.js.map +0 -1
- package/dist/xgettext/xgettext.d.ts +0 -16
- package/dist/xgettext/xgettext.js +0 -335
- package/dist/xgettext/xgettext.js.map +0 -1
- package/dist/xgettext/xgettext.spec.d.ts +0 -1
- package/dist/xgettext/xgettext.spec.js +0 -743
- package/dist/xgettext/xgettext.spec.js.map +0 -1
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.ConfigurationFactory = exports.ConfigurationSchema = void 0;
|
|
36
|
+
const runtime_1 = require("@esgettext/runtime");
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const v = __importStar(require("valibot"));
|
|
40
|
+
require("@valibot/i18n/de");
|
|
41
|
+
const package_1 = require("./package");
|
|
42
|
+
const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
|
|
43
|
+
const bugsAddressSchema = v.union([
|
|
44
|
+
v.pipe(v.string(), v.nonEmpty(gtx._("The field 'package.msgid-bugs-address' must not be empty!")), v.email(gtx._("The field 'package.msgid-bugs-address' must contain a valid email address or URL!"))),
|
|
45
|
+
v.pipe(v.string(), v.nonEmpty(gtx._("The field 'package.msgid-bugs-address' must not be empty!")), v.url(gtx._("The field 'package.msgid-bugs-address' must contain a valid email address or URL!"))),
|
|
46
|
+
]);
|
|
47
|
+
const programSchema = (program) => {
|
|
48
|
+
return v.strictObject({
|
|
49
|
+
path: v.pipe(v.string(), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", {
|
|
50
|
+
field: `programs.${program}.path`,
|
|
51
|
+
}))),
|
|
52
|
+
options: v.array(v.pipe(v.string(), v.regex(new RegExp('^(?:[A-Z]|[-a-z]{2,})')), v.nonEmpty())),
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
exports.ConfigurationSchema = v.strictObject({
|
|
56
|
+
package: v.optional(v.strictObject({
|
|
57
|
+
textdomain: v.optional(v.pipe(v.string(gtx._x("The field '{field}' must be a string!", {
|
|
58
|
+
field: 'package.textdomain',
|
|
59
|
+
})), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", {
|
|
60
|
+
field: 'package.textdomain',
|
|
61
|
+
})))),
|
|
62
|
+
'msgid-bugs-address': v.optional(bugsAddressSchema),
|
|
63
|
+
name: v.optional(v.pipe(v.string(gtx._x("The field '{field}' must be a string!", {
|
|
64
|
+
field: 'package.name',
|
|
65
|
+
})), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", {
|
|
66
|
+
field: 'package.name',
|
|
67
|
+
})))),
|
|
68
|
+
version: v.optional(v.pipe(v.string(gtx._x("The field '{field}' must be a string!", {
|
|
69
|
+
field: 'package.version',
|
|
70
|
+
})), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", {
|
|
71
|
+
field: 'package.version',
|
|
72
|
+
})))),
|
|
73
|
+
'copyright-holder': v.optional(v.pipe(v.string(gtx._x("The field '{field}' must be a string!", {
|
|
74
|
+
field: 'package.copyright-holder',
|
|
75
|
+
})), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", {
|
|
76
|
+
field: 'package.copyright-holder',
|
|
77
|
+
})))),
|
|
78
|
+
'files-from': v.optional(v.pipe(v.string(gtx._x("The field '{field}' must be a string!", {
|
|
79
|
+
field: 'package.files-from',
|
|
80
|
+
})), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", { field: 'package.files-from' })))),
|
|
81
|
+
})),
|
|
82
|
+
po: v.optional(v.strictObject({
|
|
83
|
+
directory: v.optional(v.pipe(v.string(gtx._x("The field '{field}' must be a string!", {
|
|
84
|
+
field: 'po.directory',
|
|
85
|
+
})), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", { field: 'po.directory' })))),
|
|
86
|
+
locales: v.optional(v.array(v.pipe(v.string(gtx._("The entries in 'po.locales' must be strings!")), v.nonEmpty(gtx._("The entries in 'po.locales' must not be empty!"))))),
|
|
87
|
+
})),
|
|
88
|
+
install: v.optional(v.strictObject({
|
|
89
|
+
directory: v.optional(v.string("The field 'install.directory' must be a string!")),
|
|
90
|
+
})),
|
|
91
|
+
programs: v.optional(v.strictObject({
|
|
92
|
+
msgmerge: v.optional(programSchema('msgmerge')),
|
|
93
|
+
msgfmt: v.optional(programSchema('msgfmt')),
|
|
94
|
+
})),
|
|
95
|
+
files: v.array(v.string()),
|
|
96
|
+
});
|
|
97
|
+
class ConfigurationFactory {
|
|
98
|
+
constructor() { }
|
|
99
|
+
static create(jsConfigFiles, pkgJsonFile, lang) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
102
|
+
if (ConfigurationFactory.instance) {
|
|
103
|
+
return ConfigurationFactory.instance;
|
|
104
|
+
}
|
|
105
|
+
if (lang && !lang.match(/^zh-/)) {
|
|
106
|
+
lang = lang.replace(/-.*/, '');
|
|
107
|
+
}
|
|
108
|
+
let jsConfigFilePath;
|
|
109
|
+
let msgidBugsAddressFilePath;
|
|
110
|
+
let nameFilePath;
|
|
111
|
+
let copyrightHolderFilePath;
|
|
112
|
+
let versionFilePath;
|
|
113
|
+
const rootPath = process.cwd();
|
|
114
|
+
let configuration = null;
|
|
115
|
+
for (const file of jsConfigFiles) {
|
|
116
|
+
const filePath = path.join(rootPath, file);
|
|
117
|
+
if (fs.existsSync(filePath)) {
|
|
118
|
+
const data = yield this.loadFile(filePath);
|
|
119
|
+
if (data) {
|
|
120
|
+
configuration = data;
|
|
121
|
+
configuration.files = [file];
|
|
122
|
+
jsConfigFilePath = file;
|
|
123
|
+
if ((_a = configuration.package) === null || _a === void 0 ? void 0 : _a['msgid-bugs-address']) {
|
|
124
|
+
msgidBugsAddressFilePath = filePath;
|
|
125
|
+
}
|
|
126
|
+
if ((_b = configuration.package) === null || _b === void 0 ? void 0 : _b.name) {
|
|
127
|
+
nameFilePath = filePath;
|
|
128
|
+
}
|
|
129
|
+
if ((_c = configuration.package) === null || _c === void 0 ? void 0 : _c['copyright-holder']) {
|
|
130
|
+
copyrightHolderFilePath = filePath;
|
|
131
|
+
}
|
|
132
|
+
if ((_d = configuration.package) === null || _d === void 0 ? void 0 : _d.version) {
|
|
133
|
+
versionFilePath = filePath;
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Fallback to `package.json` configuration. We also try to read
|
|
143
|
+
// msgid-bugs-address from package.json if not set.
|
|
144
|
+
if (!configuration ||
|
|
145
|
+
!configuration.package ||
|
|
146
|
+
!configuration.package['msgid-bugs-address'] ||
|
|
147
|
+
!configuration.package['name'] ||
|
|
148
|
+
!configuration.package['copyright-holder'] ||
|
|
149
|
+
!configuration.package['version']) {
|
|
150
|
+
const packageJsonPath = pkgJsonFile;
|
|
151
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
152
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
153
|
+
let fileUsed = false;
|
|
154
|
+
if (!configuration && packageJson.esgettext) {
|
|
155
|
+
configuration = packageJson.esgettext;
|
|
156
|
+
configuration.files = [];
|
|
157
|
+
fileUsed = true;
|
|
158
|
+
}
|
|
159
|
+
if (!configuration)
|
|
160
|
+
configuration = { files: [] };
|
|
161
|
+
if (!((_e = configuration.package) === null || _e === void 0 ? void 0 : _e['msgid-bugs-address'])) {
|
|
162
|
+
if ((_f = packageJson.bugs) === null || _f === void 0 ? void 0 : _f.email) {
|
|
163
|
+
(_g = configuration.package) !== null && _g !== void 0 ? _g : (configuration.package = {});
|
|
164
|
+
configuration.package['msgid-bugs-address'] =
|
|
165
|
+
packageJson.bugs.email;
|
|
166
|
+
msgidBugsAddressFilePath = 'package.json';
|
|
167
|
+
fileUsed = true;
|
|
168
|
+
}
|
|
169
|
+
else if ((_h = packageJson.bugs) === null || _h === void 0 ? void 0 : _h.url) {
|
|
170
|
+
(_j = configuration.package) !== null && _j !== void 0 ? _j : (configuration.package = {});
|
|
171
|
+
configuration.package['msgid-bugs-address'] = packageJson.bugs.url;
|
|
172
|
+
msgidBugsAddressFilePath = 'package.json';
|
|
173
|
+
fileUsed = true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (!((_k = configuration.package) === null || _k === void 0 ? void 0 : _k.name)) {
|
|
177
|
+
if (packageJson.name) {
|
|
178
|
+
(_l = configuration.package) !== null && _l !== void 0 ? _l : (configuration.package = {});
|
|
179
|
+
configuration.package.name = packageJson.name;
|
|
180
|
+
nameFilePath = 'package.json';
|
|
181
|
+
fileUsed = true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (!((_m = configuration.package) === null || _m === void 0 ? void 0 : _m['copyright-holder'])) {
|
|
185
|
+
if ((_o = packageJson.people) === null || _o === void 0 ? void 0 : _o.author) {
|
|
186
|
+
(_p = configuration.package) !== null && _p !== void 0 ? _p : (configuration.package = {});
|
|
187
|
+
configuration.package['copyright-holder'] =
|
|
188
|
+
packageJson.people.author;
|
|
189
|
+
copyrightHolderFilePath = 'package.json';
|
|
190
|
+
fileUsed = true;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (!((_q = configuration.package) === null || _q === void 0 ? void 0 : _q.version)) {
|
|
194
|
+
if (packageJson.version) {
|
|
195
|
+
(_r = configuration.package) !== null && _r !== void 0 ? _r : (configuration.package = {});
|
|
196
|
+
configuration.package.version = packageJson.version;
|
|
197
|
+
nameFilePath = 'package.json';
|
|
198
|
+
fileUsed = true;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (fileUsed) {
|
|
202
|
+
configuration.files.push('package.json');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (!configuration)
|
|
207
|
+
configuration = { files: [] };
|
|
208
|
+
const result = v.safeParse(exports.ConfigurationSchema, configuration, { lang });
|
|
209
|
+
if (!result.success) {
|
|
210
|
+
const issues = result.issues;
|
|
211
|
+
console.error(gtx._nx('There is one configuration error:', 'There are {num} configuration errors:', issues.length, { num: issues.length }));
|
|
212
|
+
for (const issue of issues) {
|
|
213
|
+
const path = v.getDotPath(issue) || gtx._('[path not set]');
|
|
214
|
+
const message = issue.issues ? issue.issues[0].message : issue.message;
|
|
215
|
+
let filename;
|
|
216
|
+
switch (path) {
|
|
217
|
+
case 'package.msgid-bugs-address':
|
|
218
|
+
filename = msgidBugsAddressFilePath;
|
|
219
|
+
break;
|
|
220
|
+
case 'name':
|
|
221
|
+
filename = nameFilePath;
|
|
222
|
+
break;
|
|
223
|
+
case 'copyright-holder':
|
|
224
|
+
filename = copyrightHolderFilePath;
|
|
225
|
+
break;
|
|
226
|
+
case 'version':
|
|
227
|
+
filename = versionFilePath;
|
|
228
|
+
break;
|
|
229
|
+
default:
|
|
230
|
+
filename = jsConfigFilePath;
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
console.error(' ' +
|
|
234
|
+
gtx._x('{programName}: error: {filename}: {variable}: {message}.', {
|
|
235
|
+
variable: path,
|
|
236
|
+
programName: 'esgettext',
|
|
237
|
+
filename,
|
|
238
|
+
message,
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
return configuration;
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
static loadFile(filePath) {
|
|
247
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
248
|
+
const extension = path.extname(filePath);
|
|
249
|
+
if (extension === '.mjs' || extension === '.cjs' || extension === '.js') {
|
|
250
|
+
return Promise.resolve(`${filePath}`).then(s => __importStar(require(s))).then(module => module.default)
|
|
251
|
+
.catch(error => {
|
|
252
|
+
console.error(gtx._x('{programName}: {filename}: error reading configuration: {error}', {
|
|
253
|
+
programName: package_1.Package.getName(),
|
|
254
|
+
filename: path.basename(filePath),
|
|
255
|
+
error,
|
|
256
|
+
}));
|
|
257
|
+
return null;
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
else if (extension === '.json') {
|
|
261
|
+
try {
|
|
262
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
263
|
+
}
|
|
264
|
+
catch (_a) {
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
throw new Error(gtx._x("{programName}: Error: {filename}: Configuration file name must end in '.mjs', '.cjs', '.js', or '.json'!", {
|
|
270
|
+
programName: package_1.Package.getName(),
|
|
271
|
+
filename: filePath,
|
|
272
|
+
}));
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
exports.ConfigurationFactory = ConfigurationFactory;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
17
|
+
const package_js_1 = require("./package.js");
|
|
18
|
+
const runtime_1 = require("@esgettext/runtime");
|
|
19
|
+
const configuration_js_1 = require("./configuration.js");
|
|
20
|
+
const xgettext_js_1 = require("./commands/xgettext.js");
|
|
21
|
+
const msgmerge_all_js_1 = require("./commands/msgmerge-all.js");
|
|
22
|
+
const install_js_1 = require("./commands/install.js");
|
|
23
|
+
const convert_js_1 = require("./commands/convert.js");
|
|
24
|
+
const msgfmt_all_js_1 = require("./commands/msgfmt-all.js");
|
|
25
|
+
const commandNames = [
|
|
26
|
+
'xgettext',
|
|
27
|
+
'msgmerge-all',
|
|
28
|
+
'msgfmt-all',
|
|
29
|
+
'install',
|
|
30
|
+
'convert',
|
|
31
|
+
];
|
|
32
|
+
const configFiles = locateConfigFiles();
|
|
33
|
+
const pkgJsonFile = locatePkgJsonFile();
|
|
34
|
+
const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
|
|
35
|
+
gtx
|
|
36
|
+
.resolve()
|
|
37
|
+
.then(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const locale = runtime_1.Textdomain.selectLocale(['en-US', 'en-GB', 'de']);
|
|
39
|
+
const ulocale = locale.replace('-', '_');
|
|
40
|
+
const configuration = yield configuration_js_1.ConfigurationFactory.create(configFiles, pkgJsonFile, locale);
|
|
41
|
+
if (!configuration)
|
|
42
|
+
process.exit(1);
|
|
43
|
+
const commands = {
|
|
44
|
+
xgettext: new xgettext_js_1.XGettext(configuration),
|
|
45
|
+
'msgmerge-all': new msgmerge_all_js_1.MsgmergeAll(configuration),
|
|
46
|
+
'msgfmt-all': new msgfmt_all_js_1.MsgfmtAll(configuration),
|
|
47
|
+
install: new install_js_1.Install(configuration),
|
|
48
|
+
convert: new convert_js_1.Convert(configuration),
|
|
49
|
+
};
|
|
50
|
+
const program = (0, yargs_1.default)(process.argv.slice(2))
|
|
51
|
+
.locale(ulocale)
|
|
52
|
+
.strict()
|
|
53
|
+
.options({
|
|
54
|
+
configuration: {
|
|
55
|
+
alias: ['config-file'],
|
|
56
|
+
type: 'string',
|
|
57
|
+
describe: gtx._('Path to configuration file'),
|
|
58
|
+
default: 'esgettext.config.{mjs,cjs,js,json}'
|
|
59
|
+
},
|
|
60
|
+
package: {
|
|
61
|
+
alias: ['package-json'],
|
|
62
|
+
type: 'string',
|
|
63
|
+
describe: gtx._("Path to 'package.json'"),
|
|
64
|
+
default: 'package.json',
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
.showHelpOnFail(false, gtx._x("Try {programName} '--help' for more information!", {
|
|
68
|
+
programName: package_js_1.Package.getName(),
|
|
69
|
+
}))
|
|
70
|
+
.demandCommand(1, gtx._('Error: No command given.'))
|
|
71
|
+
.scriptName(package_js_1.Package.getName());
|
|
72
|
+
let epilogue = configuration.files.length
|
|
73
|
+
? gtx._x('Additional defaults read from: {files}.', {
|
|
74
|
+
files: configuration.files.join(', '),
|
|
75
|
+
}) + '\n\n'
|
|
76
|
+
: '';
|
|
77
|
+
epilogue += gtx._x('Report bugs in the bugtracker at {url}!', {
|
|
78
|
+
url: package_js_1.Package.getBugTrackerUrl(),
|
|
79
|
+
});
|
|
80
|
+
for (const name of commandNames) {
|
|
81
|
+
const command = commands[name];
|
|
82
|
+
const commandName = command.synopsis()
|
|
83
|
+
? `${name} ${command.synopsis()}`
|
|
84
|
+
: name;
|
|
85
|
+
program.command({
|
|
86
|
+
command: commandName,
|
|
87
|
+
aliases: command.aliases(),
|
|
88
|
+
describe: command.description(),
|
|
89
|
+
builder: (argv) => {
|
|
90
|
+
argv.epilogue(epilogue);
|
|
91
|
+
command.additional(argv);
|
|
92
|
+
return argv.options(command.args());
|
|
93
|
+
},
|
|
94
|
+
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
+
argv._.shift(); // Remove the command name.
|
|
96
|
+
const exitCode = yield command.run(argv);
|
|
97
|
+
process.exit(exitCode);
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
program.help().epilogue(epilogue).parse();
|
|
102
|
+
}))
|
|
103
|
+
.catch((exception) => {
|
|
104
|
+
console.error(gtx._x('{programName}: unhandled exception: {exception}'), {
|
|
105
|
+
programName: package_js_1.Package.getName(),
|
|
106
|
+
exception,
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
function getArgument(option) {
|
|
110
|
+
const longOption = '--' + option;
|
|
111
|
+
const longOptionRe = new RegExp(`^${longOption}=.+`);
|
|
112
|
+
const args = process.argv.slice(2);
|
|
113
|
+
for (const [index, arg] of args.entries()) {
|
|
114
|
+
if (arg == longOption && index < args.length) {
|
|
115
|
+
return args[index + 1];
|
|
116
|
+
}
|
|
117
|
+
else if (arg.match(longOptionRe)) {
|
|
118
|
+
return arg.substring(longOption.length + 1);
|
|
119
|
+
}
|
|
120
|
+
else if (arg[0] !== '-') {
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
function locateConfigFiles() {
|
|
127
|
+
var _a;
|
|
128
|
+
const configFile = (_a = getArgument('config-file')) !== null && _a !== void 0 ? _a : getArgument('configuration');
|
|
129
|
+
return configFile !== null ? [configFile] : ['esgettext.config.mjs', 'esgettext.config.cjs', 'esgettext.config.js', 'esgettext.config.json'];
|
|
130
|
+
}
|
|
131
|
+
function locatePkgJsonFile() {
|
|
132
|
+
var _a;
|
|
133
|
+
const configFile = (_a = getArgument('package')) !== null && _a !== void 0 ? _a : getArgument('package-json');
|
|
134
|
+
return configFile !== null ? configFile : 'package.json';
|
|
135
|
+
}
|
package/dist/package.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Package = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class Package {
|
|
5
|
+
static getName() {
|
|
6
|
+
return 'esgettext';
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
return
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
}());
|
|
8
|
+
static getBugTrackerUrl() {
|
|
9
|
+
return 'https://github.com/gflohr/esgettext/issues';
|
|
10
|
+
}
|
|
11
|
+
static getVersion() {
|
|
12
|
+
return '1.2.0';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
15
|
exports.Package = Package;
|
|
16
|
-
;
|
|
17
|
-
//# sourceMappingURL=package.js.map
|
|
@@ -1,35 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.JavaScriptParser = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
25
|
-
}
|
|
26
|
-
JavaScriptParser.prototype.doParse = function (input, filename) {
|
|
27
|
-
var ast = (0, parser_1.parse)(input, {
|
|
4
|
+
const parser_1 = require("@babel/parser");
|
|
5
|
+
const parser_2 = require("./parser");
|
|
6
|
+
class JavaScriptParser extends parser_2.Parser {
|
|
7
|
+
doParse(input, filename) {
|
|
8
|
+
const ast = (0, parser_1.parse)(input, {
|
|
28
9
|
allowAwaitOutsideFunction: true,
|
|
29
10
|
allowImportExportEverywhere: true,
|
|
30
11
|
allowReturnOutsideFunction: true,
|
|
31
12
|
allowSuperOutsideMethod: true,
|
|
32
13
|
allowUndeclaredExports: true,
|
|
14
|
+
// Documented but not supported. FIXME! Maybe only missing in types.
|
|
15
|
+
// errorRecovery: true,
|
|
33
16
|
sourceFilename: filename,
|
|
34
17
|
plugins: [
|
|
35
18
|
'flow',
|
|
@@ -40,8 +23,6 @@ var JavaScriptParser = (function (_super) {
|
|
|
40
23
|
],
|
|
41
24
|
});
|
|
42
25
|
return this.extract(filename, ast);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
}(parser_2.Parser));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
46
28
|
exports.JavaScriptParser = JavaScriptParser;
|
|
47
|
-
//# sourceMappingURL=javascript.js.map
|