Skip to content

Commit eb5bde9

Browse files
committed
Turn project into a Yeoman generator
1 parent ca149df commit eb5bde9

19 files changed

+9985
-153
lines changed

.circleci/config.yml

+27-63
Original file line numberDiff line numberDiff line change
@@ -4,95 +4,65 @@ orbs:
44

55
jobs:
66
install:
7-
working_directory: ~/project-name
7+
working_directory: ~/generator-sicarator
88
docker:
9-
- image: circleci/python:3.9.7
9+
- image: circleci/node:16.12.0
1010
steps:
1111
- checkout
1212
# Download and cache dependencies
1313
- restore_cache:
1414
keys:
15-
- project-name-poetry-1.1.10-{{ checksum "poetry.lock" }}
16-
- run:
17-
name: Update Poetry to version 1.1.10
18-
command: |
19-
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python - --version 1.1.10
15+
- generator-sicarator-dependencies-{{ checksum "package-lock.json" }}
16+
# fallback to using the latest cache if no exact match is found
17+
- generator-sicarator-dependencies-
2018
- run:
2119
name: Install dependencies
2220
command: |
23-
source /home/circleci/.poetry/env
24-
poetry run pip install --upgrade pip
25-
poetry install
21+
npm install
2622
- save_cache:
27-
key: project-name-poetry-1.1.10-{{ checksum "poetry.lock" }}
23+
key: generator-sicarator-dependencies-{{ checksum "package-lock.json" }}
2824
paths:
29-
- /home/circleci/.cache/pypoetry/virtualenvs
30-
- /home/circleci/.poetry/env
25+
- node_modules
3126

3227
test:
33-
working_directory: ~/project-name
28+
working_directory: ~/generator-sicarator
3429
docker:
35-
- image: circleci/python:3.9.7
30+
- image: circleci/node:16.12.0
3631
steps:
3732
- checkout
3833
- restore_cache:
39-
key: project-name-poetry-1.1.10-{{ checksum "poetry.lock" }}
34+
keys:
35+
- generator-sicarator-dependencies-{{ checksum "package-lock.json" }}
36+
- generator-sicarator-dependencies-
4037
- run:
41-
name: run pytest
38+
name: Run jest
4239
command: |
43-
source /home/circleci/.poetry/env
44-
make test
40+
npm run test:ci
41+
environment:
42+
JEST_JUNIT_OUTPUT_DIR: ./reports/junit/
4543
- store_test_results:
46-
path: tests-results.xml
44+
path: ./reports/junit/
4745
- store_artifacts:
48-
path: htmlcov
49-
50-
black:
51-
working_directory: ~/project-name
52-
docker:
53-
- image: circleci/python:3.9.7
54-
steps:
55-
- checkout
56-
- restore_cache:
57-
key: project-name-poetry-1.1.10-{{ checksum "poetry.lock" }}
58-
- run:
59-
name: run black
60-
command: |
61-
source /home/circleci/.poetry/env
62-
make black
46+
path: ./reports/junit
6347

6448
lint:
65-
working_directory: ~/project-name
49+
working_directory: ~/generator-sicarator
6650
docker:
67-
- image: circleci/python:3.9.7
51+
- image: circleci/node:16.12.0
6852
steps:
6953
- checkout
7054
- restore_cache:
71-
key: project-name-poetry-1.1.10-{{ checksum "poetry.lock" }}
72-
- run:
73-
name: run pylint
74-
command: |
75-
source /home/circleci/.poetry/env
76-
make lint
77-
78-
isort:
79-
working_directory: ~/project-name
80-
docker:
81-
- image: circleci/python:3.9.7
82-
steps:
83-
- checkout
84-
- restore_cache:
85-
key: project-name-poetry-1.1.10-{{ checksum "poetry.lock" }}
55+
keys:
56+
- generator-sicarator-dependencies-{{ checksum "package-lock.json" }}
57+
- generator-sicarator-dependencies-
8658
- run:
87-
name: run isort
59+
name: Run eslint
8860
command: |
89-
source /home/circleci/.poetry/env
90-
make isort
91-
61+
npm run lint
9262
9363
workflows:
9464
version: 2
95-
project-name:
65+
sicarator:
9666
jobs:
9767
- install
9868
- test:
@@ -101,9 +71,3 @@ workflows:
10171
- lint:
10272
requires:
10373
- install
104-
- black:
105-
requires:
106-
- install
107-
- isort:
108-
requires:
109-
- install

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
coverage
2+
**/templates

