Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New loco cli generator #980

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
74 changes: 74 additions & 0 deletions .github/workflows/loco-cli-new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: "[loco-cli:new]"

on:
push:
branches:
- master
paths:
- "loco-new/**"
pull_request:
paths:
- "loco-new/**"

env:
RUST_TOOLCHAIN: stable
TOOLCHAIN_PROFILE: minimal

jobs:
style:
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: Checkout the code
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
components: rustfmt
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
- run: cargo fmt --all -- --check
working-directory: ./loco-new
- name: Run cargo clippy
run: cargo clippy --all-features -- -D warnings -W clippy::pedantic -W clippy::nursery -W rust-2018-idioms
working-directory: ./loco-new

test:
# needs: [style]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]

permissions:
contents: read

steps:
- name: Checkout the code
uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}

- name: Setup Rust cache
uses: Swatinem/rust-cache@v2

- name: Configure sccache
run: |
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV

- name: Run sccache-cache
uses: mozilla-actions/[email protected]

- name: Run cargo test
run: cargo test --all-features -- --test-threads 1
working-directory: ./loco-new
env:
LOCO_DEV_MODE_PATH: ${{ github.workspace }}
# NOTE NOTE NOTE: this is for optimizing build and may result in strange behavior
CARGO_TARGET_DIR: /tmp/shared-target
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["xtask", "loco-gen"]
members = ["xtask", "loco-gen", "loco-new"]
exclude = ["starters"]

[workspace.package]
Expand Down Expand Up @@ -137,8 +137,9 @@ english-to-cron = { version = "0.1.2" }
# bg_sqlt: sqlite workers
# bg_pg: postgres workers
sqlx = { version = "0.8.2", default-features = false, features = [
"postgres",
"sqlite",
"postgres",
"chrono",
"sqlite",
], optional = true }
ulid = { version = "1", optional = true }

