Skip to content

Commit 8cb354c

Browse files
committed
Merge branch 'richraid21-env-config'
2 parents 6dbd2ea + 76f3bc1 commit 8cb354c

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,26 @@ $ npm install -g create-component-app
2222
```sh
2323
$ cd ~/my-projects
2424
$ create-component-app
25+
```
26+
27+
### You can create a configuration file in your current project directory
28+
29+
Create a file in your project folder named `.ccarc`:
30+
31+
```javascript
32+
{
33+
"type": "stateless",
34+
"path": "./src/components",
35+
"jsExtension": "js",
36+
"cssExtension": "scss",
37+
"indexFile": false,
38+
"connected": false
39+
}
2540
```
2641

27-
### You can specify default values to save a lot of time
42+
### You can also pass a config file directory
2843

29-
If you want, you can set default values from a JSON:
44+
Create a JSON file `config.json`:
3045

3146
```javascript
3247
{
@@ -53,7 +68,9 @@ If you want, you can set default values from a JSON:
5368
and pass the path to config param
5469
```sh
5570
$ create-component-app --config path/to/your/config.json
56-
```
71+
```
72+
73+
Passing a config file via the CLI overrides the configuration file in the working directory
5774

5875
## Future
5976

src/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,19 @@ import { generateComponentTemplate, generateStyleFile, generateIndexFile } from
77
import questions from './questions'
88

99
// Dynamically import the config file if exist
10-
const configPath = yargs.argv.config
11-
const config = configPath ? require(`${process.cwd()}/${configPath}`) : null
10+
let config = null
11+
const argsConfigPath = yargs.argv.config
12+
const directoryConfig = `${process.cwd()}/.ccarc`
13+
14+
// Check if exist the default directory of configuration
15+
if (fs.existsSync(directoryConfig)) {
16+
config = JSON.parse(fs.readFileSync(directoryConfig, 'utf8'))
17+
}
18+
19+
// Override the config object from the directory if exist --config
20+
if (argsConfigPath) {
21+
config = require(`${process.cwd()}/${argsConfigPath}`)
22+
}
1223

1324
/**
1425
* Generate component files
@@ -43,9 +54,8 @@ function generateQuestions() {
4354
}
4455

4556
const filteredQuestions = []
46-
4757
questionKeys.forEach((question) => {
48-
if (!config[question]) {
58+
if (!config.hasOwnProperty(question)) {
4959
filteredQuestions.push(questions[question])
5060
}
5161
})

0 commit comments

Comments
 (0)