env-checklist 1.1.2 → 1.2.0

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.
@@ -0,0 +1 @@
1
+ var f=class extends Error{missing;constructor(i){super(i.join(", ")),this.name="PreflightError",this.missing=i}};function u(n){let{required:i,optional:s=[]}=l(n),{missing:r,config:t}=a(i);for(let e of s){let o=process.env[e];o&&(t[e]=o)}if(r.length>0)throw new f(r);return t}function h(n){let{required:i,optional:s=[]}=l(n),{missing:r,present:t,config:e}=a(i),o=[],c=[];for(let g of s){let p=process.env[g];p?(e[g]=p,c.push(g)):o.push(g)}return{ok:r.length===0,config:e,missing:r,present:t,optionalMissing:o,optionalPresent:c}}function l(n){return Array.isArray(n)?{required:n,optional:[]}:{required:n.required,optional:n.optional??[]}}function a(n){let i=[],s=[],r={};for(let t of n){let e=process.env[t];e?(s.push(t),r[t]=e):i.push(t)}return{missing:i,present:s,config:r}}export{f as a,u as b,h as c};
package/dist/cli.cjs CHANGED
@@ -1,12 +1,36 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var d=Object.create;var a=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var y=(e,o,r,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let s of b(o))!x.call(e,s)&&s!==r&&a(e,s,{get:()=>o[s],enumerable:!(i=h(o,s))||i.enumerable});return e};var t=(e,o,r)=>(r=e!=null?d(u(e)):{},y(o||!e||!e.__esModule?a(r,"default",{value:e,enumerable:!0}):r,e));var l=t(require("fs"),1),c=t(require("path"),1),n=t(require("chalk"),1),g=t(require("dotenv"),1);function f(e){let o=[],r={};for(let i of e){let s=process.env[i];s?r[i]=s:o.push(i)}return o.length>0&&(console.error(`
3
- \u2708\uFE0F [env-preflight] Missing variables: ${o.join(", ")}`),process.exit(1)),r}g.default.config();var m=process.cwd(),p=c.default.join(m,".env.example"),k=c.default.join(m,".env"),w=e=>console.log(`${n.default.cyan.bold("[env-checklist]")} ${e}`);l.default.existsSync(p)||(console.error(n.default.red.bold(`
4
- \u274C Error: No .env.example file found.`)),console.log(n.default.dim(`This tool requires a .env.example file to know what variables to check for.
5
- `)),process.exit(1));l.default.existsSync(k)||(console.warn(n.default.yellow.bold(`
6
- \u26A0\uFE0F Warning: No .env file found.`)),console.log(n.default.dim(`Create a .env file to satisfy the requirements in .env.example.
7
- `)));var C=l.default.readFileSync(p,"utf-8"),v=C.split(`
8
- `).map(e=>e.trim()).filter(e=>e&&!e.startsWith("#")).map(e=>e.split("=")[0].trim());v.length===0&&(w(n.default.yellow("No variables found in .env.example to validate.")),process.exit(0));console.log(n.default.blue.bold(`
9
- \u2708\uFE0F Checking environment variables...`));try{f(v),console.log(n.default.green.bold(`\u2705 All systems go. Environment is flight-ready.
10
- `))}catch(e){let o=e instanceof Error?e.message:String(e);console.error(n.default.red.bold(`
11
- \u274C Preflight Failed!`)),console.error(n.default.yellow(`Missing variables: ${o}`)),console.log(n.default.dim(`Please update your .env file to match .env.example.
2
+ "use strict";var O=Object.create;var w=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var L=(o,s,n,i)=>{if(s&&typeof s=="object"||typeof s=="function")for(let t of A(s))!j.call(o,t)&&t!==n&&w(o,t,{get:()=>s[t],enumerable:!(i=F(s,t))||i.enumerable});return o};var h=(o,s,n)=>(n=o!=null?O(M(o)):{},L(s||!o||!o.__esModule?w(n,"default",{value:o,enumerable:!0}):n,o));var g=h(require("fs"),1),u=h(require("path"),1),E=require("module"),e=h(require("chalk"),1),C=h(require("dotenv"),1);function P(o){let{required:s,optional:n=[]}=R(o),{missing:i,present:t,config:a}=T(s),f=[],b=[];for(let d of n){let $=process.env[d];$?(a[d]=$,b.push(d)):f.push(d)}return{ok:i.length===0,config:a,missing:i,present:t,optionalMissing:f,optionalPresent:b}}function R(o){return Array.isArray(o)?{required:o,optional:[]}:{required:o.required,optional:o.optional??[]}}function T(o){let s=[],n=[],i={};for(let t of o){let a=process.env[t];a?(n.push(t),i[t]=a):s.push(t)}return{missing:s,present:n,config:i}}var W={},r=process.argv.slice(2),y={fix:r.includes("--fix"),verbose:r.includes("--verbose"),help:r.includes("--help")||r.includes("-h"),version:r.includes("--version")||r.includes("-v")};if(y.version){let s=(0,E.createRequire)(W.url)("../package.json");console.log(`${e.default.cyan.bold("env-checklist")} ${e.default.white(`v${s.version}`)}`),process.exit(0)}var q=r.indexOf("--path"),m=q!==-1?r[q+1]:null;y.help&&(console.log(`
3
+ ${e.default.cyan.bold("\u2708\uFE0F env-checklist")} \u2014 preflight check for your environment variables
4
+
5
+ ${e.default.bold("Usage:")}
6
+ npx env-checklist [options]
7
+
8
+ ${e.default.bold("Options:")}
9
+ ${e.default.yellow("--verbose")} Show a status line for every key checked
10
+ ${e.default.yellow("--fix")} Auto-generate a .env file from .env.example (placeholder values)
11
+ ${e.default.yellow("--path <file>")} Use a custom .env.example path (useful in monorepos)
12
+ ${e.default.yellow("--version, -v")} Show the current version
13
+ ${e.default.yellow("--help, -h")} Show this help message
14
+
15
+ ${e.default.bold("Examples:")}
16
+ npx env-checklist
17
+ npx env-checklist --verbose
18
+ npx env-checklist --fix
19
+ npx env-checklist --path apps/api/.env.example
20
+ `),process.exit(0));var k=process.cwd(),v=m?u.default.resolve(k,m):u.default.join(k,".env.example"),x=u.default.join(k,".env");C.default.config({path:x});g.default.existsSync(v)||(console.error(e.default.red.bold(`
21
+ \u274C Error: No .env.example file found.`)),console.log(m?e.default.dim(` Looked at: ${v}
22
+ `):e.default.dim(` This tool requires a .env.example file to know what variables to check for.
23
+ `)),process.exit(1));var U=g.default.readFileSync(v,"utf-8"),N=U.split(`
24
+ `).map(o=>o.trim()),p=[],c=[];for(let o of N){if(!o||o.startsWith("#"))continue;let s=o.toLowerCase().includes("# optional"),n=o.split("=")[0].trim();n&&(s?c.push(n):p.push(n))}p.length===0&&c.length===0&&(console.log(e.default.yellow(`${e.default.cyan.bold("[env-checklist]")} No variables found in .env.example to validate.`)),process.exit(0));if(y.fix){g.default.existsSync(x)&&(console.log(e.default.yellow.bold(`
25
+ \u26A0\uFE0F .env already exists \u2014 skipping to avoid overwriting your values.`)),console.log(e.default.dim(` Delete your .env and re-run with --fix to regenerate.
26
+ `)),process.exit(0));let o=[...p,...c],s=["# Auto-generated by env-checklist --fix","# Fill in the values below before starting your app.","",...p.map(n=>`${n}=`),...c.length>0?["","# Optional",...c.map(n=>`${n}= # optional`)]:[]].join(`
27
+ `);g.default.writeFileSync(x,s,"utf-8"),console.log(e.default.green.bold(`
28
+ \u2705 .env file created from .env.example.`)),console.log(e.default.dim(` ${o.length} variable(s) scaffolded. Fill in the values before launching.
29
+ `)),process.exit(0)}g.default.existsSync(x)||(console.warn(e.default.yellow.bold(`
30
+ \u26A0\uFE0F Warning: No .env file found.`)),console.log(e.default.dim(` Run with --fix to auto-generate one, or create it manually.
31
+ `)));console.log(e.default.blue.bold(`
32
+ \u2708\uFE0F Checking environment variables...`));m&&console.log(e.default.dim(` Using: ${v}`));var l=P({required:p,optional:c});if(y.verbose){console.log("");let o=[...p.map(n=>({key:n,type:"required"})),...c.map(n=>({key:n,type:"optional"}))],s=Math.max(...o.map(n=>n.key.length),10);console.log(e.default.dim(" "+"KEY".padEnd(s+2)+"TYPE".padEnd(12)+"STATUS")),console.log(e.default.dim(" "+"\u2500".repeat(s+26)));for(let{key:n,type:i}of o){let a=(i==="required"?l.present.includes(n):l.optionalPresent.includes(n))?e.default.green("\u2705 present"):i==="optional"?e.default.dim("\u2796 not set"):e.default.red("\u274C missing"),f=i==="optional"?e.default.dim("optional"):e.default.white("required");console.log(` ${n.padEnd(s+2)}${f.padEnd(20)}${a}`)}console.log("")}var S=p.length+c.length,I=l.present.length+l.optionalPresent.length,K=l.missing.length;if(l.ok)console.log(e.default.green.bold("\u2705 All systems go. Environment is flight-ready.")),console.log(e.default.dim(` ${I}/${S} variable(s) present`)+(l.optionalMissing.length>0?e.default.dim(` \xB7 ${l.optionalMissing.length} optional not set`):"")),console.log("");else{console.error(e.default.red.bold(`
33
+ \u274C Preflight Failed!`)),console.log(""),console.log(e.default.red(" Missing required variables:"));for(let o of l.missing)console.log(` ${e.default.red("\u2716")} ${e.default.yellow(o)}`);console.log(""),console.log(e.default.dim(` ${l.present.length} passed \xB7 `)+e.default.red.bold(`${K} failed`)+e.default.dim(` \xB7 ${S} total`)),console.log(e.default.dim(`
34
+ Please update your .env file to match .env.example.
35
+ `)),console.log(e.default.dim(` Tip: run with --fix to auto-generate a .env scaffold.
12
36
  `)),process.exit(1)}
package/dist/cli.js CHANGED
@@ -1,11 +1,36 @@
1
1
  #!/usr/bin/env node
2
- import{a as r}from"./chunk-FEPVSWMN.js";import n from"fs";import l from"path";import o from"chalk";import c from"dotenv";c.config();var s=process.cwd(),t=l.join(s,".env.example"),m=l.join(s,".env"),f=e=>console.log(`${o.cyan.bold("[env-checklist]")} ${e}`);n.existsSync(t)||(console.error(o.red.bold(`
3
- \u274C Error: No .env.example file found.`)),console.log(o.dim(`This tool requires a .env.example file to know what variables to check for.
4
- `)),process.exit(1));n.existsSync(m)||(console.warn(o.yellow.bold(`
5
- \u26A0\uFE0F Warning: No .env file found.`)),console.log(o.dim(`Create a .env file to satisfy the requirements in .env.example.
6
- `)));var d=n.readFileSync(t,"utf-8"),i=d.split(`
7
- `).map(e=>e.trim()).filter(e=>e&&!e.startsWith("#")).map(e=>e.split("=")[0].trim());i.length===0&&(f(o.yellow("No variables found in .env.example to validate.")),process.exit(0));console.log(o.blue.bold(`
8
- \u2708\uFE0F Checking environment variables...`));try{r(i),console.log(o.green.bold(`\u2705 All systems go. Environment is flight-ready.
9
- `))}catch(e){let a=e instanceof Error?e.message:String(e);console.error(o.red.bold(`
10
- \u274C Preflight Failed!`)),console.error(o.yellow(`Missing variables: ${a}`)),console.log(o.dim(`Please update your .env file to match .env.example.
2
+ import{c as v}from"./chunk-RXQEM5JJ.js";import a from"fs";import f from"path";import{createRequire as k}from"module";import e from"chalk";import $ from"dotenv";var t=process.argv.slice(2),g={fix:t.includes("--fix"),verbose:t.includes("--verbose"),help:t.includes("--help")||t.includes("-h"),version:t.includes("--version")||t.includes("-v")};if(g.version){let s=k(import.meta.url)("../package.json");console.log(`${e.cyan.bold("env-checklist")} ${e.white(`v${s.version}`)}`),process.exit(0)}var u=t.indexOf("--path"),c=u!==-1?t[u+1]:null;g.help&&(console.log(`
3
+ ${e.cyan.bold("\u2708\uFE0F env-checklist")} \u2014 preflight check for your environment variables
4
+
5
+ ${e.bold("Usage:")}
6
+ npx env-checklist [options]
7
+
8
+ ${e.bold("Options:")}
9
+ ${e.yellow("--verbose")} Show a status line for every key checked
10
+ ${e.yellow("--fix")} Auto-generate a .env file from .env.example (placeholder values)
11
+ ${e.yellow("--path <file>")} Use a custom .env.example path (useful in monorepos)
12
+ ${e.yellow("--version, -v")} Show the current version
13
+ ${e.yellow("--help, -h")} Show this help message
14
+
15
+ ${e.bold("Examples:")}
16
+ npx env-checklist
17
+ npx env-checklist --verbose
18
+ npx env-checklist --fix
19
+ npx env-checklist --path apps/api/.env.example
20
+ `),process.exit(0));var m=process.cwd(),p=c?f.resolve(m,c):f.join(m,".env.example"),d=f.join(m,".env");$.config({path:d});a.existsSync(p)||(console.error(e.red.bold(`
21
+ \u274C Error: No .env.example file found.`)),console.log(c?e.dim(` Looked at: ${p}
22
+ `):e.dim(` This tool requires a .env.example file to know what variables to check for.
23
+ `)),process.exit(1));var w=a.readFileSync(p,"utf-8"),P=w.split(`
24
+ `).map(n=>n.trim()),r=[],i=[];for(let n of P){if(!n||n.startsWith("#"))continue;let s=n.toLowerCase().includes("# optional"),o=n.split("=")[0].trim();o&&(s?i.push(o):r.push(o))}r.length===0&&i.length===0&&(console.log(e.yellow(`${e.cyan.bold("[env-checklist]")} No variables found in .env.example to validate.`)),process.exit(0));if(g.fix){a.existsSync(d)&&(console.log(e.yellow.bold(`
25
+ \u26A0\uFE0F .env already exists \u2014 skipping to avoid overwriting your values.`)),console.log(e.dim(` Delete your .env and re-run with --fix to regenerate.
26
+ `)),process.exit(0));let n=[...r,...i],s=["# Auto-generated by env-checklist --fix","# Fill in the values below before starting your app.","",...r.map(o=>`${o}=`),...i.length>0?["","# Optional",...i.map(o=>`${o}= # optional`)]:[]].join(`
27
+ `);a.writeFileSync(d,s,"utf-8"),console.log(e.green.bold(`
28
+ \u2705 .env file created from .env.example.`)),console.log(e.dim(` ${n.length} variable(s) scaffolded. Fill in the values before launching.
29
+ `)),process.exit(0)}a.existsSync(d)||(console.warn(e.yellow.bold(`
30
+ \u26A0\uFE0F Warning: No .env file found.`)),console.log(e.dim(` Run with --fix to auto-generate one, or create it manually.
31
+ `)));console.log(e.blue.bold(`
32
+ \u2708\uFE0F Checking environment variables...`));c&&console.log(e.dim(` Using: ${p}`));var l=v({required:r,optional:i});if(g.verbose){console.log("");let n=[...r.map(o=>({key:o,type:"required"})),...i.map(o=>({key:o,type:"optional"}))],s=Math.max(...n.map(o=>o.key.length),10);console.log(e.dim(" "+"KEY".padEnd(s+2)+"TYPE".padEnd(12)+"STATUS")),console.log(e.dim(" "+"\u2500".repeat(s+26)));for(let{key:o,type:h}of n){let y=(h==="required"?l.present.includes(o):l.optionalPresent.includes(o))?e.green("\u2705 present"):h==="optional"?e.dim("\u2796 not set"):e.red("\u274C missing"),b=h==="optional"?e.dim("optional"):e.white("required");console.log(` ${o.padEnd(s+2)}${b.padEnd(20)}${y}`)}console.log("")}var x=r.length+i.length,S=l.present.length+l.optionalPresent.length,E=l.missing.length;if(l.ok)console.log(e.green.bold("\u2705 All systems go. Environment is flight-ready.")),console.log(e.dim(` ${S}/${x} variable(s) present`)+(l.optionalMissing.length>0?e.dim(` \xB7 ${l.optionalMissing.length} optional not set`):"")),console.log("");else{console.error(e.red.bold(`
33
+ \u274C Preflight Failed!`)),console.log(""),console.log(e.red(" Missing required variables:"));for(let n of l.missing)console.log(` ${e.red("\u2716")} ${e.yellow(n)}`);console.log(""),console.log(e.dim(` ${l.present.length} passed \xB7 `)+e.red.bold(`${E} failed`)+e.dim(` \xB7 ${x} total`)),console.log(e.dim(`
34
+ Please update your .env file to match .env.example.
35
+ `)),console.log(e.dim(` Tip: run with --fix to auto-generate a .env scaffold.
11
36
  `)),process.exit(1)}
package/dist/index.cjs CHANGED
@@ -1,2 +1 @@
1
- "use strict";var r=Object.defineProperty;var t=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var c=(e,n)=>{for(var o in n)r(e,o,{get:n[o],enumerable:!0})},l=(e,n,o,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of g(n))!f.call(e,i)&&i!==o&&r(e,i,{get:()=>n[i],enumerable:!(s=t(n,i))||s.enumerable});return e};var p=e=>l(r({},"__esModule",{value:!0}),e);var u={};c(u,{preflight:()=>a});module.exports=p(u);function a(e){let n=[],o={};for(let s of e){let i=process.env[s];i?o[s]=i:n.push(s)}return n.length>0&&(console.error(`
2
- \u2708\uFE0F [env-preflight] Missing variables: ${n.join(", ")}`),process.exit(1)),o}0&&(module.exports={preflight});
1
+ "use strict";var c=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var m=(n,i)=>{for(var r in i)c(n,r,{get:i[r],enumerable:!0})},k=(n,i,r,e)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of d(i))!P.call(n,t)&&t!==r&&c(n,t,{get:()=>i[t],enumerable:!(e=h(i,t))||e.enumerable});return n};var q=n=>k(c({},"__esModule",{value:!0}),n);var v={};m(v,{PreflightError:()=>f,preflight:()=>x,preflightSafe:()=>y});module.exports=q(v);var f=class extends Error{missing;constructor(i){super(i.join(", ")),this.name="PreflightError",this.missing=i}};function x(n){let{required:i,optional:r=[]}=a(n),{missing:e,config:t}=u(i);for(let s of r){let o=process.env[s];o&&(t[s]=o)}if(e.length>0)throw new f(e);return t}function y(n){let{required:i,optional:r=[]}=a(n),{missing:e,present:t,config:s}=u(i),o=[],p=[];for(let g of r){let l=process.env[g];l?(s[g]=l,p.push(g)):o.push(g)}return{ok:e.length===0,config:s,missing:e,present:t,optionalMissing:o,optionalPresent:p}}function a(n){return Array.isArray(n)?{required:n,optional:[]}:{required:n.required,optional:n.optional??[]}}function u(n){let i=[],r=[],e={};for(let t of n){let s=process.env[t];s?(r.push(t),e[t]=s):i.push(t)}return{missing:i,present:r,config:e}}0&&(module.exports={PreflightError,preflight,preflightSafe});
package/dist/index.d.cts CHANGED
@@ -1,6 +1,23 @@
1
1
  interface Config {
2
- [key: string]: string | number | boolean;
2
+ [key: string]: string;
3
3
  }
