@calvear/env 1.0.0

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.
Files changed (97) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE.md +19 -0
  3. package/README.md +659 -0
  4. package/arguments.d.ts +22 -0
  5. package/arguments.d.ts.map +1 -0
  6. package/arguments.js +105 -0
  7. package/arguments.js.map +1 -0
  8. package/commands/env.command.d.ts +8 -0
  9. package/commands/env.command.d.ts.map +1 -0
  10. package/commands/env.command.js +63 -0
  11. package/commands/env.command.js.map +1 -0
  12. package/commands/export.command.d.ts +8 -0
  13. package/commands/export.command.d.ts.map +1 -0
  14. package/commands/export.command.js +51 -0
  15. package/commands/export.command.js.map +1 -0
  16. package/commands/index.d.ts +6 -0
  17. package/commands/index.d.ts.map +1 -0
  18. package/commands/index.js +14 -0
  19. package/commands/index.js.map +1 -0
  20. package/commands/pull.command.d.ts +7 -0
  21. package/commands/pull.command.d.ts.map +1 -0
  22. package/commands/pull.command.js +39 -0
  23. package/commands/pull.command.js.map +1 -0
  24. package/commands/push.command.d.ts +7 -0
  25. package/commands/push.command.d.ts.map +1 -0
  26. package/commands/push.command.js +38 -0
  27. package/commands/push.command.js.map +1 -0
  28. package/commands/schema.command.d.ts +4 -0
  29. package/commands/schema.command.d.ts.map +1 -0
  30. package/commands/schema.command.js +18 -0
  31. package/commands/schema.command.js.map +1 -0
  32. package/exec.d.ts +3 -0
  33. package/exec.d.ts.map +1 -0
  34. package/exec.js +142 -0
  35. package/exec.js.map +1 -0
  36. package/index.d.ts +4 -0
  37. package/index.d.ts.map +1 -0
  38. package/index.js +20 -0
  39. package/index.js.map +1 -0
  40. package/interfaces/index.d.ts +2 -0
  41. package/interfaces/index.d.ts.map +1 -0
  42. package/interfaces/index.js +18 -0
  43. package/interfaces/index.js.map +1 -0
  44. package/interfaces/loader.interface.d.ts +21 -0
  45. package/interfaces/loader.interface.d.ts.map +1 -0
  46. package/interfaces/loader.interface.js +3 -0
  47. package/interfaces/loader.interface.js.map +1 -0
  48. package/main.d.ts +3 -0
  49. package/main.d.ts.map +1 -0
  50. package/main.js +6 -0
  51. package/main.js.map +1 -0
  52. package/package.json +85 -0
  53. package/providers/app-settings.provider.d.ts +9 -0
  54. package/providers/app-settings.provider.d.ts.map +1 -0
  55. package/providers/app-settings.provider.js +50 -0
  56. package/providers/app-settings.provider.js.map +1 -0
  57. package/providers/index.d.ts +8 -0
  58. package/providers/index.d.ts.map +1 -0
  59. package/providers/index.js +28 -0
  60. package/providers/index.js.map +1 -0
  61. package/providers/package-json.provider.d.ts +8 -0
  62. package/providers/package-json.provider.d.ts.map +1 -0
  63. package/providers/package-json.provider.js +29 -0
  64. package/providers/package-json.provider.js.map +1 -0
  65. package/providers/secrets.provider.d.ts +9 -0
  66. package/providers/secrets.provider.d.ts.map +1 -0
  67. package/providers/secrets.provider.js +43 -0
  68. package/providers/secrets.provider.js.map +1 -0
  69. package/tsconfig.build.tsbuildinfo +1 -0
  70. package/utils/command.util.d.ts +12 -0
  71. package/utils/command.util.d.ts.map +1 -0
  72. package/utils/command.util.js +135 -0
  73. package/utils/command.util.js.map +1 -0
  74. package/utils/index.d.ts +7 -0
  75. package/utils/index.d.ts.map +1 -0
  76. package/utils/index.js +23 -0
  77. package/utils/index.js.map +1 -0
  78. package/utils/interpolate.util.d.ts +4 -0
  79. package/utils/interpolate.util.d.ts.map +1 -0
  80. package/utils/interpolate.util.js +33 -0
  81. package/utils/interpolate.util.js.map +1 -0
  82. package/utils/json.util.d.ts +5 -0
  83. package/utils/json.util.d.ts.map +1 -0
  84. package/utils/json.util.js +47 -0
  85. package/utils/json.util.js.map +1 -0
  86. package/utils/logger.d.ts +3 -0
  87. package/utils/logger.d.ts.map +1 -0
  88. package/utils/logger.js +18 -0
  89. package/utils/logger.js.map +1 -0
  90. package/utils/normalize.util.d.ts +2 -0
  91. package/utils/normalize.util.d.ts.map +1 -0
  92. package/utils/normalize.util.js +44 -0
  93. package/utils/normalize.util.js.map +1 -0
  94. package/utils/schema.util.d.ts +7 -0
  95. package/utils/schema.util.d.ts.map +1 -0
  96. package/utils/schema.util.js +51 -0
  97. package/utils/schema.util.js.map +1 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [1.0.0] - 2022-03-22
