Skip to content

Commit

Permalink
prettier, unquote, and test only on 7
Browse files Browse the repository at this point in the history
  • Loading branch information
xavdid committed Mar 29, 2018
1 parent 854cedd commit 5edd1f4
Show file tree
Hide file tree
Showing 11 changed files with 2,290 additions and 94 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -36,4 +36,5 @@ jspm_packages

# Optional REPL history
.node_repl_history
.vscode
.vscode
yarn.lock
1 change: 1 addition & 0 deletions .nvmrc
@@ -0,0 +1 @@
v7.6.0
6 changes: 3 additions & 3 deletions .travis.yml
@@ -1,7 +1,7 @@
language: node_js
# version specified by heroku
# https://github.com/heroku/cli/blob/master/Makefile

node_js:
- "6.9.5"
# the last version where mock-fs@3 works, which I need
- "7"
notifications:
on_failure: change
10 changes: 4 additions & 6 deletions bin/node_version_check
@@ -1,6 +1,8 @@
#! /usr/bin/env node

// verifies that we've got the correct node version
// they just run on a "recent version" now, so we don't need this
// "pretest": "./bin/node_version_check",

'use strict'

Expand Down Expand Up @@ -28,9 +30,7 @@ got(url, { json: true })

if (herokuVersion !== testVersion) {
console.error(
`!! Should be testing against ${herokuVersion}, not ${
testVersion
}. Update .travis.yml accordingly\n`
`!! Should be testing against ${herokuVersion}, not ${testVersion}. Update .travis.yml accordingly\n`
)
code = 1
}
Expand All @@ -42,9 +42,7 @@ got(url, { json: true })

if (localVersion !== testVersion) {
console.warn(
`[WARN]: Current node version (${
localVersion
}) does not match prod node version (${herokuVersion})`
`[WARN]: Current node version (${localVersion}) does not match prod node version (${herokuVersion})`
)
}

Expand Down
13 changes: 10 additions & 3 deletions commands/pull.js
Expand Up @@ -7,7 +7,8 @@ const _ = require('lodash')
const merge = require('../util/merge')
const file = require('../util/file')

function * pull (context, heroku) {
// eslint-disable-next-line generator-star-spacing, space-before-function-paren
function* pull(context, heroku) {
let fname = context.flags.file // this gets defaulted in read
let config = yield {
remote: heroku.get(`/apps/${context.app}/config-vars`),
Expand All @@ -32,14 +33,20 @@ function * pull (context, heroku) {

module.exports = (() => {
let flags = [
...require('../util/flags')
...require('../util/flags'),
{
name: 'unquoted',
char: 'u',
description: 'write configs locally without quotes'
}
]

return {
topic: 'config',
command: 'pull',
description: 'pull env variables from heroku',
help: 'Write remote config vars into file FILE, favoring existing local configs in case of collision',
help:
'Write remote config vars into file FILE, favoring existing local configs in case of collision',
needsApp: true,
needsAuth: true,
run: cli.command(co.wrap(pull)),
Expand Down
35 changes: 28 additions & 7 deletions commands/push.js
Expand Up @@ -6,7 +6,8 @@ const merge = require('../util/merge')
const file = require('../util/file')
const _ = require('lodash')

function * patchConfig (context, heroku, payload, success) {
// eslint-disable-next-line generator-star-spacing, space-before-function-paren
function* patchConfig(context, heroku, payload, success) {
try {
yield heroku.patch(`/apps/${context.app}/config-vars`, { body: payload })
if (!context.flags.quiet) {
Expand All @@ -17,36 +18,56 @@ function * patchConfig (context, heroku, payload, success) {
}
}

function * push (context, heroku) {
// eslint-disable-next-line generator-star-spacing, space-before-function-paren
function* push(context, heroku) {
let fname = context.flags.file // this gets defaulted in read
let config = yield {
remote: heroku.get(`/apps/${context.app}/config-vars`),
local: file.read(fname, context.flags)
}

let res = merge(config.local, config.remote, context.flags)
yield patchConfig(context, heroku, res, 'Successfully wrote settings to Heroku!')
yield patchConfig(
context,
heroku,
res,
'Successfully wrote settings to Heroku!'
)

if (context.flags.clean) {
// grab keys that weren't in local
let keysToDelete = _.difference(Object.keys(config.remote), Object.keys(config.local))
let keysToDelete = _.difference(
Object.keys(config.remote),
Object.keys(config.local)
)
let nullKeys = _.fromPairs(keysToDelete.map(k => [k, null]))

yield patchConfig(context, heroku, nullKeys, 'Successfully deleted unused settings from Heroku!')
yield patchConfig(
context,
heroku,
nullKeys,
'Successfully deleted unused settings from Heroku!'
)
}
}

module.exports = (() => {
let flags = [
...require('../util/flags'),
{ name: 'clean', char: 'c', description: 'delete all destination vars that do not appear in local file' }
{
name: 'clean',
char: 'c',
description:
'delete all destination vars that do not appear in local file'
}
]

return {
topic: 'config',
command: 'push',
description: 'push env variables to heroku',
help: 'Write local config vars into heroku, favoring existing remote configs in case of collision',
help:
'Write local config vars into heroku, favoring existing remote configs in case of collision',
needsApp: true,
needsAuth: true,
run: cli.command(co.wrap(push)),
Expand Down

0 comments on commit 5edd1f4

Please sign in to comment.