@achs/env 2.0.0 → 3.1.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 (136) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.json +329 -0
  3. package/.vscode/extensions.json +18 -0
  4. package/.vscode/launch.json +30 -0
  5. package/.vscode/settings.json +29 -0
  6. package/CHANGELOG.md +13 -0
  7. package/README.md +14 -7
  8. package/jest.config.json +28 -0
  9. package/package.json +16 -16
  10. package/{arguments.js → src/arguments.ts} +38 -14
  11. package/src/commands/env.command.ts +139 -0
  12. package/src/commands/export.command.ts +88 -0
  13. package/{commands/index.d.ts → src/commands/index.ts} +0 -1
  14. package/src/commands/pull.command.ts +52 -0
  15. package/src/commands/push.command.ts +48 -0
  16. package/src/commands/schema.command.ts +31 -0
  17. package/src/exec.ts +221 -0
  18. package/{index.d.ts → src/index.ts} +0 -1
  19. package/{interfaces/index.d.ts → src/interfaces/index.ts} +0 -1
  20. package/src/interfaces/loader.interface.ts +66 -0
  21. package/src/main.ts +6 -0
  22. package/src/providers/app-settings.provider.ts +67 -0
  23. package/src/providers/azure-key-vault.provider.ts +277 -0
  24. package/src/providers/index.ts +29 -0
  25. package/src/providers/local.provider.ts +44 -0
  26. package/src/providers/package-json.provider.ts +39 -0
  27. package/src/utils/command.util.ts +223 -0
  28. package/{utils/index.d.ts → src/utils/index.ts} +0 -1
  29. package/src/utils/interpolate.util.ts +65 -0
  30. package/src/utils/json.util.ts +116 -0
  31. package/{utils/logger.js → src/utils/logger.ts} +6 -6
  32. package/src/utils/normalize.util.ts +142 -0
  33. package/src/utils/schema.util.ts +191 -0
  34. package/tests/env/appsettings.json +32 -0
  35. package/tests/env/dev.env.json +12 -0
  36. package/tests/env/dev.local.env.json +9 -0
  37. package/tests/env/env.schema.json +225 -0
  38. package/tests/env/keys.json +7 -0
  39. package/tests/env/settings/schema.json +239 -0
  40. package/tests/env/settings/settings.json +22 -0
  41. package/tests/env.int.test.ts +42 -0
  42. package/tests/exec.ts +19 -0
  43. package/tests/export.int.test.ts +9 -0
  44. package/tests/pull-push.int.test.ts +15 -0
  45. package/tests/run.js +32 -0
  46. package/tests/schema.int.test.ts +9 -0
  47. package/tests/setup.ts +13 -0
  48. package/tsconfig.build.json +10 -0
  49. package/tsconfig.json +37 -0
  50. package/arguments.d.ts +0 -25
  51. package/arguments.d.ts.map +0 -1
  52. package/arguments.js.map +0 -1
  53. package/commands/env.command.d.ts +0 -8
  54. package/commands/env.command.d.ts.map +0 -1
  55. package/commands/env.command.js +0 -85
  56. package/commands/env.command.js.map +0 -1
  57. package/commands/export.command.d.ts +0 -8
  58. package/commands/export.command.d.ts.map +0 -1
  59. package/commands/export.command.js +0 -54
  60. package/commands/export.command.js.map +0 -1
  61. package/commands/index.d.ts.map +0 -1
  62. package/commands/index.js +0 -14
  63. package/commands/index.js.map +0 -1
  64. package/commands/pull.command.d.ts +0 -7
  65. package/commands/pull.command.d.ts.map +0 -1
  66. package/commands/pull.command.js +0 -39
  67. package/commands/pull.command.js.map +0 -1
  68. package/commands/push.command.d.ts +0 -7
  69. package/commands/push.command.d.ts.map +0 -1
  70. package/commands/push.command.js +0 -38
  71. package/commands/push.command.js.map +0 -1
  72. package/commands/schema.command.d.ts +0 -4
  73. package/commands/schema.command.d.ts.map +0 -1
  74. package/commands/schema.command.js +0 -18
  75. package/commands/schema.command.js.map +0 -1
  76. package/exec.d.ts +0 -3
  77. package/exec.d.ts.map +0 -1
  78. package/exec.js +0 -142
  79. package/exec.js.map +0 -1
  80. package/index.d.ts.map +0 -1
  81. package/index.js +0 -20
  82. package/index.js.map +0 -1
  83. package/interfaces/index.d.ts.map +0 -1
  84. package/interfaces/index.js +0 -18
  85. package/interfaces/index.js.map +0 -1
  86. package/interfaces/loader.interface.d.ts +0 -21
  87. package/interfaces/loader.interface.d.ts.map +0 -1
  88. package/interfaces/loader.interface.js +0 -3
  89. package/interfaces/loader.interface.js.map +0 -1
  90. package/main.d.ts +0 -3
  91. package/main.d.ts.map +0 -1
  92. package/main.js +0 -6
  93. package/main.js.map +0 -1
  94. package/providers/app-settings.provider.d.ts +0 -8
  95. package/providers/app-settings.provider.d.ts.map +0 -1
  96. package/providers/app-settings.provider.js +0 -50
  97. package/providers/app-settings.provider.js.map +0 -1
  98. package/providers/azure-key-vault.provider.d.ts +0 -22
  99. package/providers/azure-key-vault.provider.d.ts.map +0 -1
  100. package/providers/azure-key-vault.provider.js +0 -164
  101. package/providers/azure-key-vault.provider.js.map +0 -1
  102. package/providers/index.d.ts +0 -8
  103. package/providers/index.d.ts.map +0 -1
  104. package/providers/index.js +0 -28
  105. package/providers/index.js.map +0 -1
  106. package/providers/package-json.provider.d.ts +0 -8
  107. package/providers/package-json.provider.d.ts.map +0 -1
  108. package/providers/package-json.provider.js +0 -29
  109. package/providers/package-json.provider.js.map +0 -1
  110. package/tsconfig.build.tsbuildinfo +0 -1
  111. package/utils/command.util.d.ts +0 -13
  112. package/utils/command.util.d.ts.map +0 -1
  113. package/utils/command.util.js +0 -134
  114. package/utils/command.util.js.map +0 -1
  115. package/utils/index.d.ts.map +0 -1
  116. package/utils/index.js +0 -23
  117. package/utils/index.js.map +0 -1
  118. package/utils/interpolate.util.d.ts +0 -4
  119. package/utils/interpolate.util.d.ts.map +0 -1
  120. package/utils/interpolate.util.js +0 -33
  121. package/utils/interpolate.util.js.map +0 -1
  122. package/utils/json.util.d.ts +0 -5
  123. package/utils/json.util.d.ts.map +0 -1
  124. package/utils/json.util.js +0 -48
  125. package/utils/json.util.js.map +0 -1
  126. package/utils/logger.d.ts +0 -3
  127. package/utils/logger.d.ts.map +0 -1
  128. package/utils/logger.js.map +0 -1
  129. package/utils/normalize.util.d.ts +0 -3
  130. package/utils/normalize.util.d.ts.map +0 -1
  131. package/utils/normalize.util.js +0 -61
  132. package/utils/normalize.util.js.map +0 -1
  133. package/utils/schema.util.d.ts +0 -11
  134. package/utils/schema.util.d.ts.map +0 -1
  135. package/utils/schema.util.js +0 -100
  136. package/utils/schema.util.js.map +0 -1
