Skip to content

Commit 7990c8b

Browse files
authored
Use different config files (#40)
* Add option for all config file extensions * Update the readme.md file for the configuration file * Move the require for the yaml file in the utils.js
1 parent 5e14ac8 commit 7990c8b

File tree

5 files changed

+67
-6
lines changed

5 files changed

+67
-6
lines changed

.grenrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ignoreIssuesWith": [
3+
"duplicate",
4+
"wontfix"
5+
]
6+
}

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Following the options for the module:
7474

7575
### Config file
7676

77-
You can create a `.gren.json` file where the task will be ran, where to specify your options.
77+
You can create a configuration file where the task will be ran, where to specify your options.
7878
The options in the file would be camelCase *e.g*:
7979

8080
```json
@@ -89,7 +89,15 @@ The options in the file would be camelCase *e.g*:
8989
}
9090
```
9191

92-
### Templates
92+
The accepted file extensions are the following:
93+
94+
- `.grenrc`
95+
- `.grenrc.json`
96+
- `.grenrc.yml`
97+
- `.grenrc.yaml`
98+
- `.grenrc.js`
99+
100+
#### Templates
93101

94102
You can configure the output of **gren** using templates. Set your own configuration inside the config file, which will be merged with the defaults, shown below:
95103

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"connectivity": "^1.0.0",
3737
"deep-assign": "^2.0.0",
3838
"es6-promise": "^3.2.1",
39-
"github-api": "^3.0.0"
39+
"github-api": "^3.0.0",
40+
"require-yaml": "0.0.1"
4041
},
4142
"devDependencies": {
4243
"eslint": "^3.6.0",

src/gren.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var Promise = Promise || require('es6-promise').Promise;
1010
var connectivity = require('connectivity');
1111
var templateConfig = require('./templates.json');
1212
var ObjectAssign = require('deep-assign');
13-
var configFile = fs.existsSync(process.cwd() + '/.gren.json') ? require(process.cwd() + '/.gren.json') : {};
13+
var configFile = utils.getConfigFromFile(process.cwd());
1414

1515
var defaults = {
1616
tags: false,
@@ -120,7 +120,7 @@ function prepareRelease(gren, block) {
120120

121121
if (block.id) {
122122
if (!gren.options.override) {
123-
console.warn(chalk.yellow('Skipping ' + block.release + ' (use --override to replace it)'));
123+
console.warn(chalk.black(chalk.bgYellow('Skipping ' + block.release + ' (use --override to replace it)')));
124124

125125
return Promise.resolve();
126126
}

src/utils.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

33
var chalk = require('chalk');
4+
var fs = require('fs');
5+
require('require-yaml');
46

57
/**
68
* Print a task name in a custom format
@@ -167,6 +169,49 @@ function formatDate(date) {
167169
return ('0' + date.getDate()).slice(-2) + '/' + ('0' + (date.getMonth() + 1)).slice(-2) + '/' + date.getFullYear();
168170
}
169171

172+
/**
173+
* Gets the content from a filepath a returns an object
174+
*
175+
* @since 0.6.0
176+
* @public
177+
*
178+
* @param {string} filepath
179+
* @return {Object|boolean}
180+
*/
181+
function requireConfig(filepath) {
182+
if (!fs.existsSync(filepath)) {
183+
return false;
184+
}
185+
186+
if (filepath.match(/\./g).length === 1) {
187+
return JSON.parse(fs.readFileSync(filepath, "utf8"));
188+
}
189+
190+
return require(filepath);
191+
}
192+
193+
/**
194+
* Get configuration from the one of the config files
195+
*
196+
* @since 0.6.0
197+
* @public
198+
*
199+
* @param {string} path Path where to look for config files
200+
* @return {Object} The configuration from the first found file or empty object
201+
*/
202+
function getConfigFromFile(path) {
203+
return [
204+
'.grenrc.yml',
205+
'.grenrc.json',
206+
'.grenrc.yaml',
207+
'.grenrc.js',
208+
'.grenrc'
209+
]
210+
.reduce(function(carry, filename) {
211+
return carry || requireConfig(path + '/' + filename);
212+
}, false) || {};
213+
}
214+
170215
module.exports = {
171216
printTask: printTask,
172217
task: task,
@@ -175,5 +220,6 @@ module.exports = {
175220
dashToCamelCase: dashToCamelCase,
176221
isInRange: isInRange,
177222
convertStringToArray: convertStringToArray,
178-
formatDate: formatDate
223+
formatDate: formatDate,
224+
getConfigFromFile: getConfigFromFile
179225
};

0 commit comments

Comments
 (0)