@esgettext/tools 1.1.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 +1 -1
- package/dist/command.js +0 -1
- package/dist/commands/convert.js +16 -14
- package/dist/commands/install.js +12 -4
- package/dist/commands/msgfmt-all.js +65 -46
- package/dist/commands/msgmerge-all.js +64 -46
- package/dist/commands/xgettext/file-resolver.js +0 -1
- package/dist/commands/xgettext/files-collector.js +1 -1
- package/dist/commands/xgettext.js +16 -7
- package/dist/configuration.js +172 -156
- package/dist/esgettext-package-json.js +0 -1
- package/dist/index.js +75 -24
- package/dist/package.js +1 -2
- package/dist/parser/javascript.js +2 -1
- package/dist/parser/parser.js +17 -2
- package/dist/parser/po.js +34 -1
- package/dist/parser/typescript.js +2 -1
- package/dist/pot/catalog.js +36 -1
- package/dist/pot/entry.js +71 -1
- package/dist/pot/keyword.js +10 -5
- package/package.json +5 -4
- package/dist/command.d.ts +0 -11
- package/dist/command.js.map +0 -1
- package/dist/commands/convert.d.ts +0 -24
- package/dist/commands/convert.js.map +0 -1
- package/dist/commands/install.d.ts +0 -22
- package/dist/commands/install.js.map +0 -1
- package/dist/commands/msgfmt-all.d.ts +0 -20
- package/dist/commands/msgfmt-all.js.map +0 -1
- package/dist/commands/msgmerge-all.d.ts +0 -21
- package/dist/commands/msgmerge-all.js.map +0 -1
- package/dist/commands/xgettext/file-resolver.d.ts +0 -5
- package/dist/commands/xgettext/file-resolver.js.map +0 -1
- package/dist/commands/xgettext/file-resolver.spec.d.ts +0 -1
- package/dist/commands/xgettext/file-resolver.spec.js +0 -22
- package/dist/commands/xgettext/file-resolver.spec.js.map +0 -1
- package/dist/commands/xgettext/files-collector.d.ts +0 -5
- package/dist/commands/xgettext/files-collector.js.map +0 -1
- package/dist/commands/xgettext/files-collector.spec.d.ts +0 -1
- package/dist/commands/xgettext/files-collector.spec.js +0 -96
- package/dist/commands/xgettext/files-collector.spec.js.map +0 -1
- package/dist/commands/xgettext.d.ts +0 -29
- package/dist/commands/xgettext.js.map +0 -1
- package/dist/commands/xgettext.spec.d.ts +0 -1
- package/dist/commands/xgettext.spec.js +0 -897
- package/dist/commands/xgettext.spec.js.map +0 -1
- package/dist/configuration.d.ts +0 -36
- package/dist/configuration.js.map +0 -1
- package/dist/esgettext-package-json.d.ts +0 -15
- package/dist/esgettext-package-json.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js.map +0 -1
- package/dist/package.d.ts +0 -5
- package/dist/package.js.map +0 -1
- 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 -535
- 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 -486
- 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 -121
- package/dist/parser/typescript.spec.js.map +0 -1
- 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 -244
- 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 -433
- 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/configuration.js
CHANGED
|
@@ -22,6 +22,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
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
|
+
};
|
|
25
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
35
|
exports.ConfigurationFactory = exports.ConfigurationSchema = void 0;
|
|
27
36
|
const runtime_1 = require("@esgettext/runtime");
|
|
@@ -66,11 +75,14 @@ exports.ConfigurationSchema = v.strictObject({
|
|
|
66
75
|
})), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", {
|
|
67
76
|
field: 'package.copyright-holder',
|
|
68
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' })))),
|
|
69
81
|
})),
|
|
70
82
|
po: v.optional(v.strictObject({
|
|
71
|
-
directory: v.optional(v.string(gtx._x("The field '{field}' must be a string!", {
|
|
83
|
+
directory: v.optional(v.pipe(v.string(gtx._x("The field '{field}' must be a string!", {
|
|
72
84
|
field: 'po.directory',
|
|
73
|
-
}))),
|
|
85
|
+
})), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", { field: 'po.directory' })))),
|
|
74
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!"))))),
|
|
75
87
|
})),
|
|
76
88
|
install: v.optional(v.strictObject({
|
|
@@ -84,178 +96,182 @@ exports.ConfigurationSchema = v.strictObject({
|
|
|
84
96
|
});
|
|
85
97
|
class ConfigurationFactory {
|
|
86
98
|
constructor() { }
|
|
87
|
-
static
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
lang
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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;
|
|
124
136
|
}
|
|
125
|
-
|
|
126
|
-
|
|
137
|
+
else {
|
|
138
|
+
return null;
|
|
127
139
|
}
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
return null;
|
|
132
140
|
}
|
|
133
141
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
!configuration
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
configuration
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
if (!configuration)
|
|
151
|
-
configuration = { files: [] };
|
|
152
|
-
if (!((_e = configuration.package) === null || _e === void 0 ? void 0 : _e['msgid-bugs-address'])) {
|
|
153
|
-
if ((_f = packageJson.bugs) === null || _f === void 0 ? void 0 : _f.email) {
|
|
154
|
-
(_g = configuration.package) !== null && _g !== void 0 ? _g : (configuration.package = {});
|
|
155
|
-
configuration.package['msgid-bugs-address'] =
|
|
156
|
-
packageJson.bugs.email;
|
|
157
|
-
msgidBugsAddressFilePath = 'package.json';
|
|
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 = [];
|
|
158
157
|
fileUsed = true;
|
|
159
158
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
+
}
|
|
165
175
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
+
}
|
|
173
183
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
+
}
|
|
182
192
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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');
|
|
190
203
|
}
|
|
191
|
-
}
|
|
192
|
-
if (fileUsed) {
|
|
193
|
-
configuration.files.push('package.json');
|
|
194
204
|
}
|
|
195
205
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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
|
+
}));
|
|
223
240
|
}
|
|
224
|
-
|
|
225
|
-
gtx._x('{programName}: error: {filename}: {variable}: {message}.', {
|
|
226
|
-
variable: path,
|
|
227
|
-
programName: 'esgettext',
|
|
228
|
-
filename,
|
|
229
|
-
message,
|
|
230
|
-
}));
|
|
241
|
+
return null;
|
|
231
242
|
}
|
|
232
|
-
return
|
|
233
|
-
}
|
|
234
|
-
return configuration;
|
|
243
|
+
return configuration;
|
|
244
|
+
});
|
|
235
245
|
}
|
|
236
|
-
static
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
.
|
|
241
|
-
|
|
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'!", {
|
|
242
270
|
programName: package_1.Package.getName(),
|
|
243
|
-
filename:
|
|
244
|
-
error,
|
|
271
|
+
filename: filePath,
|
|
245
272
|
}));
|
|
246
|
-
return null;
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
else if (extension === '.json') {
|
|
250
|
-
try {
|
|
251
|
-
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
252
|
-
}
|
|
253
|
-
catch (_a) {
|
|
254
|
-
return null;
|
|
255
273
|
}
|
|
256
|
-
}
|
|
257
|
-
return null;
|
|
274
|
+
});
|
|
258
275
|
}
|
|
259
276
|
}
|
|
260
277
|
exports.ConfigurationFactory = ConfigurationFactory;
|
|
261
|
-
//# sourceMappingURL=configuration.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
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
|
+
};
|
|
3
12
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
14
|
};
|
|
6
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
16
|
const yargs_1 = __importDefault(require("yargs"));
|
|
8
|
-
const
|
|
17
|
+
const package_js_1 = require("./package.js");
|
|
9
18
|
const runtime_1 = require("@esgettext/runtime");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
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");
|
|
16
25
|
const commandNames = [
|
|
17
26
|
'xgettext',
|
|
18
27
|
'msgmerge-all',
|
|
@@ -20,37 +29,53 @@ const commandNames = [
|
|
|
20
29
|
'install',
|
|
21
30
|
'convert',
|
|
22
31
|
];
|
|
32
|
+
const configFiles = locateConfigFiles();
|
|
33
|
+
const pkgJsonFile = locatePkgJsonFile();
|
|
23
34
|
const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
|
|
24
35
|
gtx
|
|
25
36
|
.resolve()
|
|
26
|
-
.then(
|
|
37
|
+
.then(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
38
|
const locale = runtime_1.Textdomain.selectLocale(['en-US', 'en-GB', 'de']);
|
|
28
39
|
const ulocale = locale.replace('-', '_');
|
|
29
|
-
const configuration =
|
|
40
|
+
const configuration = yield configuration_js_1.ConfigurationFactory.create(configFiles, pkgJsonFile, locale);
|
|
30
41
|
if (!configuration)
|
|
31
42
|
process.exit(1);
|
|
32
43
|
const commands = {
|
|
33
|
-
xgettext: new
|
|
34
|
-
'msgmerge-all': new
|
|
35
|
-
'msgfmt-all': new
|
|
36
|
-
install: new
|
|
37
|
-
convert: new
|
|
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),
|
|
38
49
|
};
|
|
39
50
|
const program = (0, yargs_1.default)(process.argv.slice(2))
|
|
40
51
|
.locale(ulocale)
|
|
41
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
|
+
})
|
|
42
67
|
.showHelpOnFail(false, gtx._x("Try {programName} '--help' for more information!", {
|
|
43
|
-
programName:
|
|
68
|
+
programName: package_js_1.Package.getName(),
|
|
44
69
|
}))
|
|
45
70
|
.demandCommand(1, gtx._('Error: No command given.'))
|
|
46
|
-
.scriptName(
|
|
71
|
+
.scriptName(package_js_1.Package.getName());
|
|
47
72
|
let epilogue = configuration.files.length
|
|
48
73
|
? gtx._x('Additional defaults read from: {files}.', {
|
|
49
74
|
files: configuration.files.join(', '),
|
|
50
75
|
}) + '\n\n'
|
|
51
76
|
: '';
|
|
52
77
|
epilogue += gtx._x('Report bugs in the bugtracker at {url}!', {
|
|
53
|
-
url:
|
|
78
|
+
url: package_js_1.Package.getBugTrackerUrl(),
|
|
54
79
|
});
|
|
55
80
|
for (const name of commandNames) {
|
|
56
81
|
const command = commands[name];
|
|
@@ -66,19 +91,45 @@ gtx
|
|
|
66
91
|
command.additional(argv);
|
|
67
92
|
return argv.options(command.args());
|
|
68
93
|
},
|
|
69
|
-
handler:
|
|
70
|
-
argv._.shift();
|
|
71
|
-
const exitCode =
|
|
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);
|
|
72
97
|
process.exit(exitCode);
|
|
73
|
-
},
|
|
98
|
+
}),
|
|
74
99
|
});
|
|
75
100
|
}
|
|
76
101
|
program.help().epilogue(epilogue).parse();
|
|
77
|
-
})
|
|
102
|
+
}))
|
|
78
103
|
.catch((exception) => {
|
|
79
104
|
console.error(gtx._x('{programName}: unhandled exception: {exception}'), {
|
|
80
|
-
programName:
|
|
105
|
+
programName: package_js_1.Package.getName(),
|
|
81
106
|
exception,
|
|
82
107
|
});
|
|
83
108
|
});
|
|
84
|
-
|
|
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
|
@@ -11,6 +11,8 @@ class JavaScriptParser extends parser_2.Parser {
|
|
|
11
11
|
allowReturnOutsideFunction: true,
|
|
12
12
|
allowSuperOutsideMethod: true,
|
|
13
13
|
allowUndeclaredExports: true,
|
|
14
|
+
// Documented but not supported. FIXME! Maybe only missing in types.
|
|
15
|
+
// errorRecovery: true,
|
|
14
16
|
sourceFilename: filename,
|
|
15
17
|
plugins: [
|
|
16
18
|
'flow',
|
|
@@ -24,4 +26,3 @@ class JavaScriptParser extends parser_2.Parser {
|
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
exports.JavaScriptParser = JavaScriptParser;
|
|
27
|
-
//# sourceMappingURL=javascript.js.map
|