|
1 | 1 | /* eslint-disable @typescript-eslint/no-var-requires */
|
2 | 2 | const path = require('path');
|
| 3 | +const fs = require('fs'); |
| 4 | + |
| 5 | +const statics = ['CNAME']; |
| 6 | + |
| 7 | +exports.onPostBuild = ({ reporter }) => { |
| 8 | + function findRepoRoot(dir = process.cwd()) { |
| 9 | + const gitDir = path.join(dir, '.git'); |
| 10 | + |
| 11 | + if (fs.existsSync(gitDir)) { |
| 12 | + return dir; |
| 13 | + } |
| 14 | + |
| 15 | + const parentDir = path.dirname(dir); |
| 16 | + if (parentDir === dir) { |
| 17 | + return null; |
| 18 | + } |
| 19 | + |
| 20 | + return findRepoRoot(parentDir); |
| 21 | + } |
| 22 | + |
| 23 | + const root = findRepoRoot(); |
| 24 | + const dist = path.join(root, '.docz/dist'); |
| 25 | + |
| 26 | + console.dir({ root, dist }); |
| 27 | + for (const file of statics) { |
| 28 | + const src = path.resolve(root, file); |
| 29 | + const dest = path.resolve(dist, file); |
| 30 | + |
| 31 | + if (!fs.existsSync(src)) { |
| 32 | + reporter.info(`File ${file} not found`); |
| 33 | + continue; |
| 34 | + } |
| 35 | + |
| 36 | + fs.copyFileSync(src, dest); |
| 37 | + reporter.info(`Copied ${src} → ${dest}`); |
| 38 | + } |
| 39 | +}; |
3 | 40 |
|
4 | 41 | exports.onCreateWebpackConfig = ({ actions, stage, loaders }) => {
|
5 | 42 | if (stage === 'build-html' || stage === 'develop-html') {
|
|
0 commit comments