forked from dempfi/ayu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
82 lines (68 loc) · 2.21 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const _ = require('lodash')
const gulp = require('gulp')
const path = require('path')
const File = require('vinyl')
const yaml = require('yamljs')
const fs = require('fs-jetpack')
const exec = require('gulp-exec')
const through = require('through2')
const clearRequire = require('clear-require')
const hexRx = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i
_.templateSettings.interpolate = /"{([\s\S]+?)}"/g
function colors(path) {
clearRequire(`./src/themes/${path}`)
return require(`./src/themes/${path}`)
}
function templates (type) {
return fs.find('./src/templates', { matching: '*' + type })
.map(p => fs.read(p, 'utf8'))
.map(_.template)
}
function parse (rx, str, def = '') {
const parsed = rx.exec(str)
return parsed ? parsed[1] : def
}
function fileNmae (str, theme) {
const version = parse(/sublime="(.*?)"/g, str)
const prefix = parse(/prefix="(.*?)"/g, str)
const ext = parse(/ext="(.*?)"/g, str, 'tmTheme')
const name = `${prefix}ayu-${theme}${version}.${ext}`
return path.join(process.cwd(), name)
}
function build (types, defs) {
const base = process.cwd()
const themes = _.concat([], types).map(templates)
return _.flatten(themes)
.map(template => template(defs))
.map(compiled => [fileNmae(compiled, defs.theme), compiled])
.map(([path, compiled]) => [path, new Buffer(compiled)])
.map(([path, contents]) => new File({ path, base, contents }))
}
function widgets (file, enc, next) {
build(['widget.xml', 'widget.json'], colors(file.relative))
.map(this.push.bind(this))
next()
}
function themes (file, enc, next) {
build(['syntax.xml', 'ui.json'], colors(file.relative))
.map(this.push.bind(this))
next()
}
gulp.task('clean', () => {
fs.find({ recursive: false, matching: '*.sublime-theme' }).forEach(fs.remove)
fs.find({ recursive: false, matching: '*.tmTheme' }).forEach(fs.remove)
})
gulp.task('widgets', () =>
gulp.src('./src/themes/!(color).js')
.pipe(through.obj(widgets))
.pipe(gulp.dest('./widgets'))
)
gulp.task('themes', () =>
gulp.src('./src/themes/!(color).js')
.pipe(through.obj(themes))
.pipe(gulp.dest('./'))
)
gulp.task('watch', () =>
gulp.watch('./src/**/*', ['themes', 'widgets'])
)
gulp.task('default', ['themes', 'widgets'])