-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathghu.js
73 lines (60 loc) · 2.69 KB
/
ghu.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
const {resolve, join} = require('path');
const {ghu, babel, includeit, pug, less, cssmin, jszip, mapfn, read, remove, uglify, wrap, write} = require('ghu');
const NAME = 'jquery-twinkle';
const ROOT = resolve(__dirname);
const SRC = join(ROOT, 'src');
const BUILD = join(ROOT, 'build');
const DIST = join(ROOT, 'dist');
ghu.defaults('release');
ghu.before(runtime => {
runtime.pkg = Object.assign({}, require('./package.json'));
runtime.comment = `${runtime.pkg.name} v${runtime.pkg.version} - ${runtime.pkg.homepage}`;
runtime.commentJs = `/*! ${runtime.comment} */\n`;
console.log(runtime.comment);
});
ghu.task('clean', 'delete build folder', () => {
return remove(`${BUILD}, ${DIST}`);
});
ghu.task('build:scripts', runtime => {
return read(`${SRC}/*.js`)
.then(includeit())
.then(babel({presets: ['@babel/preset-env']}))
.then(wrap(runtime.commentJs))
.then(write(mapfn.p(SRC, DIST), {overwrite: true}))
.then(write(mapfn.p(SRC, BUILD).s('.js', `-${runtime.pkg.version}.js`), {overwrite: true}))
.then(uglify())
.then(wrap(runtime.commentJs))
.then(write(mapfn.p(SRC, DIST).s('.js', '.min.js'), {overwrite: true}))
.then(write(mapfn.p(SRC, BUILD).s('.js', `-${runtime.pkg.version}.min.js`), {overwrite: true}));
});
ghu.task('build:other', runtime => {
return Promise.all([
read(`${SRC}/**/*.pug`)
.then(pug({pkg: runtime.pkg}))
.then(write(mapfn.p(SRC, BUILD).s('.pug', ''), {overwrite: true})),
read(`${SRC}/**/*.less`)
.then(includeit())
.then(less())
.then(cssmin())
.then(write(mapfn.p(SRC, BUILD).s('.less', '.css'), {overwrite: true})),
read(`${SRC}/demo/*.js, ${SRC}/test/*.js`)
.then(babel({presets: ['@babel/preset-env']}))
.then(uglify())
.then(wrap(runtime.commentJs))
.then(write(mapfn.p(SRC, BUILD), {overwrite: true})),
read(`${ROOT}/node_modules/scar/dist/scar.min.js`)
.then(write(`${BUILD}/test/scar.min.js`, {overwrite: true})),
read(`${ROOT}/node_modules/jquery/dist/jquery.min.js`)
.then(write(`${BUILD}/demo/jquery.min.js`, {overwrite: true}))
.then(write(`${BUILD}/test/jquery.min.js`, {overwrite: true})),
read(`${ROOT}/*.md`)
.then(write(mapfn.p(ROOT, BUILD), {overwrite: true}))
]);
});
ghu.task('build', ['build:scripts', 'build:other']);
ghu.task('zip', ['build'], runtime => {
return read(`${BUILD}/**/*`)
.then(jszip({dir: BUILD, level: 9}))
.then(write(`${BUILD}/${NAME}-${runtime.pkg.version}.zip`, {overwrite: true}));
});
ghu.task('release', ['clean', 'zip']);