forked from i18next/i18next-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
broccoli.js
59 lines (54 loc) · 1.54 KB
/
broccoli.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
49
50
51
52
53
54
55
56
57
58
59
import fse from 'fs-extra'
import Plugin from 'broccoli-plugin'
import i18nTransform from '../dist/transform'
import rsvp from 'rsvp'
import sort from 'gulp-sort'
import vfs from 'vinyl-fs'
const Promise = rsvp.Promise
export default class i18nextParser extends Plugin {
constructor(inputNodes, options = {}) {
super(...arguments)
this.options = options
}
build() {
const outputPath = this.outputPath
return new Promise((resolve, reject) => {
const files = []
let count = 0
vfs.src(this.inputPaths.map(x => x + '/**/*.{js,hbs}'))
.pipe(sort())
.pipe(
new i18nTransform(this.options)
.on('reading', function (file) {
if (!this.options.silent) {
console.log(' [read] '.green + file.path)
}
count++
})
.on('data', function (file) {
files.push(
fse.outputFile(file.path, file.contents)
)
if (!this.options.silent) {
console.log(' [write] '.green + file.path)
}
})
.on('error', function (message, region) {
if (typeof region === 'string') {
message += ': ' + region.trim()
}
console.log(' [error] '.red + message)
})
.on('finish', function () {
if (!this.options.silent) {
console.log()
}
console.log(' Stats: '.yellow + count + ' files were parsed')
Promise.all(files).then(() => {
resolve(files)
})
})
)
})
}
}