diff --git a/README.md b/README.md index 64d29c6..8d4567d 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ 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 > 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. ``` -## Add A Custom Domain To An Already Published Site! +## Add A Custom Subdomain To An Already Published Site! ```bash > pub --custom-domain hey.helpers.fun --domain startling-gingersnap-425138.netlify.app diff --git a/publify/api.py b/publify/api.py index 393b02b..5cc79eb 100644 --- a/publify/api.py +++ b/publify/api.py @@ -50,7 +50,7 @@ def deploy_page_to_netlify(dirpath: pl.Path, custom_domain: str | None = None) - print("the site is published: " + rj["url"]) if custom_domain is not None: 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: @@ -80,7 +80,7 @@ def delete_site(site_id: str) -> None: 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}" response = requests.put( URL, @@ -90,12 +90,12 @@ def set_to_custom_domain(site_id: str, custom_domain: str) -> None: if not response.ok: print(response.reason) 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]: orig_domain = domain - if not domain.startswith("http://"): + if not domain.startswith("http://") and not domain.startswith("https://"): domain = f"http://{domain}" candidate = None 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"] 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}'") return candidate diff --git a/publify/publify.py b/publify/publify.py index 55bd163..0203704 100644 --- a/publify/publify.py +++ b/publify/publify.py @@ -24,11 +24,11 @@ def cli_display_help() -> None: print( """Usage: pub help - pub [] -------------------------------->deploy a site - pub list ------------------------------->list all sites - pub custom -------------------------->set a custom domain - pub remove-custom ----------------------->remove a custom domain - pub delete/remove -------------------------------->delete a site + pub [] --------------------------------> deploy a site + pub list -------------------------------> list all sites + pub custom --------------------------> set a custom domain + pub remove-custom -----------------------> remove a custom domain + pub delete/remove --------------------------------> delete a site """ ) @@ -74,7 +74,7 @@ def cli_set_custom_domain(custom_domain: str, domain: str) -> None: return if len(NETLIFY_DOMAINS) == 1 and custom_domain.count(".") == 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: @@ -111,13 +111,8 @@ def cli_delete_site() -> None: except IndexError: print("Please provide a domain") return - got = get_site_id_from_netlify_domain(domain) try: - site_id, full_domain = got - except ValueError: - print(got) - raise - + site_id, full_domain = get_site_id_from_netlify_domain(domain) except NoResult: if len(NETLIFY_DOMAINS) == 0: raise NoCustomDomains( diff --git a/setup.py b/setup.py index 776f538..b53d353 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup( name="publify", - version="0.1.7", + version="0.1.8", description="A CLI for publishing sites to Netlify and assigning custom domains to them.", author="Zev Averbach", author_email="zev@averba.ch",