Skip to content

Commit

Permalink
Adds update command
Browse files Browse the repository at this point in the history
  • Loading branch information
jamonholmgren committed Nov 29, 2023
1 parent 5250928 commit 29e0d82
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 6 deletions.
45 changes: 42 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Qub (pronounced "cube") is a CLI that generates a web server and framework for b
<img alt="Screenshot of Qub-powered website" src="./.github/images/screenshot-website.png" width="350" />
</td></tr></table>

## Getting Started
## Getting started

_Windows Support_: Qub has only been tested on macOS and Linux. It might work on Windows WSL (Windows Subsystem for Linux) or Git Bash on Windows. If you want to help test and make it run on Windows, please open an issue or PR!

Expand All @@ -18,22 +18,61 @@ To get started, set up your `qub` alias first:
alias qub="source <(curl -sSL https://raw.githubusercontent.com/jamonholmgren/qub/main/src/cli.sh)"
```

Now, you should be able to run it like so:
Now, you should be able to run the CLI:

```
qub
qub --version
qub --help
qub create
qub update
```

## Creating a website

To create a website, run `qub create` and follow the prompts:

```
qub create
```

It'll ask you for your domain name (e.g. jamon.dev) which doubles as your project's folder name. It will also ask if you want to install QB64 (I recommend you do).

When done, you can CD into the new folder and run `./bin/build` to build the website. Then, run `./app` to start the web server. Visit [http://localhost:6464/](http://localhost:6464/) to view the website.

## Modifying your website

Your new website has the following folder structure:

```
bin
web
pages
home.html
contact.html
static
scripts.js
styles.css
footer.html
header.html
head.html
app.bas
README.md
```

### app.bas

This is the Qub web server. You can modify it if you want to change the port or add more functionality.

However, if you don't modify it, you can periodically update it by running `qub update`. Note this will blow away any modifications you've made, so be careful!

## History

When I was twelve, I built my first game in QBasic -- and kept building games and small apps (we called them "programs" in those days) for years. I have a lot of nostalgia and a special place in my heart for QBasic.

A few years ago, I was talking about rebuilding my website in something different, just for a fun challenge, and my friend Mark Villacampa said ["do it in BASIC you coward!"](https://twitter.com/MarkVillacampa/status/1594426506754801664). I took on the challenge and built [jamon.dev](https://jamon.dev) in QB64.

Once I had a working website, I realized that I wanted to make it easier for other people to build websites in QB64, so I started building Qub, aided by @knewter who is another QBasic fan from way back.
Once I had a working website, I realized that I wanted to make it easier for other people to build websites in QB64, so I started building Qub, aided by [@knewter](https://github.com/knewter) who is another QBasic fan from way back.

## TODO

Expand Down
51 changes: 48 additions & 3 deletions src/cli.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Qub CLI
# By @jamonholmgren & @knewter

main() {
VERSION="0.1.0"

Expand All @@ -15,6 +15,8 @@ main() {
GREEN='\033[1;32m'
END='\033[0m' # End Color

GITHUB_TEMPLATE="https://raw.githubusercontent.com/jamonholmgren/qub/main/template"

function replace_in_file {
local filename=$1
local variable_name=$2
Expand Down Expand Up @@ -84,8 +86,6 @@ main() {
mkdir -p "${DOMAIN}/web/pages"
mkdir -p "${DOMAIN}/web/static"

GITHUB_TEMPLATE="https://raw.githubusercontent.com/jamonholmgren/qub/main/template"

echo ""
echo -e "${GREEN}Creating project...${END}"
echo ""
Expand Down Expand Up @@ -160,6 +160,49 @@ main() {
return 0
fi

# qub update

if [[ $1 == "update" ]]; then
echo ""
echo "Updating Qub-powered QB64 website project..."
echo ""

# If we don't have an app.bas file, exit

if [[ ! -f app.bas ]]; then
echo ""
echo -e "${RED}app.bas file not found.${END} Are you in the right folder?"
echo ""
return 1
fi

# If we aren't in a git repo, exit (unless --force is passed)

if [[ ! -d .git && ($2 != "--force" && $3 != "--force") ]]; then
echo ""
echo -e "${RED}Not in a git repo ... we don't want to lose your work.${END} To force update, pass --force."
echo ""
return 1
fi

# If we are in a git repo, but the working tree is dirty, exit (unless --force is passed)

if [[ -d .git && $(git status --porcelain) && ($2 != "--force" && $3 != "--force") ]]; then
echo ""
echo -e "${RED}Git working tree is dirty ... you should commit your work first.${END} To force update, pass --force."
echo ""
return 1
fi

# Download the latest app.bas from the template

curl -s $GITHUB_TEMPLATE/app.bas > app.bas
echo -e "${GREEN}${END} app.bas updated to latest"
echo ""

return 0
fi

# Otherwise, print help

# Help command if provided -h or --help
Expand All @@ -168,6 +211,7 @@ main() {
echo -e ""
echo -e "${CYAN}Commands:${END}"
echo -e " create Create a new Qub QB64 web project"
echo -e " update Update an existing Qub QB64 web project to the latest Qub version"
echo -e ""
echo -e "${CYAN}Options:${END}"
echo -e " -h, --help Show help"
Expand All @@ -177,6 +221,7 @@ main() {
echo -e " qub --help"
echo -e " qub -v"
echo -e " qub create"
echo -e " qub update"
echo -e ""
echo -e "If you need more help, please visit:"
echo -e " ${DKGRAY}https://github.com/jamonholmgren/qub${END}"
Expand Down

0 comments on commit 29e0d82

Please sign in to comment.