surge-teardown-branches
Teardown Surge projects that no longer have a corresponding remote branch on a git repository.
Install
npm install surge-teardown-branches --save-dev# Or for the CLI npm install surge-teardown-branches --global
Usage
Surge.sh is a great tool for static hosting. Lately, I've been using it to host short lived branches of projects to visually review changes.
The problem is that Surge makes it so easy to create a project (you can use any subdomain on surge.sh
) that I ended up with a ton of projects that I didn't want to be up anymore once the corresponding branch on GitHub was deleted (after the PR was closed or merged).
This tool will go through a filtered list of your Surge projects and then run surge teardown PROJECT
for any project that doesn't have a corresponding remote branch.
Note: you must either run this command after you've already logged in with Surge or use the SURGE_LOGIN
and SURGE_TOKEN
environment variables as described here.
Assumptions
This tool makes a few assumptions so that it works in an expected way and will never teardown any projects by mistake!
So if you want this to be able to teardown your Surge projects you must name them so:
- They all end with the same unique project name / domain
- They all start with a branch name
- Between the branch and domain there can be one character (like
-
,_
, or.
)
So if your feature branches are named like feature-name-issue-99
and you call your project awsomesauce
, then when they are deployed to surge they should look like feature-name-issue-99_awesomesauce.surge.sh
or feature-name-issue-99.awesomesauce.com
if you are using a custom domain (and subdomains).
Example Time
Remote branches
greenkeeper-yargs-5.0.0
master
development
Surge projects
greenkeeper-yargs-5.0.0-myproject.surge.sh
greenkeeper-async-2.0.0-myproject.surge.sh
greenkeeper-lodash-4.0.0-myproject.surge.sh
greenkeeper-async-2.0.0-otherproject.surge.sh
myproject.surge.sh
otherproject.surge.sh
Result
surge-teardown-branches myproject.surge.sh# The following projects will be torn down # greenkeeper-async-5.0.0-myproject.surge.sh # greenkeeper-lodash-4.0.0-myproject.surge.sh # Note that myproject.surge.sh WILL NOT be torn down # because thats not what you want and would be silly
What's going on?
- Looks for all projects that look like
SOMEBRANCHNAME-myproject.surge.sh
- Looks for all remote branches
- Teardown all projects where
SOMEBRANCHNAME
isn't a remote branch greenkeeper-yargs-5.0.0-myproject.surge.sh
won't be torn down because a branch still exists with a matching name (presumably because the PR is still being worked on or waiting for review).
API
CLI
surge-teardown-branches myproject.surge.sh
JS
'myproject.surge.sh'
LICENSE
MIT