Skip to content

Commit e946432

Browse files
committed
add --preset base
1 parent 0bd8467 commit e946432

15 files changed

Lines changed: 193 additions & 89 deletions

File tree

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ repos:
7979
hooks:
8080
- id: flake8 # Lints Python code for errors and code style issues based on PEP8.
8181
args:
82-
- --config=.cpa/flake8.cfg
82+
- --config=.ci/flake8.cfg
8383
types:
8484
- python
8585
exclude: templates/
@@ -103,7 +103,7 @@ repos:
103103
hooks:
104104
- id: prettier # An opinionated code formatter supporting multiple languages.
105105
name: prettier
106-
args: [--config, .cpa/prettier.json, --write]
106+
args: [--config, .ci/prettier.json, --write]
107107
types_or:
108108
- css
109109
- scss
@@ -112,7 +112,7 @@ repos:
112112
- javascript
113113
- yaml
114114
- markdown
115-
exclude: templates/.pre-commit-config.yaml|templates/.github/workflows/ci.yaml
115+
exclude: templates/.pre-commit-config.yaml|templates/.github/workflows/ci.yaml|templates/base/ci.yaml
116116

117117
#############################################################################
118118
# Rust

example/python/.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ repos:
7777
hooks:
7878
- id: flake8 # Lints Python code for errors and code style issues based on PEP8.
7979
args:
80-
- --config=.cpa/flake8.cfg
80+
- --config=.ci/flake8.cfg
8181
types:
8282
- python
8383

@@ -100,7 +100,7 @@ repos:
100100
hooks:
101101
- id: prettier # An opinionated code formatter supporting multiple languages.
102102
name: prettier
103-
args: [--config, .cpa/prettier.json, --write]
103+
args: [--config, .ci/prettier.json, --write]
104104
types_or:
105105
- css
106106
- scss

example/python/.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"editor.formatOnSave": true,
55
"editor.defaultFormatter": "ms-python.black-formatter"
66
},
7-
"flake8.args": ["--config=.cpa/flake8.cfg"],
7+
"flake8.args": ["--config=.ci/flake8.cfg"],
88
"files.insertFinalNewline": true
99
}

example/rust/.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ repos:
5959
hooks:
6060
- id: prettier # An opinionated code formatter supporting multiple languages.
6161
name: prettier
62-
args: [--config, .cpa/prettier.json, --write]
62+
args: [--config, .ci/prettier.json, --write]
6363
types_or:
6464
- css
6565
- scss

example/rust/.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"editor.formatOnSave": true,
55
"editor.defaultFormatter": "ms-python.black-formatter"
66
},
7-
"flake8.args": ["--config=.cpa/flake8.cfg"],
7+
"flake8.args": ["--config=.ci/flake8.cfg"],
88
"files.insertFinalNewline": true
99
}

src/main.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod presets;
33
use std::process;
44

55
use clap::Parser;
6-
use presets::{common, python, rust};
6+
use presets::{base, common, python, rust};
77
use regex::Regex;
88

