-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
140 lines (126 loc) · 3.94 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
/*
* Copyright (C) 2016 TopCoder Inc., All Rights Reserved.
*/
/**
* Represents the gulp file for this ionic application
*
* @author TCDEVELOPER
* @version 1.0
*/
'use strict';
var gulp = require('gulp');
gulp.modules = process.env.ANGULAR_MODULES || "'ionic','ngResource','ya.nouislider', 'ngCordova', 'ngCordovaOauth', 'ngTwitter'";
gulp.paths = {
src: 'src',
dist: 'www',
bower: 'www/lib'
};
var path = require('path');
var sort = require('gulp-sort');
var gulpNgConfig = require('gulp-ng-config');
var bower = require('bower');
var wiredep = require('wiredep').stream;
var sh = require('shelljs');
var gutil = require('gulp-util');
var sass = require('gulp-sass');
var $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'main-bower-files', 'del']
});
var paths = gulp.paths;
gulp.task('clean', function (done) {
$.del([paths.dist + '/'], 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();
});
gulp.task('sass', function(done) {
gulp.src('./scss/ionic.app.scss')
.pipe(sass())
.on('error', sass.logError)
.pipe(gulp.dest(paths.dist +'/css/'))
.on('end', done);
});
gulp.task('ng-config', function () {
gulp.src('config.json')
.pipe(
gulpNgConfig('app', {
wrap: true,
createModule: false,
environment: process.env.BUILD_ENV || 'dev'
}))
.pipe(gulp.dest(paths.dist+'/js'))
});
gulp.task('menu', function () {
var menuInjectFiles = gulp.src(paths.src + '/components/**/menu*.html').pipe(sort(
{
// sort asc with index number in filename
comparator: function(file1, file2) {
var index1 = Number(path.basename(file1.path,'.html').substring(5));
var index2 = Number(path.basename(file2.path,'.html').substring(5));
return index1-index2;
}
}
));
var menuInjectOptions = {
starttag: '<!-- inject:menu -->',
transform: function (filePath, file) {
return file.contents.toString('utf8')
}
};
return gulp.src(paths.src + '/templates/menu.html')
.pipe($.inject(menuInjectFiles, menuInjectOptions))
.pipe(gulp.dest(paths.dist + '/templates/'));
});
gulp.task('copy-files', function () {
gulp.src(paths.src + '/*.html')
.pipe(gulp.dest(paths.dist));
gulp.src(paths.src + '/js/*.js')
.pipe(gulp.dest(paths.dist+ '/js'));
gulp.src(paths.src + '/img/**')
.pipe(gulp.dest(paths.dist+ '/img'));
gulp.src(paths.src + '/css/*.css')
.pipe(gulp.dest(paths.dist+ '/css'));
gulp.src(paths.src + '/components/**')
.pipe(gulp.dest(paths.dist+ '/components'));
});
gulp.task('inject', ['sass', 'ng-config', 'menu','copy-files'], function () {
gulp.src(paths.dist+ '/js/app.js')
.pipe($.replace(/'<!--replace modules-->'/g, gulp.modules))
.pipe(gulp.dest(paths.dist+ '/js'));
var injectStyles = gulp.src([
paths.dist + '/{css,components}/**/*.css',
paths.dist + '/css/*.css'
], { read: false });
var injectScripts = gulp.src([
paths.dist + '/{js,components}/**/*.js'
]).pipe($.angularFilesort());
var injectOptions = {
ignorePath: [paths.dist],
addRootSlash: false
};
var wiredepOptions = {
directory: paths.bower,
exclude: [/angular\.js/]
};
return gulp.src(paths.dist + '/*.html')
.pipe($.inject(injectStyles, injectOptions))
.pipe($.inject(injectScripts, injectOptions))
.pipe(wiredep(wiredepOptions))
.pipe(gulp.dest(paths.dist));
});
gulp.task('default', ['inject']);