@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/dist/index.cjs
CHANGED
|
@@ -5,12 +5,13 @@ var path6 = require('path');
|
|
|
5
5
|
var url = require('url');
|
|
6
6
|
var promises = require('fs/promises');
|
|
7
7
|
var prettier = require('prettier');
|
|
8
|
-
var
|
|
8
|
+
var pc = require('picocolors');
|
|
9
9
|
var util = require('util');
|
|
10
10
|
|
|
11
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
|
|
13
13
|
var path6__default = /*#__PURE__*/_interopDefault(path6);
|
|
14
|
+
var pc__default = /*#__PURE__*/_interopDefault(pc);
|
|
14
15
|
|
|
15
16
|
// src/parser/comment-parser.ts
|
|
16
17
|
var VALID_ENV_VAR_TYPES = /* @__PURE__ */ new Set([
|
|
@@ -543,7 +544,15 @@ env-typegen.config.mjs for runtime loading.`
|
|
|
543
544
|
return void 0;
|
|
544
545
|
}
|
|
545
546
|
async function readEnvFile(filePath) {
|
|
546
|
-
|
|
547
|
+
const resolved = path6__default.default.resolve(filePath);
|
|
548
|
+
try {
|
|
549
|
+
return await promises.readFile(resolved, "utf8");
|
|
550
|
+
} catch (err) {
|
|
551
|
+
if (err instanceof Error && err.code === "ENOENT") {
|
|
552
|
+
throw new Error(`File not found: ${filePath}`);
|
|
553
|
+
}
|
|
554
|
+
throw err;
|
|
555
|
+
}
|
|
547
556
|
}
|
|
548
557
|
async function writeOutput(filePath, content) {
|
|
549
558
|
const resolved = path6__default.default.resolve(filePath);
|
|
@@ -561,17 +570,18 @@ async function formatOutput(content, parser = "typescript") {
|
|
|
561
570
|
return content;
|
|
562
571
|
}
|
|
563
572
|
}
|
|
573
|
+
var { green, red, yellow } = pc__default.default;
|
|
564
574
|
function log(message) {
|
|
565
575
|
console.log(message);
|
|
566
576
|
}
|
|
567
577
|
function warn(message) {
|
|
568
|
-
console.warn(
|
|
578
|
+
console.warn(yellow(`\u26A0 ${message}`));
|
|
569
579
|
}
|
|
570
580
|
function error(message) {
|
|
571
|
-
console.error(
|
|
581
|
+
console.error(red(`\u2716 ${message}`));
|
|
572
582
|
}
|
|
573
583
|
function success(message) {
|
|
574
|
-
console.log(
|
|
584
|
+
console.log(green(`\u2714 ${message}`));
|
|
575
585
|
}
|
|
576
586
|
|
|
577
587
|
// src/pipeline.ts
|
|
@@ -614,10 +624,6 @@ async function persistOutput(params) {
|
|
|
614
624
|
}
|
|
615
625
|
if (dryRun) {
|
|
616
626
|
if (!silent) {
|
|
617
|
-
if (!isSingle) {
|
|
618
|
-
console.log(`// --- ${generator}: ${outputPath} ---`);
|
|
619
|
-
}
|
|
620
|
-
console.log(generated);
|
|
621
627
|
success(`Dry run: would write ${outputPath}`);
|
|
622
628
|
}
|
|
623
629
|
return;
|
|
@@ -1029,7 +1035,15 @@ function parseProviderPayload(provider, value) {
|
|
|
1029
1035
|
}
|
|
1030
1036
|
async function loadCloudSource(options) {
|
|
1031
1037
|
const resolvedPath = path6__default.default.resolve(options.filePath);
|
|
1032
|
-
|
|
1038
|
+
let raw;
|
|
1039
|
+
try {
|
|
1040
|
+
raw = await promises.readFile(resolvedPath, "utf8");
|
|
1041
|
+
} catch (err) {
|
|
1042
|
+
if (err instanceof Error && err.code === "ENOENT") {
|
|
1043
|
+
throw new Error(`File not found: ${options.filePath}`);
|
|
1044
|
+
}
|
|
1045
|
+
throw err;
|
|
1046
|
+
}
|
|
1033
1047
|
const parsed = JSON.parse(raw);
|
|
1034
1048
|
return parseProviderPayload(options.provider, parsed);
|
|
1035
1049
|
}
|
|
@@ -1192,6 +1206,9 @@ function isPlugin(value) {
|
|
|
1192
1206
|
}
|
|
1193
1207
|
async function loadPluginFromPath(pluginPath, cwd) {
|
|
1194
1208
|
const resolvedPath = path6__default.default.resolve(cwd, pluginPath);
|
|
1209
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
1210
|
+
throw new Error(`Plugin not found: ${pluginPath}`);
|
|
1211
|
+
}
|
|
1195
1212
|
const moduleValue = await import(url.pathToFileURL(resolvedPath).href);
|
|
1196
1213
|
const candidate = moduleValue.default ?? moduleValue.plugin;
|
|
1197
1214
|
if (isPlugin(candidate)) return candidate;
|
|
@@ -1408,7 +1425,7 @@ function isClientSecret(variable, key) {
|
|
|
1408
1425
|
function checkContractVariable(key, variable, context) {
|
|
1409
1426
|
const { options, issues } = context;
|
|
1410
1427
|
const value = options.values[key];
|
|
1411
|
-
const hasValue = value !== void 0
|
|
1428
|
+
const hasValue = value !== void 0;
|
|
1412
1429
|
if (variable.required && !hasValue) {
|
|
1413
1430
|
issues.push(
|
|
1414
1431
|
createIssue({
|
|
@@ -1589,12 +1606,8 @@ function diffEnvironmentSources(options) {
|
|
|
1589
1606
|
sourceName,
|
|
1590
1607
|
value: options.sources[sourceName]?.[key]
|
|
1591
1608
|
}));
|
|
1592
|
-
const present = valuesBySource.filter(
|
|
1593
|
-
|
|
1594
|
-
);
|
|
1595
|
-
const missing = valuesBySource.filter(
|
|
1596
|
-
(entry) => entry.value === void 0 || entry.value === ""
|
|
1597
|
-
);
|
|
1609
|
+
const present = valuesBySource.filter((entry) => entry.value !== void 0);
|
|
1610
|
+
const missing = valuesBySource.filter((entry) => entry.value === void 0);
|
|
1598
1611
|
if (present.length === 0 && variable?.required === true) {
|
|
1599
1612
|
for (const entry of missing) {
|
|
1600
1613
|
issues.push(
|
|
@@ -1847,6 +1860,9 @@ async function loadCommandConfig(configPath) {
|
|
|
1847
1860
|
return loadConfig(process.cwd());
|
|
1848
1861
|
}
|
|
1849
1862
|
const resolvedPath = path6__default.default.resolve(configPath);
|
|
1863
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
1864
|
+
throw new Error(`Config file not found: ${configPath}`);
|
|
1865
|
+
}
|
|
1850
1866
|
const configDir = path6__default.default.dirname(resolvedPath);
|
|
1851
1867
|
const moduleValue = await import(url.pathToFileURL(resolvedPath).href);
|
|
1852
1868
|
if (moduleValue.default === void 0) return void 0;
|