2018-04-04 10:39:21 +00:00
|
|
|
'use strict'
|
|
|
|
const webpack = require('webpack')
|
2018-04-10 05:37:06 +00:00
|
|
|
const through2 = require('through2')
|
2018-04-04 10:39:21 +00:00
|
|
|
const path = require('path')
|
|
|
|
const gulp = require('gulp')
|
|
|
|
const readline = require('readline')
|
|
|
|
const fs = require('fs')
|
|
|
|
|
|
|
|
const rimraf = require('rimraf')
|
|
|
|
const mkdirp = require('mkdirp')
|
|
|
|
|
|
|
|
const cwd = process.cwd()
|
|
|
|
|
|
|
|
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'))
|
|
|
|
webpack(webpackConfig, (err, stats) => {
|
|
|
|
if (err) {
|
|
|
|
console.error(err.stack || err)
|
|
|
|
if (err.details) {
|
|
|
|
console.error(err.details)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const info = stats.toJson()
|
|
|
|
|
|
|
|
if (stats.hasErrors()) {
|
|
|
|
console.error(info.errors)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stats.hasWarnings()) {
|
|
|
|
console.warn(info.warnings)
|
|
|
|
}
|
|
|
|
|
|
|
|
const buildInfo = stats.toString({
|
|
|
|
colors: true,
|
|
|
|
children: true,
|
|
|
|
chunks: false,
|
|
|
|
modules: false,
|
|
|
|
chunkModules: false,
|
|
|
|
hash: false,
|
|
|
|
version: false,
|
|
|
|
})
|
|
|
|
console.log(buildInfo)
|
|
|
|
done(0)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyHtml () {
|
|
|
|
const rl = readline.createInterface({
|
|
|
|
input: fs.createReadStream(path.join(cwd, 'site/demo.js')),
|
|
|
|
})
|
|
|
|
|
|
|
|
rl.on('line', (line) => {
|
|
|
|
const name = line.split('antd/')[1].split('/')[0]
|
|
|
|
console.log('create path:', name)
|
2018-04-20 09:07:41 +00:00
|
|
|
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')))
|
|
|
|
})
|
2018-04-04 10:39:21 +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
|
|
|
|
]
|
|
|
|
gulp.src(source).pipe(through2.obj(function z (file, encoding, next) {
|
|
|
|
const paths = file.path.split('/')
|
2018-04-21 11:01:52 +00:00
|
|
|
const name = paths[paths.length - 1].split('.')[0].toLowerCase()
|
2018-04-10 05:37:06 +00:00
|
|
|
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 10:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gulp.task('site-dist', (done) => {
|
|
|
|
dist(() => {
|
|
|
|
copyHtml()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
gulp.task('copy-html', () => {
|
|
|
|
copyHtml()
|
|
|
|
})
|
|
|
|
|