-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
80 lines (71 loc) · 1.83 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
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify');
const htmlmin = require('gulp-htmlmin');
const autoprefixer = require('gulp-autoprefixer');
const babel = require('gulp-babel');
const { obj } = require('through2');
const { ensureDir } = require('fs-extra');
const { join } = require('path');
const { spawn } = require('child_process');
const {
task,
src,
dest,
parallel,
} = require('gulp');
task('minify-css', () => (
src('src/static/*.css')
.pipe(autoprefixer())
.pipe(cleanCSS())
.pipe(dest('dist/static'))
));
task('minify-js', () => (
src('src/static/*.js')
.pipe(babel({ presets: ['@babel/env'] }))
.pipe(uglify())
.pipe(dest('dist/static'))
));
task('minify-html', () => (
src('src/*.html')
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(dest('dist'))
));
task('mpy-cross', () => (
src('src/lib/**/*.py')
.pipe(obj((chunk, _enc, cb) => {
const filepath = chunk.path.split('src/').pop();
const output = filepath.substring(0, filepath.lastIndexOf('.'));
const outputPath = `dist/${output}.mpy`;
ensureDir(join(__dirname, 'dist/lib'))
.then(() => {
spawn('mpy-cross', [`src/${filepath}`, '-o', outputPath])
.on('error', cb)
.on('exit', (code) => {
console.log('Output:', code, 'Created', outputPath);
cb(null, chunk);
});
})
.catch(cb);
}))
));
task('copy-lib', () => (
src('src/lib/**/!(*.py)')
.pipe(dest('dist/lib'))
));
task('copy-static', () => (
src('src/static/**/!(*.css|*.js)')
.pipe(dest('dist/static'))
));
task('copy-main', () => (
src('src/main.py')
.pipe(dest('dist'))
));
task('default', parallel(
'copy-lib',
'copy-static',
'copy-main',
'mpy-cross',
'minify-css',
'minify-js',
'minify-html',
));