-
Notifications
You must be signed in to change notification settings - Fork 11
/
gulpfile.js
123 lines (101 loc) · 3.39 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"use strict";
const gulp = require("gulp");
const del = require('del');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const gulpIf = require('gulp-if');
const babel = require('gulp-babel');
const src = "src"
const dest = "dist";
const ffext_dir = `ffextension`;
const chrome_dir = `chrome_ext`;
const bookmarklet_name = "pagezipper_10.js";
const ext_name = "pagezipper.js"
var isProd = false
const srcs = {
headers: ["header.js"],
libs: [
"lib/jquery.js",
"lib/jstoolkit.js",
"lib/levenshtein.js",
],
pgzp_srcs: [
"pagezipper.js",
"compat.js",
"image.js",
"menu.js",
"nextlink.js",
"next_url_trials.js",
"next_url.js",
"page_loader_ajax.js",
"page_loader_iframe.js",
"page_loader.js",
"util.js",
]
};
function build_pgzp(output_name, loader_file, destLoc, isProd=false, skipJq=false) {
// prepend 'src/' to filepaths
['headers', 'libs', 'pgzp_srcs'].forEach( jsFileArray => {
global[`curr_${jsFileArray}`] = srcs[jsFileArray].map( f => { return `${src}/${f}` });
});
curr_pgzp_srcs.push(loader_file);
if (skipJq) curr_libs.splice(0, 1);
var allJsFiles = curr_headers.concat(curr_libs).concat([`${destLoc}/${output_name}`]);
//compile pgzp src files
gulp.src(curr_pgzp_srcs)
.pipe(concat(output_name, {newLine: '\n\n'}))
.pipe(babel( {presets: ['es2015']} ))
.pipe(gulpIf(isProd, uglify()))
.pipe(gulp.dest(destLoc))
.on('end', function() {
// combine headers, libs, and compiled srcs
gulp.src(allJsFiles)
.pipe(concat(output_name, {newLine: '\n\n'}))
.pipe(gulp.dest(destLoc));
});
}
function copy_ext_files(ext_dir) {
gulp.src(`${src}/${ext_dir}/*`)
.pipe(gulp.dest(`${dest}/${ext_dir}`));
gulp.src(`${src}/extension_*/**`)
.pipe(gulp.dest(`${dest}/${ext_dir}`));
}
gulp.task('clean', [], () => {
var deleted = del.sync([`${dest}/*`]);
console.log(`deleted ${deleted.join(', ')}`);
});
gulp.task('make_bookmarklet', [], () => {
var loader_file = `${src}/loader_bookmarklet.js`;
build_pgzp(bookmarklet_name, loader_file, dest, isProd);
});
gulp.task('make_chrome_ext', [], () => {
copy_ext_files(chrome_dir);
build_pgzp(ext_name, `${src}/loader_chrome.js`, `${dest}/${chrome_dir}`, isProd);
});
gulp.task('make_ff_ext', [], () => {
// jQuery must be included separately for the FF reviewers
// also the FF reviewers don't want the source to be compressed
// :(
// copy over assets, common files
copy_ext_files(ffext_dir)
// copy jQuery over
var jq = srcs.libs[0];
gulp.src(`${src}/${jq}`).pipe(gulp.dest(`${dest}/${ffext_dir}/`));
// no compression for FF, remove jQuery
build_pgzp(ext_name, `${src}/loader_firefox.js`, `${dest}/${ffext_dir}`, false, true);
});
gulp.task('build', ['clean', 'make_bookmarklet', 'make_chrome_ext', 'make_ff_ext'], () => {
});
gulp.task('watch', () => {
gulp.watch(['src/**.js', 'src/**.html', 'src/**.css'], ['build']);
});
// Deploy to prod
gulp.task('prod', () => {
isProd = true;
gulp.start('build');
console.log("Built Pgzp in production mode");
});
gulp.task('default', () => {
gulp.start('build');
console.log("Built Pgzp in development mode");
});