Skip to content

Commit 86607b5

Browse files
committed
Add init option
1 parent d781738 commit 86607b5

11 files changed

Lines changed: 332 additions & 59 deletions

File tree

.babelrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"exclude": [
7+
"transform-regenerator"
8+
]
9+
}
10+
]
11+
]
12+
}

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,22 @@ It helps you to speed up productivity in React projects and stop copying, pastin
55

66
## Installation
77

8-
To install the latest version run this command:
8+
To install the latest version run the following command:
99

1010
```sh
11-
npm install generate-react-code --save-dev
11+
npm i react-codegen-cli --save-dev
1212
```
1313

14-
Then add the following script to your `packages.json` file:
15-
```json
16-
{
17-
"scripts": {
18-
"react-codegen": "react-codegen"
19-
}
20-
}
14+
React CodeGen lets you setup everything by simply running the following command:
15+
16+
```sh
17+
npx react-codegen-cli init
2118
```
2219

23-
## Get started
20+
Question by question, it will guide you through the whole process of setting up a configuration file,
21+
selecting stylesheet format, picking a destination of generated files, and a lot more.
2422

25-
`react-codegen` will look for a [configuration file](#configuration-file) in root folder and use it if available.
26-
If no config file found it will fallback to a default configuration.
23+
## Get Started
2724

2825
The following command can be used to generate code:
2926
```sh
@@ -38,8 +35,9 @@ such as connecting the `useState`, `useEffect`, `propTypes` and so on.
3835
![Demo](https://i.imgur.com/TFykAL4.png)
3936
![Demo2](https://i.imgur.com/uEMSlCz.png)
4037

41-
## Configuration file
42-
38+
## Configuration File
39+
40+
You also can set-up configuration file manually.
4341
React codegen uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for configuration file support. This means you can configure it via:
4442

4543
- A `"react-codegen"` key in your `package.json` file.
@@ -48,11 +46,14 @@ React codegen uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig)
4846

4947
The configuration file will be resolved in the root folder of the project. If no configuration file found the default config will be used.
5048

49+
`react-codegen` will look for a [configuration file](#configuration-file) in root folder and use it if available.
50+
If no config file found it will fallback to a default configuration.
51+
5152
### Configuration Options
5253

5354
| Type | Value | Default | Description |
5455
|:------------:|:------------------------------------------------------------:|:--------------:|----------------------------------------------------------------------|
55-
| styles | string | scss | Extension for style file |
56+
| styles | string | scss | Stylesheet format |
5657
| typescript | boolean | false | Generate typescript files |
5758
| jsxExt | boolean | true | Use `jsx` extension for components |
5859
| fileNameCase | came,<br/> pascal,<br/> snake,<br/> snakeUpper,<br/> kebab | pascal | File name case for generated files<br/> (default: `MyComponent.jsx`) |

package-lock.json

Lines changed: 113 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "react-codegen-cli",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "Software Development Kit for React",
5-
"main": "lib/index.js",
5+
"main": "lib/bin.js",
66
"bin": {
77
"react-codegen": "lib/index.js"
88
},
@@ -17,33 +17,24 @@
1717
"pre-push": "npm run lint"
1818
}
1919
},
20-
"babel": {
21-
"presets": [
22-
[
23-
"@babel/preset-env",
24-
{
25-
"exclude": [
26-
"transform-regenerator"
27-
]
28-
}
29-
]
30-
]
31-
},
3220
"dependencies": {
3321
"@babel/generator": "^7.10.1",
3422
"@babel/parser": "^7.10.1",
3523
"@babel/template": "^7.10.1",
3624
"@babel/traverse": "^7.10.1",
3725
"@babel/types": "^7.10.1",
3826
"chalk": "^4.0.0",
27+
"console-clear": "^1.1.1",
3928
"cosmiconfig": "^6.0.0",
29+
"detect-indent": "^6.0.0",
4030
"find-up": "^4.1.0",
4131
"fs-extra": "^9.0.0",
4232
"inquirer": "^7.1.0",
4333
"lodash": "^4.17.15",
4434
"log-symbols": "^4.0.0",
4535
"mustache": "^4.0.1",
46-
"prettier": "^2.0.5"
36+
"prettier": "^2.0.5",
37+
"yargs": "^15.3.1"
4738
},
4839
"devDependencies": {
4940
"@babel/cli": "^7.10.1",
@@ -53,6 +44,7 @@
5344
"@types/babel-types": "^7.0.7",
5445
"@types/fs-extra": "^9.0.1",
5546
"@types/inquirer": "^6.5.0",
47+
"@types/yargs": "^15.0.5",
5648
"eslint": "^6.8.0",
5749
"eslint-config-airbnb-base": "^14.1.0",
5850
"eslint-config-prettier": "^6.11.0",

src/bin.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env node
2+
3+
import { argv } from 'yargs';
4+
import { Logger } from './core/Logger';
5+
import { runCLI } from './index';
6+
7+
runCLI(argv._[0] === 'init')
8+
.then(() => process.exit(0))
9+
.catch(err => {
10+
Logger.error(err);
11+
process.exit(1);
12+
});

src/core/Logger.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class Logger {
3939
}
4040

4141
static log(value, color = 'white', icon) {
42+
if (typeof value === 'function') value = value(chalk);
4243
if (icon) return console.log(icon, chalk[color](value));
4344
return console.log(chalk[color](value));
4445
}

0 commit comments

Comments
 (0)