-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
136 lines (118 loc) · 3.91 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
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var gulpif = require('gulp-if');
var browserify = require('browserify');
var watchify = require('watchify');
var tsify = require('tsify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var rimraf = require('rimraf');
var templateCache = require('gulp-angular-templatecache');
var lcbweb = {
app: require('./bower.json').appPath || 'app',
dist: 'dist'
};
lcbweb.dist = lcbweb.app + '/' + lcbweb.dist;
var paths = {
scripts: [ lcbweb.app + '/**/*.ts' ],
styles: [ lcbweb.app + '/**/*.scss', '!' + lcbweb.app + '/bower_components/**/*.scss', '!' + lcbweb.app + '/styles/bootstrap.scss', '!' + lcbweb.app + '/styles/font-awesome.scss' ],
bootstrap: [ lcbweb.app + '/styles/bootstrap.scss' ],
fa: [ lcbweb.app + '/styles/font-awesome.scss' ],
templates: [ lcbweb.app + '/features/**/*.html', lcbweb.app + '/components/**/*.html' ],
index_pages: [ lcbweb.app + '/*.html' ],
test: [ 'test/spec/**/*.js' ],
testRequire: [
lcbweb.app + '/bower_components/angular/angular.js',
lcbweb.app + '/bower_components/angular-mocks/angular-mocks.js',
lcbweb.app + '/bower_components/angular-resource/angular-resource.js',
lcbweb.app + '/bower_components/angular-cookies/angular-cookies.js',
lcbweb.app + '/bower_components/angular-sanitize/angular-sanitize.js',
lcbweb.app + '/bower_components/angular-route/angular-route.js',
'test/mock/**/*.js',
'test/spec/**/*.js'
],
karma: 'karma.conf.js'
};
////////////////////////
//Reusable pipelines //
////////////////////////
///////////
//Tasks //
///////////
var _watch = false;
gulp.task('websitify', function() {
return _browserify('app/index.ts', 'website.js');
});
var _browserify = function(src, dest) {
var b = browserify({
entries: src,
debug: true
});
if (_watch) {
b = watchify(b);
_watch = false;
}
return b
.plugin('tsify')
.bundle()
.on('error', function (err) {
console.log(err.toString());
this.emit("end");
})
.pipe(source(dest))
.pipe(buffer())
// .pipe(plugins.uglify({ mangle: false }))
.pipe(gulp.dest(lcbweb.dist));
};
gulp.task('usemin', function() {
return gulp.src(paths.index_pages)
.pipe(plugins.useref())
.pipe(gulpif('*.js', plugins.uglify()))
.pipe(gulp.dest(lcbweb.app));
});
gulp.task('styles', function() {
gulp.src(paths.bootstrap)
.pipe(plugins.plumber())
.pipe(plugins.sass().on('error', plugins.sass.logError))
.pipe(plugins.minifyCss())
.pipe(gulp.dest(lcbweb.dist));
gulp.src(paths.fa)
.pipe(plugins.plumber())
.pipe(plugins.sass().on('error', plugins.sass.logError))
.pipe(plugins.minifyCss())
.pipe(gulp.dest(lcbweb.dist))
return gulp.src(paths.styles)
.pipe(plugins.plumber())
.pipe(plugins.concat('all.scss')) // combine all scss files so can use _media _mixins and _variables together
.pipe(plugins.sass().on('error', plugins.sass.logError))
.pipe(plugins.concat('all.css'))
.pipe(plugins.autoprefixer({ browsers: ['last 2 versions'] }))
.pipe(plugins.minifyCss())
.pipe(gulp.dest(lcbweb.dist));
});
gulp.task('templates', function() {
return gulp.src(paths.templates)
.pipe(templateCache({ module: 'lcbapp', transformUrl: function(url) {
if (url.match(/^directive/)) {
return 'components/' + url;
}
return 'features/' + url;
}}))
.pipe(gulp.dest(lcbweb.dist));
});
gulp.task('_watch', function () {
_watch = true;
gulp.watch(paths.scripts, [ 'websitify' ]);
gulp.watch(paths.styles, [ 'styles' ]);
gulp.watch(paths.bootstrap, [ 'styles' ]);
gulp.watch(paths.templates, [ 'templates' ]);
});
///////////
//Build //
///////////
gulp.task('clean', function (cb) {
rimraf('app/dist', cb);
});
gulp.task('build', [ 'websitify', 'styles', 'templates' ]);
gulp.task('default', [ 'build', 'usemin' ]);
gulp.task('watch', [ 'build', '_watch' ]);