forked from brookhong/Surfingkeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
94 lines (85 loc) · 3.29 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
var gulp = require('gulp'),
replace = require('gulp-replace'),
gp_concat = require('gulp-concat'),
clean = require('gulp-clean'),
zip = require('gulp-zip'),
gulpUtil = require('gulp-util'),
babel = require('gulp-babel'),
gp_uglify = require('gulp-uglify');
gulp.task('clean', function () {
return gulp.src('dist', {read: false})
.pipe(clean());
});
gulp.task('copy-non-js-files', ['clean'], function() {
return gulp.src(['icons/**', 'content_scripts/**', '!content_scripts/**/*.js', 'pages/**', '!pages/**/*.js'], {base: "."})
.pipe(gulp.dest('dist'));
});
gulp.task('copy-pretty-default-js', ['copy-js-files'], function() {
return gulp.src(['pages/default.js'], {base: "."})
.pipe(gulp.dest('dist'));
});
gulp.task('build_common_content_min', ['clean'], function() {
return gulp.src([
"libs/trie.js",
"libs/jquery.js",
"content_scripts/utils.js",
"content_scripts/runtime.js",
"content_scripts/normal.js",
"content_scripts/insert.js",
"content_scripts/visual.js",
"content_scripts/hints.js",
])
.pipe(gp_concat('common_content.min.js'))
.pipe(babel({presets: ['es2015']}))
.pipe(gp_uglify().on('error', gulpUtil.log))
.pipe(gulp.dest('dist/content_scripts'));
});
gulp.task('use_common_content_min', ['copy-non-js-files', 'clean'], function() {
return gulp.src([
'pages/frontend.html',
'pages/error.html',
'pages/options.html',
'pages/popup.html',
'pages/mermaid.html',
'pages/fiddle.html',
'pages/pdf_viewer.html',
'pages/markdown.html'
], {base: "."})
.pipe(replace(/.*build:common_content[^]*endbuild.*/, ' <script src="../content_scripts/common_content.min.js"></script>'))
.pipe(replace('sha256-nWgGskPWTedp2TpUOZNWBmUL17nlwxaRUKiNdVES5rE=', 'sha256-aGNhu6CROImp/w1iO+ovyGHEBwh6aqkO6VR1TDvzsUs='))
.pipe(gulp.dest('dist'));
});
gulp.task('use_common_content_min_manifest', ['copy-non-js-files', 'clean'], function() {
return gulp.src('manifest.json')
.pipe(replace(/.*build:common_content[^]*endbuild.*/, ' "content_scripts/common_content.min.js",'))
.pipe(replace('sha256-nWgGskPWTedp2TpUOZNWBmUL17nlwxaRUKiNdVES5rE=', 'sha256-aGNhu6CROImp/w1iO+ovyGHEBwh6aqkO6VR1TDvzsUs='))
.pipe(gulp.dest('dist'));
});
gulp.task('copy-js-files', ['copy-es-files'], function() {
return gulp.src([
'content_scripts/front.js',
'content_scripts/content_scripts.js',
'content_scripts/top.js',
'libs/ace/*.js',
'pages/pdf/*.js',
'libs/marked.min.js',
'libs/mermaid.min.js',
'libs/webfontloader.js'
], {base: "."})
.pipe(gp_uglify().on('error', gulpUtil.log))
.pipe(gulp.dest('dist'));
});
gulp.task('copy-es-files', ['clean'], function() {
return gulp.src([
'background.js',
'pages/*.js'
], {base: "."})
.pipe(babel({presets: ['es2015']}))
.pipe(gp_uglify().on('error', gulpUtil.log))
.pipe(gulp.dest('dist'));
});
gulp.task('default', ['copy-pretty-default-js', 'build_common_content_min', 'use_common_content_min', 'use_common_content_min_manifest'], function() {
return gulp.src('dist/**')
.pipe(zip('sk.zip'))
.pipe(gulp.dest('dist'));
});