-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
169 lines (149 loc) · 5.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
const 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 inject = require('gulp-inject');
var del = require('del');
var runSequence = require('run-sequence');
var args = require('yargs').argv;
var watch = require('gulp-watch');
var ngConstant = require('gulp-ng-constant');
var extend = require('gulp-extend');
var filter = require('gulp-filter');
var plumber = require('gulp-plumber');
var ngHtml2Js = require("gulp-ng-html2js")
var minifyHtml = require('gulp-minify-html');
var uglify = require("gulp-uglify");
var templateCache = require('gulp-angular-templatecache');
var paths = {
src: ['./src/*','./src/**/*'],
templates: ['./src/**/*.html'],
src_with_copy: ['./src/*','./src/**/*', '!./src/**/*.json', '!./src/**/*.scss', '!./src/**/scss/**/*'],
src_css: ['./src/css/**/*.css'],
src_test:['./test/**/*.js', './test/**/*.css'],
dist: './dist',
index: ['./index.html'],
sass: ['./src/scss/*.scss'],
script: ['./src/js/**/*.module.js', './src/js/**/*.js'],
config: ['./src/js/config/config.default.json'],
libs: [
'./src/lib/jquery/dist/jquery.js',
'./src/lib/ionic/js/ionic.bundle.js',
'./src/lib/ionic/css/ionic.css'
]
};
//gulp.task('default', developmentTask);
gulp.task('clean', function (cb) {
return del([paths.dist + '/**/*'], cb);
});
gulp.task('build-template', function(){
return gulp.src(paths.templates)
.pipe(minifyHtml({empty: true}))
.pipe(ngHtml2Js({
moduleName: "ion-images",
prefix: "src/"
}))
//.pipe(templateCache({
// standalone: true,
// module: 'ion-images',
// root: 'src/'
//}))
.pipe(concat("image-template.min.js"))
.pipe(gulp.dest(paths.dist + "/js"));
})
gulp.task('build-script', function(){
return gulp.src(paths.script.concat([paths.dist + '/js/image-template.min.js']))
.pipe(gulp.dest(paths.dist + '/js'))
.pipe(uglify())
.pipe(concat('ionic-images.all.min.js'))
.pipe(gulp.dest(paths.dist));
})
gulp.task('build-sass', function(){
runSequence('sass', function(){
gulp.src(paths.src_css)
.pipe(gulp.dest(paths.dist + "/css"))
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(concat('ionic-images.min.css'))
.pipe(gulp.dest(paths.dist))
});
})
gulp.task('build', function(){
runSequence('clean', 'build-template', 'build-script', 'build-sass');
})
gulp.task('config', function () {
//var model = args.model || "development";
gulp.src(paths.config)
.pipe(extend('config.json', true))
.pipe(ngConstant({
name: 'app.configs',
deps: [],
}))
.pipe(rename(function (path) {
path.basename = 'config';
path.extname = '.js';
}))
.pipe(gulp.dest('src/js/config'));
})
gulp.task('watch-config', function(){
watch(paths.config, function(){
gulp.start('config');
})
});
gulp.task('watch-sass', function(){
watch(paths.sass, function(){
gulp.start('sass');
});
});
gulp.task('watch-inject', function(){
var injectPath = paths.script.concat(paths.src_css).concat(paths.src_test);
gulp.src(injectPath, {base: './src'})
.pipe(watch(injectPath, {base: './src'}, function(file){
if(file.event === 'add' || file.event == 'unlink'){
gulp.start('inject')
}
}))
});
gulp.task('watch', ['watch-config', 'watch-sass', 'watch-inject']);
gulp.task('copy', function() {
gulp.src(paths.src_with_copy)
.pipe(gulp.dest(paths.dist));
});
gulp.task('inject', function() {
gulp.src(paths.index)
.pipe(inject(gulp.src(paths.libs,{read: false}),{relative: true, name:"inject:libs"}))
.pipe(inject(gulp.src(paths.script.concat(paths.src_css),{read: false}),{relative: true, name:"inject:app"}))
.pipe(inject(gulp.src(paths.src_test,{read: false}),{relative: true, name:"inject:test"}))
.pipe(gulp.dest('./'));
})
gulp.task('sass', function (done) {
gulp.src(paths.sass)
.pipe(sass())
.on('error', sass.logError)
.pipe(concat('ionic-images.css'))
.pipe(gulp.dest('./src/css/'))
.on('end', done);
});
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();
});