@within-7/jetr 0.7.2 → 0.7.3
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/dist/cli.js +24 -9
- 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 = `
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
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;
|