1 | 'use strict';
|
2 | const webpack = require('webpack');
|
3 | const through2 = require('through2');
|
4 | const path = require('path');
|
5 | const gulp = require('gulp');
|
6 | const readline = require('readline');
|
7 | const fs = require('fs');
|
8 |
|
9 | const rimraf = require('rimraf');
|
10 | const mkdirp = require('mkdirp');
|
11 |
|
12 | const cwd = process.cwd();
|
13 |
|
14 | function 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 |
|
47 | console.log(buildInfo);
|
48 | done(0);
|
49 | });
|
50 | }
|
51 |
|
52 | function copyHtml() {
|
53 | const rl = readline.createInterface({
|
54 | input: fs.createReadStream(path.join(cwd, 'site/demoRoutes.js')),
|
55 | });
|
56 | fs.writeFileSync(
|
57 | path.join(cwd, '_site/404.html'),
|
58 | fs.readFileSync(path.join(cwd, 'site/404.html')),
|
59 | );
|
60 | fs.writeFileSync(
|
61 | path.join(cwd, '_site/index-cn.html'),
|
62 | fs.readFileSync(path.join(cwd, '_site/index.html')),
|
63 | );
|
64 | fs.writeFileSync(path.join(cwd, '_site/CNAME'), 'vue.ant.design');
|
65 | rl.on('line', line => {
|
66 | if (line.indexOf('path:') > -1) {
|
67 | const name = line.split("'")[1].split("'")[0];
|
68 |
|
69 | console.log('create path:', name);
|
70 | const toPaths = [
|
71 | `_site/components/${name}`,
|
72 |
|
73 | `_site/iframe/${name}`,
|
74 |
|
75 | ];
|
76 | toPaths.forEach(toPath => {
|
77 | rimraf.sync(path.join(cwd, toPath));
|
78 | mkdirp(path.join(cwd, toPath), function () {
|
79 | fs.writeFileSync(
|
80 | path.join(cwd, `${toPath}/index.html`),
|
81 | fs.readFileSync(path.join(cwd, '_site/index.html')),
|
82 | );
|
83 | });
|
84 | });
|
85 | }
|
86 | });
|
87 | const source = [
|
88 | 'docs/vue/*.md',
|
89 | '*.md',
|
90 |
|
91 | ];
|
92 | gulp.src(source).pipe(
|
93 | through2.obj(function z(file, encoding, next) {
|
94 | const paths = file.path.split('/');
|
95 | const name = paths[paths.length - 1].split('.')[0].toLowerCase();
|
96 | const toPaths = [
|
97 | '_site/docs',
|
98 | '_site/docs/vue',
|
99 | `_site/docs/vue/${name}`,
|
100 | `_site/docs/vue/${name}-cn`,
|
101 | ];
|
102 | toPaths.forEach(toPath => {
|
103 | mkdirp(path.join(cwd, toPath), function () {
|
104 | fs.writeFileSync(
|
105 | path.join(cwd, `${toPath}/index.html`),
|
106 | fs.readFileSync(path.join(cwd, '_site/index.html')),
|
107 | );
|
108 | });
|
109 | });
|
110 | next();
|
111 | }),
|
112 | );
|
113 | }
|
114 |
|
115 | gulp.task(
|
116 | '_site',
|
117 | gulp.series(done => {
|
118 | dist(() => {
|
119 | copyHtml();
|
120 | done();
|
121 | });
|
122 | }),
|
123 | );
|
124 | gulp.task(
|
125 | 'copy-html',
|
126 | gulp.series(() => {
|
127 | copyHtml();
|
128 | }),
|
129 | );
|