From 142a46d91d6ed91ebae9c04ffacf01cf60c085f1 Mon Sep 17 00:00:00 2001 From: Michael Albertz Date: Thu, 23 Nov 2017 14:54:44 +0100 Subject: [PATCH 1/4] dont throw if no configuration file was found --- src/utils.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/utils.js b/src/utils.js index df90543..d5e24e1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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 {} } From a18f45b8f5f5af8b708c432d2935af361e33c240 Mon Sep 17 00:00:00 2001 From: Michael Albertz Date: Thu, 23 Nov 2017 14:55:44 +0100 Subject: [PATCH 2/4] added support for multiple arguments to the logger --- src/logger.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/logger.js b/src/logger.js index d55fc39..8c611fb 100644 --- a/src/logger.js +++ b/src/logger.js @@ -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) }, } From 0ec118a92bfd5cb78d003502e7fc7471732e0fbd Mon Sep 17 00:00:00 2001 From: Michael Albertz Date: Thu, 23 Nov 2017 14:56:14 +0100 Subject: [PATCH 3/4] added an example configuration file --- .ccarc.example | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .ccarc.example diff --git a/.ccarc.example b/.ccarc.example new file mode 100644 index 0000000..e8b0f0d --- /dev/null +++ b/.ccarc.example @@ -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" + } +} From da8e5213bd98d2d84da71a51b312baa471868ad3 Mon Sep 17 00:00:00 2001 From: Michael Albertz Date: Thu, 23 Nov 2017 15:17:33 +0100 Subject: [PATCH 4/4] updated the readme easier instructions to configuration --- README.md | 83 +++++++++++++++---------------------------------------- 1 file changed, 22 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index c656549..21d5c6e 100644 --- a/README.md +++ b/README.md @@ -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