Skip to content

Commit 7d313f8

Browse files
authored
Merge pull request #95 from opeolluwa/feat/dynamic-scripts
add sample script
2 parents cd0d4c5 + 60d365f commit 7d313f8

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

scripts/create-axum-justfile.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import os
2+
import sys
3+
4+
JUSTFILE_CONTENT = """# Alias
5+
alias install := install-deps
6+
alias config:= configure
7+
alias d := dev
8+
alias c := clean
9+
alias rs := restart
10+
alias rb := rebuild
11+
alias lt := lint
12+
alias lg := logs
13+
alias s := stop
14+
15+
set dotenv-required := true
16+
set dotenv-load := true
17+
set dotenv-path := ".env"
18+
set export := true
19+
20+
# constants
21+
DOCKER_CMD := "docker compose -f docker-compose.yaml"
22+
23+
24+
# Default Shows the default commands
25+
@default:
26+
@just --list --list-heading $'Available commands\\n'
27+
28+
# format the code
29+
@lint:
30+
cargo fmt
31+
cargo group-imports --fix
32+
cargo sort -w
33+
34+
@dev:
35+
{{ DOCKER_CMD }} up -d
36+
@just logs
37+
38+
# see docker logs, this is called internally when you run just dev
39+
@logs:
40+
{{ DOCKER_CMD }} logs -f --tail='30' app
41+
42+
43+
# destroy the running docker instance and clean the cache
44+
@kill:
45+
{{ DOCKER_CMD }} down -v
46+
47+
# stop the running docker instance without cleaning the cache, called internally when you restart the project
48+
@stop:
49+
{{ DOCKER_CMD }} down
50+
51+
# stop and start the project without removing cache and local data
52+
restart:
53+
@just stop
54+
@just dev
55+
56+
# delete the project, the cached data, target dir and restart
57+
@rebuild:
58+
@just kill
59+
@just clean
60+
{{ DOCKER_CMD }} up --build -d
61+
@just logs
62+
63+
64+
#execute all initial setup after cloning the project
65+
@configure:
66+
@just install-deps
67+
cp .env.example .env
68+
69+
70+
#remove the target dir from local file system
71+
@clean:
72+
cargo clean
73+
74+
75+
#install the local dependencies
76+
@install-deps:
77+
cargo install sea-orm-cli@^2.0.0-rc
78+
cargo install cargo-sort
79+
cargo install cargo-group-imports
80+
81+
82+
83+
[group('migration')]
84+
@migrate-add target:
85+
@sea-orm-cli migrate generate "{{target}}"
86+
87+
@generate-entities:
88+
sea-orm-cli generate entity --database-url=mysql://community:community@localhost:3307/community --with-serde both -o src/entities
89+
"""
90+
91+
def main():
92+
target_dir = input("Enter directory to create Justfile in: ").strip()
93+
94+
if not target_dir:
95+
print("Error: No directory provided")
96+
sys.exit(1)
97+
98+
if not os.path.isdir(target_dir):
99+
print(f"Error: '{target_dir}' is not a valid directory")
100+
sys.exit(1)
101+
102+
justfile_path = os.path.join(target_dir, "Justfile")
103+
104+
if os.path.exists(justfile_path):
105+
print(f"Error: Justfile already exists at {justfile_path}")
106+
sys.exit(1)
107+
108+
try:
109+
with open(justfile_path, "w", encoding="utf-8") as f:
110+
f.write(JUSTFILE_CONTENT)
111+
except OSError as e:
112+
print(f"Failed to write Justfile: {e}")
113+
sys.exit(1)
114+
115+
print(f"Justfile successfully created at {justfile_path}")
116+
117+
if __name__ == "__main__":
118+
main()

0 commit comments

Comments
 (0)