-
Notifications
You must be signed in to change notification settings - Fork 461
/
gulpfile.js
283 lines (244 loc) · 7.5 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
var gulp = require("gulp");
var plugins = require("gulp-load-plugins")({ lazy: false });
var fs = require("fs");
var path = require("path");
// var os = require("os");
var del = require("del");
// var minimist = require("minimist");
//var NwBuilder = require('nw-builder');
//var pkg = require('./package');
require("shelljs/global");
var DIST = "./dist";
// function getCustomPath() {
// var minimist = require("minimist");
// var knownOptions = {
// string: "custom",
// default: { custom: "./custom" },
// };
// var options = minimist(process.argv.slice(2), knownOptions);
// if (options && options.custom) {
// var customPath = path.join(options.custom, "**/*");
// if (customPath.indexOf("~") == 0) {
// customPath = path.join(os.homedir(), customPath, "**/*");
// } else if (customPath.indexOf(".") == 0) {
// customPath = path.join(__dirname, customPath, "**/*");
// }
// }
// return customPath || "custom/**/*";
// }
//var VERSION = pkg.version;
var taskFns = {
appJS: function () {
console.log("--rebuilding app.js...");
//combine all js files of the app
gulp
.src(["!./app/**/*_test.js", "./app/**/*.js"])
//.pipe(plugins.jshint())
//.pipe(plugins.jshint.reporter('default'))
.pipe(
plugins.babel({
presets: ["es2015"],
})
)
.pipe(plugins.concat("app.js"))
.pipe(gulp.dest(DIST))
.on("end", function () {
console.log("--done");
});
},
templates: function () {
console.log("--rebuilding templates.js...");
//combine all template files of the app into a js file
gulp
.src(["!./app/index.html", "./app/**/*.html"])
.pipe(plugins.angularTemplatecache("templates.js", { standalone: true }))
.pipe(gulp.dest(DIST))
.on("end", function () {
console.log("--done");
});
},
appCSS: function () {
console.log("--rebuilding lib.css...");
gulp
.src("./app/**/*.css")
.pipe(plugins.concat("app.css"))
.pipe(gulp.dest(DIST))
.on("end", function () {
console.log("--done");
});
},
};
gulp.task("js", taskFns.appJS);
gulp.task("templates", taskFns.templates);
gulp.task("css", taskFns.appCSS);
gulp.task("libJS", function () {
//concatenate vendor JS files
// var arr = ['cmake',
// 'coffeescript','css','sass','javascript','jsx','htmlembedded','htmlmixed',
// 'dart','erlang','go','groovy','lua','python','php','perl','ruby', 'swift',
// 'java', 'xml',
// 'vbscript',
// 'r','rust',
// 'dockerfile', 'markdown','yaml'
// ];
var arr = [
"./node_modules/jquery/dist/jquery.js",
"./node_modules/jquery.qrcode/jquery.qrcode.min.js",
"./node_modules/moment/min/moment-with-locales.js",
"./node_modules/bootstrap/dist/js/bootstrap.js",
"./node_modules/angular/angular.js",
"./node_modules/angular-sanitize/angular-sanitize.js",
"./node_modules/angular-ui-router/release/angular-ui-router.js",
"./node_modules/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js",
"./node_modules/showdown/dist/showdown.js",
"./node_modules/clipboard/dist/clipboard.min.js",
//code mirror
"./vendor/diff_match_patch.js",
// angular-translate
"./vendor/angular-translate.min.js",
"./node_modules/angular-ui-codemirror/src/ui-codemirror.js",
"./node_modules/codemirror/lib/codemirror.js",
"./node_modules/codemirror/addon/mode/simple.js",
"./node_modules/codemirror/addon/merge/merge.js",
"./node_modules/codemirror/mode/meta.js",
"./node_modules/angular-bootstrap-contextmenu/contextMenu.js",
];
// code mirror modes
var modePath = "./node_modules/codemirror/mode/";
var modes = fs.readdirSync(modePath);
modes.forEach(function (n) {
arr.push(modePath + n + "/*.js");
});
gulp.src(arr).pipe(plugins.concat("lib.js")).pipe(gulp.dest(DIST));
});
gulp.task("libCSS", function () {
//concatenate vendor CSS files
gulp
.src([
"./node_modules/bootstrap/dist/css/bootstrap.css",
"./node_modules/font-awesome/css/font-awesome.css",
"./node_modules/codemirror/lib/codemirror.css",
"./node_modules/codemirror/addon/merge/merge.css",
])
.pipe(plugins.concat("lib.css"))
.pipe(gulp.dest(DIST + "/css"));
});
gulp.task("copy-fonts", function () {
gulp
.src([
"./node_modules/bootstrap/fonts/*",
"./node_modules/font-awesome/fonts/*",
])
.pipe(gulp.dest(DIST + "/fonts"));
});
gulp.task("copy-icons", function () {
gulp.src("./app/icons/**").pipe(gulp.dest(DIST + "/icons"));
});
gulp.task("copy-node", function () {
gulp.src(["./node/**/*"]).pipe(gulp.dest(DIST + "/node"));
});
gulp.task("copy-docs", function () {
gulp.src(["./release-notes/**/*"]).pipe(gulp.dest(DIST + "/release-notes"));
});
gulp.task("copy-static", function () {
gulp.src(["./static/**/*"]).pipe(gulp.dest(DIST + "/static"));
});
// gulp.task('copy-custom', function () {
//
// gulp.src([getCustomPath()])
// .pipe(gulp.dest(DIST+'/custom'));
// });
gulp.task("copy-index", function () {
return gulp
.src([
"./app/index.html",
"./main.js",
"./server.js",
"./vendor/*.js",
"./release-notes.md",
"./tools/.yarnclean",
])
.pipe(gulp.dest(DIST));
});
gulp.task("gen-package", ["copy-index"], function () {
return gulp.src(["./package.json"]).on("end", function (cb) {
var info = require("./package");
delete info.devDependencies;
info.scripts = {
start: "electron .",
};
info.main = "main.js";
// var custom = {};
// try{ custom = require('./custom') }catch(e){}
// if(custom.appId){
// info.name= custom.appId;
// info.version = custom.version;
// }
try {
fs.statSync(DIST);
} catch (e) {
fs.mkdirSync(DIST);
}
fs.writeFileSync(DIST + "/package.json", JSON.stringify(info, " ", 2));
// eslint-disable-next-line no-undef
exec("cd dist && yarn install --prod && yarn autoclean --force", cb);
});
});
gulp.task("remove-redundant", ["gen-package"], function () {
return del.sync([
"dist/node_modules/protobufjs/dist",
"dist/node_modules/aliyun-sdk/dist",
]);
});
gulp.task("watch", function () {
gulp.watch(
[
// '!'+DIST+'/node_modules/**/*',
DIST + "/**/*.html",
DIST + "/!(node_modules)/*.js",
DIST + "/**/*.css",
],
function (event) {
return gulp.src(event.path).pipe(plugins.connect.reload());
}
);
gulp.watch(["app/**/*"], function (event) {
console.log(Math.random(), event);
if (event.path.endsWith(".js") && !event.path.endsWith("_test.js"))
taskFns.appJS();
if (
event.path.endsWith(".html") &&
event.path != path.join(__dirname, "app/index.html")
)
taskFns.templates();
if (event.path.endsWith(".css")) taskFns.appCSS();
});
// gulp.watch(['./app/**/*.js', '!./app/**/*test.js'], ['js']);
// gulp.watch(['!./app/index.html', './app/**/*.html'], ['templates']);
// gulp.watch('./app/**/*.css', ['css']);
gulp.watch(["./app/index.html", "./main.js"], ["copy-index"]);
gulp.watch(["./static/**"], ["copy-static"]);
//gulp.watch(['./custom/**'], ['copy-custom']);
gulp.watch(["./node/**"], ["copy-node"]);
});
// gulp.task('connect', plugins.connect.server({
// root: [DIST],
// port: 9000,
// livereload: true
// }));
gulp.task("build", [
"js",
"templates",
"css",
"copy-index",
"libJS",
"libCSS",
"copy-fonts",
"copy-node",
"copy-docs",
"copy-icons",
"copy-static",
"gen-package",
"remove-redundant",
]);
gulp.task("default", ["build", "watch"]);