@lindorm/config 0.1.2 → 0.2.1
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/.node_config.json +3 -0
- package/.node_config.yml +3 -0
- package/CHANGELOG.md +16 -0
- package/README.md +407 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +56 -0
- package/dist/cli.js.map +1 -0
- package/dist/types/types.d.ts +8 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/utils/configuration.d.ts +3 -13
- package/dist/utils/configuration.d.ts.map +1 -1
- package/dist/utils/configuration.js +14 -9
- package/dist/utils/configuration.js.map +1 -1
- package/dist/utils/private/coerce-all.d.ts +3 -0
- package/dist/utils/private/coerce-all.d.ts.map +1 -0
- package/dist/utils/private/coerce-all.js +33 -0
- package/dist/utils/private/coerce-all.js.map +1 -0
- package/dist/utils/private/find-process-env-value.d.ts +1 -1
- package/dist/utils/private/find-process-env-value.d.ts.map +1 -1
- package/dist/utils/private/find-process-env-value.js +6 -16
- package/dist/utils/private/find-process-env-value.js.map +1 -1
- package/dist/utils/private/index.d.ts +3 -1
- package/dist/utils/private/index.d.ts.map +1 -1
- package/dist/utils/private/index.js +3 -1
- package/dist/utils/private/index.js.map +1 -1
- package/dist/utils/private/load-config.d.ts +4 -0
- package/dist/utils/private/load-config.d.ts.map +1 -0
- package/dist/utils/private/load-config.js +16 -0
- package/dist/utils/private/load-config.js.map +1 -0
- package/dist/utils/private/load-node-config.d.ts +4 -0
- package/dist/utils/private/load-node-config.d.ts.map +1 -0
- package/dist/utils/private/load-node-config.js +17 -0
- package/dist/utils/private/load-node-config.js.map +1 -0
- package/dist/utils/private/merge-object-with-process-env.d.ts +1 -1
- package/dist/utils/private/merge-object-with-process-env.d.ts.map +1 -1
- package/dist/utils/private/merge-object-with-process-env.js +13 -6
- package/dist/utils/private/merge-object-with-process-env.js.map +1 -1
- package/package.json +19 -9
- package/dist/utils/private/merge-value-with-process-env.d.ts +0 -3
- package/dist/utils/private/merge-value-with-process-env.d.ts.map +0 -1
- package/dist/utils/private/merge-value-with-process-env.js +0 -10
- package/dist/utils/private/merge-value-with-process-env.js.map +0 -1
package/.node_config.yml
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.2.1](https://github.com/lindorm-io/monorepo/compare/@lindorm/config@0.2.0...@lindorm/config@0.2.1) (2025-07-10)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @lindorm/config
|
|
9
|
+
|
|
10
|
+
# [0.2.0](https://github.com/lindorm-io/monorepo/compare/@lindorm/config@0.1.2...@lindorm/config@0.2.0) (2025-06-17)
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- solve issues with merge ([6561027](https://github.com/lindorm-io/monorepo/commit/6561027172f31f154be84f122a68c1361399abd3))
|
|
15
|
+
- update cli ([552a9f0](https://github.com/lindorm-io/monorepo/commit/552a9f0a0839d756d9e856b7a6842aee4e01cac5))
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
- add cli for generating node_config env ([57e5ff9](https://github.com/lindorm-io/monorepo/commit/57e5ff9cad0aa655420f6232f23ae526545331b4))
|
|
20
|
+
- use zod to coerce and validate config ([03ed9b6](https://github.com/lindorm-io/monorepo/commit/03ed9b65f95bab3168a081c669118b3ed6d45538))
|
|
21
|
+
|
|
6
22
|
## [0.1.2](https://github.com/lindorm-io/monorepo/compare/@lindorm/config@0.1.1...@lindorm/config@0.1.2) (2025-01-28)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @lindorm/config
|
package/README.md
CHANGED
|
@@ -1 +1,408 @@
|
|
|
1
1
|
# @lindorm/config
|
|
2
|
+
|
|
3
|
+
Type-safe configuration management with environment variable overrides, YAML file support, and Zod schema validation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @lindorm/config
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Type-Safe Configuration**: Full TypeScript support with Zod schema validation
|
|
14
|
+
- **Multiple Configuration Sources**: YAML files, environment variables, and NODE_CONFIG
|
|
15
|
+
- **Automatic Type Coercion**: Converts string values to correct types (numbers, booleans, arrays, objects)
|
|
16
|
+
- **Environment Variable Overrides**: Override any config value with environment variables
|
|
17
|
+
- **Case Conversion**: Automatic conversion between snake_case (files/env) and camelCase (code)
|
|
18
|
+
- **Environment-Specific Config**: Load different configurations based on NODE_ENV
|
|
19
|
+
- **CLI Tool**: Convert local config files to NODE_CONFIG environment variable
|
|
20
|
+
- **NPM Package Info**: Automatically includes package name and version
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { configuration } from "@lindorm/config";
|
|
26
|
+
import { z } from "zod";
|
|
27
|
+
|
|
28
|
+
// Define your configuration schema
|
|
29
|
+
const config = configuration({
|
|
30
|
+
server: z.object({
|
|
31
|
+
port: z.number().default(3000),
|
|
32
|
+
host: z.string().default("localhost"),
|
|
33
|
+
}),
|
|
34
|
+
database: z.object({
|
|
35
|
+
url: z.string(),
|
|
36
|
+
poolSize: z.number().default(10),
|
|
37
|
+
}),
|
|
38
|
+
features: z.array(z.string()).default([]),
|
|
39
|
+
isProduction: z.boolean().default(false),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Use your typed configuration
|
|
43
|
+
console.log(config.server.port); // number
|
|
44
|
+
console.log(config.database.url); // string
|
|
45
|
+
console.log(config.npm.package.name); // automatically added
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Configuration Sources
|
|
49
|
+
|
|
50
|
+
Configuration is loaded and merged from multiple sources in this order:
|
|
51
|
+
|
|
52
|
+
1. **YAML Configuration Files** (`config/` directory)
|
|
53
|
+
2. **Environment Variables** (automatic override)
|
|
54
|
+
3. **NODE_CONFIG** environment variable (JSON object)
|
|
55
|
+
4. **NPM Package Information** (name and version)
|
|
56
|
+
|
|
57
|
+
### 1. YAML Configuration Files
|
|
58
|
+
|
|
59
|
+
Create a `config/` directory in your project root with environment-specific YAML files:
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
# config/default.yml
|
|
63
|
+
server:
|
|
64
|
+
port: 3000
|
|
65
|
+
host: localhost
|
|
66
|
+
|
|
67
|
+
database:
|
|
68
|
+
url: postgresql://localhost/myapp
|
|
69
|
+
pool_size: 10
|
|
70
|
+
|
|
71
|
+
features:
|
|
72
|
+
- feature1
|
|
73
|
+
- feature2
|
|
74
|
+
|
|
75
|
+
is_production: false
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```yaml
|
|
79
|
+
# config/production.yml
|
|
80
|
+
server:
|
|
81
|
+
port: 8080
|
|
82
|
+
host: 0.0.0.0
|
|
83
|
+
|
|
84
|
+
database:
|
|
85
|
+
pool_size: 50
|
|
86
|
+
|
|
87
|
+
is_production: true
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Files are loaded based on NODE_ENV:
|
|
91
|
+
- `default.yml` - Always loaded first
|
|
92
|
+
- `{NODE_ENV}.yml` - Environment-specific overrides (e.g., `production.yml`)
|
|
93
|
+
|
|
94
|
+
### 2. Environment Variables
|
|
95
|
+
|
|
96
|
+
Override any configuration value using environment variables. The package automatically converts between naming conventions:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Override server.port
|
|
100
|
+
SERVER_PORT=8080
|
|
101
|
+
|
|
102
|
+
# Override database.url
|
|
103
|
+
DATABASE_URL=postgresql://prod-server/myapp
|
|
104
|
+
|
|
105
|
+
# Override nested values
|
|
106
|
+
DATABASE_POOL_SIZE=50
|
|
107
|
+
|
|
108
|
+
# Arrays (JSON format)
|
|
109
|
+
FEATURES='["feature1", "feature2", "feature3"]'
|
|
110
|
+
|
|
111
|
+
# Booleans
|
|
112
|
+
IS_PRODUCTION=true
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Naming Convention**:
|
|
116
|
+
- Nested keys are flattened with underscores
|
|
117
|
+
- camelCase becomes snake_case
|
|
118
|
+
- All uppercase for environment variables
|
|
119
|
+
|
|
120
|
+
Examples:
|
|
121
|
+
- `server.port` → `SERVER_PORT`
|
|
122
|
+
- `database.poolSize` → `DATABASE_POOL_SIZE`
|
|
123
|
+
- `nested.some.deepValue` → `NESTED_SOME_DEEP_VALUE`
|
|
124
|
+
|
|
125
|
+
### 3. NODE_CONFIG
|
|
126
|
+
|
|
127
|
+
Pass configuration as a JSON string via NODE_CONFIG environment variable:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
NODE_CONFIG='{"server":{"port":9000},"features":["feat1","feat2"]}'
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### 4. .env Files
|
|
134
|
+
|
|
135
|
+
The package automatically loads `.env` files using `@dotenvx/dotenvx`:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# .env
|
|
139
|
+
DATABASE_URL=postgresql://localhost/myapp
|
|
140
|
+
SERVER_PORT=3000
|
|
141
|
+
|
|
142
|
+
# .env.production
|
|
143
|
+
DATABASE_URL=postgresql://prod-server/myapp
|
|
144
|
+
SERVER_PORT=8080
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Environment-specific `.env` files are loaded based on NODE_ENV:
|
|
148
|
+
- `.env` - Always loaded
|
|
149
|
+
- `.env.{NODE_ENV}` - Environment-specific overrides
|
|
150
|
+
|
|
151
|
+
## Advanced Usage
|
|
152
|
+
|
|
153
|
+
### Complex Schema with Defaults
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { configuration } from "@lindorm/config";
|
|
157
|
+
import { z } from "zod";
|
|
158
|
+
|
|
159
|
+
const config = configuration({
|
|
160
|
+
app: z.object({
|
|
161
|
+
name: z.string(),
|
|
162
|
+
version: z.string().optional(),
|
|
163
|
+
environment: z.enum(["development", "staging", "production"]),
|
|
164
|
+
}),
|
|
165
|
+
|
|
166
|
+
server: z.object({
|
|
167
|
+
port: z.number().min(1).max(65535),
|
|
168
|
+
host: z.string().ip(), // IP address validation
|
|
169
|
+
cors: z.object({
|
|
170
|
+
enabled: z.boolean().default(true),
|
|
171
|
+
origins: z.array(z.string().url()).default([]),
|
|
172
|
+
}),
|
|
173
|
+
}),
|
|
174
|
+
|
|
175
|
+
database: z.object({
|
|
176
|
+
primary: z.object({
|
|
177
|
+
host: z.string(),
|
|
178
|
+
port: z.number().default(5432),
|
|
179
|
+
name: z.string(),
|
|
180
|
+
user: z.string(),
|
|
181
|
+
password: z.string(),
|
|
182
|
+
ssl: z.boolean().default(false),
|
|
183
|
+
}),
|
|
184
|
+
replica: z.object({
|
|
185
|
+
host: z.string(),
|
|
186
|
+
port: z.number(),
|
|
187
|
+
}).optional(),
|
|
188
|
+
}),
|
|
189
|
+
|
|
190
|
+
redis: z.object({
|
|
191
|
+
url: z.string().url(),
|
|
192
|
+
ttl: z.number().default(3600),
|
|
193
|
+
}),
|
|
194
|
+
|
|
195
|
+
logging: z.object({
|
|
196
|
+
level: z.enum(["debug", "info", "warn", "error"]).default("info"),
|
|
197
|
+
format: z.enum(["json", "pretty"]).default("json"),
|
|
198
|
+
}),
|
|
199
|
+
|
|
200
|
+
features: z.record(z.boolean()).default({}),
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Using the Config Object
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
// Type-safe access to configuration
|
|
208
|
+
if (config.server.cors.enabled) {
|
|
209
|
+
app.use(cors({ origins: config.server.cors.origins }));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Database connection
|
|
213
|
+
const dbConfig = {
|
|
214
|
+
host: config.database.primary.host,
|
|
215
|
+
port: config.database.primary.port,
|
|
216
|
+
database: config.database.primary.name,
|
|
217
|
+
user: config.database.primary.user,
|
|
218
|
+
password: config.database.primary.password,
|
|
219
|
+
ssl: config.database.primary.ssl,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// Feature flags
|
|
223
|
+
if (config.features.newDashboard) {
|
|
224
|
+
app.use("/dashboard", newDashboardRouter);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Logging configuration
|
|
228
|
+
logger.setLevel(config.logging.level);
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Working with Arrays and Objects
|
|
232
|
+
|
|
233
|
+
Environment variables support JSON format for complex types:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
# Array of strings
|
|
237
|
+
CORS_ORIGINS='["https://app.example.com", "https://admin.example.com"]'
|
|
238
|
+
|
|
239
|
+
# Object
|
|
240
|
+
FEATURES='{"newDashboard": true, "betaApi": false}'
|
|
241
|
+
|
|
242
|
+
# Array of objects
|
|
243
|
+
SERVERS='[{"host": "server1.com", "port": 8080}, {"host": "server2.com", "port": 8081}]'
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## CLI Tool
|
|
247
|
+
|
|
248
|
+
The package includes a CLI tool for working with configuration:
|
|
249
|
+
|
|
250
|
+
### Convert Config to NODE_CONFIG
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
# Create a .node_config file (JSON, YAML, or YML)
|
|
254
|
+
echo '{"server": {"port": 9000}}' > .node_config
|
|
255
|
+
|
|
256
|
+
# Generate NODE_CONFIG environment variable
|
|
257
|
+
npx config node_config
|
|
258
|
+
# Output: NODE_CONFIG={"server":{"port":9000}}
|
|
259
|
+
|
|
260
|
+
# Use in scripts
|
|
261
|
+
export $(npx config node_config)
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
This is useful for:
|
|
265
|
+
- Docker containers
|
|
266
|
+
- CI/CD pipelines
|
|
267
|
+
- Deployment scripts
|
|
268
|
+
|
|
269
|
+
## Best Practices
|
|
270
|
+
|
|
271
|
+
### 1. Schema Definition
|
|
272
|
+
|
|
273
|
+
Define your schema in a separate file for reusability:
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
// config/schema.ts
|
|
277
|
+
import { z } from "zod";
|
|
278
|
+
|
|
279
|
+
export const configSchema = {
|
|
280
|
+
server: z.object({
|
|
281
|
+
port: z.number().default(3000),
|
|
282
|
+
host: z.string().default("localhost"),
|
|
283
|
+
}),
|
|
284
|
+
// ... rest of schema
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// config/index.ts
|
|
288
|
+
import { configuration } from "@lindorm/config";
|
|
289
|
+
import { configSchema } from "./schema";
|
|
290
|
+
|
|
291
|
+
export const config = configuration(configSchema);
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### 2. Environment-Specific Defaults
|
|
295
|
+
|
|
296
|
+
Use YAML files for environment-specific defaults:
|
|
297
|
+
|
|
298
|
+
```yaml
|
|
299
|
+
# config/default.yml
|
|
300
|
+
logging:
|
|
301
|
+
level: debug
|
|
302
|
+
format: pretty
|
|
303
|
+
|
|
304
|
+
# config/production.yml
|
|
305
|
+
logging:
|
|
306
|
+
level: info
|
|
307
|
+
format: json
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### 3. Secret Management
|
|
311
|
+
|
|
312
|
+
Never commit secrets to config files. Use environment variables:
|
|
313
|
+
|
|
314
|
+
```yaml
|
|
315
|
+
# config/default.yml
|
|
316
|
+
database:
|
|
317
|
+
host: localhost
|
|
318
|
+
port: 5432
|
|
319
|
+
name: myapp
|
|
320
|
+
# DON'T put passwords here
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
# .env (add to .gitignore)
|
|
325
|
+
DATABASE_USER=myuser
|
|
326
|
+
DATABASE_PASSWORD=secret123
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### 4. Validation
|
|
330
|
+
|
|
331
|
+
Use Zod's features for comprehensive validation:
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
const config = configuration({
|
|
335
|
+
email: z.string().email(),
|
|
336
|
+
port: z.number().min(1).max(65535),
|
|
337
|
+
url: z.string().url(),
|
|
338
|
+
apiKey: z.string().min(32),
|
|
339
|
+
retryAttempts: z.number().int().positive().max(10),
|
|
340
|
+
});
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## Automatic Type Coercion
|
|
344
|
+
|
|
345
|
+
The package automatically converts string values to the correct types:
|
|
346
|
+
|
|
347
|
+
| Zod Type | Input | Output |
|
|
348
|
+
|----------|-------|--------|
|
|
349
|
+
| z.number() | "123" | 123 |
|
|
350
|
+
| z.boolean() | "true" | true |
|
|
351
|
+
| z.array() | '["a","b"]' | ["a", "b"] |
|
|
352
|
+
| z.object() | '{"a":1}' | { a: 1 } |
|
|
353
|
+
| z.bigint() | "9007199254740991" | 9007199254740991n |
|
|
354
|
+
| z.date() | "2023-01-01" | Date object |
|
|
355
|
+
|
|
356
|
+
## NPM Package Information
|
|
357
|
+
|
|
358
|
+
The configuration automatically includes package information:
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
const config = configuration({ /* your schema */ });
|
|
362
|
+
|
|
363
|
+
console.log(config.npm.package.name); // from package.json
|
|
364
|
+
console.log(config.npm.package.version); // from package.json
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## Error Handling
|
|
368
|
+
|
|
369
|
+
Configuration errors are thrown during initialization:
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
try {
|
|
373
|
+
const config = configuration({
|
|
374
|
+
required: z.string(), // No default
|
|
375
|
+
});
|
|
376
|
+
} catch (error) {
|
|
377
|
+
console.error("Configuration error:", error);
|
|
378
|
+
// Error will include details about missing required fields
|
|
379
|
+
}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
## Testing
|
|
383
|
+
|
|
384
|
+
For testing, you can override configuration using NODE_ENV and environment variables:
|
|
385
|
+
|
|
386
|
+
```typescript
|
|
387
|
+
// test/setup.ts
|
|
388
|
+
process.env.NODE_ENV = "test";
|
|
389
|
+
process.env.DATABASE_URL = "postgresql://localhost/test";
|
|
390
|
+
process.env.REDIS_URL = "redis://localhost:6379/1";
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
Or create a `config/test.yml`:
|
|
394
|
+
|
|
395
|
+
```yaml
|
|
396
|
+
database:
|
|
397
|
+
url: postgresql://localhost/test
|
|
398
|
+
|
|
399
|
+
redis:
|
|
400
|
+
url: redis://localhost:6379/1
|
|
401
|
+
|
|
402
|
+
logging:
|
|
403
|
+
level: error # Reduce noise in tests
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
## License
|
|
407
|
+
|
|
408
|
+
AGPL-3.0-or-later
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const js_yaml_1 = require("js-yaml");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
commander_1.program.name("config").description("CLI for managing configuration files");
|
|
9
|
+
const parseFile = (file) => {
|
|
10
|
+
if (file.endsWith(".json")) {
|
|
11
|
+
return parseJson(file);
|
|
12
|
+
}
|
|
13
|
+
if (file.endsWith(".yml") || file.endsWith(".yaml")) {
|
|
14
|
+
return parseYaml(file);
|
|
15
|
+
}
|
|
16
|
+
throw new Error("Unsupported file type");
|
|
17
|
+
};
|
|
18
|
+
const parseJson = (file) => JSON.parse((0, fs_1.readFileSync)(file, "utf-8"));
|
|
19
|
+
const parseYaml = (file) => (0, js_yaml_1.load)((0, fs_1.readFileSync)(file, "utf-8"));
|
|
20
|
+
commander_1.program
|
|
21
|
+
.command("node_config")
|
|
22
|
+
.description("Generate a NODE_CONFIG environment string from existing .node_config file")
|
|
23
|
+
.option("-f, --file <file>", "Path to the .node_config(?.json|yml|yaml) file", ".node_config")
|
|
24
|
+
.action((options) => {
|
|
25
|
+
try {
|
|
26
|
+
if (options.file !== ".node_config" &&
|
|
27
|
+
!(0, fs_1.existsSync)((0, path_1.join)(process.cwd(), options.file))) {
|
|
28
|
+
throw new Error(`File ${options.file} does not exist. Please provide a valid path to a .node_config file.`);
|
|
29
|
+
}
|
|
30
|
+
let file = options.file;
|
|
31
|
+
let result = "";
|
|
32
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(process.cwd(), options.file))) {
|
|
33
|
+
file = options.file;
|
|
34
|
+
}
|
|
35
|
+
else if ((0, fs_1.existsSync)((0, path_1.join)(process.cwd(), ".node_config.json"))) {
|
|
36
|
+
file = (0, path_1.join)(process.cwd(), ".node_config.json");
|
|
37
|
+
}
|
|
38
|
+
else if ((0, fs_1.existsSync)((0, path_1.join)(process.cwd(), ".node_config.yml"))) {
|
|
39
|
+
file = (0, path_1.join)(process.cwd(), ".node_config.yml");
|
|
40
|
+
}
|
|
41
|
+
else if ((0, fs_1.existsSync)((0, path_1.join)(process.cwd(), ".node_config.yaml"))) {
|
|
42
|
+
file = (0, path_1.join)(process.cwd(), ".node_config.yaml");
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw new Error("No .node_config file found. Please provide a valid path to a .node_config file.");
|
|
46
|
+
}
|
|
47
|
+
result = JSON.stringify(parseFile(file)).replace(/'/g, "'\\''");
|
|
48
|
+
console.log(`\nInsert the following into your env:\n\nNODE_CONFIG='${result}'\n`);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error(error.message);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
commander_1.program.parse();
|
|
56
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"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"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,MAAM,MAAM,cAAc,GAAG;IAAE,GAAG,EAAE;QAAE,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,CAAC;AAErF,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC"}
|
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
npm: {
|
|
5
|
-
package: {
|
|
6
|
-
name: string;
|
|
7
|
-
version: string;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
type Configuration<T extends Dict = Dict> = NpmInformation & T;
|
|
12
|
-
export declare const configuration: <T extends Dict = Dict>(mode?: ChangeCase) => Configuration<T>;
|
|
13
|
-
export {};
|
|
1
|
+
import { ZodRawShape } from "zod";
|
|
2
|
+
import { NpmInformation } from "../types";
|
|
3
|
+
export declare const configuration: <T extends ZodRawShape>(schema: T) => NpmInformation & T;
|
|
14
4
|
//# sourceMappingURL=configuration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../src/utils/configuration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../src/utils/configuration.ts"],"names":[],"mappings":"AAEA,OAAO,EAAK,WAAW,EAAE,MAAM,KAAK,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,WAAW,EAAE,QAAQ,CAAC,KAAG,cAAc,GAAG,CAuBjF,CAAC"}
|
|
@@ -5,23 +5,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.configuration = void 0;
|
|
7
7
|
const dotenvx_1 = __importDefault(require("@dotenvx/dotenvx"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const utils_1 = require("@lindorm/utils");
|
|
9
|
+
const zod_1 = require("zod");
|
|
10
10
|
const private_1 = require("./private");
|
|
11
|
-
const configuration = (
|
|
11
|
+
const configuration = (schema) => {
|
|
12
12
|
dotenvx_1.default.config({
|
|
13
13
|
path: process.env.NODE_ENV ? [`.env.${process.env.NODE_ENV}`, ".env"] : ".env",
|
|
14
14
|
quiet: true,
|
|
15
15
|
});
|
|
16
|
-
const
|
|
17
|
-
const
|
|
16
|
+
const config = (0, private_1.loadConfig)(process.env);
|
|
17
|
+
const node = (0, private_1.loadNodeConfig)(process.env);
|
|
18
|
+
const merged = (0, utils_1.merge)(config, node);
|
|
19
|
+
const zod = (0, private_1.coerceAll)(zod_1.z.object(schema));
|
|
20
|
+
const parsed = zod.parse(merged);
|
|
18
21
|
const npm = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
npm: {
|
|
23
|
+
package: {
|
|
24
|
+
name: process.env.npm_package_name || "",
|
|
25
|
+
version: process.env.npm_package_version || "",
|
|
26
|
+
},
|
|
22
27
|
},
|
|
23
28
|
};
|
|
24
|
-
return
|
|
29
|
+
return (0, utils_1.merge)(parsed, npm);
|
|
25
30
|
};
|
|
26
31
|
exports.configuration = configuration;
|
|
27
32
|
//# sourceMappingURL=configuration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../src/utils/configuration.ts"],"names":[],"mappings":";;;;;;AAAA,+DAAuC;AACvC,
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../src/utils/configuration.ts"],"names":[],"mappings":";;;;;;AAAA,+DAAuC;AACvC,0CAAuC;AACvC,6BAAqC;AAErC,uCAAkE;AAE3D,MAAM,aAAa,GAAG,CAAwB,MAAS,EAAsB,EAAE;IACpF,iBAAO,CAAC,MAAM,CAAC;QACb,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM;QAC9E,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,IAAA,oBAAU,EAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,IAAA,wBAAc,EAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,IAAA,aAAK,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAEnC,MAAM,GAAG,GAAG,IAAA,mBAAS,EAAC,OAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IACxC,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAEjC,MAAM,GAAG,GAAG;QACV,GAAG,EAAE;YACH,OAAO,EAAE;gBACP,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE;gBACxC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,EAAE;aAC/C;SACF;KACF,CAAC;IAEF,OAAO,IAAA,aAAK,EAAqB,MAAM,EAAE,GAAU,CAAC,CAAC;AACvD,CAAC,CAAC;AAvBW,QAAA,aAAa,iBAuBxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-all.d.ts","sourceRoot":"","sources":["../../../src/utils/private/coerce-all.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,UAAU,EAAE,MAAM,KAAK,CAAC;AAE3D,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,UAAU,EAAE,QAAQ,CAAC,KAAG,CAkC3D,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.coerceAll = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const coerceAll = (schema) => {
|
|
6
|
+
const def = schema._def;
|
|
7
|
+
switch (def.typeName) {
|
|
8
|
+
case zod_1.ZodFirstPartyTypeKind.ZodString:
|
|
9
|
+
return zod_1.z.coerce.string(def);
|
|
10
|
+
case zod_1.ZodFirstPartyTypeKind.ZodNumber:
|
|
11
|
+
return zod_1.z.coerce.number(def);
|
|
12
|
+
case zod_1.ZodFirstPartyTypeKind.ZodBoolean:
|
|
13
|
+
return zod_1.z.coerce.boolean(def);
|
|
14
|
+
case zod_1.ZodFirstPartyTypeKind.ZodDate:
|
|
15
|
+
return zod_1.z.coerce.date(def);
|
|
16
|
+
case zod_1.ZodFirstPartyTypeKind.ZodBigInt:
|
|
17
|
+
return zod_1.z.coerce.bigint(def);
|
|
18
|
+
case zod_1.ZodFirstPartyTypeKind.ZodArray:
|
|
19
|
+
return zod_1.z.array((0, exports.coerceAll)(def.type), def);
|
|
20
|
+
case zod_1.ZodFirstPartyTypeKind.ZodObject: {
|
|
21
|
+
const shape = def.shape();
|
|
22
|
+
const newShape = {};
|
|
23
|
+
for (const key in shape) {
|
|
24
|
+
newShape[key] = (0, exports.coerceAll)(shape[key]);
|
|
25
|
+
}
|
|
26
|
+
return zod_1.z.object(newShape, def);
|
|
27
|
+
}
|
|
28
|
+
default:
|
|
29
|
+
return schema;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.coerceAll = coerceAll;
|
|
33
|
+
//# sourceMappingURL=coerce-all.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce-all.js","sourceRoot":"","sources":["../../../src/utils/private/coerce-all.ts"],"names":[],"mappings":";;;AACA,6BAA2D;AAEpD,MAAM,SAAS,GAAG,CAAuB,MAAS,EAAK,EAAE;IAC9D,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC;IAExB,QAAQ,GAAG,CAAC,QAAQ,EAAE,CAAC;QACrB,KAAK,2BAAqB,CAAC,SAAS;YAClC,OAAO,OAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAQ,CAAC;QAErC,KAAK,2BAAqB,CAAC,SAAS;YAClC,OAAO,OAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAQ,CAAC;QAErC,KAAK,2BAAqB,CAAC,UAAU;YACnC,OAAO,OAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAQ,CAAC;QAEtC,KAAK,2BAAqB,CAAC,OAAO;YAChC,OAAO,OAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAQ,CAAC;QAEnC,KAAK,2BAAqB,CAAC,SAAS;YAClC,OAAO,OAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAQ,CAAC;QAErC,KAAK,2BAAqB,CAAC,QAAQ;YACjC,OAAO,OAAC,CAAC,KAAK,CAAC,IAAA,iBAAS,EAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAQ,CAAC;QAElD,KAAK,2BAAqB,CAAC,SAAS,CAAC,CAAC,CAAC;YACrC,MAAM,KAAK,GAAI,GAAG,CAAC,KAAgC,EAAE,CAAC;YACtD,MAAM,QAAQ,GAAqB,EAAE,CAAC;YACtC,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;gBACxB,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAA,iBAAS,EAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YACxC,CAAC;YACD,OAAO,OAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAQ,CAAC;QACxC,CAAC;QAED;YACE,OAAO,MAAM,CAAC;IAClB,CAAC;AACH,CAAC,CAAC;AAlCW,QAAA,SAAS,aAkCpB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProcessEnv } from "../../types";
|
|
2
|
-
export declare const findProcessEnvValue: (processEnv: ProcessEnv, key: string,
|
|
2
|
+
export declare const findProcessEnvValue: (processEnv: ProcessEnv, key: string, parent?: string) => any;
|
|
3
3
|
//# sourceMappingURL=find-process-env-value.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-process-env-value.d.ts","sourceRoot":"","sources":["../../../src/utils/private/find-process-env-value.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"find-process-env-value.d.ts","sourceRoot":"","sources":["../../../src/utils/private/find-process-env-value.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,eAAO,MAAM,mBAAmB,GAC9B,YAAY,UAAU,EACtB,KAAK,MAAM,EACX,SAAS,MAAM,KACd,GAQF,CAAC"}
|
|
@@ -2,23 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findProcessEnvValue = void 0;
|
|
4
4
|
const case_1 = require("@lindorm/case");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
try {
|
|
8
|
-
return JSON.parse(value);
|
|
9
|
-
}
|
|
10
|
-
catch {
|
|
11
|
-
return value;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
const findProcessEnvValue = (processEnv, key, parentKey) => {
|
|
5
|
+
const utils_1 = require("@lindorm/utils");
|
|
6
|
+
const findProcessEnvValue = (processEnv, key, parent) => {
|
|
15
7
|
const k = (0, case_1.changeCase)(key, case_1.ChangeCase.Constant);
|
|
16
|
-
const
|
|
17
|
-
const search =
|
|
18
|
-
const value = processEnv[search] ? processEnv[search] :
|
|
19
|
-
|
|
20
|
-
const splitArray = (0, is_1.isString)(parsed) && parsed.includes(";") ? parsed.split(";").map(tryParse) : null;
|
|
21
|
-
return splitArray ? splitArray : parsed;
|
|
8
|
+
const pkey = parent ? (0, case_1.changeCase)(parent, case_1.ChangeCase.Constant) : undefined;
|
|
9
|
+
const search = pkey ? `${pkey}_${k}` : k;
|
|
10
|
+
const value = processEnv[search] ? processEnv[search] : undefined;
|
|
11
|
+
return value ? (0, utils_1.safelyParse)(value) : undefined;
|
|
22
12
|
};
|
|
23
13
|
exports.findProcessEnvValue = findProcessEnvValue;
|
|
24
14
|
//# sourceMappingURL=find-process-env-value.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-process-env-value.js","sourceRoot":"","sources":["../../../src/utils/private/find-process-env-value.ts"],"names":[],"mappings":";;;AAAA,wCAAuD;AACvD,
|
|
1
|
+
{"version":3,"file":"find-process-env-value.js","sourceRoot":"","sources":["../../../src/utils/private/find-process-env-value.ts"],"names":[],"mappings":";;;AAAA,wCAAuD;AACvD,0CAA6C;AAGtC,MAAM,mBAAmB,GAAG,CACjC,UAAsB,EACtB,GAAW,EACX,MAAe,EACV,EAAE;IACP,MAAM,CAAC,GAAG,IAAA,iBAAU,EAAC,GAAG,EAAE,iBAAU,CAAC,QAAQ,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAA,iBAAU,EAAC,MAAM,EAAE,iBAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE1E,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAElE,OAAO,KAAK,CAAC,CAAC,CAAC,IAAA,mBAAW,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAChD,CAAC,CAAC;AAZW,QAAA,mBAAmB,uBAY9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/private/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/private/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC"}
|
|
@@ -14,5 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./coerce-all"), exports);
|
|
18
|
+
__exportStar(require("./load-config"), exports);
|
|
19
|
+
__exportStar(require("./load-node-config"), exports);
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/private/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/private/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,gDAA8B;AAC9B,qDAAmC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../../src/utils/private/load-config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,eAAO,MAAM,UAAU,GAAI,YAAY,UAAU,KAAG,IAKnD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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.loadConfig = void 0;
|
|
7
|
+
const case_1 = require("@lindorm/case");
|
|
8
|
+
const config_1 = __importDefault(require("config"));
|
|
9
|
+
const merge_object_with_process_env_1 = require("./merge-object-with-process-env");
|
|
10
|
+
const loadConfig = (processEnv) => {
|
|
11
|
+
const config = config_1.default.util.toObject();
|
|
12
|
+
const merged = (0, merge_object_with_process_env_1.mergeObjectWithProcessEnv)(processEnv, config);
|
|
13
|
+
return (0, case_1.changeKeys)(merged, case_1.ChangeCase.Camel);
|
|
14
|
+
};
|
|
15
|
+
exports.loadConfig = loadConfig;
|
|
16
|
+
//# sourceMappingURL=load-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-config.js","sourceRoot":"","sources":["../../../src/utils/private/load-config.ts"],"names":[],"mappings":";;;;;;AAAA,wCAAuD;AAEvD,oDAAuB;AAEvB,mFAA4E;AAErE,MAAM,UAAU,GAAG,CAAC,UAAsB,EAAQ,EAAE;IACzD,MAAM,MAAM,GAAG,gBAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,IAAA,yDAAyB,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAE7D,OAAO,IAAA,iBAAU,EAAC,MAAM,EAAE,iBAAU,CAAC,KAAK,CAAC,CAAC;AAC9C,CAAC,CAAC;AALW,QAAA,UAAU,cAKrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-node-config.d.ts","sourceRoot":"","sources":["../../../src/utils/private/load-node-config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,eAAO,MAAM,cAAc,GAAI,YAAY,UAAU,KAAG,IAYvD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadNodeConfig = void 0;
|
|
4
|
+
const is_1 = require("@lindorm/is");
|
|
5
|
+
const utils_1 = require("@lindorm/utils");
|
|
6
|
+
const loadNodeConfig = (processEnv) => {
|
|
7
|
+
if (!processEnv.NODE_CONFIG)
|
|
8
|
+
return {};
|
|
9
|
+
if (!(0, is_1.isString)(processEnv.NODE_CONFIG) ||
|
|
10
|
+
!processEnv.NODE_CONFIG.startsWith("{") ||
|
|
11
|
+
!processEnv.NODE_CONFIG.endsWith("}")) {
|
|
12
|
+
throw new Error("Environment variable NODE_CONFIG must be a valid JSON string");
|
|
13
|
+
}
|
|
14
|
+
return (0, utils_1.safelyParse)(processEnv.NODE_CONFIG);
|
|
15
|
+
};
|
|
16
|
+
exports.loadNodeConfig = loadNodeConfig;
|
|
17
|
+
//# sourceMappingURL=load-node-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-node-config.js","sourceRoot":"","sources":["../../../src/utils/private/load-node-config.ts"],"names":[],"mappings":";;;AAAA,oCAAuC;AAEvC,0CAA6C;AAGtC,MAAM,cAAc,GAAG,CAAC,UAAsB,EAAQ,EAAE;IAC7D,IAAI,CAAC,UAAU,CAAC,WAAW;QAAE,OAAO,EAAE,CAAC;IAEvC,IACE,CAAC,IAAA,aAAQ,EAAC,UAAU,CAAC,WAAW,CAAC;QACjC,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC;QACvC,CAAC,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,EACrC,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;IAClF,CAAC;IAED,OAAO,IAAA,mBAAW,EAAO,UAAU,CAAC,WAAW,CAAC,CAAC;AACnD,CAAC,CAAC;AAZW,QAAA,cAAc,kBAYzB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Dict } from "@lindorm/types";
|
|
2
2
|
import { ProcessEnv } from "../../types";
|
|
3
|
-
export declare const mergeObjectWithProcessEnv:
|
|
3
|
+
export declare const mergeObjectWithProcessEnv: (processEnv: ProcessEnv, config: Dict, parent?: string) => Dict;
|
|
4
4
|
//# sourceMappingURL=merge-object-with-process-env.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-object-with-process-env.d.ts","sourceRoot":"","sources":["../../../src/utils/private/merge-object-with-process-env.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,eAAO,MAAM,yBAAyB,
|
|
1
|
+
{"version":3,"file":"merge-object-with-process-env.d.ts","sourceRoot":"","sources":["../../../src/utils/private/merge-object-with-process-env.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,eAAO,MAAM,yBAAyB,GACpC,YAAY,UAAU,EACtB,QAAQ,IAAI,EACZ,SAAS,MAAM,KACd,IAqBF,CAAC"}
|
|
@@ -2,14 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeObjectWithProcessEnv = void 0;
|
|
4
4
|
const is_1 = require("@lindorm/is");
|
|
5
|
-
const
|
|
6
|
-
const mergeObjectWithProcessEnv = (processEnv, config,
|
|
5
|
+
const find_process_env_value_1 = require("./find-process-env-value");
|
|
6
|
+
const mergeObjectWithProcessEnv = (processEnv, config, parent) => {
|
|
7
7
|
const result = {};
|
|
8
8
|
for (const [key, value] of Object.entries(config)) {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const env = (0, find_process_env_value_1.findProcessEnvValue)(processEnv, key, parent);
|
|
10
|
+
if (!(0, is_1.isUndefined)(env)) {
|
|
11
|
+
result[key] = env;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if ((0, is_1.isObject)(value)) {
|
|
15
|
+
const pkey = parent ? `${parent}_${key}` : key;
|
|
16
|
+
result[key] = (0, exports.mergeObjectWithProcessEnv)(processEnv, value, pkey);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
result[key] = value;
|
|
13
20
|
}
|
|
14
21
|
return result;
|
|
15
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-object-with-process-env.js","sourceRoot":"","sources":["../../../src/utils/private/merge-object-with-process-env.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"merge-object-with-process-env.js","sourceRoot":"","sources":["../../../src/utils/private/merge-object-with-process-env.ts"],"names":[],"mappings":";;;AAAA,oCAAoD;AAGpD,qEAA+D;AAExD,MAAM,yBAAyB,GAAG,CACvC,UAAsB,EACtB,MAAY,EACZ,MAAe,EACT,EAAE;IACR,MAAM,MAAM,GAAS,EAAE,CAAC;IAExB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,MAAM,GAAG,GAAG,IAAA,4CAAmB,EAAC,UAAU,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QAEzD,IAAI,CAAC,IAAA,gBAAW,EAAC,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;YAClB,SAAS;QACX,CAAC;QAED,IAAI,IAAA,aAAQ,EAAC,KAAK,CAAC,EAAE,CAAC;YACpB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;YAC/C,MAAM,CAAC,GAAG,CAAC,GAAG,IAAA,iCAAyB,EAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;YACjE,SAAS;QACX,CAAC;QAED,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAzBW,QAAA,yBAAyB,6BAyBpC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lindorm/config",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"author": "Jonn Nilsson",
|
|
6
6
|
"repository": {
|
|
@@ -14,28 +14,38 @@
|
|
|
14
14
|
"main": "dist/index.js",
|
|
15
15
|
"typings": "dist/index.d.ts",
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "rimraf dist && tsc -b ./tsconfig.build.json",
|
|
17
|
+
"build": "rimraf dist && tsc -b ./tsconfig.build.json && chmod +x dist/cli.js",
|
|
18
18
|
"example": "ts-node example",
|
|
19
19
|
"integration": "compd --file docker-compose.yml jest --config jest.config.integration.js --watch",
|
|
20
20
|
"integration:focus": "compd --file docker-compose.yml jest --config jest.config.integration.js --watch $1",
|
|
21
|
+
"prettier": "prettier --write ./src/*",
|
|
21
22
|
"test": "jest --watch --",
|
|
22
23
|
"test:ci": "npm run test:unit",
|
|
23
24
|
"test:integration": "jest --config jest.config.integration.js --",
|
|
24
25
|
"test:unit": "jest --config jest.config.js --",
|
|
25
26
|
"typecheck": "tsc --watch",
|
|
26
27
|
"typecheck:ci": "tsc",
|
|
27
|
-
"update": "ncu -
|
|
28
|
+
"update": "ncu -i",
|
|
29
|
+
"update:auto": "ncu -u"
|
|
30
|
+
},
|
|
31
|
+
"bin": {
|
|
32
|
+
"config": "dist/cli.js"
|
|
28
33
|
},
|
|
29
34
|
"dependencies": {
|
|
30
35
|
"@dotenvx/dotenvx": "^1.10.3",
|
|
31
|
-
"@lindorm/case": "^0.1.
|
|
32
|
-
"@lindorm/is": "^0.1.
|
|
36
|
+
"@lindorm/case": "^0.1.9",
|
|
37
|
+
"@lindorm/is": "^0.1.9",
|
|
38
|
+
"@lindorm/utils": "^0.5.1",
|
|
39
|
+
"commander": "^13.1.0",
|
|
33
40
|
"config": "^3.3.12",
|
|
34
|
-
"dotenv": "^16.4.5"
|
|
41
|
+
"dotenv": "^16.4.5",
|
|
42
|
+
"js-yaml": "^4.1.0",
|
|
43
|
+
"zod": "^3.24.3"
|
|
35
44
|
},
|
|
36
45
|
"devDependencies": {
|
|
37
|
-
"@lindorm/types": "^0.
|
|
38
|
-
"@types/config": "^3.3.4"
|
|
46
|
+
"@lindorm/types": "^0.3.1",
|
|
47
|
+
"@types/config": "^3.3.4",
|
|
48
|
+
"@types/js-yaml": "^4.0.9"
|
|
39
49
|
},
|
|
40
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "bb9f6efd6b7dcc5035535d900239a8d93f97cfb7"
|
|
41
51
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merge-value-with-process-env.d.ts","sourceRoot":"","sources":["../../../src/utils/private/merge-value-with-process-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,eAAO,MAAM,wBAAwB,eACvB,UAAU,SACf,MAAM,OACR,MAAM,cACC,MAAM,KACjB,MAIF,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeValueWithProcessEnv = void 0;
|
|
4
|
-
const find_process_env_value_1 = require("./find-process-env-value");
|
|
5
|
-
const mergeValueWithProcessEnv = (processEnv, value, key, parentKey) => {
|
|
6
|
-
const envValue = (0, find_process_env_value_1.findProcessEnvValue)(processEnv, key, parentKey);
|
|
7
|
-
return envValue ? envValue : value;
|
|
8
|
-
};
|
|
9
|
-
exports.mergeValueWithProcessEnv = mergeValueWithProcessEnv;
|
|
10
|
-
//# sourceMappingURL=merge-value-with-process-env.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merge-value-with-process-env.js","sourceRoot":"","sources":["../../../src/utils/private/merge-value-with-process-env.ts"],"names":[],"mappings":";;;AACA,qEAA+D;AAExD,MAAM,wBAAwB,GAAG,CACtC,UAAsB,EACtB,KAAa,EACb,GAAW,EACX,SAAkB,EACV,EAAE;IACV,MAAM,QAAQ,GAAG,IAAA,4CAAmB,EAAC,UAAU,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;IAEjE,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;AACrC,CAAC,CAAC;AATW,QAAA,wBAAwB,4BASnC"}
|