@vef-framework-react/dev 2.10.0 → 2.11.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.
package/dist/cli/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @vef-framework-react/dev v2.
|
|
1
|
+
/*! @vef-framework-react/dev v2.11.0 made by Venus | 2026-07-15T09:37:49.656Z */
|
|
2
2
|
import ft from"chalk";import{program as u}from"commander";import N from"process";import R from"consola";import{randomBytes as fe}from"crypto";import{constants as h}from"fs";import{chmod as pe,lstat as de,mkdir as me,open as ge,readFile as ye,rename as le,unlink as ue}from"fs/promises";import{dirname as he,isAbsolute as T,relative as G,resolve as we}from"path";var c=class extends Error{constructor(t){super(t),this.name="CodeGenerationValidationError"}};import{existsSync as Q}from"fs";import{isAbsolute as P,relative as X,resolve as _}from"path";import{createJiti as Z}from"jiti";var ee=["code-generation.config.ts","code-generation.config.mts","code-generation.config.js","code-generation.config.mjs"];async function S({projectDir:e,configFile:t}){let n=t?[te(e,t)]:ee.map(a=>_(e,a)),i=n.find(a=>Q(a));if(!i)throw new c(`Code generation config not found. Looked for: ${n.join(", ")}`);let s=await Z(e).import(i),r=ne(s);return ie(r,i),{config:r,configPath:i}}function te(e,t){let n=P(t)?t:_(e,t),i=X(e,n);if(i.startsWith("..")||P(i))throw new c(`Code generation config file escapes project root: ${t}. Must stay within ${e}.`);return n}function ne(e){return e!==null&&typeof e=="object"&&"default"in e&&e.default!==null&&typeof e.default=="object"?e.default:e}function ie(e,t){if(typeof e!="object"||e===null)throw new c(`Code generation config at ${t} must export a CodeGenerationConfig object.`);e.dictionaryKeys!==void 0&&oe(e.dictionaryKeys,t)}function oe(e,t){if(typeof e!="object"||e===null)throw new c(`Code generation config at ${t} field \`dictionaryKeys\` must be an object when set.`);if(typeof e.fetchDictionaryKeys!="function")throw new c(`Code generation config at ${t} field \`dictionaryKeys.fetchDictionaryKeys\` must be a function.`);if(e.output!==void 0&&typeof e.output!="string")throw new c(`Code generation config at ${t} field \`dictionaryKeys.output\` must be a string when set; got ${typeof e.output}.`);if(e.timeout!==void 0&&!re(e.timeout))throw new c(`Code generation config at ${t} field \`dictionaryKeys.timeout\` must be a finite non-negative number when set; got ${String(e.timeout)}.`)}function re(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0}var ae="@vef-framework-react/hooks",se=["/* eslint-disable */","// @ts-nocheck","// noinspection JSUnusedGlobalSymbols","// AUTO-GENERATED by @vef-framework-react/dev (vef gen:dictionary-keys). DO NOT EDIT."];function O(e,t){let{configFile:n,augmentTarget:i=ae}=t,o=[...se,`// Source: ${n}`,""];if(e.length===0)o.push("export type DictionaryKey = never;");else{o.push("export type DictionaryKey =");for(let[s,r]of e.entries()){let a=s===e.length-1?";":"";r.comment&&o.push(` /** ${ce(r.comment)} */`),o.push(` | ${JSON.stringify(r.key)}${a}`)}}return o.push("",`declare module ${JSON.stringify(i)} {`," interface Register {"," dictionaryKeys: DictionaryKey;"," }","}",""),o.join(`
|
|
3
3
|
`)}function ce(e){return e.replaceAll(/\s+/g," ").trim().replaceAll("*/",String.raw`*\/`)}var Ee="src/types/dictionary.gen.ts",ve=3e4,A=/^[\w.-]+$/,Ce="letters, digits, underscore, dot, hyphen",ke=e=>console.warn(e);function xe(e,t){return e.key<t.key?-1:e.key>t.key?1:0}async function v({projectDir:e,configFile:t,output:n,check:i=!1,augmentTarget:o,onWarn:s=ke}){let{config:r,configPath:a}=await S({projectDir:e,configFile:t});if(!r.dictionaryKeys)throw new c(`Code generation config at ${a} has no \`dictionaryKeys\` block.`);let{dictionaryKeys:d}=r,m=await Ke(d.fetchDictionaryKeys,d.timeout??ve);De(m);let f=Pe(m,s);f.length===0&&s("`fetchDictionaryKeys` returned no entries; the generated file will declare `DictionaryKey = never`.");let g=_e(e,n??d.output??Ee),K=O(f,{configFile:G(e,a),augmentTarget:o}),D=await Oe(g)!==K;return D&&!i&&(await Se(g),await Te(g,K)),{outputPath:g,keyCount:f.length,changed:D}}async function Ke(e,t){if(t<=0)return await e();let n;try{return await Promise.race([e(),new Promise((i,o)=>{n=setTimeout(()=>o(new Error(`fetchDictionaryKeys timed out after ${t}ms.`)),t)})])}finally{n&&clearTimeout(n)}}function De(e){for(let t of e)if(typeof t.key!="string"||!A.test(t.key))throw new c(`Invalid dictionary key ${JSON.stringify(t.key)}. Keys must match ${A} (${Ce}).`)}function Pe(e,t){let n=new Map;for(let i of e){let o=n.get(i.key);if(!o){n.set(i.key,i);continue}o.comment!==i.comment&&t(`Duplicate dictionary key "${i.key}" with conflicting comments; keeping the first occurrence.`)}return n.values().toArray().toSorted(xe)}function _e(e,t){if(T(t))throw new c(`Output path must be relative to project root; absolute paths are rejected: ${t}`);let n=we(e,t),i=G(e,n);if(i.startsWith("..")||T(i))throw new c(`Output path escapes project root: ${t}. Must stay within ${e}.`);return n}async function Se(e){let t;try{t=await de(e)}catch(n){if(n.code==="ENOENT")return;throw n}if(t.isSymbolicLink())throw new c(`Refusing to overwrite symlink at output path: ${e}. Delete the symlink and rerun generation if this is intentional.`)}async function Oe(e){try{return await ye(e,"utf-8")}catch(t){if(t.code==="ENOENT")return null;throw t}}async function Te(e,t){await me(he(e),{recursive:!0});let n=fe(6).toString("hex"),i=`${e}.${n}.tmp`,o=h.O_NOFOLLOW??0,s=h.O_WRONLY|h.O_CREAT|h.O_EXCL|o,r=await ge(i,s,384);try{await r.writeFile(t,"utf-8")}finally{await r.close()}try{await le(i,e)}catch(a){throw await ue(i).catch(()=>{}),a}await pe(e,420)}import{resolve as Ae}from"path";import{exit as Ge}from"process";import F from"consola";import{execa as Fe}from"execa";import $e from"fs-extra";var{readJsonSync:Ne}=$e,p=class extends Error{};function w(){let e=Ae(import.meta.dirname,"../../package.json");return Ne(e,{encoding:"utf-8"}).version}function $(e){e instanceof p?F.error(e.message):F.error(e),Ge(1)}async function E(){try{await Fe("pnpm",["--version"])}catch{throw new p("VEF requires pnpm. Install it from https://pnpm.io and try again.")}}async function I(e,t=N.cwd()){try{let n=await v({projectDir:t,configFile:e.config,output:e.output,check:e.check,onWarn:o=>R.warn(o)});if(e.check&&n.changed)throw new p(`Generated dictionary keys file is stale at ${n.outputPath}. Run \`vef gen:dictionary-keys\` to refresh.`);let i=n.changed?"":" (unchanged)";R.success(`Generated ${n.keyCount} dictionary keys -> ${n.outputPath}${i}`)}catch(n){if(n instanceof p)throw n;if(N.env.CI){let i=n instanceof Error?n.message:String(n);throw new p(`gen:dictionary-keys failed: ${i}`)}throw n}}import{resolve as y}from"path";import Re,{exit as Ie}from"process";import l from"consola";import{execa as k}from"execa";import be from"fs-extra";import H from"ora";import je from"prompts";var b={"pre-commit":"pnpm dlx lint-staged","commit-msg":"pnpm dlx commitlint --edit $1","pre-push":"pnpm typecheck && pnpm test"},j={"*.{js,ts,tsx,json,jsonc,md,mdx,html}":"eslint --fix","*.{css,scss}":"stylelint --fix"},U={prepare:"vef prepare",typecheck:"tsc --noEmit",test:"vitest run --passWithNoTests"},L="@vef-framework-react/";var{copy:Ue,exists:Le,move:Je,readdir:Ve,readFile:J,readJson:We,writeFile:V,writeJson:Me}=be,W="http://127.0.0.1:8080";function He(e){return e.trim().toLowerCase().replaceAll(/\s+/g,"-").replace(/^[._]+/,"").replaceAll(/[^a-z0-9~-]+/g,"-").replaceAll(/^-+|-+$/g,"")}function M(e){let t=typeof e=="string"?e.trim():"";return t?/[/\\]/.test(t)||t.includes("..")?"App name cannot contain path separators or '..'":!0:"App name is required"}function Ye(e,t){for(let n of["dependencies","devDependencies"]){let i=e[n];if(i)for(let o of Object.keys(i))o.startsWith(L)&&(i[o]=t)}}function C(e,t,n){return e.replace(new RegExp(`^${t}=.*$`,"m"),()=>`${t}=${n}`)}async function Y(e={},t=Re.cwd()){l.start("Creating a new VEF project");let n=[];e.name===void 0&&n.push({type:"text",name:"name",message:"What is the name of your app?",validate:M}),e.title===void 0&&n.push({type:"text",name:"title",message:"What is the title of your app?",validate:g=>typeof g=="string"&&g.trim().length>0||"App title is required"}),e.apiUrl===void 0&&n.push({type:"text",name:"apiUrl",message:"Dev API base URL?",initial:W});let i=await je(n,{onCancel:()=>{l.info("Operation cancelled"),Ie(0)}}),o=e.name??i.name,s=M(o);if(s!==!0)throw new p(s);let r=o.trim(),a=He(r),d=(e.title??i.title)?.trim()||r,m=(e.apiUrl??i.apiUrl)?.trim()||W,f=y(t,r);if(await Le(f)&&(await Ve(f)).length>0)throw new p(`Target directory "${r}" already exists and is not empty. Choose another name or empty it first.`);await E(),await qe(f),await Be(a,f),await Qe(f,{packageName:a,appTitle:d,apiUrl:m}),await Xe(f),await Ze(f),et(r)}var ze=[["_gitignore",".gitignore"],["_gitattributes",".gitattributes"],["_editorconfig",".editorconfig"],["_package.json","package.json"],["_tsconfig.json","tsconfig.json"],["_eslint.config.ts","eslint.config.ts"],["_stylelint.config.js","stylelint.config.js"],["_commitlint.config.ts","commitlint.config.ts"],["_vite.config.ts","vite.config.ts"]];async function qe(e){let t=y(import.meta.dirname,"../template");await Ue(t,e),l.success("Successfully copied template files");for(let[n,i]of ze)await Je(y(e,n),y(e,i))}async function Be(e,t){let n=y(t,"package.json"),i=await We(n,{encoding:"utf-8"}),o=w();i.name=e,Ye(i,o),await Me(n,i,{encoding:"utf-8",spaces:2}),l.success(`Successfully set the app name and pinned framework packages to v${o}`)}async function Qe(e,t){let n=y(e,"env/.env"),i=await J(n,{encoding:"utf-8"}),o=C(C(i,"VEF_APP_NAME",t.packageName),"VEF_APP_TITLE",t.appTitle);await V(n,o);let s=y(e,"env/.env.development"),r=await J(s,{encoding:"utf-8"});await V(s,C(r,"VEF_APP_API_BASE_URL",t.apiUrl)),l.success("Successfully configured environment files")}async function Xe(e){let t=H("Initializing git repository...").start();try{await k`git --version`,await k({cwd:e})`git init`,t.succeed("Successfully initialized git repository")}catch(n){throw t.fail("Failed to initialize git repository"),n}}async function Ze(e){let t=H("Installing dependencies...").start();try{await k({cwd:e})("pnpm",["install"]),t.succeed("Successfully installed dependencies")}catch(n){throw t.fail("Failed to install dependencies"),n}}function et(e){l.success("VEF project created successfully!"),l.box(`Next steps:
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|