|
|
const fs = require('fs'); |
|
|
const path = require('path'); |
|
|
const { execSync } = require('child_process'); |
|
|
|
|
|
const configPath = path.join(__dirname, '../config/config.ts'); |
|
|
const backupPath = path.join(__dirname, '../config/config.ts.backup'); |
|
|
|
|
|
|
|
|
fs.copyFileSync(configPath, backupPath); |
|
|
|
|
|
try { |
|
|
|
|
|
let config = fs.readFileSync(configPath, 'utf8'); |
|
|
|
|
|
|
|
|
config = config.replace(/publicPath: ['"].*['"],/, "publicPath: '/hooks/',"); |
|
|
config = config.replace( |
|
|
/{ rel: 'stylesheet', href: '\/style\.css' }/, |
|
|
"{ rel: 'stylesheet', href: '/hooks/style.css' }", |
|
|
); |
|
|
config = config.replace(/logo: '\/logo\.svg',/, "logo: '/hooks/logo.svg',"); |
|
|
|
|
|
|
|
|
fs.writeFileSync(configPath, config); |
|
|
|
|
|
|
|
|
execSync('pnpm run build:doc', { stdio: 'inherit' }); |
|
|
|
|
|
|
|
|
process.chdir(path.join(__dirname, '../dist')); |
|
|
|
|
|
|
|
|
try { |
|
|
execSync('git init', { stdio: 'inherit' }); |
|
|
} catch (e) { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
execSync('git add .', { stdio: 'inherit' }); |
|
|
|
|
|
|
|
|
execSync('git commit -m "chore: update gh-pages"', { stdio: 'inherit' }); |
|
|
|
|
|
|
|
|
try { |
|
|
execSync('git remote add origin git@github.com:alibaba/hooks.git', { stdio: 'inherit' }); |
|
|
} catch (e) { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
execSync('git push -f origin HEAD:gh-pages', { stdio: 'inherit' }); |
|
|
|
|
|
|
|
|
process.chdir(path.join(__dirname, '..')); |
|
|
} finally { |
|
|
|
|
|
fs.copyFileSync(backupPath, configPath); |
|
|
fs.unlinkSync(backupPath); |
|
|
} |
|
|
|