-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
167 lines (148 loc) · 4.55 KB
/
gulpfile.js
File metadata and controls
167 lines (148 loc) · 4.55 KB
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
var gulp = require('gulp');
var serve = require('gulp-serve');
var gutil = require('gulp-util');
var bower = require('bower');
var concat = require('gulp-concat');
var clean = require('gulp-clean');
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var ngAnnotate = require('gulp-ng-annotate');
var uglify = require("gulp-uglify");
var imagemin = require('gulp-imagemin');
var htmlreplace = require('gulp-html-replace');
var templateCache = require('gulp-angular-templatecache');
var sh = require('shelljs');
var paths = {
sass: ['./scss/**/*.scss'],
scripts: ['./src/js/**/*.js', '!./src/js/app.bundle.min.js'], // exclude the file we write too
images: ['./src/img/**/*'],
templates: ['./src/templates/**/*.html'],
css: ['./src/css/**/*.min.css'],
html: ['./src/index.html'],
extras: [],
ionicbundle: ['./src/lib/ionic/js/ionic.bundle.min.js'],
ionicfonts: ['./src/lib/ionic/fonts/*'],
lib: ['./src/lib/angular-resource/angular-resource.min.js', './src/lib/angular-underscore-module/angular-underscore-module.js', './src/lib/underscore/underscore-min.js', './src/lib/parse-1.2.18.min.js', './src/lib/moment.min.js', './src/lib/bindonce.min.js'],
dist: ['./www/']
};
var files = {
jsbundle: 'app.bundle.min.js',
appcss: 'ionic.app.css'
};
gulp.task('default', ['sass']);
gulp.task('build', ['sass', 'scripts', 'styles', 'imagemin', 'index', 'copy']);
gulp.task('serve', serve({
root: 'src',
port: 8100,
livereload: true
}));
gulp.task('clean', function() {
return gulp.src(paths.dist, {
read: false
})
.pipe(clean());
});
// Prepare Index.html for dist - ie. using min files
gulp.task('index', ['clean'], function() {
gulp.src(paths.html)
.pipe(htmlreplace({
'css': 'css/ionic.app.min.css',
'js': 'js/' + files.jsbundle
}))
.pipe(gulp.dest(paths.dist + '.'));
});
gulp.task('sass', function(done) {
gulp.src('./scss/ionic.app.scss')
.pipe(sass())
.pipe(gulp.dest('./src/css/'))
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(rename({
extname: '.min.css'
}))
.pipe(gulp.dest('./src/css/'))
.on('end', done);
});
// scripts - clean dist dir then annotate, minify, concat
gulp.task('scripts', ['clean', 'templateCache'], function() {
gulp.src(paths.scripts)
//.pipe(jshint())
//.pipe(jshint.reporter('default'))
.pipe(ngAnnotate({
remove: true,
add: true,
single_quotes: true
}))
.pipe(uglify())
.pipe(concat(files.jsbundle))
.pipe(gulp.dest(paths.dist + 'js'));
});
// concat all html templates and load into templateCache
gulp.task('templateCache', ['clean'], function() {
return gulp.src(paths.templates)
.pipe(templateCache({
'filename': 'templates.js',
'root': 'templates/',
'module': 'bluemobile'
}))
.pipe(gulp.dest('./src/js'));
});
// Copy all other files to dist directly
gulp.task('copy', ['clean'], function() {
// Copy ionic bundle file
gulp.src(paths.ionicbundle)
.pipe(gulp.dest(paths.dist + 'lib/ionic/js/.'));
// Copy ionic fonts
gulp.src(paths.ionicfonts)
.pipe(gulp.dest(paths.dist + 'lib/ionic/fonts'));
// Copy lib scripts
gulp.src(paths.lib)
.pipe(gulp.dest(paths.dist + 'lib'));
// Copy extra files
gulp.src(paths.extras)
.pipe(gulp.dest(paths.dist + '.'));
});
// styles - min app css then copy min css to dist
gulp.task('minappcss', function() {
return gulp.src('./src/css/' + files.appcss)
.pipe(minifyCss())
.pipe(rename({
extname: '.min.css'
}))
.pipe(gulp.dest('./src/css/'));
});
// styles - min app css then copy min css to dist
gulp.task('styles', ['clean', 'minappcss'], function() {
gulp.src(paths.css)
.pipe(gulp.dest(paths.dist + 'css'));
});
// Imagemin images and ouput them in dist
gulp.task('imagemin', ['clean'], function() {
gulp.src(paths.images)
.pipe(imagemin())
.pipe(gulp.dest(paths.dist + 'img'));
});
gulp.task('watch', function() {
gulp.watch([paths.sass], ['build']);
});
gulp.task('install', ['git-check'], function() {
return bower.commands.install()
.on('log', function(data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
});
gulp.task('git-check', function(done) {
if (!sh.which('git')) {
console.log(
' ' + gutil.colors.red('Git is not installed.'),
'\n Git, the version control system, is required to download Ionic.',
'\n Download git here:', gutil.colors.cyan('http://git-scm.com/downloads') + '.',
'\n Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again.'
);
process.exit(1);
}
done();
});