@hynaweb/stage 1.0.1 ā 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +61 -16
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -4,16 +4,27 @@ const fs = require('fs');
|
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const readline = require('readline');
|
|
6
6
|
|
|
7
|
-
// Points to your new Edge Function
|
|
8
7
|
const API_URL = 'https://mczesspakhkomlnmfstw.supabase.co/functions/v1/deploy-stage';
|
|
8
|
+
const DESTROY_URL = 'https://mczesspakhkomlnmfstw.supabase.co/functions/v1/destroy-stage';
|
|
9
9
|
const SUPABASE_KEY = 'sb_publishable_sG0q8k6txKHOihBduyr67w_UKfolcvj';
|
|
10
10
|
|
|
11
11
|
const configPath = path.join(require('os').homedir(), '.hyna-stage');
|
|
12
12
|
|
|
13
13
|
async function getApiKey() {
|
|
14
|
+
// Check for --key argument first (Auto-Injection)
|
|
15
|
+
const keyArg = process.argv.find(arg => arg.startsWith('--key='));
|
|
16
|
+
if (keyArg) {
|
|
17
|
+
const key = keyArg.split('=')[1];
|
|
18
|
+
fs.writeFileSync(configPath, key.trim()); // Save it for next time
|
|
19
|
+
return key.trim();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Check cache
|
|
14
23
|
if (fs.existsSync(configPath)) {
|
|
15
24
|
return fs.readFileSync(configPath, 'utf8').trim();
|
|
16
25
|
}
|
|
26
|
+
|
|
27
|
+
// Otherwise prompt
|
|
17
28
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
18
29
|
return new Promise((resolve) => {
|
|
19
30
|
rl.question('š Enter your HYNA-Stage API Key: ', (key) => {
|
|
@@ -25,27 +36,61 @@ async function getApiKey() {
|
|
|
25
36
|
}
|
|
26
37
|
|
|
27
38
|
async function main() {
|
|
28
|
-
|
|
39
|
+
const command = process.argv[2];
|
|
29
40
|
const apiKey = await getApiKey();
|
|
30
41
|
|
|
31
|
-
|
|
42
|
+
if (command === 'up') {
|
|
43
|
+
console.log('š Initializing HYNA-Stage...');
|
|
32
44
|
console.log('š¦ Spinning up cloud environment...');
|
|
33
45
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
try {
|
|
47
|
+
const res = await axios.post(API_URL, {}, {
|
|
48
|
+
headers: {
|
|
49
|
+
'Authorization': 'Bearer ' + apiKey,
|
|
50
|
+
'apikey': SUPABASE_KEY,
|
|
51
|
+
'Content-Type': 'application/json'
|
|
52
|
+
}
|
|
53
|
+
});
|
|
41
54
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
console.log('\nā
Environment is LIVE!');
|
|
56
|
+
console.log('š URL: \x1b[36m' + res.data.url + '\x1b[0m');
|
|
57
|
+
console.log('š Sandbox ID: ' + res.data.sandbox_id);
|
|
58
|
+
console.log('ā±ļø Auto-destruct in: 1 hour\n');
|
|
59
|
+
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.error('ā Error:', err.response?.data?.error || err.message);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (command === 'down') {
|
|
65
|
+
const sandboxId = process.argv.find(arg => !arg.startsWith('--') && arg !== 'down' && arg !== 'up');
|
|
66
|
+
|
|
67
|
+
if (!sandboxId) {
|
|
68
|
+
console.error('ā Please provide a sandbox ID: hyna-stage down <sandbox_id>');
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
46
71
|
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
console.log('šļø Destroying sandbox ' + sandboxId + '...');
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
await axios.post(DESTROY_URL, { sandbox_id: sandboxId }, {
|
|
76
|
+
headers: {
|
|
77
|
+
'Authorization': 'Bearer ' + apiKey,
|
|
78
|
+
'apikey': SUPABASE_KEY,
|
|
79
|
+
'Content-Type': 'application/json'
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
console.log('\nā
Environment destroyed successfully.\n');
|
|
84
|
+
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error('ā Error:', err.response?.data?.error || err.message);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
console.log('Usage:');
|
|
91
|
+
console.log(' hyna-stage up Spin up a new environment');
|
|
92
|
+
console.log(' hyna-stage down <id> Destroy a specific environment');
|
|
49
93
|
}
|
|
50
94
|
}
|
|
95
|
+
|
|
51
96
|
main();
|