Skip to content

Commit 37fc23f

Browse files
committed
feat: init
1 parent d818677 commit 37fc23f

File tree

4 files changed

+136
-2
lines changed

4 files changed

+136
-2
lines changed

README.TEMPLATE.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# react-hooks-<%= name %>
2+
3+
[![NPM version][npm-image]][npm-url]
4+
[![npm download][download-image]][download-url]
5+
[![Build Status][travis-image]][travis-url]
6+
7+
<%= desc %>
8+
9+
## Install
10+
11+
>**Note:** The Hooks isn't stable now, the stable version will be available on [Q1 of 2019](https://reactjs.org/blog/2018/11/27/react-16-roadmap.html).
12+
>
13+
>Make sure that you have installed the correct version of `react(>= v16.7.0-alpha)` and `react-dom(>= v16.7.0-alpha)`.
14+
15+
### npm
16+
17+
```bash
18+
npm install --save @use-hooks/<%= name %>
19+
```
20+
21+
### yarn
22+
23+
```bash
24+
yarn add @use-hooks/<%= name %>
25+
```
26+
27+
## API
28+
29+
### Params
30+
31+
```js
32+
<%= params %>
33+
```
34+
35+
### Returns
36+
37+
```js
38+
<%= returns %>
39+
```
40+
41+
## Usage
42+
43+
```js
44+
<%- example %>
45+
```
46+
47+
[Live Show](https://use-hooks.github.io/react-hooks-<%= name %>/)
48+
49+
## Development
50+
51+
> Node >= v8 LTS
52+
53+
- Clone the project to local disk
54+
- `npm install`
55+
- `npm start`
56+
57+
## License
58+
59+
MIT
60+
61+
> Generated by [create-react-hooks](https://github.com/use-hooks/create-react-hooks).
62+
63+
[npm-image]: https://img.shields.io/npm/v/@use-hooks/<%= name %>.svg?style=flat-square
64+
[npm-url]: https://npmjs.org/package/@use-hooks/<%= name %>
65+
[download-image]: https://img.shields.io/npm/dm/@use-hooks/<%= name %>.svg?style=flat-square
66+
[download-url]: https://npmjs.org/package/@use-hooks/<%= name %>
67+
[travis-url]: https://travis-ci.org/use-hooks/react-hooks-<%= name %>
68+
[travis-image]: https://img.shields.io/travis/use-hooks/react-hooks-<%= name %>.svg?style=flat-square

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# readme-generator
2-
Readme Generator
1+
# use-hooks-readme
2+
3+
Readme Generator for Use Hooks

index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env node
2+
3+
const { readFileSync, writeFileSync } = require('fs');
4+
const { join } = require('path');
5+
const { render } = require('ejs');
6+
7+
const pkg = require(join(process.cwd(), 'package.json'));
8+
9+
if (!/^@use-hooks\//.test(pkg.name)) {
10+
console.error('ERROR: Only for @use-hooks packages.');
11+
process.exit(0);
12+
}
13+
14+
const jsdocRegex = /[ \t]*\/\*\*\s*\n([^*]*(\*[^/])?)*\*\//g;
15+
const sourceCode = readFileSync(join(process.cwd(), 'src/index.js'), 'utf8');
16+
17+
const jsdocs = sourceCode.match(jsdocRegex);
18+
19+
if (
20+
!jsdocs
21+
|| jsdocs.length !== 2
22+
|| !jsdocs[0].includes('Params')
23+
|| !jsdocs[1].includes('Returns')
24+
) {
25+
console.error('ERROR: Invalid format of JSDoc.');
26+
process.exit(0);
27+
}
28+
29+
const example = readFileSync(join(process.cwd(), 'example/App.jsx'), 'utf8');
30+
31+
const readmeTpl = readFileSync(join(__dirname, 'README.TEMPLATE.md'), 'utf8');
32+
33+
const readme = render(readmeTpl, {
34+
name: pkg.name.split('/')[1],
35+
desc: pkg.description,
36+
params: jsdocs[0],
37+
returns: jsdocs[1],
38+
example: example.replace('../src', pkg.name),
39+
});
40+
41+
writeFileSync(join(process.cwd(), 'README.md'), readme, 'utf8');

package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "use-hooks-readme",
3+
"version": "1.0.0",
4+
"description": "Readme Generator",
5+
"main": "index.js",
6+
"bin": "index.js",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/use-hooks/readme-generator.git"
10+
},
11+
"keywords": [
12+
"react",
13+
"react-hooks"
14+
],
15+
"author": "Cody Chan <int64ago@gmail.com>",
16+
"license": "MIT",
17+
"bugs": {
18+
"url": "https://github.com/use-hooks/readme-generator/issues"
19+
},
20+
"homepage": "https://github.com/use-hooks/readme-generator#readme",
21+
"dependencies": {
22+
"ejs": "^2.6.1"
23+
}
24+
}

0 commit comments

Comments
 (0)