-
Notifications
You must be signed in to change notification settings - Fork 55
/
gulpfile.js
382 lines (337 loc) · 11.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
var gulp = require('gulp');
var git = require('gulp-git');
var express = require('express');
var browserSync = require('browser-sync');
var runSequence = require('run-sequence');
var tslint = require('gulp-tslint');
var typedoc = require("gulp-typedoc");
var superstatic = require('superstatic');
var shell = require("gulp-shell");
var Rsync = require('rsync');
var opn = require('opn');
var typescript = require('gulp-typescript');
var tsProject = typescript.createProject('tsconfig.json');
var sourcemaps = require('gulp-sourcemaps');
var rimraf = require("gulp-rimraf");
var replace = require("gulp-replace");
var insert = require("gulp-insert");
var concat = require("gulp-concat");
var uglify = require("gulp-uglify");
var tslintStylish = require('gulp-tslint-stylish');
var util = require('gulp-util');
//var commentSwap = require('gulp-comment-swap');
//var tsc = require('gulp-typescript');
// current version [email protected]
// jspm bundle src/App.js ./dist/index.js --skip-source-maps
// jspm bundle App.ts dev-bundle.js --watch
// https://github.com/jspm/jspm.io/pull/43/files?short_path=4cea63c#diff-4cea63c9d39d3e90a68b25b0030e90aa
/** Typescript configuration **/
var paths = {
dist: "./dist",
assets: "./dist/public/assets",
jspm: "./dist/jspm_packages",
sources: "./src/**/*.ts",
sourcesToCopy: ["index.html"],
targetHTML: "./src/public/index.html",
bundleHTML: "./dist/public",
targetJS: "index.js",
targetMinifiedJS: "index.min.js"
};
/**********************
* public commands
*********************/
gulp.task("production", function (callback) {
runSequence(
"x_clean",
"x_assets",
"x_jspm",
"x_copy_files",
"x_build-ts",
"x_copy",
"x_bundle",
"x_minify",
"x_target",
"x_clear_remote",
"x_rsync",
//'x_open_server_bundle',
"x_rsync",
function (error) {
if (error) {
console.log(error.message);
} else {
console.log("FINISHED SUCCESSFULLY");
}
callback(error);
});
});
/** launch the systemjs development server, files are kept raw
* run it from the command line via:
*
* gulp development (will launch browser)
* gulp development --restart (will not launch browser and restart daemon every 10min for best performance)
*
**/
gulp.task('development', function (done) {
console.log(util.env.restart)
if (util.env.restart) {
runSequence('x_open_server_development_auto', done);
} else {
runSequence('x_open_server_development', done);
}
});
gulp.task('typedocs', function (done) {
runSequence('x_typedocs', 'x_docs_rsync', 'x_docs_chown1', 'x_docs_chown2', done);
});
/** secure.digitalsignage.com **/
gulp.task('x_rsync', function () {
var rsync = Rsync.build({
source: '/cygdrive/c/msweb/studioDashboard/dist/',
destination: '[email protected]:/var/www/sites/dynasite/htdocs/_msportal/_js/_node/public/',
exclude: ['*.bat', '*.iml', '.gitignore', '.git', '.idea/']
});
rsync.set('progress');
rsync.flags('avzp');
console.log('running the command ' + rsync.command());
rsync.output(
function (data) {
console.log('sync: ' + data);
}, function (data) {
console.log('sync: ' + data);
}
);
rsync.execute(function (error, stdout, stderr) {
console.log('completed ' + error + ' ' + stdout + ' ' + stderr)
});
});
/** Monster Signage **/
// gulp.task('x_rsync', function () {
// var rsync = Rsync.build({
// source: '/cygdrive/c/msweb/studioDashboard/dist/',
// destination: '[email protected]:/var/www/sites/monstersignage/htdocs',
// exclude: ['*.bat', '*.iml', '.gitignore', '.git', '.idea/']
// });
// rsync.set('progress');
// rsync.flags('avzp');
// console.log('running the command ' + rsync.command());
// rsync.output(
// function (data) {
// console.log('sync: ' + data);
// }, function (data) {
// console.log('sync: ' + data);
// }
// );
// rsync.execute(function (error, stdout, stderr) {
// console.log('completed ' + error + ' ' + stdout + ' ' + stderr)
// });
// });
/** upload files to remote server for distribution **/
gulp.task('x_docs_rsync', function () {
var rsync = Rsync.build({
source: '/cygdrive/c/msweb/studioDashboard/docs',
destination: '[email protected]:/var/www/sites/mediasignage.com/htdocs/dashDocs'
});
rsync.set('progress');
rsync.flags('avzp');
console.log('running the command ' + rsync.command());
rsync.output(
function (data) {
console.log('sync: ' + data);
}, function (data) {
console.log('sync: ' + data);
}
);
rsync.execute(function (error, stdout, stderr) {
console.log('completed ' + error + ' ' + stdout + ' ' + stderr)
});
});
/** Dangerous, this will wipe your current source and sync with GitHub **/
gulp.task('vanish***', function (done) {
var c = 8;
console.log('Starting in ' + c + ' seconds');
var handler = setInterval(function () {
c--;
console.log('syncing in ---> ' + c);
if (c == 0) {
clearInterval(handler);
console.log('sync');
runSequence('x_gitReset', 'x_gitPull', done);
}
}, 1000)
});
/**********************
* private commands x_...
*********************/
/** Generate project documentation **/
gulp.task("x_typedocs", function () {
return gulp
.src(["./src/*.ts"])
.pipe(typedoc({
module: "system",
target: "es5",
theme: "default",
experimentalDecorators: true,
ignoreCompilerErrors: true,
includeDeclarations: false,
out: "docs",
name: "studioDashboard",
version: true
}))
});
/** Transpile TypeScript files **/
gulp.task('x_build-ts', function () {
return gulp.src('./src/**/*.ts')
.pipe(sourcemaps.init())
.pipe(typescript(tsProject))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./src'));
});
/** bundle the app with jspm **/
// 0.16 jspm bundle-sfx src/App.js ./dist/index.js --skip-source-maps
// 0.17 jspm bundle src/App.js ./dist/index.js --skip-source-maps
gulp.task("x_bundle",
shell.task(["jspm bundle src/App.js " + paths.dist + "/" + paths.targetJS + ' --skip-source-maps'])
);
gulp.task("x_docs_chown1",
shell.task(["ssh [email protected] chown -R Sean /var/www/sites/mediasignage.com/htdocs/dashDocs/*"])
);
gulp.task("x_docs_chown2",
shell.task(["ssh [email protected] chmod -R 777 /var/www/sites/mediasignage.com/htdocs/dashDocs/*"])
);
gulp.task("x_clear_remote",
shell.task(["ssh [email protected] rm -r -f /var/www/sites/dynasite/htdocs/_msportal/_js/_node/public/src"])
);
/** execute a hard reset on git head to latest **/
gulp.task('x_gitReset', function () {
git.exec({args: '-c core.quotepath=false reset --hard HEAD --'}, function (err, stdout) {
if (err) throw err;
});
});
/** execute a git pull **/
gulp.task('x_gitPull', function () {
git.exec({args: '-c core.quotepath=false pull --progress --no-stat -v --progress origin master'}, function (err, stdout) {
if (err) throw err;
});
});
gulp.task('x_open_server_bundle', function () {
opn('http://monstersignage.com/public/index.html');
});
// gulp.task('x_open_server_bundle', function () {
// server = express();
// server.use(express.static('./'));
// server.listen(8003);
// browserSync({
// open: false,
// port: 8080,
// proxy: 'localhost:8003',
// reloadDelay: '1000'
// });
// opn('https://secure.digitalsignage.com/_studiodash-dist/index.html');
// });
// , '**/*.ts','**/*.html','**/*.css'
gulp.task('x_open_server_development', ['x_watch_source'], function () {
process.stdout.write('Starting browserSync and superstatic...\n');
browserSync({
port: 8080,
open: false,
files: ['index.html'],
notify: true,
reloadDebounce: 400,
server: {
baseDir: './',
directory: true
}
});
opn('http://localhost:8080/src/public/index.html')
});
/**
* to get a fresh server every x minutes for better dev performance run:
* forever stop 0 ; forever start -a -l f.log node_modules/gulp/bin/gulp.js development_auto ; tail -f ~/.forever/f.log
**/
//files: ['index.html', '**/*.ts','**/*.html','**/*.css'],
gulp.task('x_open_server_development_auto', ['x_watch_source'], function () {
process.stdout.write('Starting browserSync and superstatic...\n');
browserSync({
port: 8080,
open: false,
files: ['index.html', '**/*.ts'],
notify: true,
reloadDebounce: 400,
server: {
baseDir: './',
directory: true
}
});
// exit every 20 minutes so forever will restart it
setTimeout(function () {
process.exit()
}, 3200000);
});
gulp.task('x_assets', function () {
return gulp.src([
'./src/public/assets/**/*'
]).pipe(gulp.dest(paths.assets));
});
gulp.task('x_jspm', function () {
return gulp.src([
'./jspm_packages/sys*'
]).pipe(gulp.dest(paths.jspm));
});
gulp.task('x_copy_files', function () {
gulp.src(['./src/**/*.html', './src/**/*.woff2', './src/**/*.css'
]).pipe(gulp.dest(paths.dist));
gulp.src([
'./src/public/world_data.js',
'./jspm.config.js',
'./jspm.browser.js',
]).pipe(gulp.dest(paths.bundleHTML));
return gulp.src(['./**/*.html', './**/*.woff2', './**/*.css'
]).pipe(gulp.dest(paths.dist));
});
gulp.task("x_lint", function () {
return gulp.src(paths.sources)
.pipe(tslint())
.pipe(tslint.report(tslintStylish, {
emitError: true,
sort: true,
bell: true
}));
});
gulp.task('x_watch_source', function () {
gulp.watch([paths.sources]);
});
// Delete the dist directory
gulp.task("x_clean", function () {
return gulp.src(paths.dist, {read: false}).pipe(rimraf({force: true}));
});
// copy required sources to the dist folder
gulp.task("x_copy", function () {
gulp.src(paths.sourcesToCopy).pipe(gulp.dest(paths.dist));
});
gulp.task("x_minify", function () {
gulp.src(paths.targetJS, {cwd: paths.dist})
.pipe(uglify({mangle: false}))
.pipe(concat("index.min.js"))
.pipe(gulp.dest(paths.bundleHTML));
});
var finalIndex = '' +
'<script src="../jspm_packages/system.js"></script>' +
'<script src="jspm.browser.js"></script>' +
'<script src="jspm.config.js"></script>' +
'<script src="./index.min.js"></script>' +
'<script>' +
'SystemJS.import("src/App.js")' +
'.catch(function (e) { console.error(e,"error system.js " + e); }) ' +
'</script>'
// update index.html to point to the minified bundle
gulp.task("x_target", function () {
gulp.src([paths.targetHTML])
// remove script tags
.pipe(replace(/<!-- sys_import_start -->[^]+<!-- sys_import_end -->/, ""))
.pipe(replace(/<!-- sys_import_start -->[^]+<!-- sys_import_end -->/, ""))
.pipe(replace(/<!-- config_start -->[^]+<!-- config_end -->/, ""))
.pipe(replace(/<!-- sys_jspm_start -->[^]+<!-- sys_jspm_end -->/, finalIndex))
//.pipe(replace(/<script.*\n.*\n<\/script>/g, ""))
//.pipe(replace(/\n\n/g, "\n"))
//.pipe(insert.append("\n<script src='" + paths.targetMinifiedJS + "'></script>"))
.pipe(gulp.dest(paths.bundleHTML))
});