Repository navigation
Expand file tree
/
Copy pathdeploy.js
More file actions
49 lines (42 loc) · 1.35 KB
/
Copy pathdeploy.js
File metadata and controls
49 lines (42 loc) · 1.35 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
/**
* Conditional deployment script
* Only deploys to gh-pages when on the main branch
*/
const { execSync } = require('child_process');
const ghpages = require('gh-pages');
const path = require('path');
// Get the current branch name
function getCurrentBranch() {
try {
return execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
} catch (error) {
console.error('Error getting current branch:', error.message);
process.exit(1);
}
}
// Main function to handle deployment
function deploy() {
const currentBranch = getCurrentBranch();
console.log(`Current branch: ${currentBranch}`);
if (currentBranch === 'main') {
console.log('On main branch - proceeding with deployment to gh-pages...');
const distPath = path.join(__dirname, '..', 'dist');
ghpages.publish(distPath, {
branch: 'gh-pages',
message: 'Auto-deploy from main branch',
repo: 'https://github.com/sureshmurali/My-Portfolio.git',
}, (err) => {
if (err) {
console.error('Deployment failed:', err);
process.exit(1);
} else {
console.log('Successfully deployed to gh-pages!');
}
});
} else {
console.log('Not on main branch - skipping deployment to gh-pages');
console.log('To deploy, please switch to the main branch and run "yarn deploy"');
}
}
// Execute the deployment
deploy();