varlock 0.0.6 → 0.0.8
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/auto-load.js +6 -5
- package/dist/{chunk-X3HJMANF.js → chunk-5B7JZEDE.js} +6 -5
- package/dist/chunk-5B7JZEDE.js.map +1 -0
- package/dist/{chunk-USSBWRQF.js → chunk-6FFRZOIK.js} +8 -8
- package/dist/{chunk-USSBWRQF.js.map → chunk-6FFRZOIK.js.map} +1 -1
- package/dist/{chunk-7TXRGZZC.js → chunk-7OHVYEDG.js} +4 -3
- package/dist/chunk-7OHVYEDG.js.map +1 -0
- package/dist/{chunk-656FP6YP.js → chunk-BM3UAHAH.js} +5 -6
- package/dist/chunk-BM3UAHAH.js.map +1 -0
- package/dist/chunk-CQHOPN6M.js +14 -0
- package/dist/{chunk-YSPDPNBR.js.map → chunk-CQHOPN6M.js.map} +1 -1
- package/dist/{chunk-WGUFO7CT.js → chunk-GYHC6Y7D.js} +7 -8
- package/dist/chunk-GYHC6Y7D.js.map +1 -0
- package/dist/{chunk-DAZNZPLN.js → chunk-H5PNRKYP.js} +559 -75
- package/dist/chunk-H5PNRKYP.js.map +1 -0
- package/dist/chunk-LZ45SLAI.js +12 -0
- package/dist/chunk-LZ45SLAI.js.map +1 -0
- package/dist/{chunk-ANHWU7RB.js → chunk-MPS3IXAW.js} +18 -7
- package/dist/chunk-MPS3IXAW.js.map +1 -0
- package/dist/{chunk-ASGIMFTP.js → chunk-P74HB2II.js} +4 -3
- package/dist/chunk-P74HB2II.js.map +1 -0
- package/dist/{chunk-JX4PYL7V.js → chunk-PQPGBNGV.js} +6 -7
- package/dist/chunk-PQPGBNGV.js.map +1 -0
- package/dist/{chunk-46HUIBFX.js → chunk-SHQHITWV.js} +9 -12
- package/dist/chunk-SHQHITWV.js.map +1 -0
- package/dist/{chunk-HBCSJWPN.js → chunk-UFPWQAFZ.js} +14 -14
- package/dist/chunk-UFPWQAFZ.js.map +1 -0
- package/dist/{chunk-INMYFAWB.js → chunk-Y2RFMQ5X.js} +342 -60
- package/dist/chunk-Y2RFMQ5X.js.map +1 -0
- package/dist/{chunk-BIYA4LBB.js → chunk-YK4SATSE.js} +7 -8
- package/dist/chunk-YK4SATSE.js.map +1 -0
- package/dist/cli/cli-executable.js +25 -33
- package/dist/cli/cli-executable.js.map +1 -1
- package/dist/dotenv-compat.js +6 -5
- package/dist/{env-B8lQt2sl.d.ts → env-k8iRuXIH.d.ts} +2 -2
- package/dist/index.d.ts +27 -2
- package/dist/index.js +28 -12
- package/dist/index.js.map +1 -1
- package/dist/init.command-L4HF4372.js +9 -0
- package/dist/{init.command-3DHC5DNC.js.map → init.command-L4HF4372.js.map} +1 -1
- package/dist/load.command-VHNPXTDI.js +9 -0
- package/dist/{load.command-CTOV5PYR.js.map → load.command-VHNPXTDI.js.map} +1 -1
- package/dist/login.command-OIQBNMNZ.js +8 -0
- package/dist/{login.command-UZBZIPP3.js.map → login.command-OIQBNMNZ.js.map} +1 -1
- package/dist/run.command-2OE432A5.js +9 -0
- package/dist/{run.command-5276KIMX.js.map → run.command-2OE432A5.js.map} +1 -1
- package/dist/runtime/env.d.ts +1 -1
- package/dist/runtime/env.js +1 -1
- package/dist/runtime/patch-console.js +3 -2
- package/dist/runtime/patch-response.js +3 -2
- package/dist/runtime/patch-server-response.js +3 -2
- package/dist/telemetry.command-MYQU7FPB.js +8 -0
- package/dist/{telemetry.command-UHJTZULL.js.map → telemetry.command-MYQU7FPB.js.map} +1 -1
- package/package.json +9 -9
- package/dist/chunk-3NTATUIY.js +0 -17
- package/dist/chunk-3NTATUIY.js.map +0 -1
- package/dist/chunk-46HUIBFX.js.map +0 -1
- package/dist/chunk-5URKU5HG.js +0 -172
- package/dist/chunk-5URKU5HG.js.map +0 -1
- package/dist/chunk-656FP6YP.js.map +0 -1
- package/dist/chunk-7TXRGZZC.js.map +0 -1
- package/dist/chunk-ANHWU7RB.js.map +0 -1
- package/dist/chunk-ASGIMFTP.js.map +0 -1
- package/dist/chunk-BIYA4LBB.js.map +0 -1
- package/dist/chunk-DAZNZPLN.js.map +0 -1
- package/dist/chunk-HBCSJWPN.js.map +0 -1
- package/dist/chunk-HH7DAS63.js +0 -540
- package/dist/chunk-HH7DAS63.js.map +0 -1
- package/dist/chunk-I3J2UCH7.js +0 -32
- package/dist/chunk-I3J2UCH7.js.map +0 -1
- package/dist/chunk-INMYFAWB.js.map +0 -1
- package/dist/chunk-JX4PYL7V.js.map +0 -1
- package/dist/chunk-LHTLO65N.js +0 -99
- package/dist/chunk-LHTLO65N.js.map +0 -1
- package/dist/chunk-PUGFIZE3.js +0 -143
- package/dist/chunk-PUGFIZE3.js.map +0 -1
- package/dist/chunk-WGUFO7CT.js.map +0 -1
- package/dist/chunk-X3HJMANF.js.map +0 -1
- package/dist/chunk-YSPDPNBR.js +0 -14
- package/dist/doctor.command-SBG4H7Z4.js +0 -7
- package/dist/doctor.command-SBG4H7Z4.js.map +0 -1
- package/dist/encrypt.command-AGHQ4KTI.js +0 -7
- package/dist/encrypt.command-AGHQ4KTI.js.map +0 -1
- package/dist/init.command-3DHC5DNC.js +0 -13
- package/dist/load.command-CTOV5PYR.js +0 -12
- package/dist/login.command-UZBZIPP3.js +0 -10
- package/dist/run.command-5276KIMX.js +0 -12
- package/dist/telemetry.command-UHJTZULL.js +0 -10
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import { detectJsPackageManager, logLines, fmt, pathExists, installJsDependency } from './chunk-GYHC6Y7D.js';
|
|
2
|
+
import { define } from './chunk-33ROL4J5.js';
|
|
3
|
+
import { loadVarlockEnvGraph } from './chunk-MPS3IXAW.js';
|
|
4
|
+
import { StaticValueResolver, DotEnvFileDataSource, gracefulExit, checkIsFileGitIgnored, ansis_default } from './chunk-Y2RFMQ5X.js';
|
|
1
5
|
import { __commonJS, __name, __toESM } from './chunk-XN24GZXQ.js';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import fs2 from 'fs/promises';
|
|
8
|
+
import 'util';
|
|
9
|
+
import y2, { stdin, stdout } from 'process';
|
|
10
|
+
import O from 'readline';
|
|
11
|
+
import { Writable } from 'stream';
|
|
12
|
+
import { envSpecUpdater, ParsedEnvSpecStaticValue, parseEnvSpecDotEnvFile } from '@env-spec/parser';
|
|
13
|
+
import { WriteStream } from 'tty';
|
|
5
14
|
|
|
6
15
|
// ../../node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
|
|
7
16
|
var require_src = __commonJS({
|
|
@@ -132,7 +141,6 @@ var require_picocolors = __commonJS({
|
|
|
132
141
|
|
|
133
142
|
// ../../node_modules/.pnpm/@clack+core@0.5.0/node_modules/@clack/core/dist/index.mjs
|
|
134
143
|
var import_sisteransi = __toESM(require_src(), 1);
|
|
135
|
-
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
136
144
|
function DD({ onlyFirst: e2 = false } = {}) {
|
|
137
145
|
const t = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
|
|
138
146
|
return new RegExp(t, e2 ? void 0 : "g");
|
|
@@ -507,31 +515,6 @@ var SD = class extends x {
|
|
|
507
515
|
this.value = u2 ? this.value.filter((t) => t !== this._value) : [...this.value, this._value];
|
|
508
516
|
}
|
|
509
517
|
};
|
|
510
|
-
var TD = Object.defineProperty;
|
|
511
|
-
var jD = /* @__PURE__ */ __name((e2, u2, t) => u2 in e2 ? TD(e2, u2, { enumerable: true, configurable: true, writable: true, value: t }) : e2[u2] = t, "jD");
|
|
512
|
-
var U = /* @__PURE__ */ __name((e2, u2, t) => (jD(e2, typeof u2 != "symbol" ? u2 + "" : u2, t), t), "U");
|
|
513
|
-
var MD = class extends x {
|
|
514
|
-
static {
|
|
515
|
-
__name(this, "MD");
|
|
516
|
-
}
|
|
517
|
-
constructor({ mask: u2, ...t }) {
|
|
518
|
-
super(t), U(this, "valueWithCursor", ""), U(this, "_mask", "\u2022"), this._mask = u2 ?? "\u2022", this.on("finalize", () => {
|
|
519
|
-
this.valueWithCursor = this.masked;
|
|
520
|
-
}), this.on("value", () => {
|
|
521
|
-
if (this.cursor >= this.value.length) this.valueWithCursor = `${this.masked}${import_picocolors.default.inverse(import_picocolors.default.hidden("_"))}`;
|
|
522
|
-
else {
|
|
523
|
-
const F2 = this.masked.slice(0, this.cursor), s = this.masked.slice(this.cursor);
|
|
524
|
-
this.valueWithCursor = `${F2}${import_picocolors.default.inverse(s[0])}${s.slice(1)}`;
|
|
525
|
-
}
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
get cursor() {
|
|
529
|
-
return this._cursor;
|
|
530
|
-
}
|
|
531
|
-
get masked() {
|
|
532
|
-
return this.value.replaceAll(/./g, this._mask);
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
518
|
var OD = Object.defineProperty;
|
|
536
519
|
var PD = /* @__PURE__ */ __name((e2, u2, t) => u2 in e2 ? OD(e2, u2, { enumerable: true, configurable: true, writable: true, value: t }) : e2[u2] = t, "PD");
|
|
537
520
|
var J = /* @__PURE__ */ __name((e2, u2, t) => (PD(e2, typeof u2 != "symbol" ? u2 + "" : u2, t), t), "J");
|
|
@@ -563,7 +546,7 @@ var LD = class extends x {
|
|
|
563
546
|
};
|
|
564
547
|
|
|
565
548
|
// ../../node_modules/.pnpm/@clack+prompts@0.11.0/node_modules/@clack/prompts/dist/index.mjs
|
|
566
|
-
var
|
|
549
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
567
550
|
__toESM(require_src(), 1);
|
|
568
551
|
function ce() {
|
|
569
552
|
return y2.platform !== "win32" ? y2.env.TERM !== "linux" : !!y2.env.CI || !!y2.env.WT_SESSION || !!y2.env.TERMINUS_SUBLIME || y2.env.ConEmuTask === "{cmd::Cmder}" || y2.env.TERM_PROGRAM === "Terminus-Sublime" || y2.env.TERM_PROGRAM === "vscode" || y2.env.TERM === "xterm-256color" || y2.env.TERM === "alacritty" || y2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
@@ -583,7 +566,7 @@ var P2 = u("\u25CB", " ");
|
|
|
583
566
|
u("\u25FB", "[\u2022]");
|
|
584
567
|
u("\u25FC", "[+]");
|
|
585
568
|
u("\u25FB", "[ ]");
|
|
586
|
-
|
|
569
|
+
u("\u25AA", "\u2022");
|
|
587
570
|
u("\u2500", "-");
|
|
588
571
|
u("\u256E", "+");
|
|
589
572
|
u("\u251C", "+");
|
|
@@ -596,80 +579,581 @@ var b2 = /* @__PURE__ */ __name((t) => {
|
|
|
596
579
|
switch (t) {
|
|
597
580
|
case "initial":
|
|
598
581
|
case "active":
|
|
599
|
-
return
|
|
582
|
+
return import_picocolors.default.cyan(le);
|
|
600
583
|
case "cancel":
|
|
601
|
-
return
|
|
584
|
+
return import_picocolors.default.red(L2);
|
|
602
585
|
case "error":
|
|
603
|
-
return
|
|
586
|
+
return import_picocolors.default.yellow(W2);
|
|
604
587
|
case "submit":
|
|
605
|
-
return
|
|
588
|
+
return import_picocolors.default.green(C);
|
|
606
589
|
}
|
|
607
590
|
}, "b");
|
|
608
591
|
var G2 = /* @__PURE__ */ __name((t) => {
|
|
609
592
|
const { cursor: n, options: r2, style: i } = t, s = t.maxItems ?? Number.POSITIVE_INFINITY, c = Math.max(process.stdout.rows - 4, 0), a = Math.min(c, Math.max(s, 5));
|
|
610
593
|
let l2 = 0;
|
|
611
594
|
n >= l2 + a - 3 ? l2 = Math.max(Math.min(n - a + 3, r2.length - a), 0) : n < l2 + 2 && (l2 = Math.max(n - 2, 0));
|
|
612
|
-
const $2 = a < r2.length && l2 > 0,
|
|
613
|
-
return r2.slice(l2, l2 + a).map((p2,
|
|
614
|
-
const j2 =
|
|
615
|
-
return j2 || E ?
|
|
595
|
+
const $2 = a < r2.length && l2 > 0, g2 = a < r2.length && l2 + a < r2.length;
|
|
596
|
+
return r2.slice(l2, l2 + a).map((p2, v, f) => {
|
|
597
|
+
const j2 = v === 0 && $2, E = v === f.length - 1 && g2;
|
|
598
|
+
return j2 || E ? import_picocolors.default.dim("...") : i(p2, v + l2 === n);
|
|
616
599
|
});
|
|
617
600
|
}, "G");
|
|
618
|
-
var ge = /* @__PURE__ */ __name((t) => new MD({ validate: t.validate, mask: t.mask ?? $e, render() {
|
|
619
|
-
const n = `${import_picocolors2.default.gray(o)}
|
|
620
|
-
${b2(this.state)} ${t.message}
|
|
621
|
-
`, r2 = this.valueWithCursor, i = this.masked;
|
|
622
|
-
switch (this.state) {
|
|
623
|
-
case "error":
|
|
624
|
-
return `${n.trim()}
|
|
625
|
-
${import_picocolors2.default.yellow(o)} ${i}
|
|
626
|
-
${import_picocolors2.default.yellow(d2)} ${import_picocolors2.default.yellow(this.error)}
|
|
627
|
-
`;
|
|
628
|
-
case "submit":
|
|
629
|
-
return `${n}${import_picocolors2.default.gray(o)} ${import_picocolors2.default.dim(i)}`;
|
|
630
|
-
case "cancel":
|
|
631
|
-
return `${n}${import_picocolors2.default.gray(o)} ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(i ?? ""))}${i ? `
|
|
632
|
-
${import_picocolors2.default.gray(o)}` : ""}`;
|
|
633
|
-
default:
|
|
634
|
-
return `${n}${import_picocolors2.default.cyan(o)} ${r2}
|
|
635
|
-
${import_picocolors2.default.cyan(d2)}
|
|
636
|
-
`;
|
|
637
|
-
}
|
|
638
|
-
} }).prompt(), "ge");
|
|
639
601
|
var ve = /* @__PURE__ */ __name((t) => {
|
|
640
602
|
const n = /* @__PURE__ */ __name((r2, i) => {
|
|
641
603
|
const s = r2.label ?? String(r2.value);
|
|
642
604
|
switch (i) {
|
|
643
605
|
case "selected":
|
|
644
|
-
return `${
|
|
606
|
+
return `${import_picocolors.default.dim(s)}`;
|
|
645
607
|
case "active":
|
|
646
|
-
return `${
|
|
608
|
+
return `${import_picocolors.default.green(k2)} ${s} ${r2.hint ? import_picocolors.default.dim(`(${r2.hint})`) : ""}`;
|
|
647
609
|
case "cancelled":
|
|
648
|
-
return `${
|
|
610
|
+
return `${import_picocolors.default.strikethrough(import_picocolors.default.dim(s))}`;
|
|
649
611
|
default:
|
|
650
|
-
return `${
|
|
612
|
+
return `${import_picocolors.default.dim(P2)} ${import_picocolors.default.dim(s)}`;
|
|
651
613
|
}
|
|
652
614
|
}, "n");
|
|
653
615
|
return new LD({ options: t.options, initialValue: t.initialValue, render() {
|
|
654
|
-
const r2 = `${
|
|
616
|
+
const r2 = `${import_picocolors.default.gray(o)}
|
|
655
617
|
${b2(this.state)} ${t.message}
|
|
656
618
|
`;
|
|
657
619
|
switch (this.state) {
|
|
658
620
|
case "submit":
|
|
659
|
-
return `${r2}${
|
|
621
|
+
return `${r2}${import_picocolors.default.gray(o)} ${n(this.options[this.cursor], "selected")}`;
|
|
660
622
|
case "cancel":
|
|
661
|
-
return `${r2}${
|
|
662
|
-
${
|
|
623
|
+
return `${r2}${import_picocolors.default.gray(o)} ${n(this.options[this.cursor], "cancelled")}
|
|
624
|
+
${import_picocolors.default.gray(o)}`;
|
|
663
625
|
default:
|
|
664
|
-
return `${r2}${
|
|
665
|
-
${
|
|
666
|
-
${
|
|
626
|
+
return `${r2}${import_picocolors.default.cyan(o)} ${G2({ cursor: this.cursor, options: this.options, maxItems: t.maxItems, style: /* @__PURE__ */ __name((i, s) => n(i, s ? "active" : "inactive"), "style") }).join(`
|
|
627
|
+
${import_picocolors.default.cyan(o)} `)}
|
|
628
|
+
${import_picocolors.default.cyan(d2)}
|
|
667
629
|
`;
|
|
668
630
|
}
|
|
669
631
|
} }).prompt();
|
|
670
632
|
}, "ve");
|
|
671
|
-
`${
|
|
633
|
+
`${import_picocolors.default.gray(o)} `;
|
|
634
|
+
function isUnicodeSupported() {
|
|
635
|
+
const { env } = y2;
|
|
636
|
+
const { TERM, TERM_PROGRAM } = env;
|
|
637
|
+
if (y2.platform !== "win32") {
|
|
638
|
+
return TERM !== "linux";
|
|
639
|
+
}
|
|
640
|
+
return Boolean(env.WT_SESSION) || Boolean(env.TERMINUS_SUBLIME) || env.ConEmuTask === "{cmd::Cmder}" || TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
641
|
+
}
|
|
642
|
+
__name(isUnicodeSupported, "isUnicodeSupported");
|
|
643
|
+
|
|
644
|
+
// src/cli/helpers/prompts.ts
|
|
645
|
+
var unicode = isUnicodeSupported();
|
|
646
|
+
var unicodeOr = /* @__PURE__ */ __name((c, fallback) => unicode ? c : fallback, "unicodeOr");
|
|
647
|
+
var S_STEP_ACTIVE = unicodeOr("\u25C6", "*");
|
|
648
|
+
var S_STEP_CANCEL = unicodeOr("\u25A0", "x");
|
|
649
|
+
var S_STEP_ERROR = unicodeOr("\u25B2", "x");
|
|
650
|
+
var S_STEP_SUBMIT = unicodeOr("\u25C7", "o");
|
|
651
|
+
unicodeOr("\u250C", "T");
|
|
652
|
+
var S_BAR = unicodeOr("\u2502", "|");
|
|
653
|
+
var S_BAR_END = unicodeOr("\u2514", "\u2014");
|
|
654
|
+
var S_RADIO_ACTIVE = unicodeOr("\u25CF", ">");
|
|
655
|
+
var S_RADIO_INACTIVE = unicodeOr("\u25CB", " ");
|
|
656
|
+
var S_CHECKBOX_ACTIVE = unicodeOr("\u25FB", "[\u2022]");
|
|
657
|
+
var S_CHECKBOX_SELECTED = unicodeOr("\u25FC", "[+]");
|
|
658
|
+
var S_CHECKBOX_INACTIVE = unicodeOr("\u25FB", "[ ]");
|
|
659
|
+
unicodeOr("\u25AA", "\u2022");
|
|
660
|
+
unicodeOr("\u2500", "-");
|
|
661
|
+
unicodeOr("\u256E", "+");
|
|
662
|
+
unicodeOr("\u251C", "+");
|
|
663
|
+
unicodeOr("\u256F", "+");
|
|
664
|
+
unicodeOr("\u25CF", "\u2022");
|
|
665
|
+
unicodeOr("\u25C6", "*");
|
|
666
|
+
unicodeOr("\u25B2", "!");
|
|
667
|
+
unicodeOr("\u25A0", "x");
|
|
668
|
+
var symbol = /* @__PURE__ */ __name((state) => {
|
|
669
|
+
switch (state) {
|
|
670
|
+
case "initial":
|
|
671
|
+
case "active":
|
|
672
|
+
return ansis_default.cyan(S_STEP_ACTIVE);
|
|
673
|
+
case "cancel":
|
|
674
|
+
return ansis_default.red(S_STEP_CANCEL);
|
|
675
|
+
case "error":
|
|
676
|
+
return ansis_default.yellow(S_STEP_ERROR);
|
|
677
|
+
case "submit":
|
|
678
|
+
return ansis_default.green(S_STEP_SUBMIT);
|
|
679
|
+
}
|
|
680
|
+
}, "symbol");
|
|
681
|
+
var limitOptions = /* @__PURE__ */ __name((params) => {
|
|
682
|
+
const { cursor, options, style } = params;
|
|
683
|
+
const output = params.output ?? process.stdout;
|
|
684
|
+
const rows = output instanceof WriteStream && output.rows !== void 0 ? output.rows : 10;
|
|
685
|
+
const paramMaxItems = params.maxItems ?? Number.POSITIVE_INFINITY;
|
|
686
|
+
const outputMaxItems = Math.max(rows - 4, 0);
|
|
687
|
+
const maxItems = Math.min(outputMaxItems, Math.max(paramMaxItems, 5));
|
|
688
|
+
let slidingWindowLocation = 0;
|
|
689
|
+
if (cursor >= slidingWindowLocation + maxItems - 3) {
|
|
690
|
+
slidingWindowLocation = Math.max(Math.min(cursor - maxItems + 3, options.length - maxItems), 0);
|
|
691
|
+
} else if (cursor < slidingWindowLocation + 2) {
|
|
692
|
+
slidingWindowLocation = Math.max(cursor - 2, 0);
|
|
693
|
+
}
|
|
694
|
+
const shouldRenderTopEllipsis = maxItems < options.length && slidingWindowLocation > 0;
|
|
695
|
+
const shouldRenderBottomEllipsis = maxItems < options.length && slidingWindowLocation + maxItems < options.length;
|
|
696
|
+
return options.slice(slidingWindowLocation, slidingWindowLocation + maxItems).map((option, i, arr) => {
|
|
697
|
+
const isTopLimit = i === 0 && shouldRenderTopEllipsis;
|
|
698
|
+
const isBottomLimit = i === arr.length - 1 && shouldRenderBottomEllipsis;
|
|
699
|
+
return isTopLimit || isBottomLimit ? ansis_default.dim("...") : style(option, i + slidingWindowLocation === cursor);
|
|
700
|
+
});
|
|
701
|
+
}, "limitOptions");
|
|
702
|
+
var confirm = /* @__PURE__ */ __name((opts) => {
|
|
703
|
+
const active = opts.active ?? "Yes";
|
|
704
|
+
const inactive = opts.inactive ?? "No";
|
|
705
|
+
return new dD({
|
|
706
|
+
active,
|
|
707
|
+
inactive,
|
|
708
|
+
input: opts.input,
|
|
709
|
+
output: opts.output,
|
|
710
|
+
initialValue: opts.initialValue ?? true,
|
|
711
|
+
render() {
|
|
712
|
+
const title = `
|
|
713
|
+
${symbol(this.state)} ${opts.message}
|
|
714
|
+
`;
|
|
715
|
+
const value = this.value ? active : inactive;
|
|
716
|
+
switch (this.state) {
|
|
717
|
+
case "submit":
|
|
718
|
+
return `${title}\u200E ${ansis_default.dim(value)}`;
|
|
719
|
+
case "cancel":
|
|
720
|
+
return `${title}\u200E ${ansis_default.strikethrough(
|
|
721
|
+
ansis_default.dim(value)
|
|
722
|
+
)}
|
|
723
|
+
`;
|
|
724
|
+
default: {
|
|
725
|
+
return `${title}\u200E ${this.value ? `${ansis_default.green(S_RADIO_ACTIVE)} ${active}` : `${ansis_default.dim(S_RADIO_INACTIVE)} ${ansis_default.dim(active)}`} ${ansis_default.dim("/")} ${!this.value ? `${ansis_default.green(S_RADIO_ACTIVE)} ${inactive}` : `${ansis_default.dim(S_RADIO_INACTIVE)} ${ansis_default.dim(inactive)}`}
|
|
726
|
+
`;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}).prompt();
|
|
731
|
+
}, "confirm");
|
|
732
|
+
var select = /* @__PURE__ */ __name((opts) => {
|
|
733
|
+
const opt = /* @__PURE__ */ __name((option, state) => {
|
|
734
|
+
const label = option.label ?? String(option.value);
|
|
735
|
+
switch (state) {
|
|
736
|
+
case "selected":
|
|
737
|
+
return `${ansis_default.dim(label)}`;
|
|
738
|
+
case "active":
|
|
739
|
+
return `${ansis_default.green(S_RADIO_ACTIVE)} ${label} ${option.hint ? ansis_default.dim(`(${option.hint})`) : ""}`;
|
|
740
|
+
case "cancelled":
|
|
741
|
+
return `${ansis_default.strikethrough(ansis_default.dim(label))}`;
|
|
742
|
+
default:
|
|
743
|
+
return `${ansis_default.dim(S_RADIO_INACTIVE)} ${ansis_default.dim(label)}`;
|
|
744
|
+
}
|
|
745
|
+
}, "opt");
|
|
746
|
+
return new LD({
|
|
747
|
+
options: opts.options,
|
|
748
|
+
input: opts.input,
|
|
749
|
+
output: opts.output,
|
|
750
|
+
initialValue: opts.initialValue,
|
|
751
|
+
render() {
|
|
752
|
+
const title = `${ansis_default.gray(S_BAR)}
|
|
753
|
+
${symbol(this.state)} ${opts.message}
|
|
754
|
+
`;
|
|
755
|
+
switch (this.state) {
|
|
756
|
+
case "submit":
|
|
757
|
+
return `${title}${ansis_default.gray(S_BAR)} ${opt(this.options[this.cursor], "selected")}`;
|
|
758
|
+
case "cancel":
|
|
759
|
+
return `${title}${ansis_default.gray(S_BAR)} ${opt(
|
|
760
|
+
this.options[this.cursor],
|
|
761
|
+
"cancelled"
|
|
762
|
+
)}
|
|
763
|
+
${ansis_default.gray(S_BAR)}`;
|
|
764
|
+
default: {
|
|
765
|
+
return `${title}${ansis_default.cyan(S_BAR)} ${limitOptions({
|
|
766
|
+
output: opts.output,
|
|
767
|
+
cursor: this.cursor,
|
|
768
|
+
options: this.options,
|
|
769
|
+
maxItems: opts.maxItems,
|
|
770
|
+
style: /* @__PURE__ */ __name((item, active) => opt(item, active ? "active" : "inactive"), "style")
|
|
771
|
+
}).join(`
|
|
772
|
+
${ansis_default.cyan(S_BAR)} `)}
|
|
773
|
+
${ansis_default.cyan(S_BAR_END)}
|
|
774
|
+
`;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}).prompt();
|
|
779
|
+
}, "select");
|
|
780
|
+
var multiselect = /* @__PURE__ */ __name((opts) => {
|
|
781
|
+
const opt = /* @__PURE__ */ __name((option, state) => {
|
|
782
|
+
const label = option.label ?? String(option.value);
|
|
783
|
+
if (state === "active") {
|
|
784
|
+
return `${ansis_default.cyan(S_CHECKBOX_ACTIVE)} ${label} ${option.hint ? ansis_default.dim(`(${option.hint})`) : ""}`;
|
|
785
|
+
}
|
|
786
|
+
if (state === "selected") {
|
|
787
|
+
return `${ansis_default.green(S_CHECKBOX_SELECTED)} ${ansis_default.dim(label)} ${option.hint ? ansis_default.dim(`(${option.hint})`) : ""}`;
|
|
788
|
+
}
|
|
789
|
+
if (state === "cancelled") {
|
|
790
|
+
return `${ansis_default.strikethrough(ansis_default.dim(label))}`;
|
|
791
|
+
}
|
|
792
|
+
if (state === "active-selected") {
|
|
793
|
+
return `${ansis_default.green(S_CHECKBOX_SELECTED)} ${label} ${option.hint ? ansis_default.dim(`(${option.hint})`) : ""}`;
|
|
794
|
+
}
|
|
795
|
+
if (state === "submitted") {
|
|
796
|
+
return `${ansis_default.dim(label)}`;
|
|
797
|
+
}
|
|
798
|
+
return `${ansis_default.dim(S_CHECKBOX_INACTIVE)} ${ansis_default.dim(label)}`;
|
|
799
|
+
}, "opt");
|
|
800
|
+
return new SD({
|
|
801
|
+
options: opts.options,
|
|
802
|
+
input: opts.input,
|
|
803
|
+
output: opts.output,
|
|
804
|
+
initialValues: opts.initialValues,
|
|
805
|
+
required: opts.required ?? true,
|
|
806
|
+
cursorAt: opts.cursorAt,
|
|
807
|
+
validate(selected) {
|
|
808
|
+
if (this.required && selected.length === 0) {
|
|
809
|
+
return `Please select at least one option.
|
|
810
|
+
${ansis_default.reset(
|
|
811
|
+
ansis_default.dim(
|
|
812
|
+
`Press ${ansis_default.gray(ansis_default.bgWhite(ansis_default.inverse(" space ")))} to select, ${ansis_default.gray(
|
|
813
|
+
ansis_default.bgWhite(ansis_default.inverse(" enter "))
|
|
814
|
+
)} to submit`
|
|
815
|
+
)
|
|
816
|
+
)}`;
|
|
817
|
+
}
|
|
818
|
+
},
|
|
819
|
+
render() {
|
|
820
|
+
let title = `${ansis_default.gray(S_BAR)}
|
|
821
|
+
${symbol(this.state)} ${opts.message}
|
|
822
|
+
`;
|
|
823
|
+
if (opts.details) title += `${ansis_default.gray(S_BAR)} ${opts.details}
|
|
824
|
+
`;
|
|
825
|
+
const styleOption = /* @__PURE__ */ __name((option, active) => {
|
|
826
|
+
const selected = this.value.includes(option.value);
|
|
827
|
+
if (active && selected) {
|
|
828
|
+
return opt(option, "active-selected");
|
|
829
|
+
}
|
|
830
|
+
if (selected) {
|
|
831
|
+
return opt(option, "selected");
|
|
832
|
+
}
|
|
833
|
+
return opt(option, active ? "active" : "inactive");
|
|
834
|
+
}, "styleOption");
|
|
835
|
+
switch (this.state) {
|
|
836
|
+
case "submit": {
|
|
837
|
+
return `${title}${ansis_default.gray(S_BAR)} ${this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "submitted")).join(ansis_default.dim(", ")) || ansis_default.dim("none")}`;
|
|
838
|
+
}
|
|
839
|
+
case "cancel": {
|
|
840
|
+
const label = this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "cancelled")).join(ansis_default.dim(", "));
|
|
841
|
+
return `${title}${ansis_default.gray(S_BAR)} ${label.trim() ? `${label}
|
|
842
|
+
${ansis_default.gray(S_BAR)}` : ""}`;
|
|
843
|
+
}
|
|
844
|
+
case "error": {
|
|
845
|
+
const footer = this.error.split("\n").map((ln, i) => i === 0 ? `${ansis_default.yellow(S_BAR_END)} ${ansis_default.yellow(ln)}` : ` ${ln}`).join("\n");
|
|
846
|
+
return `${title + ansis_default.yellow(S_BAR)} ${limitOptions({
|
|
847
|
+
output: opts.output,
|
|
848
|
+
options: this.options,
|
|
849
|
+
cursor: this.cursor,
|
|
850
|
+
maxItems: opts.maxItems,
|
|
851
|
+
style: styleOption
|
|
852
|
+
}).join(`
|
|
853
|
+
${ansis_default.yellow(S_BAR)} `)}
|
|
854
|
+
${footer}
|
|
855
|
+
`;
|
|
856
|
+
}
|
|
857
|
+
default: {
|
|
858
|
+
return `${title}${ansis_default.cyan(S_BAR)} ${limitOptions({
|
|
859
|
+
output: opts.output,
|
|
860
|
+
options: this.options,
|
|
861
|
+
cursor: this.cursor,
|
|
862
|
+
maxItems: opts.maxItems,
|
|
863
|
+
style: styleOption
|
|
864
|
+
}).join(`
|
|
865
|
+
${ansis_default.cyan(S_BAR)} `)}
|
|
866
|
+
${ansis_default.cyan(S_BAR_END)}
|
|
867
|
+
`;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}).prompt();
|
|
872
|
+
}, "multiselect");
|
|
873
|
+
var prompts = {
|
|
874
|
+
confirm,
|
|
875
|
+
select,
|
|
876
|
+
multiselect
|
|
877
|
+
};
|
|
878
|
+
var prompts_default = prompts;
|
|
879
|
+
var PUBLIC_PREFIXES = [
|
|
880
|
+
"PUBLIC",
|
|
881
|
+
"VITE",
|
|
882
|
+
"NEXT_PUBLIC",
|
|
883
|
+
"NUXT_PUBLIC"
|
|
884
|
+
];
|
|
885
|
+
var PUBLIC_KEYWORDS = ["PUBLIC"];
|
|
886
|
+
var SENSITIVE_KEYWORDS = [
|
|
887
|
+
"SECRET",
|
|
888
|
+
"API_KEY",
|
|
889
|
+
"PASSWORD",
|
|
890
|
+
"TOKEN",
|
|
891
|
+
"PRIVATE",
|
|
892
|
+
"CREDENTIALS"
|
|
893
|
+
];
|
|
894
|
+
function isValidUrl(val) {
|
|
895
|
+
try {
|
|
896
|
+
const u2 = new URL(val);
|
|
897
|
+
return true;
|
|
898
|
+
} catch (err) {
|
|
899
|
+
return false;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
__name(isValidUrl, "isValidUrl");
|
|
903
|
+
var EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
904
|
+
var VALID_NUMBER_REGEX = /^(0|([1-9][0-9]*))?(\.[0-9]+)?$/;
|
|
905
|
+
function inferItemDecorators(file, itemKey, valueStr) {
|
|
906
|
+
let itemIsPublic = false;
|
|
907
|
+
if (PUBLIC_PREFIXES.some((prefix) => itemKey.startsWith(prefix))) itemIsPublic = true;
|
|
908
|
+
if (PUBLIC_KEYWORDS.some((keyword) => itemKey.includes(keyword))) itemIsPublic = true;
|
|
909
|
+
let itemIsSensitive = false;
|
|
910
|
+
if (SENSITIVE_KEYWORDS.some((keyword) => itemKey.includes(keyword))) itemIsSensitive = true;
|
|
911
|
+
if (itemIsPublic) ; else if (itemIsSensitive) {
|
|
912
|
+
envSpecUpdater.setItemDecorator(file, itemKey, "sensitive", "true");
|
|
913
|
+
}
|
|
914
|
+
if (itemKey === "PORT" || itemKey.endsWith("_PORT")) {
|
|
915
|
+
envSpecUpdater.setItemDecorator(file, itemKey, "type", "port");
|
|
916
|
+
} else if (itemKey.endsWith("_EMAIL")) {
|
|
917
|
+
envSpecUpdater.setItemDecorator(file, itemKey, "type", "email");
|
|
918
|
+
} else if (itemKey.endsWith("_URL") || itemKey.endsWith("_URI")) {
|
|
919
|
+
envSpecUpdater.setItemDecorator(file, itemKey, "type", "url");
|
|
920
|
+
} else if (valueStr) {
|
|
921
|
+
if (valueStr.startsWith("<") && valueStr.endsWith(">")) {
|
|
922
|
+
envSpecUpdater.setItemDecorator(file, itemKey, "example", valueStr);
|
|
923
|
+
}
|
|
924
|
+
if (valueStr === "true" || valueStr === "false") {
|
|
925
|
+
envSpecUpdater.setItemDecorator(file, itemKey, "type", "boolean");
|
|
926
|
+
} else if (EMAIL_REGEX.test(valueStr)) {
|
|
927
|
+
envSpecUpdater.setItemDecorator(file, itemKey, "type", "email");
|
|
928
|
+
} else if (valueStr !== "0" && valueStr !== "1" && VALID_NUMBER_REGEX.test(valueStr)) {
|
|
929
|
+
envSpecUpdater.setItemDecorator(file, itemKey, "type", "number");
|
|
930
|
+
} else if (isValidUrl(valueStr)) {
|
|
931
|
+
envSpecUpdater.setItemDecorator(file, itemKey, "type", "url");
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
__name(inferItemDecorators, "inferItemDecorators");
|
|
936
|
+
function inferSchemaUpdates(file) {
|
|
937
|
+
for (const item of file.configItems) {
|
|
938
|
+
const valueStr = item.value instanceof ParsedEnvSpecStaticValue && item.value.value?.toString() || "";
|
|
939
|
+
inferItemDecorators(file, item.key, valueStr);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
__name(inferSchemaUpdates, "inferSchemaUpdates");
|
|
943
|
+
function ensureAllItemsExist(envGraph, schemaFile) {
|
|
944
|
+
const addedItemKeys = [];
|
|
945
|
+
for (const itemKey in envGraph.configSchema) {
|
|
946
|
+
const item = envGraph.configSchema[itemKey];
|
|
947
|
+
const itemInSchema = schemaFile.configItems.find((i) => i.key === itemKey);
|
|
948
|
+
if (!itemInSchema) {
|
|
949
|
+
if (addedItemKeys.length === 0) {
|
|
950
|
+
envSpecUpdater.injectFromStr(schemaFile, [
|
|
951
|
+
"",
|
|
952
|
+
"# items added to schema by `varlock init`",
|
|
953
|
+
"# that were missing in example, but detected in other env files",
|
|
954
|
+
"# PLEASE REVIEW THESE!",
|
|
955
|
+
"# ---",
|
|
956
|
+
""
|
|
957
|
+
].join("\n"), { location: "end" });
|
|
958
|
+
}
|
|
959
|
+
addedItemKeys.push(itemKey);
|
|
960
|
+
envSpecUpdater.injectFromStr(schemaFile, [`${itemKey}=`].join("\n"));
|
|
961
|
+
const itemValue = item.valueResolver instanceof StaticValueResolver && item.valueResolver.staticValue || "";
|
|
962
|
+
inferItemDecorators(schemaFile, itemKey, String(itemValue));
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
__name(ensureAllItemsExist, "ensureAllItemsExist");
|
|
967
|
+
async function detectRedundantValues(envGraph, opts = {}) {
|
|
968
|
+
const schema = envGraph.schemaDataSource;
|
|
969
|
+
if (!schema) return {};
|
|
970
|
+
const redundantItemsBySourcePath = {};
|
|
971
|
+
const schemaValues = schema.getStaticValues();
|
|
972
|
+
for (const source of envGraph.dataSources) {
|
|
973
|
+
if (source === schema) continue;
|
|
974
|
+
if (source.type === "example") continue;
|
|
975
|
+
if (!(source instanceof DotEnvFileDataSource) || !source.parsedFile) continue;
|
|
976
|
+
const sourceValues = source.getStaticValues();
|
|
977
|
+
for (const [key, value] of Object.entries(sourceValues)) {
|
|
978
|
+
if (schemaValues[key] !== value) continue;
|
|
979
|
+
redundantItemsBySourcePath[source.fullPath] ||= [];
|
|
980
|
+
redundantItemsBySourcePath[source.fullPath].push(key);
|
|
981
|
+
if (opts.delete) {
|
|
982
|
+
envSpecUpdater.deleteItem(source.parsedFile, key);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
if (opts.delete) {
|
|
986
|
+
await fs2.writeFile(source.fullPath, source.parsedFile.toString(), "utf8");
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
return redundantItemsBySourcePath;
|
|
990
|
+
}
|
|
991
|
+
__name(detectRedundantValues, "detectRedundantValues");
|
|
992
|
+
|
|
993
|
+
// src/cli/commands/init.command.ts
|
|
994
|
+
var commandSpec = define({
|
|
995
|
+
name: "init",
|
|
996
|
+
description: "Set up varlock in the current project",
|
|
997
|
+
args: {}
|
|
998
|
+
});
|
|
999
|
+
var commandFn = /* @__PURE__ */ __name(async (ctx) => {
|
|
1000
|
+
const jsPackageManager = detectJsPackageManager();
|
|
1001
|
+
console.log("\u{1F9D9} Hello and welcome to Varlock \u{1F512}\u{1F525}\u2728");
|
|
1002
|
+
let envGraph = await loadVarlockEnvGraph();
|
|
1003
|
+
const existingSchemaFile = envGraph.dataSources.find((dataSource) => {
|
|
1004
|
+
return dataSource.type === "schema";
|
|
1005
|
+
});
|
|
1006
|
+
if (existingSchemaFile) {
|
|
1007
|
+
logLines([
|
|
1008
|
+
`It looks like you already have a ${fmt.fileName(".env.schema")} file \u{1F389}`,
|
|
1009
|
+
"This init helper is meant to help you get a new project set up.",
|
|
1010
|
+
"If you need to make changes to your schema or values, you can update your files directly.",
|
|
1011
|
+
"See more docs at https://varlock.dev/guides/schema"
|
|
1012
|
+
]);
|
|
1013
|
+
} else {
|
|
1014
|
+
let exampleFileToConvert = null;
|
|
1015
|
+
const allExampleFiles = envGraph.dataSources.filter((dataSource) => {
|
|
1016
|
+
return dataSource instanceof DotEnvFileDataSource && dataSource.type === "example";
|
|
1017
|
+
});
|
|
1018
|
+
if (allExampleFiles.length === 1) {
|
|
1019
|
+
exampleFileToConvert = allExampleFiles[0];
|
|
1020
|
+
} else if (allExampleFiles.length > 1) {
|
|
1021
|
+
console.log("");
|
|
1022
|
+
const selectedExample = await ve({
|
|
1023
|
+
message: `We detected more than one example .env file. Which one should we use to create your new ${fmt.fileName(".env.schema")}?`,
|
|
1024
|
+
options: allExampleFiles.map((file) => ({
|
|
1025
|
+
label: file.fileName,
|
|
1026
|
+
value: file
|
|
1027
|
+
}))
|
|
1028
|
+
});
|
|
1029
|
+
if (pD(selectedExample)) return gracefulExit(0);
|
|
1030
|
+
exampleFileToConvert = selectedExample;
|
|
1031
|
+
}
|
|
1032
|
+
const parsedEnvFile = exampleFileToConvert?.parsedFile || parseEnvSpecDotEnvFile("");
|
|
1033
|
+
if (!parsedEnvFile) throw new Error("No parsed .env file found");
|
|
1034
|
+
envSpecUpdater.ensureHeader(parsedEnvFile, [
|
|
1035
|
+
"This env file uses @env-spec - see https://varlock.dev/env-spec for more info",
|
|
1036
|
+
""
|
|
1037
|
+
// TODO: add env spec version? real links?
|
|
1038
|
+
].join("\n"));
|
|
1039
|
+
envSpecUpdater.setRootDecorator(parsedEnvFile, "defaultRequired", "false", { explicitTrue: true });
|
|
1040
|
+
envSpecUpdater.setRootDecorator(parsedEnvFile, "defaultSensitive", "false", { explicitTrue: true });
|
|
1041
|
+
envSpecUpdater.setRootDecorator(parsedEnvFile, "generateTypes", "lang=ts, path=env.d.ts", { bareFnArgs: true });
|
|
1042
|
+
envSpecUpdater.injectFromStr(parsedEnvFile, [
|
|
1043
|
+
"",
|
|
1044
|
+
"# example env variable injected by `varlock init` \u26A0\uFE0F DELETE THIS ITEM! \u26A0\uFE0F",
|
|
1045
|
+
'# @required @sensitive @example="example value"',
|
|
1046
|
+
'EXAMPLE_ITEM="delete me!"',
|
|
1047
|
+
""
|
|
1048
|
+
].join("\n"), { location: "after_header" });
|
|
1049
|
+
inferSchemaUpdates(parsedEnvFile);
|
|
1050
|
+
ensureAllItemsExist(envGraph, parsedEnvFile);
|
|
1051
|
+
const schemaFilePath = path.join(process.cwd(), ".env.schema");
|
|
1052
|
+
await fs2.writeFile(schemaFilePath, parsedEnvFile.toString());
|
|
1053
|
+
if (exampleFileToConvert) {
|
|
1054
|
+
logLines([
|
|
1055
|
+
"",
|
|
1056
|
+
`Your ${fmt.fileName(exampleFileToConvert.fileName)} has been used to generate your new ${fmt.fileName(".env.schema")}:`,
|
|
1057
|
+
fmt.filePath(schemaFilePath)
|
|
1058
|
+
]);
|
|
1059
|
+
} else {
|
|
1060
|
+
logLines([
|
|
1061
|
+
"",
|
|
1062
|
+
`Your new ${fmt.fileName(".env.schema")} file has been created:`,
|
|
1063
|
+
fmt.filePath(schemaFilePath)
|
|
1064
|
+
]);
|
|
1065
|
+
}
|
|
1066
|
+
if (await checkIsFileGitIgnored(schemaFilePath)) {
|
|
1067
|
+
logLines([ansis_default.dim(`(and updated ${fmt.fileName(".gitignore")} to ensure it will be tracked by git)`)]);
|
|
1068
|
+
await fs2.appendFile(".gitignore", "\n!.env.schema");
|
|
1069
|
+
}
|
|
1070
|
+
logLines([
|
|
1071
|
+
"",
|
|
1072
|
+
ansis_default.bold(`\u{1F6A7} Please review and update your new ${fmt.fileName(".env.schema")} file! \u{1F6A7}`),
|
|
1073
|
+
`We've done our best to get you started, but you must review and make sure it is correct!`,
|
|
1074
|
+
"",
|
|
1075
|
+
`\u{1F449} Some helpful pointers to get you started:`,
|
|
1076
|
+
`- add a description to each item when the name is not self explanitory - it will come through in generated types`,
|
|
1077
|
+
`- use ${fmt.decorator("@required")} (or ${fmt.decorator("@optional")}) to tag items that should fail validation when empty`,
|
|
1078
|
+
`- use ${fmt.decorator("@sensitive")} to tag items that contain sensitive secrets, and must be handled accordingly`,
|
|
1079
|
+
`- use ${fmt.decorator("@type")} to set an item's data type (if not a basic string), which affects validation and coercion logic`,
|
|
1080
|
+
`- if an item value is a ${ansis_default.italic("useful example")} rather than a default, use ${fmt.decorator("@example")}`,
|
|
1081
|
+
`- if an item value is just a dummy placeholder, delete it`
|
|
1082
|
+
]);
|
|
1083
|
+
const confirmReviewed = await prompts_default.confirm({
|
|
1084
|
+
message: `Have you reviewed and updated your new ${fmt.fileName(".env.schema")} file?`
|
|
1085
|
+
});
|
|
1086
|
+
if (pD(confirmReviewed)) return gracefulExit(0);
|
|
1087
|
+
envGraph = await loadVarlockEnvGraph();
|
|
1088
|
+
if (envGraph.configSchema.EXAMPLE_ITEM) {
|
|
1089
|
+
logLines([
|
|
1090
|
+
"",
|
|
1091
|
+
ansis_default.bold(`\u{1F6A8} Really? ${ansis_default.red("You didn't remove the EXAMPLE_ITEM!")}`),
|
|
1092
|
+
`Please make sure your schema is all correct before using it...`
|
|
1093
|
+
]);
|
|
1094
|
+
}
|
|
1095
|
+
if (exampleFileToConvert) {
|
|
1096
|
+
const confirmDeleteExample = await prompts_default.confirm({
|
|
1097
|
+
message: `Should we delete your ${fmt.fileName(exampleFileToConvert.fileName)} file? ${ansis_default.italic.gray("(you can always do this yourself later)")}`
|
|
1098
|
+
});
|
|
1099
|
+
if (pD(confirmDeleteExample)) return gracefulExit(0);
|
|
1100
|
+
if (confirmDeleteExample) {
|
|
1101
|
+
await fs2.unlink(exampleFileToConvert.fullPath);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
const defaultsFile = envGraph.dataSources.find((dataSource) => {
|
|
1105
|
+
return dataSource instanceof DotEnvFileDataSource && dataSource.type === "defaults";
|
|
1106
|
+
});
|
|
1107
|
+
if (defaultsFile) {
|
|
1108
|
+
logLines([
|
|
1109
|
+
"",
|
|
1110
|
+
`\u{1F6A7} We detected a ${fmt.fileName(defaultsFile.fileName)} file in your project`,
|
|
1111
|
+
`You should migrate these default values into ${fmt.fileName(".env.schema")} and delete ${fmt.fileName(defaultsFile.fileName)}`
|
|
1112
|
+
]);
|
|
1113
|
+
}
|
|
1114
|
+
const redundantInfo = await detectRedundantValues(envGraph);
|
|
1115
|
+
if (Object.keys(redundantInfo).length > 0) {
|
|
1116
|
+
logLines([
|
|
1117
|
+
"",
|
|
1118
|
+
ansis_default.bold("\u203C\uFE0F Now that your schema contains defaults, some values in your other .env files are redundant:")
|
|
1119
|
+
]);
|
|
1120
|
+
for (const [sourcePath, itemKeys] of Object.entries(redundantInfo)) {
|
|
1121
|
+
console.log(fmt.filePath(sourcePath));
|
|
1122
|
+
console.log(" ", itemKeys.map((k3) => ansis_default.italic(k3)).join(", "));
|
|
1123
|
+
}
|
|
1124
|
+
const confirmDeleteRedundant = await prompts_default.confirm({
|
|
1125
|
+
message: "Should we delete these redundant values from your other .env files?"
|
|
1126
|
+
});
|
|
1127
|
+
if (pD(confirmDeleteRedundant)) return gracefulExit(0);
|
|
1128
|
+
if (confirmDeleteRedundant) {
|
|
1129
|
+
await detectRedundantValues(envGraph, { delete: true });
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
logLines([
|
|
1133
|
+
"",
|
|
1134
|
+
ansis_default.bold("\u{1F389} Great!"),
|
|
1135
|
+
`You can run ${fmt.command("varlock load", { jsPackageManager })} to attempt loading your env vars validate against your new schema.`,
|
|
1136
|
+
"",
|
|
1137
|
+
"Check out our docs for more info about integrating into your application.",
|
|
1138
|
+
"",
|
|
1139
|
+
"\u{1F4D6} https://varlock.dev \u{1F448}",
|
|
1140
|
+
""
|
|
1141
|
+
]);
|
|
1142
|
+
}
|
|
1143
|
+
if (jsPackageManager && await pathExists(path.join(process.cwd(), "package.json"))) {
|
|
1144
|
+
const installResult = installJsDependency({
|
|
1145
|
+
packageManager: jsPackageManager.name,
|
|
1146
|
+
packageName: "varlock"
|
|
1147
|
+
});
|
|
1148
|
+
if (installResult) {
|
|
1149
|
+
logLines([
|
|
1150
|
+
"",
|
|
1151
|
+
`\u2705 Added ${fmt.packageName("varlock")} as a dependency in your package.json`
|
|
1152
|
+
]);
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
}, "commandFn");
|
|
672
1156
|
|
|
673
|
-
export {
|
|
674
|
-
//# sourceMappingURL=chunk-
|
|
675
|
-
//# sourceMappingURL=chunk-
|
|
1157
|
+
export { commandFn, commandSpec };
|
|
1158
|
+
//# sourceMappingURL=chunk-H5PNRKYP.js.map
|
|
1159
|
+
//# sourceMappingURL=chunk-H5PNRKYP.js.map
|