Expand Down
2 changes: 1 addition & 1 deletion README-pt_BR.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Para ver mais recursos do Loco, confira nosso [site de documentação](https://l
## Começando
<!-- <snip id="quick-installation-command" inject_from="yaml" template="sh"> -->
```sh
cargo install loco-cli
cargo install loco
cargo install sea-orm-cli # Only when DB is needed
```
<!-- </snip> -->
Expand Down
2 changes: 1 addition & 1 deletion README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Loco 是一个用 Rust 编写的 Web 框架,类似于 Rails。Loco 提供快
通过 Cargo 安装 Loco:

```sh
cargo install loco-cli
cargo install loco
```

## 快速开始
Expand Down
2 changes: 1 addition & 1 deletion README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Pour en savoir plus sur les fonctionnalités de Loco, consultez notre [site Web
## Commencez rapidement
<!-- <snip id="quick-installation-command" inject_from="yaml" template="sh"> -->
```sh
cargo install loco-cli
cargo install loco
cargo install sea-orm-cli # Only when DB is needed
```
<!-- </snip> -->
Expand Down
2 changes: 1 addition & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Locoの詳細な機能については、[ドキュメントウェブサイト](h

## 始め方
```sh
cargo install loco-cli
cargo install loco
cargo install sea-orm-cli # データベースが必要な場合のみ
```

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ So see more Loco features, check out our [documentation website](https://loco.rs
## Getting Started
<!-- <snip id="quick-installation-command" inject_from="yaml" template="sh"> -->
```sh
cargo install loco-cli
cargo install loco
cargo install sea-orm-cli # Only when DB is needed
```
<!-- </snip> -->
Expand Down
2 changes: 1 addition & 1 deletion docs-site/content/blog/axum-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ To build a Rust app with [Axum session](https://crates.io/crates/axum_session),
Start by creating a new project and selecting the `SaaS app` template:

```sh
$ cargo install loco-cli
$ cargo install loco
$ loco new
✔ ❯ App name? · myapp
? ❯ What would you like to build?
Expand Down
2 changes: 1 addition & 1 deletion docs-site/content/blog/deploy-aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In this article, we will explore how to deploy a Rust app built with [loco](http
````sh

```sh
$ cargo install loco-cli
$ cargo install loco
$ loco new
✔ ❯ App name? · myapp
? ❯ What would you like to build?
Expand Down
4 changes: 2 additions & 2 deletions docs-site/content/docs/extras/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The `auth` feature comes as a default with the library. If desired, you can turn

### Getting Started with a SaaS App

Create your app using the [loco-cli](/docs/getting-started/tour) and select the `SaaS app (with DB and user auth)` option.
Create your app using the [loco cli](/docs/getting-started/tour) and select the `SaaS app (with DB and user auth)` option.

To explore the out-of-the-box auth controllers, run the following command:

Expand Down Expand Up @@ -177,7 +177,7 @@ async fn current(

### Creating new app

For this time, let create your rest app using the [loco-cli](/docs/getting-started/tour) and select the `Rest app` option.
For this time, let create your rest app using the [loco cli](/docs/getting-started/tour) and select the `Rest app` option.
To create new app, run the following command and follow the instructions:

```sh
Expand Down
2 changes: 1 addition & 1 deletion docs-site/content/docs/getting-started/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You can follow this guide for a step-by-step "bottom up" learning, or you can ju

<!-- <snip id="quick-installation-command" inject_from="yaml" template="sh"> -->
```sh
cargo install loco-cli
cargo install loco
cargo install sea-orm-cli # Only when DB is needed
```
<!-- </snip> -->
Expand Down
2 changes: 1 addition & 1 deletion docs-site/content/docs/getting-started/starters.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Simplify your project setup with Loco's predefined boilerplates, designed to mak

<!-- <snip id="quick-installation-command" inject_from="yaml" template="sh"> -->
```sh
cargo install loco-cli
cargo install loco
cargo install sea-orm-cli # Only when DB is needed
```
<!-- </snip> -->
Expand Down
6 changes: 3 additions & 3 deletions docs-site/content/docs/getting-started/tour/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ flair =[]
<br/>
<br/>
<br/>
Let's create a blog backend on Loco in just a few minutes. First install `loco-cli` and `sea-orm-cli`:
Let's create a blog backend on Loco in just a few minutes. First install `loco` and `sea-orm-cli`:

<!-- <snip id="quick-installation-command" inject_from="yaml" template="sh"> -->
```sh
cargo install loco-cli
cargo install loco
cargo install sea-orm-cli # Only when DB is needed
```
<!-- </snip> -->
Expand Down Expand Up @@ -165,7 +165,7 @@ $ curl localhost:5150/posts

For those counting -- the commands for creating a blog backend were:

1. `cargo install loco-cli`
1. `cargo install loco`
2. `cargo install sea-orm-cli`
3. `loco new`
4. `cargo loco generate scaffold post title:string content:text --api`
Expand Down
12 changes: 1 addition & 11 deletions docs-site/content/docs/processing/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,7 @@ Generate the task:

<!-- <snip id="generate-task-help-command" inject_from="yaml" action="exec" template="sh"> -->
```sh
Generate a Task based on the given name

Usage: demo_app-cli generate task [OPTIONS] <NAME>

Arguments:
<NAME> Name of the thing to generate

Options:
-e, --environment <ENVIRONMENT> Specify the environment [default: development]
-h, --help Print help
-V, --version Print version
cd ./examples/demo && cargo loco generate task --help
```
<!-- </snip> -->

Expand Down
39 changes: 2 additions & 37 deletions docs-site/content/docs/the-app/your-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,7 @@ cargo loco --help

<!-- <snip id="exec-help-command" inject_from="yaml" action="exec" template="sh"> -->
```sh
The one-person framework for Rust

Usage: demo_app-cli [OPTIONS] <COMMAND>

Commands:
start Start an app
db Perform DB operations
routes Describe all application endpoints
middleware Describe all application middlewares
task Run a custom task
scheduler Run the scheduler
generate code generation creates a set of files and code templates based on a predefined set of rules
doctor Validate and diagnose configurations
version Display the app version
watch Watch and restart the app
help Print this message or the help of the given subcommand(s)

Options:
-e, --environment <ENVIRONMENT> Specify the environment [default: development]
-h, --help Print help
-V, --version Print version
cd ./examples/demo && cargo loco --help
```
<!-- </snip> -->

Expand Down Expand Up @@ -134,22 +114,7 @@ Scaffolding is an efficient and speedy method for generating key components of a
See scaffold command:
<!-- <snip id="scaffold-help-command" inject_from="yaml" action="exec" template="sh"> -->
```sh
Generates a CRUD scaffold, model and controller

Usage: demo_app-cli generate scaffold [OPTIONS] <NAME> [FIELDS]...

Arguments:
<NAME> Name of the thing to generate
[FIELDS]... Model fields, eg. title:string hits:int

Options:
-k, --kind <KIND> The kind of scaffold to generate [possible values: api, html, htmx]
--htmx Use HTMX scaffold
--html Use HTML scaffold
--api Use API scaffold
-e, --environment <ENVIRONMENT> Specify the environment [default: development]
-h, --help Print help
-V, --version Print version
cd ./examples/demo && cargo loco generate scaffold --help
```
<!-- </snip> -->

Expand Down
6 changes: 3 additions & 3 deletions docs-site/translations/tour-fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ flair =[]
<br/>
<br/>
<br/>
Créons un blog coté serveur sur Loco en quelques minutes. Commençons par installer `loco-cli` et `sea-orm-cli`:
Créons un blog coté serveur sur Loco en quelques minutes. Commençons par installer `loco` et `sea-orm-cli`:

<!-- <snip id="quick-installation-command" inject_from="yaml" template="sh"> -->
```sh
cargo install loco-cli
cargo install loco
cargo install sea-orm-cli # Only when DB is needed
```
<!-- </snip> -->
Expand Down Expand Up @@ -146,7 +146,7 @@ $ curl localhost:5150/posts

Pour ceux qui comptent -- les commandes pour créer un backend de blog étaient:

1. `cargo install loco-cli`
1. `cargo install loco`
2. `cargo install sea-orm-cli`
3. `loco new`
4. `cargo loco generate scaffold post title:string content:text`
Expand Down
52 changes: 52 additions & 0 deletions loco-new/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "loco"
version = "0.2.10"
edition = "2021"
description = "loco cli website generator"
license = "Apache-2.0"
homepage = "https://docs.rs/loco-cli"
documentation = "https://docs.rs/loco-cli"
authors = ["Dotan Nahum <[email protected]>", "Elad Kaplan <[email protected]>"]

[features]
test-wizard = []

[profile.release]
strip = true

[[bin]]
name = "loco"
path = "src/bin/main.rs"
required-features = []


[dependencies]
thiserror = { version = "1.0.63" }
clap = { version = "4.4.7", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1.0" }
serde_variant = { version = "0.1.3" }
tracing = { version = "0.1.40" }
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
heck = { version = "0.5.0" }
dialoguer = "0.11.0"
strum = { version = "0.26", features = ["derive"] }
unicode-xid = { version = "0.2.6" }
rhai = { version = "1.20.0" }
include_dir = { version = "0.7.4" }
fs_extra = { version = "1.3.0" }
walkdir = { version = "2.5.0" }
tera = { version = "1.20.0" }
colored = { version = "2" }
duct = { version = "0.13.6" }
rand = { version = "0.8.5" }

[dev-dependencies]
uuid = { version = "1.11.0", features = ["v4", "fast-rng"] }
serde_yaml = { version = "0.9" }
insta = { version = "1.41.1", features = ["redactions", "yaml", "filters"] }
rstest = { version = "0.23.0" }
tree-fs = "0.2.0"
mockall = "0.13.0"
toml = "0.8.19"
regex = "1.11.1"
4 changes: 4 additions & 0 deletions loco-new/base_template/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[alias]
loco = "run --"
loco-tool = "run --bin tool --"
playground = "run --example playground"
Loading
Loading