-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
86 lines (80 loc) · 2.62 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
81
82
83
84
85
86
const webpack = require('webpack');
const fse = require('fs-extra');
const gulp = require('gulp');
const runSequence = require('run-sequence');
const pug = require('pug');
const path = require('path');
const webpackConfig = require('./webpack.config');
const PluginError = require('plugin-error');
const log = require('fancy-log');
gulp.task('clean', () => {
return fse.remove(path.resolve(__dirname, 'dist'))
.then(_ => {
return fse.mkdir(path.resolve(__dirname, 'dist'));
});
});
gulp.task('create-package', () => {
return fse.writeFile(
path.resolve(__dirname, 'dist', 'package.json'),
JSON.stringify({ main: 'main.js' }),
{ encoding: 'utf8', flag: 'w' }
)
})
gulp.task('build-html', () => {
const dialog = fse.readFile(path.resolve(__dirname, 'src', 'templates', 'dialog.pug'), 'utf8')
.then(data => {
return pug.render(data);
})
.then(html => {
return fse.writeFile(
path.resolve(__dirname, 'dist', 'dialog.html'),
html,
{ encoding: 'utf8', flag: 'w' }
)
});
const index = fse.readFile(path.resolve(__dirname, 'src', 'templates', 'index.pug'), 'utf8')
.then(data => {
return pug.render(data);
})
.then(html => {
return fse.writeFile(
path.resolve(__dirname, 'dist', 'index.html'),
html,
{ encoding: 'utf8', flag: 'w' }
)
});
return Promise.all([dialog, index]);
});
gulp.task('copy', () => {
return gulp.src(['./src/lib/**/*', './src/assets/**/*'], { base: path.resolve(__dirname, 'src') })
.pipe(gulp.dest(path.resolve(__dirname, 'dist')));
});
gulp.task('build-source', () => {
return new Promise((resolve, reject) => {
webpack(webpackConfig, (err, stats) => {
const jsonStats = stats && stats.toJson();
const buildError = err || jsonStats.errors[0] || jsonStats.warnings[0];
if (buildError) {
reject(new PluginError('webpack', buildError));
} else {
log('[webpack]', stats.toString({
colors: true,
version: false,
hash: false,
timings: false,
chunks: false,
chunkModules: false,
}));
resolve();
}
});
});
});
gulp.task('build', ['clean'], (done) => {
return runSequence([
'copy',
'build-html',
'create-package',
'build-source'
], done);
})