Skip to content

Commit 16c390b

Browse files
authored
5 refactor generator and template (#6)
* feat!(close #5): update generator & template * chore: add banner.png
1 parent abc96e1 commit 16c390b

File tree

8 files changed

+75
-75
lines changed

8 files changed

+75
-75
lines changed

README.md

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div align="center">
22
<h1>create-service</h1>
33
<p>Boring Express Microservice Generator</p>
4-
5-
<div>
4+
5+
<p>
66
<a href="https://github.com/boringcodes/create-service/commits" aria-label="Commitizen Friendly">
77
<img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square">
88
</a>
@@ -12,24 +12,26 @@
1212
<a href="https://david-dm.org/boringcodes/create-service" aria-label="Dependencies Status">
1313
<img src="https://img.shields.io/david/boringcodes/create-service?style=flat-square">
1414
</a>
15-
<a href="https://www.npmjs.com/package/@boringcodes/create-service" aria-label="NPM Version">
16-
<img src="https://img.shields.io/npm/v/@boringcodes/create-service?color=brightgreen&style=flat-square">
15+
<a href="https://www.npmjs.com/package/generator-create-service" aria-label="NPM Version">
16+
<img src="https://img.shields.io/npm/v/generator-create-service?color=brightgreen&style=flat-square">
1717
</a>
18-
<a href="https://www.npmjs.com/package/@boringcodes/create-service" aria-label="NPM Downloads">
19-
<img src="https://img.shields.io/npm/dm/@boringcodes/create-service?style=flat-square">
18+
<a href="https://www.npmjs.com/package/generator-create-service" aria-label="NPM Downloads">
19+
<img src="https://img.shields.io/npm/dm/generator-create-service?style=flat-square">
2020
</a>
2121
<a href="https://github.com/boringcodes/create-service/blob/master/LICENSE" aria-label="MIT License">
2222
<img src="https://img.shields.io/github/license/boringcodes/create-service?color=brightgreen&style=flat-square">
2323
</a>
2424
<a href="https://github.com/boringcodes" aria-label="BoringCodes Verified">
2525
<img src="https://img.shields.io/badge/boringcodes-verified-brightgreen?style=flat-square">
2626
</a>
27-
</div>
27+
</p>
28+
29+
<img src="banner.png">
2830
</div>
2931

3032
## Install
3133

32-
Make sure `yeoman` is installed:
34+
Make sure `yeoman` is installed
3335

3436
```sh
3537
$ yarn global add yo
@@ -38,36 +40,40 @@ $ yarn global add yo
3840
Then install the generator
3941

4042
```sh
41-
$ yarn global add @boringcodes/create-service
43+
$ yarn global add generator-create-service
4244
```
4345

4446
## Usage
4547

46-
With [yo](https://github.com/yeoman/yo):
48+
Create a new directory
49+
50+
```sh
51+
$ mkdir service-name
52+
```
53+
54+
Then navigate to the created directory and run the following command to generate source
4755

4856
```sh
4957
$ yo create-service
5058
```
5159

5260
This scaffolds out:
61+
5362
```
54-
├── Dockerfile
55-
├── README.md
63+
├── src
64+
│ ├── components
65+
│ │   ├── things
66+
│ │   │   ├── constants.ts
67+
│ │   │   ├── controller.ts
68+
│ │   │   ├── index.ts
69+
│ │   └── types.ts
70+
│ ├── app.ts
71+
│ ├── index.ts
72+
│ └── routes.ts
73+
├── .env.example
74+
├── .huskyrc
5675
├── package.json
57-
└── src
58-
├── app.ts
59-
├── components
60-
│   ├── things
61-
│   │   ├── constants.ts
62-
│   │   ├── controller.ts
63-
│   │   ├── index.ts
64-
│   │   ├── middleware.ts
65-
│   │   ├── model.ts
66-
│   │   ├── repository.ts
67-
│   │   └── type.ts
68-
│   └── types.ts
69-
├── index.ts
70-
└── routes.ts
76+
└── tslint.json
7177
```
7278

7379
## Contributing

banner.png

49.7 KB
Loading

generators/app/index.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,53 @@ module.exports = class extends Generator {
1010
yosay(`Welcome to the astounding ${chalk.red(pkg.name)} generator!`),
1111
);
1212

13+
const gitName = this.user.git.name() || 'organization';
14+
const gitEmail = this.user.git.email() || 'hi@domain.com';
15+
const githubUsername = await (async () => {
16+
try {
17+
const username = await this.user.github.username();
18+
19+
return username;
20+
} catch (err) {
21+
return 'organization';
22+
}
23+
})();
1324
const prompts = [
1425
{
1526
type: 'input',
1627
name: 'elementName',
1728
message: 'What is the name of your service?',
18-
default: 'my-awesome-service',
29+
default: this.appname,
1930
},
2031
{
2132
type: 'input',
2233
name: 'elementDescription',
23-
message: 'Give us some small description of your service',
24-
default: '',
34+
message: 'Description of your service?',
35+
default: 'My awesome service',
36+
},
37+
{
38+
type: 'input',
39+
name: 'elementHomepageUrl',
40+
message: 'Homepage URL?',
41+
default: `https://github.com/${githubUsername}/${this.appname}`,
42+
},
43+
{
44+
type: 'input',
45+
name: 'elementBugsUrl',
46+
message: 'Bugs tracking URL?',
47+
default: `https://github.com/${githubUsername}/${this.appname}/issues`,
2548
},
2649
{
2750
type: 'input',
2851
name: 'elementAuthor',
29-
message: 'Who is the author of this service?',
30-
default: '',
52+
message: 'Author of this service?',
53+
default: `${gitName} \<${gitEmail}\>`,
54+
},
55+
{
56+
type: 'input',
57+
name: 'elementRepositoryUrl',
58+
message: 'Repository URL?',
59+
default: `https://github.com/${githubUsername}/${this.appname}.git`,
3160
},
3261
];
3362

