-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
201 lines (170 loc) · 4.82 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
const assembler = require('fabricator-assemble');
const browserSync = require('browser-sync');
const csso = require('gulp-csso');
const del = require('del');
const gulp = require('gulp');
const gutil = require('gulp-util');
const gulpif = require('gulp-if');
const imagemin = require('gulp-imagemin');
const prefix = require('gulp-autoprefixer');
const rename = require('gulp-rename');
const reload = browserSync.reload;
const runSequence = require('run-sequence');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const webpack = require('webpack');
const ghPages = require('gulp-gh-pages');
// configuration
const config = {
dev: gutil.env.dev,
styles: {
browsers: 'last 1 version',
fabricator: {
src: 'src/assets/fabricator/styles/fabricator.scss',
dest: 'dist/assets/fabricator/styles',
watch: 'src/assets/fabricator/styles/**/*.scss',
},
toolkit: {
src: 'src/assets/toolkit/styles/toolkit.scss',
dest: 'dist/assets/toolkit/styles',
watch: 'src/assets/toolkit/styles/**/*.scss',
},
},
scripts: {
fabricator: {
src: './src/assets/fabricator/scripts/fabricator.js',
dest: 'dist/assets/fabricator/scripts',
watch: 'src/assets/fabricator/scripts/**/*',
},
toolkit: {
src: './src/assets/toolkit/scripts/toolkit.js',
dest: 'dist/assets/toolkit/scripts',
watch: 'src/assets/toolkit/scripts/**/*',
},
},
fonts: {
toolkit: {
src: './src/assets/toolkit/fonts/**/*',
dest: 'dist/assets/toolkit/fonts'
}
},
images: {
toolkit: {
src: ['src/assets/toolkit/images/**/*', 'src/favicon.ico'],
dest: 'dist/assets/toolkit/images',
watch: 'src/assets/toolkit/images/**/*',
},
},
templates: {
watch: 'src/**/*.{html,md,json,yml}',
},
dest: 'dist',
};
// clean
gulp.task('clean', del.bind(null, [config.dest]));
// styles
gulp.task('styles:fabricator', () => {
gulp.src(config.styles.fabricator.src)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(prefix('last 1 version'))
.pipe(gulpif(!config.dev, csso()))
.pipe(rename('f.css'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(config.styles.fabricator.dest))
.pipe(gulpif(config.dev, reload({ stream: true })));
});
gulp.task('styles:toolkit', () => {
gulp.src(config.styles.toolkit.src)
.pipe(gulpif(config.dev, sourcemaps.init()))
.pipe(sass({
includePaths: './node_modules',
}).on('error', sass.logError))
.pipe(prefix('last 1 version'))
.pipe(gulpif(!config.dev, csso()))
.pipe(gulpif(config.dev, sourcemaps.write()))
.pipe(gulp.dest(config.styles.toolkit.dest))
.pipe(gulpif(config.dev, reload({ stream: true })));
});
gulp.task('styles', ['styles:fabricator', 'styles:toolkit']);
// scripts
const webpackConfig = require('./webpack.config')(config);
gulp.task('scripts', (done) => {
webpack(webpackConfig, (err, stats) => {
if (err) {
gutil.log(gutil.colors.red(err()));
}
const result = stats.toJson();
if (result.errors.length) {
result.errors.forEach((error) => {
gutil.log(gutil.colors.red(error));
});
}
done();
});
});
// fonts
gulp.task('fonts', () => {
return gulp.src(config.fonts.toolkit.src)
.pipe(gulp.dest(config.fonts.toolkit.dest))
});
// images
gulp.task('images', ['favicon'], () => {
return gulp.src(config.images.toolkit.src)
.pipe(imagemin())
.pipe(gulp.dest(config.images.toolkit.dest));
});
gulp.task('favicon', () => {
return gulp.src('src/favicon.ico')
.pipe(gulp.dest(config.dest));
});
// assembler
gulp.task('assembler', (done) => {
assembler({
logErrors: config.dev,
dest: config.dest,
});
done();
});
// server
gulp.task('serve', () => {
browserSync({
server: {
baseDir: config.dest,
},
notify: false,
logPrefix: 'FABRICATOR',
});
gulp.task('assembler:watch', ['assembler'], browserSync.reload);
gulp.watch(config.templates.watch, ['assembler:watch']);
gulp.task('styles:watch', ['styles']);
gulp.watch([config.styles.fabricator.watch, config.styles.toolkit.watch], ['styles:watch']);
gulp.task('scripts:watch', ['scripts'], browserSync.reload);
gulp.watch([config.scripts.fabricator.watch, config.scripts.toolkit.watch], ['scripts:watch']);
gulp.task('images:watch', ['images'], browserSync.reload);
gulp.watch(config.images.toolkit.watch, ['images:watch']);
});
// default build task
gulp.task('default', ['clean'], () => {
// define build tasks
const tasks = [
'styles',
'scripts',
'fonts',
'images',
'assembler',
];
// run build
runSequence(tasks, () => {
if (config.dev) {
gulp.start('serve');
}
});
});
// deploy
gulp.task('deploy', () => {
return gulp.src(config.dest + '/**/*')
.pipe(ghPages({
remoteUrl: '[email protected]:pyconca/2017-patterns.git'
}));
});