@arkenv/cli 0.0.9 → 0.0.10
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/index.cjs +12 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -40,10 +40,12 @@ ${(0,i.styleText)(`gray`,B)}`:``}`;default:{let a=r?`${(0,i.styleText)(`cyan`,B)
|
|
|
40
40
|
${(0,i.styleText)(`cyan`,B)} `:`
|
|
41
41
|
`:` ${(0,i.styleText)(`dim`,`/`)} `}${this.value?`${(0,i.styleText)(`dim`,H)} ${(0,i.styleText)(`dim`,n)}`:`${(0,i.styleText)(`green`,Me)} ${n}`}
|
|
42
42
|
${o}
|
|
43
|
-
`}}}}).prompt()},
|
|
43
|
+
`}}}}).prompt()},G={message:(e=[],{symbol:t=(0,i.styleText)(`gray`,B),secondarySymbol:n=(0,i.styleText)(`gray`,B),output:r=process.stdout,spacing:a=1,withGuide:o}={})=>{let s=[],c=o??j.withGuide,l=c?n:``,u=c?`${t} `:``,d=c?`${n} `:``;for(let e=0;e<a;e++)s.push(l);let f=Array.isArray(e)?e:e.split(`
|
|
44
44
|
`);if(f.length>0){let[e,...r]=f;e.length>0?s.push(`${u}${e}`):s.push(c?t:``);for(let e of r)e.length>0?s.push(`${d}${e}`):s.push(c?n:``)}r.write(`${s.join(`
|
|
45
45
|
`)}
|
|
46
|
-
`)},info:(e,t)=>{G.message(e,{...t,symbol:(0,i.styleText)(`blue`,Re)})},success:(e,t)=>{G.message(e,{...t,symbol:(0,i.styleText)(`green`,ze)})},step:(e,t)=>{G.message(e,{...t,symbol:(0,i.styleText)(`green`,z)})},warn:(e,t)=>{G.message(e,{...t,symbol:(0,i.styleText)(`yellow`,Be)})},warning:(e,t)=>{G.warn(e,t)},error:(e,t)=>{G.message(e,{...t,symbol:(0,i.styleText)(`red`,Ve)})}},
|
|
46
|
+
`)},info:(e,t)=>{G.message(e,{...t,symbol:(0,i.styleText)(`blue`,Re)})},success:(e,t)=>{G.message(e,{...t,symbol:(0,i.styleText)(`green`,ze)})},step:(e,t)=>{G.message(e,{...t,symbol:(0,i.styleText)(`green`,z)})},warn:(e,t)=>{G.message(e,{...t,symbol:(0,i.styleText)(`yellow`,Be)})},warning:(e,t)=>{G.warn(e,t)},error:(e,t)=>{G.message(e,{...t,symbol:(0,i.styleText)(`red`,Ve)})}},Ge=(e=``,t)=>{let n=t?.output??process.stdout,r=t?.withGuide??j.withGuide?`${(0,i.styleText)(`gray`,V)} `:``;n.write(`${r}${(0,i.styleText)(`red`,e)}
|
|
47
|
+
|
|
48
|
+
`)},Ke=(e=``,t)=>{let n=t?.output??process.stdout,r=t?.withGuide??j.withGuide?`${(0,i.styleText)(`gray`,B)}
|
|
47
49
|
${(0,i.styleText)(`gray`,V)} `:``;n.write(`${r}${e}
|
|
48
50
|
|
|
49
51
|
`)},qe=e=>(0,i.styleText)(`dim`,e),Je=(e,t,n)=>{let r={hard:!0,trim:!1},i=O(e,t,r).split(`
|
|
@@ -106,7 +108,7 @@ ${t?(0,i.styleText)(`cyan`,V):``}
|
|
|
106
108
|
outdir: "./dist",
|
|
107
109
|
${b.default.green(`plugins: [arkenv]`)}
|
|
108
110
|
});
|
|
109
|
-
`),{success:!0,instructions:a.trim()}}async function St(e,t){let r=t||await Y();if(!r)return{status:`not_found`};let i=n.default.basename(r);try{let t=await e.readFile(r);if((0,u.parse)(t)?.compilerOptions?.strict===!0)return{status:`already_strict`,file:i};let n=(0,u.applyEdits)(t,(0,u.modify)(t,[`compilerOptions`,`strict`],!0,{formattingOptions:{insertSpaces:!0,tabSize:2}}));return await e.writeFile(r,n),{status:`updated`,file:i}}catch{return{status:`error`,file:i}}}var Ct=class{constructor(e,t){this.isQuiet=e,this.stdio=t}async exists(e){try{return await t.default.access(e),!0}catch{return!1}}async readFile(e){return t.default.readFile(e,`utf-8`)}async writeFile(e,n){await t.default.writeFile(e,n,`utf-8`)}async mkdir(e,n){await t.default.mkdir(e,{recursive:n})}async execute(e,t=[]){return new Promise((n,r)=>{let i=(0,d.spawn)(e,t,{stdio:this.isQuiet?`pipe`:this.stdio,shell:!1}),a=``,o=``,s=1e4;this.isQuiet&&(i.stdout?.on(`data`,e=>{a=(a+e.toString()).slice(-s)}),i.stderr?.on(`data`,e=>{o=(o+e.toString()).slice(-s)})),i.on(`close`,(e,t)=>{if(e===0)n();else{let n=e===null?`Command terminated by signal ${t}`:`Command failed with code ${e}`;this.isQuiet&&(a&&(n+=`\n${b.default.dim(`STDOUT:`)}\n${a}`),o&&(n+=`\n${b.default.red(`STDERR:`)}\n${o}`)),r(Error(n))}}),i.on(`error`,r)})}async updateTsConfigToStrict(e){return St(this,e)}async findViteConfig(){return vt()}async findBunConfig(){return yt()}async bootstrapViteConfig(e,t){return bt(this,e,t)}async bootstrapBunConfig(e,t){return xt(e,t)}async safeAppend(e,t,n){let{safeAppend:r}=await Promise.resolve().then(()=>m);return r(e,t,n)}};
|
|
111
|
+
`),{success:!0,instructions:a.trim()}}async function St(e,t){let r=t||await Y();if(!r)return{status:`not_found`};let i=n.default.basename(r);try{let t=await e.readFile(r);if((0,u.parse)(t)?.compilerOptions?.strict===!0)return{status:`already_strict`,file:i};let n=(0,u.applyEdits)(t,(0,u.modify)(t,[`compilerOptions`,`strict`],!0,{formattingOptions:{insertSpaces:!0,tabSize:2}}));return await e.writeFile(r,n),{status:`updated`,file:i}}catch{return{status:`error`,file:i}}}var Ct=class{constructor(e,t){this.isQuiet=e,this.stdio=t}async exists(e){try{return await t.default.access(e),!0}catch{return!1}}async readFile(e){return t.default.readFile(e,`utf-8`)}async writeFile(e,n){await t.default.writeFile(e,n,`utf-8`)}async mkdir(e,n){await t.default.mkdir(e,{recursive:n})}async execute(e,t=[]){return new Promise((n,r)=>{let i=(0,d.spawn)(e,t,{stdio:this.isQuiet?`pipe`:this.stdio,shell:!1}),a=``,o=``,s=1e4;this.isQuiet&&(i.stdout?.on(`data`,e=>{a=(a+e.toString()).slice(-s)}),i.stderr?.on(`data`,e=>{o=(o+e.toString()).slice(-s)})),i.on(`close`,(e,t)=>{if(e===0)n();else{let n=e===null?`Command terminated by signal ${t}`:`Command failed with code ${e}`;this.isQuiet&&(a&&(n+=`\n${b.default.dim(`STDOUT:`)}\n${a}`),o&&(n+=`\n${b.default.red(`STDERR:`)}\n${o}`)),r(Error(n))}}),i.on(`error`,r)})}async updateTsConfigToStrict(e){return St(this,e)}async findViteConfig(){return vt()}async findBunConfig(){return yt()}async bootstrapViteConfig(e,t){return bt(this,e,t)}async bootstrapBunConfig(e,t){return xt(e,t)}async safeAppend(e,t,n){let{safeAppend:r}=await Promise.resolve().then(()=>m);return r(e,t,n)}};const Q={overwriteEnvSchemaFile:(e=`./src/env.ts`)=>async()=>{if((0,c.existsSync)(n.default.resolve(process.cwd(),e))){let t=await W({message:b.default.yellow(`An existing ArkEnv configuration was found at ${Z(e)}. Do you want to overwrite it?`),initialValue:!1,active:`Yes (override my configuration)`,inactive:`No (abort)`});return M(t)||!t?null:t}return!0},framework:e=>async()=>{let t=await q({message:`Select your framework or build tool:`,initialValue:e?.framework,options:[{value:`vanilla`,label:`Vanilla${e?.framework===`vanilla`?` (Detected)`:``}`,hint:`Node.js, Bun, server-side or runtime-only validation`},{value:`vite`,label:`Vite${e?.framework===`vite`?` (Detected)`:``}`,hint:`Client-side and static inlining validation`},{value:`bun-fullstack`,label:`Bun fullstack dev server${e?.framework===`bun-fullstack`?` (Detected)`:``}`,hint:`Client-side bundling and Bun.serve integration`}]});return M(t)?null:t},bunBuild:(e=!1)=>async()=>{let t=await W({message:`Optional: Would you also like to bootstrap a custom Bun.build script for programmatic bundling?`,initialValue:e});return M(t)?null:t},useDefaultPath:(e=`./src/env.ts`)=>async()=>{let t=await W({message:`Use default config path (${Z(e)})?`,initialValue:!0,active:`Yes (Recommended)`,inactive:`No, let me customize it`});return M(t)?null:t},path:(e=`./src/env.ts`)=>async({results:t})=>{if(t.useDefaultPath===null)return null;if(!t.useDefaultPath){let t=await $e({message:`Where should we create the ArkEnv config?`,placeholder:e,initialValue:e});if(M(t))return null;let n=typeof t==`string`?t.trim():``;return n===``?e:n}return e},installTypeDefinitions:async({results:e})=>{if(e.framework===null)return null;if(e.framework===`vite`||e.framework===`bun`){let t=e.framework===`vite`?`vite-env.d.ts`:`bun-env.d.ts`,r=n.default.dirname(n.default.resolve(process.cwd(),e.path||`./src/env.ts`)),i=n.default.join(r,t);if(c.default.existsSync(i))return!0;let a=await W({message:`Establish ${Z(t)} for typesafe environment variables?`,initialValue:!0,active:`Yes (Recommended)`,inactive:`No`});return M(a)?null:a}return!0},envDtsHandling:async({results:e})=>{if(e.installTypeDefinitions===null)return null;if(!e.installTypeDefinitions||e.framework!==`vite`&&e.framework!==`bun`)return`skip`;let t=e.framework===`vite`?`vite-env.d.ts`:`bun-env.d.ts`,r=n.default.dirname(n.default.resolve(process.cwd(),e.path||`./src/env.ts`)),i=n.default.join(r,t);if(c.default.existsSync(i)){let e=await q({message:`Found existing ${Z(t)}. How should we handle ArkEnv types?`,options:[{value:`append`,label:`Append types safely (if needed)`,hint:`Recommended`},{value:`overwrite`,label:`Overwrite entirely`,hint:`Destructive`},{value:`skip`,label:`Skip`}]});return M(e)?null:e}return`overwrite`},validator:async()=>{let e=await q({message:`Select your preferred validator library:`,options:[{value:`arktype`,label:`ArkType (Recommended)`,hint:`TypeScript's 1:1 validator, optimized from editor to runtime`},{value:`zod`,label:`Zod`,hint:`TypeScript-first schema validation with static type inference`},{value:`valibot`,label:`Valibot`,hint:`The modular and type safe schema library`}]});return M(e)?null:e},useEnvExample:(e,t=`.env.example`)=>async()=>{if(e&&e.length>0){let n=await W({message:t===`.env.example`?`Detected ${Z(`.env.example`)} with ${e.length} keys. Use them for your schema?`:`Detected ${e.length} environment variables used in your project. Use them for your schema?`,active:`Yes (Recommended)`,initialValue:!0});return M(n)?null:n}return!1}};async function wt(e,t=!1){let n=e?.defaultEnvPath||`./src/env.ts`,r=e?.envKeys||null,i=e?.envKeysSource||`.env.example`;if(t){let t=e?.framework||`vanilla`,i;return(t===`vite`||t===`bun-fullstack`)&&(i=e?.hasTypeFile?`append`:`overwrite`),(0,p.shake)({path:n,validator:`arktype`,framework:t,bunFeatures:t===`bun-fullstack`?e?.bunFeatures??[`serve`]:void 0,language:`ts`,overwriteEnvSchemaFile:!0,installTypeDefinitions:t!==`vanilla`,installSkill:!1,envDtsHandling:i,envKeys:r??void 0})}let a={},o=[{key:`overwriteEnvSchemaFile`,fn:()=>Q.overwriteEnvSchemaFile(n)()},{key:`framework`,fn:()=>Q.framework(e)()},{key:`bunBuild`,fn:({results:t})=>t.framework===`bun-fullstack`?Q.bunBuild(e?.bunFeatures?.includes(`build`)||t.framework===`bun-fullstack`&&e?.framework===`bun-fullstack`&&e?.bunFeatures?.includes(`build`))():Promise.resolve(void 0)},{key:`useDefaultPath`,fn:()=>Q.useDefaultPath(n)()},{key:`path`,fn:e=>Q.path(n)(e)},{key:`installTypeDefinitions`,fn:e=>Q.installTypeDefinitions(e)},{key:`envDtsHandling`,fn:e=>Q.envDtsHandling(e)},{key:`validator`,fn:()=>Q.validator()},{key:`useEnvExample`,fn:()=>Q.useEnvExample(r,i)()}];for(let{key:e,fn:t}of o){let n=await t({results:a});if(n===null||typeof n==`symbol`&&M(n))return Ge(`Operation cancelled`),null;a[e]=n}let s=a.framework===`bun-fullstack`?a.bunBuild?[`serve`,`build`]:[`serve`]:void 0;return(0,p.shake)({...a,bunFeatures:s,language:`ts`,installSkill:!1,envKeys:a.useEnvExample?r??void 0:void 0})}var Tt=class{async confirm(e,t=!0,n,r){let i=await W((0,p.shake)({message:e,initialValue:t,active:n,inactive:r}));return M(i)?null:i}async runWizard(e,t=!1){return wt(e,t)}},Et=class{constructor(e,t={}){this.args=e.slice(2),this.command=this.args[0],this.isYes=this.args.includes(`--yes`)||this.args.includes(`-y`),this.isQuiet=this.args.includes(`--quiet`)||this.args.includes(`-q`),this.isJson=this.args.includes(`--json`)||this.args.includes(`-j`),this.isAgent=this.args.includes(`--agent`)||this.args.includes(`-a`),this.helpRequested=this.args.includes(`--help`)||this.args.includes(`-h`),this.isAgent&&(this.isYes=!0,this.isQuiet=!0,this.isJson=!0),this.logger=t.logger||new tt({isQuiet:this.isQuiet,isJson:this.isJson,isYes:this.isYes})}},Dt=`0.0.10`,Ot=class{constructor(e){this.logger=e}async execute(){this.logger.log(`ArkEnv CLI v${Dt}`),this.logger.log(`\n${b.default.bold(`Usage:`)}`),this.logger.log(` arkenv init Set up ArkEnv in your project`),this.logger.log(`\n${b.default.bold(`Options:`)}`),this.logger.log(` --yes, -y Skip prompts and use defaults (also passed to skill processes)`),this.logger.log(` --agent, -a Agent mode: --yes --quiet --json`),this.logger.log(` --quiet, -q Quiet mode: Suppress output, capture logs on failure`),this.logger.log(` --json, -j Output structured JSON to stdout`),this.logger.log(` --help, -h Show this help message`)}};const kt=(e,t)=>{let n=e?.length?e.map(e=>`\t\t${e}: "string = ''",`).join(`
|
|
110
112
|
`):` NODE_ENV: "'development' | 'production' | 'test' = 'development'",
|
|
111
113
|
PORT: "number.port = 3000",`;return t===`vite`?r.default`
|
|
112
114
|
import { type } from "arkenv";
|
|
@@ -141,7 +143,7 @@ ${n}
|
|
|
141
143
|
});
|
|
142
144
|
|
|
143
145
|
export const env = arkenv(Env);
|
|
144
|
-
`},
|
|
146
|
+
`},At=e=>r.default`
|
|
145
147
|
/// <reference types="vite/client" />
|
|
146
148
|
|
|
147
149
|
type ImportMetaEnvAugmented =
|
|
@@ -154,7 +156,7 @@ ${n}
|
|
|
154
156
|
interface ImportMeta {
|
|
155
157
|
readonly env: ImportMetaEnv;
|
|
156
158
|
}
|
|
157
|
-
`,
|
|
159
|
+
`,jt=e=>r.default`
|
|
158
160
|
/// <reference types="bun-types" />
|
|
159
161
|
|
|
160
162
|
type ProcessEnvAugmented = import("@arkenv/bun-plugin").ProcessEnvAugmented<
|
|
@@ -164,7 +166,7 @@ ${n}
|
|
|
164
166
|
declare namespace NodeJS {
|
|
165
167
|
interface ProcessEnv extends ProcessEnvAugmented {}
|
|
166
168
|
}
|
|
167
|
-
`,
|
|
169
|
+
`,Mt=(e,t)=>{let n=e?.length?e.map(e=>`\t\t${e}: v.optional(v.string(), ""),`).join(`
|
|
168
170
|
`):` NODE_ENV: v.optional(v.picklist(["development", "production", "test"]), "development"),
|
|
169
171
|
PORT: v.optional(v.pipe(v.string(), v.transform(Number), v.number(), v.integer(), v.minValue(1), v.maxValue(65535)), 3000),`;return t===`vite`?r.default`
|
|
170
172
|
import * as v from "valibot";
|
|
@@ -200,7 +202,7 @@ ${n}
|
|
|
200
202
|
});
|
|
201
203
|
|
|
202
204
|
export const env = arkenv(Env);
|
|
203
|
-
`},
|
|
205
|
+
`},Nt=(e,t)=>{let n=e?.length?e.map(e=>`\t\t${e}: z.string().default(""),`).join(`
|
|
204
206
|
`):` NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
|
|
205
207
|
PORT: z.coerce.number().int().min(1).max(65535).default(3000),`;return t===`vite`?r.default`
|
|
206
208
|
import { z } from "zod";
|
|
@@ -236,12 +238,12 @@ ${n}
|
|
|
236
238
|
});
|
|
237
239
|
|
|
238
240
|
export const env = arkenv(Env);
|
|
239
|
-
`};function
|
|
241
|
+
`};function Pt(e){let{validator:t,envKeys:n,framework:r}=e;switch(t){case`arktype`:return`${kt(n,r)}\n`;case`zod`:return`${Nt(n,r)}\n`;case`valibot`:return`${Mt(n,r)}\n`;default:throw Error(`Unsupported validator: ${t}`)}}function Ft(e,t){switch(e){case`pnpm`:return[`pnpm`,[`add`,...t]];case`yarn`:return[`yarn`,[`add`,...t]];case`bun`:return[`bun`,[`add`,...t]];default:return[`npm`,[`install`,...t]]}}function It(e){return e.metadata.framework===`vite`?`2. Access via ${Z(`import.meta.env.YOUR_VAR`)}`:e.metadata.framework===`bun`?`2. Access via ${Z(`process.env.YOUR_VAR`)}`:`2. Import and use: import { env } from "${Z(e.metadata.importPath)}"`}function Lt(e,t){if(t)return{message:r.default`
|
|
240
242
|
Inside your AI assistant (e.g. Claude Code), use:
|
|
241
243
|
${Z(`/arkenv`)} - automatically refine your schema and configure integrations.
|
|
242
|
-
`,title:`Next steps`};let n=e.skill?.dlxCommand.join(` `)||`npx`,i=e.skill?.packageName||`yamcodes/arkenv`,a=
|
|
244
|
+
`,title:`Next steps`};let n=e.skill?.dlxCommand.join(` `)||`npx`,i=e.skill?.packageName||`yamcodes/arkenv`,a=It(e);return{message:r.default`
|
|
243
245
|
1. Check ${Z(e.metadata.displayPath)} and refine your environment schema.
|
|
244
246
|
${a}
|
|
245
247
|
3. (Recommended) Install the AI skill: ${Z(`${n} skills add ${i}`)}
|
|
246
248
|
Then run ${Z(`/arkenv`)} inside your AI assistant to finish.
|
|
247
|
-
`,title:`Next steps`}}var
|
|
249
|
+
`,title:`Next steps`}}var Rt=class{constructor(e,t){this.workspace=e,this.reporter=t}async execute(e){let t=this.reporter.spinner();t.start(`Scaffolding ArkEnv configuration...`);try{for(let t of e.files){if(t.action===`append`){if(!e.bootstrap||e.bootstrap.framework!==`vite`&&e.bootstrap.framework!==`bun-fullstack`){this.reporter.warn(`Skipping safe-append for ${Z(n.default.basename(t.path))}: unsupported framework.`);continue}await this.workspace.safeAppend(t.path,t.content,e.bootstrap.framework)?this.reporter.info(`Appended ArkEnv types to ${Z(n.default.basename(t.path))}.`):this.reporter.info(`${Z(n.default.basename(t.path))} already contains ArkEnv types.`);continue}if(await this.workspace.mkdir(n.default.dirname(t.path),!0),await this.workspace.writeFile(t.path,t.content),t.label!==`environment schema`&&t.label?.includes(`types`)){let e=t.action===`overwrite`?`Updated`:`Created`;this.reporter.info(`${e} ${Z(n.default.basename(t.path))} for typesafe environment variables.`)}}if(t.stop(`Configuration scaffolded!`),e.install&&process.env.SKIP_INSTALL!==`true`){this.reporter.step(`Installing dependencies with ${Z(e.install.packageManager)}...`);let[t,n]=Ft(e.install.packageManager,e.install.dependencies);await this.workspace.execute(t,n)}let r=!1;if(e.tsConfig){let t=await this.workspace.updateTsConfigToStrict(e.tsConfig.path);t.status===`updated`?(this.reporter.info(`Enforced strict: true in your ${Z(t.file)}`),r=!0):t.status===`error`&&this.reporter.warn(`Could not automatically update ${Z(t.file||`tsconfig.json`)}. Please ensure 'strict: true' is set manually.`)}if(e.bootstrap){if(e.bootstrap.framework===`vite`){let t=await this.workspace.findViteConfig();if(t){this.reporter.step(`Bootstrapping Vite plugin...`);let r=await this.workspace.bootstrapViteConfig(t,e.bootstrap.importPath||`./src/env`);r.success?r.updated&&this.reporter.info(`Updated ${Z(n.default.basename(t))}`):(this.reporter.warn(`Could not automatically update ${Z(n.default.basename(t))}: ${r.error}`),this.reporter.info(`Please add ${Z(`@arkenv/vite-plugin`)} manually.`))}else this.reporter.info(`No Vite config found — please add ${Z(`@arkenv/vite-plugin`)} to your Vite config manually.`)}else if(e.bootstrap.framework===`bun-fullstack`){let t=await this.workspace.findBunConfig(),n=await this.workspace.bootstrapBunConfig(t,e.bootstrap.bunFeatures);n.success&&n.instructions?this.reporter.info(n.instructions):n.success||this.reporter.error(n.error||`Bun bootstrap failed`)}}let i=!1;if(e.skill&&process.env.SKIP_INSTALL!==`true`){this.reporter.step(`Installing ArkEnv agent skill...`);try{let[t,...n]=e.skill.dlxCommand,r=[...n,`skills`,`add`,e.skill.packageName];e.skill.isYes&&r.push(`--yes`),await this.workspace.execute(t,r),i=!0}catch(e){let t=e instanceof Error?e.message:String(e);this.reporter.warn(`Failed to install ArkEnv AI skill: ${t}`)}}let a=Lt(e,i);this.reporter.note(a.message,a.title),this.reporter.finish(`${gt} ArkEnv scaffolding complete. Happy coding!`,{path:e.metadata.displayPath,framework:e.metadata.framework,validator:e.metadata.validator,packageManager:e.metadata.packageManager,tsConfigUpdated:r,skillInstalled:i})}catch(e){throw t.stop(`Scaffolding failed.`),e}}};function zt(e){switch(e){case`pnpm`:return[`pnpm`,`dlx`];case`yarn`:return[`yarn`,`dlx`];case`bun`:return[`bunx`];default:return[`npx`]}}function Bt(e){let{options:t,packageManager:r,tsConfig:i,shouldUpdateTsConfig:a,cwd:o,existingFiles:s}=e,c=n.default.resolve(o,t.path),l=n.default.dirname(c),u={files:[],metadata:{displayPath:``,framework:t.framework,validator:t.validator,packageManager:r,importPath:``}},d=Pt(t),f=s.includes(c);(!f||t.overwriteEnvSchemaFile!==!1)&&u.files.push({path:c,content:d,action:f?`overwrite`:`create`,label:`environment schema`});let m=[`arkenv`,t.validator];if(t.framework===`vite`&&m.push(`@arkenv/vite-plugin`),t.framework===`bun-fullstack`&&t.bunFeatures?.length&&m.push(`@arkenv/bun-plugin`),u.install={packageManager:r,dependencies:m},a&&i.file&&(u.tsConfig={path:n.default.resolve(o,i.file),action:`strict`}),(t.framework===`vite`||t.framework===`bun-fullstack`&&t.bunFeatures?.length)&&t.installTypeDefinitions!==!1){let e=t.framework===`vite`?`vite-env.d.ts`:`bun-env.d.ts`,r=n.default.join(l,e),i=s.includes(r);if(t.envDtsHandling!==`skip`)if(t.envDtsHandling===`append`||!t.envDtsHandling&&i)u.files.push({path:r,content:c,action:`append`,label:`${t.framework} types`});else{let e=t.framework===`vite`?At(t.path):jt(t.path);u.files.push({path:r,content:e,action:i?`overwrite`:`create`,label:`${t.framework} types`})}}(t.framework===`vite`||t.framework===`bun-fullstack`)&&(u.bootstrap=(0,p.shake)({framework:t.framework,bunFeatures:t.framework===`bun-fullstack`?t.bunFeatures:void 0})),t.installSkill&&(u.skill={dlxCommand:zt(r),packageName:`yamcodes/arkenv`,isYes:e.isYes});let h=n.default.relative(o,c).replace(/\\/g,`/`),g=h.startsWith(`.`)?h:`./${h}`,_=g.replace(/\.(ts|js|tsx|jsx)$/,``);return u.metadata.displayPath=g,u.metadata.importPath=_,u.bootstrap&&(u.bootstrap.importPath=_),u}var Vt=class{constructor(e,t,n,r){this.logger=e,this.workspace=t,this.prompt=n,this.scanner=r}async execute(e){let t=await this.collect(e);if(!t)return;let n=Bt(t),r=new Rt(this.workspace,this.logger);try{await r.execute(n)}catch(e){this.logger.fatal(`Scaffolding failed.`,e)}}async collect(e){let{isYes:t,isAgent:r}=e;this.logger.interactiveStdout(!0);try{let e=!1,i=await this.scanner.checkTsConfig();if(i.status===`not_strict`)if(t)e=!0;else{this.logger.warn(`TypeScript strict mode is not enabled in your ${Z(i.file)}.`);let t=await this.prompt.confirm(`ArkEnv requires ${Z(`strict`)} mode in your ${Z(i.file)}. Would you like to enable it now?`,!0,`Yes (Recommended)`);if(t===null)return null;if(!t)return this.logger.cancel(`Operation cancelled.`),null;e=!0}let a=await this.scanner.detectFramework(process.cwd(),i.parsed),o=a===`bun-fullstack`?await this.scanner.detectBunFeatures(process.cwd(),i.parsed):void 0,s=await this.scanner.suggestDefaultEnvPath(process.cwd(),i.parsed),c=n.default.resolve(process.cwd(),s),l=await this.scanner.getEnvExampleKeys(process.cwd(),i.parsed,c),u=!1;if(a===`vite`||a===`bun-fullstack`){let e=a===`vite`?`vite-env.d.ts`:`bun-env.d.ts`,t=n.default.dirname(c),r=n.default.join(t,e);u=await this.workspace.exists(r)}let d=await this.prompt.runWizard((0,p.shake)({framework:a,bunFeatures:o,defaultEnvPath:s,tsConfig:i.parsed??null,envKeys:l?.keys,envKeysSource:l?.source,hasTypeFile:u}),t);if(d===null)return null;if(r)d.installSkill=!1;else if(t)d.installSkill=!0;else{let e=await this.prompt.confirm(`Would you like to install the ArkEnv agent skill?`,!0,`Yes (Recommended)`);if(e===null)return null;d.installSkill=e}let f=n.default.resolve(process.cwd(),d.path);if(await this.workspace.exists(f)&&d.overwriteEnvSchemaFile===void 0){let e=await this.prompt.confirm(`File ${Z(n.default.basename(f))} already exists. Overwrite?`,!1);if(e===null)return null;if(!e)return this.logger.cancel(`Operation cancelled.`),null;d.overwriteEnvSchemaFile=e}let m=await this.scanner.detectPackageManager(process.cwd(),i.parsed),h=[];await this.workspace.exists(f)&&h.push(f);let g;if(d.framework===`vite`?g=`vite-env.d.ts`:d.framework===`bun-fullstack`&&(g=`bun-env.d.ts`),g){let e=n.default.dirname(f),t=n.default.join(e,g);await this.workspace.exists(t)&&h.push(t)}return(0,p.shake)({cwd:process.cwd(),options:d,detectedFramework:a,detectedBunFeatures:o,packageManager:m,tsConfig:i,shouldUpdateTsConfig:e,existingFiles:h,isYes:t})}finally{this.logger.interactiveStdout(!1)}}};function Ht(e){let t=new Et(e),n=t.logger,r=new Ct(t.isQuiet,n.stdio),i=new Tt;return{cli:t,logger:n,workspace:r,prompt:i,initUseCase:new Vt(n,r,i,new ht),helpUseCase:new Ot(n)}}let $,Ut=!1;async function Wt(){let{cli:e,logger:t,initUseCase:n,helpUseCase:r}=Ht(process.argv);$=t,Gt(t),e.helpRequested&&(await r.execute(),await t.flush(),process.exit(0)),e.command!==`init`&&(e.command?t.error(`Unknown command: ${e.command}`):t.error(`Missing command.`),await r.execute(),await t.flush(),process.exit(1));try{await n.execute({isYes:e.isYes,isQuiet:e.isQuiet,isAgent:e.isAgent})}catch(e){try{t.fatal(`An unexpected error occurred`,e)}catch{}await t.flush(),process.exit(1)}}function Gt(e){let t=async t=>{Ut&&process.exit(t),Ut=!0,setTimeout(()=>{process.exit(t)},2e3).unref(),e.interactiveStdout&&e.interactiveStdout(!1);try{e.cancel(`Operation cancelled.`),await e.flush()}catch(t){e.error&&e.error(`Logger failed during shutdown`,t)}finally{process.exit(t)}};process.on(`SIGINT`,()=>t(130)),process.on(`SIGTERM`,()=>t(143))}Wt(),process.on(`unhandledRejection`,async e=>{if($){try{$.fatal(`Unhandled rejection`,e)}catch{}await $.flush()}else console.error(`Unhandled rejection`,e);process.exit(1)}),process.on(`uncaughtException`,async e=>{if($){try{$.fatal(`Uncaught exception`,e)}catch{}await $.flush()}else console.error(`Uncaught exception`,e);process.exit(1)});
|