|
| 1 | +/* eslint-disable no-console */ |
| 2 | +const execa = require('execa'); |
| 3 | +const fs = require('fs'); |
| 4 | + |
| 5 | +(async () => { |
| 6 | + try { |
| 7 | + await execa('git', ['checkout', '--orphan', 'gh-pages']); |
| 8 | + // eslint-disable-next-line no-console |
| 9 | + console.log('Building started...'); |
| 10 | + await execa('npm', ['run', 'build']); |
| 11 | + // Understand if it's dist or build folder |
| 12 | + const folderName = fs.existsSync('dist') ? 'dist' : 'build'; |
| 13 | + await execa('git', ['--work-tree', folderName, 'add', '--all']); |
| 14 | + await execa('git', ['--work-tree', folderName, 'commit', '-m', 'gh-pages']); |
| 15 | + console.log('Pushing to gh-pages...'); |
| 16 | + await execa('git', ['push', 'origin', 'HEAD:gh-pages', '--force']); |
| 17 | + await execa('rm', ['-r', folderName]); |
| 18 | + await execa('git', ['checkout', '-f', 'master']); |
| 19 | + await execa('git', ['branch', '-D', 'gh-pages']); |
| 20 | + console.log('Successfully deployed, check your settings'); |
| 21 | + } catch (e) { |
| 22 | + // eslint-disable-next-line no-console |
| 23 | + console.log(e.message); |
| 24 | + process.exit(1); |
| 25 | + } |
| 26 | +})(); |
0 commit comments