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

Updated dependencies and code style. #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 12 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ function loadConfig () {
if (fs.existsSync('config.yml')) {
return loadConfigFile('config.yml')
} else {
let templ = {}
const templ = {}
multiFile = true
let files = fs.readdirSync('config')
const files = fs.readdirSync('config')
for (let i = 0; i < files.length; i++) {
if (files[i].endsWith('.yml')) {
let keyName = files[i].substring(0, files[i].length - '.yml'.length)
const keyName = files[i].substring(0, files[i].length - '.yml'.length)
templ[keyName] = loadConfigFile('config/' + files[i])
}
}
Expand All @@ -58,7 +58,7 @@ function loadConfig () {

function getEnvIdFromBranch () {
try {
let branch = sh.exec('git name-rev HEAD --name-only', {silent: true}).stdout
let branch = sh.exec('git name-rev HEAD --name-only', { silent: true }).stdout

branch = _.last(_.split(branch, '/'))

Expand Down Expand Up @@ -86,27 +86,27 @@ function getEnvId (obj, env) {

function substitute (file, p) {
let success = false
let replaced = p.replace(/\${([\w.-]+)}/g, function (match, term) {
const replaced = p.replace(/\${([\w.-]+)}/g, function (match, term) {
if (!success) {
success = _.has(file, term)
}
return _.get(file, term) || match
})
return {success: success, replace: replaced}
return { success: success, replace: replaced }
}

function transform (file, obj) {
let changed = false
let resultant = _.mapValues(obj, function (p) {
const resultant = _.mapValues(obj, function (p) {
if (_.isPlainObject(p)) {
let transformed = transform(file, p)
const transformed = transform(file, p)
if (!changed && transformed.changed) {
changed = true
}
return transformed.result
}
if (_.isString(p)) {
let subbed = substitute(file, p)
const subbed = substitute(file, p)
if (!changed && subbed.success) {
changed = true
}
Expand All @@ -121,15 +121,15 @@ function transform (file, obj) {
}
return p
})
return {changed: changed, result: resultant}
return { changed: changed, result: resultant }
}

function log () {
console.log('CONFIG:', envId || '-', environmentType || '-')
}

function requireSettings (settings) {
let erredSettings = []
const erredSettings = []
settings = _.isString(settings) ? [settings] : settings
_.forEach(settings, function (setting) {
if (!_.has(config, setting)) {
Expand All @@ -150,7 +150,7 @@ function swapVariables (configFile) {
function readAndSwap (obj) {
let altered = false
do {
let temp = transform(obj, obj)
const temp = transform(obj, obj)
obj = temp.result
altered = temp.changed
} while (altered)
Expand Down
Loading