The Glitch team is busy building their web-based editor. So we're making our own command line tool for the service, and it's called Snail.
Install, sign in, and specify a project.
You can also practice using Snail online to see what it offers.
Use npm or download a bundled script or clone our repository.
npm option. Install a copy from our package on npm. Run this:
npm install -g glitch-snail
Bundled script option. We have a single-file bundle for Node.js on our GitHub Releases page. Download it and set it up to be executable and add it to your PATH:
curl -LO https://github.com/wh0/snail-cli/releases/latest/download/snail.js chmod +x snail.js mkdir -p ~/.local/bin ln -s "$PWD/snail.js" ~/.local/bin/snail
Repository option. Clone a copy of our Git repository and have npm install it:
git clone https://github.com/wh0/snail-cli.git cd snail-cli npm install -g
Get a sign-in code over email or create a new anonymous user.
Signing in stores your persistent token in $HOME/.config/snail/persistent-token
.
Sign-in code over email option.
💔 This doesn't work anymore, Glitch now requires a CAPTCHA solution for this endpoint.
snail auth send-email snailuser@example.com snail auth code xxxxxxxxx-xxxxx-xxxxxxxx
New anonymous user option.
snail auth anon
Create a Git remote or specify the project on each command.
Git remote option.
snail remote -p glitch-hello-website snail ot ls .
On each command option.
snail ot ls -p glitch-hello-website .
We have a simple page. We want to deploy it and add an image.
We have Snail installed, and we're signed in to an anonymous account.
type snail snail is /app/.local/bin/snail
snail whoami -n
28021122
Here's the page, in a Git repository.
git log -p commit 213b517180c7a4af53836287679bc62c43fc3eba Author: w <none> Date: Sat Oct 24 02:58:43 2020 +0000 add placeholder diff --git a/index.html b/index.html new file mode 100644 index 0000000..8435ed0 --- /dev/null +++ b/index.html @@ -0,0 +1 @@ +yay
The image will go on the assets CDN, so it's not in our repository.
git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
my-asset.png
nothing added to commit but untracked files present (use "git add" to track)
First, we set up the glitch
Git remote so that subsequent commands will operate on a specific project.
Later, we'll also use this remote to push code into the project.
snail remote -p lapis-empty-cafe
git remote -v glitch https://982a[redacted]@api.glitch.com/git/lapis-empty-cafe (fetch) glitch https://982a[redacted]@api.glitch.com/git/lapis-empty-cafe (push)
The project we're deploying to wasn't created on this anonymous account, so we have to join the project before we can make any changes to it. We request to join, and another project member approves this request in the web editor.
snail ot request-join -r
Requesting to join as snail-652c
We run a few commands to clear out the starter project.
The snail term
command connects us to an interactive terminal session where we can do that.
snail term Welcome to the Glitch console If you’re following someone else’s instructions make sure you trust them. If in doubt post a question in our forum https://support.glitch.com For now, the console and the editor don't automatically sync. You can manually run the `refresh` command and it will force a refresh, updating the editor with any console-created files. For more information about this and other technical restrictions, please see the Help Center: https://glitch.com/help app@lapis-empty-cafe:~ 06:44 $ rm -rf * .??* app@lapis-empty-cafe:~ 06:44 $ git init Initialized empty Git repository in /app/.git/ app@lapis-empty-cafe:~ 06:44 $ ls -a . .. .git app@lapis-empty-cafe:~ 06:45 $ exit logout
We upload the image to the assets CDN. That gives us a URL, which we put in our page.
snail asset push my-asset.png
https://cdn.glitch.com/8e6cdc77-20b9-4209-850f-d2607eeae33a%2Fmy-asset.png?v=1622356099641
cat >>index.html
<img src="https://cdn.glitch.com/8e6cdc77-20b9-4209-850f-d2607eeae33a%2Fmy-asset.png?v=1622356099641">
Ctrl-D
git commit -am "add asset" [master 6a65e3c] add asset 1 file changed, 1 insertion(+)
We transfer our site over Git.
To avoid conflict with the project's own checkout of the master
branch, we push to a new branch called staging
.
git push glitch master:staging Counting objects: 6, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (6/6), 492 bytes | 0 bytes/s, done. Total 6 (delta 0), reused 0 (delta 0) To https://982a[redacted]@api.glitch.com/git/lapis-empty-cafe * [new branch] master -> staging
Then we use Git inside the project to update to the version we pushed.
The snail exec
command lets us run single commands, in case we aren't in the mood for an entire terminal session.
snail exec -- git reset --hard staging
HEAD is now at 6a65e3c add asset
Finally, we manually run refresh
because we've updated the project outside the Glitch editor.
We watch the logs to see it come back up.
snail exec -- refresh
restarting...
snail logs Serving at http://1e7adc1b5ef7:3000, http://127.0.0.1:3000, http://172.17.0.62:3000 Serving at http://1e7adc1b5ef7:3000, http://127.0.0.1:3000, http://172.17.0.62:3000 Ctrl-C
Now our application is online with the page we created!
curl https://lapis-empty-cafe.glitch.me/ yay <img src="https://cdn.glitch.com/8e6cdc77-20b9-4209-850f-d2607eeae33a%2Fmy-asset.png?v=1622356099641">