-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
128 lines (112 loc) · 3.38 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
/*
* Start Config Gulp
* Load Plugins
*/
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var watch = require('gulp-watch');
var rename = require('gulp-rename');
var minifyCSS = require('gulp-minify-css');
var cp = require('child_process');
var browserSync = require('browser-sync');
var mainBowerFiles = require('main-bower-files');
var loadjekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
var vendor = require('./gulp/vendor').vendor;
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
// Directories
var appURL = 'app'
var assetsURL = appURL + '/assets';
/**
* Gulp Tasks
*/
/**
* Build the Jekyll Site
*/
gulp.task('jekyll:build', function (done) {
browserSync.notify(messages.jekyllBuild);
return cp.spawn(loadjekyll, ['build'], {stdio: 'inherit'})
.on('close', done);
});
/**
* Rebuild Jekyll & do page reload
*/
gulp.task('jekyll:rebuild', ['jekyll:build'], function () {
browserSync.reload();
});
/**
* Wait for jekyll:build, then launch the Server
*/
gulp.task('browser-sync', ['sass', 'js', 'jekyll:build'], function() {
browserSync({
server: {
baseDir: 'dist'
}
});
});
/**
* Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds)
*/
gulp.task('sass', function () {
return gulp.src(assetsURL + '/scss/style.scss')
.pipe(sass({
includePaths: ['scss'],
errLogToConsole: true,
onError: browserSync.notify
}))
//.pipe(minifyCSS())
.pipe(gulp.dest(assetsURL + '/css'));
});
/**
* concatenate and minify JS files and save it to assets/js folder.
*/
gulp.task('js', function() {
gulp.src(vendor.js)
.pipe(concat('all.js'))
.pipe(gulp.dest(assetsURL + '/js'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest(assetsURL + '/js'))
});
/**
* Watch scss files for changes & recompile
* Watch html/md files, run jekyll & reload BrowserSync
*/
gulp.task('watch', function () {
gulp.watch(assetsURL + '/scss/**/*.scss', ['sass', 'jekyll:rebuild']);
gulp.watch([appURL + '/**/*.{html,markdown,md}', '!' + assetsURL + '/**/*'], ['jekyll:rebuild']);
gulp.watch(assetsURL + '/js/app.js', ['js', 'jekyll:rebuild']);
});
/**
* Default task, running just `gulp` will compile the sass,
* compile the jekyll site, launch BrowserSync & watch files.
*/
gulp.task('default', ['browser-sync', 'watch']);
/**
* Copy Main Files from bower_components to assets/vendor folder.
*/
gulp.task('vendor', function() {
return gulp.src(mainBowerFiles(), { base: 'bower_components' })
.pipe(gulp.dest(assetsURL + '/vendor'))
});
/**
* Copy Foundation Setting File from vendor to assets/scss/settings.
*/
gulp.task('copy:foundation', function() {
var fs = require('fs');
if (fs.existsSync(assetsURL + '/scss/settings/_foundation-settings.scss')) {
console.log('Foundation Settings File Exist!')
} else {
console.log('Copy Foundation Settings File to Settings Folder.');
gulp.src(assetsURL + '/vendor/foundation/scss/foundation/_settings.scss')
.pipe(rename('_foundation-settings.scss'))
.pipe(gulp.dest(assetsURL + '/scss/settings'));
}
});
/**
* Start Your New Project with this task (only once).
*/
gulp.task('start', ['vendor', 'copy:foundation', 'default']);