Skip to content

Commit 8e96be6

Browse files
authored
refactor: rework bootstrap (#10)
Signed-off-by: tison <wander4096@gmail.com>
1 parent eccd823 commit 8e96be6

File tree

5 files changed

+133
-289
lines changed

5 files changed

+133
-289
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
/target
2+
3+
# temporary files
4+
.DS_Store
5+
__pycache__

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,30 @@
66
[![Apache 2.0 licensed][license-badge]][license-url]
77
[![Build Status][actions-badge]][actions-url]
88

9-
[crates-badge]: https://img.shields.io/crates/v/template.svg
10-
[crates-url]: https://crates.io/crates/template
11-
[docs-badge]: https://docs.rs/template/badge.svg
9+
[crates-badge]: https://img.shields.io/crates/v/${projectName}.svg
10+
[crates-url]: https://crates.io/crates/${projectName}
11+
[docs-badge]: https://docs.rs/${projectName}/badge.svg
1212
[msrv-badge]: https://img.shields.io/badge/MSRV-1.85-green?logo=rust
13-
[docs-url]: https://docs.rs/template
14-
[license-badge]: https://img.shields.io/crates/l/template
13+
[docs-url]: https://docs.rs/${projectName}
14+
[license-badge]: https://img.shields.io/crates/l/${projectName}
1515
[license-url]: LICENSE
1616
[actions-badge]: https://github.com/fast/template/workflows/CI/badge.svg
17-
[actions-url]:https://github.com/fast/template/actions?query=workflow%3ACI
17+
[actions-url]: https://github.com/fast/template/actions?query=workflow%3ACI
1818

1919
Use this repository as a GitHub template to quickly start a new Rust project.
2020

2121
## Getting Started
2222

23-
1. Create a new repository using this template
24-
2. Clone your repository and run the rename script:
25-
- **Linux/macOS:** `./rename-project.sh`
26-
- **Windows:** `.\rename-project.ps1`
27-
3. Follow the prompts, review changes, and commit
23+
1. Create a new repository using this template;
24+
2. Clone your repository and run the bootstrap script: `./bootstrap.py`;
25+
3. Follow the prompts, review changes, and commit;
2826
4. Start building your project!
2927

3028
## Minimum Rust version policy
3129

3230
This crate is built against the latest stable release, and its minimum supported rustc version is 1.85.0.
3331

34-
The policy is that the minimum Rust version required to use this crate can be increased in minor version updates. For example, if Template 1.0 requires Rust 1.60.0, then Template 1.0.z for all values of z will also require Rust 1.60.0 or newer. However, Template 1.y for y > 0 may require a newer minimum version of Rust.
32+
The policy is that the minimum Rust version required to use this crate can be increased in minor version updates. For example, if version 1.0 requires Rust 1.60.0, then version 1.0.z for all values of z will also require Rust 1.60.0 or newer. However, version 1.y for y > 0 may require a newer minimum version of Rust.
3533

3634
## License
3735

bootstrap.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright 2025 FastLabs Developers
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import os
18+
import sys
19+
20+
def main():
21+
print("Welcome to the project bootstrap script!")
22+
23+
# 1. Get user input
24+
try:
25+
project_name = input("Enter your project name (e.g., my-awesome-project): ").strip()
26+
if not project_name:
27+
print("Error: Project name cannot be empty.")
28+
sys.exit(1)
29+
30+
github_username = input("Enter your GitHub username (e.g., torvalds): ").strip()
31+
if not github_username:
32+
print("Error: GitHub username cannot be empty.")
33+
sys.exit(1)
34+
except KeyboardInterrupt:
35+
print("\nOperation cancelled.")
36+
sys.exit(0)
37+
38+
print(f"\nBootstrapping project '{project_name}' for user '{github_username}'...\n")
39+
40+
# 2. Update README.md
41+
# Replaces:
42+
# - fast/template -> username/project_name
43+
# - ${projectName} -> project_name
44+
readme_path = "README.md"
45+
if os.path.exists(readme_path):
46+
with open(readme_path, "r", encoding="utf-8") as f:
47+
content = f.read()
48+
49+
new_content = content.replace("fast/template", f"{github_username}/{project_name}")
50+
new_content = new_content.replace("${projectName}", project_name)
51+
52+
if content != new_content:
53+
with open(readme_path, "w", encoding="utf-8") as f:
54+
f.write(new_content)
55+
print(f"✅ Updated {readme_path}")
56+
else:
57+
print(f"ℹ️ No changes needed in {readme_path}")
58+
else:
59+
print(f"⚠️ Warning: {readme_path} not found.")
60+
61+
# 3. Update Cargo.toml (Workspace Root)
62+
# Replaces:
63+
# - fast/template -> username/project_name
64+
# - "template" (in members) -> "project_name"
65+
root_cargo_path = "Cargo.toml"
66+
if os.path.exists(root_cargo_path):
67+
with open(root_cargo_path, "r", encoding="utf-8") as f:
68+
content = f.read()
69+
70+
new_content = content.replace("fast/template", f"{github_username}/{project_name}")
71+
# Identify workspace member "template" specifically to avoid false positives
72+
new_content = new_content.replace('"template"', f'"{project_name}"')
73+
74+
if content != new_content:
75+
with open(root_cargo_path, "w", encoding="utf-8") as f:
76+
f.write(new_content)
77+
print(f"✅ Updated {root_cargo_path}")
78+
else:
79+
print(f"ℹ️ No changes needed in {root_cargo_path}")
80+
else:
81+
print(f"⚠️ Warning: {root_cargo_path} not found.")
82+
83+
# 4. Update template/Cargo.toml (Package Name)
84+
# Replaces:
85+
# - name = "template" -> name = "project_name"
86+
# Note: We edit the file inside the directory *before* renaming the directory
87+
template_cargo_path = "template/Cargo.toml"
88+
if os.path.exists(template_cargo_path):
89+
with open(template_cargo_path, "r", encoding="utf-8") as f:
90+
content = f.read()
91+
92+
new_content = content.replace('name = "template"', f'name = "{project_name}"')
93+
94+
if content != new_content:
95+
with open(template_cargo_path, "w", encoding="utf-8") as f:
96+
f.write(new_content)
97+
print(f"✅ Updated {template_cargo_path}")
98+
else:
99+
print(f"ℹ️ No changes needed in {template_cargo_path}")
100+
else:
101+
# If the directory was already renamed in a previous run, we might want to check the new name
102+
# but for a simple bootstrap script, assuming standard state is fine.
103+
print(f"⚠️ Warning: {template_cargo_path} not found (Did you already run this script?)")
104+
105+
# 5. Rename template directory
106+
if os.path.exists("template"):
107+
os.rename("template", project_name)
108+
print(f"✅ Renamed directory 'template' to '{project_name}'")
109+
else:
110+
if os.path.exists(project_name):
111+
print(f"ℹ️ Directory '{project_name}' already exists.")
112+
else:
113+
print("⚠️ Warning: Directory 'template' not found.")
114+
115+
print("\n🎉 Bootstrap complete!")
116+
print(f"You can now delete this script: rm {os.path.basename(__file__)}")
117+
118+
if __name__ == "__main__":
119+
main()

rename-project.ps1

Lines changed: 0 additions & 133 deletions
This file was deleted.

0 commit comments

Comments
 (0)