This commit is contained in:
james 2026-01-17 22:22:16 +10:30
commit dc6331e5fc
No known key found for this signature in database
GPG Key ID: E1FFBA228F4CAD87
11 changed files with 183 additions and 0 deletions

10
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,10 @@
# Default ignored files
/shelf/
/workspace.xml
# Ignored default folder with query files
/queries/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

14
.idea/discord.xml generated Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="ASK" />
<option name="description" value="" />
<option name="applicationTheme" value="default" />
<option name="iconsTheme" value="default" />
<option name="button1Title" value="" />
<option name="button1Url" value="" />
<option name="button2Title" value="" />
<option name="button2Url" value="" />
<option name="customApplicationId" value="" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="IncorrectFormatting" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
</profile>
</component>

10
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<MTProjectMetadataState>
<option name="userId" value="-4c3c6a73:19b0b3d1327:-7fff" />
</MTProjectMetadataState>
</option>
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/workspace-template.iml" filepath="$PROJECT_DIR$/.idea/workspace-template.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

8
.idea/workspace-template.iml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

25
cargo-generate.toml Normal file
View File

@ -0,0 +1,25 @@
[template]
cargo_generate_version = ">=0.18.0"
[hooks]
post = ["post-generate.rhai"]
[placeholders.project-name]
type = "string"
prompt = "Project name?"
regex = "^[a-zA-Z][a-zA-Z0-9_-]*$"
[placeholders.crates]
type = "string"
prompt = "Crate names (comma-separated, e.g. 'core,cli,macros')?"
default = "core"
[placeholders.author]
type = "string"
prompt = "Author?"
default = ""
[placeholders.license]
type = "string"
prompt = "License?"
default = "MIT"

77
post-generate.rhai Normal file
View File

@ -0,0 +1,77 @@
// Post-generation hook: creates crates based on user input
let crates_input = variable::get("crates");
let project_name = variable::get("project-name");
let author = variable::get("author");
let license = variable::get("license");
// Parse comma-separated crate names
let crate_names = crates_input.split(",");
for crate_name in crate_names {
let crate_name = crate_name.trim();
if crate_name.is_empty() {
continue;
}
let crate_dir = `crates/${crate_name}`;
let src_dir = `${crate_dir}/src`;
// Create directories
file::create_dir(crate_dir);
file::create_dir(src_dir);
// Determine if this looks like a binary crate
let is_bin = crate_name.contains("cli") || crate_name.contains("bin") || crate_name == "app";
// Create Cargo.toml
let cargo_toml = `[package]
name = "${project_name}-${crate_name}"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
description = ""
[dependencies]
[lints]
workspace = true
`;
if is_bin {
cargo_toml = `[package]
name = "${project_name}-${crate_name}"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
description = ""
[[bin]]
name = "${project_name}"
path = "src/main.rs"
[dependencies]
[lints]
workspace = true
`;
}
file::write(`${crate_dir}/Cargo.toml`, cargo_toml);
// Create src/lib.rs or src/main.rs
if is_bin {
file::write(`${src_dir}/main.rs`, `fn main() {
println!("Hello from ${project_name}!");
}
`);
} else {
file::write(`${src_dir}/lib.rs`, `//! ${crate_name} crate for ${project_name}.
`);
}
}
// Clean up the placeholder .gitkeep directory
file::delete("crates/.gitkeep");

1
{{project-name}}/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target/

View File

@ -0,0 +1,18 @@
[workspace]
resolver = "3"
members = ["crates/*"]
[workspace.package]
version = "0.1.0"
edition = "2024"
authors = [{% if author %}"{{author}}"{% endif %}]
license = "{{license}}"
[workspace.dependencies]
[workspace.lints.rust]
unsafe_code = "warn"
[workspace.lints.clippy]
all = "warn"
pedantic = "warn"