Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions script/setup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ require "./system_check"

print_done

notice "Installing shards"
run_command "shards", "install"

print_done

notice "Installing JS dependencies"
run_command "bun", "install"
run_command "bun", "install", "--no-progress"

notice "Compiling assets"
run_command "bun", "run", "build"

print_done

notice "Installing shards"
run_command "shards", "install"

if !File.exists?(".env")
notice "No .env found. Creating one."
File.touch ".env"
Expand Down
18 changes: 7 additions & 11 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ shards:

cadmium_transliterator:
git: https://github.com/cadmiumcr/transliterator.git
version: 0.1.0+git.commit.46c4c14594057dbcfaf27e7e7c8c164d3f0ce3f1
version: 0.1.0+git.commit.0dcedb98cbac7dd5827f204a0714b62f25c6515a

carbon:
git: https://github.com/luckyframework/carbon.git
Expand Down Expand Up @@ -48,25 +48,21 @@ shards:
git: https://github.com/crystal-loot/exception_page.git
version: 0.5.0

fnv:
git: https://github.com/naqvis/crystal-fnv.git
version: 0.1.3

habitat:
git: https://github.com/luckyframework/habitat.git
version: 0.4.9

html5:
git: https://github.com/naqvis/crystal-html5.git
version: 0.5.0
version: 0.5.1

lexbor:
git: https://github.com/kostya/lexbor.git
version: 3.1.3

lucky:
git: https://github.com/luckyframework/lucky.git
version: 1.4.0+git.commit.93e9d9e32a5bd68c2219bf470f87b5977653dc3a
version: 1.5.0

lucky_cache:
git: https://github.com/luckyframework/lucky_cache.git
Expand All @@ -78,7 +74,7 @@ shards:

lucky_flow:
git: https://github.com/luckyframework/lucky_flow.git
version: 0.10.0
version: 0.10.2

lucky_router:
git: https://github.com/luckyframework/lucky_router.git
Expand Down Expand Up @@ -114,17 +110,17 @@ shards:

webdrivers:
git: https://github.com/crystal-loot/webdrivers.cr.git
version: 0.4.4
version: 0.4.5

webless:
git: https://github.com/crystal-loot/webless.git
version: 0.1.0
version: 0.2.0

wordsmith:
git: https://github.com/luckyframework/wordsmith.git
version: 0.5.0

xpath2:
git: https://github.com/naqvis/crystal-xpath2.git
version: 0.1.3
version: 0.2.0

2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ crystal: ">= 1.10.0"
dependencies:
lucky:
github: luckyframework/lucky
branch: main
version: ~> 1.5.0
carbon:
github: luckyframework/carbon
version: ~> 0.6.0
Expand Down
2 changes: 1 addition & 1 deletion src/actions/guides/getting-started/concepts.cr
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Guides::GettingStarted::Concepts < GuideAction

### `script` folder

This folder contains a setup script for bootstrapping your app by default. Place any other bash style scripts or executables you may need for your app in here.
This folder contains a setup script for bootstrapping your app by default. Place any other scripts or executables you may need for your app in here.

### `spec` folder

Expand Down
12 changes: 5 additions & 7 deletions src/actions/guides/getting-started/installing.cr
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class Guides::GettingStarted::Installing < GuideAction
psql --version
```

Should return `psql (PostgreSQL) 10.x` or higher.
Should return `psql (PostgreSQL) #{LuckyDependencyVersions.min_compatible_postgres_version}` or higher.

### 3. Create a database user and set a password

