1 |
|
2 | 'use strict';
|
3 | var path = require('path');
|
4 | var gulp = require('gulp');
|
5 |
|
6 | var extToSrc = require('../lib/ext-to-glob');
|
7 | var unlink = require('../lib/unlink');
|
8 | var compileWxss = require('../compiler/compile-wxss');
|
9 | var watchLog = require('../log/watch');
|
10 |
|
11 | var WXSS_EXTS = ['scss', 'sass', 'css', 'wxss'];
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function compile(config) {
|
17 | return compileWxss(config, extToSrc(config, WXSS_EXTS));
|
18 | }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | exports.build = function (config) {
|
24 | return function (cb) {
|
25 | compile(config);
|
26 | cb && cb();
|
27 | };
|
28 | }
|
29 |
|
30 | function isAsset(file, config) {
|
31 | return config.assets && file.startsWith(path.join(config.src, config.assets));
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | exports.watch = function (config) {
|
38 | var update = function (file) {
|
39 |
|
40 | if (isAsset(file, config)) {
|
41 | return compile(config);
|
42 | } else {
|
43 | return compileWxss(config, file);
|
44 | }
|
45 | };
|
46 |
|
47 | return function (cb) {
|
48 | var glob = extToSrc(config, WXSS_EXTS, true);
|
49 | watchLog('wxss', glob)
|
50 | gulp.watch(glob, {})
|
51 | .on('change', update)
|
52 | .on('add', update)
|
53 | .on('unlink', function (file) {
|
54 | if (isAsset(file, config)) {
|
55 | return compile(config);
|
56 | } else {
|
57 | return unlink(config.src, config.dist, '.wxss')(file);
|
58 | }
|
59 | });
|
60 | cb && cb();
|
61 | }
|
62 | } |
\ | No newline at end of file |