-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
160 lines (126 loc) · 4.41 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
//gulp automation (for documenatation generation)
var gulp = require('gulp');
var swig = require('gulp-swig');
var watchify = require('watchify');
var browserSync = require('browser-sync');
var browserify = require('browserify');
var sass = require('gulp-ruby-sass');
var vss = require('vinyl-source-stream');
var autoprefixer = require('gulp-autoprefixer');
var deployGh = require('gulp-gh-pages');
// pass along gulp reference to have tasks imported
require('gulp-release-tasks')(gulp);
//html generation from swig templates
var swigopts = {
defaults: {
cache: false
}
};
var port = 4276;
//conveniences
var examplesPath = './examples'; //the lab is were we code
var distPath = './dist'; //the dist is the processed results
// gulp.task('gen-examples', function () {
// gulp.src('./examples/index.swig')
// .pipe(swig(swigopts))
// .pipe(gulp.dest( './dist/' ));
//
// });
// watch the js with watchify and if it changes rebuild, refresh browser
// browserify bundle js (and watch for future changes to trigger it again)
gulp.task('watchify', function(){
//mostly similary to the watchify task right above with one addition
var bundleShare = function(b) {
return b.bundle() //recall b (the watchify/browserify object alreadyknows the source files). carry out the bundling
.on("error", function(err) {
console.log("Browserify error:", err);
})
.pipe(vss( distPath + '/js/source.js'))
.pipe(gulp.dest('./'))
//after you're done bundling, inform browserSync to reload the page
.pipe(browserSync.reload({stream:true, once: true}));
};
var b = browserify({
cache: {},
packageCache: {},
fullPaths: true
});
//files we'll bundle and watch for changes to trigger bundling
b.add(examplesPath + '/js/source.js');
// b.add(examplesPath + '/index.nunj');
//wrap
b = watchify(b);
//whenever a file we're bundling is updated
b.on('update', function(paths){
//give some sort of gulp indication that a save occured on one of the watched files
console.log('watchify rebundling: ', paths);
bundleShare(b); //browserify away
});
// b.on('error', function (error) { // Catch any js errors and prevent them from crashing gulp
// console.error(error);
// this.emit('end');
// })
//while we're here let's do a one time browserify bundling
bundleShare(b);
});
//compile sass -> css
gulp.task('sass', function() {
return gulp.src(examplesPath + '/sass/styles.scss')
.pipe(sass({
//disabling sourmaps for now fir gulp-ruby-sass work with gulp-autoprefixer
//see http://stackoverflow.com/questions/26979433/gulp-with-gulp-ruby-sass-error-style-css-map31-unknown-word
"sourcemap=none": true,
//have some more stylesheets you may want to use? Add them here
"loadPath" : ['assets/scss']
}))
.on('error', function (error) { // Catch any SCSS errors and prevent them from crashing gulp
console.error(error);
this.emit('end');
})
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest(distPath + '/css'))
.pipe(browserSync.reload({ stream:true, once: true }));
});
//generate the html from the swig templates
gulp.task('gen-html', function() {
console.log('gen-html: generating html to %s', distPath);
var swigopts = {
defaults: {
cache: false
}
};
return gulp.src(examplesPath + '/index.swig')
.pipe(swig(swigopts))
.pipe(gulp.dest(distPath));
});
//watching non-specialized files (like sas changes)
gulp.task('watch', function(){
//when the scss changes, run gulp-sass task
gulp.watch(examplesPath + '/sass/styles.scss', ['sass']);
//when the html (swig template) changes
gulp.watch(examplesPath + '/**/*.swig', ['gen-html']);
})
//we'll kick off watchify which will take care of the bundling and inform us
// ex: $ gulp browserSync --batch svg-pocket-guide --name svg-001-test
gulp.task('browserSync', ['watchify', 'watch'], function() {
browserSync(
{
server: { //have browser-synce be the static site
baseDir: "./", //the root /
directory: true //alternatly the root can just be the directory and you click the file
},
port: port,
// browserSync will have some watching duties as well. whenever the
// generated html changes we'll have refresh
files: [ distPath + '/index.html' ]
});
});
//
gulp.task('deploy-gh-pages', function () {
//fetch docs from generated area
return gulp.src('./dist/**/*')
.pipe(deployGh());
});