@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.
Files changed (87) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/command.js +0 -1
  4. package/dist/commands/convert.js +16 -14
  5. package/dist/commands/install.js +12 -4
  6. package/dist/commands/msgfmt-all.js +65 -46
  7. package/dist/commands/msgmerge-all.js +64 -46
  8. package/dist/commands/xgettext/file-resolver.js +0 -1
  9. package/dist/commands/xgettext/files-collector.js +1 -1
  10. package/dist/commands/xgettext.js +16 -7
  11. package/dist/configuration.js +172 -156
  12. package/dist/esgettext-package-json.js +0 -1
  13. package/dist/index.js +75 -24
  14. package/dist/package.js +1 -2
  15. package/dist/parser/javascript.js +2 -1
  16. package/dist/parser/parser.js +17 -2
  17. package/dist/parser/po.js +34 -1
  18. package/dist/parser/typescript.js +2 -1
  19. package/dist/pot/catalog.js +36 -1
  20. package/dist/pot/entry.js +71 -1
  21. package/dist/pot/keyword.js +10 -5
  22. package/package.json +5 -4
  23. package/dist/command.d.ts +0 -11
  24. package/dist/command.js.map +0 -1
  25. package/dist/commands/convert.d.ts +0 -24
  26. package/dist/commands/convert.js.map +0 -1
  27. package/dist/commands/install.d.ts +0 -22
  28. package/dist/commands/install.js.map +0 -1
  29. package/dist/commands/msgfmt-all.d.ts +0 -20
  30. package/dist/commands/msgfmt-all.js.map +0 -1
  31. package/dist/commands/msgmerge-all.d.ts +0 -21
  32. package/dist/commands/msgmerge-all.js.map +0 -1
  33. package/dist/commands/xgettext/file-resolver.d.ts +0 -5
  34. package/dist/commands/xgettext/file-resolver.js.map +0 -1
  35. package/dist/commands/xgettext/file-resolver.spec.d.ts +0 -1
  36. package/dist/commands/xgettext/file-resolver.spec.js +0 -22
  37. package/dist/commands/xgettext/file-resolver.spec.js.map +0 -1
  38. package/dist/commands/xgettext/files-collector.d.ts +0 -5
  39. package/dist/commands/xgettext/files-collector.js.map +0 -1
  40. package/dist/commands/xgettext/files-collector.spec.d.ts +0 -1
  41. package/dist/commands/xgettext/files-collector.spec.js +0 -96
  42. package/dist/commands/xgettext/files-collector.spec.js.map +0 -1
  43. package/dist/commands/xgettext.d.ts +0 -29
  44. package/dist/commands/xgettext.js.map +0 -1
  45. package/dist/commands/xgettext.spec.d.ts +0 -1
  46. package/dist/commands/xgettext.spec.js +0 -897
  47. package/dist/commands/xgettext.spec.js.map +0 -1
  48. package/dist/configuration.d.ts +0 -36
  49. package/dist/configuration.js.map +0 -1
  50. package/dist/esgettext-package-json.d.ts +0 -15
  51. package/dist/esgettext-package-json.js.map +0 -1
  52. package/dist/index.d.ts +0 -2
  53. package/dist/index.js.map +0 -1
  54. package/dist/package.d.ts +0 -5
  55. package/dist/package.js.map +0 -1
  56. package/dist/parser/javascript.d.ts +0 -4
  57. package/dist/parser/javascript.js.map +0 -1
  58. package/dist/parser/javascript.spec.d.ts +0 -1
  59. package/dist/parser/javascript.spec.js +0 -535
  60. package/dist/parser/javascript.spec.js.map +0 -1
  61. package/dist/parser/parser.d.ts +0 -45
  62. package/dist/parser/parser.js.map +0 -1
  63. package/dist/parser/po.d.ts +0 -22
  64. package/dist/parser/po.js.map +0 -1
  65. package/dist/parser/po.spec.d.ts +0 -1
  66. package/dist/parser/po.spec.js +0 -486
  67. package/dist/parser/po.spec.js.map +0 -1
  68. package/dist/parser/typescript.d.ts +0 -4
  69. package/dist/parser/typescript.js.map +0 -1
  70. package/dist/parser/typescript.spec.d.ts +0 -1
  71. package/dist/parser/typescript.spec.js +0 -121
  72. package/dist/parser/typescript.spec.js.map +0 -1
  73. package/dist/pot/catalog.d.ts +0 -26
  74. package/dist/pot/catalog.js.map +0 -1
  75. package/dist/pot/catalog.spec.d.ts +0 -1
  76. package/dist/pot/catalog.spec.js +0 -244
  77. package/dist/pot/catalog.spec.js.map +0 -1
  78. package/dist/pot/entry.d.ts +0 -35
  79. package/dist/pot/entry.js.map +0 -1
  80. package/dist/pot/entry.spec.d.ts +0 -1
  81. package/dist/pot/entry.spec.js +0 -433
  82. package/dist/pot/entry.spec.js.map +0 -1
  83. package/dist/pot/keyword.d.ts +0 -17
  84. package/dist/pot/keyword.js.map +0 -1
  85. package/dist/pot/keyword.spec.d.ts +0 -1
  86. package/dist/pot/keyword.spec.js +0 -54
  87. package/dist/pot/keyword.spec.js.map +0 -1
