-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
171 lines (150 loc) · 3.97 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
'use strict';
var fs = require('fs');
var exec = require('child_process').exec;
var gulp = require('gulp');
var merge = require('merge-stream');
var minify = require('gulp-minify');
var htmlmin = require('gulp-htmlmin');
var minifyCSS = require('gulp-minify-css');
var flatten = require('gulp-flatten');
var plugins = require('gulp-load-plugins')({
lazy: false
});
var _ = require('lodash');
var connect = require('gulp-connect');
var replace = require('gulp-replace');
var version = require('./package.json').version;
var tokenImages = fs.readdirSync('./src/components/app/img/tokens').map(function(file) {
return file.replace('.svg', '');
});
var config = require('./config-dev.json');
if (process.argv[2] === 'deploy-prod') {
config = require('./config-prod.json');
}
// Remove files and folders
gulp.task('clean', function() {
return gulp.src([
'./dist'
], {
read: false
})
.pipe(plugins.rimraf());
});
// Builds the templates
gulp.task('templates', function() {
return gulp.src([
'!./src/index.html',
'./src/components/**/*.html'
])
.pipe(plugins.angularTemplatecache('templates.js', {
standalone: true
}))
.pipe(replace('{~version~}', version))
.pipe(replace('{~etherscan_url~}', config.etherscan_url))
.pipe(gulp.dest('./dist'));
});
// Copy the static files
gulp.task('copy', function() {
var images = gulp.src([
'./src/**/*.{svg,png,jpg,gif}'
])
.pipe(flatten())
.pipe(gulp.dest('./dist/img'));
var fonts = gulp.src([
'./src/**/*.{otf,ttf}'
])
.pipe(flatten())
.pipe(gulp.dest('./dist/font'));
var i18n = gulp.src([
'./src/i18n/*.json'
])
.pipe(gulp.dest('./dist/i18n'));
var favicon = gulp.src('./src/favicon.ico')
.pipe(gulp.dest('./dist'));
return merge(images, fonts, i18n, favicon);
});
// Replaces the usemin blocks by concatenation files
gulp.task('usemin', ['templates'], function() {
return gulp.src('./src/index.html')
.pipe(plugins.usemin())
.pipe(replace('{~tokens~}', '["' + tokenImages.join('","') + '"]'))
.pipe(replace('{~eth_dictionary~}', JSON.stringify(require('./eth_dictionary.json'))))
.pipe(replace('{~config~}', JSON.stringify(_.omit(config, ['deploy_cmd']))))
.pipe(gulp.dest('./dist'));
});
// minify/uglify js, html and css files
gulp.task('uglify', ['usemin'], function() {
var js = gulp.src([
//'./dist/libs.js',
'./dist/app.js'
])
.pipe(minify({
ext: {
src: '-debug.js',
min: '.js'
},
ignoreFiles: ['.min.js']
}))
.pipe(gulp.dest('./dist'));
var html = gulp.src('./dist/index.html')
.pipe(htmlmin({
removeComments: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true
}))
.pipe(gulp.dest('./dist'));
var css = gulp.src([
'./dist/libs.css',
'./dist/app.css'
])
.pipe(minifyCSS())
.pipe(gulp.dest('./dist'));
return merge(js, html, css);
});
// Get a clean dist folder
gulp.task('build', ['usemin', 'copy'], function() {
return gulp.src([
'./dist/app-debug.js',
'./dist/templates.js'
], {
read: false
})
.pipe(plugins.rimraf());
});
// Watch for changes in order to re-run the build
gulp.task('watch', function() {
gulp.watch(['./src/**/*'], ['build']);
});
// Serve the built project in a web server
gulp.task('connect', function() {
connect.server({
root: 'dist',
port: 14613,
https: true,
fallback: 'dist/index.html',
livereload: false
});
});
gulp.task('serve', [
'build',
'connect',
'watch'
]);
gulp.task('default', ['serve'], function() {
console.log('Go to https://localhost:14613 to view your app !');
});
gulp.task('deploy-dev', ['build'], function(cb) {
exec(config.deploy_cmd, function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('deploy-prod', ['build', 'uglify'], function(cb) {
exec(config.deploy_cmd, function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});