-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
73 lines (57 loc) · 2.21 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
/*eslint-env node*/
'use strict';
const gulp = require('gulp');
const clean = require('gulp-clean');
const cleanhtml = require('gulp-cleanhtml');
const stripdebug = require('gulp-strip-debug');
const uglify = require('gulp-uglify-es').default;
const zip = require('gulp-zip');
const pump = require('pump');
const sourcemaps = require('gulp-sourcemaps');
// clean build directory
gulp.task('clean', () => gulp.src('build/*', { read: false }).pipe(clean()));
// copy static folders to build directory
gulp.task('copy:icons', () => {
return gulp.src('src/icons/**').pipe(gulp.dest('build/icons'));
});
gulp.task('copy:locales', () => {
return gulp.src('src/_locales/**').pipe(gulp.dest('build/_locales'));
});
gulp.task('copy:manifest', () => {
return gulp.src('src/manifest.json').pipe(gulp.dest('build'));
});
// copy and compress HTML files
gulp.task('copy:html', () => gulp.src('src/*.html').pipe(cleanhtml()).pipe(gulp.dest('build')));
// uglify all scripts, creating source maps
gulp.task('copy:scripts', (cb) => {
pump(
[
gulp.src(['src/scripts/**/*.js']),
sourcemaps.init(),
// stripdebug(),
uglify({ ecma: 5 }),
sourcemaps.write(),
gulp.dest('build/scripts'),
],
cb
);
});
gulp.task('copy', gulp.series('copy:icons', 'copy:locales', 'copy:manifest', 'copy:html', 'copy:scripts'));
gulp.task('zip:map', () => {
const manifest = require('./src/manifest');
const mapFileName = `case-converter_v${manifest.version}-maps.zip`;
// collect all source maps
return gulp.src('build/scripts/**/*.map').pipe(zip(mapFileName)).pipe(gulp.dest('dist'));
});
gulp.task('zip:dist', () => {
const manifest = require('./src/manifest');
const distFileName = `case-converter_v${manifest.version}.zip`;
// build distributable extension
return gulp.src(['build/**', '!build/scripts/**/*.map']).pipe(zip(distFileName)).pipe(gulp.dest('dist'));
});
// build ditributable and sourcemaps after other tasks completed
gulp.task('zip', gulp.series('zip:dist', 'zip:map'));
// build ditributable and sourcemaps after other tasks completed
gulp.task('build', gulp.series('copy', 'zip'));
//run all tasks after build directory has been cleaned
gulp.task('default', gulp.series('clean', 'build'));