-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
62 lines (57 loc) · 1.88 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
const gulp = require('gulp')
const yaml = require('gulp-yaml')
const jsonConcat = require('gulp-json-concat')
const merge = require('merge-stream')
const jeditor = require('gulp-json-editor')
const rename = require('gulp-rename')
const jsonFormat = require('gulp-json-format')
const tv4 = require('gulp-tv4')
const through = require('through2')
const packageData = require('./package.json')
gulp.task('default', () => {
let controllerJson = gulp.src('./controller/*.yml')
.pipe(yaml({ space: 0 }))
.pipe(tv4('./schema/controller.schema.json'))
.pipe(through.obj((file, enc, callback) => {
callback(null, file)
if (!file.tv4.valid) {
throw new Error(file.tv4.error + ' at ' + file.path)
}
}))
.pipe(jsonConcat('Controllers.json', (data) => {
return new Buffer(JSON.stringify(data))
}))
let platformJson = gulp.src('./platform/*.yml')
.pipe(yaml({ space: 0 }))
.pipe(tv4('./schema/platform.schema.json'))
.pipe(through.obj((file, enc, callback) => {
callback(null, file)
if (!file.tv4.valid) {
throw new Error(file.tv4.error + ' at ' + file.path)
}
}))
.pipe(jsonConcat('Platforms.json', function (data) {
return new Buffer(JSON.stringify(data))
}))
return merge(platformJson, controllerJson)
.pipe(jsonConcat('stone.json', function (data) {
return new Buffer(JSON.stringify(data))
}))
.pipe(jeditor({
'version': packageData.version
}))
.pipe(gulp.dest('./dist'))
.pipe(rename('stone.dist.json'))
.pipe(jsonFormat(0))
.pipe(gulp.dest('./dist'))
})
gulp.task('format-platform', () => {
gulp.src('./platform/*.yml')
.pipe(yaml({ space: 2, safe: true }))
.pipe(gulp.dest('./src/platform'))
})
gulp.task('format-controller', () => {
gulp.src('./controller/*.yml')
.pipe(yaml({ space: 2, safe: true }))
.pipe(gulp.dest('./src/controller'))
})