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
17 changes: 17 additions & 0 deletions .ccarc.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"templatesDirPath": "./templates",
"path": "./src/components",
"jsExtension": "js",
"cssExtension": "css",
"includeTests": true,
"includeStories": true,
"indexFile": false,
"connected": false,
"componentMethods": [],
"fileNames": {
"testFileMatch": "spec",
"testFileName": "myTest",
"componentFileName": "template",
"styleFileName": "style"
}
}
83 changes: 22 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,71 +81,32 @@ and searching up the file tree until a config file is (or isn't) found.

### Basic Configuration

JSON:

```json
// .ccarc
{
"type": "class",
"path": "./src/components"
}
```

YAML:

```yaml
# .ccarc
type: class
path: ./src/components
```
An example configuration file can be found here: [.ccarc.example](.ccarc.example), you can use this
file by copying it to the root of your project.

Currently supported options are:

Option | Description
--- | ---
`type` | Default type of the component `["stateless", "class", "pure"]`
`templatesDirPath` | Default path to get the templates from the custom templates folder
`path` | Default path to create component file and folder
`jsExtension` | Default extension for your javascript file `["js", "jsx"]`
`cssExtension` | Default extension for your css file `["css", "scss", "sass", "less", false]`. Set to false if you don't want a style file
`includeTests` | Default flag to include a test file in the folder `[true, false]`
`includeStories` | Default flag to include a storybook file in the folder `[true, false]`
`indexFile` | Default flag to create an index file in the folder `[false, true]`
`connected` | Default flag to integrate connect redux in the index file `[false, true]`
`componentMethods` | Only for "class" and "pure", insert method inside the component (i.e. `["componentDidMount", "shouldComponentUpdate", "onClick"]`)
`fileNames` | Choose the specific filename for your component's file.
`fileNames.testFileMatch` | specify the match part of test file
`fileNames.testFileName` | specify the file name of your test file
`fileNames.componentFileName` | specify the component file name
`fileNames.styleFileName` | specify the style file name !!IMPORTANT: Include cssExtension.

### You can also pass a config file

1) Create a JSON file `config.json`:

```javascript
{
// Default type of component ["stateless", "class", "pure"]
"type": "stateless",

// Default path to get the templates from the custom templates folder
"templatesDirPath": "./templates",

// Default path to create component file and folder
"path": "./src/components",

// Default extension for your javascript file ["js", "jsx"]
"jsExtension": "js",

// Default extension for your css file ["css", "scss", "sass", "less", false]
// Set to false if you don't want a style file
"cssExtension": "css",

// Default flag to include a test file in the folder [true, false]
"includeTests": true,

// Default flag to include a storybook file in the folder [true, false]
"includeStories": true,

// Default flag to create an index file in the folder [false, true]
"indexFile": false,

// Default flag to integrate connect redux in the index file [false, true]
"connected": false,

// Only for "class" and "pure", insert method inside the component
"componentMethods": ["componentDidMount", "shouldComponentUpdate", "onClick"],

// Choose the specific filename for your component's file.
"fileNames": {
"testFileMatch": "spec", // specify the match part of test file
"testFileName": "myTest", // specify the file name of your test file
"componentFileName": "template", // specify the component file name
"styleFileName": "style" // specify the style file name !!IMPORTANT: Include cssExtension.
}
}
```

2) and pass the path to config param

```sh
Expand Down
22 changes: 10 additions & 12 deletions src/logger.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
/* eslint-disable no-console */
import chalk from 'chalk'

const Logger = {
log(msg) {
/* eslint-disable no-console */
return console.log(chalk.green(JSON.stringify(msg)))
/* eslint-enable no-console */
log(...msg) {
return console.log(chalk.green('[Info]'), ...msg)
},
error(msg) {
/* eslint-disable no-console */
return console.error(chalk.bold.red(JSON.stringify(msg)))
/* eslint-enable no-console */
error(...msg) {
return console.error(chalk.bold.red('[Error]'), ...msg)
},
warn(msg) {
/* eslint-disable no-console */
return console.warn(chalk.keyword('orange')(JSON.stringify(msg)))
/* eslint-enable no-console */
warn(...msg) {
return console.warn(chalk.keyword('orange')('[Warn]'), ...msg)
},
debug(...msg) {
return console.warn(chalk.blue('[Debug]'), ...msg)
},
}

Expand Down
13 changes: 10 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,17 @@ function getConfig(configPath, searchPath = process.cwd(), stopDir = homedir())
const configPathAbsolute = useCustomPath && path.join(process.cwd(), configPath)
// search from the root of the process if the user didnt specify a config file,
// or use the custom path if a file is passed.
const { config, filepath } = explorer.load(searchPathAbsolute, configPathAbsolute)
return { ...(config || {}), filepath }
const result = explorer.load(searchPathAbsolute, configPathAbsolute)

// dont throw if the explorer didnt find a configfile,
// instead use default config
const config = result ? result.config : {}
const filepath = result ? result.filepath : {}
if (!result) Logger.log('No config file detected, using defaults.')

return { ...config, filepath }
} catch (error) {
Logger.error('Bad config file, Please check config file syntax')
Logger.error('An error occured while parsing your config file. Using defaults...\n\n', error.message)
}
return {}
}
Expand Down