forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
129 lines (120 loc) · 3.17 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
'use strict';
const webpack = require('webpack');
const through2 = require('through2');
const path = require('path');
const gulp = require('gulp');
const readline = require('readline');
const fs = require('fs');
const rimraf = require('rimraf');
const mkdirp = require('mkdirp');
const cwd = process.cwd();
function dist(done) {
rimraf.sync(path.join(cwd, '_site'));
process.env.RUN_ENV = 'PRODUCTION';
const webpackConfig = require(path.join(cwd, 'build/webpack.site.conf.js'));
webpack(webpackConfig, (err, stats) => {
if (err) {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
return;
}
const info = stats.toJson();
if (stats.hasErrors()) {
console.error(info.errors);
}
if (stats.hasWarnings()) {
console.warn(info.warnings);
}
const buildInfo = stats.toString({
colors: true,
children: true,
chunks: false,
modules: false,
chunkModules: false,
hash: false,
version: false,
});
// eslint-disable-next-line no-console
console.log(buildInfo);
done(0);
});
}
function copyHtml() {
const rl = readline.createInterface({
input: fs.createReadStream(path.join(cwd, 'site/demoRoutes.js')),
});
fs.writeFileSync(
path.join(cwd, '_site/404.html'),
fs.readFileSync(path.join(cwd, 'site/404.html')),
);
fs.writeFileSync(
path.join(cwd, '_site/index-cn.html'),
fs.readFileSync(path.join(cwd, '_site/index.html')),
);
fs.writeFileSync(path.join(cwd, '_site/CNAME'), 'vue.ant.design');
rl.on('line', line => {
if (line.indexOf('path:') > -1) {
const name = line.split("'")[1].split("'")[0];
// eslint-disable-next-line no-console
console.log('create path:', name);
const toPaths = [
`_site/components/${name}`,
// `_site/components/${name}-cn`,
`_site/iframe/${name}`,
// `_site/iframe/${name}-cn`,
];
toPaths.forEach(toPath => {
rimraf.sync(path.join(cwd, toPath));
mkdirp(path.join(cwd, toPath), function () {
fs.writeFileSync(
path.join(cwd, `${toPath}/index.html`),
fs.readFileSync(path.join(cwd, '_site/index.html')),
);
});
});
}
});
const source = [
'docs/vue/*.md',
'*.md',
// '!components/vc-slider/**/*', // exclude vc-slider
];
gulp.src(source).pipe(
through2.obj(function z(file, encoding, next) {
const paths = file.path.split('/');
const name = paths[paths.length - 1].split('.')[0].toLowerCase();
const toPaths = [
'_site/docs',
'_site/docs/vue',
`_site/docs/vue/${name}`,
`_site/docs/vue/${name}-cn`,
];
toPaths.forEach(toPath => {
mkdirp(path.join(cwd, toPath), function () {
fs.writeFileSync(
path.join(cwd, `${toPath}/index.html`),
fs.readFileSync(path.join(cwd, '_site/index.html')),
);
});
});
next();
}),
);
}
gulp.task(
'_site',
gulp.series(done => {
dist(() => {
copyHtml();
done();
});
}),
);
gulp.task(
'copy-html',
gulp.series(() => {
copyHtml();
}),
);