forked from mwasiluk/angular-surveys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
144 lines (115 loc) · 4.05 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
var gulp = require('gulp');
var del = require('del');
var merge = require('merge-stream');
var plugins = require('gulp-load-plugins')();
var Server = require('karma').Server;
var browserSync = require('browser-sync').create();
var argv = require('yargs').argv;
gulp.task('clean', function (cb) {
return del(['tmp', 'dist'], cb);
});
gulp.task('build-css', ['clean'], function () {
return gulp.src('./styles/*')
.pipe(plugins.plumber({ errorHandler: onError }))
.pipe(plugins.sass())
.pipe(plugins.minifyCss())
.pipe(plugins.rename({
extname: '.min.css'
}))
.pipe(gulp.dest('./dist'));
});
gulp.task('build-tmp', ['build-css'], function () {
var builderStream = buildTemp('src/builder/', 'mwFormBuilder');
var viewerStream = buildTemp('src/viewer/', 'mwFormViewer');
var utilsStream = buildTemp('src/utils/', 'mwFormUtils');
return merge(builderStream, viewerStream, utilsStream);
});
gulp.task('default', ['build-tmp'], function () {
var i18n = gulp.src('i18n/**/*.json').pipe(plugins.jsonminify()).pipe(gulp.dest('dist/i18n/'));
var builderStream = buildModuleStream('form-builder', 'mwFormBuilder');
var viewerStream = buildModuleStream('form-viewer', 'mwFormViewer');
var utilsStream = buildModuleStream('form-utils', 'mwFormUtils');
return merge(builderStream, viewerStream, utilsStream, i18n);
});
gulp.task('watch', function() {
return gulp.watch(['i18n/**/*.json','./src/**/*.html', './styles/*.*css', 'src/**/*.js'], ['default']);
});
function buildTemp(src, moduleName) {
var tmpDir = 'tmp/'+moduleName;
var copy = gulp.src(src + '**/*').pipe(gulp.dest(tmpDir));
return merge(copy);
}
function buildTemplates(src, moduleName, dest, filePrefix){
return gulp.src(src + '**/*.html')
.pipe(plugins.minifyHtml())
.pipe(plugins.angularTemplatecache({
module: moduleName,
filename: filePrefix+'-tpls.min.js'
}))
.pipe(plugins.uglify())
.pipe(gulp.dest(dest));
}
function buildModuleStream(destPrefix, moduleName) {
var tmpDir = 'tmp/'+moduleName;
var bootstrapTemplates = buildTemplates(tmpDir+'/templates/bootstrap/', moduleName, 'dist', destPrefix+'-bootstrap');
var materialTemplates = buildTemplates(tmpDir+'/templates/material/', moduleName, 'dist', destPrefix+'-material');
var module = gulp.src(tmpDir + '/**/*.js')
.pipe(plugins.plumber({ errorHandler: onError }))
.pipe(plugins.angularFilesort())
.pipe(plugins.ngAnnotate())
.pipe(plugins.concat(destPrefix+'.js'))
.pipe(gulp.dest('dist'));
var development = (argv.dev === undefined) ? false : true;
if(!development){
module.pipe(plugins.uglify())
.pipe(plugins.stripDebug())
.pipe(plugins.concat(destPrefix+'.min.js'))
.pipe(gulp.dest('dist'));
}
return merge(module, bootstrapTemplates, materialTemplates);
}
gulp.task('test', function (done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function() {
done();
}).start();
});
/**
* Serve
*/
// error function for plumber
var onError = function (err) {
console.log(err);
this.emit('end');
};
var browserSyncInit = function(baseDir){
browserSync.init({
server: {
baseDir: baseDir,
index: "demo.html",
routes: {
"/bower_components": "bower_components",
"/vendor": "vendor",
"/dist": "dist",
"/i18n": "i18n"
}
},
port: 8080,
open: 'local',
browser: "google chrome"
});
};
var gulpWatch = function(){
gulp.watch(['i18n/**/*.json', './src/**/*.html', './styles/*.*css', 'src/**/*.js'], ['default-watch']);
};
gulp.task('default-watch', ['default'], ()=>{ browserSync.reload() });
gulp.task('serve', ['default'], ()=>{
browserSyncInit("demo-material");
gulpWatch();
});
gulp.task('serve-bootstrap', ['default'], ()=>{
browserSyncInit("demo");
gulpWatch();
});