forked from getkaiwa/kaiwa
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathGulpfile.js
130 lines (116 loc) · 3.56 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
var batch = require('gulp-batch');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var concat = require('gulp-concat');
var concatCss = require('gulp-concat-css');
var fs = require('fs');
var gulp = require('gulp');
var jade = require('gulp-jade');
var merge = require('merge-stream');
var mkdirp = require('mkdirp');
var source = require('vinyl-source-stream');
var stylus = require('gulp-stylus');
var templatizer = require('templatizer');
var watch = require('gulp-watch');
var gitrev = require('git-rev');
var webpack = require("webpack-stream");
var gutil = require("gulp-util");
function getConfig() {
var config = fs.readFileSync('./dev_config.json');
return JSON.parse(config);
}
gulp.task('compile', ['resources', 'client', 'config', 'manifest']);
gulp.task('watch', function () {
watch([
'./src/**',
'!./src/js/templates.js',
'./dev_config.json'
], batch(function (events, done) {
console.log('==> Recompiling Kaiwa');
gulp.start('compile', done);
}));
});
gulp.task('resources', function () {
return gulp.src('./src/resources/**')
.pipe(gulp.dest('./public'));
});
gulp.task('client', ['jade-templates', 'jade-views'], function (cb) {
webpack(Object.assign({
plugins: []
}, require('./webpack.config.js')), null, function(err, stats) {
if(err) return cb(JSON.stringify(err));
gutil.log("[webpack]", stats.toString());
return stats;
})
.pipe(gulp.dest('./public/js'))
.on('end', cb);
});
gulp.task('config', function (cb) {
var config = getConfig();
gitrev.short(function (commit) {
config.server.softwareVersion = {
"name": config.server.name,
"version": commit
}
config.server.baseUrl = config.http.baseUrl
mkdirp('./public', function (error) {
if (error) {
cb(error);
return;
}
fs.writeFile(
'./public/config.js',
'var SERVER_CONFIG = ' + JSON.stringify(config.server) + ';',
cb);
});
})
});
gulp.task('manifest', function (cb) {
var pkg = require('./package.json');
var config = getConfig();
fs.readFile('./src/manifest/manifest.cache', 'utf-8', function (error, content) {
if (error) {
cb(error);
return;
}
mkdirp('./public', function (error) {
if (error) {
cb(error);
return;
}
var manifest = content.replace(
'#{version}',
pkg.version + config.isDev ? ' ' + Date.now() : '');
fs.writeFile('./public/manifest.cache', manifest, cb);
});
});
});
gulp.task('jade-templates', function (cb) {
templatizer('./src/jade/templates', './src/js/templates.js', cb);
});
gulp.task('jade-views', ['css'], function () {
var config = getConfig();
return gulp.src([
'./src/jade/views/*',
'!./src/jave/views/layout.jade'
])
.pipe(jade({
locals: {
config: config
}
}))
.pipe(gulp.dest('./public/'));
});
gulp.task('css', ['stylus'], function () {
return gulp.src([
'./build/css/*.css',
'./src/css/*.css'
])
.pipe(concatCss('app.css'))
.pipe(gulp.dest('./public/css/'));
});
gulp.task('stylus', function () {
return gulp.src('./src/stylus/client.styl')
.pipe(stylus())
.pipe(gulp.dest('./build/css'));
});