forked from behavior3/behavior3editor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
276 lines (243 loc) · 7.99 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
// GULP MODULES ===============================================================
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var minifyCSS = require('gulp-minify-css');
var minifyHTML = require('gulp-minify-html');
var connect = require('gulp-connect');
var less = require('gulp-less');
var jshint = require('gulp-jshint');
var foreach = require("gulp-foreach");
var zip = require("gulp-zip");
var packager = require('electron-packager');
var templateCache = require('gulp-angular-templatecache');
var replace = require('gulp-replace');
var stylish = require('jshint-stylish');
var exec = require('child_process').exec;
var fs = require('fs');
var rimraf = require('rimraf');
var merge = require('merge-stream');
var os = require('os');
var path = require('path');
// VARIABLES ==================================================================
var project = JSON.parse(fs.readFileSync('package.json', 'utf8'));
var build_version = project.version;
var build_date = (new Date()).toISOString().replace(/T.*/, '');
var is_win = /^win/.test(process.platform);
var is_ia32 = os.arch() == "ia32";
// FILES ======================================================================
var vendor_js = [
'src/assets/libs/createjs.min.js',
'src/assets/libs/creatine-1.0.0.min.js',
'src/assets/libs/behavior3js-0.1.0.min.js',
'src/assets/libs/mousetrap.min.js',
'bower_components/angular/angular.min.js',
'bower_components/angular-animate/angular-animate.min.js',
'bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js',
'bower_components/angular-ui-router/release/angular-ui-router.min.js',
'bower_components/sweetalert/dist/sweetalert.min.js',
];
var vendor_css = [
'bower_components/bootstrap/dist/css/bootstrap.min.css',
'bower_components/sweetalert/dist/sweetalert.css',
];
var vendor_fonts = [
'bower_components/fontawesome/fonts/*',
'src/assets/fonts/**/*',
];
var preload_js = [
'src/assets/js/preload.js',
];
var preload_css = [
'bower_components/fontawesome/css/font-awesome.min.css',
'src/assets/css/preload.css',
];
var app_js = [
'src/editor/namespaces.js',
'src/editor/utils/*.js',
'src/editor/**/*.js',
'src/app/app.js',
'src/app/app.routes.js',
'src/app/app.controller.js',
'src/app/**/*.js',
'src/start.js',
];
var app_less = [
'src/assets/less/index.less',
];
var app_imgs = [
'src/assets/imgs/**/*',
];
var app_html = [
'src/app/**/*.html',
];
var app_entry = [
'src/index.html',
'src/package.json',
'src/desktop.js',
]
// TASKS (VENDOR) =============================================================
gulp.task('_vendor_js', function() {
return gulp.src(vendor_js)
.pipe(uglify())
.pipe(concat('vendor.min.js'))
.pipe(gulp.dest('build/js'))
});
gulp.task('_vendor_css', function() {
return gulp.src(vendor_css)
.pipe(minifyCSS())
.pipe(concat('vendor.min.css'))
.pipe(gulp.dest('build/css'))
});
gulp.task('_vendor_fonts', function() {
return gulp.src(vendor_fonts)
.pipe(gulp.dest('build/fonts'))
});
gulp.task('_vendor', ['_vendor_js', '_vendor_css', '_vendor_fonts']);
// TASKS (PRELOAD) ============================================================
gulp.task('_preload_js', function() {
return gulp.src(preload_js)
.pipe(uglify())
.pipe(concat('preload.min.js'))
.pipe(gulp.dest('build/js'))
.pipe(connect.reload())
});
gulp.task('_preload_css', function() {
return gulp.src(preload_css)
.pipe(minifyCSS())
.pipe(concat('preload.min.css'))
.pipe(gulp.dest('build/css'))
.pipe(connect.reload())
});
gulp.task('_preload', ['_preload_js', '_preload_css']);
// TASKS (APP) ================================================================
gulp.task('_app_js_dev', function() {
return gulp.src(app_js)
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(replace('[BUILD_VERSION]', build_version))
.pipe(replace('[BUILD_DATE]', build_date))
.pipe(concat('app.min.js'))
.pipe(gulp.dest('build/js'))
.pipe(connect.reload())
});
gulp.task('_app_js_build', function() {
return gulp.src(app_js)
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(replace('[BUILD_VERSION]', build_version))
.pipe(replace('[BUILD_DATE]', build_date))
.pipe(uglify())
.pipe(concat('app.min.js'))
.pipe(gulp.dest('build/js'))
.pipe(connect.reload())
});
gulp.task('_app_less', function() {
return gulp.src(app_less)
.pipe(less())
.pipe(minifyCSS())
.pipe(concat('app.min.css'))
.pipe(gulp.dest('build/css'))
.pipe(connect.reload())
});
gulp.task('_app_imgs', function() {
return gulp.src(app_imgs)
.pipe(gulp.dest('build/imgs'))
});
gulp.task('_app_html', function() {
return gulp.src(app_html)
.pipe(minifyHTML({empty:true}))
.pipe(replace('[BUILD_VERSION]', build_version))
.pipe(replace('[BUILD_DATE]', build_date))
.pipe(templateCache('templates.min.js', {standalone:true}))
.pipe(gulp.dest('build/js'))
.pipe(connect.reload())
});
gulp.task('_app_entry', function() {
return gulp.src(app_entry)
// .pipe(minifyHTML({empty:true}))
.pipe(replace('[BUILD_VERSION]', build_version))
.pipe(replace('[BUILD_DATE]', build_date))
.pipe(gulp.dest('build'))
.pipe(connect.reload())
});
gulp.task('_app_dev', [
'_app_js_dev',
'_app_less',
'_app_imgs',
'_app_html',
'_app_entry'
]);
gulp.task('_app_build', [
'_app_js_build',
'_app_less',
'_app_imgs',
'_app_html',
'_app_entry'
]);
// TASKS (LIVE RELOAD) ========================================================
gulp.task('_livereload', function() {
connect.server({
livereload: true,
root: 'build',
port: 8000,
});
});
gulp.task('_watch', ['_livereload'], function() {
gulp.watch(preload_js, ['_preload_js']);
gulp.watch(preload_css, ['_preload_css']);
gulp.watch(app_js, ['_app_js_dev']);
gulp.watch(app_less, ['_app_less']);
gulp.watch(app_html, ['_app_html']);
gulp.watch(app_entry, ['_app_entry']);
});
// TASKS (NODE WEBKIT) ========================================================
gulp.task('_electron', ['build'], function(cb) {
packager({
dir : 'build',
out : '.temp-dist',
name : project.name,
platform : 'linux,win32',
arch : 'all',
version : '0.34.2',
overwrite : true,
asar : true
}, function done(err, appPath) {
cb(err);
})
});
gulp.task('_electron_zip', ['_electron'], function() {
return gulp.src('.temp-dist/*')
.pipe(foreach(function(stream, file) {
var fileName = file.path.substr(file.path.lastIndexOf("/")+1);
gulp.src('.temp-dist/'+fileName+'/**/*')
.pipe(zip(fileName+'.zip'))
.pipe(gulp.dest('./dist'));
return stream;
}));
});
gulp.task('_run_electron', ['_electron'], function() {
var plat;
var arch;
if (is_win) {
plat = "win32";
} else {
plat = "linux";
}
if (is_ia32) {
arch = "ia32";
} else {
arch = "x64";
}
var command = path.join(".temp-dist", "behavior3editor-" + plat + "-" + arch, "behavior3editor");
if (is_win) {
command = command + ".exe";
}
exec(command);
});
// COMMANDS ===================================================================
gulp.task('build', ['_vendor', '_preload', '_app_build']);
gulp.task('dev', ['_vendor', '_preload', '_app_dev']);
gulp.task('serve', ['_vendor', '_preload', '_app_dev', '_watch']);
gulp.task('dist', ['_electron_zip']);
gulp.task('nw', ['_run_electron']);