make-json-to-env 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +3 -4
  2. package/index.js +21 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -67,10 +67,9 @@ convert-json-env example.json --prefix="export "
67
67
  **Output (`example.env`):**
68
68
 
69
69
  ```env
70
- export APIKEY=
71
- export AUTHDOMAIN=
72
- export PROJECTID=
73
-
70
+ APP_NAME="My Cool App"
71
+ PORT=8080
72
+ DB_ENABLED=true
74
73
  ```
75
74
 
76
75
  ---
package/index.js CHANGED
@@ -13,16 +13,32 @@ if (!inputFile) {
13
13
  process.exit(1);
14
14
  }
15
15
 
16
+ /**
17
+ * Converts JSON keys and values to ENV format
18
+ */
16
19
  function convertToEnv(json, prefix) {
17
- return Object.keys(json)
18
- .map(key => `${prefix}${key.toUpperCase()}=`)
20
+ return Object.entries(json)
21
+ .map(([key, value]) => {
22
+ const envKey = `${prefix}${key.toUpperCase()}`;
23
+
24
+ // Handle different value types
25
+ let envValue = value;
26
+ if (typeof value === 'object' && value !== null) {
27
+ envValue = JSON.stringify(value);
28
+ }
29
+
30
+ // Wrap in quotes if value contains spaces
31
+ if (typeof envValue === 'string' && envValue.includes(' ')) {
32
+ envValue = `"${envValue}"`;
33
+ }
34
+
35
+ return `${envKey}=${envValue}`;
36
+ })
19
37
  .join('\n');
20
38
  }
21
39
 
22
40
  function run() {
23
41
  const inputPath = path.resolve(process.cwd(), inputFile);
24
-
25
- // Generate output name: example.json -> example.env
26
42
  const parsedPath = path.parse(inputPath);
27
43
  const outputPath = path.join(parsedPath.dir, `${parsedPath.name}.env`);
28
44
 
@@ -37,7 +53,7 @@ function run() {
37
53
  const envContent = convertToEnv(json, prefix);
38
54
 
39
55
  fs.writeFileSync(outputPath, envContent);
40
- console.log(`✅ ${path.basename(outputPath)} created.`);
56
+ console.log(`✅ ${path.basename(outputPath)} created with values.`);
41
57
  } catch (error) {
42
58
  console.error('❌ Error:', error.message);
43
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "make-json-to-env",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Generates a template .env.example from a config.json file",
5
5
  "main": "index.js",
6
6
  "bin": {