-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
66 lines (56 loc) · 1.94 KB
/
gulpfile.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
60
61
62
63
64
65
66
const gulp = require('gulp')
const del = require('del')
const path = require('path')
const fs = require('fs')
const config = require('./webpack.config')
const webpack = require('webpack-stream')
const through = require('through2')
const vinyl = require('vinyl')
const yaml = require('yaml')
function createI18nPipe(gen) {
return through.obj(function(vinylFile, encoding, callback) {
const files = fs.readdirSync(vinylFile.path).filter(x => path.extname(x) === '.yaml').map(x => path.join(vinylFile.path, x))
.map(x => ({ name: path.basename(x, '.yaml'), value: yaml.parse(fs.readFileSync(x).toString())}))
const content = gen(files, 'provider')
const file = new vinyl({
path: './index.ts',
contents: new Buffer(content)
})
callback(null, file)
})
}
function createModuleI18nPipe() {
return createI18nPipe(require('./node_modules/typei18n/lib/index').gen)
}
function createBuildI18nPipe() {
return createI18nPipe(require('./lib/index').gen)
}
gulp.task('clean', function() {
return del([path.join(__dirname, './lib')])
})
gulp.task('build:local', function() {
return gulp
.src(path.join(__dirname, './src/locales'))
.pipe(createModuleI18nPipe())
.pipe(gulp.dest(path.join(__dirname, './src/locales')))
})
gulp.task('build:lib', function() {
return gulp
.src(path.join(__dirname, './src'))
.pipe(webpack(config.lib))
.pipe(gulp.dest(path.join(__dirname, './lib')))
})
gulp.task('build:cli', function() {
return gulp
.src(path.join(__dirname, './src'))
.pipe(webpack(config.cli))
.pipe(gulp.dest(path.join(__dirname, './lib')))
})
gulp.task('build:bootstrapping', function () {
return gulp
.src(path.join(__dirname, './src/locales'))
.pipe(createBuildI18nPipe())
.pipe(gulp.dest(path.join(__dirname, './src/locales')))
})
gulp.task('build', gulp.parallel(['build:lib', 'build:cli']))
gulp.task('default', gulp.series(['build:local', 'build', 'build:bootstrapping', 'build']))