@@ -0,0 +1,239 @@
1
+ {
2
+ "package-json": {
3
+ "type": "object",
4
+ "properties": {
5
+ "ENV": {
6
+ "type": [
7
+ "string"
8
+ ],
9
+ "nullable": true
10
+ },
11
+ "VERSION": {
12
+ "type": [
13
+ "string"
14
+ ],
15
+ "nullable": true
16
+ },
17
+ "PROJECT": {
18
+ "type": [
19
+ "string"
20
+ ],
21
+ "nullable": true
22
+ },
23
+ "NAME": {
24
+ "type": [
25
+ "string"
26
+ ],
27
+ "nullable": true
28
+ },
29
+ "TITLE": {
30
+ "type": [
31
+ "string"
32
+ ],
33
+ "nullable": true
34
+ },
35
+ "DESCRIPTION": {
36
+ "type": [
37
+ "string"
38
+ ],
39
+ "nullable": true
40
+ }
41
+ }
42
+ },
43
+ "app-settings": {
44
+ "type": "object",
45
+ "properties": {
46
+ "VAR1": {
47
+ "type": [
48
+ "string"
49
+ ],
50
+ "nullable": true
51
+ },
52
+ "C1": {
53
+ "type": [
54
+ "string"
55
+ ],
56
+ "nullable": true
57
+ },
58
+ "C2": {
59
+ "type": [
60
+ "string"
61
+ ],
62
+ "nullable": true
63
+ },
64
+ "C3": {
65
+ "type": [
66
+ "integer"
67
+ ],
68
+ "nullable": true
69
+ },
70
+ "GROUP1": {
71
+ "type": [
72
+ "object"
73
+ ],
74
+ "properties": {
75
+ "VAR1": {
76
+ "type": [
77
+ "null"
78
+ ],
79
+ "nullable": true
80
+ },
81
+ "VAR2": {
82
+ "type": [
83
+ "string"
84
+ ],
85
+ "nullable": true
86
+ },
87
+ "VAR3": {
88
+ "type": [
89
+ "boolean"
90
+ ],
91
+ "nullable": true
92
+ },
93
+ "GROUP2": {
94
+ "type": [
95
+ "object"
96
+ ],
97
+ "properties": {
98
+ "VAR1": {
99
+ "type": [
100
+ "string"
101
+ ],
102
+ "nullable": true
103
+ }
104
+ },
105
+ "nullable": true
106
+ }
107
+ },
108
+ "nullable": true
109
+ },
110
+ "C4": {
111
+ "type": [
112
+ "string"
113
+ ],
114
+ "format": "utc-millisec",
115
+ "nullable": true
116
+ },
117
+ "NODE_ENV": {
118
+ "type": [
119
+ "string"
120
+ ],
121
+ "nullable": true
122
+ }
123
+ }
124
+ },
125
+ "azure-key-vault": {
126
+ "type": "object",
127
+ "properties": {
128
+ "VAR1": {
129
+ "type": [
130
+ "boolean"
131
+ ],
132
+ "nullable": true
133
+ },
134
+ "VAR2": {
135
+ "type": [
136
+ "boolean"
137
+ ],
138
+ "nullable": true
139
+ },
140
+ "VAR3": {
141
+ "type": [
142
+ "integer"
143
+ ],
144
+ "nullable": true
145
+ },
146
+ "VAR4": {
147
+ "type": [
148
+ "string"
149
+ ],
150
+ "nullable": true
151
+ },
152
+ "ARR1": {
153
+ "type": [
154
+ "array"
155
+ ],
156
+ "nullable": true
157
+ },
158
+ "GROUP2": {
159
+ "type": [
160
+ "object"
161
+ ],
162
+ "properties": {
163
+ "VAR1": {
164
+ "type": [
165
+ "string"
166
+ ],
167
+ "nullable": true
168
+ },
169
+ "VAR2": {
170
+ "type": [
171
+ "string"
172
+ ],
173
+ "nullable": true
174
+ }
175
+ },
176
+ "nullable": true
177
+ },
178
+ "$SECRET": {
179
+ "type": [
180
+ "string"
181
+ ],
182
+ "nullable": true
183
+ },
184
+ "GROUP1": {
185
+ "type": [
186
+ "object"
187
+ ],
188
+ "properties": {
189
+ "VAR1": {
190
+ "type": [
191
+ "null"
192
+ ],
193
+ "nullable": true
194
+ }
195
+ },
196
+ "nullable": true
197
+ }
198
+ }
199
+ },
200
+ "local": {
201
+ "type": "object",
202
+ "properties": {
203
+ "VAR4": {
204
+ "type": [
205
+ "string"
206
+ ],
207
+ "nullable": true
208
+ },
209
+ "GROUP1": {
210
+ "type": [
211
+ "object"
212
+ ],
213
+ "properties": {
214
+ "VAR1": {
215
+ "type": [
216
+ "null"
217
+ ],
218
+ "nullable": true
219
+ }
220
+ },
221
+ "nullable": true
222
+ },
223
+ "GROUP2": {
224
+ "type": [
225
+ "object"
226
+ ],
227
+ "properties": {
228
+ "VAR2": {
229
+ "type": [
230
+ "string"
231
+ ],
232
+ "nullable": true
233
+ }
234
+ },
235
+ "nullable": true
236
+ }
237
+ }
238
+ }
239
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "logMaskValuesOfKeys": ["SECRET"],
3
+ "providers": [
4
+ {
5
+ "path": "package-json"
6
+ },
7
+ {
8
+ "path": "app-settings"
9
+ },
10
+ {
11
+ "path": "azure-key-vault",
12
+ "config": {
13
+ "dev": {
14
+ "vaultUrl": "https://azure.vault.net"
15
+ }
16
+ }
17
+ },
18
+ {
19
+ "path": "local"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,42 @@
1
+ import { execEnv, execDebugEnv } from './exec';
2
+
3
+ const subcmd = ': node tests/run.js';
4
+
5
+ describe('env command', () => {
6
+ test('show helps', () => {
7
+ const response = execEnv('--help');
8
+
9
+ expect(response).toMatch(/usage: env/i);
10
+ });
11
+
12
+ test('load env into run.js', () => {
13
+ const response = execEnv('-e dev', '--m debug', subcmd);
14
+
15
+ expect(response).not.toMatch(/error/i);
16
+ });
17
+
18
+ test('load env without modes into run.js', () => {
19
+ const response = execEnv('-e dev', ': node tests/run.js');
20
+
21
+ expect(response).not.toMatch(/error/i);
22
+ });
23
+
24
+ test('load env with two modes into run.js', () => {
25
+ const response = execEnv('-e dev', '--m debug build', subcmd);
26
+
27
+ expect(response).not.toMatch(/error/i);
28
+ });
29
+
30
+ test('load env with options after subcmd', () => {
31
+ const response = execEnv('-e dev', subcmd, ': -m debug');
32
+
33
+ expect(response).not.toMatch(/error/i);
34
+ });
35
+
36
+ test('logger must not show SECRET variable value', () => {
37
+ const response = execDebugEnv('-e dev', subcmd);
38
+
39
+ expect(response).not.toMatch(/error/i);
40
+ expect(response).not.toMatch(/any secret/i);
41
+ });
42
+ });
package/tests/exec.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { execSync } from 'child_process';
2
+
3
+ const CMD = 'node dist/main.js';
4
+
5
+ const BASE_ARGS = ['--root tests/env', '--mock'];
6
+
7
+ export const execEnv = (...args: string[]): string | undefined => {
8
+ return execSync(
9
+ `${CMD} ${[...BASE_ARGS, '--log error', ...args].join(' ')}`
10
+ )?.toString();
11
+ };
12
+
13
+ export const execDebugEnv = (...args: string[]): string | undefined => {
14
+ return execSync(
15
+ `${CMD} ${[...BASE_ARGS, '--log debug', ...args].join(' ')}`
16
+ )?.toString();
17
+ };
18
+
19
+ export { execSync as exec } from 'child_process';
@@ -0,0 +1,9 @@
1
+ import { execEnv } from './exec';
2
+
3
+ describe('export commands', () => {
4
+ test('export', () => {
5
+ const response = execEnv('export', '-e dev', '-m debug');
6
+
7
+ expect(response).not.toMatch(/error/i);
8
+ });
9
+ });
@@ -0,0 +1,15 @@
1
+ import { execEnv } from './exec';
2
+
3
+ describe('pull & push commands', () => {
4
+ test('pull', () => {
5
+ const response = execEnv('pull', '-e dev');
6
+
7
+ expect(response).not.toMatch(/error/i);
8
+ });
9
+
10
+ test('push', () => {
11
+ const response = execEnv('push', '-e dev');
12
+
13
+ expect(response).not.toMatch(/error/i);
14
+ });
15
+ });
package/tests/run.js ADDED
@@ -0,0 +1,32 @@
1
+ function validateEnv(...vars) {
2
+ for(const key of vars) {
3
+ if(!process.env[key])
4
+ {
5
+ throw new Error(`${key} dont loaded`);
6
+ }
7
+ }
8
+ }
9
+
10
+ validateEnv(
11
+ 'NODE_ENV',
12
+ 'ENV',
13
+ 'VERSION',
14
+ 'PROJECT',
15
+ 'NAME',
16
+ 'TITLE',
17
+ 'DESCRIPTION',
18
+ 'VAR1',
19
+ 'C1',
20
+ 'C2',
21
+ 'C3',
22
+ 'C4',
23
+ 'GROUP1__VAR2',
24
+ 'GROUP1__VAR3',
25
+ 'GROUP1__GROUP2__VAR1',
26
+ 'VAR2',
27
+ 'VAR3',
28
+ 'VAR4',
29
+ 'ARR1',
30
+ 'GROUP2__VAR1',
31
+ 'GROUP2__VAR2'
32
+ );
@@ -0,0 +1,9 @@
1
+ import { execEnv } from './exec';
2
+
3
+ describe('schema command', () => {
4
+ test('schema', () => {
5
+ const response = execEnv('schema', '-e dev', '-m debug');
6
+
7
+ expect(response).not.toMatch(/error/i);
8
+ });
9
+ });
package/tests/setup.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { exec, execEnv } from './exec';
2
+
3
+ /**
4
+ * Builds app and regenerates schema.
5
+ */
6
+ function setup(): void {
7
+ // builds application
8
+ exec('npm run build');
9
+ // generates schema from environment variables
10
+ execEnv('schema', '-e dev', '-m debug');
11
+ }
12
+
13
+ export default setup;
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": [
4
+ "tests/**/*",
5
+ "**/*.spec.ts",
6
+ "**/*.test.ts",
7
+ "**/__tests__",
8
+ "**/__mocks__"
9
+ ]
10
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": "src",
4
+ "outDir": "dist",
5
+
6
+ "target": "es2018",
7
+ "module": "commonjs",
8
+ "moduleResolution": "node",
9
+ "resolveJsonModule": true,
10
+
11
+ "allowJs": false,
12
+ "checkJs": false,
13
+
14
+ "experimentalDecorators": true,
15
+ "emitDecoratorMetadata": true,
16
+
17
+ "incremental": true,
18
+ "sourceMap": true,
19
+ "declaration": true,
20
+ "declarationMap": true,
21
+ "removeComments": true,
22
+
23
+ "isolatedModules": true,
24
+ "esModuleInterop": true,
25
+ "importHelpers": false,
26
+ "skipLibCheck": false,
27
+ "downlevelIteration": false,
28
+
29
+ "strict": true,
30
+ "strictPropertyInitialization": false,
31
+ "noFallthroughCasesInSwitch": false,
32
+ "noUnusedLocals": false,
33
+ "noUnusedParameters": false,
34
+ "exactOptionalPropertyTypes": false
35
+ },
36
+ "include": ["src/**/*", "tests/**/*", "**/*.spec.ts", "**/*.test.ts"]
37
+ }
package/arguments.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import { JSONSchemaType } from 'ajv';
2
- import { Arguments, Options } from 'yargs';
3
- import { EnvProviderConfig } from './interfaces';
4
- export interface CommandArguments extends Arguments {
5
- env: string;
6
- modes?: string[];
7
- app?: Record<string, unknown>;
8
- schema?: Record<string, JSONSchemaType<object>>;
9
- providers: EnvProviderConfig[];
10
- local: boolean;
11
- nestingDelimiter: string;
12
- arrayDescomposition: boolean;
13
- expand: boolean;
14
- root: string;
15
- configFile: string;
16
- schemaFile: string;
17
- resolve: 'merge' | 'override';
18
- nullable: boolean;
19
- detectFormat: boolean;
20
- logLevel?: 'silly' | 'trace' | 'debug' | 'info' | 'warn' | 'error';
21
- logMaskAnyRegEx?: string[];
22
- logMaskValuesOfKeys?: string[];
23
- }
24
- export declare const args: Record<keyof CommandArguments, Options>;
25
- //# sourceMappingURL=arguments.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arguments.d.ts","sourceRoot":"","sources":["../src/arguments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AASjD,MAAM,WAAW,gBAAiB,SAAQ,SAAS;IAC/C,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,SAAS,EAAE,iBAAiB,EAAE,CAAC;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,E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AAO,EAAE,IAAI;QACb,QAAQ,EAAE,4DAA4D;KACzE;IACD,QAAQ,EAAE;QACN,KAAK,EAAE,MAAM,CAAC,aAAa;QAC3B,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,MAAM;QACf,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC;KAChE;IACD,eAAe,EAAE;QACb,KAAK,EAAE,MAAM,CAAC,aAAa;QAC3B,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,EAAE;KACd;IACD,mBAAmB,EAAE;QACjB,KAAK,EAAE,MAAM,CAAC,aAAa;QAC3B,KAAK,EAAE,KAAK;QACZ,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,EAAE;KACd;CACJ,CAAC"}
@@ -1,8 +0,0 @@
1
- import { CommandModule } from 'yargs';
2
- import { CommandArguments } from '../arguments';
3
- export interface EnvCommandArguments extends CommandArguments {
4
- subcmd: string[];
5
- schemaValidate: boolean;
6
- }
7
- export declare const envCommand: CommandModule<any, EnvCommandArguments>;
8
- //# sourceMappingURL=env.command.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"env.command.d.ts","sourceRoot":"","sources":["../../src/commands/env.command.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAahD,MAAM,WAAW,mBAAoB,SAAQ,gBAAgB;IAGzD,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB,cAAc,EAAE,OAAO,CAAC;CAC3B;AAQD,eAAO,MAAM,UAAU,EAAE,aAAa,CAAC,GAAG,EAAE,mBAAmB,CA2G9D,CAAC"}
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.envCommand = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
8
- const merge_deep_1 = __importDefault(require("merge-deep"));
9
- const child_process_1 = require("child_process");
10
- const utils_1 = require("../utils");
11
- exports.envCommand = {
12
- command: '$0 [options..] [: <subcmd> :]',
13
- describe: 'Inject environment variables into process',
14
- builder: (builder) => {
15
- builder
16
- .options({
17
- subcmd: {
18
- type: 'array',
19
- describe: 'Command for inject environment variables'
20
- },
21
- schemaValidate: {
22
- alias: 'validate',
23
- type: 'boolean',
24
- default: true,
25
- describe: 'Whether validates variables using JSON schema'
26
- }
27
- })
28
- .example('env -e dev -m test unit : npm test', 'Loads "dev" environment variables, in "test" and "unit" modes, for "npm start" command')
29
- .example('env -e dev -m debug : npm start : -c my-config.json', 'Loads "dev" environment variables, in "debug" mode, for "npm test" command and custom config file')
30
- .example('env -e dev -m debug -c [[root]]/[[env]].env.json : npm start', 'Loads custom config file placed in root folder and named same as the env')
31
- .check((argv) => {
32
- if (argv._.length === 0 && !argv.subcmd) {
33
- utils_1.logger.error('No one subcommand provided for exec surrounded by :');
34
- process.exit(1);
35
- }
36
- return true;
37
- });
38
- return builder;
39
- },
40
- handler: async ({ providers, schemaValidate, expand, ...argv }) => {
41
- var _a;
42
- const results = await (0, utils_1.loadVariablesFromProviders)(providers, argv);
43
- let env = (0, merge_deep_1.default)({ NODE_ENV: 'development' }, ...(0, utils_1.flatResults)(results));
44
- env = (0, utils_1.flatten)(env, argv.nestingDelimiter);
45
- if (schemaValidate) {
46
- let schema = {};
47
- for (const { handler: { key } } of providers) {
48
- const providerSchema = (_a = argv.schema) === null || _a === void 0 ? void 0 : _a[key];
49
- if (providerSchema) {
50
- schema = Object.assign(schema, (0, utils_1.flatSchema)(providerSchema, '', argv.nestingDelimiter));
51
- }
52
- }
53
- const validator = (0, utils_1.createValidator)({
54
- type: 'object',
55
- properties: schema
56
- });
57
- if (!validator(env)) {
58
- utils_1.logger.error('schema validation failed', validator.errors);
59
- process.exit(1);
60
- }
61
- }
62
- env = (0, utils_1.normalize)(env, argv.nestingDelimiter, argv.arrayDescomposition);
63
- if (expand)
64
- env = (0, utils_1.interpolate)(env, env);
65
- utils_1.logger.debug('environment loaded:', env);
66
- process.env = {
67
- ...process.env,
68
- ...env
69
- };
70
- utils_1.logger.info('executing command >', chalk_1.default.bold.yellow(argv.subcmd.join(' ')));
71
- (0, child_process_1.spawn)(argv.subcmd[0], argv.subcmd.slice(1), {
72
- stdio: 'inherit',
73
- shell: true
74
- }).on('exit', (code) => {
75
- if (code === 0) {
76
- utils_1.logger.info('process finished successfully');
77
- }
78
- else {
79
- utils_1.logger.error('process finished with error');
80
- process.exit(1);
81
- }
82
- });
83
- }
84
- };
85
- //# sourceMappingURL=env.command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"env.command.js","sourceRoot":"","sources":["../../src/commands/env.command.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,4DAA+B;AAC/B,iDAAsC;AAGtC,oCAUkB;AAgBL,QAAA,UAAU,GAA4C;IAC/D,OAAO,EAAE,+BAA+B;IACxC,QAAQ,EAAE,2CAA2C;IACrD,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE;QACjB,OAAO;aACF,OAAO,CAAC;YACL,MAAM,EAAE;gBACJ,IAAI,EAAE,OAAO;gBACb,QAAQ,EAAE,0CAA0C;aACvD;YACD,cAAc,EAAE;gBACZ,KAAK,EAAE,UAAU;gBACjB,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,+CAA+C;aAC5D;SACJ,CAAC;aACD,OAAO,CACJ,oCAAoC,EACpC,wFAAwF,CAC3F;aACA,OAAO,CACJ,qDAAqD,EACrD,mGAAmG,CACtG;aACA,OAAO,CACJ,8DAA8D,EAC9D,0EAA0E,CAC7E;aACA,KAAK,C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,GAAG,CAAC,EAAE;gBACjB,cAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;gBAE3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACnB;SACJ;QAED,GAAG,GAAG,IAAA,iBAAS,EAAC,GAAG,EAAE,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACtE,IAAI,MAAM;YAAE,GAAG,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAExC,cAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;QAGzC,OAAO,CAAC,GAAG,GAAG;YACV,GAAG,OAAO,CAAC,GAAG;YACd,GAAG,GAAG;SACT,CAAC;QAEF,cAAM,CAAC,IAAI,CACP,qBAAqB,EACrB,eAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAC3C,CAAC;QAEF,IAAA,qBAAK,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;YACxC,KAAK,EAAE,SAAS;YAChB,KAAK,EAAE,IAAI;SACd,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACnB,IAAI,IAAI,KAAK,CAAC,EAAE;gBACZ,cAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;aAChD;iBAAM;gBACH,cAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;gBAE5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACnB;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ,CAAC"}
@@ -1,8 +0,0 @@
1
- import { CommandModule } from 'yargs';
2
- import { CommandArguments } from '../arguments';
3
- export interface ExportCommandArguments extends CommandArguments {
4
- format: 'json' | 'dotenv';
5
- uri: string;
6
- }
7
- export declare const exportCommand: CommandModule<any, ExportCommandArguments>;
8
- //# sourceMappingURL=export.command.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"export.command.d.ts","sourceRoot":"","sources":["../../src/commands/export.command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAYhD,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC5D,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;IAE1B,GAAG,EAAE,MAAM,CAAC;CACf;AAQD,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,GAAG,EAAE,sBAAsB,CA6DpE,CAAC"}
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.exportCommand = void 0;
7
- const merge_deep_1 = __importDefault(require("merge-deep"));
8
- const utils_1 = require("../utils");
9
- exports.exportCommand = {
10
- command: 'export [options..]',
11
- describe: 'Export unified environment variables to a file from providers',
12
- builder: (builder) => {
13
- builder
14
- .options({
15
- uri: {
16
- alias: ['u', 'p', 'path'],
17
- type: 'string',
18
- default: '.env',
19
- describe: 'Uri for export file with variables'
20
- },
21
- format: {
22
- alias: 'f',
23
- type: 'string',
24
- default: 'dotenv',
25
- choices: ['json', 'dotenv'],
26
- describe: 'Format for export variables'
27
- }
28
- })
29
- .example('env export -e dev -m build', 'Exports "dev" variables to a dotenv file at root as ".env"')
30
- .example('env export -e prod -m build -f json --uri [[env]].env.json', 'Exports "prod" variables to a json file at root as "prod.env.json"');
31
- return builder;
32
- },
33
- handler: async ({ providers, expand, ...argv }) => {
34
- const results = await (0, utils_1.loadVariablesFromProviders)(providers, argv);
35
- let env = (0, merge_deep_1.default)({ NODE_ENV: 'development' }, ...(0, utils_1.flatAndValidateResults)(results, argv));
36
- env = (0, utils_1.flatten)(env, argv.nestingDelimiter);
37
- env = (0, utils_1.normalize)(env, argv.nestingDelimiter, argv.arrayDescomposition);
38
- if (expand)
39
- env = (0, utils_1.interpolate)(env, env);
40
- utils_1.logger.debug('environment loaded:', env);
41
- const { format, uri } = argv;
42
- switch (format) {
43
- case 'dotenv':
44
- await (0, utils_1.writeEnvFromJson)(uri, env, true);
45
- break;
46
- case 'json':
47
- await (0, utils_1.writeJson)(uri, env, true);
48
- break;
49
- default:
50
- utils_1.logger.error(`format ${format} not recognized`);
51
- }
52
- }
53
- };
54
- //# sourceMappingURL=export.command.js.map