-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
148 lines (131 loc) · 3.2 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
const gulp = require('gulp');
const jshint = require('gulp-jshint');
const jshintReporter = require('jshint-stylish');
const shell = require('gulp-shell');
const open = require('gulp-open');
const os = require('os');
const babel = require('rollup-plugin-babel');
const rollup = require('gulp-rollup');
const sourcemaps = require('gulp-sourcemaps');
const sass = require('gulp-sass');
const autoprefixer = require('autoprefixer');
const postcss = require('gulp-postcss');
const imagemin = require('gulp-imagemin');
const cssmin = require('gulp-cssmin');
const DepLinker = require('dep-linker');
const paths = {
src: [
'./models/**/*.js',
'./routes/**/*.js',
'keystone.js',
'package.json'
],
style: {
src: [
'./front-end-src/scss/**/*.scss',
'./public/styles/**/*.scss'
],
dest: './public/styles/'
},
js: {
src: [
'./front-end-src/js/**/*.js',
'!./front-end-src/js/**/_*.*',
'!./front-end-src/js/**/_*/*'
],
dest: './public/js/',
all: ['./front-end-src/js/**/*']
},
assets: {
src: './front-end-src/assets/**/*.*',
dest: './public/assets/'
},
img: {
src: './front-end-src/img/**/*.*',
dest: './public/img/'
}
};
// gulp lint
gulp.task('lint', () => {
gulp.src(paths.src)
.pipe(jshint())
.pipe(jshint.reporter(jshintReporter));
});
// gulp watcher for lint
gulp.task('watch:lint', () => {
gulp.watch(paths.src, ['lint']);
});
gulp.task('watch:sass', () => {
gulp.watch(paths.style.src, ['sass']);
});
gulp.task('sass', () => {
gulp.src(paths.style.src)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(postcss([autoprefixer({ browsers: ['last 15 versions'] })]))
.pipe(cssmin())
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.style.dest));
});
gulp.task('rollup', () => {
gulp.src(paths.js.src)
.pipe(sourcemaps.init())
.pipe(rollup({
plugins: [
babel({ exclude: 'node_modules/**', presets: ['es2015-rollup'] })
] }))
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.js.dest));
});
gulp.task('watch:rollup', () => {
gulp.watch(paths.js.all, ['rollup']);
});
gulp.task('assets', () => {
gulp.src(paths.assets.src)
.pipe(gulp.dest(paths.assets.dest));
});
gulp.task('watch:assets', () => {
gulp.watch(paths.js.src, ['assets']);
});
gulp.task('dependencies', () => {
return DepLinker.copyDependenciesTo('./public/scripts');
});
gulp.task('img', () => {
gulp.src(paths.img.src)
.pipe(imagemin({
progressive: true
}))
.pipe(gulp.dest(paths.img.dest));
});
gulp.task('watch:img', () => {
gulp.watch(paths.js.src, ['img']);
});
gulp.task('runKeystone', shell.task('node keystone.js'));
gulp.task('watch', [
'watch:sass',
'watch:lint',
'watch:rollup',
'watch:assets',
'watch:img'
]);
gulp.task('open', () => {
const platform = os.platform;
let browserName;
switch (platform) {
case 'darwin': // OSX
browserName = 'google chrome';
break;
case 'win32': // Windows
browserName = 'chrome';
break;
default: // linux
browserName = 'google-chrome';
}
gulp.src(__filename)
.pipe(open({
uri: 'http://localhost:3000',
app: browserName
}));
});
gulp.task('default', ['rollup', 'watch', 'runKeystone', 'open']);
gulp.task('build-watch', ['dependencies', 'rollup', 'sass', 'assets', 'img', 'watch']);