forked from decentralized-identity/web-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
90 lines (81 loc) · 2.4 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
87
88
89
90
const fs = require('fs-extra');
const gulp = require('gulp');
const concat = require('gulp-concat');
const terser = require('gulp-terser');
const cleanCSS = require('gulp-clean-css');
const mergeStreams = require('merge-stream');
const nunjucksRender = require('gulp-nunjucks-render');
const root = 'extension/';
const compiledJS = root + 'js/compiled/';
const compiledCSS = root + 'css/compiled/';
var assets = {
js: {
'web-components': [
'slide-panels.js',
'tab-panels.js',
'render-list.js',
'modal-overlay.js',
'detail-box.js',
'notice-bar.js',
].map(name => root + 'js/web-components/' + name),
body: [
root + 'content.js',
root + 'js/views/view.js'
]
},
css: {
'head': [
root + 'css/views/view.css',
root + 'css/font-awesome.css'
],
'web-components': [
'slide-panels.css',
'modal-overlay.css',
'tab-panels.css',
'detail-box.css',
'notice-bar.css',
'item-lists.css'
].map(name => root + 'css/web-components/' + name),
}
};
async function compileJS(){
return new Promise(async resolve => {
await fs.ensureDir(compiledJS);
mergeStreams(
...Object.keys(assets.js).map(file => {
return gulp.src(assets.js[file])
.pipe(terser())
.pipe(concat(file + '.js'))
.pipe(gulp.dest(compiledJS))
})
).on('finish', () => resolve())
});
}
async function compileCSS(){
return new Promise(async resolve => {
await fs.ensureDir(compiledCSS);
mergeStreams(
...Object.keys(assets.css).map(file => {
return gulp.src(assets.css[file])
.pipe(cleanCSS())
.pipe(concat(file + '.css'))
.pipe(gulp.dest(compiledCSS))
})
).on('finish', () => resolve())
});
}
async function renderTemplates() {
return gulp.src('templates/pages/**/*.html')
.pipe(nunjucksRender({
path: ['templates', 'templates/partials', 'templates/pages'],
data: {
}
}))
.pipe(gulp.dest('./extension/views'))
};
gulp.task('build', gulp.series(compileCSS, compileJS, renderTemplates));
gulp.task('watch', () => {
gulp.watch([root + '**/*.js', '!' + root + 'js/compiled/**/*'], compileJS);
gulp.watch([root + '**/*.css', '!' + root + 'css/compiled/**/*'], compileCSS);
gulp.watch(['templates/**/*'], gulp.parallel(renderTemplates));
});