@@ -39,18 +68,13 @@ module.exports = class extends Generator {
3968

4069
writing() {
4170
this.fs.copyTpl(
42-
[this.templatePath('**')],
71+
[this.templatePath('**/*'), this.templatePath('**/.*')],
4372
this.destinationPath(),
4473
this.props,
4574
);
46-
47-
this.fs.copyTpl(
48-
this.templatePath('.env.example'),
49-
this.destinationPath('.env.example'),
50-
);
5175
}
5276

5377
install() {
54-
this.installDependencies();
78+
this.yarnInstall();
5579
}
5680
};

generators/app/templates/.gitignore

Lines changed: 0 additions & 25 deletions
This file was deleted.

generators/app/templates/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

generators/app/templates/package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
22
"name": "<%= elementName %>",
3-
"description": "<%= elementDescription %>",
43
"version": "0.0.0",
5-
"private": true,
6-
"license": "MIT",
7-
"author": "<%= elementAuthor %>",
8-
"repository": "",
9-
"bugs": "",
4+
"description": "<%= elementDescription %>",
5+
"homepage": "<%= elementHomepageUrl %>",
6+
"bugs": "<%= elementBugsUrl %>",
7+
"author": "<%- elementAuthor %>",
8+
"repository": "<%= elementRepositoryUrl %>",
109
"scripts": {
1110
"clean": "rm -rf build",
1211
"purge": "rm -rf node_modules",
@@ -31,7 +30,6 @@
3130
"devDependencies": {
3231
"@types/express": "^4.16.0",
3332
"@types/morgan": "^1.7.35",
34-
"@types/qs": "^6.5.1",
3533
"@types/yup": "^0.26.3",
3634
"husky": "^1.2.1",
3735
"standard-version": "^4.4.0",

generators/app/templates/src/components/things/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { NAME } from './constants';
1010

1111
interface Request extends ExpressRequest {
1212
readonly [NAME]: any;
13-
};
13+
}
1414

1515
const list = async (_: Request, res: Response, next: NextFunction) => {
1616
try {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@boringcodes/create-service",
2+
"name": "generator-create-service",
33
"version": "0.1.1",
44
"description": "Boring Express Microservice Generator",
55
"homepage": "https://github.com/boringcodes/create-service",

0 commit comments

Comments
 (0)