.gitignore

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,2 @@
1-
# byte-compiled / optimized / DLL files
2-
__pycache__/
3-
*.py[cod]
4-
5-
# unit tests / coverage reports
6-
/tests-results.xml
7-
/.coverage
8-
/coverage.xml
9-
/htmlcov/
10-
11-
# pyenv
12-
/.python-version
13-
14-
# IDE
15-
.idea/
16-
.vscode/
17-
18-
# macOS
19-
.DS_Store
1+
node_modules
2+
coverage

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021 Yannick Wolff <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+16-69
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,24 @@
1-
# {project-name}
2-
3-
{project-description}
1+
# Sicarator
2+
> Sicara's project generator
43
54
## Installation
65

7-
To install this project, you need `Python 3.9.7`.
8-
The recommended way to install it is using [pyenv](https://github.com/pyenv/pyenv).
9-
10-
### Install poetry
11-
12-
```bash
13-
python -m pip install --upgrade pip
14-
pip install poetry==1.1.10
15-
```
16-
17-
### Install requirements through poetry
18-
19-
```bash
20-
poetry install --no-root
21-
```
22-
23-
### Install git hooks (running before commit and push commands)
24-
25-
```bash
26-
poetry run pre-commit install -t pre-commit
27-
poetry run pre-commit install -t pre-push
28-
```
29-
30-
## Testing
31-
32-
To run unit tests, run `pytest` with:
33-
```bash
34-
poetry run pytest tests --cov src
35-
```
36-
or
37-
```bash
38-
make test
39-
```
40-
41-
## Formatting and static analysis
42-
43-
### Code formatting with `black`
44-
45-
To check code formatting, run `black` with:
46-
```bash
47-
poetry run black . --check
48-
```
49-
or
50-
```bash
51-
make black
52-
```
6+
- Install a stable version of [node.js](https://nodejs.org/) if you don't have one
7+
- Install [Yeoman](http://yeoman.io):
8+
```bash
9+
npm install -g yo
10+
```
11+
- Clone `sicarator` project and install it:
12+
```bas
13+
git clone https://github.com/sicara/sicarator generator-sicarator
14+
npm link generator-sicarator
15+
```
16+
⚠️ it has to be installed into a folder starting with `generator-` to be recognized as a generator by `Yeoman`
5317

54-
You can also [integrate it to your IDE](https://black.readthedocs.io/en/stable/integrations/editors.html) to reformat
55-
your code each time you save a file.
18+
## Usage
5619

57-
### Static analysis
20+
Generate a new project with:
5821

59-
To run static analysis, run `pylint` with:
60-
```bash
61-
poetry run pylint src tests
62-
```
63-
or
64-
```bash
65-
make lint
66-
```
67-
68-
### Imports ordering
69-
70-
To check imports ordering, run `isort` with:
71-
```bash
72-
poetry run isort . --check
73-
```
74-
or
7522
```bash
76-
make isort
23+
yo sicarator
7724
```

__tests__/app.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
const path = require("path");
3+
const assert = require("yeoman-assert");
4+
const helpers = require("yeoman-test");
5+
6+
describe("generator-sicarator:app", () => {
7+
beforeAll(() => {
8+
return helpers.run(path.join(__dirname, "../generators/app")).withPrompts({
9+
projectName: "project-name",
10+
projectDescription: "Project Description"
11+
});
12+
});
13+
14+
it("creates README.md", () => {
15+
assert.file(["README.md"]);
16+
});
17+
});

generators/app/index.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"use strict";
2+
const Generator = require("yeoman-generator");
3+
const chalk = require("chalk");
4+
const yosay = require("yosay");
5+
const path = require("path");
6+
const mkdirp = require("mkdirp");
7+
8+
module.exports = class extends Generator {
9+
prompting() {
10+
// Have Yeoman greet the user.
11+
this.log(
12+
yosay(
13+
`Hi, I'm ${chalk.red(
14+
"Sicarator"
15+
)}! I'm going to help you to set up your new project!`
16+
)
17+
);
18+
19+
const prompts = [
20+
{
21+
name: "projectName",
22+
message: "What's the name of your project?",
23+
default: path.basename(process.cwd())
24+
},
25+
{
26+
name: "projectDescription",
27+
message: "Describe it in one line:"
28+
}
29+
];
30+
31+
return this.prompt(prompts).then(props => {
32+
this.props = props;
33+
});
34+
}
35+
36+
default() {
37+
if (path.basename(this.destinationPath()) !== this.props.projectName) {
38+
this.log(`${chalk.green("create folder")} ${this.props.projectName}.`);
39+
mkdirp.sync(this.props.projectName);
40+
this.destinationRoot(this.destinationPath(this.props.projectName));
41+
}
42+
}
43+
44+
writing() {
45+
this.fs.copyTpl(
46+
this.templatePath(),
47+
this.destinationPath(),
48+
{
49+
projectName: this.props.projectName,
50+
projectDescription: this.props.projectDescription
51+
},
52+
{},
53+
{ globOptions: { dot: true } }
54+
);
55+
}
56+
};

0 commit comments

Comments
 (0)