gulpfile.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. 'use strict';
  2. const webpack = require('webpack');
  3. const through2 = require('through2');
  4. const path = require('path');
  5. const gulp = require('gulp');
  6. const readline = require('readline');
  7. const fs = require('fs');
  8. const rimraf = require('rimraf');
  9. const mkdirp = require('mkdirp');
  10. const cwd = process.cwd();
  11. function dist(done) {
  12. rimraf.sync(path.join(cwd, '_site'));
  13. process.env.RUN_ENV = 'PRODUCTION';
  14. const webpackConfig = require(path.join(cwd, 'build/webpack.site.conf.js'));
  15. webpack(webpackConfig, (err, stats) => {
  16. if (err) {
  17. console.error(err.stack || err);
  18. if (err.details) {
  19. console.error(err.details);
  20. }
  21. return;
  22. }
  23. const info = stats.toJson();
  24. if (stats.hasErrors()) {
  25. console.error(info.errors);
  26. }
  27. if (stats.hasWarnings()) {
  28. console.warn(info.warnings);
  29. }
  30. const buildInfo = stats.toString({
  31. colors: true,
  32. children: true,
  33. chunks: false,
  34. modules: false,
  35. chunkModules: false,
  36. hash: false,
  37. version: false,
  38. });
  39. console.log(buildInfo);
  40. done(0);
  41. });
  42. }
  43. function copyHtml() {
  44. const rl = readline.createInterface({
  45. input: fs.createReadStream(path.join(cwd, 'site/demoRoutes.js')),
  46. });
  47. fs.writeFileSync(
  48. path.join(cwd, '_site/404.html'),
  49. fs.readFileSync(path.join(cwd, 'site/404.html')),
  50. );
  51. fs.writeFileSync(
  52. path.join(cwd, '_site/index-cn.html'),
  53. fs.readFileSync(path.join(cwd, '_site/index.html')),
  54. );
  55. fs.writeFileSync(path.join(cwd, '_site/CNAME'), 'vue.ant.design');
  56. rl.on('line', line => {
  57. if (line.indexOf('path:') > -1) {
  58. const name = line.split("'")[1].split("'")[0];
  59. console.log('create path:', name);
  60. const toPaths = [
  61. `_site/components/${name}`,
  62. // `_site/components/${name}-cn`,
  63. `_site/iframe/${name}`,
  64. // `_site/iframe/${name}-cn`,
  65. ];
  66. toPaths.forEach(toPath => {
  67. rimraf.sync(path.join(cwd, toPath));
  68. mkdirp(path.join(cwd, toPath), function() {
  69. fs.writeFileSync(
  70. path.join(cwd, `${toPath}/index.html`),
  71. fs.readFileSync(path.join(cwd, '_site/index.html')),
  72. );
  73. });
  74. });
  75. }
  76. });
  77. const source = [
  78. 'docs/vue/*.md',
  79. '*.md',
  80. // '!components/vc-slider/**/*', // exclude vc-slider
  81. ];
  82. gulp.src(source).pipe(
  83. through2.obj(function z(file, encoding, next) {
  84. const paths = file.path.split('/');
  85. const name = paths[paths.length - 1].split('.')[0].toLowerCase();
  86. const toPaths = [
  87. '_site/docs',
  88. '_site/docs/vue',
  89. `_site/docs/vue/${name}`,
  90. `_site/docs/vue/${name}-cn`,
  91. ];
  92. toPaths.forEach(toPath => {
  93. mkdirp(path.join(cwd, toPath), function() {
  94. fs.writeFileSync(
  95. path.join(cwd, `${toPath}/index.html`),
  96. fs.readFileSync(path.join(cwd, '_site/index.html')),
  97. );
  98. });
  99. });
  100. next();
  101. }),
  102. );
  103. }
  104. gulp.task(
  105. '_site',
  106. gulp.series(done => {
  107. dist(() => {
  108. copyHtml();
  109. done();
  110. });
  111. }),
  112. );
  113. gulp.task(
  114. 'copy-html',
  115. gulp.series(() => {
  116. copyHtml();
  117. }),
  118. );