forked from fossasia/open-event-wsgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
147 lines (130 loc) · 3.95 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
var gulp = require('gulp'),
connect = require('gulp-connect'),
clean = require('gulp-clean'),
inject = require('gulp-inject'),
uglify = require('gulp-uglify'),
minify = require('gulp-minify-css'),
flatten = require('gulp-flatten');
var bases = {
dev: {
root: './',
app: './app',
libs: './app/libs',
assets: './assets',
testapi: './testapi'
},
dist: {
root: 'dist/',
app: 'dist/app/',
libs: 'dist/libs/',
assets: 'dist/assets',
testapi: 'dist/testapi'
}
};
var srcPaths = {
index: [
'./index.html',
'./app.js',
'./main.css',
'./config.js'
],
libs: [
'./bower_components/angular/angular.js',
'./bower_components/leaflet/leaflet.*',
'./bower_components/**/angular-animate.js',
'./bower_components/**/angular-aria.js',
'./bower_components/**/angular-leaflet-directive.js',
'./bower_components/**/angular-material.js',
'./bower_components/**/angular-material.css',
'./bower_components/**/angular-ui-router.js',
'./bower_components/**/ngStorage.js',
],
assets: ['./assets/**/*'],
components: ['./app/**/*'],
testapi: ['./testapi/**/*']
};
var distPaths = {
css: [
bases.dist.root + 'assets/**/*.css',
bases.dist.root + 'libs/**/*.css',
bases.dist.root + 'main.css'
],
js: [
bases.dist.root + 'assets/**/*.js',
bases.dist.root + 'libs/angular.*js',
bases.dist.root + 'libs/**/*.js',
bases.dist.root + 'app.js',
bases.dist.root + 'app/components/**/*.js'
]
};
function distCopy () {
gulp.src(srcPaths.index)
.pipe(gulp.dest(bases.dist.root));
gulp.src(srcPaths.libs)
.pipe(flatten())
.pipe(gulp.dest(bases.dist.libs));
gulp.src(srcPaths.assets)
.pipe(gulp.dest(bases.dist.assets));
gulp.src(srcPaths.components)
.pipe(gulp.dest(bases.dist.app));
gulp.src(srcPaths.testapi)
.pipe(gulp.dest(bases.dist.testapi));
}
function injectImports ($envType) {
if ($envType === 'dist') {
var distIndex = gulp.src(bases.dist.root + 'index.html');
var distIncludes =
gulp.src(distPaths.css.concat(distPaths.js), {read:false});
// Flush the inject blocks so the real include can work
distIndex.pipe(inject(gulp.src('')))
.pipe(gulp.dest(bases.dist.root));
// Include really now
distIndex.pipe(inject(distIncludes, {
addRootSlash: false,
ignorePath: bases.dist.root
}))
.pipe(gulp.dest(bases.dist.root));
} else {
var devIndex = gulp.src('./index.html');
// It's not necessary to read the files (will speed up things),
// we're only after their paths:
var devIncludes = gulp.src(
srcPaths.assets.concat(
srcPaths.libs).concat(
srcPaths.index).concat(
srcPaths.components), {read: false});
devIndex.pipe(inject(devIncludes, {
addRootSlash: false,
ignorePath: '/'
})).pipe(gulp.dest('./'));
}
}
function distMinify () {
gulp.src(distPaths.css, {cwd: './**'})
.pipe(minify({compatibility: 'ie8'}))
.pipe(gulp.dest('./'));
gulp.src(distPaths.js, {cwd: './**'})
.pipe(uglify())
.pipe(gulp.dest('./'));
}
gulp.task('webserver', function() {
injectImports('dev');
setTimeout(function(){}, 2000);
connect.server({
livereload: true
});
});
gulp.task('clean', function() {
return gulp.src(bases.dist.root)
.pipe(clean());
});
gulp.task('dist', function() {
distCopy();
setTimeout(function(){ injectImports('dist'); }, 2000);
});
gulp.task('dist-min', function() {
distCopy();
setTimeout(function(){ injectImports('dist'); }, 2000);
setTimeout(function(){ distMinify(); }, 2000);
});
gulp.task('default', ['webserver']);