-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch-github-repo.ts
49 lines (39 loc) · 1.44 KB
/
fetch-github-repo.ts
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Octokit } from "@octokit/rest";
import * as fs from 'fs-extra';
import * as path from 'path';
import * as shell from 'shelljs';
async function fetchGitHubRepo() {
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
const owner = 'JiaHongL';
const repo = 'ng-chat-app';
try {
const { data } = await octokit.repos.get({ owner, repo });
const repoUrl = data.clone_url;
const repoDir = path.join(__dirname, 'temp-repo');
if (fs.existsSync(repoDir)) {
shell.rm('-rf', repoDir);
}
shell.exec(`git clone ${repoUrl} ${repoDir}`);
const angularProjectDir = path.join(repoDir, '');
if (!fs.existsSync(path.join(angularProjectDir, 'angular.json'))) {
throw new Error('Angular project not found in the specified directory');
}
shell.cd(angularProjectDir);
shell.exec('npm install');
shell.exec('npx ng build --configuration production');
const distDir = path.join(angularProjectDir, 'dist/ng-chat-app/browser');
const publicDir = path.join(__dirname, 'dist/public');
if (!fs.existsSync(distDir)) {
throw new Error('Build output directory not found');
}
fs.copySync(distDir, publicDir, { overwrite: true });
console.log(`Build output copied to ${publicDir}`);
} catch (error) {
console.error('Error fetching the GitHub repo:', error);
}
}
// 確保腳本能獨立運行
if (require.main === module) {
fetchGitHubRepo();
}
export { fetchGitHubRepo };