Include git ignore in init template (#101)

This commit is contained in:
Austin Abell 2021-03-08 21:49:11 -05:00 committed by GitHub
parent 09fa8b5ee0
commit d543b335b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 10 deletions

3
.gitignore vendored
View File

@ -9,4 +9,5 @@ target/
.anchor .anchor
test-ledger test-ledger
examples/*/Cargo.lock examples/*/Cargo.lock
examples/**/Cargo.lock examples/**/Cargo.lock
.DS_Store

View File

@ -194,6 +194,10 @@ fn init(name: String, typescript: bool) -> Result<()> {
let mut virt_manifest = File::create("Cargo.toml")?; let mut virt_manifest = File::create("Cargo.toml")?;
virt_manifest.write_all(template::virtual_manifest().as_bytes())?; virt_manifest.write_all(template::virtual_manifest().as_bytes())?;
// Initialize .gitignore file
let mut virt_manifest = File::create(".gitignore")?;
virt_manifest.write_all(template::git_ignore().as_bytes())?;
// Build the program. // Build the program.
fs::create_dir("programs")?; fs::create_dir("programs")?;
@ -206,7 +210,7 @@ fn init(name: String, typescript: bool) -> Result<()> {
let mut ts_config = File::create("tsconfig.json")?; let mut ts_config = File::create("tsconfig.json")?;
ts_config.write_all(template::ts_config().as_bytes())?; ts_config.write_all(template::ts_config().as_bytes())?;
let mut mocha = File::create(&format!("tests/{}.ts", name))?; let mut mocha = File::create(&format!("tests/{}.spec.ts", name))?;
mocha.write_all(template::ts_mocha(&name).as_bytes())?; mocha.write_all(template::ts_mocha(&name).as_bytes())?;
} else { } else {
let mut mocha = File::create(&format!("tests/{}.js", name))?; let mut mocha = File::create(&format!("tests/{}.js", name))?;

View File

@ -1,13 +1,12 @@
use heck::CamelCase; use heck::CamelCase;
use heck::SnakeCase; use heck::SnakeCase;
pub fn virtual_manifest() -> String { pub fn virtual_manifest() -> &'static str {
r#"[workspace] r#"[workspace]
members = [ members = [
"programs/*" "programs/*"
] ]
"# "#
.to_string()
} }
pub fn cargo_toml(name: &str) -> String { pub fn cargo_toml(name: &str) -> String {
@ -64,7 +63,7 @@ main();
) )
} }
pub fn deploy_script() -> String { pub fn deploy_script() -> &'static str {
r#" r#"
// Migrations are an early feature. Currently, they're nothing more than this // Migrations are an early feature. Currently, they're nothing more than this
// single deploy script that's invoked from the CLI, injecting a provider // single deploy script that's invoked from the CLI, injecting a provider
@ -79,12 +78,10 @@ module.exports = async function (provider) {
// Add your deploy script here. // Add your deploy script here.
} }
"# "#
.to_string()
} }
pub fn xargo_toml() -> String { pub fn xargo_toml() -> &'static str {
r#"[target.bpfel-unknown-unknown.dependencies.std] r#"[target.bpfel-unknown-unknown.dependencies.std]
features = []"# features = []"#
.to_string()
} }
pub fn lib_rs(name: &str) -> String { pub fn lib_rs(name: &str) -> String {
@ -151,7 +148,7 @@ describe('{}', () => {{
) )
} }
pub fn ts_config() -> String { pub fn ts_config() -> &'static str {
r#"{ r#"{
"compilerOptions": { "compilerOptions": {
"types": ["mocha", "chai"], "types": ["mocha", "chai"],
@ -163,5 +160,16 @@ pub fn ts_config() -> String {
} }
} }
"# "#
.to_string() }
pub fn git_ignore() -> &'static str {
r#"# ignore Mac OS noise
.DS_Store
# ignore the build directory for Rust/Anchor
target
# Ignore backup files creates by cargo fmt.
**/*.rs.bk
"#
} }