ant-design-vue/scripts/gulpfile.js

128 lines
3.1 KiB
JavaScript
Raw Normal View History

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