@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
package/dist/commands/install.js
CHANGED
|
@@ -27,9 +27,12 @@ exports.Install = void 0;
|
|
|
27
27
|
const fs_1 = require("fs");
|
|
28
28
|
const runtime_1 = require("@esgettext/runtime");
|
|
29
29
|
const mkdirp = __importStar(require("mkdirp"));
|
|
30
|
+
const optspec_1 = require("../optspec");
|
|
30
31
|
const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
|
|
31
32
|
class Install {
|
|
32
33
|
constructor(configuration) {
|
|
34
|
+
this.locales = undefined;
|
|
35
|
+
this.options = undefined;
|
|
33
36
|
this.configuration = configuration;
|
|
34
37
|
}
|
|
35
38
|
synopsis() {
|
|
@@ -42,11 +45,11 @@ class Install {
|
|
|
42
45
|
return [];
|
|
43
46
|
}
|
|
44
47
|
args() {
|
|
45
|
-
var _a, _b, _c, _d, _e;
|
|
48
|
+
var _a, _b, _c, _d, _e, _f;
|
|
46
49
|
return {
|
|
47
50
|
locales: {
|
|
51
|
+
multi: true,
|
|
48
52
|
alias: 'l',
|
|
49
|
-
type: 'array',
|
|
50
53
|
describe: gtx._('List of locale identifiers'),
|
|
51
54
|
demandOption: true,
|
|
52
55
|
default: (_a = this.configuration.po) === null || _a === void 0 ? void 0 : _a.locales,
|
|
@@ -66,10 +69,16 @@ class Install {
|
|
|
66
69
|
choices: ['gmo', 'mo'],
|
|
67
70
|
group: gtx._('Input file options:'),
|
|
68
71
|
},
|
|
72
|
+
'default-domain': {
|
|
73
|
+
type: 'string',
|
|
74
|
+
describe: gtx._('The textdomain to use'),
|
|
75
|
+
default: (_d = this.configuration.package) === null || _d === void 0 ? void 0 : _d.textdomain,
|
|
76
|
+
group: gtx._('Output file options'),
|
|
77
|
+
},
|
|
69
78
|
'output-directory': {
|
|
70
79
|
type: 'string',
|
|
71
80
|
describe: gtx._('Output directory'),
|
|
72
|
-
default: (
|
|
81
|
+
default: (_f = (_e = this.configuration.install) === null || _e === void 0 ? void 0 : _e.directory) !== null && _f !== void 0 ? _f : 'src/locale',
|
|
73
82
|
group: gtx._('Output file options:'),
|
|
74
83
|
},
|
|
75
84
|
'output-format': {
|
|
@@ -86,6 +95,7 @@ class Install {
|
|
|
86
95
|
},
|
|
87
96
|
};
|
|
88
97
|
}
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
89
99
|
additional(_) { }
|
|
90
100
|
init(argv) {
|
|
91
101
|
var _a, _b, _c, _d;
|
|
@@ -120,8 +130,10 @@ class Install {
|
|
|
120
130
|
}
|
|
121
131
|
}
|
|
122
132
|
run(argv) {
|
|
123
|
-
this.init(argv);
|
|
124
133
|
return new Promise(resolve => {
|
|
134
|
+
if (!(0, optspec_1.coerceOptions)(argv, this.args())) {
|
|
135
|
+
return resolve(1);
|
|
136
|
+
}
|
|
125
137
|
const promises = [];
|
|
126
138
|
for (let i = 0; i < this.locales.length; ++i) {
|
|
127
139
|
const locale = this.locales[i];
|
|
@@ -224,7 +236,11 @@ class Install {
|
|
|
224
236
|
installLocale(locale) {
|
|
225
237
|
try {
|
|
226
238
|
const directory = this.options.outputDirectory + '/' + locale + '/LC_MESSAGES';
|
|
227
|
-
const outFile = directory +
|
|
239
|
+
const outFile = directory +
|
|
240
|
+
'/' +
|
|
241
|
+
this.options.defaultDomain +
|
|
242
|
+
'.' +
|
|
243
|
+
this.options.outputFormat;
|
|
228
244
|
const inFile = this.options.directory + '/' + locale + '.' + this.options.inputFormat;
|
|
229
245
|
if (!(0, fs_1.existsSync)(directory)) {
|
|
230
246
|
mkdirp.sync(directory);
|
|
@@ -246,4 +262,3 @@ class Install {
|
|
|
246
262
|
}
|
|
247
263
|
}
|
|
248
264
|
exports.Install = Install;
|
|
249
|
-
//# sourceMappingURL=install.js.map
|
|
@@ -22,15 +22,27 @@ 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.MsgfmtAll = void 0;
|
|
27
36
|
const fs = __importStar(require("fs"));
|
|
28
37
|
const childProcess = __importStar(require("child_process"));
|
|
29
38
|
const runtime_1 = require("@esgettext/runtime");
|
|
30
39
|
const package_1 = require("../package");
|
|
40
|
+
const optspec_1 = require("../optspec");
|
|
31
41
|
const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
|
|
32
42
|
class MsgfmtAll {
|
|
33
43
|
constructor(configuration) {
|
|
44
|
+
this.locales = undefined;
|
|
45
|
+
this.options = undefined;
|
|
34
46
|
this.configuration = configuration;
|
|
35
47
|
}
|
|
36
48
|
synopsis() {
|
|
@@ -46,8 +58,7 @@ class MsgfmtAll {
|
|
|
46
58
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
47
59
|
const options = {
|
|
48
60
|
locales: {
|
|
49
|
-
|
|
50
|
-
type: 'array',
|
|
61
|
+
multi: true,
|
|
51
62
|
describe: gtx._('List of locale identifiers'),
|
|
52
63
|
demandOption: true,
|
|
53
64
|
default: (_a = this.configuration.po) === null || _a === void 0 ? void 0 : _a.locales,
|
|
@@ -73,8 +84,8 @@ class MsgfmtAll {
|
|
|
73
84
|
group: gtx._('Mode of operation:'),
|
|
74
85
|
},
|
|
75
86
|
options: {
|
|
87
|
+
multi: true,
|
|
76
88
|
type: 'string',
|
|
77
|
-
array: true,
|
|
78
89
|
describe: gtx._x("Options to pass to '{program}' program (without hyphens)", { program: 'msgfmt' }),
|
|
79
90
|
default: ((_h = (_g = this.configuration.programs) === null || _g === void 0 ? void 0 : _g.msgfmt) === null || _h === void 0 ? void 0 : _h.options) || [
|
|
80
91
|
'check',
|
|
@@ -96,6 +107,7 @@ class MsgfmtAll {
|
|
|
96
107
|
}
|
|
97
108
|
return options;
|
|
98
109
|
}
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
99
111
|
additional(_) { }
|
|
100
112
|
init(argv) {
|
|
101
113
|
var _a, _b;
|
|
@@ -117,11 +129,20 @@ class MsgfmtAll {
|
|
|
117
129
|
}
|
|
118
130
|
}
|
|
119
131
|
run(argv) {
|
|
120
|
-
this.init(argv);
|
|
121
132
|
return new Promise(resolve => {
|
|
122
|
-
this.
|
|
123
|
-
|
|
124
|
-
|
|
133
|
+
if (!(0, optspec_1.coerceOptions)(argv, this.args())) {
|
|
134
|
+
return resolve(1);
|
|
135
|
+
}
|
|
136
|
+
this.init(argv);
|
|
137
|
+
const promises = this.locales.map(locale => this.msgfmtLocale(locale));
|
|
138
|
+
Promise.all(promises)
|
|
139
|
+
.then(results => {
|
|
140
|
+
const hasOne = results.some(result => result === 1);
|
|
141
|
+
resolve(hasOne ? 1 : 0);
|
|
142
|
+
})
|
|
143
|
+
.catch(() => {
|
|
144
|
+
resolve(1);
|
|
145
|
+
});
|
|
125
146
|
});
|
|
126
147
|
}
|
|
127
148
|
convertOptions(options) {
|
|
@@ -147,54 +168,55 @@ class MsgfmtAll {
|
|
|
147
168
|
}
|
|
148
169
|
return errors ? null : msgmergeOptions;
|
|
149
170
|
}
|
|
150
|
-
|
|
151
|
-
return
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
po
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
try {
|
|
165
|
-
const msgfmt = childProcess.spawn(this.options.msgfmt, args, {
|
|
166
|
-
windowsHide: true,
|
|
167
|
-
});
|
|
168
|
-
msgfmt.stdout.on('data', (data) => process.stdout.write(data.toString()));
|
|
169
|
-
msgfmt.stderr.on('data', (data) => process.stderr.write(data.toString()));
|
|
170
|
-
msgfmt.on('close', code => {
|
|
171
|
-
if (code) {
|
|
172
|
-
fs.unlinkSync(moFile);
|
|
173
|
-
resolve(1);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
resolve(0);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
msgfmt.on('error', err => {
|
|
180
|
-
throw new Error(gtx._x("Failed to run '{prg}': {err}", {
|
|
181
|
-
prg: this.options.msgfmt,
|
|
182
|
-
err,
|
|
171
|
+
msgfmtLocale(locale) {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
return new Promise(resolve => {
|
|
174
|
+
const args = this.convertOptions(this.options.options);
|
|
175
|
+
if (!args)
|
|
176
|
+
return resolve(1);
|
|
177
|
+
const poFile = this.options.directory + '/' + locale + '.po';
|
|
178
|
+
const moFile = this.options.directory + '/' + locale + '.' + this.options.format;
|
|
179
|
+
args.push('-o', moFile, poFile);
|
|
180
|
+
if (this.options.verbose) {
|
|
181
|
+
console.log(gtx._x("Compiling '{po}' into '{mo}'.", {
|
|
182
|
+
po: poFile,
|
|
183
|
+
mo: moFile,
|
|
183
184
|
}));
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
catch (err) {
|
|
185
|
+
}
|
|
187
186
|
try {
|
|
188
|
-
|
|
187
|
+
const msgfmt = childProcess.spawn(this.options.msgfmt, args, {
|
|
188
|
+
windowsHide: true,
|
|
189
|
+
});
|
|
190
|
+
msgfmt.stdout.on('data', (data) => process.stdout.write(data.toString()));
|
|
191
|
+
msgfmt.stderr.on('data', (data) => process.stderr.write(data.toString()));
|
|
192
|
+
msgfmt.on('close', code => {
|
|
193
|
+
if (code) {
|
|
194
|
+
fs.unlinkSync(moFile);
|
|
195
|
+
resolve(1);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
resolve(0);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
msgfmt.on('error', err => {
|
|
202
|
+
throw new Error(gtx._x("Failed to run '{prg}': {err}", {
|
|
203
|
+
prg: this.options.msgfmt,
|
|
204
|
+
err,
|
|
205
|
+
}));
|
|
206
|
+
});
|
|
189
207
|
}
|
|
190
|
-
catch (
|
|
191
|
-
|
|
208
|
+
catch (err) {
|
|
209
|
+
try {
|
|
210
|
+
fs.unlinkSync(moFile);
|
|
211
|
+
}
|
|
212
|
+
catch (err1) {
|
|
213
|
+
console.error(err1);
|
|
214
|
+
}
|
|
215
|
+
console.error(err);
|
|
216
|
+
resolve(1);
|
|
192
217
|
}
|
|
193
|
-
|
|
194
|
-
resolve(1);
|
|
195
|
-
}
|
|
218
|
+
});
|
|
196
219
|
});
|
|
197
220
|
}
|
|
198
221
|
}
|
|
199
222
|
exports.MsgfmtAll = MsgfmtAll;
|
|
200
|
-
//# sourceMappingURL=msgfmt-all.js.map
|
|
@@ -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.MsgmergeAll = void 0;
|
|
27
36
|
const path = __importStar(require("path"));
|
|
@@ -29,10 +38,13 @@ const fs = __importStar(require("fs"));
|
|
|
29
38
|
const childProcess = __importStar(require("child_process"));
|
|
30
39
|
const runtime_1 = require("@esgettext/runtime");
|
|
31
40
|
const package_1 = require("../package");
|
|
41
|
+
const optspec_1 = require("../optspec");
|
|
32
42
|
const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
|
|
33
43
|
class MsgmergeAll {
|
|
34
44
|
constructor(configuration) {
|
|
35
45
|
var _a, _b;
|
|
46
|
+
this.locales = [];
|
|
47
|
+
this.options = {};
|
|
36
48
|
this.configuration = configuration;
|
|
37
49
|
if (((_a = configuration.package) === null || _a === void 0 ? void 0 : _a.textdomain) &&
|
|
38
50
|
typeof ((_b = configuration.po) === null || _b === void 0 ? void 0 : _b.directory) !== 'undefined') {
|
|
@@ -61,8 +73,8 @@ class MsgmergeAll {
|
|
|
61
73
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
62
74
|
const options = {
|
|
63
75
|
locales: {
|
|
76
|
+
multi: true,
|
|
64
77
|
alias: 'l',
|
|
65
|
-
type: 'array',
|
|
66
78
|
describe: gtx._('List of locale identifiers'),
|
|
67
79
|
demandOption: true,
|
|
68
80
|
default: (_a = this.configuration.po) === null || _a === void 0 ? void 0 : _a.locales,
|
|
@@ -82,8 +94,8 @@ class MsgmergeAll {
|
|
|
82
94
|
group: gtx._('Mode of operation:'),
|
|
83
95
|
},
|
|
84
96
|
options: {
|
|
97
|
+
multi: true,
|
|
85
98
|
type: 'string',
|
|
86
|
-
array: true,
|
|
87
99
|
describe: gtx._x("Options to pass to '{program}' program (without hyphens)", { program: 'msgmerge' }),
|
|
88
100
|
default: (_h = (_g = this.configuration.programs) === null || _g === void 0 ? void 0 : _g.msgfmt) === null || _h === void 0 ? void 0 : _h.options,
|
|
89
101
|
group: gtx._('Mode of operation:'),
|
|
@@ -129,11 +141,20 @@ class MsgmergeAll {
|
|
|
129
141
|
}
|
|
130
142
|
}
|
|
131
143
|
run(argv) {
|
|
132
|
-
this.init(argv);
|
|
133
144
|
return new Promise(resolve => {
|
|
134
|
-
this.
|
|
135
|
-
|
|
136
|
-
|
|
145
|
+
if (!(0, optspec_1.coerceOptions)(argv, this.args())) {
|
|
146
|
+
return resolve(1);
|
|
147
|
+
}
|
|
148
|
+
this.init(argv);
|
|
149
|
+
const promises = this.locales.map(locale => this.msgmergeLocale(locale));
|
|
150
|
+
Promise.all(promises)
|
|
151
|
+
.then(results => {
|
|
152
|
+
const hasOne = results.some(result => result === 1);
|
|
153
|
+
resolve(hasOne ? 1 : 0);
|
|
154
|
+
})
|
|
155
|
+
.catch(() => {
|
|
156
|
+
resolve(1);
|
|
157
|
+
});
|
|
137
158
|
});
|
|
138
159
|
}
|
|
139
160
|
convertOptions(options) {
|
|
@@ -159,54 +180,55 @@ class MsgmergeAll {
|
|
|
159
180
|
}
|
|
160
181
|
return errors ? null : msgmergeOptions;
|
|
161
182
|
}
|
|
162
|
-
|
|
163
|
-
return
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
pot
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
prg:
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
183
|
+
msgmergeLocale(locale) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
return new Promise(resolve => {
|
|
186
|
+
const args = this.convertOptions(this.options.options);
|
|
187
|
+
if (!args)
|
|
188
|
+
return resolve(1);
|
|
189
|
+
const poFile = this.options.directory + '/' + locale + '.po';
|
|
190
|
+
const oldPoFile = this.options.directory + '/' + locale + '.old.po';
|
|
191
|
+
args.push(oldPoFile, this.potfile, '-o', poFile);
|
|
192
|
+
console.log(gtx._x("Merging '{pot}' into '{po}'.", {
|
|
193
|
+
pot: this.potfile,
|
|
194
|
+
po: poFile,
|
|
195
|
+
}));
|
|
196
|
+
try {
|
|
197
|
+
fs.renameSync(poFile, oldPoFile);
|
|
198
|
+
const msgmerge = childProcess.spawn(this.options.msgmerge, args, {
|
|
199
|
+
windowsHide: true,
|
|
200
|
+
});
|
|
201
|
+
msgmerge.on('error', err => {
|
|
202
|
+
throw new Error(gtx._x("Failed to run '{prg}': {err}", {
|
|
203
|
+
prg: this.options.msgmerge,
|
|
204
|
+
err,
|
|
205
|
+
}));
|
|
206
|
+
});
|
|
207
|
+
msgmerge.stdout.on('data', (data) => process.stdout.write(data.toString()));
|
|
208
|
+
msgmerge.stderr.on('data', (data) => process.stderr.write(data.toString()));
|
|
209
|
+
msgmerge.on('close', code => {
|
|
210
|
+
if (code) {
|
|
211
|
+
fs.renameSync(oldPoFile, poFile);
|
|
212
|
+
resolve(1);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
fs.unlinkSync(oldPoFile);
|
|
216
|
+
resolve(0);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
try {
|
|
189
222
|
fs.renameSync(oldPoFile, poFile);
|
|
190
|
-
resolve(1);
|
|
191
223
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
resolve(0);
|
|
224
|
+
catch (err1) {
|
|
225
|
+
console.error(err1);
|
|
195
226
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
catch (err) {
|
|
199
|
-
try {
|
|
200
|
-
fs.renameSync(oldPoFile, poFile);
|
|
227
|
+
console.error(err);
|
|
228
|
+
resolve(1);
|
|
201
229
|
}
|
|
202
|
-
|
|
203
|
-
console.error(err1);
|
|
204
|
-
}
|
|
205
|
-
console.error(err);
|
|
206
|
-
resolve(1);
|
|
207
|
-
}
|
|
230
|
+
});
|
|
208
231
|
});
|
|
209
232
|
}
|
|
210
233
|
}
|
|
211
234
|
exports.MsgmergeAll = MsgmergeAll;
|
|
212
|
-
//# sourceMappingURL=msgmerge-all.js.map
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Potfiles = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
const glob_1 = require("glob");
|
|
8
|
+
const runtime_1 = require("@esgettext/runtime");
|
|
9
|
+
const package_1 = require("../package");
|
|
10
|
+
const optspec_1 = require("../optspec");
|
|
11
|
+
const gtx = runtime_1.Textdomain.getInstance('com.cantanea.esgettext-tools');
|
|
12
|
+
class Potfiles {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
|
+
constructor(configuration) {
|
|
15
|
+
this.GIT_DIRECTORY_NAME = '.git';
|
|
16
|
+
this.options = undefined;
|
|
17
|
+
this.configuration = configuration;
|
|
18
|
+
}
|
|
19
|
+
synopsis() {
|
|
20
|
+
return `[${gtx._('PATTERN')}...]`;
|
|
21
|
+
}
|
|
22
|
+
description() {
|
|
23
|
+
return gtx._('Write a list of filenames with translatable strings to standard output.');
|
|
24
|
+
}
|
|
25
|
+
aliases() {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
args() {
|
|
29
|
+
var _a;
|
|
30
|
+
return {
|
|
31
|
+
exclude: {
|
|
32
|
+
multi: true,
|
|
33
|
+
alias: 'x',
|
|
34
|
+
type: 'string',
|
|
35
|
+
describe: gtx._('Pattern for files to ignore.'),
|
|
36
|
+
},
|
|
37
|
+
git: {
|
|
38
|
+
type: 'boolean',
|
|
39
|
+
describe: gtx._('Only list files under (git) version control.'),
|
|
40
|
+
default: this.isGitRepo(),
|
|
41
|
+
},
|
|
42
|
+
include: {
|
|
43
|
+
multi: true,
|
|
44
|
+
type: 'string',
|
|
45
|
+
describe: gtx._('Pattern for additional files to include (even when not under version control).'),
|
|
46
|
+
},
|
|
47
|
+
directory: {
|
|
48
|
+
type: 'string',
|
|
49
|
+
describe: gtx._('Make paths relative to this directory.'),
|
|
50
|
+
default: (_a = this.configuration.po) === null || _a === void 0 ? void 0 : _a.directory,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
55
|
+
additional(argv) {
|
|
56
|
+
argv.positional(gtx._('PATTERN'), {
|
|
57
|
+
type: 'string',
|
|
58
|
+
describe: gtx._('Filename patterns for source files'),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
isDirectory(path) {
|
|
62
|
+
const stats = (0, fs_1.lstatSync)(path);
|
|
63
|
+
if (stats.isDirectory()) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
else if (stats.isSymbolicLink()) {
|
|
67
|
+
const realPath = (0, fs_1.realpathSync)(path);
|
|
68
|
+
const realStats = (0, fs_1.statSync)(realPath);
|
|
69
|
+
if (realStats.isDirectory()) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
isGitDirectory(path) {
|
|
81
|
+
const fullPath = (0, path_1.join)(path, this.GIT_DIRECTORY_NAME);
|
|
82
|
+
return (0, fs_1.existsSync)(fullPath) && this.isDirectory(fullPath);
|
|
83
|
+
}
|
|
84
|
+
isGitRepo() {
|
|
85
|
+
if (this.isGitDirectory(process.cwd())) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
let currentPath = process.cwd();
|
|
89
|
+
while (true) {
|
|
90
|
+
const parentPath = (0, path_1.join)(currentPath, '..');
|
|
91
|
+
if (parentPath === currentPath) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (this.isGitDirectory(parentPath)) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
currentPath = parentPath;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
init(argv) {
|
|
102
|
+
const options = argv;
|
|
103
|
+
this.options = options;
|
|
104
|
+
}
|
|
105
|
+
filterGit(allFiles) {
|
|
106
|
+
const stdout = (0, child_process_1.execSync)('git ls-files').toString('utf-8');
|
|
107
|
+
const repoFiles = stdout
|
|
108
|
+
.trim()
|
|
109
|
+
.split('\n')
|
|
110
|
+
.map(filename => (0, path_1.resolve)(filename));
|
|
111
|
+
const filtered = [];
|
|
112
|
+
for (const filename of allFiles) {
|
|
113
|
+
const resolved = (0, path_1.resolve)(filename);
|
|
114
|
+
if (repoFiles.includes(resolved)) {
|
|
115
|
+
filtered.push(filename);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return filtered;
|
|
119
|
+
}
|
|
120
|
+
makeRelative(filename, base) {
|
|
121
|
+
const absoluteFilename = (0, path_1.resolve)(filename);
|
|
122
|
+
const absoluteBase = (0, path_1.resolve)(base);
|
|
123
|
+
return (0, path_1.relative)(absoluteBase, absoluteFilename);
|
|
124
|
+
}
|
|
125
|
+
run(argv) {
|
|
126
|
+
return new Promise(resolve => {
|
|
127
|
+
if (!(0, optspec_1.coerceOptions)(argv, this.args())) {
|
|
128
|
+
return resolve(1);
|
|
129
|
+
}
|
|
130
|
+
this.init(argv);
|
|
131
|
+
const patterns = this.options[gtx._('PATTERN')];
|
|
132
|
+
if (!patterns.length) {
|
|
133
|
+
console.error(gtx._x('{programName}: Error: No filename patterns specified!', {
|
|
134
|
+
programName: package_1.Package.getName(),
|
|
135
|
+
}));
|
|
136
|
+
return resolve(1);
|
|
137
|
+
}
|
|
138
|
+
const candidates = (0, glob_1.globSync)(patterns, { ignore: this.options.exclude });
|
|
139
|
+
let filtered;
|
|
140
|
+
if (this.options.git) {
|
|
141
|
+
filtered = this.filterGit(candidates);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
filtered = candidates.filter(filename => !this.isDirectory(filename));
|
|
145
|
+
}
|
|
146
|
+
if (typeof this.options.include !== 'undefined') {
|
|
147
|
+
const included = (0, glob_1.globSync)(this.options.include).filter(filename => !this.isDirectory(filename));
|
|
148
|
+
filtered.push(...included);
|
|
149
|
+
}
|
|
150
|
+
// sort | uniq for JavaScript.
|
|
151
|
+
filtered = filtered.sort().filter((item, index) => {
|
|
152
|
+
return index === 0 || item !== filtered[index - 1];
|
|
153
|
+
});
|
|
154
|
+
if (typeof this.options.directory !== 'undefined' &&
|
|
155
|
+
this.options.directory.length) {
|
|
156
|
+
filtered = filtered.map(filename => this.makeRelative(filename, this.options.directory));
|
|
157
|
+
}
|
|
158
|
+
for (const filename of filtered) {
|
|
159
|
+
console.log(filename);
|
|
160
|
+
}
|
|
161
|
+
resolve(0);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.Potfiles = Potfiles;
|
|
@@ -18,6 +18,7 @@ class FilesCollector {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
args.forEach(filename => filenames.push(filename));
|
|
21
|
+
// Make filenames unique.
|
|
21
22
|
this.filenames = Array.from(new Set(filenames));
|
|
22
23
|
}
|
|
23
24
|
getFilesFromFile(filename) {
|
|
@@ -36,4 +37,3 @@ class FilesCollector {
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
exports.FilesCollector = FilesCollector;
|
|
39
|
-
//# sourceMappingURL=files-collector.js.map
|