configorama 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -80,6 +80,9 @@ const config = configorama.sync(myConfigFilePath, {
80
80
 
81
81
  ```yml
82
82
  apiKey: ${env:SECRET_KEY}
83
+
84
+ # Fallback to default value if env var not found
85
+ apiKeyWithFallback: ${env:SECRET_KEY, 'defaultApiKey'}
83
86
  ```
84
87
 
85
88
  ### CLI option flags
@@ -90,6 +93,9 @@ bar: ${opt:stage}
90
93
 
91
94
  # Composed example makes `foo: dev-hello`
92
95
  foo: ${opt:stage}-hello
96
+
97
+ # You can also provide a default value. If no --stage flag is provided, it will use 'dev'
98
+ foo: ${opt:stage, 'dev'}
93
99
  ```
94
100
 
95
101
  ### Self references
@@ -97,26 +103,34 @@ foo: ${opt:stage}-hello
97
103
  ```yml
98
104
  foo: bar
99
105
 
106
+ zaz:
107
+ matazaz: 1
108
+ wow:
109
+ cool: 2
110
+
100
111
  # Self file reference. Resolves to `bar`
101
112
  one: ${self:foo}
102
113
 
103
114
  # Shorthand self reference. Resolves to `bar`
104
- two: ${foo}
115
+ two: ${foo}
116
+
117
+ # Dot prop reference will traverse the object. Resolves to `2`
118
+ three: ${zaz.wow.cool}
105
119
  ```
106
120
 
107
121
  ### File references
108
122
 
109
123
  ```yml
110
- # import full yml/json/toml file via relative path
111
- yamlFileRef: ${file(./subFile.yml)}
124
+ # Import full yml/json/toml file via relative path
125
+ fileRef: ${file(./subFile.yml)}
112
126
 
113
- # import sub values from files. This imports other-config.yml `topLevel:` value
114
- yamlFileValue: ${file(./other-config.yml):topLevel}
127
+ # Import sub values from files. This imports other-config.yml `topLevel:` value
128
+ fileValue: ${file(./other-config.yml):topLevel}
115
129
 
116
- # import sub values from files. This imports other-config.json `nested.value` value
117
- yamlFileValueSubKey: ${file(./other-config.json):nested.value}
130
+ # Import sub values from files. This imports other-config.json `nested.value` value
131
+ fileValueSubKey: ${file(./other-config.json):nested.value}
118
132
 
119
- # fallback to default value if file not found
133
+ # Fallback to default value if file not found
120
134
  fallbackValueExample: ${file(./not-found.yml), 'fall back value'}
121
135
  ```
122
136
 
@@ -131,46 +145,74 @@ asyncJSValue: ${file(./async-value.js)}
131
145
 
132
146
  ```js
133
147
  /* async-value.js */
134
- module.exports = (config) => {
135
- return fetchSecretsFromRemoteStore()
148
+ function delay(t, v) {
149
+ return new Promise((resolve) => setTimeout(resolve.bind(null, v), t))
136
150
  }
137
151
 
138
- function fetchSecretsFromRemoteStore() {
139
- return delay(1000).then(() => {
140
- return Promise.resolve('asyncval')
141
- })
152
+ async function fetchSecretsFromRemoteStore(config) {
153
+ await delay(1000)
154
+ return 'asyncval'
142
155
  }
143
156
 
144
- function delay(t, v) {
145
- return new Promise((resolve) => setTimeout(resolve.bind(null, v), t))
146
- }
157
+ module.exports = fetchSecretsFromRemoteStore
147
158
  ```
148
159
 
149
160
  ### Git references
150
161
 
151
162
  Resolve values from `cwd` git data.
152
163
 
164
+ <!-- doc-gen CODE src=tests/gitVariables/gitVariables.yml -->
153
165
  ```yml
166
+ ########################
167
+ # Git Variables
168
+ ########################
169
+
170
+ # Repo owner/name. E.g. DavidWells/configorama
171
+ repo: ${git:repo}
154
172
  repository: ${git:repository}
155
173
 
156
- describe: ${git:describe}
174
+ # Repo owner. E.g. DavidWells
175
+ owner: ${git:owner}
176
+ repoOwner: ${git:repoOwner}
177
+ repoOwnerDashed: ${git:repo-owner}
178
+
179
+ # Url. E.g. https://github.com/DavidWells/configorama
180
+ url: ${git:url}
181
+ repoUrl: ${git:repoUrl}
182
+ repoUrlDashed: ${git:repo-url}
157
183
 
184
+ # Directory. E.g. https://github.com/DavidWells/configorama/tree/master/tests/gitVariables
185
+ dir: ${git:dir}
186
+ directory: ${git:directory}
187
+
188
+ # Branch
158
189
  branch: ${git:branch}
159
190
 
191
+ # Commits. E.g. 785fa6b982d67b079d53099d57c27fa87c075211
160
192
  commit: ${git:commit}
161
193
 
194
+ # Sha1. E.g. 785fa6b
162
195
  sha1: ${git:sha1}
163
196
 
197
+ # Message. E.g. 'Initial commit'
164
198
  message: ${git:message}
165
199
 
200
+ # Remotes. E.g. https://github.com/DavidWells/configorama
166
201
  remote: ${git:remote}
167
-
168
202
  remoteDefined: ${git:remote('origin')}
169
-
170
203
  remoteDefinedNoQuotes: ${git:remote(origin)}
171
204
 
172
- repoUrl: ${git:repoUrl}
205
+ # Tags. E.g. v0.5.2-1-g785fa6b
206
+ tag: ${git:tag}
207
+ # Describe. E.g. v0.5.2-1-g785fa6b
208
+ describe: ${git:describe}
209
+
210
+ # Timestamp. E.g. 2025-01-28T07:28:53.000Z
211
+ gitTimestampRelativePath: ${git:timestamp('../../package.json')}
212
+ # Timestamp. E.g. 2025-01-28T07:28:53.000Z
213
+ gitTimestampAbsolutePath: ${git:timestamp('package.json')}
173
214
  ```
215
+ <!-- end-doc-gen -->
174
216
 
175
217
  ### Filters (experimental)
176
218
 
package/cli.js CHANGED
@@ -3,17 +3,17 @@
3
3
  const fs = require('fs')
4
4
  const minimist = require('minimist')
5
5
  const Configorama = require('./src/main')
6
+ const deepLog = require('./src/utils/deep-log')
6
7
 
7
8
  // Parse command line arguments
8
9
  const argv = minimist(process.argv.slice(2), {
9
10
  string: ['output', 'o', 'format', 'f'],
10
- boolean: ['help', 'h', 'version', 'v', 'debug', 'd', 'allow-unknown', 'allow-undefined'],
11
+ boolean: ['help', 'h', 'version', 'v', 'debug', 'allow-unknown', 'allow-undefined'],
11
12
  alias: {
12
13
  h: 'help',
13
14
  v: 'version',
14
15
  o: 'output',
15
16
  f: 'format',
16
- d: 'debug'
17
17
  },
18
18
  default: {
19
19
  format: 'json'
@@ -74,8 +74,32 @@ const options = {
74
74
  dynamicArgs: argv
75
75
  }
76
76
 
77
+ if (options.dynamicArgs.verbose) {
78
+ console.log('───────────── Input Options ──────────────────────')
79
+ const dynamicArgs = options.dynamicArgs || {}
80
+ const {
81
+ _,
82
+ verbose,
83
+ v,
84
+ debug,
85
+ d,
86
+ help,
87
+ h,
88
+ version,
89
+ f,
90
+ format,
91
+ 'allow-unknown': allowUnknown,
92
+ 'allow-undefined': allowUndefined,
93
+ ...rest
94
+ } = dynamicArgs
95
+ console.log()
96
+ deepLog(rest)
97
+ console.log()
98
+ }
99
+
77
100
  // Create Configorama instance
78
101
  const configorama = new Configorama(inputFile, options)
102
+ // console.log('configorama', configorama)
79
103
 
80
104
  // Process the configuration
81
105
  configorama.init(argv)
@@ -103,7 +127,9 @@ configorama.init(argv)
103
127
  fs.writeFileSync(argv.output, output)
104
128
  console.log(`Configuration written to ${argv.output}`)
105
129
  } else {
106
- console.log(output)
130
+ if (!argv.verbose) {
131
+ console.log(output)
132
+ }
107
133
  }
108
134
  })
109
135
  .catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "configorama",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Variable support for configuration files",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -63,7 +63,7 @@
63
63
  "traverse": "^0.6.8"
64
64
  },
65
65
  "devDependencies": {
66
- "markdown-magic": "^2.6.1",
66
+ "markdown-magic": "^3.4.0",
67
67
  "uvu": "^0.5.6",
68
68
  "watchlist": "^0.3.1"
69
69
  }