-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
172 lines (152 loc) · 3.55 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
161
162
163
164
165
166
167
168
169
170
171
172
const autoprefixer = require('autoprefixer-core');
const cssnano = require('cssnano');
const cssnext = require('cssnext');
const del = require('del');
const eslint = require('eslint');
const ghpages = require('gh-pages');
const gulp = require('gulp');
const gutil = require('gulp-util');
const liveServer = require('live-server');
const PagesWriter = require('./lib/PagesWriter');
const path = require('path');
const paths = require('./lib/paths');
const postcss = require('gulp-postcss');
const postcssImport = require('postcss-import');
const postcssNested = require('postcss-nested');
const props = require('./lib/props');
const reload = require('require-reload')(require);
const sourcemaps = require('gulp-sourcemaps');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
var pw;
gulp.task('generate', ['js'], function(done) {
const renderer = reload('./public/bundle');
pw = new PagesWriter();
pw.setState({
paths: paths(),
props: props(),
renderer: renderer,
}).once('write', done);
});
gulp.task('paths:watch', ['generate'], function() {
gulp.watch([
'paths.js',
'posts/**/*',
], function() {
pw.setState({ paths: paths() });
});
});
gulp.task('props:watch', ['generate'], function() {
gulp.watch([
'posts/**/*',
], function() {
pw.setState({ props: props() });
});
});
gulp.task('renderer:watch', ['generate'], function() {
gulp.watch([
'public/bundle.js',
], function() {
const renderer = reload('./public/bundle');
pw.setState({ renderer: renderer });
});
});
gulp.task('assets', function() {
return gulp.src([
'src/CNAME',
'src/fonts/**/*',
'src/images/**/*',
], { base: 'src' })
.pipe(gulp.dest('public'));
});
gulp.task('build', [
'assets',
'css:build',
'generate',
]);
gulp.task('clean', function(done) {
del('public', done);
});
gulp.task('css', function() {
const processors = [
postcssImport,
postcssNested,
cssnext(),
autoprefixer,
];
return gulp.src('src/css/app.css')
.pipe(sourcemaps.init())
.pipe(postcss(processors))
.pipe(sourcemaps.write())
.pipe(gulp.dest('public'));
});
gulp.task('css:watch', ['css'], function() {
gulp.watch('src/css/**/*', ['css']);
});
gulp.task('css:build', function() {
const processors = [
postcssImport,
postcssNested,
cssnext(),
autoprefixer,
cssnano,
];
return gulp.src('src/css/app.css')
.pipe(postcss(processors))
.pipe(gulp.dest('public'));
});
gulp.task('deploy', ['build'], function(done) {
ghpages.publish(path.join(__dirname, 'public'), {
branch: 'master',
}, done);
});
gulp.task('js', function(done) {
var initialDone;
webpack(webpackConfig).watch({}, function(err, stats) {
if (err) {
throw new gutil.PluginError('webpack', err);
}
if (!initialDone) {
done();
initialDone = true;
}
});
});
const cli = new eslint.CLIEngine({
extensions: ['.js', '.jsx'],
});
const formatter = cli.getFormatter();
gulp.task('lint', function(done) {
const report = cli.executeOnFiles(['.']);
console.log(formatter(report.results));
done();
});
gulp.task('lint:watch', ['lint'], function() {
gulp.watch([
'*.js',
'.eslintrc',
'lib/**/*',
'src/js/**/*',
], ['lint']);
});
function server() {
liveServer.start({
port: 4069,
root: 'public',
wait: 16,
});
}
gulp.task('server', function() {
server();
});
gulp.task('watch', [
'assets',
'css:watch',
'generate',
'lint:watch',
'paths:watch',
'props:watch',
'renderer:watch',
], function() {
server();
});