silgi 0.25.5 → 0.25.6
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 +1 -0
- package/dist/cli/dev.mjs +1 -0
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/install.mjs +1 -0
- package/dist/cli/writeTypesAndFiles.mjs +30 -18
- package/package.json +1 -1
package/dist/build.mjs
CHANGED
package/dist/cli/dev.mjs
CHANGED
package/dist/cli/index.mjs
CHANGED
package/dist/cli/install.mjs
CHANGED
|
@@ -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,14 @@ 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
|
-
|
|
1608
|
-
|
|
1609
|
-
const
|
|
1610
|
-
if (!groupedVars[
|
|
1611
|
-
groupedVars[
|
|
1596
|
+
Object.entries(flattenedConfig).forEach(([key, { value, originalPath }]) => {
|
|
1597
|
+
if (originalPath.length > 0) {
|
|
1598
|
+
const firstKey = originalPath[0];
|
|
1599
|
+
const categoryName = extractCategoryFromCamel(firstKey);
|
|
1600
|
+
if (!groupedVars[categoryName]) {
|
|
1601
|
+
groupedVars[categoryName] = {};
|
|
1612
1602
|
}
|
|
1613
|
-
groupedVars[
|
|
1603
|
+
groupedVars[categoryName][key] = value;
|
|
1614
1604
|
} else {
|
|
1615
1605
|
if (!groupedVars.OTHER) {
|
|
1616
1606
|
groupedVars.OTHER = {};
|
|
@@ -1629,6 +1619,28 @@ ${varsContent}`;
|
|
|
1629
1619
|
silgi.options.runtimeConfig = safeRuntimeConfig;
|
|
1630
1620
|
return _sharedRuntimeConfig;
|
|
1631
1621
|
}
|
|
1622
|
+
function extractCategoryFromCamel(str) {
|
|
1623
|
+
if (/^[a-z]+[A-Z]/.test(str)) {
|
|
1624
|
+
const matches = str.match(/^([a-z]+)([A-Z][a-z0-9]*)?/);
|
|
1625
|
+
if (matches && matches[2]) {
|
|
1626
|
+
return `${matches[1].toUpperCase()}_${matches[2].toUpperCase()}`;
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
return str.toUpperCase();
|
|
1630
|
+
}
|
|
1631
|
+
function flattenObject(obj, prefix = "SILGI", originalPath = []) {
|
|
1632
|
+
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
1633
|
+
const formattedKey = snakeCase(key).toUpperCase();
|
|
1634
|
+
const newKey = `${prefix}_${formattedKey}`;
|
|
1635
|
+
const newPath = [...originalPath, key];
|
|
1636
|
+
if (typeof value === "object" && value !== null) {
|
|
1637
|
+
Object.assign(acc, flattenObject(value, newKey, newPath));
|
|
1638
|
+
} else {
|
|
1639
|
+
acc[newKey] = { value, originalPath: newPath };
|
|
1640
|
+
}
|
|
1641
|
+
return acc;
|
|
1642
|
+
}, {});
|
|
1643
|
+
}
|
|
1632
1644
|
|
|
1633
1645
|
const GLOB_SCAN_PATTERN = "**/*.{js,mjs,cjs,ts,mts,cts,tsx,jsx}";
|
|
1634
1646
|
async function scanAndSyncOptions(silgi) {
|