6
+
7
+ - Load environment variables and executes a subcommand or script.
8
+ - Custom and integrated providers for load, piush and pull variables.
9
+ - Pulls variables from providers.
10
+ - Pushes variables to providers.
11
+ - Creates a JSON Schema from variables for validation.
package/LICENSE.md ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2021 Cristopher Alvear
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
19
+ OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,659 @@
1
+ <div id="top" align="center">
2
+ <img
3
+ alt="logo"
4
+ src="https://nodejs.org/static/images/logo.svg"
5
+ width="256px"
6
+ />
7
+
8
+ </br>
9
+
10
+ <h1><b>env</b></h1>
11
+ <h4>¡Environment variables made easy!</h4>
12
+ </div>
13
+
14
+ <br />
15
+
16
+ <p align="center">
17
+ <img
18
+ src="https://img.shields.io/badge/version-1.0.0-blue?style=flat-square"
19
+ alt="version"
20
+ />
21
+ &nbsp;
22
+ <img
23
+ src="https://img.shields.io/badge/TypeScript-007ACC?style=flat-square&logo=typescript&logoColor=white"
24
+ alt="typescript"
25
+ />
26
+ &nbsp;
27
+ <img
28
+ src="https://img.shields.io/badge/nodejs-~14.0.0_||_^16.14.2-darkgreen?style=flat-square"
29
+ alt="nodejs engine"
30
+ />
31
+ &nbsp;
32
+ <img
33
+ src="https://img.shields.io/badge/npm->=7.5.6-darkgreen?style=flat-square"
34
+ alt="npm engine"
35
+ />
36
+ &nbsp;
37
+ <img
38
+ src="https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square"
39
+ alt="license"
40
+ />
41
+ </p>
42
+
43
+ <br />
44
+
45
+ <!-- ABOUT THE PROJECT -->
46
+
47
+ ## 📖 **About**
48
+
49
+ Eases NodeJS <b>environment variable handling</b>, like [env-cmd](https://www.npmjs.com/package/env-cmd) or [dotenv](https://www.npmjs.com/package/dotenv), but with <b>powerfull features and extensibility</b> for adding custom providers (as plugins) for <u>load</u>, <u>pull</u> and <u>push</u> the variables from different stores.
50
+
51
+ <p align="right">(<a href="#top">back to top</a>)</p>
52
+
53
+ <!-- REQUIREMENTS -->
54
+
55
+ ## 📌 **Requirements**
56
+
57
+ First, [download](https://nodejs.org/) and install **NodeJS**. Version `14` or higher is required.
58
+
59
+ Validate installed versions of node and npm with:
60
+
61
+ ```bash
62
+ > node -v
63
+ v16.14.2
64
+
65
+ > npm -v
66
+ 8.3.0
67
+ ```
68
+
69
+ You can initialize a new npm project using:
70
+
71
+ ```bash
72
+ > npm init
73
+ ```
74
+
75
+ <p align="right">(<a href="#top">back to top</a>)</p>
76
+
77
+ <!-- QUICK START -->
78
+
79
+ ## ⚡️ **Quick start**
80
+
81
+ > 🔔 Make sure that you have [NodeJS 14+](https://nodejs.org/) installed on your computer.
82
+
83
+ - Installs the package:
84
+
85
+ ```bash
86
+ > npm install @calvear/env
87
+
88
+ added 1 packages, and audited 1 packages in 1s
89
+
90
+ found 0 vulnerabilities
91
+ > _
92
+ ```
93
+
94
+ - Executes binary directly:
95
+
96
+ ```bash
97
+ > node_modules/.bin/env --help
98
+
99
+ Usage: env [command] [options..] [: subcmd [:]] [options..]
100
+
101
+ Commands:
102
+ env [options..] [: <subcmd> :]
103
+ env pull [options..]
104
+ env push [options..]
105
+ env schema [options..]
106
+ > _
107
+ ```
108
+
109
+ - Or add desired commands in your **npm script** in `package.json`:
110
+
111
+ ```javascript
112
+ {
113
+ ...,
114
+ "scripts": {
115
+ // starts project injecting "dev" environment variables and debug log level
116
+ "start:dev": "env -e dev -m debug : node dist/main.js : --log debug",
117
+ // starts project injecting "prod" environment variables
118
+ "start:prod": "env -e prod -m debug : node dist/main.js",
119
+ ...,
120
+ // builds project injecting "prod" environment variables
121
+ "build:prod": "env -e prod -m build : tsc",
122
+ ...,
123
+ "env:schema": "env schema -e dev",
124
+ // uploads environment "dev" variables
125
+ "env:push:dev": "env push -e dev",
126
+ // downloads environment "dev" variables
127
+ "env:pull:dev": "env pull -e dev"
128
+ },
129
+ ...
130
+ }
131
+ ```
132
+
133
+ - Execs your command:
134
+
135
+ **file**: _dist/main.js_
136
+
137
+ ```javascript
138
+ console.log(`My environment loaded is: ${process.env.ENV}`);
139
+ ```
140
+
141
+ ```bash
142
+ > npm run start:dev
143
+
144
+ 13:31:59.865 INFO loading dev environment in debug mode
145
+ 13:31:59.911 DEBUG using package-json provider
146
+ 13:31:59.912 DEBUG using app-settings provider
147
+ 13:31:59.914 DEBUG using secrets provider
148
+ 13:32:00.109 DEBUG environment loaded:
149
+ {
150
+ NODE_ENV: 'development',
151
+ ENV: 'dev',
152
+ VERSION: '1.0.0',
153
+ NAME: '@my-app',
154
+ VAR1: true,
155
+ VAR2: true,
156
+ GROUP1__VAR1: 'G1V2',
157
+ ARR1: '1,val,true',
158
+ SECRET: '***'
159
+ }
160
+ 13:32:00.116 INFO executing command > node dist/main.js
161
+ My environment loaded is: dev
162
+ 13:32:00.232 INFO process finished successfully
163
+ > _
164
+ ```
165
+
166
+ <p align="right">(<a href="#top">back to top</a>)</p>
167
+
168
+ ## ⛩ **Structure**
169
+
170
+ ```bash
171
+ ├── src/
172
+ │   ├── commands/ # lib commands handlers
173
+ │   │   ├── env.command.ts
174
+ │   │   ├── export.command.ts
175
+ │   │   ├── pull.command.ts
176
+ │   │   ├── push.command.ts
177
+ │   │   └── schema.command.ts
178
+ │   ├── interfaces/ # provider interfaces
179
+ │   ├── providers/ # integrated providers
180
+ │   │   ├── package-json.provider.ts
181
+ │   │   ├── app-settings.provider.ts
182
+ │   │   └── secrets.provider.ts
183
+ │   ├── utils/
184
+ │   │   ├── command.util.ts
185
+ │   │   ├── interpolate.util.ts
186
+ │   │   ├── json.util.ts
187
+ │   │   ├── normalize.util.ts
188
+ │   │   ├── schema.util.ts
189
+ │   │   └── logger.ts
190
+ │   ├── arguments.ts # global arguments
191
+ │   ├── exec.ts # initialization logic (load config, commands, etc.)
192
+ │   └── main.ts
193
+ ├── tests/ # integration tests
194
+ ├── .eslintrc.json
195
+ ├── jest.config.json
196
+ ├── tsconfig.build.json
197
+ └── tsconfig.json
198
+ ```
199
+
200
+ <p align="right">(<a href="#top">back to top</a>)</p>
201
+
202
+ <!-- COMMANDS AND OPTIONS -->
203
+
204
+ ## ⚙️ **Commands & Options**
205
+
206
+ Options handling has the ability of **replace arguments itself**, using `[[` and `]]` as delimiters.
207
+ So, in example for define your config file path, you must use your _root_ argument,
208
+ supposing root has the value of "config", this definition _`[[root]]/any-config-file.json`_ will be
209
+ _`config/any-config-file.json`_, or if your _env_ argument is "dev", this definition
210
+ _`[[root]]/config-file.[[env]].json`_ will be _`config/config-file.dev.json`_.
211
+
212
+ <div align="center">
213
+ <span style="font-size:20px;font-weight:bold" align="center">Options</span>
214
+ </div>
215
+
216
+ ### Global options
217
+
218
+ | Option | Description | Type | Default | Required? |
219
+ | ---------------------------------- | -------------------------------------- | ---------- | ------- | --------- |
220
+ | `--help` | Shows help | `boolean` | | No |
221
+ | `--e, --env` | Environment for load | `string` | | Yes |
222
+ | `-m, --modes` | Execution modes | `string[]` | `[]` | No |
223
+ | `--nd, --nestingDelimiter` | Nesting level delimiter for flatten | `string` | `__` | No |
224
+ | `--arrDesc, --arrayDescomposition` | Whether serialize or break down arrays | `boolean` | `false` | No |
225
+
226
+ </br>
227
+
228
+ ### Workspace options
229
+
230
+ | Option | Description | Type | Default | Required? |
231
+ | ------------------ | --------------------------------- | -------- | -------------------------- | --------- |
232
+ | `--root` | Default environment folder path | `string` | `env` | No |
233
+ | `-c, --configFile` | Config JSON file path | `string` | `[[root]]/env.config.json` | No |
234
+ | `-s, --schemaFile` | Environment Schema JSON file path | `string` | `[[root]]/env.schema.json` | No |
235
+
236
+ ### JSON Schema options
237
+
238
+ | Option | Description | Type | Default | Required? |
239
+ | ---------------------- | ---------------------------------------------------------- | ----------------- | ------- | --------- |
240
+ | `-r, --resolve` | Whether merges new schema or override | `merge, override` | `merge` | No |
241
+ | `--null, --nullable` | Whether variables are nullable by default | `boolean` | `true` | No |
242
+ | `--df, --detectFormat` | Whether format of strings variables are included in schema | `boolean` | `true` | No |
243
+
244
+ ### Logger options
245
+
246
+ | Option | Description | Type | Default | Required? |
247
+ | ------------------- | ----------- | ---------------------------------------- | ------- | --------- |
248
+ | `--log, --logLevel` | Log level | `silly, trace, debug, info, warn, error` | `info` | No |
249
+
250
+ <div align="center">
251
+ <span style="font-size:20px;font-weight:bold" align="center">Commands</span>
252
+ </div>
253
+
254
+ - ## **`env`**
255
+
256
+ Inject your environment variables into `process.env` and executes a command.
257
+
258
+ ```bash
259
+ env -e [env] [options..] [: subcmd [:]] [options..]
260
+ ```
261
+
262
+ Examples:
263
+
264
+ ```bash
265
+ > env -e dev -m test unit : npm test
266
+ ```
267
+
268
+ ```bash
269
+ > env -e dev -m debug : npm start : -c [[root]]/[[env]].env.json
270
+ ```
271
+
272
+ ```bash
273
+ > env -e prod -m build optimize : npm build
274
+ ```
275
+
276
+ - ## **`pull`**
277
+
278
+ Pulls environment variables from providers stores.
279
+
280
+ ```bash
281
+ env pull -e [env] [options..]
282
+ ```
283
+
284
+ | Option | Description | Type | Default | Required? |
285
+ | ----------------- | ------------------------- | --------- | ------- | --------- |
286
+ | `-o, --overwrite` | Overwrite local variables | `boolean` | `false` | No |
287
+
288
+ Examples:
289
+
290
+ ```bash
291
+ > env pull -e dev
292
+ ```
293
+
294
+ - ## **`push`**
295
+
296
+ Pushes environment variables to providers stores.
297
+
298
+ ```bash
299
+ env push -e [env] [options..]
300
+ ```
301
+
302
+ | Option | Description | Type | Default | Required? |
303
+ | ------------- | ------------------------------------ | --------- | ------- | --------- |
304
+ | `-f, --force` | Force push for secrets (replace all) | `boolean` | `false` | No |
305
+
306
+ Examples:
307
+
308
+ ```bash
309
+ > env push -e dev
310
+ ```
311
+
312
+ - ## **`schema`**
313
+
314
+ Generates validation schema from providers output variables.
315
+
316
+ ```bash
317
+ env schema -e [env] -m [modes] [options..]
318
+ ```
319
+
320
+ Examples:
321
+
322
+ ```bash
323
+ > env schema -e dev -m build
324
+ ```
325
+
326
+ - ## **`export`**
327
+
328
+ Export unified environment variables to a file from providers.
329
+
330
+ ```bash
331
+ env export -e [env] -m [modes] [options..]
332
+ ```
333
+
334
+ | Option | Description | Type | Default | Required? |
335
+ | --------------- | ---------------------------------- | -------- | -------- | --------- |
336
+ | `-u, -p, --uri` | Uri for export file with variables | `string` | `.env` | No |
337
+ | `-f, --format` | Format for export variables | `string` | `dotenv` | No |
338
+
339
+ Examples:
340
+
341
+ ```bash
342
+ > env export -e dev -m build -f json --uri [[env]].env.json
343
+ ```
344
+
345
+ <p align="right">(<a href="#top">back to top</a>)</p>
346
+
347
+ <!-- PROVIDERS -->
348
+
349
+ ## 📡 **Providers**
350
+
351
+ Main feature of this library is using providers for get and set environment variables.
352
+ So, you cand define your own provider, but lib came with 3 integrated providers:
353
+
354
+ - ## **`package-json`**
355
+
356
+ Load some info from your project `package.json`.
357
+
358
+ Info read is:
359
+
360
+ ```json
361
+ {
362
+ "version": "1.0.0",
363
+ "project": "project-name",
364
+ "name": "@package-name",
365
+ "title": "app-name",
366
+ "description": "any description"
367
+ }
368
+ ```
369
+
370
+ | Option | Description | Type | Default | Required? |
371
+ | ------------------- | --------------------------- | -------- | ------- | --------- |
372
+ | `--vp, --varPrefix` | Prefix for loaded variables | `string` | `""` | No |
373
+
374
+ Examples:
375
+
376
+ ```bash
377
+ > env -e dev -m build : react-script build : --vp REACT_APP_
378
+ ```
379
+
380
+ </br>
381
+
382
+ - ## **`app-settings`**
383
+
384
+ Non secrets loader for `appsettings.json`.
385
+
386
+ `appsettings.json` file has the format below:
387
+
388
+ ```json
389
+ {
390
+ "|DEFAULT|": {},
391
+ "|MODE|": {},
392
+ "|ENV|": {}
393
+ }
394
+ ```
395
+
396
+ In example:
397
+
398
+ ```json
399
+ {
400
+ "|DEFAULT|": {
401
+ "VAR1": "v1_default"
402
+ },
403
+ "|MODE|": {
404
+ "::build": {
405
+ "NODE_ENV": "production"
406
+ },
407
+ "::debug": {
408
+ "NODE_ENV": "development"
409
+ },
410
+ "::test": {
411
+ "NODE_ENV": "test"
412
+ }
413
+ },
414
+ "|ENV|": {
415
+ "::dev": {
416
+ "C1": "V1",
417
+ "C2": "V2",
418
+ "C3": 3,
419
+ "GROUP1": {
420
+ "VAR1": null,
421
+ "VAR2": "G1V2",
422
+ "VAR3": true,
423
+ "GROUP2": {
424
+ "VAR1": "G1G2V1"
425
+ }
426
+ },
427
+ "C4": "23"
428
+ }
429
+ }
430
+ }
431
+ ```
432
+
433
+ | Option | Description | Type | Default | Required? |
434
+ | ----------------------- | ------------------------------------ | -------- | --------------------------- | --------- |
435
+ | `--ef, --envFile` | Environment variables file path | `string` | `[[root]]/appsettings.json` | No |
436
+ | `--sp, --sectionPrefix` | Prefix for env and modes in env file | `string` | `::` | No |
437
+
438
+ </br>
439
+
440
+ - ## **`secrets`**
441
+
442
+ Secrets loader for `env/secrets/[[env]].env.json` and `env/secrets/[[env]].local.env.json`.
443
+
444
+ | Option | Description | Type | Default | Required? |
445
+ | -------------------------- | -------------------------------- | -------- | ----------------------------------------- | --------- |
446
+ | `--sf, --secretFile` | Secret variables file path | `string` | `[[root]]/secrets/[[env]].env.json` | No |
447
+ | `--lsf, --localSecretFile` | Local secret variables file path | `string` | `[[root]]/secrets/[[env]].local.env.json` | No |
448
+
449
+ - ## **`package-json`**
450
+
451
+ Load some info from your project `package.json`.
452
+
453
+ Info read is:
454
+
455
+ ```json
456
+ {
457
+ "version": "1.0.0",
458
+ "project": "project-name",
459
+ "name": "@package-name",
460
+ "title": "app-name",
461
+ "description": "any description"
462
+ }
463
+ ```
464
+
465
+ | Option | Description | Type | Default | Required? |
466
+ | ------------------- | --------------------------- | -------- | ------- | --------- |
467
+ | `--vp, --varPrefix` | Prefix for loaded variables | `string` | `""` | No |
468
+
469
+ Examples:
470
+
471
+ ```bash
472
+ > env -e dev -m build : react-script build : --vp REACT_APP_
473
+ ```
474
+
475
+ <p align="right">(<a href="#top">back to top</a>)</p>
476
+
477
+ <!-- PROVIDERS -->
478
+
479
+ ## ✒ **Creating Custom Providers**
480
+
481
+ You can create your custom providers, in two ways:
482
+
483
+ - **Local Script**: you must create a JavaScript file (.js), exporting by default your "provider" following standard interface exported by this lib.
484
+ - **NPM Package**: you must create your custom NPM library and export by default your "provider" using standard interface exported by this lib.
485
+
486
+ How to load your provider is shown in Config Section.
487
+
488
+ In example, a provider exported by your NPM package written in TypeScript should be like:
489
+
490
+ ```typescript
491
+ import { CommandArguments, EnvProvider } from '@calvear/env';
492
+ import { logger, readJson, writeJson } from '@calvear/env/utils';
493
+
494
+ const KEY = 'my-unique-provider-key';
495
+
496
+ interface MyProviderCommandArguments extends CommandArguments {
497
+ anyExtraOption: boolean;
498
+ }
499
+
500
+ export const MyProvider: EnvProvider<MyProviderCommandArguments> = {
501
+ // unique identifier for provider
502
+ key: KEY,
503
+
504
+ // (optional) allows to provider adds new arguments/options
505
+ // to commands using yargs for builder
506
+ builder: (builder) => {
507
+ builder.options({
508
+ anyExtraOption: {
509
+ group: KEY,
510
+ alias: ['a', 'aeo'],
511
+ type: 'boolean',
512
+ default: false,
513
+ describe: 'Any option description',
514
+ },
515
+ });
516
+ },
517
+
518
+ // call on environment variables loading,
519
+ // may be a Promise
520
+ load: ({ env, modes, ...options }) => {
521
+ if (env === 'dev')
522
+ return {
523
+ NODE_ENV: 'development',
524
+ };
525
+
526
+ // you can return a list of JSON environment variables for merge
527
+ return [
528
+ {
529
+ NODE_ENV: 'production',
530
+ },
531
+ {
532
+ ANY_VAR: 'ANY_VALUE',
533
+ ANY_GROUP: {
534
+ INNER_VAR: 12,
535
+ },
536
+ },
537
+ ];
538
+ },
539
+
540
+ // (optional) call on pulling variables from provider store,
541
+ // config may pass in your config file
542
+ pull: ({ env, modes, ...options }, config) => {
543
+ // anyway you want for pulling variables to cache
544
+ },
545
+
546
+ // (optional) call on pushing/updating variables to provider store,
547
+ // config may pass in your config file
548
+ push: ({ env, modes, ...options }, config) => {
549
+ // anyway you should do for pushing or updating your variables
550
+ },
551
+ };
552
+ ```
553
+
554
+ <p align="right">(<a href="#top">back to top</a>)</p>
555
+
556
+ <!-- CONFIG -->
557
+
558
+ ## 📥 **Config**
559
+
560
+ You can configure any config argument inside you config file, but commonly providers are designed for this purpose.
561
+
562
+ ```javascript
563
+ {
564
+ "log": "silly",
565
+ // will hide values of keys SECRET and MY_API_KEY in logging
566
+ "logMaskValuesOfKeys": ["SECRET", "MY_API_KEY"],
567
+ // integrated providers and custom providers together
568
+ "providers": [
569
+ {
570
+ "path": "package-json",
571
+ "type": "integrated"
572
+ },
573
+ {
574
+ "path": "app-settings",
575
+ "type": "integrated"
576
+ },
577
+ {
578
+ "path": "secrets",
579
+ "type": "integrated"
580
+ },
581
+ {
582
+ // custom NPM package
583
+ "path": "@npm-package",
584
+ "type": "module",
585
+ "config": {
586
+ "any-config": "any value"
587
+ }
588
+ },
589
+ {
590
+ // custom script inside project
591
+ "path": "scripts/custom-loader.js",
592
+ "type": "script"
593
+ }
594
+ ]
595
+ }
596
+ ```
597
+
598
+ <!-- ROADMAP -->
599
+
600
+ ## 📑 Roadmap
601
+
602
+ - [x] Environment injection handling
603
+ - [x] Customizable variables store providers
604
+ - [x] Commands
605
+ - [x] `push` executes a pushing action over every providers
606
+ - [x] `pull` executes a pulling action over every providers
607
+ - [x] `schema` regenerates JSON schema using providers output
608
+ - [x] `export` exports environment variables in json or dotenv format
609
+ - [ ] `prepare` prepares environment (creates folder and files required)
610
+ - [ ] Improve documentation
611
+ - [ ] Providers pull history
612
+ - [ ] Providers pull and push difference calc and prompts
613
+ - [ ] Providers dependsOn option
614
+ - [ ] Programatic module
615
+
616
+ <p align="right">(<a href="#top">back to top</a>)</p>
617
+
618
+ ## 🧿 **Linting**
619
+
620
+ Project uses ESLint, for code formatting and code styling normalizing.
621
+
622
+ - **eslint**: linter integrated with TypeScript.
623
+
624
+ For correct interpretation of linters, is recommended to use [Visual Studio Code](https://code.visualstudio.com/) as IDE and install the plugins in .vscode folder at 'extensions.json', as well as use the config provided in 'settings.json'
625
+
626
+ <p align="right">(<a href="#top">back to top</a>)</p>
627
+
628
+ <!-- CHANGELOG -->
629
+
630
+ ## 📋 Changelog
631
+
632
+ For last changes see [CHANGELOG.md](CHANGELOG.md) file for details.
633
+
634
+ <p align="right">(<a href="#top">back to top</a>)</p>
635
+
636
+ <!-- BUILT WITH -->
637
+
638
+ ## 🛠️ Built with
639
+
640
+ - [yargs](http://yargs.js.org/)
641
+ - [tslog](https://tslog.js.org/#/)
642
+ - [subslate](https://github.com/josh-hemphill/subslate)
643
+ - [merge-deep](https://github.com/jonschlinkert/merge-deep)
644
+ - [ajv](https://ajv.js.org/)
645
+ - [to-json-schema](https://www.npmjs.com/package/to-json-schema)
646
+
647
+ <p align="right">(<a href="#top">back to top</a>)</p>
648
+
649
+ <!-- LICENSE -->
650
+
651
+ ## 📄 License
652
+
653
+ This project is licensed under the MIT License - see [LICENSE.md](LICENSE.md) file for details.
654
+
655
+ <p align="right">(<a href="#top">back to top</a>)</p>
656
+
657
+ ---
658
+
659
+ ⌨ by [Alvear Candia, Cristopher Alejandro](https://github.com/calvear93)