@jayfong/x-server 2.21.7 → 2.21.9

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.
@@ -29,4 +29,5 @@ export declare class EnvUtil {
29
29
  file: string;
30
30
  outFile: string;
31
31
  }): Promise<void>;
32
+ private static getTypesFromValue;
32
33
  }
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'node:path';
3
- import { dedent, devOrProd, escapeRegExp, isNumeric } from 'vtils';
3
+ import { dedent, devOrProd, escapeRegExp, isNumeric, isPlainObject } from 'vtils';
4
4
  import { parse as yamlParse } from 'yaml';
5
5
  export class EnvUtil {
6
6
  static normalizeValue(value) {
@@ -143,7 +143,7 @@ export class EnvUtil {
143
143
  ${env.comment.split(/[\r\n]+/g).map(line => `* ${line.trim()}`).join('\n*\n')}
144
144
  */
145
145
  ` : ''}
146
- ${env.key}: ${Array.isArray(env.value) ? `Array<${env.value[0] ? typeof env.value[0] : 'any'}>` : typeof env.value};
146
+ ${env.key}: ${EnvUtil.getTypesFromValue(env.value)};
147
147
  `).join('\n')}
148
148
  }
149
149
  }
@@ -155,6 +155,9 @@ export class EnvUtil {
155
155
  const types = EnvUtil.makeTypes(envs);
156
156
  await fs.outputFile(outFile, types);
157
157
  }
158
+ static getTypesFromValue(value) {
159
+ return Array.isArray(value) ? `Array<${value[0] ? EnvUtil.getTypesFromValue(value[0]) : 'any'}>` : isPlainObject(value) ? Object.keys(value).length ? `Record<any, ${EnvUtil.getTypesFromValue(value[Object.keys(value)[0]])}>` : `Record<any, any>` : typeof value;
160
+ }
158
161
  }
159
162
  EnvUtil.NEWLINE = '\n';
160
163
  EnvUtil.RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*(.*)?\s*$/;