silgi 0.25.5 → 0.25.7

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/dist/build.mjs CHANGED
@@ -28,6 +28,7 @@ import '@oxc-parser/wasm';
28
28
  import 'klona';
29
29
  import 'silgi/runtime';
30
30
  import 'unstorage';
31
+ import 'scule';
31
32
  import './cli/types.mjs';
32
33
  import 'c12';
33
34
  import 'compatx';
package/dist/cli/dev.mjs CHANGED
@@ -34,6 +34,7 @@ import '@oxc-parser/wasm';
34
34
  import 'klona';
35
35
  import 'silgi/runtime';
36
36
  import 'unstorage';
37
+ import 'scule';
37
38
  import './types.mjs';
38
39
  import 'c12';
39
40
  import 'compatx';
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.25.5";
4
+ const version = "0.25.7";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -32,6 +32,7 @@ import '@oxc-parser/wasm';
32
32
  import 'klona';
33
33
  import 'silgi/runtime';
34
34
  import 'unstorage';
35
+ import 'scule';
35
36
  import 'pathe/utils';
36
37
  import 'picocolors';
37
38
  import '../_chunks/silgiApp.mjs';
@@ -55,6 +55,14 @@ const SilgiCLIDefaults = {
55
55
  vfsDir: "{{ silgi.serverDir }}/vfs",
56
56
  typesDir: "{{ silgi.serverDir }}/types"
57
57
  },
58
+ // Codegen
59
+ codegen: {
60
+ env: {
61
+ safeList: [
62
+ ["silgi", "version"]
63
+ ]
64
+ }
65
+ },
58
66
  // Modules
59
67
  _modules: [],
60
68
  modules: [],
@@ -26,6 +26,7 @@ import { klona } from 'klona';
26
26
  import { useSilgiRuntimeConfig, initRuntimeConfig } from 'silgi/runtime';
27
27
  import { createStorage, builtinDrivers } from 'unstorage';
28
28
  import { peerDependencies } from 'silgi/meta';
29
+ import { snakeCase } from 'scule';
29
30
  import { l as loadOptions, s as silgiGenerateType } from './types.mjs';
30
31
  import { resolveAlias as resolveAlias$1 } from 'pathe/utils';
31
32
 
@@ -1584,17 +1585,6 @@ function useCLIRuntimeConfig(silgi) {
1584
1585
  data.runtimeConfig = safeRuntimeConfig;
1585
1586
  silgi.options.envOptions = silgi.options.envOptions;
1586
1587
  });
1587
- function flattenObject(obj, prefix = "SILGI") {
1588
- return Object.entries(obj).reduce((acc, [key, value]) => {
1589
- const newKey = `${prefix}_${key.toUpperCase()}`;
1590
- if (typeof value === "object" && value !== null) {
1591
- Object.assign(acc, flattenObject(value, newKey));
1592
- } else {
1593
- acc[newKey] = value;
1594
- }
1595
- return acc;
1596
- }, {});
1597
- }
1598
1588
  addTemplate({
1599
1589
  filename: "env.example",
1600
1590
  write: true,
@@ -1603,14 +1593,21 @@ function useCLIRuntimeConfig(silgi) {
1603
1593
  console.log("Generating env.example");
1604
1594
  const flattenedConfig = flattenObject(safeRuntimeConfig);
1605
1595
  const groupedVars = {};
1606
- Object.entries(flattenedConfig).forEach(([key, value]) => {
1607
- const parts = key.split("_");
1608
- if (parts.length >= 2) {
1609
- const mainCategory = parts[1];
1610
- if (!groupedVars[mainCategory]) {
1611
- groupedVars[mainCategory] = {};
1596
+ Object.entries(flattenedConfig).forEach(([key, { value, originalPath }]) => {
1597
+ const shouldExclude = silgi.options.codegen.env.safeList.some((safePath) => {
1598
+ if (safePath.length !== originalPath.length)
1599
+ return false;
1600
+ return safePath.every((segment, index) => segment.toLowerCase() === originalPath[index].toLowerCase());
1601
+ });
1602
+ if (shouldExclude)
1603
+ return;
1604
+ if (originalPath.length > 0) {
1605
+ const firstKey = originalPath[0];
1606
+ const categoryName = extractCategoryFromCamel(firstKey);
1607
+ if (!groupedVars[categoryName]) {
1608
+ groupedVars[categoryName] = {};
1612
1609
  }
1613
- groupedVars[mainCategory][key] = value;
1610
+ groupedVars[categoryName][key] = value;
1614
1611
  } else {
1615
1612
  if (!groupedVars.OTHER) {
1616
1613
  groupedVars.OTHER = {};
@@ -1629,6 +1626,28 @@ ${varsContent}`;
1629
1626
  silgi.options.runtimeConfig = safeRuntimeConfig;
1630
1627
  return _sharedRuntimeConfig;
1631
1628
  }
1629
+ function extractCategoryFromCamel(str) {
1630
+ if (/^[a-z]+[A-Z]/.test(str)) {
1631
+ const matches = str.match(/^([a-z]+)([A-Z][a-z0-9]*)?/);
1632
+ if (matches && matches[2]) {
1633
+ return `${matches[1].toUpperCase()}_${matches[2].toUpperCase()}`;
1634
+ }
1635
+ }
1636
+ return str.toUpperCase();
1637
+ }
1638
+ function flattenObject(obj, prefix = "SILGI", originalPath = []) {
1639
+ return Object.entries(obj).reduce((acc, [key, value]) => {
1640
+ const formattedKey = snakeCase(key).toUpperCase();
1641
+ const newKey = `${prefix}_${formattedKey}`;
1642
+ const newPath = [...originalPath, key];
1643
+ if (typeof value === "object" && value !== null) {
1644
+ Object.assign(acc, flattenObject(value, newKey, newPath));
1645
+ } else {
1646
+ acc[newKey] = { value, originalPath: newPath };
1647
+ }
1648
+ return acc;
1649
+ }, {});
1650
+ }
1632
1651
 
1633
1652
  const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
1634
1653
  async function scanAndSyncOptions(silgi) {
@@ -602,6 +602,11 @@ interface SilgiCLIOptions extends PresetOptions {
602
602
  logLevel: LogLevel;
603
603
  appConfig: AppConfig;
604
604
  appConfigFiles: string[];
605
+ codegen: {
606
+ env: {
607
+ safeList: string[][];
608
+ };
609
+ };
605
610
  storage: StorageMounts$1;
606
611
  devStorage: StorageMounts$1;
607
612
  workspaceDir: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.25.5",
4
+ "version": "0.25.7",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {