moontraze 2.0.7 → 2.0.8
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 +58 -27
- package/package.json +1 -1
package/lib/deploy.js
CHANGED
|
@@ -17,7 +17,6 @@ async function waitForDeployJob({ apiUrl, token, jobId }) {
|
|
|
17
17
|
const printProgress = (msg) => {
|
|
18
18
|
if (!msg || msg === lastMessage) return;
|
|
19
19
|
lastMessage = msg;
|
|
20
|
-
// same line update (gray)
|
|
21
20
|
process.stdout.write('\r\x1b[K' + chalk.gray(' ' + msg));
|
|
22
21
|
};
|
|
23
22
|
|
|
@@ -37,15 +36,14 @@ async function waitForDeployJob({ apiUrl, token, jobId }) {
|
|
|
37
36
|
throw new Error(data.error || `Status check failed (${res.status})`);
|
|
38
37
|
}
|
|
39
38
|
} catch (e) {
|
|
40
|
-
// network blip — keep polling
|
|
41
39
|
printProgress('Checking status...');
|
|
42
40
|
continue;
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
const state = data.state;
|
|
46
44
|
const progress = data.progress;
|
|
47
|
-
|
|
48
45
|
let message = 'Working...';
|
|
46
|
+
|
|
49
47
|
if (typeof progress === 'object' && progress?.message) {
|
|
50
48
|
message = progress.message;
|
|
51
49
|
} else if (typeof progress === 'number') {
|
|
@@ -64,7 +62,6 @@ async function waitForDeployJob({ apiUrl, token, jobId }) {
|
|
|
64
62
|
process.stdout.write('\n');
|
|
65
63
|
return data.result || {};
|
|
66
64
|
}
|
|
67
|
-
|
|
68
65
|
if (state === 'failed') {
|
|
69
66
|
process.stdout.write('\n');
|
|
70
67
|
throw new Error(data.error || 'Deploy failed');
|
|
@@ -105,7 +102,10 @@ async function deploy({
|
|
|
105
102
|
const linked = getProject();
|
|
106
103
|
const name = (projectName || linked?.projectName || '')
|
|
107
104
|
.toLowerCase()
|
|
108
|
-
.
|
|
105
|
+
.trim()
|
|
106
|
+
.replace(/[^a-z0-9-]/g, '-')
|
|
107
|
+
.replace(/-+/g, '-')
|
|
108
|
+
.replace(/^-|-$/g, '');
|
|
109
109
|
|
|
110
110
|
if (!name || name.length < 3) {
|
|
111
111
|
throw new Error(
|
|
@@ -117,8 +117,6 @@ async function deploy({
|
|
|
117
117
|
console.log(chalk.cyan(label));
|
|
118
118
|
console.log(` API ${api}`);
|
|
119
119
|
console.log(` Project ${name}`);
|
|
120
|
-
console.log(` Target https://${name}.${domain}`);
|
|
121
|
-
console.log('');
|
|
122
120
|
|
|
123
121
|
const spinner = ora('Packaging...').start();
|
|
124
122
|
const t0 = Date.now();
|
|
@@ -128,19 +126,47 @@ async function deploy({
|
|
|
128
126
|
zipPath = await zipCwd();
|
|
129
127
|
const mb = (fs.statSync(zipPath).size / 1024 / 1024).toFixed(2);
|
|
130
128
|
|
|
129
|
+
// -------- Check if project already exists --------
|
|
131
130
|
spinner.text = 'Checking project...';
|
|
132
131
|
let alreadyExists = false;
|
|
132
|
+
let existingUrl = null;
|
|
133
|
+
let hostLabel = null;
|
|
134
|
+
|
|
133
135
|
try {
|
|
134
|
-
const statusRes = await fetch(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
const statusRes = await fetch(
|
|
137
|
+
`${api}/api/hosting/status/${encodeURIComponent(name)}`,
|
|
138
|
+
{ headers: { Authorization: `Bearer ${token}` } }
|
|
139
|
+
);
|
|
140
|
+
const statusData = await statusRes.json().catch(() => ({}));
|
|
141
|
+
|
|
142
|
+
// exists true = deployed / building / failed (status API fix ke baad)
|
|
143
|
+
if (statusRes.ok && statusData.exists) {
|
|
144
|
+
alreadyExists = true;
|
|
145
|
+
existingUrl = statusData.primaryUrl || statusData.url || null;
|
|
146
|
+
hostLabel = statusData.hostLabel || null;
|
|
140
147
|
}
|
|
141
|
-
} catch (_) {
|
|
148
|
+
} catch (_) {
|
|
149
|
+
// network fail → backend khud decide karega
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Target URL dikhao
|
|
153
|
+
const previewUrl =
|
|
154
|
+
existingUrl ||
|
|
155
|
+
(hostLabel
|
|
156
|
+
? `https://${hostLabel}.${domain}`
|
|
157
|
+
: `https://${name}.${domain}`);
|
|
158
|
+
spinner.stop();
|
|
159
|
+
console.log(` Target ${previewUrl}`);
|
|
160
|
+
console.log(
|
|
161
|
+
chalk.gray(
|
|
162
|
+
alreadyExists
|
|
163
|
+
? ' Mode Redeploy (existing project)'
|
|
164
|
+
: ' Mode New deploy'
|
|
165
|
+
)
|
|
166
|
+
);
|
|
167
|
+
console.log('');
|
|
142
168
|
|
|
143
|
-
spinner.
|
|
169
|
+
spinner.start(`Uploading (${mb} MB)...`);
|
|
144
170
|
|
|
145
171
|
const form = new FormData();
|
|
146
172
|
form.append('projectName', name);
|
|
@@ -148,12 +174,10 @@ async function deploy({
|
|
|
148
174
|
filename: `${name}.zip`,
|
|
149
175
|
contentType: 'application/zip',
|
|
150
176
|
});
|
|
177
|
+
// Backend bhi force-redeploy karta hai agar same name exist kare
|
|
151
178
|
form.append('redeploy', alreadyExists ? 'true' : 'false');
|
|
152
179
|
|
|
153
|
-
// Always use /deploy — backend queue handle karega
|
|
154
|
-
// (redeploy bhi same endpoint se queue ho sakta hai)
|
|
155
180
|
const endpoint = `${api}/api/hosting/deploy`;
|
|
156
|
-
|
|
157
181
|
const res = await fetch(endpoint, {
|
|
158
182
|
method: 'POST',
|
|
159
183
|
headers: {
|
|
@@ -171,10 +195,10 @@ async function deploy({
|
|
|
171
195
|
data = { error: text };
|
|
172
196
|
}
|
|
173
197
|
|
|
174
|
-
// ---------- Queued
|
|
198
|
+
// ---------- Queued flow ----------
|
|
175
199
|
if (res.status === 202 && data.jobId) {
|
|
176
200
|
spinner.stop();
|
|
177
|
-
console.log(chalk.gray(
|
|
201
|
+
console.log(chalk.gray(' Upload done — build starting...'));
|
|
178
202
|
console.log('');
|
|
179
203
|
|
|
180
204
|
const result = await waitForDeployJob({
|
|
@@ -185,7 +209,13 @@ async function deploy({
|
|
|
185
209
|
|
|
186
210
|
const sec = ((Date.now() - t0) / 1000).toFixed(1);
|
|
187
211
|
const url =
|
|
188
|
-
result?.url ||
|
|
212
|
+
result?.url ||
|
|
213
|
+
existingUrl ||
|
|
214
|
+
data.url ||
|
|
215
|
+
`https://${name}.${domain}`;
|
|
216
|
+
|
|
217
|
+
const wasRedeploy =
|
|
218
|
+
alreadyExists || data.redeploy === true || result?.redeploy === true;
|
|
189
219
|
|
|
190
220
|
console.log('');
|
|
191
221
|
console.log(chalk.green(` Production ${url}`));
|
|
@@ -197,14 +227,12 @@ async function deploy({
|
|
|
197
227
|
);
|
|
198
228
|
}
|
|
199
229
|
console.log(chalk.gray(` Time ${sec}s`));
|
|
200
|
-
console.log(
|
|
201
|
-
chalk.green(alreadyExists || data.redeploy ? '✓ Redeployed' : '✓ Deployed')
|
|
202
|
-
);
|
|
230
|
+
console.log(chalk.green(wasRedeploy ? '✓ Redeployed' : '✓ Deployed'));
|
|
203
231
|
console.log('');
|
|
204
232
|
return result;
|
|
205
233
|
}
|
|
206
234
|
|
|
207
|
-
// ----------
|
|
235
|
+
// ---------- Sync fallback ----------
|
|
208
236
|
const sec = ((Date.now() - t0) / 1000).toFixed(1);
|
|
209
237
|
if (!res.ok) {
|
|
210
238
|
spinner.fail(`Failed (${sec}s)`);
|
|
@@ -212,14 +240,17 @@ async function deploy({
|
|
|
212
240
|
}
|
|
213
241
|
|
|
214
242
|
spinner.succeed(`Ready in ${sec}s`);
|
|
215
|
-
const url = data.url || `https://${name}.${domain}`;
|
|
243
|
+
const url = data.url || existingUrl || `https://${name}.${domain}`;
|
|
216
244
|
console.log('');
|
|
217
245
|
console.log(chalk.green(` Production ${url}`));
|
|
218
246
|
if (data.deployment?.version) {
|
|
219
247
|
console.log(chalk.gray(` Version ${data.deployment.version}`));
|
|
220
248
|
}
|
|
221
|
-
console.log(
|
|
249
|
+
console.log(
|
|
250
|
+
chalk.green(alreadyExists || data.redeploy ? '✓ Redeployed' : '✓ Deployed')
|
|
251
|
+
);
|
|
222
252
|
console.log('');
|
|
253
|
+
return data;
|
|
223
254
|
} finally {
|
|
224
255
|
if (zipPath && fs.existsSync(zipPath)) {
|
|
225
256
|
try {
|