@within-7/jetr 0.5.2 → 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.
- package/dist/cli.js +62 -0
- 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
|
|
|
@@ -697,6 +714,51 @@ tokenCmd.command("revoke").description("Revoke a share token").argument("<site>"
|
|
|
697
714
|
process.exit(1);
|
|
698
715
|
}
|
|
699
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
|
+
if (result.route_registered) {
|
|
723
|
+
console.log(chalk2.green(` Route auto-registered on Cloudflare`));
|
|
724
|
+
}
|
|
725
|
+
if (result.note) {
|
|
726
|
+
console.log(` ${chalk2.dim(String(result.note))}`);
|
|
727
|
+
}
|
|
728
|
+
if (result.cname_target) {
|
|
729
|
+
console.log();
|
|
730
|
+
console.log(` DNS: ${chalk2.cyan(String(result.hostname))} CNAME ${chalk2.dim(String(result.cname_target))}`);
|
|
731
|
+
}
|
|
732
|
+
console.log();
|
|
733
|
+
} catch (e) {
|
|
734
|
+
console.error(chalk2.red(e.message));
|
|
735
|
+
process.exit(1);
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
domainCmd.command("list").description("List custom domains for a site").argument("<site>", "Site name").action(async (site) => {
|
|
739
|
+
try {
|
|
740
|
+
const { domains } = await api.listDomains(site);
|
|
741
|
+
if (domains.length === 0) {
|
|
742
|
+
console.log(chalk2.dim("No custom domains. Run: jetr domain add <site> <hostname>"));
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
for (const d of domains) {
|
|
746
|
+
console.log(` ${chalk2.bold(d.hostname)} ${chalk2.dim(`(id: ${d.id})`)}`);
|
|
747
|
+
}
|
|
748
|
+
} catch (e) {
|
|
749
|
+
console.error(chalk2.red(e.message));
|
|
750
|
+
process.exit(1);
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
domainCmd.command("remove").description("Remove a custom domain").argument("<site>", "Site name").argument("<id>", "Domain ID").action(async (site, id) => {
|
|
754
|
+
try {
|
|
755
|
+
await api.removeDomain(site, id);
|
|
756
|
+
console.log(chalk2.green(`\u2713 Domain removed`));
|
|
757
|
+
} catch (e) {
|
|
758
|
+
console.error(chalk2.red(e.message));
|
|
759
|
+
process.exit(1);
|
|
760
|
+
}
|
|
761
|
+
});
|
|
700
762
|
function parseDeployArgs(paths) {
|
|
701
763
|
if (paths.length === 0) {
|
|
702
764
|
return { mode: "directory", dir: "." };
|