Expand Down Expand Up @@ -319,23 +319,21 @@ class Guides::GettingStarted::Installing < GuideAction
```

#{permalink(ANCHOR_NODE)}
## Node and Yarn (optional)
## Bun (optional)

> You can skip this if you only plan to build APIs.

### 1. Install

* [Node](https://nodejs.org/en/download/). Requires at least v11
* [Yarn](https://yarnpkg.com/lang/en/docs/install/)
* [Bun](https://bun.sh). Requires at least #{LuckyDependencyVersions.min_compatible_bun_version}

### 2. Check installation

```bash
node -v
yarn -v
bun -v
```

Node should return greater than v11. Yarn should return greater than 1.x.
Bun should return at least #{LuckyDependencyVersions.min_compatible_bun_version}.

## Chrome Browser (optional)

Expand Down
100 changes: 11 additions & 89 deletions src/actions/guides/getting-started/starting_project.cr
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,26 @@ class Guides::GettingStarted::StartingProject < GuideAction
To start the server and run your project,
* first change into the directory for your newly created app with `cd {project_name}`.
* Next, you may need to update your database settings in `config/database.cr`.
* Then run `script/setup` to install dependencies
* Then run `crystal script/setup.cr` to install dependencies
* and finally `lucky dev` to start the server.

Running `lucky dev` will use an installed process manager (Overmind, Foreman,
etc.) to start the processes defined in `Procfile.dev`. By default
Running `lucky dev` will use an built-in process manager [Nox](https://github.com/crystal-loot/nox)
to start the processes defined in `Procfile.dev`. By default
`Procfile.dev` will start the lucky server, start asset compilation (browser app only),
and run a [system check](##{ANCHOR_SYSTEM_CHECK}).

> Lucky will look for a number of process managers. So if you prefer Forego
and someone else on your team prefers to use Overmind, `lucky dev` will work
for both of you.

## Script Helpers

Your new Lucky project comes with a few helper scripts located in the `script/` folder.

### Setup script

The first script you will use is the `script/setup`. You should run this after you
The first script you will use is the `script/setup.cr`. You should run this after you
first create your project. It will do a few things for you.

* Run a [system check](##{ANCHOR_SYSTEM_CHECK}) script first.
* Install Javascript dependencies. (browser app only)
* Install Crystal dependencies.
* Install Javascript dependencies. (browser app only)
* Add a `.env` file if you don't already have one.
* Create your database. (Note: the configuration settings are in `config/database.cr`)
* Verify the connection to your database.
Expand All @@ -94,97 +90,23 @@ class Guides::GettingStarted::StartingProject < GuideAction
#{permalink(ANCHOR_SYSTEM_CHECK)}
### System check script

The `script/system_check` script is called when you run `script/setup`. It is also called every
The `script/system_check.cr` script is called when you run `crystal script/setup.cr`. It is also called every
time you run `lucky dev` because Lucky defines a `system_check` process in your `Procfile.dev`.

The purpose of this script is to check that your system has everything it needs in order to run
this application for local development. By default we check these things:

* Ensure `yarn` is installed. (browser apps only)
* Ensure you have a process manager (Overmind, Foreman, etc.)
* Ensure `bun` is installed. (browser apps only)
* Check that postgres client tools are installed.

You can also extend this script to include checks for additional systems you may need.
(i.e. redis, elasticsearch, etc.).

## Bash function helpers

Located in `script/helpers/function_helpers` is a set of Bash functions used for writing a few
simple checks for your Lucky app.

### The `command_not_found` function

return `true` if the command passed to it is not found.

```bash
if command_not_found "yarn"; then
echo "Yarn is not installed"
fi
```

### The `command_not_running` function

return `true` if the command passed to it is not currently running.

```bash
if command_not_running "redis-cli ping"; then
echo "Redis is not running"
fi
```

### The `is_mac` function

return `true` if you run this script on macOS.

```bash
if is_mac; then
echo "Running on macOS"
fi
```

### The `is_linux` function

return `true` if you run this script on linux.

```bash
if is_linux; then
echo "Running on Linux"
fi
```

> There are a lot of Linux flavors out there. This should catch the most common ones at least.

### The `print_error` function
## Function helpers

print your custom error message and exit to allow for stopping your process manager.

```bash
print_error "Redis is not running. Be sure to start it with 'brew services start redis'"
```

### Full example

You can use a combination of these functions to remind you of which services you need
running every time you start your application for local development. For example,
if your app uses background job processing, and you need redis running for that to work,
then you could add this to your `script/system_check`.

```bash
if command_not_found "redis-cli"; then
print_error "Redis is required, and must be installed"
fi

if command_not_running "redis-cli ping"; then
if is_mac; then
booting_guide = "brew services start redis"
fi
if is_linux; then
booting_guide = "sudo systemctl start redis-server"
fi

print_error "Redis is not currently running. Try using " $booting_guide
fi
```
Located in `script/helpers/function_helpers.cr` is a set of functions used for writing a few
simple checks for your Lucky app. These are just helper methods you can use to streamline your
setup. These are not required by Lucky, so you are free to alter these as you need.
MD
end
end
6 changes: 3 additions & 3 deletions src/models/lucky_cli_version.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ module LuckyCliVersion
end

def current_version : SemanticVersion
SemanticVersion.new(1, 4, 1)
SemanticVersion.new(1, 5, 0)
end

def min_compatible_crystal_version : SemanticVersion
SemanticVersion.new(1, 10, 0)
SemanticVersion.new(1, 16, 0)
end

def max_compatible_crystal_version : SemanticVersion
SemanticVersion.new(1, 16, 3)
SemanticVersion.new(1, 20, 0)
end
end
8 changes: 6 additions & 2 deletions src/models/lucky_dependency_versions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ module LuckyDependencyVersions
extend self

def min_compatible_postgres_version
SemanticVersion.new(12, 12, 0)
SemanticVersion.new(14, 0, 0)
end

def min_compatible_node_version
SemanticVersion.new(16, 5, 0)
SemanticVersion.new(20, 20, 2)
end

def min_compatible_bun_version
SemanticVersion.new(1, 3, 0)
end
end