-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·155 lines (128 loc) · 4.14 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
var gulp = require('gulp'),
gutil = require('gulp-util'),
clean = require('gulp-clean'),
uglify = require('gulp-uglify'),
ngmin = require('gulp-ngmin'),
watch = require('gulp-watch'),
concat = require('gulp-concat'),
ngHtml2Js = require("gulp-ng-html2js"),
inject = require("gulp-inject"),
refresh = require('gulp-livereload'),
replace = require('gulp-replace'),
lrserver = require('tiny-lr')(),
express = require('express'),
livereload = require('connect-livereload'),
pkg = require('./package.json'),
livereloadport = 35729,
serverport = 8080
ngAppBase = pkg.name;
//We only configure the server here and start it only when running the watch task
var server = express();
//Add livereload middleware before static-middleware
server.use(livereload({
port: livereloadport
}));
server.use(express.static(__dirname + '/build'));
var nitrous_server = express();
nitrous_server.use(express.static(__dirname + '/build'));
// =====================================
// File Bundles
// =====================================
var base = { base: './src/app/' };
var vendorJS = [
'./src/_vendor/angular/angular.min.js',
'./src/_vendor/angular-ui-router/release/angular-ui-router.min.js',
'./src/_vendor/theme/dependencies.js',
'./src/_vendor/theme/main.js',
];
var appJS = [
'./src/buid_head.js',
'./temp/**/**/*.tmpl.js',
'./src/app/app.js',
'./src/app/**/*-module.js',
'./src/app/**/*.js',
'./src/buid_foot.js',
'!./src/app/**/*.spec.js'
];
// =====================================
// Tasks
// =====================================
gulp.task('clean', function(){
gulp
.src(['./build/*', './temp/*'], {read:false})
.pipe(clean());
});
// uglify task
gulp.task('js', function() {
var vendorStream = gulp.src(vendorJS)
.pipe(concat('vendors.js'))
.pipe(gulp.dest('./build/app'));
// Concatenate AND minify app sources
var appStream = gulp.src(appJS)
.pipe(concat('app.js'))
.pipe(ngmin())
//.pipe(uglify())
.pipe(gulp.dest('./build/app'));
gulp.src('./src/index.html')
.pipe(inject(vendorStream, {starttag: '<!-- inject:vendor:{{ext}} -->', ignorePath: '/build'}))
.pipe(inject(appStream, {starttag: '<!-- inject:app:{{ext}} -->', ignorePath: '/build'}))
.pipe(gulp.dest('./build'))
.pipe(refresh(lrserver));
gulp.src('./src/layout_static.html').pipe(gulp.dest('./build'))
});
// templatify
gulp.task('templatify', function () {
gulp.src("./src/**/*.tmpl.html")
.pipe(ngHtml2Js({
moduleName: ngAppBase + '.templates',
prefix: "/",
rename: function (url) {
var last = url.split('/').pop();
return '/partials/' + last;
}
}))
.pipe(gulp.dest("./temp"));
});
gulp.task('move', function () {
gulp
.src(['./src/css/**/*.*'])
.pipe(gulp.dest('./build/css'));
gulp
.src(['./src/ionicons/**/*.*'])
.pipe(gulp.dest('./build/css/ionicons'));
});
gulp.task('serve', function() {
//Set up your static fileserver, which serves files in the build dir
server.listen(serverport);
console.log('serving app on: ' + serverport);
});
gulp.task('nitrous_serve', function() {
//Set up your static fileserver, which serves files in the build dir
nitrous_server.listen(serverport);
console.log('serving app on: ' + serverport);
});
gulp.task('livereload', function() {
//Set up your livereload server
lrserver.listen(livereloadport);
});
gulp.task('watch', function () {
gulp.watch([
'./src/partials/**/*.js',
'./src/**/*.html',
'./src/app/**/*.js'
], base, function () {
gulp.run('build');
});
});
gulp.task('rename', function(){
gulp.src([
'./src/**/*.js',
'!./src/_vendor/*.js',
'./src/**/*.html',
])
.pipe(replace('jobney.angular-starter', ngAppBase))
.pipe(gulp.dest('src/'));
});
gulp.task('default', ['build', 'watch', 'serve', 'livereload']);
gulp.task('nitrous', ['build', 'watch', 'nitrous_serve']);
gulp.task('build', ['move','templatify', 'js']);