@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.
Files changed (91) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/command.js +0 -1
  4. package/dist/commands/add-language.js +100 -0
  5. package/dist/commands/convert.js +17 -15
  6. package/dist/commands/init.js +743 -0
  7. package/dist/commands/install.js +21 -6
  8. package/dist/commands/msgfmt-all.js +72 -50
  9. package/dist/commands/msgmerge-all.js +71 -49
  10. package/dist/commands/potfiles.js +165 -0
  11. package/dist/commands/xgettext/file-resolver.js +0 -1
  12. package/dist/commands/xgettext/files-collector.js +1 -1
  13. package/dist/commands/xgettext.js +37 -17
  14. package/dist/configuration.js +174 -115
  15. package/dist/esgettext-package-json.js +0 -1
  16. package/dist/index.js +97 -29
  17. package/dist/optspec.js +28 -0
  18. package/dist/package.js +4 -2
  19. package/dist/parser/javascript.js +2 -1
  20. package/dist/parser/parser.js +17 -2
  21. package/dist/parser/po.js +34 -1
  22. package/dist/parser/typescript.js +2 -1
  23. package/dist/pot/catalog.js +36 -1
  24. package/dist/pot/entry.js +71 -1
  25. package/dist/pot/keyword.js +10 -5
  26. package/package.json +11 -6
  27. package/dist/command.d.ts +0 -11
  28. package/dist/command.js.map +0 -1
  29. package/dist/commands/convert.d.ts +0 -24
  30. package/dist/commands/convert.js.map +0 -1
  31. package/dist/commands/install.d.ts +0 -22
  32. package/dist/commands/install.js.map +0 -1
  33. package/dist/commands/msgfmt-all.d.ts +0 -20
  34. package/dist/commands/msgfmt-all.js.map +0 -1
  35. package/dist/commands/msgmerge-all.d.ts +0 -21
  36. package/dist/commands/msgmerge-all.js.map +0 -1
  37. package/dist/commands/xgettext/file-resolver.d.ts +0 -5
  38. package/dist/commands/xgettext/file-resolver.js.map +0 -1
  39. package/dist/commands/xgettext/file-resolver.spec.d.ts +0 -1
  40. package/dist/commands/xgettext/file-resolver.spec.js +0 -22
  41. package/dist/commands/xgettext/file-resolver.spec.js.map +0 -1
  42. package/dist/commands/xgettext/files-collector.d.ts +0 -5
  43. package/dist/commands/xgettext/files-collector.js.map +0 -1
  44. package/dist/commands/xgettext/files-collector.spec.d.ts +0 -1
  45. package/dist/commands/xgettext/files-collector.spec.js +0 -96
  46. package/dist/commands/xgettext/files-collector.spec.js.map +0 -1
  47. package/dist/commands/xgettext.d.ts +0 -29
  48. package/dist/commands/xgettext.js.map +0 -1
  49. package/dist/commands/xgettext.spec.d.ts +0 -1
  50. package/dist/commands/xgettext.spec.js +0 -897
  51. package/dist/commands/xgettext.spec.js.map +0 -1
  52. package/dist/configuration.d.ts +0 -36
  53. package/dist/configuration.js.map +0 -1
  54. package/dist/esgettext-package-json.d.ts +0 -15
  55. package/dist/esgettext-package-json.js.map +0 -1
  56. package/dist/index.d.ts +0 -2
  57. package/dist/index.js.map +0 -1
  58. package/dist/package.d.ts +0 -5
  59. package/dist/package.js.map +0 -1
  60. package/dist/parser/javascript.d.ts +0 -4
  61. package/dist/parser/javascript.js.map +0 -1
  62. package/dist/parser/javascript.spec.d.ts +0 -1
  63. package/dist/parser/javascript.spec.js +0 -535
  64. package/dist/parser/javascript.spec.js.map +0 -1
  65. package/dist/parser/parser.d.ts +0 -45
  66. package/dist/parser/parser.js.map +0 -1
  67. package/dist/parser/po.d.ts +0 -22
  68. package/dist/parser/po.js.map +0 -1
  69. package/dist/parser/po.spec.d.ts +0 -1
  70. package/dist/parser/po.spec.js +0 -486
  71. package/dist/parser/po.spec.js.map +0 -1
  72. package/dist/parser/typescript.d.ts +0 -4
  73. package/dist/parser/typescript.js.map +0 -1
  74. package/dist/parser/typescript.spec.d.ts +0 -1
  75. package/dist/parser/typescript.spec.js +0 -121
  76. package/dist/parser/typescript.spec.js.map +0 -1
  77. package/dist/pot/catalog.d.ts +0 -26
  78. package/dist/pot/catalog.js.map +0 -1
  79. package/dist/pot/catalog.spec.d.ts +0 -1
  80. package/dist/pot/catalog.spec.js +0 -244
  81. package/dist/pot/catalog.spec.js.map +0 -1
  82. package/dist/pot/entry.d.ts +0 -35
  83. package/dist/pot/entry.js.map +0 -1
  84. package/dist/pot/entry.spec.d.ts +0 -1
  85. package/dist/pot/entry.spec.js +0 -433
  86. package/dist/pot/entry.spec.js.map +0 -1
  87. package/dist/pot/keyword.d.ts +0 -17
  88. package/dist/pot/keyword.js.map +0 -1
  89. package/dist/pot/keyword.spec.d.ts +0 -1
  90. package/dist/pot/keyword.spec.js +0 -54
  91. 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: (_c = (_b = this.configuration.po) === null || _b === void 0 ? void 0 : _b.directory) !== null && _c !== void 0 ? _c : '.',
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: (_d = this.configuration.package) === null || _d === void 0 ? void 0 : _d['copyright-holder'],
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: (_e = this.configuration.package) === null || _e === void 0 ? void 0 : _e.name,
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: (_f = this.configuration.package) === null || _f === void 0 ? void 0 : _f.version,
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: (_g = this.configuration.package) === null || _g === void 0 ? void 0 : _g['msgid-bugs-address'],
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
- additional(_) { }
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
@@ -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 async create(lang) {
88
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
89
- if (ConfigurationFactory.instance) {
90
- return ConfigurationFactory.instance;
91
- }
92
- if (lang && !lang.match(/^zh-/)) {
93
- lang = lang.replace(/-.*/, '');
94
- }
95
- const jsConfigFiles = [
96
- 'esgettext.config.mjs',
97
- 'esgettext.config.cjs',
98
- 'esgettext.config.js',
99
- 'esgettext.config.json',
100
- ];
101
- let jsConfigFilePath;
102
- let msgidBugsAddressFilePath;
103
- let nameFilePath;
104
- let copyrightHolderFilePath;
105
- let versionFilePath;
106
- const rootPath = process.cwd();
107
- let configuration = null;
108
- for (const file of jsConfigFiles) {
109
- const filePath = path.join(rootPath, file);
110
- if (fs.existsSync(filePath)) {
111
- const data = await this.loadFile(filePath);
112
- if (data) {
113
- configuration = data;
114
- configuration.files = [file];
115
- jsConfigFilePath = file;
116
- if ((_a = configuration.package) === null || _a === void 0 ? void 0 : _a['msgid-bugs-address']) {
117
- msgidBugsAddressFilePath = filePath;
118
- }
119
- if ((_b = configuration.package) === null || _b === void 0 ? void 0 : _b.name) {
120
- nameFilePath = filePath;
121
- }
122
- if ((_c = configuration.package) === null || _c === void 0 ? void 0 : _c['copyright-holder']) {
123
- copyrightHolderFilePath = filePath;
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
- if ((_d = configuration.package) === null || _d === void 0 ? void 0 : _d.version) {
126
- versionFilePath = filePath;
146
+ else {
147
+ return null;
127
148
  }
128
- break;
129
- }
130
- else {
131
- return null;
132
149
  }
133
150
  }
134
- }
135
- if (!configuration ||
136
- !configuration.package ||
137
- !configuration.package['msgid-bugs-address'] ||
138
- !configuration.package['name'] ||
139
- !configuration.package['copyright-holder'] ||
140
- !configuration.package['version']) {
141
- const packageJsonPath = path.join(rootPath, 'package.json');
142
- if (fs.existsSync(packageJsonPath)) {
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.email) {
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
- packageJson.bugs.email;
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.url) {
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.url;
163
- msgidBugsAddressFilePath = 'package.json';
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 (!((_k = configuration.package) === null || _k === void 0 ? void 0 : _k.name)) {
189
+ if (!((_o = configuration.package) === null || _o === void 0 ? void 0 : _o.name)) {
168
190
  if (packageJson.name) {
169
- (_l = configuration.package) !== null && _l !== void 0 ? _l : (configuration.package = {});
191
+ (_p = configuration.package) !== null && _p !== void 0 ? _p : (configuration.package = {});
170
192
  configuration.package.name = packageJson.name;
171
- nameFilePath = 'package.json';
193
+ nameFile = 'package.json';
172
194
  fileUsed = true;
173
195
  }
174
196
  }
175
- if (!((_m = configuration.package) === null || _m === void 0 ? void 0 : _m['copyright-holder'])) {
176
- if ((_o = packageJson.people) === null || _o === void 0 ? void 0 : _o.author) {
177
- (_p = configuration.package) !== null && _p !== void 0 ? _p : (configuration.package = {});
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
- copyrightHolderFilePath = 'package.json';
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 (!((_q = configuration.package) === null || _q === void 0 ? void 0 : _q.version)) {
214
+ if (!((_t = configuration.package) === null || _t === void 0 ? void 0 : _t.version)) {
185
215
  if (packageJson.version) {
186
- (_r = configuration.package) !== null && _r !== void 0 ? _r : (configuration.package = {});
216
+ (_u = configuration.package) !== null && _u !== void 0 ? _u : (configuration.package = {});
187
217
  configuration.package.version = packageJson.version;
188
- nameFilePath = 'package.json';
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
- if (!configuration)
198
- configuration = { files: [] };
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 = msgidBugsAddressFilePath;
251
+ filename = files.msgidBugsAddressFile;
210
252
  break;
211
253
  case 'name':
212
- filename = nameFilePath;
254
+ filename = files.nameFile;
213
255
  break;
214
256
  case 'copyright-holder':
215
- filename = copyrightHolderFilePath;
257
+ filename = files.copyrightHolderFile;
216
258
  break;
217
259
  case 'version':
218
- filename = versionFilePath;
260
+ filename = files.versionFile;
219
261
  break;
220
262
  default:
221
- filename = jsConfigFilePath;
263
+ filename = files.jsConfigFile;
222
264
  break;
223
265
  }
224
- console.error(' ' +
225
- gtx._x('{programName}: error: {filename}: {variable}: {message}.', {
226
- variable: path,
227
- programName: 'esgettext',
228
- filename,
229
- message,
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 null;
273
+ return false;
233
274
  }
234
- return configuration;
275
+ return true;
235
276
  }
236
- static async loadFile(filePath) {
237
- const extension = path.extname(filePath);
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
- return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
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 (_a) {
254
- return null;
284
+ catch (error) {
285
+ return {};
255
286
  }
256
- }
257
- return null;
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
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=esgettext-package-json.js.map