4
- declare function preflight(requiredKeys: string[]): Config;
4
+ interface PreflightOptions {
5
+ required: string[];
6
+ optional?: string[];
7
+ }
8
+ interface PreflightSafeResult {
9
+ ok: boolean;
10
+ config: Config;
11
+ missing: string[];
12
+ present: string[];
13
+ optionalMissing: string[];
14
+ optionalPresent: string[];
15
+ }
16
+ declare class PreflightError extends Error {
17
+ readonly missing: string[];
18
+ constructor(missing: string[]);
19
+ }
20
+ declare function preflight(input: string[] | PreflightOptions): Config;
21
+ declare function preflightSafe(input: string[] | PreflightOptions): PreflightSafeResult;
5
22
 
6
- export { type Config, preflight };
23
+ export { type Config, PreflightError, type PreflightOptions, type PreflightSafeResult, preflight, preflightSafe };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,23 @@
1
1
  interface Config {
2
- [key: string]: string | number | boolean;
2
+ [key: string]: string;
3
3
  }
4
- declare function preflight(requiredKeys: string[]): Config;
4
+ interface PreflightOptions {
5
+ required: string[];
6
+ optional?: string[];
7
+ }
8
+ interface PreflightSafeResult {
9
+ ok: boolean;
10
+ config: Config;
11
+ missing: string[];
12
+ present: string[];
13
+ optionalMissing: string[];
14
+ optionalPresent: string[];
15
+ }
16
+ declare class PreflightError extends Error {
17
+ readonly missing: string[];
18
+ constructor(missing: string[]);
19
+ }
20
+ declare function preflight(input: string[] | PreflightOptions): Config;
21
+ declare function preflightSafe(input: string[] | PreflightOptions): PreflightSafeResult;
5
22
 
