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.
- package/README.md +3 -4
- package/index.js +21 -5
- package/package.json +1 -1
package/README.md
CHANGED
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.
|
|
18
|
-
.map(key =>
|
|
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
|
}
|