summaryrefslogtreecommitdiff
path: root/scripts/cpGHPages.ts
blob: b820c80604b4f571ec94e1679c60f2cfcc4a9863 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import * as createGit from 'simple-git/promise';
import { resolve, join } from 'path';
import { copyFileSync, readdirSync, statSync, unlinkSync } from 'fs';

const baseDir = resolve(__dirname, '..');
const to = (...paths: string[]) => join(baseDir, ...paths);
const git = createGit();
git.log({
  from: 'HEAD~1',
  to: 'HEAD'
}).then(async log => {
  const hash = log.latest.hash.slice(0, 7);
  await git.checkout('gh-pages');
  for (const f of readdirSync(to('.'))) {
    if (statSync(f).isFile())
      unlinkSync(to(f));
  }
  const files = readdirSync(to('dist'))
  for (const f of files) {
    copyFileSync(to('dist', f), to(f));
  }
  await git.add(files);
  await git.commit('Build demo from ' + hash);
  await git.checkout('master');
});