Skip to content

Commit 682af7f

Browse files
committed
add version
1 parent 2457f5f commit 682af7f

File tree

6 files changed

+189
-6
lines changed

6 files changed

+189
-6
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ dist-ssr
2828
__MACOSX
2929

3030
generate-snapshot.sh
31-
solo-project.md
31+
solo-project.md
32+
33+
# Rust build artifacts (root level)
34+
/target
35+
/Cargo.lock

Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "version_manager"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[[bin]]
7+
name = "version_manager"
8+
path = "version_manager.rs"
9+
10+
[dependencies]
11+
regex = "1.10"
12+

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
<h1>Solo - Your next API Client ⚡</h1>
44
</div>
55

6-
76
[![CI](https://github.com/sreq-inc/Solo/actions/workflows/ci.yml/badge.svg)](https://github.com/sreq-inc/Solo/actions/workflows/ci.yml) [![publish](https://github.com/sreq-inc/solo/actions/workflows/publish.yml/badge.svg)](https://github.com/sreq-inc/solo/actions/workflows/publish.yml)
87

98
<img width="1106" alt="image" src="https://github.com/user-attachments/assets/1edebfa9-ff8a-466a-a5ae-4b8eed207a39" />
109

11-
12-
13-
1410
## Installation
1511

1612
### macOS
@@ -52,6 +48,23 @@ bun tauri dev
5248
bun tauri build
5349
```
5450

51+
## Development
52+
53+
### Version Management
54+
55+
To update the project version across all configuration files:
56+
57+
```bash
58+
./version.sh
59+
```
60+
61+
This script will:
62+
63+
- Display the current version
64+
- Prompt for the new version
65+
- Update `package.json`, `src-tauri/Cargo.toml`, and `src-tauri/tauri.conf.json`
66+
- Create a git commit with the changes
67+
5568
## License
5669

5770
This project is licensed under the [Business Source License 1.1 (BSL 1.1)](https://mariadb.com/bsl11/).

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

version.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Script to run the version manager
4+
5+
echo "🚀 Compiling version manager..."
6+
cargo build --release --bin version_manager 2>/dev/null
7+
8+
if [ $? -eq 0 ]; then
9+
echo "✅ Compilation complete!"
10+
echo ""
11+
./target/release/version_manager
12+
else
13+
echo "❌ Compilation error. Trying with cargo run..."
14+
cargo run --bin version_manager
15+
fi

version_manager.rs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
use regex::Regex;
2+
use std::fs;
3+
use std::io::{self, Write};
4+
use std::process::Command;
5+
6+
fn main() -> Result<(), Box<dyn std::error::Error>> {
7+
println!("🔍 Version Manager - Solo");
8+
println!("=========================\n");
9+
10+
// File paths
11+
let package_json_path = "package.json";
12+
let cargo_toml_path = "src-tauri/Cargo.toml";
13+
let tauri_conf_path = "src-tauri/tauri.conf.json";
14+
15+
// Read current version
16+
let current_version = get_current_version(package_json_path)?;
17+
println!("📦 Current version: {}\n", current_version);
18+
19+
// Ask for new version
20+
print!("✏️ Enter the new version (e.g., 0.0.17): ");
21+
io::stdout().flush()?;
22+
23+
let mut new_version = String::new();
24+
io::stdin().read_line(&mut new_version)?;
25+
let new_version = new_version.trim();
26+
27+
// Validate version format
28+
if !is_valid_version(new_version) {
29+
eprintln!("❌ Error: Invalid version format! Use format: X.Y.Z");
30+
std::process::exit(1);
31+
}
32+
33+
println!(
34+
"\n🔄 Updating version from {} to {}...\n",
35+
current_version, new_version
36+
);
37+
38+
// Update files
39+
update_package_json(package_json_path, &current_version, new_version)?;
40+
println!("✅ Updated: {}", package_json_path);
41+
42+
update_cargo_toml(cargo_toml_path, &current_version, new_version)?;
43+
println!("✅ Updated: {}", cargo_toml_path);
44+
45+
update_tauri_conf(tauri_conf_path, &current_version, new_version)?;
46+
println!("✅ Updated: {}", tauri_conf_path);
47+
48+
// Create commit
49+
println!("\n📝 Creating commit...");
50+
create_commit(new_version)?;
51+
52+
println!("\n🎉 Version successfully updated to {}!", new_version);
53+
println!("📌 Commit created: chore: bump version to {}", new_version);
54+
55+
Ok(())
56+
}
57+
58+
fn get_current_version(package_json_path: &str) -> Result<String, Box<dyn std::error::Error>> {
59+
let content = fs::read_to_string(package_json_path)?;
60+
let re = Regex::new(r#""version":\s*"([^"]+)""#)?;
61+
62+
if let Some(caps) = re.captures(&content) {
63+
Ok(caps[1].to_string())
64+
} else {
65+
Err("Could not find version in package.json".into())
66+
}
67+
}
68+
69+
fn is_valid_version(version: &str) -> bool {
70+
let re = Regex::new(r"^\d+\.\d+\.\d+$").unwrap();
71+
re.is_match(version)
72+
}
73+
74+
fn update_package_json(
75+
path: &str,
76+
old_version: &str,
77+
new_version: &str,
78+
) -> Result<(), Box<dyn std::error::Error>> {
79+
let content = fs::read_to_string(path)?;
80+
let pattern = format!(r#""version": "{}""#, old_version);
81+
let replacement = format!(r#""version": "{}""#, new_version);
82+
let updated = content.replace(&pattern, &replacement);
83+
fs::write(path, updated)?;
84+
Ok(())
85+
}
86+
87+
fn update_cargo_toml(
88+
path: &str,
89+
old_version: &str,
90+
new_version: &str,
91+
) -> Result<(), Box<dyn std::error::Error>> {
92+
let content = fs::read_to_string(path)?;
93+
let pattern = format!(r#"version = "{}""#, old_version);
94+
let replacement = format!(r#"version = "{}""#, new_version);
95+
let updated = content.replace(&pattern, &replacement);
96+
fs::write(path, updated)?;
97+
Ok(())
98+
}
99+
100+
fn update_tauri_conf(
101+
path: &str,
102+
old_version: &str,
103+
new_version: &str,
104+
) -> Result<(), Box<dyn std::error::Error>> {
105+
let content = fs::read_to_string(path)?;
106+
let pattern = format!(r#""version": "{}""#, old_version);
107+
let replacement = format!(r#""version": "{}""#, new_version);
108+
let updated = content.replace(&pattern, &replacement);
109+
fs::write(path, updated)?;
110+
Ok(())
111+
}
112+
113+
fn create_commit(version: &str) -> Result<(), Box<dyn std::error::Error>> {
114+
// Add modified files
115+
let status = Command::new("git")
116+
.args(&[
117+
"add",
118+
"package.json",
119+
"src-tauri/Cargo.toml",
120+
"src-tauri/tauri.conf.json",
121+
])
122+
.status()?;
123+
124+
if !status.success() {
125+
return Err("Error adding files to git".into());
126+
}
127+
128+
// Create commit
129+
let commit_message = format!("chore: bump version to {}", version);
130+
let status = Command::new("git")
131+
.args(&["commit", "-m", &commit_message])
132+
.status()?;
133+
134+
if !status.success() {
135+
return Err("Error creating commit".into());
136+
}
137+
138+
Ok(())
139+
}

0 commit comments

Comments
 (0)