@within-7/jetr 0.7.2 → 0.7.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.
Files changed (2) hide show
  1. package/dist/cli.js +29 -10
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -147,6 +147,10 @@ var api = {
147
147
  async listDomains(name) {
148
148
  return json(`/sites/${name}/domains`);
149
149
  },
150
+ async lookupDomain(hostname) {
151
+ const data = await json(`/domains/lookup?hostname=${encodeURIComponent(hostname)}`);
152
+ return data.site;
153
+ },
150
154
  async addDomain(name, hostname) {
151
155
  return json(`/sites/${name}/domains`, {
152
156
  method: "POST",
@@ -501,21 +505,32 @@ program.argument("[paths...]", "directory, file(s), and/or site name to deploy")
501
505
  console.log(chalk2.dim(`File mode: ${files.map((f) => basename2(f)).join(", ")}`));
502
506
  }
503
507
  const isCustomDomain = rawName.includes(".");
504
- const siteName = isCustomDomain ? sanitizeName(rawName.replace(/\./g, "-")) || generateName() : sanitizeName(rawName) || generateName();
505
508
  const customHostname = isCustomDomain ? rawName.toLowerCase().trim() : null;
509
+ let siteName;
506
510
  const spinner = ora("").start();
507
511
  try {
508
- await ensureSiteExists(spinner, siteName);
509
512
  if (customHostname) {
510
- spinner.text = `Binding domain ${customHostname}...`;
511
- try {
512
- const domainResult = await api.addDomain(siteName, customHostname);
513
- if (domainResult.route_registered) {
514
- spinner.text = `Route registered for ${customHostname}`;
513
+ spinner.text = `Resolving ${customHostname}...`;
514
+ const existingSite = await api.lookupDomain(customHostname);
515
+ if (existingSite) {
516
+ siteName = existingSite;
517
+ } else {
518
+ if (customHostname.endsWith(".within-7.com")) {
519
+ siteName = customHostname.split(".")[0];
520
+ } else {
521
+ siteName = sanitizeName(customHostname.replace(/\./g, "-")) || generateName();
522
+ }
523
+ await ensureSiteExists(spinner, siteName);
524
+ spinner.text = `Binding ${customHostname}...`;
525
+ try {
526
+ await api.addDomain(siteName, customHostname);
527
+ } catch (e) {
528
+ if (!e.message.includes("already in use")) throw e;
515
529
  }
516
- } catch (e) {
517
- if (!e.message.includes("already in use")) throw e;
518
530
  }
531
+ } else {
532
+ siteName = sanitizeName(rawName) || generateName();
533
+ await ensureSiteExists(spinner, siteName);
519
534
  }
520
535
  const result = mode === "directory" ? await deploy(siteName, dir, (msg) => {
521
536
  spinner.text = msg;
@@ -809,7 +824,11 @@ async function ensureSiteExists(spinner, siteName) {
809
824
  spinner.text = "Checking site...";
810
825
  try {
811
826
  await api.getSite(siteName);
812
- } catch {
827
+ } catch (e) {
828
+ const msg = e.message || "";
829
+ if (msg.includes("Forbidden")) {
830
+ throw new Error(`Site "${siteName}" belongs to another user`);
831
+ }
813
832
  spinner.text = `Creating site ${siteName}...`;
814
833
  await api.createSite(siteName);
815
834
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@within-7/jetr",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "CLI for Jetr static site hosting",
5
5
  "type": "module",
6
6
  "bin": {