configre 1.1.4 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@ Welcome to Configre, the coolest way to manage your project's configuration with
7
7
  - **Environment-Specific Configurations**: Automatically loads configurations based on the hostname or a custom profile passed via command line arguments.
8
8
  - **Fallback to Defaults**: Uses a default configuration as a baseline, ensuring your application always has the necessary settings.
9
9
  - **Easy Integration**: A simple setup process that integrates effortlessly into any project.
10
- - **Support for `.js` Config Files**: Allows for dynamic configuration values and comments for better clarity.
10
+ - **Support for `.cjs` Config Files**: Config files must use the `.cjs` extension. This allows dynamic configuration values and comments, and works the same in both CommonJS and ESM projects.
11
11
 
12
12
  ## 🌟 Getting Started
13
13
 
@@ -21,21 +21,20 @@ To get started with Configre, follow these steps:
21
21
  npm install configre --save
22
22
  ```
23
23
 
24
+ > You can also add Configre as a skill for AI agentic development:
25
+ > ```bash
26
+ > npx skills add https://github.com/clasen/Configre --skill configre
27
+ > ```
28
+
24
29
  2. **Setup Your Configuration Files**
25
30
 
26
31
  Organize your configuration files within a directory (e.g., `config`). Create a default configuration file and environment-specific files as needed.
27
32
 
28
- - `index.js`: Your default configuration.
29
- - `[hostname].js`: Override configurations for specific hosts.
30
- - `[hostname].dev.js`: Development-specific configurations.
33
+ - `index.cjs`: Your default configuration.
34
+ - `[hostname].cjs`: Override configurations for specific hosts.
35
+ - `[hostname].dev.cjs`: Development-specific configurations.
31
36
 
32
- > **Note:** If your main project uses `"type": "module"` in its `package.json`, add a `package.json` inside the `config/` directory with the following content so you can keep using `module.exports` in your config files:
33
- >
34
- > ```json
35
- > {
36
- > "type": "commonjs"
37
- > }
38
- > ```
37
+ > **Note:** Config files must always use the `.cjs` extension. That way they work in both CommonJS and ESM projects and you can use `module.exports` in them.
39
38
 
40
39
  3. **Use Configre in Your Project**
41
40
 
@@ -50,10 +49,10 @@ To get started with Configre, follow these steps:
50
49
 
51
50
  Imagine you have the following structure in your `config` directory:
52
51
 
53
- - `index.js`: Contains default settings.
54
- - `myhostname.js`: Contains overrides for the host named `myhostname`.
52
+ - `index.cjs`: Contains default settings.
53
+ - `myhostname.cjs`: Contains overrides for the host named `myhostname`.
55
54
 
56
- Your `index.js` might look like this:
55
+ Your `index.cjs` might look like this:
57
56
 
58
57
  ```javascript
59
58
  module.exports = {
@@ -68,7 +67,7 @@ module.exports = {
68
67
  }
69
68
  ```
70
69
 
71
- And your `myhostname.js`:
70
+ And your `myhostname.cjs`:
72
71
 
73
72
  ```javascript
74
73
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "configre",
3
- "version": "1.1.4",
3
+ "version": "1.1.8",
4
4
  "description": "🔧 Effortlessly Tailor Your Settings",
5
5
  "dependencies": {
6
6
  "lemonlog": "^1.0.2",
@@ -0,0 +1,113 @@
1
+ ---
2
+ name: configre
3
+ description: Set up and manage environment-specific configuration in Node.js projects using the Configre library. Use when the user wants to add configuration management, create environment configs, set up hostname-based settings, or mentions "configre", "config files", "environment config", or "per-host settings".
4
+ metadata:
5
+ category: configuration
6
+ tags: [nodejs, config, environment, settings, env]
7
+ ---
8
+
9
+ # Configre
10
+
11
+ Environment-specific configuration manager for Node.js. Merges a default config with hostname or profile-based overrides using deep merge (lodash).
12
+
13
+ ## Instructions
14
+
15
+ ### Step 1: Install the package
16
+
17
+ ```bash
18
+ npm install configre --save
19
+ ```
20
+
21
+ ### Step 2: Create the config directory
22
+
23
+ ```
24
+ project/
25
+ ├── config/
26
+ │ ├── index.js # Default settings (required)
27
+ │ ├── myhostname.js # Host-specific overrides (optional)
28
+ │ └── myhostname.dev.js # Dev override for host (optional)
29
+ ```
30
+
31
+ If the project uses `"type": "module"` in `package.json`, create `config/package.json`:
32
+
33
+ ```json
34
+ { "type": "commonjs" }
35
+ ```
36
+
37
+ This is needed because config files use `module.exports`.
38
+
39
+ ### Step 3: Write the default config (`config/index.js`)
40
+
41
+ ```javascript
42
+ module.exports = {
43
+ db: {
44
+ host: 'localhost',
45
+ port: 5432,
46
+ user: 'dev',
47
+ password: 'dev-pass'
48
+ },
49
+ api: {
50
+ key: 'default-key',
51
+ url: 'http://localhost:3000'
52
+ }
53
+ };
54
+ ```
55
+
56
+ ### Step 4: Write host/profile overrides
57
+
58
+ Create `config/<hostname>.js` with only the keys that differ — they are deep-merged over defaults:
59
+
60
+ ```javascript
61
+ module.exports = {
62
+ db: {
63
+ user: 'prod-user',
64
+ password: 'prod-secret'
65
+ }
66
+ };
67
+ ```
68
+
69
+ ### Step 5: Load the configuration
70
+
71
+ ```javascript
72
+ const cfg = require("configre")();
73
+
74
+ console.log(cfg.db.host); // from default
75
+ console.log(cfg.db.user); // from host override
76
+ ```
77
+
78
+ To use a custom config directory:
79
+
80
+ ```javascript
81
+ const cfg = require("configre")(__dirname + "/settings");
82
+ ```
83
+
84
+ ## Profile resolution
85
+
86
+ Configre determines the active profile from `process.argv[2]` (CLI argument) or `os.hostname()` as fallback. It then checks for overrides in this order (first match wins):
87
+
88
+ 1. `config/<profile>.dev.js` or `.cjs` — dev override
89
+ 2. `config/<profile>.js` or `.cjs` — production override
90
+ 3. No match — uses defaults only
91
+
92
+ ## Examples
93
+
94
+ **Example 1: Basic setup**
95
+ User says: "Add configuration management to my Node.js project"
96
+ Actions: install configre, create `config/index.js` with project defaults, load with `require("configre")()`
97
+ Result: merged config object ready to use
98
+
99
+ **Example 2: Multi-environment**
100
+ User says: "I need different database settings per server"
101
+ Actions: create `config/index.js` with defaults, create `config/<hostname>.js` per server with db overrides
102
+ Result: each server automatically loads its own config based on hostname
103
+
104
+ **Example 3: Custom profile via CLI**
105
+ User says: "I want to run my app with a staging config"
106
+ Actions: create `config/staging.js`, run app with `node app.js staging`
107
+ Result: staging overrides are merged over defaults
108
+
109
+ ## Key behaviors
110
+
111
+ - **Deep merge**: nested objects merge recursively via lodash `_.merge`
112
+ - **Both `.js` and `.cjs`** extensions are supported for all config files
113
+ - **Function vs constructor**: `Configre(path)` returns the merged config directly; `new Configre(path)` returns the instance (use `.get()` to retrieve config)
File without changes
File without changes