99
#[derive(Parser)]
@@ -46,6 +46,13 @@ pub struct Language {
4646

4747
#[allow(clippy::needless_return)]
4848
fn validate_preset(preset: &str) -> Language {
49+
if preset == "base" {
50+
return Language {
51+
language: "base".to_string(),
52+
ver: "".to_string(),
53+
};
54+
}
55+
4956
if preset == "rust" {
5057
return Language {
5158
language: "rust".to_string(),
@@ -78,6 +85,8 @@ fn main() {
7885
} else if lang.language == "rust" {
7986
let prefix = common(&args.name, create, &lang);
8087
rust(&args.name, &prefix);
88+
} else if lang.language == "base" {
89+
let _prefix = base(&args.name, create, &lang);
8190
} else {
8291
eprintln!("Preset: {:?} not supported", args.preset);
8392
}
@@ -93,6 +102,8 @@ fn main() {
93102
} else if lang.language == "rust" {
94103
let prefix = common(&args.name, create, &lang);
95104
rust(&args.name, &prefix);
105+
} else if lang.language == "base" {
106+
let _prefix = base(&args.name, create, &lang);
96107
} else {
97108
eprintln!("Preset: {:?} not supported", args.preset);
98109
}

src/presets.rs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ pub struct Makefile {}
4545
pub struct GhCI {}
4646

4747
#[derive(Template)]
48-
#[template(path = ".cpa/prettier.json", escape = "none")]
48+
#[template(path = "base/ci.yaml", escape = "none")]
49+
pub struct GhCIBase {}
50+
51+
#[derive(Template)]
52+
#[template(path = ".ci/prettier.json", escape = "none")]
4953
pub struct Prettier {}
5054

5155
#[derive(Template)]
@@ -54,17 +58,19 @@ pub struct PreCommitConfig {
5458
pub language: String,
5559
}
5660

61+
#[derive(Template)]
62+
#[template(path = "base/.pre-commit-config.yaml", escape = "none")]
63+
pub struct PreCommitConfigBase {
64+
pub language: String,
65+
}
66+
5767
////////////////////////////////////
5868
// PYTHON
5969
////////////////////////////////////
6070
#[derive(Template)]
6171
#[template(path = "python/Dockerfile", escape = "none")]
6272
pub struct PyDockerfile {}
6373

64-
#[derive(Template)]
65-
#[template(path = "python/main.py", escape = "none")]
66-
pub struct PyMain {}
67-
6874
#[derive(Template)]
6975
#[template(path = "python/pyproject.toml", escape = "none")]
7076
pub struct PyProject {
@@ -74,7 +80,7 @@ pub struct PyProject {
7480
}
7581

7682
#[derive(Template)]
77-
#[template(path = ".cpa/flake8.cfg", escape = "none")]
83+
#[template(path = ".ci/flake8.cfg", escape = "none")]
7884
pub struct Flake8 {}
7985

8086
////////////////////////////////////
@@ -98,7 +104,7 @@ pub fn common(name: &str, create: bool, lang: &Language) -> String {
98104
let prefix: String = if create { format!("./{}", name) } else { "./".to_string() };
99105

100106
// Create needed dirs
101-
let _ = fs::create_dir_all(format!("{}/.cpa", prefix));
107+
let _ = fs::create_dir_all(format!("{}/.ci", prefix));
102108
let _ = fs::create_dir_all(format!("{}/.vscode", prefix));
103109
let _ = fs::create_dir_all(format!("{}/.github/workflows", prefix));
104110

@@ -110,7 +116,7 @@ pub fn common(name: &str, create: bool, lang: &Language) -> String {
110116
language: lang.language.to_string(),
111117
}
112118
.write(&prefix, ".pre-commit-config.yaml");
113-
Prettier {}.write(&prefix, ".cpa/prettier.json");
119+
Prettier {}.write(&prefix, ".ci/prettier.json");
114120
VSCodeSettings {}.write(&prefix, ".vscode/settings.json");
115121
VSCodeExtensions {}.write(&prefix, ".vscode/extensions.json");
116122
prefix
@@ -120,8 +126,7 @@ pub fn python(name: &str, prefix: &str, lang: &Language) {
120126
let black_target_ver = format!("py{}", lang.ver.replace('.', ""));
121127

122128
// Render Python-specific files
123-
Flake8 {}.write(prefix, ".cpa/flake8.cfg");
124-
PyMain {}.write(prefix, "main.py");
129+
Flake8 {}.write(prefix, ".ci/flake8.cfg");
125130
PyDockerfile {}.write(prefix, "Dockerfile");
126131

127132
let pyproj: PyProject = PyProject {
@@ -140,3 +145,22 @@ pub fn rust(name: &str, prefix: &str) {
140145
CargoToml { name: name.to_string() }.write(prefix, "Cargo.toml");
141146
RustFmt {}.write(prefix, "rustfmt.toml");
142147
}
148+
149+
pub fn base(name: &str, create: bool, lang: &Language) -> String {
150+
let prefix: String = if create { format!("./{}", name) } else { "./".to_string() };
151+
152+
// Create needed dirs
153+
let _ = fs::create_dir_all(format!("{}/.ci", prefix));
154+
let _ = fs::create_dir_all(format!("{}/.github/workflows", prefix));
155+
156+
// Render common files
157+
GhCIBase {}.write(&prefix, ".github/workflows/ci.yaml");
158+
GitIgnore {}.write(&prefix, ".gitignore");
159+
Makefile {}.write(&prefix, "Makefile");
160+
PreCommitConfigBase {
161+
language: lang.language.to_string(),
162+
}
163+
.write(&prefix, ".pre-commit-config.yaml");
164+
Prettier {}.write(&prefix, ".ci/prettier.json");
165+
prefix
166+
}

templates/.github/workflows/ci.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ name: CI
33

44
on:
55
pull_request: # Start the job on all PRs
6-
branches: [master, main]
7-
types: [synchronize, opened, reopened, ready_for_review]
8-
push: # Start the job on all main branch push
9-
branches: [master, main]
106

117
jobs:
128
precommit:

0 commit comments

Comments
 (0)