-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathtask.js
More file actions
66 lines (56 loc) · 2.22 KB
/
task.js
File metadata and controls
66 lines (56 loc) · 2.22 KB
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 path = require('path')
const fs = require('fs')
const gulp = require('gulp')
const ora = require('ora')
const nop = require('gulp-nop')
const sass = require('gulp-sass')
const autoprefixer = require('gulp-autoprefixer')
const cssmin = require('gulp-cssmin')
const config = require('./config')
exports.fonts = function (opts) {
const spin = ora(opts.message).start()
const stream = gulp.src(path.resolve(config.themePath, './src/fonts/**'))
.pipe((opts.minimize || config.minimize) ? cssmin({showLog: false}) : nop())
.pipe(gulp.dest(path.resolve(opts.out || config.out, './fonts')))
.on('end', function () {
spin.succeed()
return this
})
return stream
}
exports.build = function (opts) {
const spin = ora(opts.message).start()
let components
let cssFiles = '*'
if (config.components) {
components = config.components.concat(['base'])
cssFiles = '{' + components.join(',') + '}'
}
const varsPath = path.resolve(config.themePath, './src/common/var.scss')
const varsStorePath = path.resolve(config.themePath, './src/common/var-store.scss')
// Some exceptions may cause the compilation to fail to recover normally
if (!fs.existsSync(varsStorePath)) {
// Store default vars
fs.writeFileSync(varsStorePath, fs.readFileSync(varsPath, 'utf-8'), 'utf-8')
}
if (!fs.existsSync(path.resolve(process.cwd(), opts.config || config.config))) {
throw new Error(`config file "${path.resolve(process.cwd(), opts.config || config.config)}" not exist`)
}
fs.writeFileSync(varsPath, fs.readFileSync(path.resolve(process.cwd(), opts.config || config.config)), 'utf-8')
const stream = gulp.src([opts.config || config.config, path.resolve(config.themePath, './src/' + cssFiles + '.scss')])
.pipe(sass.sync())
.pipe(autoprefixer({
overrideBrowserslist: opts.browsers || config.browsers,
cascade: false
}))
.pipe((opts.minimize || config.minimize) ? cssmin({showLog: false}) : nop())
.pipe(gulp.dest(opts.out || config.out))
.on('end', function () {
// Restore default vars
fs.writeFileSync(varsPath, fs.readFileSync(varsStorePath, 'utf-8'), 'utf-8')
fs.unlinkSync(varsStorePath)
spin.succeed()
return this
})
return stream
}