This repository was archived by the owner on Mar 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
59 lines (49 loc) · 1.97 KB
/
deploy.js
File metadata and controls
59 lines (49 loc) · 1.97 KB
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
50
51
52
53
54
55
56
57
58
59
import { execSync } from 'child_process';
import { existsSync, rmSync, cpSync } from 'fs';
import { join } from 'path';
const distDir = 'dist';
const deployDir = '.gh-pages-deploy';
try {
// Clean up any existing deploy directory
if (existsSync(deployDir)) {
rmSync(deployDir, { recursive: true, force: true });
}
// Get the remote URL
const remoteUrl = execSync('git remote get-url origin', { encoding: 'utf-8' }).trim();
// Clone the gh-pages branch (or create new)
console.log('Setting up gh-pages branch...');
try {
execSync(`git clone --branch gh-pages --single-branch --depth 1 ${remoteUrl} ${deployDir}`, { stdio: 'inherit' });
} catch {
// Branch doesn't exist, create a new orphan branch
execSync(`git clone --depth 1 ${remoteUrl} ${deployDir}`, { stdio: 'inherit' });
process.chdir(deployDir);
execSync('git checkout --orphan gh-pages', { stdio: 'inherit' });
execSync('git rm -rf .', { stdio: 'inherit' });
process.chdir('..');
}
// Clear existing files in deploy dir (except .git)
console.log('Clearing old files...');
const deployGitDir = join(deployDir, '.git');
execSync(`Get-ChildItem -Path "${deployDir}" -Exclude ".git" | Remove-Item -Recurse -Force`, { shell: 'powershell', stdio: 'inherit' });
// Copy dist contents to deploy directory
console.log('Copying new files...');
cpSync(distDir, deployDir, { recursive: true });
// Commit and push
console.log('Committing and pushing...');
process.chdir(deployDir);
execSync('git add -A', { stdio: 'inherit' });
try {
execSync('git commit -m "Deploy to gh-pages"', { stdio: 'inherit' });
execSync('git push origin gh-pages --force', { stdio: 'inherit' });
console.log('Deployed successfully!');
} catch (e) {
console.log('No changes to deploy or push failed');
}
// Cleanup
process.chdir('..');
rmSync(deployDir, { recursive: true, force: true });
} catch (error) {
console.error('Deploy failed:', error.message);
process.exit(1);
}