-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.js
More file actions
66 lines (54 loc) · 1.59 KB
/
Copy pathmodule.js
File metadata and controls
66 lines (54 loc) · 1.59 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
import path from 'path';
import { obj as thru } from 'through2';
// import del from 'del';
import vfs from 'vinyl-fs';
import gulpPlumber from 'gulp-plumber';
import gulpUglify from 'gulp-uglify';
import gulpFn from 'gulp-fn';
import gulpClip from 'gulp-clip-empty-files';
import * as pkg from './package.json';
let develop, output, source, cwd, sourcemaps, sep;
export function init (config, core) {
develop = core.args.env() === 'develop';
source = config.source || '**/*.js';
sep = config.sep || '.';
sourcemaps = config.maps || (config.maps && develop) || false;
output = config.output;
cwd = config.cwd ? path.join (process.cwd(), config.cwd) : process.cwd();
if (!output || !cwd) {
core.utils.error (pkg.name, 'config.output & config.cwd are required');
return;
}
build();
let bs = core.globals.get('bs');
if (develop && bs) {
bs.watch (source, {
ignoreInitial: true, cwd
})
.on ('add', build)
.on ('change', build);
}
return;
}
function build (file) {
var msg = file ? file : pkg.name
console.log (pkg.name + ' compiling');
console.time (msg);
vfs.src (source, { sourcemaps, cwd })
.on ('end', () => {
console.timeEnd (msg);
})
.pipe (gulpClip())
.pipe (gulpPlumber())
.pipe (gulpFn (
function (file) {
var file_frombase = path.relative(file.base, file.history[0]);
var file_leftover = file.history[0].replace(file_frombase, '');
file.history[0] = path.join(file_leftover, file_frombase.replace(path.sep, sep));
}, true)
)
.pipe (develop ? thru() : gulpUglify())
.pipe (vfs.dest (output, {
sourcemaps: sourcemaps ? '.' : false
}));
}