This repository has been archived by the owner on May 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
176 lines (154 loc) · 4.09 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
// @flow
/* eslint no-console: 0 */
const fs = require('fs');
const gulp = require('gulp');
const ignore = require('gulp-ignore');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const svgSprite = require('gulp-svg-sprite');
const path = require('path');
const del = require('del');
const plumber = require('gulp-plumber');
const pump = require('pump');
const exec = require('child_process').exec;
const IGNORED_JS_SOURCE = ['**/__mocks__', '**/*.test.js'];
const spriteDirContents = fs.readdirSync(path.join('static', 'sprites'));
const SPRITE_TASKS = [];
const SPRITE_WATCH_TASKS = [];
spriteDirContents.forEach(p => {
if (p.startsWith('.')) {
return;
}
const taskName = `sprite:${p}`;
SPRITE_TASKS.push(taskName);
SPRITE_WATCH_TASKS.push(`watch:${taskName}`);
gulp.task(taskName, () =>
gulp
.src(`static/sprites/${p}/*.svg`)
.pipe(plumber())
.pipe(
svgSprite({
mode: {
symbol: {
sprite: `${p}.svg`,
dest: '',
},
},
})
)
.pipe(gulp.dest('static/assets/img/svg'))
);
gulp.task(`watch:${taskName}`, () =>
gulp.watch(`static/sprites/${p}/*.svg`, [taskName])
);
});
gulp.task('sprite', SPRITE_TASKS);
gulp.task('watch:sprite', SPRITE_WATCH_TASKS);
gulp.task('clean:build', () => del('build'));
gulp.task('clean:next', () => del('.next'));
gulp.task('babel:server', ['clean:build'], () =>
gulp
.src('server/**/*.js')
.pipe(plumber())
.pipe(ignore.exclude(IGNORED_JS_SOURCE))
.pipe(babel())
.pipe(gulp.dest('build/server'))
);
gulp.task('babel:clean', () => del('node_modules/.cache/babel-loader'));
gulp.task('next:compile', ['clean:next'], cb => {
exec(
`${path.join('node_modules', '.bin', 'next')} build`,
(err, stdout, stderr) => {
if (stdout) console.log(stdout);
if (stderr) console.log(stderr);
cb(err);
}
);
});
gulp.task('storybook:head', ['templates:fetch'], cb => {
exec(
`${path.join('node_modules', '.bin', 'babel-node')} ${path.join(
'.',
'scripts',
'make-storybook-head'
)}`,
(err, stdout, stderr) => {
if (stdout) console.log(stdout);
if (stderr) console.log(stderr);
cb(err);
}
);
});
gulp.task('vendor', cb => {
pump(
[
gulp.src([
'node_modules/html5-history-api/history.js',
'node_modules/classlist-polyfill/src/index.js',
]),
uglify(),
concat('ie9-polyfill.js'),
gulp.dest('static/assets/vendor'),
],
cb
);
});
gulp.task('templates:fetch', ['babel:clean'], cb => {
exec(
`${path.join('node_modules', '.bin', 'babel-node')} ${path.join(
'.',
'scripts',
'fetch-templates'
)}`,
(err, stdout, stderr) => {
if (stdout) console.log(stdout);
if (stderr) console.log(stderr);
cb(err);
}
);
});
const GRAPHQL_QUERIES = path.join('data', 'dao', 'graphql', '*.graphql');
const GRAPHQL_SCHEMA = path.join('graphql', 'schema.json');
gulp.task('graphql:schema', cb => {
exec(
`${path.join('node_modules', '.bin', 'babel-node')} ${path.join(
'.',
'scripts',
'generate-schema'
)}`,
(err, stdout, stderr) => {
if (stdout) console.log(stdout);
if (stderr) console.log(stderr);
cb(err);
}
);
});
gulp.task('graphql:types', ['graphql:schema'], cb => {
exec(
`${path.join(
'node_modules',
'.bin',
'apollo-codegen'
)} generate ${GRAPHQL_QUERIES} --schema ${GRAPHQL_SCHEMA} --target flow --output data/dao/graphql/types.js --no-add-typename`,
(err, stdout, stderr) => {
if (stdout) console.log(stdout);
if (stderr) console.log(stderr);
cb(err);
}
);
});
gulp.task('watch:graphql', () => [
gulp.watch('server/graphql/*.js', ['graphql:schema']),
gulp.watch(
[GRAPHQL_QUERIES.replace(/\\/g, '/'), GRAPHQL_SCHEMA.replace(/\\/g, '/')],
['graphql:types']
),
]);
gulp.task('build', [
'templates:fetch',
'babel:server',
'next:compile',
'vendor',
]);
gulp.task('watch', ['watch:graphql', 'watch:sprite']);