forked from PogungDev/coreliquid-master
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-vercel-deployment.js
More file actions
355 lines (292 loc) Β· 11.2 KB
/
setup-vercel-deployment.js
File metadata and controls
355 lines (292 loc) Β· 11.2 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/usr/bin/env node
/**
* CoreLiquid Vercel Deployment Setup Script
* Mempersiapkan semua kebutuhan untuk deployment ke Vercel
*/
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
class VercelSetup {
constructor() {
this.projectRoot = __dirname;
this.envPath = path.join(__dirname, '.env');
this.envLocalPath = path.join(__dirname, '.env.local');
this.envExamplePath = path.join(__dirname, '.env.example');
this.targetBranch = 'implementation';
}
printHeader() {
console.log('\nπ ===== CoreLiquid Vercel Setup =====');
console.log('π― Mempersiapkan deployment untuk Hackathon Core Connect');
console.log('πΏ Target branch: implementation\n');
}
async checkPrerequisites() {
console.log('π Checking Prerequisites...');
// Check Git
try {
execSync('git --version', { stdio: 'pipe' });
console.log('β
Git installed');
} catch (error) {
throw new Error('β Git not installed! Please install Git first.');
}
// Check Node.js
try {
const nodeVersion = execSync('node --version', { encoding: 'utf8' }).trim();
console.log(`β
Node.js ${nodeVersion}`);
} catch (error) {
throw new Error('β Node.js not installed!');
}
// Check npm
try {
const npmVersion = execSync('npm --version', { encoding: 'utf8' }).trim();
console.log(`β
npm ${npmVersion}`);
} catch (error) {
throw new Error('β npm not installed!');
}
// Check if in git repository
try {
execSync('git status', { stdio: 'pipe', cwd: this.projectRoot });
console.log('β
Git repository detected');
} catch (error) {
throw new Error('β Not in a git repository!');
}
console.log('\n');
}
async setupWalletConnect() {
console.log('π WalletConnect Setup');
console.log('\nπ LANGKAH-LANGKAH:');
console.log('1. Buka https://cloud.walletconnect.com/');
console.log('2. Buat akun baru atau login');
console.log('3. Klik "Create Project"');
console.log('4. Isi nama project: "CoreLiquid Protocol"');
console.log('5. Copy Project ID yang diberikan\n');
return new Promise((resolve) => {
rl.question('π Paste WalletConnect Project ID: ', (projectId) => {
if (!projectId || projectId.length < 10) {
console.log('β Invalid Project ID!');
process.exit(1);
}
console.log('β
WalletConnect Project ID saved');
resolve(projectId);
});
});
}
createEnvironmentFiles(walletConnectId) {
console.log('\nπ Creating Environment Files...');
const envContent = `# CoreLiquid Protocol Environment Variables
# Generated by setup-vercel-deployment.js
# ===========================================
# CRITICAL: WalletConnect Configuration
# ===========================================
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=${walletConnectId}
# ===========================================
# Core Blockchain Configuration
# ===========================================
NEXT_PUBLIC_ENVIRONMENT=testnet
NEXT_PUBLIC_CORE_RPC_URL=https://rpc.test2.btcs.network
NEXT_PUBLIC_CORE_CHAIN_ID=1114
NEXT_PUBLIC_CORE_MAINNET_RPC_URL=https://rpc.coredao.org
NEXT_PUBLIC_CORE_MAINNET_CHAIN_ID=1116
NEXT_PUBLIC_CORE_WS_URL=wss://ws.coredao.org
# ===========================================
# Contract Addresses (Real Deployed)
# ===========================================
# Core Tokens
NEXT_PUBLIC_CORE_LIQUID_TOKEN=0xcAc1f956DE2B60059971cC8CeE12aC11B5295E0a
NEXT_PUBLIC_BTC_TOKEN=0xC515E6030cC331Be138E9FE011ce23dd6eA0c9d6
NEXT_PUBLIC_CORE_LIQUID_POOL=0x1234567890123456789012345678901234567890
# TULL (True Unified Liquidity Layer)
NEXT_PUBLIC_SIMPLE_TULL_ADDRESS=0x0B306BF915C4d645ff596e518fAf3F9669b97016
NEXT_PUBLIC_OPTIMIZED_TULL_ADDRESS=0xc6e7DF5E7b4f2A278906862b61205850344D4e7d
# Core Native Staking
NEXT_PUBLIC_CORE_NATIVE_STAKING_ADDRESS=0xDB8cFf278adCCF9E9b5da745B44E754fC4EE3C76
NEXT_PUBLIC_STCORE_TOKEN_ADDRESS=0xBb2180ebd78ce97360503434eD37fcf4a1Df61c3
# Unified Liquidity Pool
NEXT_PUBLIC_UNIFIED_LIQUIDITY_POOL_ADDRESS=0x50EEf481cae4250d252Ae577A09bF514f224C6C4
NEXT_PUBLIC_UNIFIED_LP_TOKEN_ADDRESS=0x62c20Aa1e0272312BC100b4e23B4DC1Ed96dD7D1
# Protocol Components
NEXT_PUBLIC_REVENUE_MODEL_ADDRESS=0xDEb1E9a6Be7Baf84208BB6E10aC9F9bbE1D70809
NEXT_PUBLIC_RISK_ENGINE_ADDRESS=0xD718d5A27a29FF1cD22403426084bA0d479869a0
NEXT_PUBLIC_DEPOSIT_MANAGER_ADDRESS=0x4f559F30f5eB88D635FDe1548C4267DB8FaB0351
NEXT_PUBLIC_CREDIT_MANAGER_ADDRESS=0x416C42991d05b31E9A6dC209e91AD22b79D87Ae6
NEXT_PUBLIC_CORE_LIQUID_PROTOCOL_ADDRESS=0x978e3286EB805934215a88694d80b09aDed68D90
NEXT_PUBLIC_APR_OPTIMIZER_ADDRESS=0xd21060559c9beb54fC07aFd6151aDf6cFCDDCAeB
NEXT_PUBLIC_POSITION_NFT_ADDRESS=0x4C52a6277b1B84121b3072C0c92b6Be0b7CC10F1
# ===========================================
# App Configuration
# ===========================================
NEXT_PUBLIC_APP_NAME=CoreLiquid Protocol
NEXT_PUBLIC_ENABLE_TESTNET=true
# ===========================================
# Development (Optional)
# ===========================================
# PRIVATE_KEY=your_private_key_for_development_only
# TREASURY_ADDRESS=your_treasury_address
# GOVERNANCE_ADDRESS=your_governance_address
`;
// Create .env.local for local development
fs.writeFileSync(this.envLocalPath, envContent);
console.log('β
.env.local created for local development');
// Update .env if exists, or create new one
if (fs.existsSync(this.envPath)) {
let existingEnv = fs.readFileSync(this.envPath, 'utf8');
// Update WalletConnect ID
if (existingEnv.includes('NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=')) {
existingEnv = existingEnv.replace(
/NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=.*/,
`NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=${walletConnectId}`
);
} else {
existingEnv += `\nNEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=${walletConnectId}\n`;
}
fs.writeFileSync(this.envPath, existingEnv);
console.log('β
.env updated with WalletConnect ID');
} else {
fs.writeFileSync(this.envPath, envContent);
console.log('β
.env created');
}
}
checkGitStatus() {
console.log('\nπΏ Checking Git Status...');
try {
const currentBranch = execSync('git branch --show-current', {
encoding: 'utf8',
cwd: this.projectRoot
}).trim();
console.log(`π Current branch: ${currentBranch}`);
if (currentBranch !== this.targetBranch) {
console.log(`π Need to switch to ${this.targetBranch} branch`);
return false;
}
console.log(`β
Already on ${this.targetBranch} branch`);
return true;
} catch (error) {
console.log('β Error checking git status:', error.message);
return false;
}
}
setupGitBranch() {
console.log(`\nπΏ Setting up ${this.targetBranch} branch...`);
try {
// Check if branch exists
try {
execSync(`git show-ref --verify --quiet refs/heads/${this.targetBranch}`, {
stdio: 'pipe',
cwd: this.projectRoot
});
// Branch exists, switch to it
console.log(`π Switching to existing ${this.targetBranch} branch...`);
execSync(`git checkout ${this.targetBranch}`, {
stdio: 'inherit',
cwd: this.projectRoot
});
} catch (error) {
// Branch doesn't exist, create it
console.log(`π Creating new ${this.targetBranch} branch...`);
execSync(`git checkout -b ${this.targetBranch}`, {
stdio: 'inherit',
cwd: this.projectRoot
});
}
console.log(`β
Successfully on ${this.targetBranch} branch`);
} catch (error) {
console.log('β Error setting up git branch:', error.message);
throw error;
}
}
testBuild() {
console.log('\nπ¨ Testing Build...');
try {
console.log('π¦ Installing dependencies...');
execSync('npm install', { stdio: 'inherit', cwd: this.projectRoot });
console.log('ποΈ Testing build...');
execSync('npm run build', { stdio: 'inherit', cwd: this.projectRoot });
console.log('β
Build successful!');
} catch (error) {
console.log('β Build failed!');
console.log('π‘ Please fix build errors before deploying to Vercel');
throw error;
}
}
commitChanges() {
console.log('\nπ Committing Changes...');
try {
// Add files
execSync('git add .', { cwd: this.projectRoot });
// Check if there are changes to commit
try {
execSync('git diff --cached --exit-code', { stdio: 'pipe', cwd: this.projectRoot });
console.log('βΉοΈ No changes to commit');
return;
} catch (error) {
// There are changes to commit
}
// Commit
execSync('git commit -m "feat: setup vercel deployment configuration"', {
stdio: 'inherit',
cwd: this.projectRoot
});
console.log('β
Changes committed');
} catch (error) {
console.log('β οΈ Could not commit changes:', error.message);
}
}
pushToRemote() {
console.log('\nπ Pushing to Remote...');
try {
execSync(`git push origin ${this.targetBranch}`, {
stdio: 'inherit',
cwd: this.projectRoot
});
console.log('β
Pushed to remote repository');
} catch (error) {
console.log('β οΈ Could not push to remote:', error.message);
console.log('π‘ You may need to push manually later');
}
}
printNextSteps() {
console.log('\nπ― ===== NEXT STEPS =====');
console.log('\n1. π Buka https://vercel.com dan login');
console.log('2. π Klik "Add New..." β "Project"');
console.log('3. π Import repository GitHub Anda');
console.log('4. βοΈ Configure project:');
console.log(' - Project Name: coreliquid-protocol');
console.log(' - Framework: Next.js');
console.log(` - Production Branch: ${this.targetBranch}`);
console.log('\n5. π§ Add Environment Variables di Vercel:');
console.log(' - Copy semua variables dari .env.local');
console.log(' - Set untuk Production, Preview, dan Development');
console.log('\n6. π Deploy!');
console.log('\nπ Baca VERCEL_DEPLOYMENT_MANUAL.md untuk panduan lengkap');
console.log('\nβ¨ Good luck dengan hackathon! π');
}
async run() {
try {
this.printHeader();
await this.checkPrerequisites();
const walletConnectId = await this.setupWalletConnect();
this.createEnvironmentFiles(walletConnectId);
if (!this.checkGitStatus()) {
this.setupGitBranch();
}
this.testBuild();
this.commitChanges();
this.pushToRemote();
this.printNextSteps();
} catch (error) {
console.log('\nβ Setup failed:', error.message);
process.exit(1);
} finally {
rl.close();
}
}
}
if (require.main === module) {
const setup = new VercelSetup();
setup.run();
}
module.exports = VercelSetup;