Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(add): add project specific gitignore #6

Merged
merged 2 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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