@just-be/deploy 0.5.0 → 0.7.0

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.
Files changed (2) hide show
  1. package/index.ts +54 -8
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -16,6 +16,7 @@
16
16
  * Environment Variables:
17
17
  * R2_BUCKET_NAME # R2 bucket name
18
18
  * KV_NAMESPACE_ID # KV namespace ID
19
+ * DEBUG # Set to "1" or "true" to enable verbose error output
19
20
  *
20
21
  * Example deploy.json:
21
22
  * {
@@ -57,13 +58,28 @@ import {
57
58
 
58
59
  const BUCKET_NAME = process.env.R2_BUCKET_NAME || "content-bucket";
59
60
  const KV_NAMESPACE_ID = process.env.KV_NAMESPACE_ID || "6118ae3b937c4883b3c582dfef8a0c05";
61
+ const DEBUG = process.env.DEBUG === "1" || process.env.DEBUG === "true";
60
62
 
61
63
  /**
62
64
  * Run wrangler command using bunx to ensure it resolves from package dependencies
65
+ * Splits command into array so each part is passed as a separate argument
63
66
  */
64
- function wrangler(command: TemplateStringsArray, ...values: unknown[]) {
65
- const cmd = String.raw(command, ...values);
66
- return $`bunx wrangler ${cmd}`;
67
+ function wrangler(strings: TemplateStringsArray, ...values: unknown[]) {
68
+ // Build an array by interleaving string parts and values
69
+ const parts = [];
70
+ for (let i = 0; i < strings.length; i++) {
71
+ // Split string part on whitespace and add non-empty parts
72
+ const words = strings[i].trim().split(/\s+/).filter(Boolean);
73
+ parts.push(...words);
74
+
75
+ // Add the value as a separate argument
76
+ if (i < values.length) {
77
+ parts.push(String(values[i]));
78
+ }
79
+ }
80
+
81
+ // Bun's shell will treat array elements as separate arguments
82
+ return $`bunx wrangler ${parts}`;
67
83
  }
68
84
 
69
85
  /**
@@ -177,7 +193,15 @@ async function uploadToR2(localPath: string, r2Key: string): Promise<boolean> {
177
193
  await wrangler`r2 object put ${BUCKET_NAME}/${r2Key} --file ${localPath}`;
178
194
  return true;
179
195
  } catch (error) {
180
- console.error(`\nFailed to upload ${localPath}:`, error);
196
+ if (DEBUG) {
197
+ console.error(`\nFailed to upload ${localPath}:`);
198
+ console.error("Error details:", error);
199
+ if (error instanceof Error) {
200
+ console.error("Stack trace:", error.stack);
201
+ }
202
+ } else {
203
+ console.error(`\nFailed to upload ${localPath}:`, error);
204
+ }
181
205
  return false;
182
206
  }
183
207
  }
@@ -189,7 +213,14 @@ async function validateWranglerAuth(): Promise<boolean> {
189
213
  try {
190
214
  await wrangler`whoami`.quiet();
191
215
  return true;
192
- } catch {
216
+ } catch (error) {
217
+ if (DEBUG) {
218
+ console.error("\nWrangler auth validation failed:");
219
+ console.error("Error details:", error);
220
+ if (error instanceof Error) {
221
+ console.error("Stack trace:", error.stack);
222
+ }
223
+ }
193
224
  return false;
194
225
  }
195
226
  }
@@ -201,7 +232,15 @@ async function validateKVAccess(): Promise<boolean> {
201
232
  try {
202
233
  await wrangler`kv key list --namespace-id ${KV_NAMESPACE_ID}`.quiet();
203
234
  return true;
204
- } catch {
235
+ } catch (error) {
236
+ if (DEBUG) {
237
+ console.error("\nKV access validation failed:");
238
+ console.error("Error details:", error);
239
+ if (error instanceof Error) {
240
+ console.error("Stack trace:", error.stack);
241
+ }
242
+ console.error(`Namespace ID: ${KV_NAMESPACE_ID}`);
243
+ }
205
244
  return false;
206
245
  }
207
246
  }
@@ -213,7 +252,14 @@ async function getCurrentBranch(): Promise<string> {
213
252
  try {
214
253
  const result = await $`git rev-parse --abbrev-ref HEAD`.text();
215
254
  return result.trim();
216
- } catch {
255
+ } catch (error) {
256
+ if (DEBUG) {
257
+ console.error("\nFailed to get current git branch:");
258
+ console.error("Error details:", error);
259
+ if (error instanceof Error) {
260
+ console.error("Stack trace:", error.stack);
261
+ }
262
+ }
217
263
  throw new Error("Failed to get current git branch. Are you in a git repository?");
218
264
  }
219
265
  }
@@ -439,7 +485,7 @@ async function deploy() {
439
485
  process.exit(1);
440
486
  }
441
487
  s.stop("✓ Authentication verified");
442
- } catch (error) {
488
+ } catch {
443
489
  console.error("\n❌ Authentication failed");
444
490
  console.error("\nAlternatively, you can set up an API token:");
445
491
  console.error(" export CLOUDFLARE_API_TOKEN=your-token");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@just-be/deploy",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Deploy static sites to Cloudflare R2 with subdomain routing",
5
5
  "type": "module",
6
6
  "bin": {