forked from jenseng/react-i18nliner
-
Notifications
You must be signed in to change notification settings - Fork 2
/
newindex.js
48 lines (38 loc) · 1.34 KB
/
newindex.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var log = require('./util/createLogger')('preact-i18nline');
var chalk = require('chalk');
var gr = chalk.grey;
var Index = require('i18nline/lib/commands/index');
function NewIndex(options) {
if (options.silent) log.level = log.NONE;
Index.call(this, options);
}
NewIndex.prototype = Object.create(Index.prototype);
NewIndex.prototype.constructor = NewIndex;
NewIndex.prototype.indexFileHook = function(script) {
return script.replace(
"// Generated by i18nline",
"// Generated by i18nline and preact-i18nline"
).replace(
"import I18n from 'i18nline';",
"import I18n from 'preact-i18nline/i18n';"
);
};
NewIndex.prototype.run = function() {
log[!this.sub && this.constructor === NewIndex ? 'info' : 'debug'](
'Generating index file with preact-i18nline\n' +
gr('Import the generated file into your project\n')
);
// run i18nline index first
Index.prototype.run.apply(this, arguments);
if (this.constructor === NewIndex) {
for (var i = 0, e; (e = this.errors[i]); i++) {
log.error('ERR' + (i + 1) + '\n' + e);
}
}
var elapsed = (new Date()).getTime() - this.startTime;
log[!this.sub && this.constructor === NewIndex ? 'info' : 'debug'](
"\nIndex finished " + (this.isSuccess() ? "" : "with errors ") + "in " + (elapsed / 1000) + " seconds\n"
);
return this.isSuccess();
};
module.exports = NewIndex;