-
Notifications
You must be signed in to change notification settings - Fork 644
/
gulpfile.js
268 lines (245 loc) · 7.77 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
const gulp = require("gulp"),
// sass = require("gulp-ruby-sass"),
// autoprefixer = require("gulp-autoprefixer"),
minifycss = require("gulp-clean-css"),
jshint = require("gulp-jshint"),
uglify = require("gulp-uglify"),
// imagemin = require("gulp-imagemin"),
// rename = require("gulp-rename"),
concat = require("gulp-concat"),
notify = require("gulp-notify"),
cache = require("gulp-cache"),
livereload = require("gulp-livereload"),
del = require("del"),
fs = require("fs"),
path = require("path"),
beautify = require("js-beautify").js_beautify,
run = require("run-sequence"),
// wiredep = require("wiredep").stream,
connect = require("gulp-connect"),
// mainBowerFiles = require("gulp-main-bower-files"),
// babel = require("gulp-babel"),
// gutil = require("gulp-util"),
typescript = require("gulp-tsc"),
source = require('vinyl-source-stream'),
browserify = require("browserify"),
tsify = require("tsify");
// obfuscate = require("gulp-obfuscate");
gulp.task("clean-dist", () => {
return del(["dist/**/*"], { force: true });
});
gulp.task("index", function() {
return browserify({
basedir: '.',
debug: true,
entries: ['app/src/index.ts'],
cache: {},
packageCache: {}
})
.plugin(tsify)
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest("dist/js"));
});
gulp.task("compile", function() {
return gulp
.src(["./app/src/**/*.ts"])
.pipe(
typescript({
sourceMap: true,
target: "ES2015",
module: "commonjs"
})
)
.pipe(gulp.dest("./dist/"));
});
// gulp.task("bower", function() {
// gulp
// .src("./src/index.html")
// .pipe(
// wiredep({
// optional: "configuration",
// goes: "here"
// })
// )
// .pipe(gulp.dest("./dist/"))
// .pipe(notify({ message: "bower task complete" }));
// });
// gulp.task('main-bower-files', function () {
// return gulp.src('./bower.json')
// .pipe(mainBowerFiles({
// overrides: {
// 'kityminder-editor': {
// main: [
// './dist/images/*.*',
// './dist/kityminder.editor.css',
// './dist/kityminder.editor.js'
// ]
// },
// bootstrap: {
// main: [
// './dist/js/bootstrap.js',
// './dist/css/*.*',
// './dist/fonts/*.*'
// ]
// }
// }
// }))
// .pipe(gulp.dest('./dist/libs'));
// });
// gulp.task('clean-libs', () => {
// return del(['dist/libs'], { force: true });
// });
gulp.task("copy-i18n-vendor", function() {
// i18n
return gulp
.src(["locale/*.json"])
.pipe(gulp.dest("dist/locale"));
});
gulp.task("copy-js-vendor", function() {
// 解决需要引入的问题,单独处理
gulp
.src(["bower_components/jquery/dist/jquery.min.js"])
.pipe(gulp.dest("dist/js"));
return gulp
.src([
"bower_components/jquery/dist/jquery.min.js",
"bower_components/bootstrap/dist/js/bootstrap.min.js",
"bower_components/bootbox.js/bootbox.js",
"bower_components/angular/angular.min.js",
"bower_components/angular-bootstrap/ui-bootstrap-tpls.js",
"bower_components/codemirror/lib/codemirror.js",
"bower_components/codemirror/mode/xml/xml.js",
"bower_components/codemirror/mode/javascript/javascript.js",
"bower_components/codemirror/mode/css/css.js",
"bower_components/codemirror/mode/htmlmixed/htmlmixed.js",
"bower_components/codemirror/mode/markdown/markdown.js",
"bower_components/codemirror/addon/mode/overlay.js",
"bower_components/codemirror/mode/gfm/gfm.js",
"bower_components/angular-ui-codemirror/ui-codemirror.js",
"bower_components/marked/lib/marked.js",
"bower_components/kity/dist/kity.min.js",
"bower_components/hotbox/hotbox.js",
"bower_components/json-diff/json-diff.js",
"bower_components/kityminder-core/dist/kityminder.core.min.js",
"bower_components/color-picker/dist/color-picker.js",
"bower_components/kityminder-editor/dist/kityminder.editor.js"
])
.pipe(concat("vendor.js"))
.pipe(uglify())
.pipe(gulp.dest("dist/js"))
.pipe(notify({ message: "Scripts task complete" }));
});
gulp.task("copy-css-vendor", function() {
return gulp
.src([
"bower_components/bootstrap/dist/css/bootstrap.css",
"bower_components/codemirror/lib/codemirror.css",
"bower_components/hotbox/hotbox.css",
"bower_components/kityminder-core/dist/kityminder.core.css",
"bower_components/color-picker/dist/color-picker.css",
"bower_components/kityminder-editor/dist/kityminder.editor.css"
])
.pipe(concat("vendor.css"))
.pipe(minifycss())
.pipe(gulp.dest("dist/style"))
.pipe(notify({ message: "css task complete" }));
});
gulp.task("copy-font-vendor", function() {
return gulp
.src("bower_components/bootstrap/dist/fonts/*.*")
.pipe(gulp.dest("dist/fonts"));
});
gulp.task("copy-images-vendor", function() {
return gulp
.src(["bower_components/kityminder-editor/dist/images/*.*"])
.pipe(gulp.dest("dist/style/images"));
});
gulp.task("copy-html-vendor", function() {
gulp.src("./app/static/index.html").pipe(gulp.dest("dist"));
gulp.src("./app/src/ui/pref_dialog.seg.html").pipe(gulp.dest("dist/ui"));
// gulp.src("./app/static/favicon.ico").pipe(gulp.dest("dist"));
});
gulp.task("copy-css", function() {
return gulp
.src("app/**/*.css")
.pipe(minifycss())
.pipe(gulp.dest("dist/"))
.pipe(notify({ message: "css task complete" }));
});
gulp.task("copy-js", function() {
return (
gulp
.src(["src/**/*.js"])
.pipe(concat("main.js"))
// 语法检查
.pipe(jshint())
.pipe(jshint.reporter("default"))
//压缩
.pipe(
uglify({
mangle: false, //类型:Boolean 默认:true 是否修改变量名
compress: true //类型:Boolean 默认:true 是否完全压缩
})
)
// 混淆
// .pipe(obfuscate())
// 输出到文件夹
.pipe(gulp.dest("dist/js"))
.pipe(notify({ message: "Scripts task complete" }))
);
});
gulp.task("webserver", function() {
connect.server({ port: 8848 });
});
gulp.task("default", function(done) {
run(
"clean-dist",
"build-version",
// "index",
"compile",
"copy-css",
// "copy-js",
"copy-html-vendor",
// 'bower',
// 'main-bower-files',
"copy-css-vendor",
"copy-i18n-vendor",
"copy-js-vendor",
"copy-font-vendor",
"copy-images-vendor",
// 'clean-libs',
done
);
});
gulp.task("watch", function() {
// Create LiveReload server
livereload.listen();
// Watch any files in dist/, reload on change
gulp.watch(["dist/**"]).on("change", livereload.changed);
});
gulp.task("build-version", () => {
// build next version num.
let url = path.join(__dirname, "app/src", "version.ts");
let text = fs.readFileSync(url, "utf-8");
let version = text
.substring(text.indexOf("[") + 1, text.lastIndexOf("]"))
.replace(/ /gi, "")
.split(",");
version[0] = parseInt(version[0]);
version[1] = parseInt(version[1]);
version[2] = parseInt(version[2]);
version[3]++;
// let version = require("./dist/version").version;
// version[3]++;
console.log(`version -> ${version.join(".")}`);
let cnt = beautify(`export let version = ${JSON.stringify(version)};`);
fs.writeFileSync(url, cnt, "utf-8");
// update package.json
url = "./package.json";
cnt = fs.readFileSync(url);
let d = JSON.parse(cnt);
d.version = version.slice(0, 3).join(".");
cnt = beautify(JSON.stringify(d), { indent_size: 2 });
fs.writeFileSync(url, cnt, "utf-8");
});