help is a bit nicer looking, fixed a bug caused by moving an API call outside a try/xcept
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
the site is published: http://6426ed336771f2380224fb84--scintillating-mochi-760bd3.netlify.app
|
the site is published: http://6426ed336771f2380224fb84--scintillating-mochi-760bd3.netlify.app
|
||||||
```
|
```
|
||||||
|
|
||||||
## Publish Sites to Netlify With Custom Domains Too!
|
## Publish Sites to Netlify With Custom Subdomains Too!
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
> pub --root-dir mysite --custom-domain dude.helpers.fun
|
> pub --root-dir mysite --custom-domain dude.helpers.fun
|
||||||
@@ -30,7 +30,7 @@ the site is published: http://642718842cb34f02bc6b0137--cheery-daifuku-f3417f.ne
|
|||||||
the site is published at dudette.helpers.fun.
|
the site is published at dudette.helpers.fun.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Add A Custom Domain To An Already Published Site!
|
## Add A Custom Subdomain To An Already Published Site!
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
> pub --custom-domain hey.helpers.fun --domain startling-gingersnap-425138.netlify.app
|
> pub --custom-domain hey.helpers.fun --domain startling-gingersnap-425138.netlify.app
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ def deploy_page_to_netlify(dirpath: pl.Path, custom_domain: str | None = None) -
|
|||||||
print("the site is published: " + rj["url"])
|
print("the site is published: " + rj["url"])
|
||||||
if custom_domain is not None:
|
if custom_domain is not None:
|
||||||
check_that_custom_domain_is_not_in_use(custom_domain)
|
check_that_custom_domain_is_not_in_use(custom_domain)
|
||||||
set_to_custom_domain(rj["id"], custom_domain)
|
set_to_custom_domain(rj["id"], custom_domain, rj["url"])
|
||||||
|
|
||||||
|
|
||||||
def remove_custom_domain(site_id: str) -> None:
|
def remove_custom_domain(site_id: str) -> None:
|
||||||
@@ -80,7 +80,7 @@ def delete_site(site_id: str) -> None:
|
|||||||
raise Exception("something went wrong")
|
raise Exception("something went wrong")
|
||||||
|
|
||||||
|
|
||||||
def set_to_custom_domain(site_id: str, custom_domain: str) -> None:
|
def set_to_custom_domain(site_id: str, custom_domain: str, orig_url: str) -> None:
|
||||||
URL = f"https://app.netlify.com/access-control/bb-api/api/v1/sites/{site_id}"
|
URL = f"https://app.netlify.com/access-control/bb-api/api/v1/sites/{site_id}"
|
||||||
response = requests.put(
|
response = requests.put(
|
||||||
URL,
|
URL,
|
||||||
@@ -90,12 +90,12 @@ def set_to_custom_domain(site_id: str, custom_domain: str) -> None:
|
|||||||
if not response.ok:
|
if not response.ok:
|
||||||
print(response.reason)
|
print(response.reason)
|
||||||
raise Exception("something went wrong with setting the custom domain")
|
raise Exception("something went wrong with setting the custom domain")
|
||||||
print(f"the site is published at {custom_domain}.")
|
print(f"the site is published at {custom_domain}. (originally '{orig_url}')")
|
||||||
|
|
||||||
|
|
||||||
def get_site_id_from_netlify_domain(domain: str) -> tuple[str, str]:
|
def get_site_id_from_netlify_domain(domain: str) -> tuple[str, str]:
|
||||||
orig_domain = domain
|
orig_domain = domain
|
||||||
if not domain.startswith("http://"):
|
if not domain.startswith("http://") and not domain.startswith("https://"):
|
||||||
domain = f"http://{domain}"
|
domain = f"http://{domain}"
|
||||||
candidate = None
|
candidate = None
|
||||||
for site in get_all_sites():
|
for site in get_all_sites():
|
||||||
@@ -106,6 +106,8 @@ def get_site_id_from_netlify_domain(domain: str) -> tuple[str, str]:
|
|||||||
)
|
)
|
||||||
candidate = site["id"], site["url"]
|
candidate = site["id"], site["url"]
|
||||||
if candidate is None:
|
if candidate is None:
|
||||||
|
if domain.startswith("http://"):
|
||||||
|
return get_site_id_from_netlify_domain(domain.replace("http", "https"))
|
||||||
raise NoResult(f"no result for partial domain '{orig_domain}'")
|
raise NoResult(f"no result for partial domain '{orig_domain}'")
|
||||||
return candidate
|
return candidate
|
||||||
|
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ def cli_display_help() -> None:
|
|||||||
print(
|
print(
|
||||||
"""Usage:
|
"""Usage:
|
||||||
pub help
|
pub help
|
||||||
pub <rootpath> [<custom_domain>] -------------------------------->deploy a site
|
pub <rootpath> [<custom_domain>] --------------------------------> deploy a site
|
||||||
pub list ------------------------------->list all sites
|
pub list -------------------------------> list all sites
|
||||||
pub custom <custom_domain> <existing_domain> -------------------------->set a custom domain
|
pub custom <custom_domain> <existing_domain> --------------------------> set a custom domain
|
||||||
pub remove-custom <custom_domain> ----------------------->remove a custom domain
|
pub remove-custom <custom_domain> -----------------------> remove a custom domain
|
||||||
pub delete/remove <domain or custom_domain> -------------------------------->delete a site
|
pub delete/remove <domain or custom_domain> --------------------------------> delete a site
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ def cli_set_custom_domain(custom_domain: str, domain: str) -> None:
|
|||||||
return
|
return
|
||||||
if len(NETLIFY_DOMAINS) == 1 and custom_domain.count(".") == 0:
|
if len(NETLIFY_DOMAINS) == 1 and custom_domain.count(".") == 0:
|
||||||
custom_domain = f"{custom_domain}.{NETLIFY_DOMAINS[0]}"
|
custom_domain = f"{custom_domain}.{NETLIFY_DOMAINS[0]}"
|
||||||
set_to_custom_domain(site_id, custom_domain)
|
set_to_custom_domain(site_id, custom_domain, domain)
|
||||||
|
|
||||||
|
|
||||||
def cli_remove_custom_domain() -> None:
|
def cli_remove_custom_domain() -> None:
|
||||||
@@ -111,13 +111,8 @@ def cli_delete_site() -> None:
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
print("Please provide a domain")
|
print("Please provide a domain")
|
||||||
return
|
return
|
||||||
got = get_site_id_from_netlify_domain(domain)
|
|
||||||
try:
|
try:
|
||||||
site_id, full_domain = got
|
site_id, full_domain = get_site_id_from_netlify_domain(domain)
|
||||||
except ValueError:
|
|
||||||
print(got)
|
|
||||||
raise
|
|
||||||
|
|
||||||
except NoResult:
|
except NoResult:
|
||||||
if len(NETLIFY_DOMAINS) == 0:
|
if len(NETLIFY_DOMAINS) == 0:
|
||||||
raise NoCustomDomains(
|
raise NoCustomDomains(
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -3,7 +3,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="publify",
|
name="publify",
|
||||||
version="0.1.7",
|
version="0.1.8",
|
||||||
description="A CLI for publishing sites to Netlify and assigning custom domains to them.",
|
description="A CLI for publishing sites to Netlify and assigning custom domains to them.",
|
||||||
author="Zev Averbach",
|
author="Zev Averbach",
|
||||||
author_email="zev@averba.ch",
|
author_email="zev@averba.ch",
|
||||||
|
|||||||
Reference in New Issue
Block a user