Skip to content

Commit

Permalink
feat: initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
boennemann committed Apr 29, 2016
1 parent 10e35b4 commit cb09252
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]

end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
*.log
*.dump
*.swp
.DS_Store
.nyc_output
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
sudo: false
language: node_js
cache:
directories:
- node_modules
notifications:
email: false
node_js:
- 6
- 4
- '0.12'
before_script:
- npm prune
after_success:
- 'curl -Lo travis_after_all.py https://git.io/travis_after_all'
- python travis_after_all.py
- 'export $(cat .to_export_back) &> /dev/null'
- npm run semantic-release
branches:
except:
- "/^v\\d+\\.\\d+\\.\\d+$/"
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @greenkeeper/rc

[![Build Status](https://travis-ci.org/greenkeeperio/rc.svg?branch=master)](https://travis-ci.org/greenkeeperio/rc)
[![Dependency Status](https://david-dm.org/greenkeeperio/rc/master.svg)](https://david-dm.org/greenkeeperio/rc/master)
[![devDependency Status](https://david-dm.org/greenkeeperio/rc/master/dev-status.svg)](https://david-dm.org/greenkeeperio/rc/master#info=devDependencies)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

`get`, `set`, `unset`, `replace` or `merge` Greenkeeper config and persist it to a `.greenkeeperrc` file in the homedir.
45 changes: 45 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var fs = require('fs')
var path = require('path')

var _ = require('lodash')
var home = require('os-homedir')

var configPath = path.join(home(), '.greenkeeperrc')

var config

try {
config = JSON.parse(fs.readFileSync(configPath))
} catch (e) {
config = {}
}

exports.get = function (name) {
return name
? config[name]
: config
}

exports.set = function (name, value) {
config[name] = value
exports._save()
}

exports.unset = function (name) {
delete config[name]
exports._save()
}

exports.replace = function (newConfig) {
config = newConfig
exports._save()
}

exports.merge = function (newConfig) {
_.merge(config, newConfig)
exports._save()
}

exports._save = function () {
fs.writeFileSync(configPath, JSON.stringify(config, null, 2))
}
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@greenkeeper/rc",
"description": "CRUD for .greenkeeperrc file",
"author": "Stephan Bönnemann <[email protected]> (http://boennemann.me)",
"bugs": {
"url": "https://github.com/greenkeeperio/rc/issues"
},
"dependencies": {
"lodash": "^4.11.1",
"os-homedir": "^1.0.1"
},
"devDependencies": {
"standard": "^6.0.8",
"semantic-release": "^4.3.5"
},
"homepage": "https://greenkeeper.io",
"license": "Apache-2.0",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/greenkeeperio/rc.git"
},
"scripts": {
"test": "standard",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"publishConfig": {
"access": "public"
}
}

0 comments on commit cb09252

Please sign in to comment.