moontraze 1.0.0 → 1.0.1
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/lib/deploy.js +41 -9
- package/package.json +1 -1
package/lib/deploy.js
CHANGED
|
@@ -14,7 +14,10 @@ async function deploy({ prod = true, projectName } = {}) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const linked = getProject();
|
|
17
|
-
const name = (projectName || linked?.projectName || '')
|
|
17
|
+
const name = (projectName || linked?.projectName || '')
|
|
18
|
+
.toLowerCase()
|
|
19
|
+
.replace(/[^a-z0-9-]/g, '');
|
|
20
|
+
|
|
18
21
|
if (!name || name.length < 3) {
|
|
19
22
|
throw new Error('No project linked. Run: npx moontraze link my-site');
|
|
20
23
|
}
|
|
@@ -24,28 +27,54 @@ async function deploy({ prod = true, projectName } = {}) {
|
|
|
24
27
|
|
|
25
28
|
console.log('');
|
|
26
29
|
console.log(chalk.cyan('Moontraze'));
|
|
27
|
-
console.log(`
|
|
28
|
-
console.log(`
|
|
29
|
-
console.log(`
|
|
30
|
+
console.log(` Inspect ${api}`);
|
|
31
|
+
console.log(` Project ${name}`);
|
|
32
|
+
console.log(` Target https://${name}.${domain}`);
|
|
30
33
|
console.log('');
|
|
31
34
|
|
|
32
35
|
const spinner = ora('Packaging...').start();
|
|
33
36
|
const t0 = Date.now();
|
|
34
37
|
let zipPath;
|
|
38
|
+
|
|
35
39
|
try {
|
|
36
40
|
zipPath = await zipCwd();
|
|
37
41
|
const mb = (fs.statSync(zipPath).size / 1024 / 1024).toFixed(2);
|
|
42
|
+
spinner.text = `Checking project...`;
|
|
43
|
+
|
|
44
|
+
// 1. Pehle check karo project already exist karta hai ya nahi
|
|
45
|
+
let alreadyExists = false;
|
|
46
|
+
try {
|
|
47
|
+
const statusRes = await fetch(`${api}/api/hosting/status/${name}`, {
|
|
48
|
+
headers: { Authorization: `Bearer ${cfg.token}` },
|
|
49
|
+
});
|
|
50
|
+
if (statusRes.ok) {
|
|
51
|
+
const statusData = await statusRes.json();
|
|
52
|
+
alreadyExists = !!statusData.exists;
|
|
53
|
+
}
|
|
54
|
+
} catch (_) {
|
|
55
|
+
// status fail → assume new
|
|
56
|
+
}
|
|
57
|
+
|
|
38
58
|
spinner.text = `Uploading (${mb} MB)...`;
|
|
39
59
|
|
|
40
60
|
const form = new FormData();
|
|
41
61
|
form.append('projectName', name);
|
|
42
|
-
form.append('redeploy', prod ? 'true' : 'true'); // always overwrite for existing
|
|
43
62
|
form.append('file', fs.createReadStream(zipPath), {
|
|
44
63
|
filename: `${name}.zip`,
|
|
45
64
|
contentType: 'application/zip',
|
|
46
65
|
});
|
|
47
66
|
|
|
48
|
-
|
|
67
|
+
// 2. Exist karta hai to /redeploy, nahi to /deploy
|
|
68
|
+
const endpoint = alreadyExists
|
|
69
|
+
? `${api}/api/hosting/redeploy`
|
|
70
|
+
: `${api}/api/hosting/deploy`;
|
|
71
|
+
|
|
72
|
+
// /deploy pe redeploy flag bhejo (safety)
|
|
73
|
+
if (!alreadyExists) {
|
|
74
|
+
form.append('redeploy', 'false');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const res = await fetch(endpoint, {
|
|
49
78
|
method: 'POST',
|
|
50
79
|
headers: {
|
|
51
80
|
Authorization: `Bearer ${cfg.token}`,
|
|
@@ -71,12 +100,15 @@ async function deploy({ prod = true, projectName } = {}) {
|
|
|
71
100
|
|
|
72
101
|
spinner.succeed(`Ready in ${sec}s`);
|
|
73
102
|
const url = data.url || `https://${name}.${domain}`;
|
|
103
|
+
|
|
74
104
|
console.log('');
|
|
75
|
-
console.log(chalk.green(`
|
|
105
|
+
console.log(chalk.green(` Production ${url}`));
|
|
76
106
|
if (data.deployment?.version) {
|
|
77
|
-
console.log(chalk.gray(`
|
|
107
|
+
console.log(chalk.gray(` Version ${data.deployment.version}`));
|
|
78
108
|
}
|
|
79
|
-
console.log(
|
|
109
|
+
console.log(
|
|
110
|
+
chalk.green(alreadyExists ? '✓ Redeployed' : '✓ Deployed')
|
|
111
|
+
);
|
|
80
112
|
console.log('');
|
|
81
113
|
} finally {
|
|
82
114
|
if (zipPath && fs.existsSync(zipPath)) {
|