@towns-protocol/generated 0.0.330 → 0.0.334

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.
@@ -1 +1 @@
1
- 736544ae31c29d6c0c86588ccc78650b3a25c2db
1
+ 677a4134ce56178b1a854a81416313fb119c3f0a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@towns-protocol/generated",
3
- "version": "0.0.330",
3
+ "version": "0.0.334",
4
4
  "packageManager": "yarn@3.8.0",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -26,5 +26,5 @@
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
- "gitHead": "f472a3c4a6f67a96e378db552e2880327eef42ba"
29
+ "gitHead": "8e35a9aabd11b73c165ed5200e0be0f76fdc84bc"
30
30
  }
@@ -4,6 +4,7 @@ import path from 'node:path';
4
4
  const deploymentsOutputFile = 'config/deployments.json';
5
5
  const deploymentsSourceDir = 'deployments';
6
6
 
7
+ // parse deployment folder jsons into a single json object
7
8
  function combineJson(dir) {
8
9
  const outputData = {};
9
10
  const files = fs.readdirSync(dir).filter(file => file.endsWith('.json'));
@@ -35,8 +36,46 @@ function combineJson(dir) {
35
36
  return outputData;
36
37
  }
37
38
 
39
+ // helper for env var readability
40
+ function keyToEnvKey(key) {
41
+ // convert camelCase to snake_case, handling acronyms properly
42
+ return key
43
+ .replace(/([a-z])([A-Z])/g, '$1_$2') // insert _ between lowercase and uppercase
44
+ .replace(/([A-Z])([A-Z][a-z])/g, '$1_$2') // insert _ between acronym and next word
45
+ .toUpperCase();
46
+ }
47
+
48
+ // convert a json object to a .env file content string
49
+ function convertToEnv(data, prefix = '') {
50
+ // recursively walk nested objects, convert all keys to UPPER SNAKE CASE and values set equal to value,
51
+ let envContent = ''
52
+ for (const key of Object.keys(data)) {
53
+ const value = data[key];
54
+ const envKey = `${prefix}${keyToEnvKey(key)}`;
55
+ if (typeof value === 'object') {
56
+ envContent += convertToEnv(value, `${envKey}_`);
57
+ } else {
58
+ envContent += `${envKey}=${String(value)}\n`;
59
+ }
60
+ }
61
+ return envContent;
62
+ }
63
+
64
+
65
+
38
66
  const outputData = combineJson(deploymentsSourceDir);
39
67
 
68
+
69
+ // for each top level key in outputData, write a .env file in the deployments/<key> folder
70
+ // with all keys in the json converted to UPPER SNAKE CASE
71
+ for (const key of Object.keys(outputData)) {
72
+ const envFile = path.join(deploymentsSourceDir, key, '.env');
73
+ const data = outputData[key];
74
+ const envData = convertToEnv(data);
75
+ fs.writeFileSync(envFile, `RIVER_ENV=${key}\n${envData}`);
76
+ }
77
+
78
+ // write a config.json file
40
79
  fs.mkdirSync(path.dirname(deploymentsOutputFile), { recursive: true });
41
80
  fs.writeFileSync(deploymentsOutputFile, JSON.stringify(outputData, null, 2));
42
81