-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
155 lines (122 loc) · 2.87 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
//--------------//
// DEPENDENCIES //
//--------------//
var gulp = require('gulp');
var del = require('del');
var runSequence = require('run-sequence');
var compass = require('gulp-compass');
var rename = require('gulp-rename');
var minifyCSS = require('gulp-minify-css');
var serverFactory = require('spa-server');
var deploy = require('gulp-gh-pages');
var ncp = require('ncp').ncp;
//---------------//
// CONFIGURATION //
//---------------//
var cssDir = './css';
var scssDir = './scss';
var miniSuffix = '.min';
var deployTmpPath = './.deploy';
var demoServer;
//-------//
// TASKS //
//-------//
gulp.task('default', function(callback) {
runSequence('clean', 'build', callback);
});
gulp.task('clean', function(callback) {
del(cssDir + '/*').then(function () {
callback();
});
});
gulp.task('build', ['build:styles']);
gulp.task('build:styles', function() {
var compassConfig = {
css: cssDir,
sass: scssDir,
environment: 'development',
style: 'expanded',
comments: true
};
return gulp.src(scssDir + '/*.scss')
// Writing development version.
.pipe(compass(compassConfig))
.pipe(gulp.dest(cssDir))
// Writing minified version.
.pipe(rename({suffix: miniSuffix}))
.pipe(minifyCSS())
.pipe(gulp.dest(cssDir))
;
});
//===========//
// WEBSERVER //
//===========//
gulp.task('webserver.start', function (callback) {
demoServer = serverFactory.create({
path: './site',
port: 8888,
serveStaticConfig: {
index: 'index.html'
}
});
demoServer.start(callback);
});
gulp.task('webserver.stop', function (callback) {
demoServer.stop(callback);
});
//======//
// SITE //
//======//
gulp.task('site', ['webserver.start']);
gulp.task('site-deploy', function (done) {
runSequence(
'site-deploy-before',
'site-deploy-actual',
'site-deploy-after',
done
);
});
gulp.task('site-deploy-actual', function () {
console.log('Starting to deploy files...');
return gulp.src(deployTmpPath + '/**/*')
.pipe(deploy())
;
});
gulp.task('site-deploy-before', function (done) {
// Clearing temp directories and making a temp copy.
deployClearTemp(function () {
makeTempCopy(done);
});
/**
* Makes a temporary copy of the site directory with symlinks resolved.
*
* @param {function} callback
*/
function makeTempCopy (callback) {
ncp('./site', deployTmpPath, {
dereference: true
}, function (error) {
if (error) {
return console.error(error);
}
console.log('Temporary copy created!');
callback();
});
}
});
gulp.task('site-deploy-after', function (done) {
deployClearTemp(done);
});
/**
* Clears temp directory.
*
* @param {function} callback
*/
function deployClearTemp (callback) {
del(deployTmpPath, './.publish')
.then(function () {
console.log('Temporary directories removed!');
callback();
})
;
}