mechanica 2.1.0-beta.6 → 2.1.0-beta.7

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/README.md CHANGED
@@ -361,7 +361,7 @@ These drive a locally installed Chrome or Edge (or `--browser <path>`) and need
361
361
  | `mechanica images` | Generate image dimensions and blur-up previews for `.mech/assets` (needs `sharp`; `--force` redoes all) |
362
362
  | `mechanica login` | Sign in to the Mechanica platform and save an access token for this machine (`--host`, `--token`) |
363
363
  | `mechanica link <slug>` | Point this repository at a site on the platform (`--create` makes the site); uploads are then kept by the platform, so `.mech/assets/` goes into `.gitignore` |
364
- | `mechanica push` | Publish the committed project to the platform: pull what was edited online, send the uploads it lacks, `git push`, build and upload the bundle when the code changed, wait for the deploy |
364
+ | `mechanica push` | Publish the committed project to the platform: pull what was edited online, send the uploads it lacks, `git push`, build and upload the bundle when the code changed, wait for the deploy. It pushes the branch that is checked out, under its own name: the first branch a site is pushed is the site itself, any other is deployed to an address of its own (`<slug>--<branch>`) with its own online editor — a branch name is lowercase letters, digits and single hyphens |
365
365
  | `mechanica assets pull` | Download the uploads made in the platform's online editor that this project lacks (the dev server fetches them one by one on demand) |
366
366
 
367
367
  ## Plugin options
package/dist/cli.js CHANGED
@@ -428,7 +428,20 @@ var POLL_MS = 1e3;
428
428
  var DEPLOY_TIMEOUT_MS = 3e5;
429
429
  var AUTO_DEPLOY_WAIT_MS = 1e4;
