forked from technykim/nem-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·228 lines (204 loc) · 7.51 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
var $ = require('gulp-load-plugins')();
var argv = require('yargs').argv;
var browser = require('browser-sync');
var gulp = require('gulp');
var panini = require('panini');
var rimraf = require('rimraf');
var sequence = require('run-sequence');
var sherpa = require('style-sherpa');
var i18n = require('gulp-i18n-gspreadsheet');
var config = require('./config.json');
// Check for --production flag
var isProduction = !!(argv.production);
// var isProduction = true;
// Port to use for the development server.
var PORT = 8765;
// Browsers to target when prefixing CSS.
var COMPATIBILITY = ['last 2 versions', 'ie >= 9'];
// File paths to various assets are defined here.
var PATHS = {
assets: [
'src/assets/**/*',
'!src/assets/{!img,js,scss}/**/*'
],
sass: [
'bower_components/foundation-sites/scss',
'bower_components/motion-ui/src/',
'bower_components/font-awesome/scss'
],
javascript: [
'bower_components/jquery/dist/jquery.js',
'bower_components/what-input/what-input.js',
'bower_components/foundation-sites/js/foundation.core.js',
'bower_components/foundation-sites/js/foundation.util.*.js',
// Paths to individual JS components defined below
'bower_components/foundation-sites/js/foundation.abide.js',
'bower_components/foundation-sites/js/foundation.accordion.js',
'bower_components/foundation-sites/js/foundation.accordionMenu.js',
'bower_components/foundation-sites/js/foundation.drilldown.js',
'bower_components/foundation-sites/js/foundation.dropdown.js',
'bower_components/foundation-sites/js/foundation.dropdownMenu.js',
'bower_components/foundation-sites/js/foundation.equalizer.js',
'bower_components/foundation-sites/js/foundation.interchange.js',
// 'bower_components/foundation-sites/js/foundation.magellan.js',
'bower_components/foundation-sites/js/foundation.offcanvas.js',
'bower_components/foundation-sites/js/foundation.orbit.js',
'bower_components/foundation-sites/js/foundation.responsiveMenu.js',
'bower_components/foundation-sites/js/foundation.responsiveToggle.js',
'bower_components/foundation-sites/js/foundation.reveal.js',
'bower_components/foundation-sites/js/foundation.slider.js',
'bower_components/foundation-sites/js/foundation.sticky.js',
'bower_components/foundation-sites/js/foundation.tabs.js',
'bower_components/foundation-sites/js/foundation.toggler.js',
'bower_components/foundation-sites/js/foundation.tooltip.js',
// Path to non-foundation JS components
// 'bower_components/twitter-fetcher/js/twitterFetcher.js',
'bower_components/i18next/i18next.js',
// 'bower_components/smooth-scroll/dist/js/smooth-scroll.js',
// 'bower_components/jquery-sticky/jquery.sticky.js',
// 'bower_components/gumshoe/dist/js/gumshoe.js',
// 'bower_components/skrollr-stylesheets/src/skrollr.stylesheets.js',
// 'bower_components/skrollr/src/skrollr.js',
// 'bower_components/skrollr-menu/src/skrollr.menu.js',
'bower_components/svg-injector/svg-injector.js',
'bower_components/numeral/numeral.js',
'bower_components/slick-carousel/slick/slick.js',
'src/assets/js/!(app.js)**/*.js',
'src/assets/js/app.js'
]
};
// Delete the "dist" folder
// This happens every time a build starts
gulp.task('clean', function(done) {
rimraf('dist', done);
});
// Copy files out of the assets folder
// This task skips over the "img", "js", and "scss" folders, which are parsed separately
gulp.task('copy', function() {
gulp.src(PATHS.assets)
.pipe(gulp.dest('dist/assets'));
});
// Copy page templates into finished HTML files
gulp.task('pages', function() {
gulp.src('src/pages/**/*.{html,hbs,handlebars}')
.pipe(panini({
root: 'src/pages/',
layouts: 'src/layouts/',
partials: 'src/partials/',
data: 'src/data/',
helpers: 'src/helpers/'
}))
.pipe(gulp.dest('dist'));
});
gulp.task('pages:reset', function(cb) {
panini.refresh();
gulp.run('pages');
cb();
});
// Compile Sass into CSS
// In production, the CSS is compressed
gulp.task('sass', function() {
var uncss = $.if(isProduction, $.uncss({
html: ['src/**/*.html'],
ignore: [
new RegExp('^meta\..*'),
new RegExp('^\.is-.*')
]
}));
var cleancss = $.if(isProduction, $.cleanCss());
return gulp.src('src/assets/scss/app.scss')
.pipe($.sourcemaps.init())
.pipe($.sass({
includePaths: PATHS.sass
})
.on('error', $.sass.logError))
.pipe($.autoprefixer({
browsers: COMPATIBILITY
}))
// removed compressing css, it was causing bugs in navbar
// .pipe(uncss)
.pipe(cleancss)
.pipe($.if(!isProduction, $.sourcemaps.write()))
.pipe(gulp.dest('dist/assets/css'));
});
// Combine JavaScript into one file
// In production, the file is minified
gulp.task('javascript', function() {
var uglify = $.if(isProduction, $.uglify()
.on('error', function (e) {
console.log(e);
}));
return gulp.src(PATHS.javascript)
.pipe($.sourcemaps.init())
.pipe($.concat('app.js'))
.pipe(uglify)
.pipe($.if(!isProduction, $.sourcemaps.write()))
.pipe(gulp.dest('dist/assets/js'));
});
// Copy fontawesome font icons to dist folder
gulp.task('fonts', function() {
gulp.src('bower_components/font-awesome/fonts/**.*')
.pipe(gulp.dest('dist/assets/fonts/'));
});
// place needed pdf's at root level of dist
gulp.task('pdfs', function() {
gulp.src('src/assets/pdfs/**.*')
.pipe(gulp.dest('dist'));
});
gulp.task('nccCopy', ['clean'], function () {
return gulp.src(['src/ncc/**/*'], {
base: 'src'
}).pipe(gulp.dest('dist'));
});
// Copy images to the "dist" folder
// In production, the images are compressed
gulp.task('images', function() {
var imagemin = $.if(isProduction, $.imagemin({
progressive: true
}));
return gulp.src('src/assets/img/**/*')
.pipe(imagemin)
.pipe(gulp.dest('dist/assets/img'));
});
// Build the "dist" folder by running all of the above tasks
gulp.task('build', function(done) {
sequence('clean', ['translate', 'pages', 'sass', 'javascript', 'images', 'copy', 'fonts', 'pdfs', 'nccCopy'], done);
});
// google spreadsheet i18n.
// Pulls columns from gspreadsheet and puts each column in seperate json file.
gulp.task('translate', function() {
var document_key = '1dCO6KpecxgB577Fd0Gk0W-h9NuwTwPyDB7lysiNSZ34';
if(!isProduction && config.document_key !== undefined) {
document_key = (config.document_key);
}
gulp.src('src/*')
.pipe(i18n({
private_key_id: (config.private_key_id),
private_key: (config.private_key),
client_email: (config.client_email),
client_id: (config.client_id),
type: 'service_account',
document_key: document_key,
default_locale: 'en',
write_default_translations: 'true',
key_column: 'key',
ext: '.json',
output_dir: 'locales/'
}))
.pipe(gulp.dest('dist/assets/'));
});
// Start a server with LiveReload to preview the site in
gulp.task('server', ['build'], function() {
browser.init({
server: 'dist', port: PORT
});
});
// Build the site, run the server, and watch for file changes
gulp.task('default', ['build', 'server'], function() {
gulp.watch(PATHS.assets, ['copy', browser.reload]);
gulp.watch(['src/pages/**/*.html'], ['pages', browser.reload]);
gulp.watch(['src/{layouts,partials}/**/*.html'], ['pages:reset', browser.reload]);
gulp.watch(['src/assets/scss/**/*.scss'], ['sass', browser.reload]);
gulp.watch(['src/assets/js/**/*.js'], ['javascript', browser.reload]);
gulp.watch(['src/assets/img/**/*'], ['images', browser.reload]);
});