-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
176 lines (146 loc) · 4.26 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
var gulp = require('gulp');
var gutil = require('gulp-util');
var bower = require('bower');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sh = require('shelljs');
var del = require('del');
var sourcemaps = require('gulp-sourcemaps');
var babel = require('gulp-babel');
var watch = require('gulp-watch');
var paths = {
destBase: 'www/',
sassWatch: ['src/**/*.scss'],
sass: ['src/ionic.app.scss'],
images: ['src/img/**/*'],
lib: ['src/lib/**/*', 'bower_components/**/*'],
templates: ['src/**/*.html'],
scripts: ['src/**/*.js', '!src/**/*.spec.js', '!src/lib/**/*'],
e2e: ["./src/**/*.e2e.spec.js", "!./src/**/*.cordova.e2e.spec.js"],
e2eCordova: ["./src/**/*.cordova.e2e.spec.js"]
};
// Build
gulp.task('default', ['build']);
gulp.task('build', ['images', 'sass', 'lib', 'templates', 'scripts'])
gulp.task('clean', function (done) {
del(['www/**/*'], done);
});
gulp.task('rebuild', ['clean'], function (done) {
gulp.start('build');
});
gulp.task('sass', function (done) {
gulp.src(paths.sass)
.pipe(sass({
errLogToConsole: true
}))
.pipe(gulp.dest(paths.destBase))
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(rename({extname: '.min.css'}))
.pipe(gulp.dest(paths.destBase))
.on('end', done);
});
gulp.task('images', function (done) {
gulp.src(paths.images)
.pipe(gulp.dest(paths.destBase + 'img/'))
.on('end', done)
});
gulp.task('lib', function (done) {
gulp.src(paths.lib)
.pipe(gulp.dest(paths.destBase + 'lib/'))
.on('end', done)
});
gulp.task('templates', function (done) {
gulp.src(paths.templates)
.pipe(gulp.dest(paths.destBase))
.on('end', done)
});
gulp.task('scripts', function (done) {
gulp.src(paths.scripts)
.pipe(sourcemaps.init())
.pipe(babel())
.on('error', function (err) {
console.log('[scripts] Error: ' + err.message);
})
.pipe(concat('all.js'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.destBase))
.on('end', done);
});
// Watch
gulp.task('watch', function () {
watch(paths.templates, function () {
gulp.start('templates')
});
watch(paths.scripts, function () {
gulp.start('scripts')
});
watch(paths.images, function () {
gulp.start('images')
});
watch(paths.sassWatch, function () {
gulp.start('sass')
});
});
// Unit tests
var _ = require('lodash');
var karma = require('karma').server;
var karmaConf = require('./karma.conf.js');
// Run test once and exit
gulp.task('test', function (done) {
karma.start(_.assign({}, karmaConf, {singleRun: true}), done);
});
// Watch for file changes and re-run tests on each change
gulp.task('tdd', function (done) {
karma.start(karmaConf, done);
});
// Ionic predefined
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();
});
// E2E tests
var webdriver_standalone = require("gulp-protractor").webdriver_standalone;
var protractor = require("gulp-protractor").protractor;
gulp.task('webdriver-standalone', webdriver_standalone);
gulp.task('e2e', function () {
gulp.src(paths.e2e)
.pipe(protractor({
configFile: "protractor/protractor.conf.js"
}))
.on('error', function(e) { throw e })
});
gulp.task('e2e-cordova', function () {
gulp.src(paths.e2eCordova)
.pipe(protractor({
configFile: "protractor/protractor-cordova.conf.js"
}))
.on('error', function(e) { throw e })
});
// Environment setup
var ngConstant = require('gulp-ng-constant'),
yargs = require('yargs');
gulp.task('config', function () {
var args = yargs.argv;
gulp.src('env/' + args.env + '.json')
.pipe(ngConstant())
.pipe(rename('config.js'))
.pipe(gulp.dest('src'));
});