Skip to content

Commit

Permalink
feat(add): add project specific gitignore (#6)
Browse files Browse the repository at this point in the history
* feat(add): add project specific gitignore

* refactor: always include automatic/manual project selection
  • Loading branch information
Rickard Natt och Dag authored Dec 11, 2020
1 parent 9788797 commit 5d46002
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 59 deletions.
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ logs

# Distribution folders
target
test-folder

# Local stuff
.merlin
# IDE
.vscode

# mac
# Mac
.DS_Store
.rts2_cache_cjs
.rts2_cache_esm
15 changes: 12 additions & 3 deletions src/commands/add.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
use crate::utils::{helpers, npm, progressbar::Spinner, template};
use crate::utils::{
helpers, npm,
progressbar::Spinner,
project::{Project, ProjectType},
template,
};
use colored::*;
use helpers::Result;
use serde_json::json;
use std::fs;

pub fn git() -> Result<()> {
template::render_file(include_str!("../templates/.gitignore"), ".gitignore", None)?;
pub fn git(project_type: Option<ProjectType>) -> Result<()> {
let project = Project::new(project_type);

project.log();

template::render_file(project.gitignore(), ".gitignore", None)?;

Ok(())
}
Expand Down
5 changes: 1 addition & 4 deletions src/commands/github_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use helpers::Result;
use serde_json::json;

pub fn run(no_npm: bool, project_type: Option<ProjectType>) -> Result<()> {
let project = match project_type {
Some(project_type) => Project::from_project_type(project_type),
None => Project::new(),
};
let project = Project::new(project_type);

project.log();

Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ enum AddCommand {
/// Create a base setup for config files
Config,
/// Add gitignore files
Git,
Git {
/// Project type
#[structopt(long, short, possible_values = &ProjectType::variants(), case_insensitive = true)]
project: Option<ProjectType>,
},
/// Add GraphQL Codegen
GraphqlCodegen,
/// Add Husky setup
Expand Down Expand Up @@ -52,7 +56,7 @@ pub fn run() -> Result<()> {

match opt {
Cli::Add(AddCommand::Config) => add::config()?,
Cli::Add(AddCommand::Git) => add::git()?,
Cli::Add(AddCommand::Git { project }) => add::git(project)?,
Cli::Add(AddCommand::GraphqlCodegen) => add::graphql_codegen()?,
Cli::Add(AddCommand::Husky) => add::husky()?,
Cli::Add(AddCommand::Jest) => add::jest()?,
Expand Down
36 changes: 0 additions & 36 deletions src/templates/.gitignore

This file was deleted.

14 changes: 14 additions & 0 deletions src/templates/gitignore/.gitignore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Dependencies
node_modules

# Logs
*.log

# env
.env

# IDE
.vscode

# Mac
.DS_Store
18 changes: 18 additions & 0 deletions src/templates/gitignore/.gitignore.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Dependencies
node_modules

# Logs
*.log

# env
.env

# Distribution folders
lib

# IDE
.merlin
.vscode

# Mac
.DS_Store
15 changes: 15 additions & 0 deletions src/templates/gitignore/.gitignore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Logs
logs
*.log

# env
.env

# Distribution folders
target

# IDE
.vscode

# Mac
.DS_Store
30 changes: 22 additions & 8 deletions src/utils/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ impl Project {
}
}

pub fn gitignore(&self) -> &'static str {
match self.project_type {
ProjectType::ReScript => {
include_str!("../templates/gitignore/.gitignore.res")
}
ProjectType::JavaScript => {
include_str!("../templates/gitignore/.gitignore.js")
}
ProjectType::Rust => {
include_str!("../templates/gitignore/.gitignore.rs")
}
}
}

pub fn release_config(&self) -> &'static str {
match self.project_type {
ProjectType::ReScript => {
Expand All @@ -73,14 +87,14 @@ impl Project {
format::success(&format!("Found {} project", self.project_type))
}

pub fn from_project_type(project_type: ProjectType) -> Project {
Project { project_type }
}

pub fn new() -> Project {
let project_type = make();

Project { project_type }
pub fn new(project_type: Option<ProjectType>) -> Project {
match project_type {
Some(project_type) => Project { project_type },
None => {
let project_type = make();
Project { project_type }
}
}
}
}

Expand Down

0 comments on commit 5d46002

Please sign in to comment.