@@ -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 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;
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
- if ((_d = configuration.package) === null || _d === void 0 ? void 0 : _d.version) {
126
- versionFilePath = filePath;
137
+ else {
138
+ return null;
127
139
  }
128
- break;
129
- }
130
- else {
131
- return null;
132
140
  }
133
141
  }
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'));
144
- let fileUsed = false;
145
- if (!configuration && packageJson.esgettext) {
146
- configuration = packageJson.esgettext;
147
- configuration.files = [];
148
- fileUsed = true;
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
- else if ((_h = packageJson.bugs) === null || _h === void 0 ? void 0 : _h.url) {
161
- (_j = configuration.package) !== null && _j !== void 0 ? _j : (configuration.package = {});
162
- configuration.package['msgid-bugs-address'] = packageJson.bugs.url;
163
- msgidBugsAddressFilePath = 'package.json';
164
- fileUsed = true;
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
- if (!((_k = configuration.package) === null || _k === void 0 ? void 0 : _k.name)) {
168
- if (packageJson.name) {
169
- (_l = configuration.package) !== null && _l !== void 0 ? _l : (configuration.package = {});
170
- configuration.package.name = packageJson.name;
171
- nameFilePath = 'package.json';
172
- fileUsed = true;
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
- 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 = {});
178
- configuration.package['copyright-holder'] =
179
- packageJson.people.author;
180
- copyrightHolderFilePath = 'package.json';
181
- fileUsed = true;
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
- if (!((_q = configuration.package) === null || _q === void 0 ? void 0 : _q.version)) {
185
- if (packageJson.version) {
186
- (_r = configuration.package) !== null && _r !== void 0 ? _r : (configuration.package = {});
187
- configuration.package.version = packageJson.version;
188
- nameFilePath = 'package.json';
189
- fileUsed = true;
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
- if (!configuration)
198
- configuration = { files: [] };
199
- const result = v.safeParse(exports.ConfigurationSchema, configuration, { lang });
200
- if (!result.success) {
201
- const issues = result.issues;
202
- console.error(gtx._nx('There is one configuration error:', 'There are {num} configuration errors:', issues.length, { num: issues.length }));
203
- for (const issue of issues) {
204
- const path = v.getDotPath(issue) || gtx._('[path not set]');
205
- const message = issue.issues ? issue.issues[0].message : issue.message;
206
- let filename;
207
- switch (path) {
208
- case 'package.msgid-bugs-address':
209
- filename = msgidBugsAddressFilePath;
210
- break;
211
- case 'name':
212
- filename = nameFilePath;
213
- break;
214
- case 'copyright-holder':
215
- filename = copyrightHolderFilePath;
216
- break;
217
- case 'version':
218
- filename = versionFilePath;
219
- break;
220
- default:
221
- filename = jsConfigFilePath;
222
- break;
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
- console.error(' ' +
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 null;
233
- }
234
- return configuration;
243
+ return configuration;
244
+ });
235
245
  }
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}', {
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: path.basename(filePath),
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
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=esgettext-package-json.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 package_1 = require("./package");
17
+ const package_js_1 = require("./package.js");
9
18
  const runtime_1 = require("@esgettext/runtime");
10
- const configuration_1 = require("./configuration");
11
- const xgettext_1 = require("./commands/xgettext");
12
- const msgmerge_all_1 = require("./commands/msgmerge-all");
13
- const install_1 = require("./commands/install");
14
- const convert_1 = require("./commands/convert");
15
- const msgfmt_all_1 = require("./commands/msgfmt-all");
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(async () => {
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 = await configuration_1.ConfigurationFactory.create(locale);
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 xgettext_1.XGettext(configuration),
34
- 'msgmerge-all': new msgmerge_all_1.MsgmergeAll(configuration),
35
- 'msgfmt-all': new msgfmt_all_1.MsgfmtAll(configuration),
36
- install: new install_1.Install(configuration),
37
- convert: new convert_1.Convert(configuration),
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: package_1.Package.getName(),
68
+ programName: package_js_1.Package.getName(),
44
69
  }))
45
70
  .demandCommand(1, gtx._('Error: No command given.'))
46
- .scriptName(package_1.Package.getName());
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: package_1.Package.getBugTrackerUrl(),
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: async (argv) => {
70
- argv._.shift();
71
- const exitCode = await command.run(argv);
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: package_1.Package.getName(),
105
+ programName: package_js_1.Package.getName(),
81
106
  exception,
82
107
  });
83
108
  });
84
- //# sourceMappingURL=index.js.map
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
@@ -9,8 +9,7 @@ class Package {
9
9
  return 'https://github.com/gflohr/esgettext/issues';
10
10
  }
11
11
  static getVersion() {
12
- return '1.1.0';
12
+ return '1.2.0';
13
13
  }
14
14
  }
15
15
  exports.Package = Package;
16
- //# sourceMappingURL=package.js.map
@@ -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