-
Notifications
You must be signed in to change notification settings - Fork 12
/
gulpfile.js
156 lines (139 loc) · 4.17 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*global require */
/*!
* @see {@link https://github.com/mildrenben/surface/blob/master/gulpfile.js}
* @see {@link https://www.webstoemp.com/blog/gulp-setup/}
* @see {@link https://gulpjs.com/plugins/blackList.json}
* @see {@link https://hackernoon.com/how-to-automate-all-the-things-with-gulp-b21a3fc96885}
* @see {@link https://stackoverflow.com/questions/36897877/gulp-error-the-following-tasks-did-not-complete-did-you-forget-to-signal-async}
* @see {@link https://zzz.buzz/2016/11/19/gulp-4-0-upgrade-guide/}
* @see {@link https://blog.khophi.co/migrate-gulp-4-complete-example/}
* @see {@link https://www.joezimjs.com/javascript/complete-guide-upgrading-gulp-4/}
* @see {@link https://codeburst.io/switching-to-gulp-4-0-271ae63530c0}
*/
var gulp = require("gulp");
var plumber = require("gulp-plumber");
var uglify = require("gulp-uglify");
var sourcemaps = require("gulp-sourcemaps");
var rename = require("gulp-rename");
var browserSync = require("browser-sync").create();
var reload = browserSync.reload;
/*!
* @see {@link https://github.com/babel/babel/issues/7910}
*/
var babel = require("gulp-babel");
var babelOptions;
babelOptions = {
"sourceType": "script",
"presets": ["@babel/env"],
"plugins": ["@babel/plugin-transform-object-assign",
"@babel/plugin-transform-arrow-functions",
"@babel/plugin-transform-async-to-generator"]
};
/*!
* @see {@link https://github.com/beautify-web/js-beautify}
* a JSON-formatted file indicated by the --config parameter
* a .jsbeautifyrc file containing JSON data at any level of the filesystem above $PWD
* using external config may cause
* failure to find it
* if the input/output files reside higher
* than the config file itself
*/
/* var beautify = require("gulp-jsbeautifier"); */
var beautifyOptions;
beautifyOptions = {
/* "config": ".jsbeautifyrc", */
"editorconfig": false,
"indent_size": 4,
"indent_char": "\t",
"indent_with_tabs": true,
"eol": "\n",
"end_with_newline": true,
"indent_level": 0,
"preserve_newlines": true,
"max_preserve_newlines": 10,
"html": {
"indent_inner_html": true,
"indent_scripts": false,
"js": {},
"css": {}
},
"css": {
"newline_between_rules": true
},
"js": {
"space_in_paren": false,
"space_in_empty_paren": false,
"jslint_happy": false,
"space_after_anon_function": true,
"space_after_named_function": false,
"brace_style": "collapse",
"unindent_chained_methods": false,
"break_chained_methods": true,
"keep_array_indentation": true,
"unescape_strings": false,
"wrap_line_length": 0,
"e4x": false,
"comma_first": false,
"operator_position": "before-newline"
}
};
/*!
* @see {@link https://prettier.io/docs/en/options.html}
* using external config may cause
* failure to find it
* if the input/output files reside higher
* than the config file itself
*/
var prettier = require("gulp-prettier");
var prettierOptions;
prettierOptions = {
/* "config": ".prettierrc", */
"tabWidth": 4,
"useTabs": true,
"endOfLine": "lf",
"printWidth:": 0
};
var stripDebug = require("gulp-strip-debug");
var eslint = require("gulp-eslint");
var options = {
libbundle: {
src: "./src/*.js",
js: "./js"
},
};
gulp.task("compile-libbundle-js", function () {
return gulp.src(options.libbundle.src)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(babel(babelOptions))
.pipe(prettier(prettierOptions))
/* .pipe(beautify(beautifyOptions)) */
.pipe(gulp.dest(options.libbundle.js))
.pipe(rename(function (path) {
path.basename += ".min";
}))
.pipe(stripDebug())
.pipe(uglify())
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(options.libbundle.js))
.pipe(plumber.stop());
});
gulp.task("lint-libbundle-js", function () {
return gulp.src(options.libbundle.src)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
/*!
* @see {@link https://browsersync.io/docs/gulp}
*/
gulp.task("browser-sync", gulp.series(gulp.parallel(
"lint-libbundle-js"), function watchChanges() {
browserSync.init({
server: "./"
});
gulp.watch("./*.html").on("change", reload);
gulp.watch("./js/*.js").on("change", reload);
gulp.watch("./src/*.js", gulp.parallel("compile-libbundle-js")).on("change", reload);
}));
gulp.task("default", gulp.task("browser-sync"));