Comparing version 2.2.2 to 2.2.3
@@ -5,10 +5,8 @@ { | ||
"main": "src/index.js", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"scripts": { | ||
"test": "ava test", | ||
"test:watch": "ava test --watch", | ||
"demo:dot": "node ./bin/as-a . node ./demo", | ||
"demo": "node ./bin/as-a demo node ./demo", | ||
"lint": "standard --verbose bin/*.js src/*.js test/*.js", | ||
"fix": "standard --verbose --fix bin/*.js src/*.js test/*.js", | ||
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";", | ||
"commit": "commit-wizard", | ||
@@ -54,22 +52,6 @@ "semantic-release": "semantic-release" | ||
"devDependencies": { | ||
"ava": "^4.0.1", | ||
"pre-git": "3.3.0", | ||
"semantic-release": "^17.4.4", | ||
"standard": "^16.0.4" | ||
}, | ||
"config": { | ||
"pre-git": { | ||
"commit-msg": [ | ||
"simple" | ||
], | ||
"pre-commit": [ | ||
"npm run lint" | ||
], | ||
"pre-push": [ | ||
"npm run size" | ||
], | ||
"post-commit": [], | ||
"post-merge": [] | ||
} | ||
"ava": "5", | ||
"prettier": "^3.1.1", | ||
"semantic-release": "22" | ||
} | ||
} |
@@ -11,3 +11,4 @@ # as-a | ||
Watch [Use Utility as-a To Load Multiple Secrets And Pass To Cypress](https://youtu.be/GyjCGKzFjWA) to see how I pass multiple values via environment variables when launching Cypress test runner. | ||
- 📺 Watch [Use Utility as-a To Load Multiple Secrets And Pass To Cypress](https://youtu.be/GyjCGKzFjWA) to see how I pass multiple values via environment variables when launching Cypress test runner. | ||
- 📺 Watch [Inject Entire Objects Into Cypress Tests Using as-a Utility](https://youtu.be/dxGhIvFNm4I) | ||
@@ -14,0 +15,0 @@ ## Install |
@@ -17,3 +17,3 @@ 'use strict' | ||
*/ | ||
function getSettings (name) { | ||
function getSettings(name) { | ||
la(is.unemptyString(name), 'expected env name', name) | ||
@@ -27,6 +27,10 @@ | ||
const ini = loadUserIni() | ||
return getSettingsFrom(name, ini) | ||
} | ||
const envNames = name.split(',') | ||
.map(_.trim) | ||
.filter(is.unemptyString) | ||
function getSettingsFrom(name, ini) { | ||
la(is.unemptyString(name), 'expected env name', name) | ||
la(ini, 'expected loaded ini object', ini) | ||
const envNames = name.split(',').map(_.trim).filter(is.unemptyString) | ||
debug('loading sections', envNames) | ||
@@ -40,5 +44,13 @@ | ||
const settings = ini[envName] | ||
la(is.object(settings), | ||
'expected settings for section', envName, 'not', settings) | ||
return settings | ||
// Trim the values of each setting | ||
const trimmedSettings = _.mapValues(settings, _.trim) | ||
la( | ||
is.object(trimmedSettings), | ||
'expected settings for section', | ||
envName, | ||
'not', | ||
trimmedSettings, | ||
) | ||
return trimmedSettings | ||
}) | ||
@@ -50,3 +62,3 @@ | ||
function asA (name, command) { | ||
function asA(name, command) { | ||
la(is.unemptyString(name), 'expected env name', name) | ||
@@ -57,9 +69,8 @@ la(is.array(command), 'expected command to run', command) | ||
runCommand(command, combined) | ||
.catch(function (error) { | ||
console.error(error) | ||
process.exit(-1) | ||
}) | ||
runCommand(command, combined).catch(function (error) { | ||
console.error(error) | ||
process.exit(-1) | ||
}) | ||
} | ||
module.exports = { asA, getSettings } | ||
module.exports = { asA, getSettings, getSettingsFrom } |
@@ -13,3 +13,3 @@ 'use strict' | ||
function readFiles (first, second) { | ||
function readFiles(first, second) { | ||
const firstSource = read(first, 'utf-8') | ||
@@ -24,7 +24,7 @@ if (!second) { | ||
function hasAliases (name) { | ||
function hasAliases(name) { | ||
return name.includes(',') | ||
} | ||
function loadIniFiles (filename1, filename2) { | ||
function loadIniFiles(filename1, filename2) { | ||
const readIni = readFiles.bind(null, filename1, filename2) | ||
@@ -44,3 +44,6 @@ const ini = new SimpleIni(readIni, { throwOnDuplicate: false }) | ||
debug('splitting section "%s" into multiple sections', sectionName) | ||
const aliases = sectionName.split(',').filter(Boolean).map(s => s.trim()) | ||
const aliases = sectionName | ||
.split(',') | ||
.filter(Boolean) | ||
.map((s) => s.trim()) | ||
aliases.forEach(function (alias) { | ||
@@ -56,14 +59,18 @@ ini[alias] = ini[sectionName] | ||
function loadUserIni () { | ||
function loadUserIni(useCurrentFolderOnly = false) { | ||
const localFile = join(process.cwd(), PROFILE_FILENAME) | ||
const localIniFilename = exists(localFile) ? localFile : undefined | ||
const fullProfileFilename = join(userHome, PROFILE_FILENAME) | ||
if (exists(fullProfileFilename)) { | ||
return loadIniFiles(fullProfileFilename, localIniFilename) | ||
if (!useCurrentFolderOnly) { | ||
const fullProfileFilename = join(userHome, PROFILE_FILENAME) | ||
if (exists(fullProfileFilename)) { | ||
return loadIniFiles(fullProfileFilename, localIniFilename) | ||
} | ||
} | ||
const profileInFolder = join(userHome, PROFILE_FOLDER, PROFILE_FILENAME) | ||
if (exists(profileInFolder)) { | ||
return loadIniFiles(profileInFolder, localIniFilename) | ||
if (!useCurrentFolderOnly) { | ||
const profileInFolder = join(userHome, PROFILE_FOLDER, PROFILE_FILENAME) | ||
if (exists(profileInFolder)) { | ||
return loadIniFiles(profileInFolder, localIniFilename) | ||
} | ||
} | ||
@@ -70,0 +77,0 @@ |
13856
3
183
218