Skip to content
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
19 changes: 19 additions & 0 deletions .github/workflows/create-github-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: create-github-release

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
create-github-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/create-release@v1
env:
# This token is provided by Actions, you do not need to create your own token
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
tag_name: ${{github.ref}}
release_name: Release ${{github.ref}}
19 changes: 19 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: publish-npm

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org
- run: yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
70 changes: 46 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,68 @@
<div align="center">
<h1>repo-template</h1>
<p>Boring GitHub Repository Template</p>
<div>
<a href="https://github.com/boringcodes/repo-template/commits" aria-label="Commitizen Friendly">
<h1>create-service-component</h1>
<p>Boring Express Microservice Component Generator</p>

<p>
<a href="https://github.com/boringcodes/create-service-component/commits" aria-label="Commitizen Friendly">
<img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square">
</a>
<a href="https://github.com/boringcodes/repo-template/actions" aria-label="GitHub Workflow Status">
<img src="https://img.shields.io/github/workflow/status/boringcodes/repo-template/main-workflow?style=flat-square">
<a href="https://github.com/boringcodes/create-service-component/actions" aria-label="GitHub Workflow Status">
<img src="https://img.shields.io/github/workflow/status/boringcodes/create-service-component/publish-npm?style=flat-square">
</a>
<a href="https://david-dm.org/boringcodes/repo-template" aria-label="Dependencies Status">
<img src="https://img.shields.io/david/boringcodes/repo-template?style=flat-square">
<a href="https://david-dm.org/boringcodes/create-service-component" aria-label="Dependencies Status">
<img src="https://img.shields.io/david/boringcodes/create-service-component?style=flat-square">
</a>
<a href="https://www.npmjs.com/package/@boringcodes/repo-template" aria-label="NPM Version">
<img src="https://img.shields.io/npm/v/@boringcodes/repo-template?color=brightgreen&style=flat-square">
<a href="https://www.npmjs.com/package/generator-create-service-component" aria-label="NPM Version">
<img src="https://img.shields.io/npm/v/generator-create-service-component?color=brightgreen&style=flat-square">
</a>
<a href="https://www.npmjs.com/package/@boringcodes/repo-template" aria-label="NPM Downloads">
<img src="https://img.shields.io/npm/dm/@boringcodes/repo-template?style=flat-square">
<a href="https://www.npmjs.com/package/generator-create-service-component" aria-label="NPM Downloads">
<img src="https://img.shields.io/npm/dm/generator-create-service-component?style=flat-square">
</a>
<a href="https://github.com/boringcodes/repo-template/blob/master/LICENSE" aria-label="MIT License">
<img src="https://img.shields.io/github/license/boringcodes/repo-template?color=brightgreen&style=flat-square">
<a href="https://github.com/boringcodes/create-service-component/blob/master/LICENSE" aria-label="MIT License">
<img src="https://img.shields.io/github/license/boringcodes/create-service-component?color=brightgreen&style=flat-square">
</a>
<a href="https://github.com/boringcodes" aria-label="BoringCodes Verified">
<img src="https://img.shields.io/badge/boringcodes-verified-brightgreen?style=flat-square">
</a>
</div>
</p>

<img src="banner.png">
</div>

## Installation
## Install

Make sure `yeoman` is installed

```sh
$ yarn global add yo
```

Use the package manager to install foobar.
Then install the generator