430
430
  /**
431
- * `mechanica push`: publish the committed project to the platform.
431
+ * Why a branch cannot be pushed under its name, or null when it can. On the platform a branch
432
+ * is served at an address of its own (`<slug>--<branch>`), so its name must be able to be part
433
+ * of one: lowercase letters, digits and single hyphens. The platform checks the same (and how
434
+ * long the name may be for the site) — this only says it before anything is sent.
435
+ */
436
+ function branchProblem(name) {
437
+ if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(name) || name.length > 40 || name.includes("--") || name === "edit") return `The branch "${name}" cannot be pushed under this name: on the platform a branch's name becomes part of its address, so it is up to 40 lowercase letters, digits and single hyphens (and not "edit"). Rename it — \`git branch -m new-name\` — and push again.`;
438
+ return null;
439
+ }
440
+ /**
441
+ * `mechanica push`: publish the committed project to the platform — the branch that is checked
442
+ * out, under its own name. The first branch a site is pushed becomes the site itself; any
443
+ * other is deployed to an address of its own, with its own online editor, and never touches
444
+ * the site.
432
445
  *
433
446
  * 1. bring in what was published online since the last pull (`pull --rebase`),
434
447
  * 2. send the uploads the platform lacks (they are not in git), then `git push`
@@ -463,18 +476,30 @@ async function runPush() {
463
476
  ])).code !== 0) throw new Error("Nothing to push yet — commit your project first");
464
477
  const dirty = await gitOk(cwd, ["status", "--porcelain"]);
465
478
  if (dirty) throw new Error(`Commit or stash your changes first — the working tree is not clean:\n${dirty}`);
479
+ const current = await git(cwd, [
480
+ "symbolic-ref",
481
+ "--quiet",
482
+ "--short",
483
+ "HEAD"
484
+ ]);
485
+ if (current.code !== 0 || !current.stdout) throw new Error("No branch is checked out (a detached HEAD) — switch to the branch you want to push");
486
+ const branch = current.stdout;
487
+ const problem = branchProblem(branch);
488
+ if (problem) throw new Error(problem);
489
+ const ref = `refs/heads/${branch}`;
490
+ const query = `?branch=${encodeURIComponent(branch)}`;
466
491
  if (await gitOk(cwd, [
467
492
  "ls-remote",
468
493
  "--heads",
469
494
  "mechanica",
470
- "main"
495
+ ref
471
496
  ], auth)) {
472
497
  console.info("Pulling changes from the platform…");
473
498
  const pulled = await git(cwd, [
474
499
  "pull",
475
500
  "--rebase",
476
501
  REMOTE_NAME,
477
- "main"
502
+ branch
478
503
  ], auth);
479
504
  if (pulled.code !== 0) throw new Error(`Could not rebase onto the platform's changes:\n${pulled.stderr || pulled.stdout}\nResolve the conflict (\`git rebase --continue\`), then run \`mechanica push\` again.`);
480
505
  }
@@ -484,14 +509,14 @@ async function runPush() {
484
509
  token
485
510
  });
486
511
  const head = await gitOk(cwd, ["rev-parse", "HEAD"]);
487
- console.info(`Pushing ${head.slice(0, 8)} to ${link.slug}…`);
512
+ console.info(`Pushing ${head.slice(0, 8)} to ${link.slug} (${branch})…`);
488
513
  const pushed = await git(cwd, [
489
514
  "push",
490
515
  REMOTE_NAME,
491
- "HEAD:refs/heads/main"
516
+ `HEAD:${ref}`
492
517
  ], auth);
493
518
  if (pushed.code !== 0) throw new Error(`git push failed:\n${pushed.stderr || pushed.stdout}`);
494
- const statusPath = `/api/sites/${site.uuid}/status`;
519
+ const statusPath = `/api/sites/${site.uuid}/status${query}`;
495
520
  let status = await request(link.origin, "GET", statusPath, { token });
496
521
  let deployId = null;
497
522
  if (status.needsBundle) {
@@ -501,7 +526,7 @@ async function runPush() {
501
526
  engine: engineVersion()
502
527
  });
503
528
  console.info(`Uploading the bundle (${(body.length / 1024 / 1024).toFixed(1)} MB)…`);
504
- const uploaded = await request(link.origin, "POST", `/api/sites/${site.uuid}/bundles`, {
529
+ const uploaded = await request(link.origin, "POST", `/api/sites/${site.uuid}/bundles${query}`, {
505
530
  token,
506
531
  raw: body
507
532
  });
@@ -531,7 +556,7 @@ async function runPush() {
531
556
  if (deploy.log) console.error(`\n${deploy.log}\n`);
532
557
  throw new Error(`Deploy failed: ${deploy.error ?? "unknown error"}. The previous version stays live.`);
533
558
  }
534
- console.info(`\nLive at ${deploy.url ?? status.url} — ${deploy.pages} page(s)`);
559
+ console.info(`\n${branch} is live at ${deploy.url ?? status.url} — ${deploy.pages} page(s)`);
535
560
  }
536
561
  //#endregion
537
562
  //#region src/cli/headless.ts
@@ -1218,7 +1243,9 @@ Usage:
1218
1243
  (--create makes the site, --name "Site name")
1219
1244
  mechanica push Publish the committed project: pull what was edited
1220
1245
  online, git push, build + upload the bundle when the
1221
- code changed, and wait for the deploy
1246
+ code changed, and wait for the deploy. Pushes the
1247
+ branch that is checked out: the first one pushed is
1248
+ the site, any other gets an address of its own
1222
1249
  mechanica shot <blockId> Screenshot one block via the dev preview route
1223
1250
  mechanica shot </path> Screenshot a whole page (editor overlay stripped)
1224
1251
  (--page </path>, --data <json|@file>, --width 1440,768,
@@ -1,5 +1,15 @@
1
1
  /**
2
- * `mechanica push`: publish the committed project to the platform.
2
+ * Why a branch cannot be pushed under its name, or null when it can. On the platform a branch
3
+ * is served at an address of its own (`<slug>--<branch>`), so its name must be able to be part
4
+ * of one: lowercase letters, digits and single hyphens. The platform checks the same (and how
5
+ * long the name may be for the site) — this only says it before anything is sent.
6
+ */
7
+ export declare function branchProblem(name: string): string | null;
8
+ /**
9
+ * `mechanica push`: publish the committed project to the platform — the branch that is checked
10
+ * out, under its own name. The first branch a site is pushed becomes the site itself; any
11
+ * other is deployed to an address of its own, with its own online editor, and never touches
12
+ * the site.
3
13
  *
4
14
  * 1. bring in what was published online since the last pull (`pull --rebase`),
5
15
  * 2. send the uploads the platform lacks (they are not in git), then `git push`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mechanica",
3
- "version": "2.1.0-beta.6",
3
+ "version": "2.1.0-beta.7",
4
4
  "description": "Build Vue 3 websites with a visual block editor",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  "prepublishOnly": "bun ../../scripts/ensure-bun-publish.js && bun run build"
67
67
  },
68
68
  "dependencies": {
69
- "mechanica-shared": "2.1.0-beta.6",
69
+ "mechanica-shared": "2.1.0-beta.7",
70
70
  "@vue/compiler-sfc": "^3.5.38",
71
71
  "compact-json-schema": "^0.1.5",
72
72
  "estree-walker": "^3.0.3",