-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathgulpfile.js
95 lines (77 loc) · 2.35 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
'use strict';
var fs = require('fs');
var path = require('path');
var gulp = require('gulp');
var brfs = require('brfs');
var source = require('vinyl-source-stream');
var connect = require('gulp-connect');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var reactify = require('reactify');
var browserify = require('browserify');
var watchify = require('watchify');
var uglify = require('gulp-uglify');
var replace = require('gulp-replace');
gulp.task('default', ['set-version', 'lib', 'style'], function () {
gulp.watch('./stylesheets/**/*.scss', ['style']);
return connect.server({
root: ['dist'],
port: 8000,
livereload: true
});
});
gulp.task('lib', function () {
var bundler = watchify(browserify({
cache: {},
packageCache: {},
fullPaths: true,
extensions: '.jsx'
}));
bundler.add('./lib/init.js');
bundler.transform(reactify);
bundler.transform(brfs);
bundler.on('update', rebundle);
function rebundle () {
console.log('rebundling');
return bundler.bundle()
.on('error', function (err) {
console.log(err.message);
})
.pipe(source('main.js'))
.pipe(gulp.dest('./dist/js'))
.pipe(connect.reload());
}
return rebundle();
});
gulp.task('style', function () {
return gulp.src('./stylesheets/main.scss')
.pipe(sass({errLogToConsole: true, outputStyle: 'compressed'}))
.pipe(autoprefixer())
.pipe(gulp.dest('./dist/css'))
.pipe(connect.reload());
});
gulp.task('set-version', function () {
return gulp.src('./dist/index.html')
.pipe(replace(/\?v=([\w\.]+)/g, '?v=' + require('./package.json').version))
.pipe(gulp.dest('./dist/'))
.pipe(connect.reload());
});
gulp.task('schemes', function () {
var source = 'dist/schemes';
var index = 'index.json';
var output = [];
fs.readdirSync(source).forEach(function (folder) {
if (folder !== index) {
var files = fs.readdirSync(path.join(source, folder));
output = output.concat(files.map(function (file) {
return path.join(folder, path.basename(file, '.json'));
}));
}
});
fs.writeFileSync(path.join(source, index), JSON.stringify(output));
});
gulp.task('minify', function () {
return gulp.src('./dist/js/*')
.pipe(uglify())
.pipe(gulp.dest('./dist/js'));
});