Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix settings commands #316

Merged
merged 3 commits into from
Jul 17, 2017
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"fs-extra": "^3.0.1",
"globby": "^6.1.0",
"inquirer": "^3.0.6",
"jsonpath": "^0.2.11",
"jsonwebtoken": "^7.4.0",
"latest-version": "^3.0.0",
"minimist": "^1.2.0",
Expand Down
13 changes: 8 additions & 5 deletions src/modules/apps/settings/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import * as jp from 'jsonpath'
import {path} from 'ramda'

import {apps} from '../../../clients'
import {dirnameJoin} from '../../../file'

const {getAppSettings} = apps

const FIELDS_START_INDEX = 2

export default {
description: 'Get app settings',
requiredArgs: 'app',
optionalArgs: 'field',
handler: (app: string, field: string) => {
optionalArgs: 'fields',
handler: (app: string, _, options) => {
const fields = options._.slice(FIELDS_START_INDEX)
return getAppSettings(app)
.then(res => field === null ? res : jp.value(res, `$.${field}`))
.then(msg => JSON.stringify(msg, null, 2))
.then(settings => fields === null ? settings : path(fields, settings))
.then(value => JSON.stringify(value, null, 2))
.tap(console.log)
},
set: {
Expand Down
33 changes: 25 additions & 8 deletions src/modules/apps/settings/set.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import * as jp from 'jsonpath'
import {last, assocPath, merge, __} from 'ramda'

import {apps} from '../../../clients'

const {saveAppSettings} = apps
const {getAppSettings, saveAppSettings} = apps

const FIELDS_START_INDEX = 3

const castValue = value => {
let parsedValue
try {
parsedValue = JSON.parse(value)
} catch (err) {
parsedValue = value
}
const numberCast = Number(value)
return isNaN(numberCast) ? parsedValue : numberCast
}

export default {
description: 'Set a value',
requiredArgs: ['app', 'field', 'value'],
handler: (app: string, field: string, value: string) => {
const patch = {}
jp.value(patch, '$.' + field, value)
return saveAppSettings(app, patch)
.then(res => JSON.stringify(res, null, 2))
requiredArgs: ['app', 'fields', 'value'],
handler: (app: string, _field, _value, options) => {
const value = last(options._)
const fields = options._.slice(FIELDS_START_INDEX, options._.length - 1)
const realValue = castValue(value)
const commandSettings = assocPath(fields, realValue, {})
return getAppSettings(app)
.then(merge(__, commandSettings))
.then(newSettings => JSON.stringify(newSettings, null, 2))
.tap(newSettings => saveAppSettings(app, newSettings))
.tap(console.log)
},
}
15 changes: 9 additions & 6 deletions src/modules/apps/settings/unset.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import * as jp from 'jsonpath'
import {dissocPath} from 'ramda'

import {apps} from '../../../clients'

const {getAppSettings, saveAppSettings} = apps

const FIELDS_START_INDEX = 3

export default {
description: 'Unset a value',
requiredArgs: ['app', 'field'],
handler: (app: string, field: string) => {
requiredArgs: ['app', 'fields'],
handler: (app: string, _, options) => {
const fields = options._.slice(FIELDS_START_INDEX)
return getAppSettings(app)
.tap(patch => jp.value(patch, `$.${field}`, null))
.then(patch => saveAppSettings(app, patch))
.then(res => JSON.stringify(res, null, 2))
.then(dissocPath(fields))
.then(newSettings => JSON.stringify(newSettings, null, 2))
.tap(newSettings => saveAppSettings(app, newSettings))
.tap(console.log)
},
}
128 changes: 16 additions & 112 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,6 @@
mime-types "^2.1.12"
multipart-stream "^2.0.1"

JSONSelect@0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/JSONSelect/-/JSONSelect-0.4.0.tgz#a08edcc67eb3fcbe99ed630855344a0cf282bb8d"

abbrev@1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f"
Expand Down Expand Up @@ -1054,10 +1050,6 @@ circular-json@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.1.tgz#be8b36aefccde8b3ca7aa2d6afc07a37242c0d2d"

cjson@~0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/cjson/-/cjson-0.2.1.tgz#73cd8aad65d9e1505f9af1744d3b79c1527682a5"

clean-stack@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-1.1.1.tgz#a1b3711122df162df7c7cb9b3c0470f28cb58adb"
Expand Down Expand Up @@ -1156,10 +1148,6 @@ color-name@^1.1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.2.tgz#5c8ab72b64bd2215d617ae9559ebb148475cf98d"

colors@0.5.x:
version "0.5.1"
resolved "https://registry.yarnpkg.com/colors/-/colors-0.5.1.tgz#7d0023eaeb154e8ee9fce75dcb923d0ed1667774"

colors@1.0.3, colors@1.0.x:
version "1.0.3"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
Expand Down Expand Up @@ -1454,10 +1442,6 @@ duplexer@~0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1"

ebnf-parser@~0.1.9:
version "0.1.10"
resolved "https://registry.yarnpkg.com/ebnf-parser/-/ebnf-parser-0.1.10.tgz#cd1f6ba477c5638c40c97ed9b572db5bab5d8331"

ecc-jsbn@~0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz#0fc73a9ed5f0d53c38193398523ef7e543777505"
Expand Down Expand Up @@ -1575,24 +1559,6 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.4, escape-string-regexp@^
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"

escodegen@0.0.21:
version "0.0.21"
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-0.0.21.tgz#53d652cfa1030388279458a5266c5ffc709c63c3"
dependencies:
esprima "~1.0.2"
estraverse "~0.0.4"
optionalDependencies:
source-map ">= 0.1.2"

escodegen@~0.0.24:
version "0.0.28"
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-0.0.28.tgz#0e4ff1715f328775d6cab51ac44a406cd7abffd3"
dependencies:
esprima "~1.0.2"
estraverse "~1.3.0"
optionalDependencies:
source-map ">= 0.1.2"

escope@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/escope/-/escope-3.6.0.tgz#e01975e812781a163a6dadfdd80398dc64c889c3"
Expand Down Expand Up @@ -1706,14 +1672,6 @@ espree@^3.4.0:
acorn "^5.0.1"
acorn-jsx "^3.0.0"

esprima@1.0.x, esprima@~1.0.2:
version "1.0.4"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-1.0.4.tgz#9f557e08fc3b4d26ece9dd34f8fbf476b62585ad"

esprima@1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-1.2.2.tgz#76a0fd66fcfe154fd292667dc264019750b1657b"

esprima@^2.6.0:
version "2.7.3"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581"
Expand Down Expand Up @@ -1745,14 +1703,6 @@ estraverse@^4.0.0, estraverse@^4.1.1, estraverse@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13"

estraverse@~0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-0.0.4.tgz#01a0932dfee574684a598af5a67c3bf9b6428db2"

estraverse@~1.3.0:
version "1.3.2"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-1.3.2.tgz#37c2b893ef13d723f276d878d60d8535152a6c42"

estraverse@~4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.1.1.tgz#f6caca728933a850ef90661d0e17982ba47111a2"
Expand Down Expand Up @@ -2687,26 +2637,6 @@ jest-validate@^19.0.2:
leven "^2.0.0"
pretty-format "^19.0.0"

jison-lex@0.2.x:
version "0.2.1"
resolved "https://registry.yarnpkg.com/jison-lex/-/jison-lex-0.2.1.tgz#ac4b815e8cce5132eb12b5dfcfe8d707b8844dfe"
dependencies:
lex-parser "0.1.x"
nomnom "1.5.2"

jison@0.4.13:
version "0.4.13"
resolved "https://registry.yarnpkg.com/jison/-/jison-0.4.13.tgz#9041707d62241367f58834532b9f19c2c36fac78"
dependencies:
JSONSelect "0.4.0"
cjson "~0.2.1"
ebnf-parser "~0.1.9"
escodegen "0.0.21"
esprima "1.0.x"
jison-lex "0.2.x"
lex-parser "~0.1.3"
nomnom "1.5.2"

jodid25519@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/jodid25519/-/jodid25519-1.0.2.tgz#06d4912255093419477d425633606e0e90782967"
Expand Down Expand Up @@ -2780,15 +2710,6 @@ jsonify@~0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"

jsonpath@^0.2.11:
version "0.2.11"
resolved "https://registry.yarnpkg.com/jsonpath/-/jsonpath-0.2.11.tgz#bfe22e0665b9712f8e7bdf7e2e1f8c08b594c60e"
dependencies:
esprima "1.2.2"
jison "0.4.13"
static-eval "0.2.3"
underscore "1.7.0"

jsonpointer@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/jsonpointer/-/jsonpointer-4.0.1.tgz#4fd92cb34e0e9db3c89c8622ecf51f9b978c6cb9"
Expand Down Expand Up @@ -2886,10 +2807,6 @@ levn@^0.3.0, levn@~0.3.0:
prelude-ls "~1.1.2"
type-check "~0.3.2"

lex-parser@0.1.x, lex-parser@~0.1.3:
version "0.1.4"
resolved "https://registry.yarnpkg.com/lex-parser/-/lex-parser-0.1.4.tgz#64c4f025f17fd53bfb45763faeb16f015a747550"

load-json-file@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-1.1.0.tgz#956905708d58b4bab4c2261b04f59f31c99374c0"
Expand Down Expand Up @@ -3172,13 +3089,6 @@ node-pre-gyp@^0.6.29:
tar "^2.2.1"
tar-pack "^3.4.0"

nomnom@1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/nomnom/-/nomnom-1.5.2.tgz#f4345448a853cfbd5c0d26320f2477ab0526fe2f"
dependencies:
colors "0.5.x"
underscore "1.1.x"

nopt@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.1.tgz#d0d4685afd5415193c8c7505602d0d17cd64474d"
Expand Down Expand Up @@ -4033,16 +3943,16 @@ sort-keys@^1.1.1, sort-keys@^1.1.2:
dependencies:
source-map "^0.5.6"

"source-map@>= 0.1.2", source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1:
version "0.5.6"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"

source-map@^0.4.4:
version "0.4.4"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b"
dependencies:
amdefine ">=0.0.4"

source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1:
version "0.5.6"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"

spawn-wrap@1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/spawn-wrap/-/spawn-wrap-1.2.4.tgz#920eb211a769c093eebfbd5b0e7a5d2e68ab2e40"
Expand Down Expand Up @@ -4101,12 +4011,6 @@ stack-utils@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-1.0.1.tgz#d4f33ab54e8e38778b0ca5cfd3b3afb12db68620"

static-eval@0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/static-eval/-/static-eval-0.2.3.tgz#023f17ac9fee426ea788c12ea39206dc175f8b2a"
dependencies:
escodegen "~0.0.24"

stream-combiner@~0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/stream-combiner/-/stream-combiner-0.0.4.tgz#4d5e433c185261dde623ca3f44c586bcf5c4ad14"
Expand Down Expand Up @@ -4327,7 +4231,11 @@ tryit@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb"

tslib@^1.0.0, tslib@^1.6.0:
tslib@^1.0.0:
version "1.7.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.1.tgz#bc8004164691923a79fe8378bbeb3da2017538ec"

tslib@^1.6.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.0.tgz#6e8366695f72961252b35167b0dd4fbeeafba491"

Expand All @@ -4336,8 +4244,8 @@ tslint-config-vtex@^1.2.0:
resolved "https://registry.yarnpkg.com/tslint-config-vtex/-/tslint-config-vtex-1.3.0.tgz#9b2ec36fb5caafa20722b6584aa9c1d291168721"

tslint-eslint-rules@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/tslint-eslint-rules/-/tslint-eslint-rules-4.0.0.tgz#4e0e59ecd5701c9a48c66ed47bdcafb1c635d27b"
version "4.1.1"
resolved "https://registry.yarnpkg.com/tslint-eslint-rules/-/tslint-eslint-rules-4.1.1.tgz#7c30e7882f26bc276bff91d2384975c69daf88ba"
dependencies:
doctrine "^0.7.2"
tslib "^1.0.0"
Expand All @@ -4358,7 +4266,11 @@ tslint@^5.2.0:
tslib "^1.6.0"
tsutils "^1.8.0"

tsutils@^1.4.0, tsutils@^1.8.0:
tsutils@^1.4.0:
version "1.9.1"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-1.9.1.tgz#b9f9ab44e55af9681831d5f28d0aeeaf5c750cb0"

tsutils@^1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-1.8.0.tgz#bf8118ed8e80cd5c9fc7d75728c7963d44ed2f52"

Expand Down Expand Up @@ -4411,14 +4323,6 @@ uid2@0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/uid2/-/uid2-0.0.3.tgz#483126e11774df2f71b8b639dcd799c376162b82"

underscore@1.1.x:
version "1.1.7"
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.1.7.tgz#40bab84bad19d230096e8d6ef628bff055d83db0"

underscore@1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.7.0.tgz#6bbaf0877500d36be34ecaa584e0db9fef035209"

unique-string@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unique-string/-/unique-string-1.0.0.tgz#9e1057cca851abb93398f8b33ae187b99caec11a"
Expand Down