UNPKG

3.15 kBJavaScriptView Raw
1'use strict';
2const webpack = require('webpack');
3const through2 = require('through2');
4const path = require('path');
5const gulp = require('gulp');
6const readline = require('readline');
7const fs = require('fs');
8
9const rimraf = require('rimraf');
10const mkdirp = require('mkdirp');
11
12const cwd = process.cwd();
13
14function dist(done) {
15 rimraf.sync(path.join(cwd, '_site'));
16 process.env.RUN_ENV = 'PRODUCTION';
17 const webpackConfig = require(path.join(cwd, 'build/webpack.site.conf.js'));
18 webpack(webpackConfig, (err, stats) => {
19 if (err) {
20 console.error(err.stack || err);
21 if (err.details) {
22 console.error(err.details);
23 }
24 return;
25 }
26
27 const info = stats.toJson();
28
29 if (stats.hasErrors()) {
30 console.error(info.errors);
31 }
32
33 if (stats.hasWarnings()) {
34 console.warn(info.warnings);
35 }
36
37 const buildInfo = stats.toString({
38 colors: true,
39 children: true,
40 chunks: false,
41 modules: false,
42 chunkModules: false,
43 hash: false,
44 version: false,
45 });
46 console.log(buildInfo);
47 done(0);
48 });
49}
50
51function copyHtml() {
52 const rl = readline.createInterface({
53 input: fs.createReadStream(path.join(cwd, 'site/demoRoutes.js')),
54 });
55 fs.writeFileSync(
56 path.join(cwd, '_site/404.html'),
57 fs.readFileSync(path.join(cwd, 'site/404.html')),
58 );
59 fs.writeFileSync(
60 path.join(cwd, '_site/index-cn.html'),
61 fs.readFileSync(path.join(cwd, '_site/index.html')),
62 );
63 fs.writeFileSync(path.join(cwd, '_site/CNAME'), 'vue.ant.design');
64 rl.on('line', line => {
65 if (line.indexOf('path:') > -1) {
66 const name = line.split("'")[1].split("'")[0];
67 console.log('create path:', name);
68 const toPaths = [
69 `_site/components/${name}`,
70 // `_site/components/${name}-cn`,
71 `_site/iframe/${name}`,
72 // `_site/iframe/${name}-cn`,
73 ];
74 toPaths.forEach(toPath => {
75 rimraf.sync(path.join(cwd, toPath));
76 mkdirp(path.join(cwd, toPath), function() {
77 fs.writeFileSync(
78 path.join(cwd, `${toPath}/index.html`),
79 fs.readFileSync(path.join(cwd, '_site/index.html')),
80 );
81 });
82 });
83 }
84 });
85 const source = [
86 'docs/vue/*.md',
87 '*.md',
88 // '!components/vc-slider/**/*', // exclude vc-slider
89 ];
90 gulp.src(source).pipe(
91 through2.obj(function z(file, encoding, next) {
92 const paths = file.path.split('/');
93 const name = paths[paths.length - 1].split('.')[0].toLowerCase();
94 const toPaths = [
95 '_site/docs',
96 '_site/docs/vue',
97 `_site/docs/vue/${name}`,
98 `_site/docs/vue/${name}-cn`,
99 ];
100 toPaths.forEach(toPath => {
101 mkdirp(path.join(cwd, toPath), function() {
102 fs.writeFileSync(
103 path.join(cwd, `${toPath}/index.html`),
104 fs.readFileSync(path.join(cwd, '_site/index.html')),
105 );
106 });
107 });
108 next();
109 }),
110 );
111}
112
113gulp.task(
114 '_site',
115 gulp.series(done => {
116 dist(() => {
117 copyHtml();
118 done();
119 });
120 }),
121);
122gulp.task(
123 'copy-html',
124 gulp.series(() => {
125 copyHtml();
126 }),
127);