🌈 An enterprise-class UI components based on Ant Design and Vue. 🐜
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.8 KiB

'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');
7 years ago
const rimraf = require('rimraf');
const mkdirp = require('mkdirp');
7 years ago
const cwd = process.cwd();
7 years ago
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'));
7 years ago
webpack(webpackConfig, (err, stats) => {
if (err) {
console.error(err.stack || err);
7 years ago
if (err.details) {
console.error(err.details);
7 years ago
}
return;
7 years ago
}
const info = stats.toJson();
7 years ago
if (stats.hasErrors()) {
console.error(info.errors);
7 years ago
}
if (stats.hasWarnings()) {
console.warn(info.warnings);
7 years ago
}
const buildInfo = stats.toString({
colors: true,
children: true,
chunks: false,
modules: false,
chunkModules: false,
hash: false,
version: false,
});
console.log(buildInfo);
done(0);
});
7 years ago
}
function copyHtml() {
7 years ago
const rl = readline.createInterface({
input: fs.createReadStream(path.join(cwd, 'site/demoRoutes.js')),
});
7 years ago
rl.on('line', line => {
if (line.indexOf('path:') > -1) {
const name = line.split("'")[1].split("'")[0];
console.log('create path:', name);
const toPaths = [
`site-dist/components/${name}`,
// `site-dist/components/${name}-cn`,
`site-dist/iframe/${name}`,
// `site-dist/iframe/${name}-cn`,
];
toPaths.forEach(toPath => {
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')),
);
});
});
}
});
7 years ago
const source = [
'docs/vue/*.md',
'*.md',
7 years ago
// '!components/vc-slider/**/*', // exclude vc-slider
];
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();
}),
);
7 years ago
}
gulp.task('site-dist', done => {
7 years ago
dist(() => {
copyHtml();
});
});
7 years ago
gulp.task('copy-html', () => {
copyHtml();
});