@xlameiro/env-typegen 0.1.4 → 0.1.5
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/CHANGELOG.md +6 -0
- package/dist/cli.js +51 -23
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +33 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/cli.js
CHANGED
|
@@ -99,7 +99,7 @@ var require_picocolors = __commonJS({
|
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
// src/cli.ts
|
|
102
|
-
import { realpathSync } from "fs";
|
|
102
|
+
import { existsSync as existsSync6, realpathSync } from "fs";
|
|
103
103
|
import { createRequire } from "module";
|
|
104
104
|
import path13 from "path";
|
|
105
105
|
import { fileURLToPath, pathToFileURL as pathToFileURL5 } from "url";
|
|
@@ -610,7 +610,15 @@ function parseEnvFile(filePath) {
|
|
|
610
610
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
611
611
|
import path4 from "path";
|
|
612
612
|
async function readEnvFile(filePath) {
|
|
613
|
-
|
|
613
|
+
const resolved = path4.resolve(filePath);
|
|
614
|
+
try {
|
|
615
|
+
return await readFile(resolved, "utf8");
|
|
616
|
+
} catch (err) {
|
|
617
|
+
if (err instanceof Error && err.code === "ENOENT") {
|
|
618
|
+
throw new Error(`File not found: ${filePath}`);
|
|
619
|
+
}
|
|
620
|
+
throw err;
|
|
621
|
+
}
|
|
614
622
|
}
|
|
615
623
|
async function writeOutput(filePath, content) {
|
|
616
624
|
const resolved = path4.resolve(filePath);
|
|
@@ -634,14 +642,15 @@ async function formatOutput(content, parser = "typescript") {
|
|
|
634
642
|
|
|
635
643
|
// src/utils/logger.ts
|
|
636
644
|
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
645
|
+
var { green, red, yellow } = import_picocolors.default;
|
|
637
646
|
function log(message) {
|
|
638
647
|
console.log(message);
|
|
639
648
|
}
|
|
640
649
|
function error(message) {
|
|
641
|
-
console.error(
|
|
650
|
+
console.error(red(`\u2716 ${message}`));
|
|
642
651
|
}
|
|
643
652
|
function success(message) {
|
|
644
|
-
console.log(
|
|
653
|
+
console.log(green(`\u2714 ${message}`));
|
|
645
654
|
}
|
|
646
655
|
|
|
647
656
|
// src/pipeline.ts
|
|
@@ -684,10 +693,6 @@ async function persistOutput(params) {
|
|
|
684
693
|
}
|
|
685
694
|
if (dryRun) {
|
|
686
695
|
if (!silent) {
|
|
687
|
-
if (!isSingle) {
|
|
688
|
-
console.log(`// --- ${generator}: ${outputPath} ---`);
|
|
689
|
-
}
|
|
690
|
-
console.log(generated);
|
|
691
696
|
success(`Dry run: would write ${outputPath}`);
|
|
692
697
|
}
|
|
693
698
|
return;
|
|
@@ -739,6 +744,7 @@ async function runGenerate(options) {
|
|
|
739
744
|
}
|
|
740
745
|
|
|
741
746
|
// src/validation-command.ts
|
|
747
|
+
import { existsSync as existsSync4 } from "fs";
|
|
742
748
|
import path11 from "path";
|
|
743
749
|
import { pathToFileURL as pathToFileURL4 } from "url";
|
|
744
750
|
import { parseArgs } from "util";
|
|
@@ -810,7 +816,15 @@ function parseProviderPayload(provider, value) {
|
|
|
810
816
|
}
|
|
811
817
|
async function loadCloudSource(options) {
|
|
812
818
|
const resolvedPath = path6.resolve(options.filePath);
|
|
813
|
-
|
|
819
|
+
let raw;
|
|
820
|
+
try {
|
|
821
|
+
raw = await readFile2(resolvedPath, "utf8");
|
|
822
|
+
} catch (err) {
|
|
823
|
+
if (err instanceof Error && err.code === "ENOENT") {
|
|
824
|
+
throw new Error(`File not found: ${options.filePath}`);
|
|
825
|
+
}
|
|
826
|
+
throw err;
|
|
827
|
+
}
|
|
814
828
|
const parsed = JSON.parse(raw);
|
|
815
829
|
return parseProviderPayload(options.provider, parsed);
|
|
816
830
|
}
|
|
@@ -961,6 +975,7 @@ async function loadValidationContract(options) {
|
|
|
961
975
|
}
|
|
962
976
|
|
|
963
977
|
// src/plugins.ts
|
|
978
|
+
import { existsSync as existsSync3 } from "fs";
|
|
964
979
|
import path8 from "path";
|
|
965
980
|
import { pathToFileURL as pathToFileURL3 } from "url";
|
|
966
981
|
function isRecord3(value) {
|
|
@@ -982,6 +997,9 @@ function isPlugin(value) {
|
|
|
982
997
|
}
|
|
983
998
|
async function loadPluginFromPath(pluginPath, cwd) {
|
|
984
999
|
const resolvedPath = path8.resolve(cwd, pluginPath);
|
|
1000
|
+
if (!existsSync3(resolvedPath)) {
|
|
1001
|
+
throw new Error(`Plugin not found: ${pluginPath}`);
|
|
1002
|
+
}
|
|
985
1003
|
const moduleValue = await import(pathToFileURL3(resolvedPath).href);
|
|
986
1004
|
const candidate = moduleValue.default ?? moduleValue.plugin;
|
|
987
1005
|
if (isPlugin(candidate)) return candidate;
|
|
@@ -1198,7 +1216,7 @@ function isClientSecret(variable, key) {
|
|
|
1198
1216
|
function checkContractVariable(key, variable, context) {
|
|
1199
1217
|
const { options, issues } = context;
|
|
1200
1218
|
const value = options.values[key];
|
|
1201
|
-
const hasValue = value !== void 0
|
|
1219
|
+
const hasValue = value !== void 0;
|
|
1202
1220
|
if (variable.required && !hasValue) {
|
|
1203
1221
|
issues.push(
|
|
1204
1222
|
createIssue({
|
|
@@ -1379,12 +1397,8 @@ function diffEnvironmentSources(options) {
|
|
|
1379
1397
|
sourceName,
|
|
1380
1398
|
value: options.sources[sourceName]?.[key]
|
|
1381
1399
|
}));
|
|
1382
|
-
const present = valuesBySource.filter(
|
|
1383
|
-
|
|
1384
|
-
);
|
|
1385
|
-
const missing = valuesBySource.filter(
|
|
1386
|
-
(entry) => entry.value === void 0 || entry.value === ""
|
|
1387
|
-
);
|
|
1400
|
+
const present = valuesBySource.filter((entry) => entry.value !== void 0);
|
|
1401
|
+
const missing = valuesBySource.filter((entry) => entry.value === void 0);
|
|
1388
1402
|
if (present.length === 0 && variable?.required === true) {
|
|
1389
1403
|
for (const entry of missing) {
|
|
1390
1404
|
issues.push(
|
|
@@ -1645,6 +1659,9 @@ async function loadCommandConfig(configPath) {
|
|
|
1645
1659
|
return loadConfig(process.cwd());
|
|
1646
1660
|
}
|
|
1647
1661
|
const resolvedPath = path11.resolve(configPath);
|
|
1662
|
+
if (!existsSync4(resolvedPath)) {
|
|
1663
|
+
throw new Error(`Config file not found: ${configPath}`);
|
|
1664
|
+
}
|
|
1648
1665
|
const configDir = path11.dirname(resolvedPath);
|
|
1649
1666
|
const moduleValue = await import(pathToFileURL4(resolvedPath).href);
|
|
1650
1667
|
if (moduleValue.default === void 0) return void 0;
|
|
@@ -1904,6 +1921,7 @@ async function runValidationCommand(params) {
|
|
|
1904
1921
|
|
|
1905
1922
|
// src/watch.ts
|
|
1906
1923
|
import { watch } from "chokidar";
|
|
1924
|
+
import { existsSync as existsSync5 } from "fs";
|
|
1907
1925
|
import path12 from "path";
|
|
1908
1926
|
function debounce(fn, delay) {
|
|
1909
1927
|
let timer;
|
|
@@ -1916,6 +1934,13 @@ function debounce(fn, delay) {
|
|
|
1916
1934
|
};
|
|
1917
1935
|
}
|
|
1918
1936
|
function startWatch({ inputPath, runOptions, cwd = process.cwd() }) {
|
|
1937
|
+
const inputPaths = Array.isArray(inputPath) ? inputPath : [inputPath];
|
|
1938
|
+
for (const singlePath of inputPaths) {
|
|
1939
|
+
if (!existsSync5(singlePath)) {
|
|
1940
|
+
error(`File not found: ${singlePath}`);
|
|
1941
|
+
return process.exit(1);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1919
1944
|
const inputLabel = Array.isArray(inputPath) ? inputPath.join(", ") : inputPath;
|
|
1920
1945
|
log(`Watching ${inputLabel} for changes...`);
|
|
1921
1946
|
void runGenerate(runOptions).catch((err) => {
|
|
@@ -2061,6 +2086,15 @@ async function runValidationSubcommand(subcommand, argv) {
|
|
|
2061
2086
|
process.exitCode = exitCode;
|
|
2062
2087
|
}
|
|
2063
2088
|
}
|
|
2089
|
+
async function loadExplicitConfig(configPath, userPath) {
|
|
2090
|
+
if (!existsSync6(configPath)) {
|
|
2091
|
+
throw new Error(`Config file not found: ${userPath}`);
|
|
2092
|
+
}
|
|
2093
|
+
const configDir = path13.dirname(configPath);
|
|
2094
|
+
const mod = await import(pathToFileURL5(configPath).href);
|
|
2095
|
+
const rawConfig = mod.default;
|
|
2096
|
+
return rawConfig ? applyConfigPaths2(rawConfig, configDir) : void 0;
|
|
2097
|
+
}
|
|
2064
2098
|
async function runCli(argv = process.argv.slice(2)) {
|
|
2065
2099
|
const maybeSubcommand = argv[0];
|
|
2066
2100
|
if (maybeSubcommand !== void 0 && VALIDATION_SUBCOMMANDS.has(maybeSubcommand)) {
|
|
@@ -2096,13 +2130,7 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
2096
2130
|
if (values.config === void 0) {
|
|
2097
2131
|
fileConfig = await loadConfig(process.cwd());
|
|
2098
2132
|
} else {
|
|
2099
|
-
|
|
2100
|
-
const configDir = path13.dirname(configPath);
|
|
2101
|
-
const mod = await import(pathToFileURL5(configPath).href);
|
|
2102
|
-
const rawConfig = mod.default;
|
|
2103
|
-
if (rawConfig) {
|
|
2104
|
-
fileConfig = applyConfigPaths2(rawConfig, configDir);
|
|
2105
|
-
}
|
|
2133
|
+
fileConfig = await loadExplicitConfig(path13.resolve(values.config), values.config);
|
|
2106
2134
|
}
|
|
2107
2135
|
const cliInput = values.input?.length ? values.input : void 0;
|
|
2108
2136
|
const input = cliInput ?? fileConfig?.input;
|