Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
config
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libs
config
Commits
f798690c
Commit
f798690c
authored
1 year ago
by
Sigmund, Dominik
Browse files
Options
Downloads
Plain Diff
Merge branch '2-add-optional-prefix-for-env-variables' into 'main'
Fix constructor Closes
#2
See merge request
!8
parents
aef91218
a680b8f8
No related branches found
No related tags found
1 merge request
!8
Fix constructor
Pipeline
#129471
failed
4 months ago
Stage: test
Changes
3
Pipelines
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
index.js
+3
-2
3 additions, 2 deletions
index.js
index.test.js
+11
-11
11 additions, 11 deletions
index.test.js
package.json
+1
-1
1 addition, 1 deletion
package.json
with
15 additions
and
14 deletions
index.js
+
3
−
2
View file @
f798690c
...
@@ -2,7 +2,7 @@ var fs = require('fs')
...
@@ -2,7 +2,7 @@ var fs = require('fs')
var
path
=
require
(
'
path
'
)
var
path
=
require
(
'
path
'
)
var
merge
=
require
(
'
lodash.merge
'
)
var
merge
=
require
(
'
lodash.merge
'
)
module
.
exports
=
function
(
basePath
=
undefined
,
envPrefix
=
undefined
)
{
function
createConfig
(
basePath
=
undefined
,
envPrefix
=
undefined
)
{
let
configDefaults
let
configDefaults
let
configLocal
let
configLocal
let
envPrefixUpper
=
envPrefix
?
envPrefix
.
toUpperCase
()
+
"
_
"
:
''
let
envPrefixUpper
=
envPrefix
?
envPrefix
.
toUpperCase
()
+
"
_
"
:
''
...
@@ -105,3 +105,4 @@ module.exports = function(basePath = undefined, envPrefix = undefined) {
...
@@ -105,3 +105,4 @@ module.exports = function(basePath = undefined, envPrefix = undefined) {
config
.
_reload
()
config
.
_reload
()
return
config
return
config
}
}
module
.
exports
=
{
createConfig
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
index.test.js
+
11
−
11
View file @
f798690c
const
fs
=
require
(
'
fs
'
).
promises
const
fs
=
require
(
'
fs
'
).
promises
const
Config
=
require
(
'
./index
'
)
const
create
Config
=
require
(
'
./index
'
)
.
createConfig
let
jsonDefaults
=
{
let
jsonDefaults
=
{
setting
:
"
defaultvalue
"
,
setting
:
"
defaultvalue
"
,
...
@@ -25,7 +25,7 @@ describe('config', function() {
...
@@ -25,7 +25,7 @@ describe('config', function() {
it
(
'
should only have values from config.defaults.json
'
,
async
function
()
{
it
(
'
should only have values from config.defaults.json
'
,
async
function
()
{
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.defaults.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
expect
(
config
.
setting
).
toBe
(
'
defaultvalue
'
)
expect
(
config
.
setting
).
toBe
(
'
defaultvalue
'
)
...
@@ -34,7 +34,7 @@ describe('config', function() {
...
@@ -34,7 +34,7 @@ describe('config', function() {
it
(
'
should only have values from config.json
'
,
async
function
()
{
it
(
'
should only have values from config.json
'
,
async
function
()
{
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.json
'
)
expect
(
config
.
setting
).
toBe
(
'
localvalue
'
)
expect
(
config
.
setting
).
toBe
(
'
localvalue
'
)
...
@@ -44,7 +44,7 @@ describe('config', function() {
...
@@ -44,7 +44,7 @@ describe('config', function() {
it
(
'
should have both values with preference to config.json
'
,
async
function
()
{
it
(
'
should have both values with preference to config.json
'
,
async
function
()
{
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
...
@@ -57,7 +57,7 @@ describe('config', function() {
...
@@ -57,7 +57,7 @@ describe('config', function() {
await
fs
.
mkdir
(
'
tmp
'
)
await
fs
.
mkdir
(
'
tmp
'
)
await
fs
.
writeFile
(
'
tmp/config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
tmp/config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
tmp/config.json
'
,
JSON
.
stringify
(
jsonLocals
))
await
fs
.
writeFile
(
'
tmp/config.json
'
,
JSON
.
stringify
(
jsonLocals
))
let
config
=
new
Config
(
'
tmp
'
)
let
config
=
create
Config
(
'
tmp
'
)
await
fs
.
unlink
(
'
tmp/config.json
'
)
await
fs
.
unlink
(
'
tmp/config.json
'
)
await
fs
.
unlink
(
'
tmp/config.defaults.json
'
)
await
fs
.
unlink
(
'
tmp/config.defaults.json
'
)
await
fs
.
rmdir
(
'
tmp
'
)
await
fs
.
rmdir
(
'
tmp
'
)
...
@@ -75,7 +75,7 @@ describe('config', function() {
...
@@ -75,7 +75,7 @@ describe('config', function() {
process
.
env
[
'
ANOTHER_MORE
'
]
=
'
false
'
process
.
env
[
'
ANOTHER_MORE
'
]
=
'
false
'
process
.
env
[
'
EVEN_DEEPER_KEY
'
]
=
'
true
'
process
.
env
[
'
EVEN_DEEPER_KEY
'
]
=
'
true
'
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
...
@@ -98,7 +98,7 @@ describe('config', function() {
...
@@ -98,7 +98,7 @@ describe('config', function() {
process
.
env
[
'
P_ANOTHER_MORE
'
]
=
'
false
'
process
.
env
[
'
P_ANOTHER_MORE
'
]
=
'
false
'
process
.
env
[
'
P_EVEN_DEEPER_KEY
'
]
=
'
true
'
process
.
env
[
'
P_EVEN_DEEPER_KEY
'
]
=
'
true
'
let
config
=
new
Config
(
undefined
,
'
p
'
)
let
config
=
create
Config
(
undefined
,
'
p
'
)
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
...
@@ -119,7 +119,7 @@ describe('config', function() {
...
@@ -119,7 +119,7 @@ describe('config', function() {
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
await
fs
.
writeFile
(
'
file.txt
'
,
'
value-from-file
'
)
await
fs
.
writeFile
(
'
file.txt
'
,
'
value-from-file
'
)
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
...
@@ -133,7 +133,7 @@ describe('config', function() {
...
@@ -133,7 +133,7 @@ describe('config', function() {
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
...
@@ -146,7 +146,7 @@ describe('config', function() {
...
@@ -146,7 +146,7 @@ describe('config', function() {
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
let
config
=
new
Config
()
let
config
=
create
Config
()
expect
(
config
.
setting
).
toBe
(
'
localvalue
'
)
expect
(
config
.
setting
).
toBe
(
'
localvalue
'
)
...
@@ -165,7 +165,7 @@ describe('config', function() {
...
@@ -165,7 +165,7 @@ describe('config', function() {
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
...
...
This diff is collapsed.
Click to expand it.
package.json
+
1
−
1
View file @
f798690c
{
{
"name"
:
"@libs/config"
,
"name"
:
"@libs/config"
,
"version"
:
"1.13.
5
"
,
"version"
:
"1.13.
6
"
,
"description"
:
"Simple Config with ENV Support"
,
"description"
:
"Simple Config with ENV Support"
,
"main"
:
"index.js"
,
"main"
:
"index.js"
,
"scripts"
:
{
"scripts"
:
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment