cpGHPages.ts 745 B

12345678910111213141516171819202122232425
  1. import * as createGit from 'simple-git/promise';
  2. import { resolve, join } from 'path';
  3. import { copyFileSync, readdirSync, statSync, unlinkSync } from 'fs';
  4. const baseDir = resolve(__dirname, '..');
  5. const to = (...paths: string[]) => join(baseDir, ...paths);
  6. const git = createGit();
  7. git.log({
  8. from: 'HEAD~1',
  9. to: 'HEAD'
  10. }).then(async log => {
  11. const hash = log.latest.hash.slice(0, 7);
  12. await git.checkout('gh-pages');
  13. for (const f of readdirSync(to('.'))) {
  14. if (statSync(f).isFile())
  15. unlinkSync(to(f));
  16. }
  17. const files = readdirSync(to('dist'))
  18. for (const f of files) {
  19. copyFileSync(to('dist', f), to(f));
  20. }
  21. await git.add(files);
  22. await git.commit('Build demo from ' + hash);
  23. await git.checkout('master');
  24. });