gh-pages-deploy.js (25 lines of code) (raw):

/* eslint-disable no-console */ const execa = require('execa'); const rimraf = require('rimraf'); const fs = require('fs'); (async () => { try { await execa('git', ['checkout', '--orphan', 'gh-pages']); // eslint-disable-next-line no-console console.log('Building started...'); await execa('npm', ['run', 'build']); // await execa("yarn", ["build"]); // Understand if it's dist or build folder const folderName = fs.existsSync('dist') ? 'dist' : 'build'; fs.writeFile(folderName + '/CNAME', 'clocks.lab.epam.com', {}, function (err) {}); await execa('git', ['--work-tree', folderName, 'add', '--all']); await execa('git', ['--work-tree', folderName, 'commit', '-m', 'gh-pages']); console.log('Pushing to gh-pages...'); await execa('git', ['push', 'origin', 'HEAD:gh-pages', '--force']); await rimraf('./' + folderName, () => { console.log(folderName + ' folder successfully deleted'); }); await execa('git', ['checkout', '-f', 'main']); await execa('git', ['branch', '-D', 'gh-pages']); console.log('Successfully deployed'); } catch (e) { // eslint-disable-next-line no-console console.log(e.message); process.exit(1); } })();