-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optimize the post process script
- Loading branch information
Showing
6 changed files
with
61 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,32 @@ | ||
import os | ||
import subprocess | ||
|
||
# Function to remove a file if it exists | ||
def remove_file_if_exists(file_path): | ||
if os.path.exists(file_path): | ||
os.remove(file_path) | ||
|
||
# Get crate type from the cookiecutter template | ||
crate_type = "{{cookiecutter.crate_type}}" | ||
|
||
# Define paths to main.rs and lib.rs | ||
main_rs = "src/main.rs" | ||
lib_rs = "src/lib.rs" | ||
|
||
# Handle crate type and remove unnecessary files | ||
if crate_type == "bin": | ||
remove_file_if_exists(lib_rs) | ||
elif crate_type == "lib": | ||
remove_file_if_exists(main_rs) | ||
else: | ||
raise ValueError(f"Unknown crate type: {crate_type}") | ||
|
||
# Initialize Git repository | ||
try: | ||
subprocess.run(["git", "init"], check=True) | ||
except subprocess.CalledProcessError: | ||
print("Failed to initialize Git repository. Please make sure Git is installed and try manually.") | ||
except subprocess.CalledProcessError as e: | ||
print(f"Failed to initialize Git repository. Error: {e}") | ||
except FileNotFoundError: | ||
print("Git command not found. Please install Git and try again.") | ||
except Exception as e: | ||
print(f"An unexpected error occurred: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters