Repository navigation
Expand file tree
/
Copy pathdeploy.js
More file actions
181 lines (156 loc) · 5.18 KB
/
Copy pathdeploy.js
File metadata and controls
181 lines (156 loc) · 5.18 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env node
/**
* GiftEase Deployment Script
* This script helps automate the deployment process to GitHub and Vercel
*/
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
// Colors for console output
const colors = {
reset: '\x1b[0m',
bright: '\x1b[1m',
dim: '\x1b[2m',
underscore: '\x1b[4m',
blink: '\x1b[5m',
reverse: '\x1b[7m',
hidden: '\x1b[8m',
fg: {
black: '\x1b[30m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m',
white: '\x1b[37m'
}
};
// Utility functions
const log = (message, color = colors.fg.white) => {
console.log(`${color}${message}${colors.reset}`);
};
const error = (message) => {
console.error(`${colors.fg.red}Error: ${message}${colors.reset}`);
};
const success = (message) => {
console.log(`${colors.fg.green}✓ ${message}${colors.reset}`);
};
const warning = (message) => {
console.warn(`${colors.fg.yellow}⚠ ${message}${colors.reset}`);
};
const info = (message) => {
console.log(`${colors.fg.cyan}ℹ ${message}${colors.reset}`);
};
// Check if we're in the right directory
const checkDirectory = () => {
const requiredFiles = ['package.json', 'index.html', 'vite.config.js'];
const missingFiles = requiredFiles.filter(file => !fs.existsSync(file));
if (missingFiles.length > 0) {
error(`Missing required files: ${missingFiles.join(', ')}`);
error('Please run this script from the project root directory');
process.exit(1);
}
success('Directory check passed');
};
// Check if Git is installed
const checkGit = () => {
try {
execSync('git --version', { stdio: 'ignore' });
success('Git is installed');
return true;
} catch (err) {
error('Git is not installed or not in PATH');
return false;
}
};
// Check if Node.js and npm are installed
const checkNodeAndNpm = () => {
try {
const nodeVersion = execSync('node --version', { encoding: 'utf8' }).trim();
const npmVersion = execSync('npm --version', { encoding: 'utf8' }).trim();
success(`Node.js ${nodeVersion} and npm ${npmVersion} are installed`);
return true;
} catch (err) {
error('Node.js or npm is not installed or not in PATH');
return false;
}
};
// Initialize Git repository if not already done
const initGit = () => {
try {
// Check if already a Git repository
execSync('git status', { stdio: 'ignore' });
info('Git repository already initialized');
return true;
} catch (err) {
// Not a Git repository, initialize it
try {
execSync('git init', { stdio: 'ignore' });
success('Git repository initialized');
return true;
} catch (initErr) {
error('Failed to initialize Git repository');
return false;
}
}
};
// Add all files and commit if needed
const commitChanges = () => {
try {
// Check if there are any changes to commit
const status = execSync('git status --porcelain', { encoding: 'utf8' });
if (status.trim() !== '') {
execSync('git add .', { stdio: 'ignore' });
execSync('git commit -m "Automated deployment commit"', { stdio: 'ignore' });
success('Changes committed');
} else {
info('No changes to commit');
}
return true;
} catch (err) {
error('Failed to commit changes');
return false;
}
};
// Main deployment function
const deploy = async () => {
log('🚀 Starting GiftEase Deployment Process', colors.fg.cyan);
log('=====================================', colors.fg.cyan);
// Check prerequisites
checkDirectory();
if (!checkGit() || !checkNodeAndNpm()) {
error('Prerequisites not met. Please install required tools.');
process.exit(1);
}
// Initialize Git if needed
if (!initGit()) {
process.exit(1);
}
// Commit any changes
if (!commitChanges()) {
process.exit(1);
}
log('\n📋 Deployment Instructions:', colors.fg.yellow);
log('1. Create a new repository on GitHub at https://github.com/new', colors.fg.white);
log('2. Name it "gift-ease" and click "Create repository"', colors.fg.white);
log('3. Copy the repository URL (looks like https://github.com/YOUR_USERNAME/gift-ease.git)', colors.fg.white);
log('4. Run the following commands:', colors.fg.white);
log(' git remote add origin YOUR_REPOSITORY_URL', colors.fg.blue);
log(' git push -u origin main', colors.fg.blue);
log('5. Go to https://vercel.com/ and sign in with GitHub', colors.fg.white);
log('6. Click "New Project" and import your gift-ease repository', colors.fg.white);
log('7. Configure with these settings:', colors.fg.white);
log(' - Framework Preset: Vite', colors.fg.blue);
log(' - Build Command: npm run build', colors.fg.blue);
log(' - Output Directory: dist', colors.fg.blue);
log('8. Click "Deploy" and wait for deployment to complete', colors.fg.white);
log('\n✅ Deployment preparation complete!', colors.fg.green);
log('The project is ready for deployment to GitHub and Vercel.', colors.fg.green);
log('Follow the instructions above to complete the process.', colors.fg.green);
};
// Run deployment
deploy().catch(err => {
error(`Deployment failed: ${err.message}`);
process.exit(1);
});