ant-design-vue/scripts/gulpfile.js

117 lines
2.9 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-dist'));
process.env.RUN_ENV = 'PRODUCTION';
const webpackConfig = require(path.join(cwd, 'webpack.site.config.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-dist/404.html'),
fs.readFileSync(path.join(cwd, 'site/404.html')),
);
2019-02-19 22:35:03 +08:00
fs.writeFileSync(path.join(cwd, 'site-dist/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-dist/components/${name}`,
// `site-dist/components/${name}-cn`,
`site-dist/iframe/${name}`,
// `site-dist/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-dist/index.html')),
);
});
});
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-dist/docs',
'site-dist/docs/vue',
`site-dist/docs/vue/${name}`,
`site-dist/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-dist/index.html')),
);
});
});
next();
}),
);
2018-04-04 18:39:21 +08:00
}
2019-01-12 11:33:27 +08:00
gulp.task('site-dist', done => {
2018-04-04 18:39:21 +08:00
dist(() => {
2019-01-12 11:33:27 +08:00
copyHtml();
});
});
2018-04-04 18:39:21 +08:00
gulp.task('copy-html', () => {
2019-01-12 11:33:27 +08:00
copyHtml();
});