-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathbuild.js
199 lines (177 loc) · 7.8 KB
/
build.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// jshint ignore: start
// jscs:disable
'use strict';
var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');
var gutil = require('gulp-util');
var exec = require('child_process').exec;
var themeSelected = gutil.env.theme ? gutil.env.theme : 'volumio';
var variantSelected = gutil.env.variant ? gutil.env.variant : 'volumio';
var $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'main-bower-files', 'uglify-save-license', 'del']
});
gulp.task('partials', function () {
return gulp.src([
path.join(conf.paths.src, '/app/**/*.html'),
path.join(conf.paths.tmp, '/serve/app/**/*.html')
])
.pipe($.minifyHtml({
empty: true,
spare: true,
quotes: true
}))
.pipe($.angularTemplatecache('templateCacheHtml.js', {
module: 'volumio',
root: 'app'
}))
.pipe(gulp.dest(conf.paths.tmp + '/partials/'));
});
gulp.task('html', ['inject', 'partials'], function (cb) {
var partialsInjectFile = gulp.src(path.join(conf.paths.tmp, '/partials/templateCacheHtml.js'), { read: false });
var partialsInjectOptions = {
starttag: '<!-- inject:partials -->',
ignorePath: path.join(conf.paths.tmp, '/partials'),
addRootSlash: false
};
var htmlFilter = $.filter('*.html');
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');
var assets;
return gulp.src(path.join(conf.paths.tmp, '/serve/*.html'))
.pipe($.inject(partialsInjectFile, partialsInjectOptions))
.pipe(assets = $.useref.assets())
.pipe($.rev())
.pipe(jsFilter)
.pipe($.ngAnnotate())
.pipe($.uglify({ preserveComments: $.uglifySaveLicense })).on('error', conf.errorHandler('Uglify'))
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.replace('../../bower_components/bootstrap-sass-official/assets/fonts/bootstrap/', '../fonts/'))
.pipe($.replace('../../bower_components/components-font-awesome/fonts', '../fonts/'))
.pipe($.csso())
.pipe(cssFilter.restore())
.pipe(assets.restore())
.pipe($.useref())
.pipe($.revReplace())
.pipe(htmlFilter)
.pipe($.minifyHtml({
empty: true,
spare: true,
quotes: true,
conditionals: true
}))
.pipe(htmlFilter.restore())
.pipe(gulp.dest(path.join(conf.paths.dist, '/')))
.pipe($.size({ title: path.join(conf.paths.dist, '/'), showFiles: true }));
cb(err);
});
// Only applies for fonts from bower dependencies
// Custom fonts are handled by the "other" task
gulp.task('fonts', function () {
var paths = $.mainBowerFiles()
paths.push('bower_components/bootstrap-sass-official/**');
return gulp.src(paths)
.pipe($.filter('**/*.{eot,svg,ttf,woff,woff2}'))
.pipe($.flatten())
.pipe(gulp.dest(path.join(conf.paths.dist, '/fonts/')));
});
gulp.task('fontawesome', function() {
return gulp.src('bower_components/components-font-awesome/fonts/*.*')
.pipe(gulp.dest(path.join(conf.paths.dist, '/fonts/')));
});
gulp.task('other', function () {
var fileFilter = $.filter(function (file) {
return file.stat.isFile();
});
return gulp.src([
path.join(conf.paths.src, '/**/*'),
path.join('!' + conf.paths.src, '/app/themes/**/*'),
path.join('!' + conf.paths.src, '/**/*.{html,css,js,scss}')
])
.pipe(fileFilter)
.pipe(gulp.dest(path.join(conf.paths.dist, '/')));
});
gulp.task('theme', function () {
var fileFilter = $.filter(function (file) {
return file.stat.isFile();
});
return gulp.src([
path.join(conf.paths.src, '/app/themes/' + themeSelected + '/assets/**/*'),
path.join('!' + conf.paths.src, '/app/themes/' + themeSelected + '/assets/variants/!(' + variantSelected + ')/**/*'),
// path.join(conf.paths.src, '/app/themes/' + themeSelected + '/assets/variants/'+variantSelected+'/**/*'),
// path.join(conf.paths.src, '/app/themes/' + themeSelected + '/assets/variants/' + variantSelected + '/**/*')
// path.join('!' + conf.paths.src, '/**/*.{html,css,js,scss}')
])
.pipe(fileFilter)
.pipe(gulp.dest(path.join(conf.paths.dist, '/app/themes/' + themeSelected + '/assets')));
});
//Set static page title to remove FOUC
gulp.task('replace-page-title', ['html'], function () {
var fs = require('fs');
var themeSettings =
fs.readFileSync(`${conf.paths.src}/app/themes/${themeSelected}/assets/variants/${variantSelected}/${variantSelected}-settings.json`, 'utf8');
themeSettings = JSON.parse(themeSettings);
var pageTitle = themeSettings.pageTitle || 'Audiophile music player';
var index = fs.readFileSync(`dist/index.html`, 'utf8');
index = index.replace('<title></title>', `<title>${pageTitle}</title>`);
index = index.replace(/@APP_NAME/g, themeSettings.app || '');
index = index.replace(/@BAR_COLOR/g, themeSettings.addressBarColor || '');
fs.writeFileSync('dist/index.html', index);
});
//Set static page title to remove FOUC
gulp.task('meta-cards', ['html'], function () {
var fs = require('fs');
var metaCardsContent = '';
if (variantSelected === 'volumio') {
var websiteUrl = 'https://myvolumio.org';
if (gutil.env.env === 'development') {
websiteUrl = 'https://myvolumio-dev.firebaseapp.com';
}
var tagline = 'The audiophile music player designed and fine-tuned for high quality music playback';
var title = 'Volumio - The Audiophile Music Player';
var metaImageUrl = websiteUrl + '/app/assets-common/volumio-meta.jpg';
metaCardsContent = '<meta property="og:type" content="website">';
metaCardsContent += '<meta property="og:url" content="'+ websiteUrl +'">';
metaCardsContent += '<meta property="og:title" content="' + title +'">';
metaCardsContent += '<meta property="og:image" content="' + metaImageUrl + '">';
metaCardsContent += '<meta property="og:description" content="' + tagline +'">';
metaCardsContent += '<meta property="og:site_name" content="Volumio">';
metaCardsContent += '<meta property="og:locale" content="en_US">';
metaCardsContent += '<meta property="og:image:width" content="1200">';
metaCardsContent += '<meta property="og:image:height" content="630">';
metaCardsContent += '<meta name="twitter:card" content="summary">';
metaCardsContent += '<meta name="twitter:site" content="@volumio">';
metaCardsContent += '<meta name="twitter:url" content="'+ websiteUrl +'">';
metaCardsContent += '<meta name="twitter:title" content="' + title +'">';
metaCardsContent += '<meta name="twitter:description" content="' + tagline +'">';
metaCardsContent += '<meta name="twitter:image" content="' + metaImageUrl + '">';
}
var index = fs.readFileSync(`dist/index.html`, 'utf8');
index = index.replace('<meta-cards></meta-cards>', metaCardsContent);
fs.writeFileSync('dist/index.html', index);
});
gulp.task('static-pages', ['credits'], function () {
var fileFilter = $.filter(function (file) {
return file.stat.isFile();
});
return gulp.src([
path.join(conf.paths.src, '/app/themes/' + themeSelected + '/assets/static-pages/*')
])
// .pipe(fileFilter)
.pipe(gulp.dest(path.join(conf.paths.dist, '/app/themes/' + themeSelected + '/assets/static-pages')));
});
gulp.task('clean', function (done) {
$.del([path.join(conf.paths.dist, '/'), path.join(conf.paths.tmp, '/'), path.join(conf.paths.src, '/app/themes/' + themeSelected + '/assets/variants/' + variantSelected + '/dist')], done);
});
gulp.task('credits', function (cb) {
exec('node src/app/themes/' + themeSelected + '/scripts/credits.js ' + themeSelected + ' ' + variantSelected, function (err, stdout, stderr) {
cb(err);
});
})
gulp.task('tos', function (cb) {
exec('curl https://volumio.github.io/volumio-tos/ --output ' + path.join('src','app','components','myvolumio','templates','terms-and-conditions.html'), function (err, stdout, stderr) {
cb(err);
});
})
gulp.task('build-app', ['credits', 'fonts', 'fontawesome', 'other', 'static-pages', 'theme', 'replace-page-title', 'meta-cards', 'tos']);