2019-01-12 03:33:27 +00:00
|
|
|
'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');
|
2018-04-04 10:39:21 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const rimraf = require('rimraf');
|
|
|
|
const mkdirp = require('mkdirp');
|
2018-04-04 10:39:21 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const cwd = process.cwd();
|
2018-04-04 10:39:21 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
function dist(done) {
|
2019-02-23 04:12:44 +00:00
|
|
|
rimraf.sync(path.join(cwd, '_site'));
|
2019-01-12 03:33:27 +00:00
|
|
|
process.env.RUN_ENV = 'PRODUCTION';
|
2019-12-30 09:11:03 +00:00
|
|
|
const webpackConfig = require(path.join(cwd, 'build/webpack.site.conf.js'));
|
2018-04-04 10:39:21 +00:00
|
|
|
webpack(webpackConfig, (err, stats) => {
|
|
|
|
if (err) {
|
2019-01-12 03:33:27 +00:00
|
|
|
console.error(err.stack || err);
|
2018-04-04 10:39:21 +00:00
|
|
|
if (err.details) {
|
2019-01-12 03:33:27 +00:00
|
|
|
console.error(err.details);
|
2018-04-04 10:39:21 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
return;
|
2018-04-04 10:39:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const info = stats.toJson();
|
2018-04-04 10:39:21 +00:00
|
|
|
|
|
|
|
if (stats.hasErrors()) {
|
2019-01-12 03:33:27 +00:00
|
|
|
console.error(info.errors);
|
2018-04-04 10:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stats.hasWarnings()) {
|
2019-01-12 03:33:27 +00:00
|
|
|
console.warn(info.warnings);
|
2018-04-04 10:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const buildInfo = stats.toString({
|
|
|
|
colors: true,
|
|
|
|
children: true,
|
|
|
|
chunks: false,
|
|
|
|
modules: false,
|
|
|
|
chunkModules: false,
|
|
|
|
hash: false,
|
|
|
|
version: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2021-06-23 15:08:16 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2019-01-12 03:33:27 +00:00
|
|
|
console.log(buildInfo);
|
|
|
|
done(0);
|
|
|
|
});
|
2018-04-04 10:39:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
function copyHtml() {
|
2018-04-04 10:39:21 +00:00
|
|
|
const rl = readline.createInterface({
|
2018-07-13 13:55:29 +00:00
|
|
|
input: fs.createReadStream(path.join(cwd, 'site/demoRoutes.js')),
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2019-02-16 08:51:21 +00:00
|
|
|
fs.writeFileSync(
|
2019-02-23 04:12:44 +00:00
|
|
|
path.join(cwd, '_site/404.html'),
|
2019-02-16 08:51:21 +00:00
|
|
|
fs.readFileSync(path.join(cwd, 'site/404.html')),
|
|
|
|
);
|
2019-02-19 10:37:10 +00:00
|
|
|
fs.writeFileSync(
|
2019-02-23 04:12:44 +00:00
|
|
|
path.join(cwd, '_site/index-cn.html'),
|
|
|
|
fs.readFileSync(path.join(cwd, '_site/index.html')),
|
2019-02-19 10:37:10 +00:00
|
|
|
);
|
2019-02-23 04:12:44 +00:00
|
|
|
fs.writeFileSync(path.join(cwd, '_site/CNAME'), 'vue.ant.design');
|
2019-01-12 03:33:27 +00:00
|
|
|
rl.on('line', line => {
|
2018-07-13 13:55:29 +00:00
|
|
|
if (line.indexOf('path:') > -1) {
|
2019-01-12 03:33:27 +00:00
|
|
|
const name = line.split("'")[1].split("'")[0];
|
2021-06-23 15:08:16 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2019-01-12 03:33:27 +00:00
|
|
|
console.log('create path:', name);
|
2018-07-13 13:55:29 +00:00
|
|
|
const toPaths = [
|
2019-02-23 04:12:44 +00:00
|
|
|
`_site/components/${name}`,
|
|
|
|
// `_site/components/${name}-cn`,
|
|
|
|
`_site/iframe/${name}`,
|
|
|
|
// `_site/iframe/${name}-cn`,
|
2019-01-12 03:33:27 +00:00
|
|
|
];
|
2018-07-13 13:55:29 +00:00
|
|
|
toPaths.forEach(toPath => {
|
2019-01-12 03:33:27 +00:00
|
|
|
rimraf.sync(path.join(cwd, toPath));
|
2021-06-23 15:08:16 +00:00
|
|
|
mkdirp(path.join(cwd, toPath), function () {
|
2019-01-12 03:33:27 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
path.join(cwd, `${toPath}/index.html`),
|
2019-02-23 04:12:44 +00:00
|
|
|
fs.readFileSync(path.join(cwd, '_site/index.html')),
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-07-13 13:55:29 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-04-10 05:37:06 +00:00
|
|
|
const source = [
|
|
|
|
'docs/vue/*.md',
|
2018-04-21 10:50:10 +00:00
|
|
|
'*.md',
|
2018-04-10 05:37:06 +00:00
|
|
|
// '!components/vc-slider/**/*', // exclude vc-slider
|
2019-01-12 03:33:27 +00:00
|
|
|
];
|
|
|
|
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 = [
|
2019-02-23 04:12:44 +00:00
|
|
|
'_site/docs',
|
|
|
|
'_site/docs/vue',
|
|
|
|
`_site/docs/vue/${name}`,
|
|
|
|
`_site/docs/vue/${name}-cn`,
|
2019-01-12 03:33:27 +00:00
|
|
|
];
|
|
|
|
toPaths.forEach(toPath => {
|
2021-06-23 15:08:16 +00:00
|
|
|
mkdirp(path.join(cwd, toPath), function () {
|
2019-01-12 03:33:27 +00:00
|
|
|
fs.writeFileSync(
|
|
|
|
path.join(cwd, `${toPath}/index.html`),
|
2019-02-23 04:12:44 +00:00
|
|
|
fs.readFileSync(path.join(cwd, '_site/index.html')),
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
next();
|
|
|
|
}),
|
|
|
|
);
|
2018-04-04 10:39:21 +00:00
|
|
|
}
|
|
|
|
|
2019-07-10 10:14:41 +00:00
|
|
|
gulp.task(
|
|
|
|
'_site',
|
|
|
|
gulp.series(done => {
|
|
|
|
dist(() => {
|
|
|
|
copyHtml();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
gulp.task(
|
|
|
|
'copy-html',
|
|
|
|
gulp.series(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
copyHtml();
|
2019-07-10 10:14:41 +00:00
|
|
|
}),
|
|
|
|
);
|