UNPKG

29.9 kBJavaScriptView Raw
1/*global process, __dirname */
2
3var gulp = require('gulp');
4var del = require('del');
5var preprocess = require('gulp-preprocess');
6var less = require('gulp-less');
7var rename = require("gulp-rename");
8var minifyCSS = require('gulp-minify-css');
9var uglify = require('gulp-uglify');
10var gutil = require('gulp-util');
11var concat = require('gulp-concat');
12var runSequence = require('run-sequence').use(gulp);
13var eventStream = require('event-stream');
14var ngTemplates = require('gulp-ng-templates');
15var htmlmin = require('gulp-htmlmin');
16
17var fs = require('fs-extra');
18var path = require('path');
19var server = require('server-root');
20var _ = require('underscore');
21
22_.str = require('underscore.string');
23
24var TARGET_FOLDER = 'www';
25
26var app = require('./src/app/index.js').create();
27var appMode = 'DEVELOPMENT';
28
29var modulePaths = [];
30var moduleNames = [];
31
32var getModuleFolderPath = function (installedPath) {
33 var modulePath = installedPath.split('/');
34 modulePath.pop();
35 modulePath.pop();
36 modulePath = modulePath.join('/');
37 return modulePath;
38}
39
40gulp.task('setCurrentDirectory', function () {
41 process.chdir(server.getPath(''));
42});
43
44gulp.task('copyLocalBowerComponents', function () {
45 gulp.src('./bower/**')
46 .pipe(gulp.dest('./bower_components'));
47});
48
49gulp.task('copyLocalNodeModules', function () {
50 var gulps = [];
51
52 var modules = undefined;
53 if (fs.existsSync(server.getPath('npm/modules'))) {
54 modules = _.filter(fs.readFileSync(server.getPath('npm/modules'), { encoding: 'utf8' }).split('\r\n'), function (x) {
55 return x !== undefined && x !== '';
56 });
57 }
58
59 if (fs.existsSync(server.getPath('npm'))) {
60 var packages = fs.readdirSync(server.getPath('npm'));
61 _.each(packages, function (packageItem) {
62 if (fs.lstatSync(server.getPath('npm/' + packageItem)).isDirectory()) {
63 del.sync('./node_modules/' + packageItem);
64
65 if (modules !== undefined) {
66 if (modules.indexOf(packageItem) !== -1) {
67 gulps.push(gulp.src('./npm/' + packageItem + '/**')
68 .pipe(gulp.dest('./node_modules/' + packageItem)));
69 }
70 }
71 else {
72 gulps.push(gulp.src('./npm/' + packageItem + '/**')
73 .pipe(gulp.dest('./node_modules/' + packageItem)));
74 }
75 }
76 });
77 }
78
79 if (gulps.length > 0)
80 return eventStream.merge(gulps);
81
82});
83
84gulp.task('loadModules', function () {
85
86 var paths = [];
87 _.each(modulePaths, function (modulePath) {
88 var mPath = getModuleFolderPath(modulePath);
89 mPath = mPath.replace(/\//g, '\\') + '\\';
90 paths.push(mPath);
91 });
92
93 Object.keys(require.cache).forEach(function (key) {
94 var strippedKey = key.substring(__dirname.length + 1);
95 if (_.any(paths, function (x) {
96 return strippedKey.indexOf(x) === 0;
97 }))
98 delete require.cache[key];
99 });
100
101 app = require('./src/app/index.js').create();
102
103 modulePaths = [];
104
105 var getModule = function (indexPath) {
106 if (fs.existsSync(indexPath)) {
107 var packObject = require(indexPath);
108 if (packObject && packObject.domain) {
109 return packObject;
110 }
111 }
112 return undefined;
113 }
114
115 moduleNames = [];
116
117 var mainPackageInfoPath = server.getPath('package.json');
118 if (fs.existsSync(mainPackageInfoPath)) {
119 var mainPackInfo = require(mainPackageInfoPath);
120 if (mainPackInfo.main) {
121
122 var module = getModule(server.getPath(mainPackInfo.main));
123 if (module) {
124 if (module.domain === 'core') {
125 modulePaths.push(mainPackInfo.main);
126 moduleNames.push('jsnbt');
127 app.register(module);
128 }
129 }
130 }
131 }
132
133 if (fs.existsSync(server.getPath('node_modules'))) {
134 var packages = fs.readdirSync(server.getPath('node_modules'));
135 _.each(packages, function (packageItem) {
136 if (_.str.startsWith(packageItem, 'jsnbt')) {
137 if (moduleNames.indexOf(packageItem) === -1) {
138 if (fs.lstatSync(server.getPath('node_modules/' + packageItem)).isDirectory()) {
139 var nodeModulePackagePath = server.getPath('node_modules/' + packageItem + '/package.json');
140
141 if (fs.existsSync(nodeModulePackagePath)) {
142 var nodeModulePackage = require(nodeModulePackagePath);
143
144 if (nodeModulePackage.main) {
145 var nodeModuleIndexPath = server.getPath('node_modules/' + packageItem + '/' + nodeModulePackage.main);
146 var nodeModuleIndexModule = getModule(server.getPath('node_modules/' + packageItem + '/' + nodeModulePackage.main));
147 if (nodeModuleIndexModule) {
148
149 modulePaths.push('node_modules/' + packageItem + '/' + nodeModulePackage.main);
150 app.register(nodeModuleIndexModule);
151
152 moduleNames.push(packageItem);
153 }
154 }
155 }
156 }
157 }
158 }
159 });
160 }
161
162 var mainPackageInfoPath = server.getPath('package.json');
163 if (fs.existsSync(mainPackageInfoPath)) {
164 var mainPackInfo = require(mainPackageInfoPath);
165 if (mainPackInfo.main) {
166
167 var module = getModule(server.getPath(mainPackInfo.main));
168 if (module) {
169 if (module.domain === 'core') {
170 var dbgModule = getModule(server.getPath('dbg/app/index.js'));
171 if (dbgModule) {
172 modulePaths.push('dbg/app/index.js');
173 moduleNames.push('public');
174 app.register(dbgModule);
175 }
176 }
177 if (module.domain === 'public') {
178 modulePaths.push(mainPackInfo.main);
179 moduleNames.push('public');
180 app.register(module);
181 }
182 }
183 }
184 }
185
186});
187
188gulp.task('installBowerComponents', function (done) {
189 var exec = require('child_process').exec;
190
191 var tasks = [];
192
193 var bowerPackages = [];
194
195 var bowerConfigs = [];
196
197 _.each(app.modules.all, function (module) {
198 if (typeof (module.getBower) === 'function') {
199 var bowerConfig = module.getBower();
200 bowerConfigs.push(bowerConfig);
201 }
202 });
203
204 _.each(bowerConfigs, function (bowerConfig) {
205 if (bowerConfig.dependencies) {
206 for (var dep in bowerConfig.dependencies) {
207 var packOptions = {
208 name: dep,
209 version: bowerConfig.dependencies[dep]
210 };
211 bowerPackages.push(packOptions);
212 }
213 }
214 });
215
216 var runTasks = function () {
217 var task = tasks.shift();
218 if (task)
219 task(runTasks);
220 else {
221
222 var folders = fs.readdirSync(server.getPath('bower_components'));
223
224 _.each(folders, function (folder) {
225 if (!fs.existsSync(server.getPath('bower/' + folder))) {
226 if (!_.any(bowerPackages, function (x) {
227 return (x.name + '-' + x.version) === folder;
228 })) {
229 gutil.log('bower: deleting obsolete ' + folder);
230 del.sync(server.getPath('bower_components/' + folder));
231 gutil.log('bower: deleted obsolete ' + folder);
232 }
233 }
234 });
235
236 done();
237 }
238 };
239
240 _.each(bowerPackages, function (bowerPackage) {
241 tasks.push(function (cb) {
242 if (!fs.existsSync(server.getPath('bower_components/' + bowerPackage.name + '-' + bowerPackage.version)) && !fs.existsSync(server.getPath('bower/' + bowerPackage.name))) {
243 gutil.log('bower: installing ' + bowerPackage.name + '#' + bowerPackage.version);
244 exec('bower install ' + bowerPackage.name + '-' + bowerPackage.version + '=' + bowerPackage.name + '#' + bowerPackage.version
245 + ' --config.analytics=false'
246 + ' --allow-root'
247 + ' -f',
248 { cwd: './' }, function (err, stdout, stderr) {
249 if (err)
250 throw err;
251
252 del.sync('./bower_components/' + bowerPackage.name);
253 gutil.log('bower: installed ' + bowerPackage.name + '#' + bowerPackage.version);
254
255 cb();
256 });
257 }
258 else {
259 cb();
260 }
261 });
262 });
263
264 runTasks();
265});
266
267gulp.task('cleanTarget', function () {
268
269 var targets = [
270 TARGET_FOLDER + '/migrations',
271 TARGET_FOLDER + '/mode',
272 TARGET_FOLDER + '/modules'
273 ];
274
275 if (fs.existsSync(server.getPath(TARGET_FOLDER + '/public'))) {
276 var publicFolders = fs.readdirSync(server.getPath(TARGET_FOLDER + '/public'));
277 var restricted = ['files', 'tmp'];
278 _.each(publicFolders, function (pf) {
279 if (restricted.indexOf(pf) === -1)
280 targets.push(TARGET_FOLDER + '/public/' + pf);
281 });
282 }
283
284 del.sync(targets);
285
286 if (!fs.existsSync(server.getPath(TARGET_FOLDER))) {
287 fs.mkdirpSync(server.getPath(TARGET_FOLDER));
288 fs.mkdirpSync(server.getPath(TARGET_FOLDER + '/public'));
289 fs.mkdirpSync(server.getPath(TARGET_FOLDER + '/migrations'));
290 }
291});
292
293gulp.task('setMode:dev', function () {
294
295 appMode = 'DEVELOPMENT';
296 fs.writeFileSync(TARGET_FOLDER + '/mode', 'dev', {
297 encoding: 'utf-8'
298 });
299
300});
301
302gulp.task('setMode:prod', function () {
303
304 appMode = 'PRODUCTION';
305 fs.writeFileSync(TARGET_FOLDER + '/mode', 'prod', {
306 encoding: 'utf-8'
307 });
308
309});
310
311gulp.task('setModules', function () {
312
313 var modulesText = modulePaths.join('\n');
314 fs.writeFileSync(TARGET_FOLDER + '/modules', modulesText, {
315 encoding: 'utf-8'
316 });
317
318});
319
320var getFileCopyPublicPaths = function (module, modulePath) {
321 var templatePaths = [];
322
323 if (typeof (module.getConfig) === 'function') {
324 var templates = module.getConfig().templates || [];
325
326 templatePaths = _.union(templatePaths, [
327 './' + modulePath + '/web/public/**',
328 '!./' + modulePath + '/web/public/files/**',
329 '!./' + modulePath + '/web/public/tmp/**',
330 '!./' + modulePath + '/web/public/err/**'],
331 _.filter(_.map(templates, function (x) {
332 if (!_.str.startsWith(x.html, '/admin/') || !_.str.startsWith(x.html, 'admin/'))
333 return '!./' + modulePath + '/web/public/' + _.str.ltrim(x.html, '/');
334 else
335 '';
336 }), function (f) {
337 return f !== '';
338 }));
339 }
340
341 return templatePaths;
342}
343
344var getFileCopyAdminPaths = function (module, modulePath) {
345 var adminTemplatePaths = [];
346
347 if (typeof (module.getConfig) === 'function') {
348 var templates = module.getConfig().templates || [];
349
350 adminTemplatePaths = _.union(adminTemplatePaths, ['./' + modulePath + '/web/admin/**',
351 '!./' + modulePath + '/web/admin/err/**',
352 '!./' + modulePath + '/web/admin/index.html'], _.filter(_.map(templates, function (x) {
353 if (_.str.startsWith(x.html, '/admin/') || _.str.startsWith(x.html, 'admin/'))
354 return '!./' + modulePath + '/web/admin/' + _.str.ltrim(x.html, '/');
355 else
356 return '';
357 }), function (f) {
358 return f !== '';
359 }));
360 }
361
362 return adminTemplatePaths;
363}
364
365gulp.task('copyFiles', function () {
366
367 var gulps = [];
368
369 var templatePaths = [];
370 var adminTemplatePaths = [];
371
372 _.each(moduleNames, function (moduleName, i) {
373
374 var module = require(server.getPath(modulePaths[i]));
375
376 var modulePath = getModuleFolderPath(modulePaths[i]);
377
378 templatePaths = _.union(templatePaths, getFileCopyPublicPaths(module, modulePath));
379 adminTemplatePaths = _.union(adminTemplatePaths, getFileCopyAdminPaths(module, modulePath));
380
381 });
382
383 gulps = [
384 gulp.src(templatePaths)
385 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public/')),
386
387 gulp.src(adminTemplatePaths)
388 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public/admin/'))];
389
390 if (gulps.length > 0)
391 return eventStream.merge(gulps);
392
393});
394
395gulp.task('parseTemplates', function () {
396
397 var gulps = [];
398
399 _.each(moduleNames, function (moduleName, i) {
400
401 var module = require(server.getPath(modulePaths[i]));
402
403 var modulePath = getModuleFolderPath(modulePaths[i]);
404
405 if (typeof (module.getConfig) === 'function') {
406 var templates = module.getConfig().templates || [];
407
408 _.each(templates, function (template) {
409 gulps.push(gulp.src('./' + modulePath + '/web/' + (!_.str.startsWith(template.html, '/admin/') && !_.str.startsWith(template.html, 'admin/') ? 'public/' : '') + _.str.ltrim(template.html, '/'))
410 .pipe(preprocess({ context: { NODE_ENV: appMode, DEBUG: false } }))
411 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public/' + _.str.ltrim(path.dirname(template.html), '/') + '/')));
412 });
413
414 }
415
416 gulps.push(gulp.src('./' + modulePath + '/web/public/err/*')
417 .pipe(preprocess({ context: { NODE_ENV: appMode, DEBUG: false } }))
418 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public/err/')));
419
420 gulps.push(gulp.src('./' + modulePath + '/web/admin/err/*')
421 .pipe(preprocess({ context: { NODE_ENV: appMode, DEBUG: false } }))
422 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public/admin/err/')));
423
424 });
425
426 if (gulps.length > 0)
427 return eventStream.merge(gulps);
428});
429
430gulp.task('generateJsnbtScript', function () {
431
432 var script = new require('./src/app/clib/script.js')(app);
433 var file = script.get();
434
435 fs.writeFileSync(server.getPath(TARGET_FOLDER + '/public/jsnbt.js'), file, {
436 encoding: 'utf8'
437 });
438
439});
440
441gulp.task('deployBowerComponents', function () {
442
443 var gulps = [];
444
445 var bowerConfigs = [];
446
447 _.each(app.modules.all, function (module) {
448 if (typeof (module.getBower) === 'function') {
449 var bowerConfig = module.getBower();
450 bowerConfigs.push(bowerConfig);
451 }
452 });
453
454 _.each(bowerConfigs, function (bowerConfig) {
455 var bowerComponents = 'bower_components';
456 if (bowerConfig.dependencies) {
457 if (bowerConfig.deploy) {
458 var bowerConfigKeys = _.keys(bowerConfig.deploy);
459 _.each(bowerConfigKeys, function (deployd) {
460 var packName = deployd;
461 if (bowerConfig.dependencies[packName]) {
462 var packSpecs = bowerConfig.deploy[packName];
463
464 if (packSpecs.folders) {
465 _.each(packSpecs.folders, function (folderSpecs) {
466 if (folderSpecs.src && folderSpecs.dest) {
467 folderSpecs.src = typeof (folderSpecs.src) !== 'string' ? folderSpecs.src : [folderSpecs.src];
468 folderSpecs.dest = typeof (folderSpecs.dest) !== 'string' ? folderSpecs.dest : [folderSpecs.dest];
469
470 _.each(folderSpecs.src, function (folderSpecsSrc) {
471 _.each(folderSpecs.dest, function (folderSpecsDest) {
472 var sourceDir = server.getPath(bowerComponents + '/' + folderSpecsSrc);
473 var targetDir = server.getPath(TARGET_FOLDER + '/public/' + folderSpecsDest);
474
475 gulps.push(gulp.src('./' + bowerComponents + '/' + folderSpecsSrc + '/**')
476 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public/' + folderSpecsDest)));
477 });
478 });
479 }
480 });
481 }
482 if (packSpecs.files) {
483 _.each(packSpecs.files, function (fileSpecs) {
484 if (fileSpecs.src && fileSpecs.dest) {
485 fileSpecs.src = typeof (fileSpecs.src) !== 'string' ? fileSpecs.src : [fileSpecs.src];
486 fileSpecs.dest = typeof (fileSpecs.dest) !== 'string' ? fileSpecs.dest : [fileSpecs.dest];
487
488 _.each(fileSpecs.src, function (fileSpecsSrc) {
489 _.each(fileSpecs.dest, function (fileSpecsDest) {
490 var sourceFile = server.getPath(bowerComponents + '/' + fileSpecsSrc);
491 var targetFile = server.getPath(TARGET_FOLDER + '/public/' + fileSpecsDest);
492
493 gulps.push(gulp.src('./' + bowerComponents + '/' + fileSpecsSrc)
494 .pipe(rename(path.basename(fileSpecsDest)))
495 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public/' + path.dirname(fileSpecsDest))));
496 });
497 });
498 }
499 });
500 }
501 }
502 });
503 }
504 }
505 });
506
507 if (gulps.length > 0)
508 return eventStream.merge(gulps);
509
510});
511
512gulp.task('generateStyles', function () {
513
514 var gulps = [];
515
516 var bundler = require('./src/app/tmpl/bundle.js')(app);
517 _.each(app.config.templates, function (tmpl) {
518
519 if (tmpl.styles && _.isArray(tmpl.styles)) {
520 var styleBundle = bundler.getStyleBundle(tmpl.styles);
521 _.each(styleBundle.raw, function (r) {
522 if (r.items.length > 0) {
523
524 var g = gulp.src(_.map(r.items, function (x, i) {
525 return './' + TARGET_FOLDER + '/public' + (_.str.startsWith(x, '/admin/') ? x : '' + x)
526 })).pipe(less({
527 }));
528
529 if (appMode === 'PRODUCTION') {
530 g = g.pipe(minifyCSS());
531 }
532
533 g = g.pipe(concat('less-files.less'))
534 .pipe(rename(path.basename(r.target)))
535 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public' + path.dirname(r.target)));
536
537 gulps.push(g);
538 }
539 });
540 }
541
542 });
543
544 if (gulps.length > 0)
545 return eventStream.merge(gulps);
546});
547
548gulp.task('checkStructure', function () {
549 fs.mkdirpSync('./' + TARGET_FOLDER + '/public/tmp');
550
551 fs.mkdirpSync('./' + TARGET_FOLDER + '/public/files');
552
553 _.each(app.config.fileGroups, function (fileGroup) {
554 fs.mkdirpSync('./' + TARGET_FOLDER + '/public/files/' + fileGroup);
555 });
556});
557
558gulp.task('minifyScripts', function () {
559
560 var gulps = [];
561
562 var targets = [];
563
564 var bundler = require('./src/app/tmpl/bundle.js')(app);
565 _.each(app.config.templates, function (tmpl) {
566
567 if (tmpl.scripts && _.isArray(tmpl.scripts)) {
568 var scriptBundle = bundler.getScriptBundle(tmpl.scripts);
569 _.each(scriptBundle.raw, function (r) {
570 if (r.items.length > 0 && targets.indexOf(r.target === -1)) {
571
572 var g = gulp.src(_.map(r.items, function (x, i) {
573 return './' + TARGET_FOLDER + '/public' + x
574 }))
575 .pipe(uglify({
576 preserveComments: false,
577 mangle: false,
578 compress: false,
579 wrap: false
580 }))
581 .pipe(concat('js-files.js'))
582 .pipe(rename(path.basename(r.target)))
583 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public' + path.dirname(r.target)));
584
585 gulps.push(g);
586 targets.push(r.target);
587 }
588 });
589 }
590
591 });
592
593 if (gulps.length > 0)
594 return eventStream.merge(gulps);
595});
596
597gulp.task('compressAngularTemplates', function () {
598
599 var templateFiles = _.map(app.config.templates, function (x) {
600 return '!./' + TARGET_FOLDER + '/public' + x;
601 })
602
603 return eventStream.merge([
604 gulp.src(_.union(['./' + TARGET_FOLDER + '/public/admin/tmpl/**/*.html'], templateFiles))
605 .pipe(htmlmin({
606 collapseBooleanAttributes: true,
607 collapseWhitespace: true,
608 removeAttributeQuotes: true,
609 removeComments: true,
610 removeEmptyAttributes: true,
611 removeRedundantAttributes: true,
612 removeScriptTypeAttributes: true,
613 removeStyleLinkTypeAttributes: true
614 }))
615 .pipe(ngTemplates({
616 module: 'jsnbt',
617 standalone: false,
618 path: function (path, base) {
619 return ('tmpl\\' + path.replace(base, '')).replace(/\\/gi, '//');
620 }
621 }))
622 .pipe(rename('tmpl.js'))
623 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public/admin')),
624
625 gulp.src(_.union(['./' + TARGET_FOLDER + '/public/tmpl/**/*.html'], templateFiles))
626 .pipe(htmlmin({
627 collapseBooleanAttributes: true,
628 collapseWhitespace: true,
629 removeAttributeQuotes: true,
630 removeComments: true,
631 removeEmptyAttributes: true,
632 removeRedundantAttributes: true,
633 removeScriptTypeAttributes: true,
634 removeStyleLinkTypeAttributes: true
635 }))
636 .pipe(ngTemplates({
637 module: 'jsnbt',
638 standalone: false,
639 path: function (path, base) {
640 return ('tmpl\\' + path.replace(base, '')).replace(/\\/gi, '//');
641 }
642 }))
643 .pipe(rename('tmpl.js'))
644 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public'))
645 ]);
646});
647
648function watch() {
649 gutil.log('Watch enabled. Listening for file changes...');
650
651 var processFile = function (event, prefix, destination) {
652 var sourcePath = event.path.substring(event.path.indexOf(prefix));
653 var targetPath = event.path.substring(event.path.indexOf(prefix) + prefix.length);
654 gutil.log('File ' + sourcePath + ' was ' + event.type);
655 if (event.type === 'changed') {
656 gulp.src(event.path)
657 .pipe(gulp.dest(destination + '/' + path.dirname(targetPath)))
658 .on('end', function () {
659 gutil.log('File updated on ' + path.join(destination + '/' + targetPath));
660 });
661 }
662 else if (event.type === 'deleted') {
663 del.sync(destination + '/' + targetPath);
664 gutil.log('File deleted from ' + path.join(destination + '/' + targetPath));
665 }
666 };
667
668 if (fs.existsSync(server.getPath('bower'))) {
669 var localPackages = fs.readdirSync(server.getPath('bower'));
670 _.each(localPackages, function (localPackage) {
671 if (fs.lstatSync(server.getPath('bower/' + localPackage)).isDirectory()) {
672
673 gulp.watch('./bower/' + localPackage + '/**', function (event) {
674 processFile(event, '\\bower\\' + localPackage + '\\', './bower_components/' + localPackage);
675 runSequence('deployBowerComponents', 'generateStyles');
676 });
677
678 }
679 });
680 }
681
682 if (fs.existsSync(server.getPath('npm'))) {
683 var localPackages = fs.readdirSync(server.getPath('npm'));
684 _.each(localPackages, function (localPackage) {
685 if (fs.lstatSync(server.getPath('npm/' + localPackage)).isDirectory()) {
686 gulp.watch('./npm/' + localPackage + '/**', function (event) {
687 processFile(event, '\\npm\\' + localPackage + '\\', './node_modules/' + localPackage);
688 });
689 }
690 });
691 }
692
693 _.each(moduleNames, function (moduleName, i) {
694
695 var module = require(server.getPath(modulePaths[i]));
696
697 var modulePath = getModuleFolderPath(modulePaths[i]);
698
699 gulp.watch(getFileCopyAdminPaths(module, modulePath), function (event) {
700 processFile(event, 'web\\admin\\', './' + TARGET_FOLDER + '/public/admin/');
701 });
702
703 gulp.watch(getFileCopyPublicPaths(module, modulePath), function (event) {
704 processFile(event, 'web\\public\\', './' + TARGET_FOLDER + '/public/');
705 });
706
707 gulp.watch(['./' + modulePath + '/app/clib/**', './' + modulePath + '/cfg/**'], function (event) {
708 runSequence('loadModules', 'generateJsnbtScript');
709 });
710
711
712 var templates = module.getConfig().templates || [];
713
714 _.each(templates, function (template) {
715 gulp.watch('./' + modulePath + '/web/' + (!_.str.startsWith(template.html, '/admin/') && !_.str.startsWith(template.html, 'admin/') ? 'public/' : '') + _.str.ltrim(template.html, '/'), function (event) {
716 gutil.log('File ' + event.path + ' was ' + event.type);
717 gulp.src('./' + modulePath + '/web/' + (!_.str.startsWith(template.html, '/admin/') && !_.str.startsWith(template.html, 'admin/') ? 'public/' : '') + _.str.ltrim(template.html, '/'))
718 .pipe(preprocess({ context: { NODE_ENV: appMode, DEBUG: false } }))
719 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public/' + _.str.ltrim(path.dirname(template.html), '/') + '/'))
720 .on('end', function () {
721 gutil.log('File updated on ' + path.join(TARGET_FOLDER + '/public/' + _.str.ltrim(template.html, '/')));
722 });
723 });
724 });
725
726 gulp.watch('./' + modulePath + '/web/public/err/*', function (event) {
727 gutil.log('File ' + event.path + ' was ' + event.type);
728 gulp.src(event.path)
729 .pipe(preprocess())
730 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public/err/'))
731 .on('end', function () {
732 gutil.log('File updated on ' + path.join(TARGET_FOLDER + '/public/err/' + path.basename(event.path)));
733 });
734 });
735
736 gulp.watch('./' + modulePath + '/web/admin/err/*', function (event) {
737 gutil.log('File ' + event.path + ' was ' + event.type);
738 gulp.src(event.path)
739 .pipe(preprocess())
740 .pipe(gulp.dest('./' + TARGET_FOLDER + '/public/admin/err/'))
741 .on('end', function () {
742 gutil.log('File updated on ' + path.join(TARGET_FOLDER + '/public/admin/err/' + path.basename(event.path)));
743 });
744 });
745
746 });
747
748 gulp.watch([
749 './' + TARGET_FOLDER + '/public/css/**',
750 './' + TARGET_FOLDER + '/public/admin/css/**'
751 ], ['generateStyles']);
752};
753
754gulp.task('dev', function (callback) {
755
756 runSequence(
757 'setCurrentDirectory',
758 'copyLocalBowerComponents',
759 'copyLocalNodeModules',
760 'loadModules',
761 'installBowerComponents',
762 'cleanTarget',
763 'setMode:dev',
764 'setModules',
765 'copyFiles',
766 'parseTemplates',
767 'generateJsnbtScript',
768 'deployBowerComponents',
769 'checkStructure',
770 'generateStyles',
771 callback
772 );
773
774});
775
776gulp.task('dev-update', function (callback) {
777
778 runSequence(
779 'setCurrentDirectory',
780 'copyLocalBowerComponents',
781 'copyLocalNodeModules',
782 'loadModules',
783 'installBowerComponents',
784 'cleanTarget',
785 'setMode:dev',
786 'setModules',
787 'copyFiles',
788 'parseTemplates',
789 'generateJsnbtScript',
790 'deployBowerComponents',
791 'checkStructure',
792 'generateStyles',
793 function () {
794 watch();
795 }
796 );
797
798});
799
800gulp.task('prod', function (callback) {
801
802 runSequence(
803 'setCurrentDirectory',
804 'copyLocalBowerComponents',
805 'copyLocalNodeModules',
806 'loadModules',
807 'installBowerComponents',
808 'cleanTarget',
809 'setMode:prod',
810 'setModules',
811 'copyFiles',
812 'parseTemplates',
813 'generateJsnbtScript',
814 'deployBowerComponents',
815 'checkStructure',
816 'generateStyles',
817 'minifyScripts',
818 'compressAngularTemplates',
819 callback
820 );
821
822});
823
824module.exports = gulp;
\No newline at end of file