@esgettext/tools 1.1.0 → 1.3.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/add-language.js +100 -0
- package/dist/commands/convert.js +17 -15
- package/dist/commands/init.js +743 -0
- package/dist/commands/install.js +21 -6
- package/dist/commands/msgfmt-all.js +72 -50
- package/dist/commands/msgmerge-all.js +71 -49
- package/dist/commands/potfiles.js +165 -0
- package/dist/commands/xgettext/file-resolver.js +0 -1
- package/dist/commands/xgettext/files-collector.js +1 -1
- package/dist/commands/xgettext.js +37 -17
- package/dist/configuration.js +174 -115
- package/dist/esgettext-package-json.js +0 -1
- package/dist/index.js +97 -29
- package/dist/optspec.js +28 -0
- package/dist/package.js +4 -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 +11 -6
- 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
|
@@ -33,9 +33,14 @@ const files_collector_1 = require("./xgettext/files-collector");
|
|
|
33
33
|
const typescript_1 = require("../parser/typescript");
|
|
34
34
|
const javascript_1 = require("../parser/javascript");
|
|
35
35
|
const keyword_1 = require("../pot/keyword");
|
|
36
|
+
const optspec_1 = require("../optspec");
|
|
36
37
|
const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
|
|
37
38
|
class XGettext {
|
|
39
|
+
// The date is only passed for testing.
|
|
38
40
|
constructor(configuration, date) {
|
|
41
|
+
this.catalog = undefined;
|
|
42
|
+
this.exclude = undefined;
|
|
43
|
+
this.options = undefined;
|
|
39
44
|
this.date = date;
|
|
40
45
|
this.configuration = configuration;
|
|
41
46
|
}
|
|
@@ -49,21 +54,22 @@ class XGettext {
|
|
|
49
54
|
return ['extract'];
|
|
50
55
|
}
|
|
51
56
|
args() {
|
|
52
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
57
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
53
58
|
const outputFile = ((_a = this.configuration.package) === null || _a === void 0 ? void 0 : _a.textdomain)
|
|
54
59
|
? `${this.configuration.package.textdomain}.pot`
|
|
55
60
|
: undefined;
|
|
56
61
|
return {
|
|
57
62
|
'files-from': {
|
|
63
|
+
multi: true,
|
|
58
64
|
group: gtx._('Input file location:'),
|
|
59
65
|
type: 'string',
|
|
60
|
-
array: true,
|
|
61
66
|
describe: gtx._('get list of input files from FILE'),
|
|
67
|
+
default: (_b = this.configuration.package) === null || _b === void 0 ? void 0 : _b['files-from'],
|
|
62
68
|
},
|
|
63
69
|
directory: {
|
|
70
|
+
multi: true,
|
|
64
71
|
group: gtx._('Input file location:'),
|
|
65
72
|
type: 'string',
|
|
66
|
-
array: true,
|
|
67
73
|
describe: gtx._('add directory to list for input files search\nIf input file is -, standard input is read.'),
|
|
68
74
|
},
|
|
69
75
|
'default-domain': {
|
|
@@ -84,7 +90,7 @@ class XGettext {
|
|
|
84
90
|
alias: 'p',
|
|
85
91
|
type: 'string',
|
|
86
92
|
describe: gtx._('output files will be placed in directory DIR. If output file is -, output is written to standard output.'),
|
|
87
|
-
default: (
|
|
93
|
+
default: (_d = (_c = this.configuration.po) === null || _c === void 0 ? void 0 : _c.directory) !== null && _d !== void 0 ? _d : '.',
|
|
88
94
|
},
|
|
89
95
|
language: {
|
|
90
96
|
group: gtx._('Choice of input file language:'),
|
|
@@ -107,18 +113,18 @@ class XGettext {
|
|
|
107
113
|
describe: gtx._('join messages with existing file'),
|
|
108
114
|
},
|
|
109
115
|
'exclude-file': {
|
|
116
|
+
multi: true,
|
|
110
117
|
group: gtx._('Operation mode:'),
|
|
111
118
|
alias: 'x',
|
|
112
119
|
type: 'string',
|
|
113
120
|
describe: gtx._('entries from FILE.po are not extracted'),
|
|
114
|
-
array: true,
|
|
115
121
|
},
|
|
116
122
|
'add-comments': {
|
|
123
|
+
multi: true,
|
|
117
124
|
group: gtx._('Operation mode:'),
|
|
118
125
|
alias: 'c',
|
|
119
126
|
type: 'string',
|
|
120
127
|
describe: gtx._('place comment blocks starting with TAG and preceding keyword lines in output file'),
|
|
121
|
-
array: true,
|
|
122
128
|
},
|
|
123
129
|
'add-all-comments': {
|
|
124
130
|
group: gtx._('Operation mode:'),
|
|
@@ -132,22 +138,22 @@ class XGettext {
|
|
|
132
138
|
describe: gtx._('extract all strings'),
|
|
133
139
|
},
|
|
134
140
|
keyword: {
|
|
141
|
+
multi: true,
|
|
135
142
|
group: gtx._('Language specific options:'),
|
|
136
143
|
type: 'string',
|
|
137
144
|
describe: gtx._('look for WORD as an additional keyword'),
|
|
138
|
-
array: true,
|
|
139
145
|
},
|
|
140
146
|
flag: {
|
|
147
|
+
multi: true,
|
|
141
148
|
group: gtx._('Language specific options:'),
|
|
142
149
|
type: 'string',
|
|
143
150
|
describe: gtx._('argument: WORD:ARG:FLAG, additional flag for strings inside the argument number ARG of keyword WORD'),
|
|
144
|
-
array: true,
|
|
145
151
|
},
|
|
146
152
|
instance: {
|
|
153
|
+
multi: true,
|
|
147
154
|
group: gtx._('Language specific options:'),
|
|
148
155
|
type: 'string',
|
|
149
156
|
describe: gtx._('only accept method calls of specified instance names'),
|
|
150
|
-
array: true,
|
|
151
157
|
},
|
|
152
158
|
'force-po': {
|
|
153
159
|
group: gtx._('Output details:'),
|
|
@@ -188,7 +194,7 @@ class XGettext {
|
|
|
188
194
|
group: gtx._('Output details:'),
|
|
189
195
|
type: 'string',
|
|
190
196
|
describe: gtx._('set copyright holder in output'),
|
|
191
|
-
default: (
|
|
197
|
+
default: (_e = this.configuration.package) === null || _e === void 0 ? void 0 : _e['copyright-holder'],
|
|
192
198
|
},
|
|
193
199
|
'foreign-user': {
|
|
194
200
|
group: gtx._('Output details:'),
|
|
@@ -199,19 +205,19 @@ class XGettext {
|
|
|
199
205
|
group: gtx._('Output details:'),
|
|
200
206
|
type: 'string',
|
|
201
207
|
describe: gtx._('set package name in output'),
|
|
202
|
-
default: (
|
|
208
|
+
default: (_f = this.configuration.package) === null || _f === void 0 ? void 0 : _f.name,
|
|
203
209
|
},
|
|
204
210
|
'package-version': {
|
|
205
211
|
group: gtx._('Output details:'),
|
|
206
212
|
type: 'string',
|
|
207
213
|
describe: gtx._('set package version in output'),
|
|
208
|
-
default: (
|
|
214
|
+
default: (_g = this.configuration.package) === null || _g === void 0 ? void 0 : _g.version,
|
|
209
215
|
},
|
|
210
216
|
'msgid-bugs-address': {
|
|
211
217
|
group: gtx._('Output details:'),
|
|
212
218
|
type: 'string',
|
|
213
219
|
describe: gtx._('set report address for msgid bugs'),
|
|
214
|
-
default: (
|
|
220
|
+
default: (_h = this.configuration.package) === null || _h === void 0 ? void 0 : _h['msgid-bugs-address'],
|
|
215
221
|
},
|
|
216
222
|
'msgstr-prefix': {
|
|
217
223
|
group: gtx._('Output details:'),
|
|
@@ -232,7 +238,13 @@ class XGettext {
|
|
|
232
238
|
},
|
|
233
239
|
};
|
|
234
240
|
}
|
|
235
|
-
|
|
241
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
242
|
+
additional(argv) {
|
|
243
|
+
argv.positional(gtx._('INPUTFILE'), {
|
|
244
|
+
type: 'string',
|
|
245
|
+
describe: gtx._('input files'),
|
|
246
|
+
});
|
|
247
|
+
}
|
|
236
248
|
init(argv) {
|
|
237
249
|
var _a, _b, _c, _d, _e;
|
|
238
250
|
const options = argv;
|
|
@@ -312,12 +324,14 @@ class XGettext {
|
|
|
312
324
|
}
|
|
313
325
|
let fileCollector;
|
|
314
326
|
try {
|
|
315
|
-
fileCollector = new files_collector_1.FilesCollector(this.options.filesFrom, this.options._);
|
|
327
|
+
fileCollector = new files_collector_1.FilesCollector(this.options.filesFrom, this.options[gtx._('INPUTFILE')]);
|
|
316
328
|
}
|
|
317
329
|
catch (e) {
|
|
318
330
|
console.error(`${this.options.$0}: ${e}`);
|
|
319
331
|
return 1;
|
|
320
332
|
}
|
|
333
|
+
// FIXME! The file collector must interpret all filenames relative to
|
|
334
|
+
// the files-from file's director.
|
|
321
335
|
fileCollector.filenames.forEach(filename => {
|
|
322
336
|
try {
|
|
323
337
|
if (!this.parse(this.readFile(filename), filename)) {
|
|
@@ -347,8 +361,11 @@ class XGettext {
|
|
|
347
361
|
return exitCode;
|
|
348
362
|
}
|
|
349
363
|
run(argv) {
|
|
350
|
-
this.init(argv);
|
|
351
364
|
return new Promise(resolve => {
|
|
365
|
+
if (!(0, optspec_1.coerceOptions)(argv, this.args())) {
|
|
366
|
+
return resolve(1);
|
|
367
|
+
}
|
|
368
|
+
this.init(argv);
|
|
352
369
|
try {
|
|
353
370
|
resolve(this.doRun());
|
|
354
371
|
}
|
|
@@ -374,6 +391,7 @@ class XGettext {
|
|
|
374
391
|
return process.stdin.read();
|
|
375
392
|
}
|
|
376
393
|
const directories = this.options.directory || [''];
|
|
394
|
+
// Avoid ugly absolute paths.
|
|
377
395
|
const resolve = (dir, file) => {
|
|
378
396
|
if (dir === '') {
|
|
379
397
|
return file;
|
|
@@ -388,6 +406,7 @@ class XGettext {
|
|
|
388
406
|
return (0, fs_1.readFileSync)(fullName);
|
|
389
407
|
}
|
|
390
408
|
catch (e) {
|
|
409
|
+
/* ignore */
|
|
391
410
|
}
|
|
392
411
|
}
|
|
393
412
|
return (0, fs_1.readFileSync)(resolve(directories[directories.length - 1], filename));
|
|
@@ -402,6 +421,8 @@ class XGettext {
|
|
|
402
421
|
break;
|
|
403
422
|
case '.js':
|
|
404
423
|
case '.jsx':
|
|
424
|
+
case '.mjs':
|
|
425
|
+
case '.cjs':
|
|
405
426
|
parser = new javascript_1.JavaScriptParser(this.catalog, parserOptions);
|
|
406
427
|
break;
|
|
407
428
|
case '.po':
|
|
@@ -522,4 +543,3 @@ class XGettext {
|
|
|
522
543
|
}
|
|
523
544
|
}
|
|
524
545
|
exports.XGettext = XGettext;
|
|
525
|
-
//# sourceMappingURL=xgettext.js.map
|
package/dist/configuration.js
CHANGED
|
@@ -22,9 +22,23 @@ 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
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
25
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
38
|
exports.ConfigurationFactory = exports.ConfigurationSchema = void 0;
|
|
27
39
|
const runtime_1 = require("@esgettext/runtime");
|
|
40
|
+
const package_json_1 = __importDefault(require("@npmcli/package-json"));
|
|
41
|
+
const normalize_package_data_1 = __importDefault(require("normalize-package-data"));
|
|
28
42
|
const fs = __importStar(require("fs"));
|
|
29
43
|
const path = __importStar(require("path"));
|
|
30
44
|
const v = __importStar(require("valibot"));
|
|
@@ -37,10 +51,10 @@ const bugsAddressSchema = v.union([
|
|
|
37
51
|
]);
|
|
38
52
|
const programSchema = (program) => {
|
|
39
53
|
return v.strictObject({
|
|
40
|
-
path: v.pipe(v.string(), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", {
|
|
54
|
+
path: v.optional(v.pipe(v.string(), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", {
|
|
41
55
|
field: `programs.${program}.path`,
|
|
42
|
-
}))),
|
|
43
|
-
options: v.array(v.pipe(v.string(), v.regex(new RegExp('^(?:[A-Z]|[-a-z]{2,})')), v.nonEmpty())),
|
|
56
|
+
})))),
|
|
57
|
+
options: v.optional(v.array(v.pipe(v.string(), v.regex(new RegExp('^(?:[A-Z]|[-a-z]{2,})')), v.nonEmpty()))),
|
|
44
58
|
});
|
|
45
59
|
};
|
|
46
60
|
exports.ConfigurationSchema = v.strictObject({
|
|
@@ -66,11 +80,18 @@ exports.ConfigurationSchema = v.strictObject({
|
|
|
66
80
|
})), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", {
|
|
67
81
|
field: 'package.copyright-holder',
|
|
68
82
|
})))),
|
|
83
|
+
'files-from': v.optional(v.pipe(v.string(gtx._x("The field '{field}' must be a string!", {
|
|
84
|
+
field: 'package.files-from',
|
|
85
|
+
})), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", {
|
|
86
|
+
field: 'package.files-from',
|
|
87
|
+
})))),
|
|
69
88
|
})),
|
|
70
89
|
po: v.optional(v.strictObject({
|
|
71
|
-
directory: v.optional(v.string(gtx._x("The field '{field}' must be a string!", {
|
|
90
|
+
directory: v.optional(v.pipe(v.string(gtx._x("The field '{field}' must be a string!", {
|
|
72
91
|
field: 'po.directory',
|
|
73
|
-
}))
|
|
92
|
+
})), v.nonEmpty(gtx._x("The field '{field}' must not be empty!", {
|
|
93
|
+
field: 'po.directory',
|
|
94
|
+
})))),
|
|
74
95
|
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
96
|
})),
|
|
76
97
|
install: v.optional(v.strictObject({
|
|
@@ -80,67 +101,62 @@ exports.ConfigurationSchema = v.strictObject({
|
|
|
80
101
|
msgmerge: v.optional(programSchema('msgmerge')),
|
|
81
102
|
msgfmt: v.optional(programSchema('msgfmt')),
|
|
82
103
|
})),
|
|
83
|
-
files: v.array(v.string()),
|
|
104
|
+
files: v.optional(v.array(v.string())),
|
|
84
105
|
});
|
|
85
106
|
class ConfigurationFactory {
|
|
86
107
|
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
|
-
|
|
108
|
+
static create(jsConfigFiles, pkgJsonFile, lang) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
111
|
+
if (ConfigurationFactory.instance) {
|
|
112
|
+
return ConfigurationFactory.instance;
|
|
113
|
+
}
|
|
114
|
+
if (lang && !lang.match(/^zh-/)) {
|
|
115
|
+
lang = lang.replace(/-.*/, '');
|
|
116
|
+
}
|
|
117
|
+
let jsConfigFile;
|
|
118
|
+
let msgidBugsAddressFile;
|
|
119
|
+
let nameFile;
|
|
120
|
+
let copyrightHolderFile;
|
|
121
|
+
let versionFile;
|
|
122
|
+
const rootPath = process.cwd();
|
|
123
|
+
let configuration = null;
|
|
124
|
+
for (const file of jsConfigFiles) {
|
|
125
|
+
const filePath = path.join(rootPath, file);
|
|
126
|
+
if (fs.existsSync(filePath)) {
|
|
127
|
+
const data = yield this.loadFile(filePath);
|
|
128
|
+
if (data) {
|
|
129
|
+
configuration = data;
|
|
130
|
+
configuration.files = [file];
|
|
131
|
+
jsConfigFile = file;
|
|
132
|
+
if ((_a = configuration.package) === null || _a === void 0 ? void 0 : _a['msgid-bugs-address']) {
|
|
133
|
+
msgidBugsAddressFile = filePath;
|
|
134
|
+
}
|
|
135
|
+
if ((_b = configuration.package) === null || _b === void 0 ? void 0 : _b.name) {
|
|
136
|
+
nameFile = filePath;
|
|
137
|
+
}
|
|
138
|
+
if ((_c = configuration.package) === null || _c === void 0 ? void 0 : _c['copyright-holder']) {
|
|
139
|
+
copyrightHolderFile = filePath;
|
|
140
|
+
}
|
|
141
|
+
if ((_d = configuration.package) === null || _d === void 0 ? void 0 : _d.version) {
|
|
142
|
+
versionFile = filePath;
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
124
145
|
}
|
|
125
|
-
|
|
126
|
-
|
|
146
|
+
else {
|
|
147
|
+
return null;
|
|
127
148
|
}
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
return null;
|
|
132
149
|
}
|
|
133
150
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
!configuration
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
151
|
+
// Fallback to `package.json` configuration. We also try to read
|
|
152
|
+
// msgid-bugs-address from package.json if not set.
|
|
153
|
+
if (!configuration ||
|
|
154
|
+
!configuration.package ||
|
|
155
|
+
!configuration.package['msgid-bugs-address'] ||
|
|
156
|
+
!configuration.package['name'] ||
|
|
157
|
+
!configuration.package['copyright-holder'] ||
|
|
158
|
+
!configuration.package['version']) {
|
|
159
|
+
const packageJson = yield ConfigurationFactory.getPackageJson();
|
|
144
160
|
let fileUsed = false;
|
|
145
161
|
if (!configuration && packageJson.esgettext) {
|
|
146
162
|
configuration = packageJson.esgettext;
|
|
@@ -150,52 +166,78 @@ class ConfigurationFactory {
|
|
|
150
166
|
if (!configuration)
|
|
151
167
|
configuration = { files: [] };
|
|
152
168
|
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.
|
|
169
|
+
if ((_f = packageJson.bugs) === null || _f === void 0 ? void 0 : _f.url) {
|
|
154
170
|
(_g = configuration.package) !== null && _g !== void 0 ? _g : (configuration.package = {});
|
|
155
|
-
configuration.package['msgid-bugs-address'] =
|
|
156
|
-
|
|
157
|
-
msgidBugsAddressFilePath = 'package.json';
|
|
171
|
+
configuration.package['msgid-bugs-address'] = packageJson.bugs.url;
|
|
172
|
+
msgidBugsAddressFile = 'package.json: bugs.url';
|
|
158
173
|
fileUsed = true;
|
|
159
174
|
}
|
|
160
|
-
else if ((_h = packageJson.bugs) === null || _h === void 0 ? void 0 : _h.
|
|
175
|
+
else if ((_h = packageJson.bugs) === null || _h === void 0 ? void 0 : _h.email) {
|
|
161
176
|
(_j = configuration.package) !== null && _j !== void 0 ? _j : (configuration.package = {});
|
|
162
|
-
configuration.package['msgid-bugs-address'] = packageJson.bugs.
|
|
163
|
-
|
|
177
|
+
configuration.package['msgid-bugs-address'] = packageJson.bugs.email;
|
|
178
|
+
msgidBugsAddressFile = 'package.json: bugs.email';
|
|
179
|
+
fileUsed = true;
|
|
180
|
+
}
|
|
181
|
+
else if ((_l = (_k = packageJson.people) === null || _k === void 0 ? void 0 : _k.author) === null || _l === void 0 ? void 0 : _l.email) {
|
|
182
|
+
(_m = configuration.package) !== null && _m !== void 0 ? _m : (configuration.package = {});
|
|
183
|
+
configuration.package['msgid-bugs-address'] =
|
|
184
|
+
packageJson.people.author.email;
|
|
185
|
+
msgidBugsAddressFile = 'package.json: people.author';
|
|
164
186
|
fileUsed = true;
|
|
165
187
|
}
|
|
166
188
|
}
|
|
167
|
-
if (!((
|
|
189
|
+
if (!((_o = configuration.package) === null || _o === void 0 ? void 0 : _o.name)) {
|
|
168
190
|
if (packageJson.name) {
|
|
169
|
-
(
|
|
191
|
+
(_p = configuration.package) !== null && _p !== void 0 ? _p : (configuration.package = {});
|
|
170
192
|
configuration.package.name = packageJson.name;
|
|
171
|
-
|
|
193
|
+
nameFile = 'package.json';
|
|
172
194
|
fileUsed = true;
|
|
173
195
|
}
|
|
174
196
|
}
|
|
175
|
-
if (!((
|
|
176
|
-
if ((
|
|
177
|
-
(
|
|
197
|
+
if (!((_q = configuration.package) === null || _q === void 0 ? void 0 : _q['copyright-holder'])) {
|
|
198
|
+
if ((_r = packageJson.people) === null || _r === void 0 ? void 0 : _r.author) {
|
|
199
|
+
(_s = configuration.package) !== null && _s !== void 0 ? _s : (configuration.package = {});
|
|
178
200
|
configuration.package['copyright-holder'] =
|
|
179
|
-
packageJson.people.author;
|
|
180
|
-
|
|
201
|
+
packageJson.people.author.name;
|
|
202
|
+
if (packageJson.people.author.email) {
|
|
203
|
+
configuration.package['copyright-holder'] +=
|
|
204
|
+
` <${packageJson.people.author.email}>`;
|
|
205
|
+
}
|
|
206
|
+
if (packageJson.people.author.url) {
|
|
207
|
+
configuration.package['copyright-holder'] +=
|
|
208
|
+
` <${packageJson.people.author.url}>`;
|
|
209
|
+
}
|
|
210
|
+
copyrightHolderFile = 'package.json';
|
|
181
211
|
fileUsed = true;
|
|
182
212
|
}
|
|
183
213
|
}
|
|
184
|
-
if (!((
|
|
214
|
+
if (!((_t = configuration.package) === null || _t === void 0 ? void 0 : _t.version)) {
|
|
185
215
|
if (packageJson.version) {
|
|
186
|
-
(
|
|
216
|
+
(_u = configuration.package) !== null && _u !== void 0 ? _u : (configuration.package = {});
|
|
187
217
|
configuration.package.version = packageJson.version;
|
|
188
|
-
|
|
218
|
+
nameFile = 'package.json';
|
|
189
219
|
fileUsed = true;
|
|
190
220
|
}
|
|
191
221
|
}
|
|
192
222
|
if (fileUsed) {
|
|
193
|
-
configuration.files.push('package.json');
|
|
223
|
+
(_v = configuration.files) === null || _v === void 0 ? void 0 : _v.push('package.json');
|
|
194
224
|
}
|
|
195
225
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
configuration
|
|
226
|
+
if (!configuration)
|
|
227
|
+
configuration = {};
|
|
228
|
+
if (!this.validate(configuration, {
|
|
229
|
+
msgidBugsAddressFile: msgidBugsAddressFile,
|
|
230
|
+
nameFile: nameFile,
|
|
231
|
+
copyrightHolderFile: copyrightHolderFile,
|
|
232
|
+
versionFile: versionFile,
|
|
233
|
+
jsConfigFile: jsConfigFile,
|
|
234
|
+
}, lang)) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
return configuration;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
static validate(configuration, files, lang) {
|
|
199
241
|
const result = v.safeParse(exports.ConfigurationSchema, configuration, { lang });
|
|
200
242
|
if (!result.success) {
|
|
201
243
|
const issues = result.issues;
|
|
@@ -206,56 +248,73 @@ class ConfigurationFactory {
|
|
|
206
248
|
let filename;
|
|
207
249
|
switch (path) {
|
|
208
250
|
case 'package.msgid-bugs-address':
|
|
209
|
-
filename =
|
|
251
|
+
filename = files.msgidBugsAddressFile;
|
|
210
252
|
break;
|
|
211
253
|
case 'name':
|
|
212
|
-
filename =
|
|
254
|
+
filename = files.nameFile;
|
|
213
255
|
break;
|
|
214
256
|
case 'copyright-holder':
|
|
215
|
-
filename =
|
|
257
|
+
filename = files.copyrightHolderFile;
|
|
216
258
|
break;
|
|
217
259
|
case 'version':
|
|
218
|
-
filename =
|
|
260
|
+
filename = files.versionFile;
|
|
219
261
|
break;
|
|
220
262
|
default:
|
|
221
|
-
filename =
|
|
263
|
+
filename = files.jsConfigFile;
|
|
222
264
|
break;
|
|
223
265
|
}
|
|
224
|
-
console.error('
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}));
|
|
266
|
+
console.error('\t', gtx._x('{programName}: Error: {filename}: {variable}: {message}.', {
|
|
267
|
+
variable: path,
|
|
268
|
+
programName: 'esgettext',
|
|
269
|
+
filename,
|
|
270
|
+
message,
|
|
271
|
+
}));
|
|
231
272
|
}
|
|
232
|
-
return
|
|
273
|
+
return false;
|
|
233
274
|
}
|
|
234
|
-
return
|
|
275
|
+
return true;
|
|
235
276
|
}
|
|
236
|
-
static
|
|
237
|
-
|
|
238
|
-
if (extension === '.mjs' || extension === '.cjs' || extension === '.js') {
|
|
239
|
-
return Promise.resolve(`${filePath}`).then(s => __importStar(require(s))).then(module => module.default)
|
|
240
|
-
.catch(error => {
|
|
241
|
-
console.error(gtx._x('{programName}: {filename}: error reading configuration: {error}', {
|
|
242
|
-
programName: package_1.Package.getName(),
|
|
243
|
-
filename: path.basename(filePath),
|
|
244
|
-
error,
|
|
245
|
-
}));
|
|
246
|
-
return null;
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
else if (extension === '.json') {
|
|
277
|
+
static getPackageJson() {
|
|
278
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
250
279
|
try {
|
|
251
|
-
|
|
280
|
+
const data = yield package_json_1.default.load(process.cwd());
|
|
281
|
+
(0, normalize_package_data_1.default)(data.content);
|
|
282
|
+
return data.content;
|
|
252
283
|
}
|
|
253
|
-
catch (
|
|
254
|
-
return
|
|
284
|
+
catch (error) {
|
|
285
|
+
return {};
|
|
255
286
|
}
|
|
256
|
-
}
|
|
257
|
-
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
static loadFile(filePath) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
const extension = path.extname(filePath);
|
|
292
|
+
if (extension === '.mjs' || extension === '.cjs' || extension === '.js') {
|
|
293
|
+
return Promise.resolve(`${filePath}`).then(s => __importStar(require(s))).then(module => module.default)
|
|
294
|
+
.catch(error => {
|
|
295
|
+
console.error(gtx._x('{programName}: {filename}: error reading configuration: {error}', {
|
|
296
|
+
programName: package_1.Package.getName(),
|
|
297
|
+
filename: path.basename(filePath),
|
|
298
|
+
error,
|
|
299
|
+
}));
|
|
300
|
+
return null;
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
else if (extension === '.json') {
|
|
304
|
+
try {
|
|
305
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
306
|
+
}
|
|
307
|
+
catch (_a) {
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
throw new Error(gtx._x("{programName}: Error: {filename}: Configuration file name must end in '.mjs', '.cjs', '.js', or '.json'!", {
|
|
313
|
+
programName: package_1.Package.getName(),
|
|
314
|
+
filename: filePath,
|
|
315
|
+
}));
|
|
316
|
+
}
|
|
317
|
+
});
|
|
258
318
|
}
|
|
259
319
|
}
|
|
260
320
|
exports.ConfigurationFactory = ConfigurationFactory;
|
|
261
|
-
//# sourceMappingURL=configuration.js.map
|