@within-7/jetr 0.7.0 → 0.7.1
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 +55 -94
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -478,48 +478,65 @@ program.argument("[paths...]", "Files or directory to deploy").action(async (pat
|
|
|
478
478
|
process.exit(1);
|
|
479
479
|
}
|
|
480
480
|
const { mode, dir, files, explicitName } = parseDeployArgs(paths);
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
481
|
+
let rawName = mode === "directory" ? await resolveSiteName(dir, explicitName) : explicitName;
|
|
482
|
+
if (!rawName) {
|
|
483
|
+
rawName = generateName();
|
|
484
|
+
console.log(chalk2.dim(`Site name: ${rawName}`));
|
|
485
|
+
}
|
|
486
|
+
if (mode === "files") {
|
|
487
|
+
console.log(chalk2.dim(`File mode: ${files.map((f) => basename2(f)).join(", ")}`));
|
|
488
|
+
}
|
|
489
|
+
const isCustomDomain = rawName.includes(".");
|
|
490
|
+
const siteName = isCustomDomain ? sanitizeName(rawName.replace(/\./g, "-")) || generateName() : sanitizeName(rawName) || generateName();
|
|
491
|
+
const customHostname = isCustomDomain ? rawName.toLowerCase().trim() : null;
|
|
492
|
+
const spinner = ora("").start();
|
|
493
|
+
try {
|
|
494
|
+
await ensureSiteExists(spinner, siteName);
|
|
495
|
+
if (customHostname) {
|
|
496
|
+
spinner.text = `Binding domain ${customHostname}...`;
|
|
497
|
+
try {
|
|
498
|
+
const domainResult = await api.addDomain(siteName, customHostname);
|
|
499
|
+
if (domainResult.route_registered) {
|
|
500
|
+
spinner.text = `Route registered for ${customHostname}`;
|
|
501
|
+
}
|
|
502
|
+
} catch (e) {
|
|
503
|
+
if (!e.message.includes("already in use")) throw e;
|
|
504
|
+
}
|
|
487
505
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
spinner.fail(e.message);
|
|
501
|
-
process.exit(1);
|
|
506
|
+
const result = mode === "directory" ? await deploy(siteName, dir, (msg) => {
|
|
507
|
+
spinner.text = msg;
|
|
508
|
+
}) : await deployFiles(siteName, files, (msg) => {
|
|
509
|
+
spinner.text = msg;
|
|
510
|
+
});
|
|
511
|
+
spinner.succeed("Deployed!");
|
|
512
|
+
console.log();
|
|
513
|
+
if (customHostname) {
|
|
514
|
+
console.log(` ${chalk2.bold("Domain:")} ${chalk2.cyan(customHostname)}`);
|
|
515
|
+
console.log(` ${chalk2.bold("Site:")} ${chalk2.dim(siteName)}`);
|
|
516
|
+
} else {
|
|
517
|
+
console.log(` ${chalk2.bold("Site:")} ${chalk2.cyan(siteName)}`);
|
|
502
518
|
}
|
|
503
|
-
}
|
|
504
|
-
console.log(
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
519
|
+
console.log(` ${chalk2.bold("URL:")} ${chalk2.green(customHostname ? `https://${customHostname}` : result.url)}`);
|
|
520
|
+
console.log(
|
|
521
|
+
` ${chalk2.bold("Files:")} ${result.filesUploaded} uploaded` + (result.filesDeleted > 0 ? `, ${result.filesDeleted} deleted` : "") + (result.filesUnchanged > 0 ? `, ${result.filesUnchanged} unchanged` : "") + (result.filesIgnored > 0 ? chalk2.dim(` (${result.filesIgnored} ignored)`) : "")
|
|
522
|
+
);
|
|
523
|
+
console.log(` ${chalk2.bold("Size:")} ${formatBytes(result.totalSize)}`);
|
|
524
|
+
if (customHostname) {
|
|
525
|
+
const isWithin7 = customHostname.endsWith(".within-7.com");
|
|
526
|
+
if (!isWithin7) {
|
|
527
|
+
console.log();
|
|
528
|
+
console.log(chalk2.yellow(` DNS setup required:`));
|
|
529
|
+
console.log(` ${customHostname} CNAME jetr-serve.lixilei.workers.dev`);
|
|
530
|
+
}
|
|
509
531
|
}
|
|
510
|
-
|
|
511
|
-
if (
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
await ensureSiteExists(spinner, siteName);
|
|
515
|
-
const result = await deployFiles(siteName, files, (msg) => {
|
|
516
|
-
spinner.text = msg;
|
|
517
|
-
});
|
|
518
|
-
printDeployResult(spinner, siteName, result);
|
|
519
|
-
} catch (e) {
|
|
520
|
-
spinner.fail(e.message);
|
|
521
|
-
process.exit(1);
|
|
532
|
+
console.log();
|
|
533
|
+
if (mode === "directory") {
|
|
534
|
+
const rc = loadRc(dir);
|
|
535
|
+
saveRc(dir, updateRc(rc, rawName));
|
|
522
536
|
}
|
|
537
|
+
} catch (e) {
|
|
538
|
+
spinner.fail(e.message);
|
|
539
|
+
process.exit(1);
|
|
523
540
|
}
|
|
524
541
|
});
|
|
525
542
|
program.command("login").description("Login with username and password").argument("[user]", "Username").argument("[password]", "Password").option("--token <token>", "Login directly with a JWT token").action(async (user, password, opts) => {
|
|
@@ -714,51 +731,6 @@ tokenCmd.command("revoke").description("Revoke a share token").argument("<site>"
|
|
|
714
731
|
process.exit(1);
|
|
715
732
|
}
|
|
716
733
|
});
|
|
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
|
-
});
|
|
762
734
|
function parseDeployArgs(paths) {
|
|
763
735
|
if (paths.length === 0) {
|
|
764
736
|
return { mode: "directory", dir: "." };
|
|
@@ -828,17 +800,6 @@ async function ensureSiteExists(spinner, siteName) {
|
|
|
828
800
|
await api.createSite(siteName);
|
|
829
801
|
}
|
|
830
802
|
}
|
|
831
|
-
function printDeployResult(spinner, siteName, result) {
|
|
832
|
-
spinner.succeed("Deployed!");
|
|
833
|
-
console.log();
|
|
834
|
-
console.log(` ${chalk2.bold("Site:")} ${chalk2.cyan(siteName)}`);
|
|
835
|
-
console.log(` ${chalk2.bold("URL:")} ${chalk2.green(result.url)}`);
|
|
836
|
-
console.log(
|
|
837
|
-
` ${chalk2.bold("Files:")} ${result.filesUploaded} uploaded` + (result.filesDeleted > 0 ? `, ${result.filesDeleted} deleted` : "") + (result.filesUnchanged > 0 ? `, ${result.filesUnchanged} unchanged` : "") + (result.filesIgnored > 0 ? chalk2.dim(` (${result.filesIgnored} ignored)`) : "")
|
|
838
|
-
);
|
|
839
|
-
console.log(` ${chalk2.bold("Size:")} ${formatBytes(result.totalSize)}`);
|
|
840
|
-
console.log();
|
|
841
|
-
}
|
|
842
803
|
function readSecret(prompt) {
|
|
843
804
|
return new Promise((resolve3) => {
|
|
844
805
|
process.stdout.write(prompt);
|