6
- export { type Config, preflight };
23
+ export { type Config, PreflightError, type PreflightOptions, type PreflightSafeResult, preflight, preflightSafe };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-FEPVSWMN.js";export{a as preflight};
1
+ import{a,b,c}from"./chunk-RXQEM5JJ.js";export{a as PreflightError,b as preflight,c as preflightSafe};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "env-checklist",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Ensure your environment variables are flight-ready before takeoff.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -16,7 +16,7 @@
16
16
  "start": "node ./dist/cli.js && node dist/index.js",
17
17
  "build": "tsup src/index.ts src/cli.ts --format cjs,esm --dts --clean --minify",
18
18
  "dev": "tsup src/index.ts --watch",
19
- "test": "vitest run",
19
+ "test": "vitest run --passWithNoTests",
20
20
  "lint": "tsc --noEmit"
21
21
  },
22
22
  "keywords": [
@@ -40,4 +40,4 @@
40
40
  "chalk": "^5.3.0",
41
41
  "dotenv": "^16.4.5"
42
42
  }
43
- }
43
+ }
@@ -1,2 +0,0 @@
1
- function r(s){let n=[],i={};for(let e of s){let o=process.env[e];o?i[e]=o:n.push(e)}return n.length>0&&(console.error(`
2
- \u2708\uFE0F [env-preflight] Missing variables: ${n.join(", ")}`),process.exit(1)),i}export{r as a};