@within-7/jetr 0.5.1 → 0.6.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.
- package/dist/cli.js +57 -6
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -143,6 +143,23 @@ var api = {
|
|
|
143
143
|
const body = await res.json();
|
|
144
144
|
throw new Error(body.error);
|
|
145
145
|
}
|
|
146
|
+
},
|
|
147
|
+
async listDomains(name) {
|
|
148
|
+
return json(`/sites/${name}/domains`);
|
|
149
|
+
},
|
|
150
|
+
async addDomain(name, hostname) {
|
|
151
|
+
return json(`/sites/${name}/domains`, {
|
|
152
|
+
method: "POST",
|
|
153
|
+
headers: { "Content-Type": "application/json" },
|
|
154
|
+
body: JSON.stringify({ hostname })
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
async removeDomain(name, domainId) {
|
|
158
|
+
const res = await request(`/sites/${name}/domains/${domainId}`, { method: "DELETE" });
|
|
159
|
+
if (!res.ok) {
|
|
160
|
+
const body = await res.json();
|
|
161
|
+
throw new Error(body.error);
|
|
162
|
+
}
|
|
146
163
|
}
|
|
147
164
|
};
|
|
148
165
|
|
|
@@ -465,8 +482,7 @@ program.argument("[paths...]", "Files or directory to deploy").action(async (pat
|
|
|
465
482
|
const rcDir = dir;
|
|
466
483
|
let siteName = await resolveSiteName(rcDir, explicitName);
|
|
467
484
|
if (!siteName) {
|
|
468
|
-
|
|
469
|
-
siteName = dirName || generateName();
|
|
485
|
+
siteName = generateName();
|
|
470
486
|
console.log(chalk2.dim(`Site name: ${siteName}`));
|
|
471
487
|
}
|
|
472
488
|
siteName = sanitizeName(siteName);
|
|
@@ -488,10 +504,7 @@ program.argument("[paths...]", "Files or directory to deploy").action(async (pat
|
|
|
488
504
|
console.log(chalk2.dim(`File mode: ${files.map((f) => basename2(f)).join(", ")}`));
|
|
489
505
|
let siteName = explicitName;
|
|
490
506
|
if (!siteName) {
|
|
491
|
-
|
|
492
|
-
basename2(files[0]).replace(/\.[^.]+$/, "")
|
|
493
|
-
);
|
|
494
|
-
siteName = fileName || generateName();
|
|
507
|
+
siteName = generateName();
|
|
495
508
|
console.log(chalk2.dim(`Site name: ${siteName}`));
|
|
496
509
|
}
|
|
497
510
|
siteName = sanitizeName(siteName);
|
|
@@ -701,6 +714,44 @@ tokenCmd.command("revoke").description("Revoke a share token").argument("<site>"
|
|
|
701
714
|
process.exit(1);
|
|
702
715
|
}
|
|
703
716
|
});
|
|
717
|
+
var domainCmd = program.command("domain").description("Manage custom domains");
|
|
718
|
+
domainCmd.command("add").description("Add a custom domain to a site").argument("<site>", "Site name").argument("<hostname>", "Domain (e.g. docs.example.com)").action(async (site, hostname) => {
|
|
719
|
+
try {
|
|
720
|
+
const result = await api.addDomain(site, hostname);
|
|
721
|
+
console.log(chalk2.green(`\u2713 Domain added: ${result.hostname}`));
|
|
722
|
+
console.log();
|
|
723
|
+
console.log(` Now set up DNS:`);
|
|
724
|
+
console.log(` ${chalk2.cyan(result.hostname)} CNAME ${chalk2.dim(result.cname_target)}`);
|
|
725
|
+
console.log();
|
|
726
|
+
} catch (e) {
|
|
727
|
+
console.error(chalk2.red(e.message));
|
|
728
|
+
process.exit(1);
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
domainCmd.command("list").description("List custom domains for a site").argument("<site>", "Site name").action(async (site) => {
|
|
732
|
+
try {
|
|
733
|
+
const { domains } = await api.listDomains(site);
|
|
734
|
+
if (domains.length === 0) {
|
|
735
|
+
console.log(chalk2.dim("No custom domains. Run: jetr domain add <site> <hostname>"));
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
for (const d of domains) {
|
|
739
|
+
console.log(` ${chalk2.bold(d.hostname)} ${chalk2.dim(`(id: ${d.id})`)}`);
|
|
740
|
+
}
|
|
741
|
+
} catch (e) {
|
|
742
|
+
console.error(chalk2.red(e.message));
|
|
743
|
+
process.exit(1);
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
domainCmd.command("remove").description("Remove a custom domain").argument("<site>", "Site name").argument("<id>", "Domain ID").action(async (site, id) => {
|
|
747
|
+
try {
|
|
748
|
+
await api.removeDomain(site, id);
|
|
749
|
+
console.log(chalk2.green(`\u2713 Domain removed`));
|
|
750
|
+
} catch (e) {
|
|
751
|
+
console.error(chalk2.red(e.message));
|
|
752
|
+
process.exit(1);
|
|
753
|
+
}
|
|
754
|
+
});
|
|
704
755
|
function parseDeployArgs(paths) {
|
|
705
756
|
if (paths.length === 0) {
|
|
706
757
|
return { mode: "directory", dir: "." };
|