```bash
yarn install
```sh
$ yarn global add generator-create-service-component
```

## Usage

```javascript
import foobar from 'foobar';
Navigate to the created service root dir (using [@boringcodes/create-service](https://github.com/boringcodes/create-service)) and run the following command to generate new component

foobar.start();
```sh
$ yo create-service-component
```

This scaffolds out:

```
├── src
│ ├── components
│ │   ├── componentNames
│ │   │   ├── constants.ts
│ │   │   ├── controller.ts
│ │   │   ├── index.ts
│ │   └── ...
│ ├── ...
├── ...
```

## Contributing
Expand All @@ -55,4 +77,4 @@ Please make sure to update tests as appropriate.

## License

[MIT](https://github.com/boringcodes/repo-template/blob/master/LICENSE)
[MIT](https://github.com/boringcodes/create-service-component/blob/master/LICENSE)
Binary file added banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const Generator = require('yeoman-generator');
const chalk = require('chalk');
const yosay = require('yosay');
const pluralize = require('pluralize');

const pkg = require('../../package.json');

module.exports = class extends Generator {
async prompting() {
this.log(yosay(`Welcome to the ${chalk.red(pkg.name)} generator!`));

const prompts = [
{
type: 'input',
name: 'elementComponentName',
message: 'Name of the new component (singular)?',
default: 'thing',
},
];

return this.prompt(prompts).then(props => {
this.props = {
...props,
elementComponentPluralName: pluralize(props.elementComponentName),
};
});
}

writing() {
this.fs.copyTpl(
[this.templatePath('**/*'), this.templatePath('**/.*')],
this.destinationPath('src/components'),
this.props,
);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const NAME = '<%= elementComponentName %>';
const PLURAL_NAME = '<%= elementComponentPluralName %>';

export { NAME, PLURAL_NAME };
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Request as ExpressRequest, Response, NextFunction } from 'express';
import {
BAD_REQUEST,
NOT_FOUND,
INTERNAL_SERVER_ERROR,
} from 'http-status-codes';
import { HttpError } from '@boringcodes/utils/error';

import { NAME } from './constants';

interface Request extends ExpressRequest {
readonly [NAME]: any;
}

const list = async (_: Request, res: Response, next: NextFunction) => {
try {
// TODO: list objects
const objects = [];

res.send(objects);
} catch (err) {
next(new HttpError(err.code || INTERNAL_SERVER_ERROR, err));
}
};

const count = async (_: Request, res: Response, next: NextFunction) => {
try {
// TODO: count objects
const count = 0;

res.send({ count });
} catch (err) {
next(new HttpError(err.code || INTERNAL_SERVER_ERROR, err));
}
};

const create = async (_: Request, res: Response, next: NextFunction) => {
try {
// TODO: create object
const object = {};

res.send(object);
} catch (err) {
next(new HttpError(err.code || INTERNAL_SERVER_ERROR, err));
}
};

const getById = async (req: Request, _: Response, next: NextFunction) => {
if (!req.params.id) {
next(new HttpError(BAD_REQUEST, 'Invalid resource Id'));

return;
}

try {
// TODO: get object
const object = {};

if (!object) {
next(new HttpError(NOT_FOUND, 'Resource not found'));

return;
}
// tslint:disable-next-line:no-object-mutation
Object.assign(req, { [NAME]: object });

next();
} catch (err) {
next(new HttpError(err.code || INTERNAL_SERVER_ERROR, err));
}
};

const get = (req: Request, res: Response) => {
res.send(req[NAME]);
};

const update = async (req: Request, res: Response, next: NextFunction) => {
try {
// TODO: update object
const object = req[NAME];

res.send(object);
} catch (err) {
next(err);
}
};

const del = async (req: Request, res: Response, next: NextFunction) => {
try {
// TODO: delete object
const object = req[NAME];

res.send(object);
} catch (err) {
next(new HttpError(err.code || INTERNAL_SERVER_ERROR, err));
}
};

export { list, create, count, getById, get, update, del };
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Router } from 'express';

import { Routes } from '../types';
import { PLURAL_NAME } from './constants';
import { list, count, create, getById, get, update, del } from './controller';

const path = `/${PLURAL_NAME}`;

const routes = (_: Routes) => {
const router = Router();

router.param('id', getById);

router
.route('/')
.get(list)
.post(create);

router
.route('/count')
.get(count);

router
.route('/:id')
.get(get)
.put(update)
.delete(del);

return router;
};

export default { path, routes };
34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "generator-create-service-component",
"version": "1.1.1",
"description": "Boring Express Microservice Component Generator",
"homepage": "https://github.com/boringcodes/create-service-component",
"bugs": "https://github.com/boringcodes/create-service-component/issues",
"license": "MIT",
"author": "BoringCodes <hi@boringcodes.com> (https://boringcodes.com)",
"repository": "https://github.com/boringcodes/create-service-component.git",
"main": "generators/app/index.js",
"files": [
"generators"
],
"scripts": {
"purge": "rm -rf node_modules",
"release": "standard-version",
"release:major": "yarn release --release-as major",
"release:minor": "yarn release --release-as minor",
"release:patch": "yarn release --release-as patch"
},
"keywords": [
"yeoman-generator",
"create-service-component"
],
"dependencies": {
"chalk": "^3.0.0",
"pluralize": "^8.0.0",
"yeoman-generator": "^4.5.0",
"yosay": "^2.0.2"
},
"devDependencies": {
"standard-version": "^7.1.0"
}
}
Loading