@vef-framework-react/dev 2.6.0 → 2.8.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/cjs/code-generation/dictionary/core.cjs +1 -1
- package/dist/cjs/code-generation/dictionary/index.cjs +1 -1
- package/dist/cjs/code-generation/index.cjs +1 -1
- package/dist/cjs/lint/commitlint.cjs +1 -1
- package/dist/cjs/lint/index.cjs +1 -1
- package/dist/cjs/lint/no-legacy-middle-size.cjs +1 -1
- package/dist/cjs/vite/index.cjs +1 -1
- package/dist/cjs/vite/plugin-auto-enhance/core.cjs +1 -1
- package/dist/cjs/vite/plugin-auto-enhance/index.cjs +1 -1
- package/dist/cjs/vite/plugin-auto-enhance/plugins/index.cjs +1 -1
- package/dist/cjs/vite/plugin-auto-enhance/plugins/operation-column-width.cjs +1 -1
- package/dist/cli/index.js +4 -4
- package/dist/es/code-generation/dictionary/core.js +43 -40
- package/dist/es/code-generation/dictionary/index.js +11 -4
- package/dist/es/code-generation/index.js +11 -4
- package/dist/es/lint/index.js +8 -3
- package/dist/es/lint/no-legacy-middle-size.js +25 -22
- package/dist/es/vite/index.js +6 -2
- package/dist/es/vite/plugin-auto-enhance/core.js +23 -23
- package/dist/es/vite/plugin-auto-enhance/index.js +2 -1
- package/dist/es/vite/plugin-auto-enhance/plugins/index.js +4 -1
- package/dist/es/vite/plugin-auto-enhance/plugins/operation-column-width.js +74 -72
- package/dist/types/vite/plugin-auto-enhance/core.d.ts +4 -4
- package/package.json +17 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
const c=require("./errors.cjs"),k=require("./load-config.cjs"),_=require("./render.cjs");let T=require("node:crypto"),f=require("node:fs"),o=require("node:fs/promises"),a=require("node:path");var
|
|
1
|
+
const c=require("./errors.cjs"),k=require("./load-config.cjs"),_=require("./render.cjs");let T=require("node:crypto"),f=require("node:fs"),o=require("node:fs/promises"),a=require("node:path");var p="src/types/dictionary.gen.ts",O=3e4,E=/^[\w.-]+$/,v="letters, digits, underscore, dot, hyphen",C=e=>console.warn(e);function K(e,t){return e.key<t.key?-1:e.key>t.key?1:0}async function $({projectDir:e,configFile:t,output:n,check:r=!1,augmentTarget:i,onWarn:y=C}){const{config:s,configPath:l}=await k.loadCodeGenerationConfig({projectDir:e,configFile:t});if(!s.dictionaryKeys)throw new c.CodeGenerationValidationError(`Code generation config at ${l} has no \`dictionaryKeys\` block.`);const{dictionaryKeys:d}=s,w=await A(d.fetchDictionaryKeys,d.timeout??O);F(w);const h=q(w,y);h.length===0&&y("`fetchDictionaryKeys` returned no entries; the generated file will declare `DictionaryKey = never`.");const u=D(e,n??d.output??p),m=_.renderDictionaryKeysFile(h,{configFile:(0,a.relative)(e,l),augmentTarget:i}),g=await S(u)!==m;return g&&!r&&(await N(u),await L(u,m)),{outputPath:u,keyCount:h.length,changed:g}}async function A(e,t){if(t<=0)return await e();let n;try{return await Promise.race([e(),new Promise((r,i)=>{n=setTimeout(()=>i(new Error(`fetchDictionaryKeys timed out after ${t}ms.`)),t)})])}finally{n&&clearTimeout(n)}}function F(e){for(const t of e)if(typeof t.key!="string"||!E.test(t.key))throw new c.CodeGenerationValidationError(`Invalid dictionary key ${JSON.stringify(t.key)}. Keys must match ${E} (${v}).`)}function q(e,t){const n=new Map;for(const r of e){const i=n.get(r.key);if(!i){n.set(r.key,r);continue}i.comment!==r.comment&&t(`Duplicate dictionary key "${r.key}" with conflicting comments; keeping the first occurrence.`)}return n.values().toArray().toSorted(K)}function D(e,t){if((0,a.isAbsolute)(t))throw new c.CodeGenerationValidationError(`Output path must be relative to project root; absolute paths are rejected: ${t}`);const n=(0,a.resolve)(e,t),r=(0,a.relative)(e,n);if(r.startsWith("..")||(0,a.isAbsolute)(r))throw new c.CodeGenerationValidationError(`Output path escapes project root: ${t}. Must stay within ${e}.`);return n}async function N(e){let t;try{t=await(0,o.lstat)(e)}catch(n){if(n.code==="ENOENT")return;throw n}if(t.isSymbolicLink())throw new c.CodeGenerationValidationError(`Refusing to overwrite symlink at output path: ${e}. Delete the symlink and rerun generation if this is intentional.`)}async function S(e){try{return await(0,o.readFile)(e,"utf-8")}catch(t){if(t.code==="ENOENT")return null;throw t}}async function L(e,t){await(0,o.mkdir)((0,a.dirname)(e),{recursive:!0});const n=(0,T.randomBytes)(6).toString("hex"),r=`${e}.${n}.tmp`,i=f.constants.O_NOFOLLOW??0,y=f.constants.O_WRONLY|f.constants.O_CREAT|f.constants.O_EXCL|i,s=await(0,o.open)(r,y,384);try{await s.writeFile(t,"utf-8")}finally{await s.close()}try{await(0,o.rename)(r,e)}catch(l){throw await(0,o.unlink)(r).catch(()=>{}),l}await(0,o.chmod)(e,420)}exports.generateDictionaryKeys=$;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const r=require("./errors.cjs"),e=require("./render.cjs"),i=require("./core.cjs"),
|
|
1
|
+
const r=require("./errors.cjs"),e=require("./render.cjs"),i=require("./core.cjs"),n=require("./types.cjs");exports.CodeGenerationValidationError=r.CodeGenerationValidationError;exports.DICTIONARY_AUGMENT_TARGET=e.DICTIONARY_AUGMENT_TARGET;exports.defineCodeGenerationConfig=n.defineCodeGenerationConfig;exports.generateDictionaryKeys=i.generateDictionaryKeys;exports.renderDictionaryKeysFile=e.renderDictionaryKeysFile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const r=require("./dictionary/errors.cjs"),e=require("./dictionary/render.cjs"),i=require("./dictionary/core.cjs"),
|
|
1
|
+
const r=require("./dictionary/errors.cjs"),e=require("./dictionary/render.cjs"),i=require("./dictionary/core.cjs"),n=require("./dictionary/types.cjs");exports.CodeGenerationValidationError=r.CodeGenerationValidationError;exports.DICTIONARY_AUGMENT_TARGET=e.DICTIONARY_AUGMENT_TARGET;exports.defineCodeGenerationConfig=n.defineCodeGenerationConfig;exports.generateDictionaryKeys=i.generateDictionaryKeys;exports.renderDictionaryKeysFile=e.renderDictionaryKeysFile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let
|
|
1
|
+
let e=require("@coldsmirk/commitlint-config");Object.defineProperty(exports,"defineCommitlintConfig",{enumerable:!0,get:function(){return e.defineCommitlintConfig}});
|
package/dist/cjs/lint/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("./eslint.cjs"),i=require("./stylelint.cjs");let
|
|
1
|
+
const e=require("./eslint.cjs"),i=require("./stylelint.cjs");let n=require("@coldsmirk/commitlint-config");Object.defineProperty(exports,"defineCommitlintConfig",{enumerable:!0,get:function(){return n.defineCommitlintConfig}});exports.defineEslintConfig=e.defineEslintConfig;exports.defineStylelintConfig=i.defineStylelintConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var l=new Set(["size","componentSize","gap"]),u=new Set(["TSAsExpression","TSSatisfiesExpression","TSTypeAssertion","TSNonNullExpression"]);function a(s){let e=s;for(;e&&u.has(e.type);)e=e.expression;return e?e.type==="Literal"?e.value==="middle"?e:null:e.type==="TemplateLiteral"&&e.expressions.length===0&&e.quasis.length===1&&e.quasis[0].value.cooked==="middle"?e:null:null}var o={create(s){function e(i,t){s.report({node:i,messageId:"useMedium",data:{prop:t},fix:r=>r.replaceText(i,'"medium"')})}return{JSXAttribute(i){const t=i.name?.name;if(typeof t!="string"||!l.has(t))return;const r=i.value?.type==="JSXExpressionContainer"?i.value.expression:i.value,n=a(r);n&&e(n,t)},Property(i){if(i.computed)return;const t=i.key?.type==="Identifier"?i.key.name:i.key?.type==="Literal"&&typeof i.key.value=="string"?i.key.value:null;if(typeof t!="string"||!l.has(t))return;const r=a(i.value);r&&e(r,t)}}},meta:{type:"problem",docs:{description:'Enforce "medium" instead of the legacy "middle" size token.'},fixable:"code",messages:{useMedium:'Use "medium" instead of "middle" for `{{prop}}`.'},schema:[]}},p={rules:{"no-legacy-middle-size":o}};exports.localPlugin=p;
|
package/dist/cjs/vite/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("./config.cjs");let r=require("recast");
|
|
1
|
+
const e=require("./config.cjs");let r=require("recast");exports.defineViteConfig=e.defineViteConfig;Object.defineProperty(exports,"types",{enumerable:!0,get:function(){return r.types}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let c=require("node:path"),g=require("@babel/parser"),l=require("recast");var
|
|
1
|
+
let c=require("node:path"),g=require("@babel/parser"),l=require("recast");var h=[/\.tsx?(?:\?.*)?$/],f=[/node_modules/,/\.d\.ts?(?:\?.*)?$/],p="VEF Auto-Enhance";function i(e,r){return(Array.isArray(e)?e:[e]).some(n=>typeof n=="string"?r.includes(n):n.test(r))}function m(e,r){return(0,l.parse)(e,{sourceFileName:r,parser:{parse:s=>(0,g.parse)(s,{plugins:["jsx","typescript","explicitResourceManagement"],sourceType:"module",tokens:!0})}})}var P=class{plugins=[];options;constructor(e={}){this.options={include:h,exclude:f,logPrefix:p,...e}}shouldProcessFile(e){const{include:r,exclude:s}=this.options;return s&&i(s,e)?!1:!r||i(r,e)}buildTransformInfo(e,r){const s=e.split("/").slice(-3).join("/"),n=m(r,(0,c.basename)(e));return{id:e,fileName:s,code:r,ast:n}}executeTransform(e,r){const s=this.buildTransformInfo(r,e),n=this.getActivePlugins(s);if(n.length===0)return null;const{hasChanges:u,logs:o}=this.runPlugins(n,s);for(const a of o)console.log(a);if(!u)return null;const t=(0,l.print)(s.ast);return{code:t.code,map:t.map||null}}getActivePlugins(e){return this.plugins.filter(r=>r.shouldProcess?r.shouldProcess(e):!0)}runPlugins(e,r){let s=!1;const n=[],{logPrefix:u}=this.options;for(const o of e)try{const t=o.transform(r);t.hasChanges&&(s=!0,console.log(`${u}: Plugin "${o.name}" made changes to ${r.fileName}`)),t.logs&&n.push(...t.logs)}catch(t){console.warn(`${u}: Plugin "${o.name}" failed:`,t)}return{hasChanges:s,logs:n}}registerPlugin(e){this.plugins.push(e)}registerPlugins(e){for(const r of e)this.plugins.push(r)}getRegisteredPlugins(){return this.plugins.map(({name:e,description:r})=>({name:e,description:r}))}transform(e,r){if(!this.shouldProcessFile(r)||this.plugins.length===0)return null;try{return this.executeTransform(e,r)}catch(s){return console.warn(`${this.options.logPrefix}: Error processing ${r}:`,s),null}}};exports.AutoEnhanceCore=P;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const u=require("./core.cjs"),c=require("./plugins/operation-column-width.cjs");let a=require("recast");function s({plugins:o,...t}={}){const r=new u.AutoEnhanceCore(t);return o&&r.registerPlugins(o),{name:"vef-framework:auto-enhance",enforce:"pre",buildStart(){const e=r.getRegisteredPlugins();if(e.length!==0){console.log(`Auto-Enhance: Loaded ${e.length} plugins:`);for(const n of e){const i=n.description?` - ${n.description}`:"";console.log(` - ${n.name}${i}`)}}},transform(e,n){return r.transform(e,n)}}}exports.createAutoEnhancePlugin=s;exports.operationColumnWidthPlugin=c.operationColumnWidthPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const i=require("./operation-column-width.cjs");exports.operationColumnWidthPlugin=i.operationColumnWidthPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let t=require("recast");var v=/[\
|
|
1
|
+
let t=require("recast");var v=/[\u{4E00}-\u{9FFF}\u{3400}-\u{4DBF}\u{FF00}-\u{FFEF}]/u,k="operationColumn",x="OperationButton",C=["@vef-framework-react/components","@vef-framework-react/starter"];function E(s){return C.some(e=>s===e||s.startsWith(`${e}/`))}function I(s){const e=new Map;return(0,t.visit)(s,{visitImportDeclaration(n){const i=n.node.source.value;if(typeof i!="string"||!E(i))return this.traverse(n),!1;const o=n.node.specifiers||[];for(const a of o){if(!t.types.namedTypes.ImportSpecifier.check(a))continue;const{imported:r,local:c}=a;t.types.namedTypes.Identifier.check(r)&&t.types.namedTypes.Identifier.check(c)&&r.name===x&&e.set(c.name,r.name)}return this.traverse(n),!1}}),e}function g(s){let e=0;for(const n of s)e+=v.test(n)?14:8;return e}function O(s){if(s.length===0)return{calculatedWidth:64,buttonCount:0,analysis:"No buttons found, using minimum width"};let e=0;const n=s.length;for(const[o,a]of s.entries()){let r=16;a.hasIcon&&(r+=16,a.textContent&&(r+=8)),a.textContent&&(r+=g(a.textContent));const c=a.hasIcon&&!a.textContent?32:64;r=Math.max(r,c),e+=r,o<n-1&&(e+=8)}e+=16;const i=Math.ceil(e/8)*8;return{calculatedWidth:i,buttonCount:n,analysis:`${n} buttons, calculated: ${e}px, final: ${i}px`}}function S(s,e){const{openingElement:n}=s;if(!t.types.namedTypes.JSXIdentifier.check(n.name))return null;const i=n.name.name;if(!e.has(i))return null;const o={hasIcon:!1,textContent:""},a=n.attributes||[];for(const c of a)if(t.types.namedTypes.JSXAttribute.check(c)&&t.types.namedTypes.JSXIdentifier.check(c.name)&&c.name.name==="icon"){o.hasIcon=!0;break}const r=s.children||[];for(const c of r)t.types.namedTypes.JSXText.check(c)?o.textContent+=c.value.trim():t.types.namedTypes.JSXExpressionContainer.check(c)&&t.types.namedTypes.StringLiteral.check(c.expression)&&(o.textContent+=c.expression.value);return o}function w(s,e){const n=[];return(0,t.visit)(s,{visitJSXElement(i){const o=S(i.node,e);return o&&n.push(o),this.traverse(i),!1}}),n}function M(s){return s.properties.some(e=>{if(!t.types.namedTypes.ObjectProperty.check(e))return!1;const{key:n}=e;return t.types.namedTypes.Identifier.check(n)?n.name==="width":t.types.namedTypes.StringLiteral.check(n)?n.value==="width":!1})}function F(s){return s.properties.find(e=>{if(!t.types.namedTypes.ObjectProperty.check(e)&&!t.types.namedTypes.ObjectMethod.check(e))return!1;const{key:n}=e;return t.types.namedTypes.Identifier.check(n)?n.name==="render":t.types.namedTypes.StringLiteral.check(n)?n.value==="render":!1})}function T(s,e){const{callee:n}=s;return t.types.namedTypes.Identifier.check(n)&&n.name===e}function N(s){const[e]=s.arguments;return t.types.namedTypes.ArrowFunctionExpression.check(e)||t.types.namedTypes.FunctionExpression.check(e)?e.body:null}function A(s){const[e]=s.arguments;if(!t.types.namedTypes.ArrowFunctionExpression.check(e)&&!t.types.namedTypes.FunctionExpression.check(e))return null;const{body:n}=e;if(t.types.namedTypes.ObjectExpression.check(n))return n;if(t.types.namedTypes.BlockStatement.check(n)){for(const i of n.body)if(t.types.namedTypes.ReturnStatement.check(i)&&t.types.namedTypes.ObjectExpression.check(i.argument))return i.argument}return null}function P(s){const e=new Map,n=new Map;return(0,t.visit)(s,{visitFunctionDeclaration(i){const{node:o}=i;return t.types.namedTypes.Identifier.check(o.id)&&e.set(o.id.name,o.body),this.traverse(i),!1},visitVariableDeclarator(i){const{node:o}=i;if(!t.types.namedTypes.Identifier.check(o.id)||!o.init)return this.traverse(i),!1;const a=o.id.name,{init:r}=o;if(t.types.namedTypes.ArrowFunctionExpression.check(r)||t.types.namedTypes.FunctionExpression.check(r))return e.set(a,r.body),this.traverse(i),!1;if(t.types.namedTypes.ObjectExpression.check(r))return n.set(a,r),this.traverse(i),!1;if(t.types.namedTypes.CallExpression.check(r)&&T(r,"useCallback")){const c=N(r);return c&&e.set(a,c),this.traverse(i),!1}if(t.types.namedTypes.CallExpression.check(r)&&T(r,"useMemo")){const c=A(r);return c&&n.set(a,c),this.traverse(i),!1}return this.traverse(i),!1}}),{functionMap:e,objectMap:n}}function j(s,e){if(t.types.namedTypes.ObjectMethod.check(s))return s.body;const{value:n}=s;if(t.types.namedTypes.ArrowFunctionExpression.check(n)||t.types.namedTypes.FunctionExpression.check(n))return n.body;if(t.types.namedTypes.Identifier.check(n)){const i=e.get(n.name);if(i)return i}return null}function J(s){const{openingElement:e}=s;if(t.types.namedTypes.JSXIdentifier.check(e.name))return e.name.name;if(t.types.namedTypes.JSXMemberExpression.check(e.name)){const{object:n,property:i}=e.name,o=t.types.namedTypes.JSXIdentifier.check(n)?n.name:"?",a=t.types.namedTypes.JSXIdentifier.check(i)?i.name:"?";return`${o}.${a}`}return"Unknown"}function X(s){let e=s.parentPath;for(;e;){if(t.types.namedTypes.JSXElement.check(e.node))return J(e.node);e=e.parentPath}return"Unknown"}var W={name:"operation-column-width",description:"Automatically calculate optimal width for operation columns based on button analysis",shouldProcess(s){return s.code.includes(k)},transform(s){const e=I(s.ast);if(e.size===0)return{hasChanges:!1,logs:[]};const{functionMap:n,objectMap:i}=P(s.ast);let o=!1;const a=[];return(0,t.visit)(s.ast,{visitJSXAttribute(r){const c=r.node;if(!t.types.namedTypes.JSXIdentifier.check(c.name)||c.name.name!==k)return this.traverse(r),!1;if(!t.types.namedTypes.JSXExpressionContainer.check(c.value))return this.traverse(r),!1;const{expression:f}=c.value;let u=null;if(t.types.namedTypes.ObjectExpression.check(f)?u=f:t.types.namedTypes.Identifier.check(f)&&(u=i.get(f.name)??null),!u)return this.traverse(r),!1;if(M(u))return this.traverse(r),!1;const p=F(u);if(!p)return this.traverse(r),!1;const l=j(p,n);if(!l)return this.traverse(r),!1;const d=w(l,e);if(d.length===0)return this.traverse(r),!1;const{calculatedWidth:m,analysis:y}=O(d),h=t.types.builders.objectProperty(t.types.builders.identifier("width"),t.types.builders.numericLiteral(m));h.comments=[t.types.builders.commentLine(` Auto-calculated: ${y} `,!0,!1)],u.properties.unshift(h),o=!0;const b=X(r);return a.push(`[${b}]: ${s.fileName}`,` -> Operation column auto-width: ${m}px (${y})`),this.traverse(r),!1}}),{hasChanges:o,logs:a}}};exports.operationColumnWidthPlugin=W;
|
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/*! @vef-framework-react/dev v2.
|
|
2
|
-
import
|
|
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);async function v({projectDir:e,configFile:t,output:n,check:i=!1,augmentTarget:o,onWarn:
|
|
1
|
+
/*! @vef-framework-react/dev v2.8.0 made by Venus | 2026-07-07T01:43:07.854Z */
|
|
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
|
+
`)}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
|
|
|
5
5
|
cd ${e}
|
|
6
|
-
pnpm dev`)}import{resolve as z}from"path";import
|
|
6
|
+
pnpm dev`)}import{resolve as z}from"path";import tt from"process";import x from"consola";import nt from"fs-extra";var{exists:it,readJson:ot,writeFile:rt,writeJson:at}=nt;async function q(e=tt.cwd()){let t=z(e,"package.json"),{default:n}=await import("husky"),i=n();if(i)x.warn(`Skipped husky setup: ${i}`);else for(let[a,d]of Object.entries(b)){let m=z(e,".husky",a);await it(m)||(await rt(m,d),x.success(`Successfully set up ${a} hook`))}let o=await ot(t,{encoding:"utf-8"});o.scripts??={};let{scripts:s}=o,r=!1;for(let[a,d]of Object.entries(U))s[a]||(s[a]=d,r=!0);o["lint-staged"]||(o["lint-staged"]={...j},r=!0),r&&(await at(t,o,{encoding:"utf-8",spaces:2}),x.success("Successfully set up package.json scripts and lint-staged"))}import st from"process";import{execa as ct}from"execa";async function B(e=st.cwd()){await E(),await ct({cwd:e,stdio:"inherit"})("pnpm",["update","@vef-framework-react/*"])}var pt=w();u.name("vef").description(ft.magenta("VEF Framework CLI")).version(pt).action(()=>u.help());u.command("init").description("Scaffold a new VEF project in a new directory").argument("[name]","Project directory name (also used as the npm package name)").option("-t, --title <title>","Human-readable app title").option("--api-url <url>","Dev API base URL, written to .env.development").action((e,t)=>Y({name:e,title:t.title,apiUrl:t.apiUrl}));u.command("prepare").description("Install git hooks and lint-staged, and seed package.json scripts").action(()=>q());u.command("update").description("Update @vef-framework-react/* dependencies within their semver range").action(()=>B());u.command("gen:dictionary-keys").description("Generate the DictionaryKey union type from the project's code-generation config").option("-c, --config <file>","Path to code-generation.config.ts (relative to cwd or absolute)").option("-o, --output <file>","Output file path (overrides config.dictionaryKeys.output)").option("--check","Exit non-zero if the generated file would change (CI guard)").action(e=>I(e));try{await u.parseAsync()}catch(e){$(e)}
|
|
@@ -3,80 +3,83 @@ import { loadCodeGenerationConfig as p } from "./load-config.js";
|
|
|
3
3
|
import { renderDictionaryKeysFile as E } from "./render.js";
|
|
4
4
|
import { randomBytes as T } from "node:crypto";
|
|
5
5
|
import { constants as f } from "node:fs";
|
|
6
|
-
import { chmod as O, lstat as v, mkdir as K, open as _, readFile as $, rename as
|
|
7
|
-
import { dirname as
|
|
6
|
+
import { chmod as O, lstat as v, mkdir as K, open as _, readFile as $, rename as A, unlink as C } from "node:fs/promises";
|
|
7
|
+
import { dirname as F, isAbsolute as h, relative as k, resolve as N } from "node:path";
|
|
8
8
|
var S = "src/types/dictionary.gen.ts", D = 3e4, g = /^[\w.-]+$/, L = "letters, digits, underscore, dot, hyphen", x = (t) => console.warn(t);
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
function P(t, e) {
|
|
10
|
+
return t.key < e.key ? -1 : t.key > e.key ? 1 : 0;
|
|
11
|
+
}
|
|
12
|
+
async function z({ projectDir: t, configFile: e, output: n, check: i = !1, augmentTarget: r, onWarn: c = x }) {
|
|
13
|
+
const { config: o, configPath: s } = await p({
|
|
11
14
|
projectDir: t,
|
|
12
15
|
configFile: e
|
|
13
16
|
});
|
|
14
17
|
if (!o.dictionaryKeys)
|
|
15
|
-
throw new a(`Code generation config at ${
|
|
16
|
-
const { dictionaryKeys: l } = o, m = await
|
|
17
|
-
|
|
18
|
-
const u = I(m,
|
|
19
|
-
u.length === 0 &&
|
|
20
|
-
const y = R(t,
|
|
21
|
-
configFile: k(t,
|
|
18
|
+
throw new a(`Code generation config at ${s} has no \`dictionaryKeys\` block.`);
|
|
19
|
+
const { dictionaryKeys: l } = o, m = await U(l.fetchDictionaryKeys, l.timeout ?? D);
|
|
20
|
+
b(m);
|
|
21
|
+
const u = I(m, c);
|
|
22
|
+
u.length === 0 && c("`fetchDictionaryKeys` returned no entries; the generated file will declare `DictionaryKey = never`.");
|
|
23
|
+
const y = R(t, n ?? l.output ?? S), d = E(u, {
|
|
24
|
+
configFile: k(t, s),
|
|
22
25
|
augmentTarget: r
|
|
23
|
-
}), w = await
|
|
24
|
-
return w && !
|
|
26
|
+
}), w = await Y(y) !== d;
|
|
27
|
+
return w && !i && (await W(y), await G(y, d)), {
|
|
25
28
|
outputPath: y,
|
|
26
29
|
keyCount: u.length,
|
|
27
30
|
changed: w
|
|
28
31
|
};
|
|
29
32
|
}
|
|
30
|
-
async function
|
|
33
|
+
async function U(t, e) {
|
|
31
34
|
if (e <= 0)
|
|
32
35
|
return await t();
|
|
33
|
-
let
|
|
36
|
+
let n;
|
|
34
37
|
try {
|
|
35
|
-
return await Promise.race([t(), new Promise((
|
|
36
|
-
|
|
38
|
+
return await Promise.race([t(), new Promise((i, r) => {
|
|
39
|
+
n = setTimeout(() => r(new Error(`fetchDictionaryKeys timed out after ${e}ms.`)), e);
|
|
37
40
|
})]);
|
|
38
41
|
} finally {
|
|
39
|
-
|
|
42
|
+
n && clearTimeout(n);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
|
-
function
|
|
45
|
+
function b(t) {
|
|
43
46
|
for (const e of t)
|
|
44
47
|
if (typeof e.key != "string" || !g.test(e.key))
|
|
45
48
|
throw new a(`Invalid dictionary key ${JSON.stringify(e.key)}. Keys must match ${g} (${L}).`);
|
|
46
49
|
}
|
|
47
50
|
function I(t, e) {
|
|
48
|
-
const
|
|
49
|
-
for (const
|
|
50
|
-
const r =
|
|
51
|
+
const n = /* @__PURE__ */ new Map();
|
|
52
|
+
for (const i of t) {
|
|
53
|
+
const r = n.get(i.key);
|
|
51
54
|
if (!r) {
|
|
52
|
-
|
|
55
|
+
n.set(i.key, i);
|
|
53
56
|
continue;
|
|
54
57
|
}
|
|
55
|
-
r.comment !==
|
|
58
|
+
r.comment !== i.comment && e(`Duplicate dictionary key "${i.key}" with conflicting comments; keeping the first occurrence.`);
|
|
56
59
|
}
|
|
57
|
-
return
|
|
60
|
+
return n.values().toArray().toSorted(P);
|
|
58
61
|
}
|
|
59
62
|
function R(t, e) {
|
|
60
63
|
if (h(e))
|
|
61
64
|
throw new a(`Output path must be relative to project root; absolute paths are rejected: ${e}`);
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
65
|
+
const n = N(t, e), i = k(t, n);
|
|
66
|
+
if (i.startsWith("..") || h(i))
|
|
64
67
|
throw new a(`Output path escapes project root: ${e}. Must stay within ${t}.`);
|
|
65
|
-
return
|
|
68
|
+
return n;
|
|
66
69
|
}
|
|
67
70
|
async function W(t) {
|
|
68
71
|
let e;
|
|
69
72
|
try {
|
|
70
73
|
e = await v(t);
|
|
71
|
-
} catch (
|
|
72
|
-
if (
|
|
74
|
+
} catch (n) {
|
|
75
|
+
if (n.code === "ENOENT")
|
|
73
76
|
return;
|
|
74
|
-
throw
|
|
77
|
+
throw n;
|
|
75
78
|
}
|
|
76
79
|
if (e.isSymbolicLink())
|
|
77
80
|
throw new a(`Refusing to overwrite symlink at output path: ${t}. Delete the symlink and rerun generation if this is intentional.`);
|
|
78
81
|
}
|
|
79
|
-
async function
|
|
82
|
+
async function Y(t) {
|
|
80
83
|
try {
|
|
81
84
|
return await $(t, "utf-8");
|
|
82
85
|
} catch (e) {
|
|
@@ -85,22 +88,22 @@ async function b(t) {
|
|
|
85
88
|
throw e;
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
|
-
async function
|
|
89
|
-
await K(
|
|
90
|
-
const
|
|
91
|
+
async function G(t, e) {
|
|
92
|
+
await K(F(t), { recursive: !0 });
|
|
93
|
+
const n = T(6).toString("hex"), i = `${t}.${n}.tmp`, r = f.O_NOFOLLOW ?? 0, c = f.O_WRONLY | f.O_CREAT | f.O_EXCL | r, o = await _(i, c, 384);
|
|
91
94
|
try {
|
|
92
95
|
await o.writeFile(e, "utf-8");
|
|
93
96
|
} finally {
|
|
94
97
|
await o.close();
|
|
95
98
|
}
|
|
96
99
|
try {
|
|
97
|
-
await
|
|
98
|
-
} catch (
|
|
99
|
-
throw await
|
|
100
|
-
}),
|
|
100
|
+
await A(i, t);
|
|
101
|
+
} catch (s) {
|
|
102
|
+
throw await C(i).catch(() => {
|
|
103
|
+
}), s;
|
|
101
104
|
}
|
|
102
105
|
await O(t, 420);
|
|
103
106
|
}
|
|
104
107
|
export {
|
|
105
|
-
|
|
108
|
+
z as generateDictionaryKeys
|
|
106
109
|
};
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import "./errors.js";
|
|
2
|
-
import "./render.js";
|
|
3
|
-
import "./core.js";
|
|
4
|
-
import "./types.js";
|
|
1
|
+
import { CodeGenerationValidationError as o } from "./errors.js";
|
|
2
|
+
import { DICTIONARY_AUGMENT_TARGET as i, renderDictionaryKeysFile as n } from "./render.js";
|
|
3
|
+
import { generateDictionaryKeys as m } from "./core.js";
|
|
4
|
+
import { defineCodeGenerationConfig as f } from "./types.js";
|
|
5
|
+
export {
|
|
6
|
+
o as CodeGenerationValidationError,
|
|
7
|
+
i as DICTIONARY_AUGMENT_TARGET,
|
|
8
|
+
f as defineCodeGenerationConfig,
|
|
9
|
+
m as generateDictionaryKeys,
|
|
10
|
+
n as renderDictionaryKeysFile
|
|
11
|
+
};
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import "./dictionary/errors.js";
|
|
2
|
-
import "./dictionary/render.js";
|
|
3
|
-
import "./dictionary/core.js";
|
|
4
|
-
import "./dictionary/types.js";
|
|
1
|
+
import { CodeGenerationValidationError as o } from "./dictionary/errors.js";
|
|
2
|
+
import { DICTIONARY_AUGMENT_TARGET as i, renderDictionaryKeysFile as n } from "./dictionary/render.js";
|
|
3
|
+
import { generateDictionaryKeys as m } from "./dictionary/core.js";
|
|
4
|
+
import { defineCodeGenerationConfig as f } from "./dictionary/types.js";
|
|
5
|
+
export {
|
|
6
|
+
o as CodeGenerationValidationError,
|
|
7
|
+
i as DICTIONARY_AUGMENT_TARGET,
|
|
8
|
+
f as defineCodeGenerationConfig,
|
|
9
|
+
m as generateDictionaryKeys,
|
|
10
|
+
n as renderDictionaryKeysFile
|
|
11
|
+
};
|
package/dist/es/lint/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import "./commitlint.js";
|
|
2
|
-
import "./eslint.js";
|
|
3
|
-
import "./stylelint.js";
|
|
1
|
+
import { defineCommitlintConfig as o } from "./commitlint.js";
|
|
2
|
+
import { defineEslintConfig as n } from "./eslint.js";
|
|
3
|
+
import { defineStylelintConfig as e } from "./stylelint.js";
|
|
4
|
+
export {
|
|
5
|
+
o as defineCommitlintConfig,
|
|
6
|
+
n as defineEslintConfig,
|
|
7
|
+
e as defineStylelintConfig
|
|
8
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var l = /* @__PURE__ */ new Set([
|
|
2
2
|
"size",
|
|
3
3
|
"componentSize",
|
|
4
4
|
"gap"
|
|
@@ -8,35 +8,38 @@ var n = /* @__PURE__ */ new Set([
|
|
|
8
8
|
"TSTypeAssertion",
|
|
9
9
|
"TSNonNullExpression"
|
|
10
10
|
]);
|
|
11
|
-
function s
|
|
12
|
-
|
|
11
|
+
function a(s) {
|
|
12
|
+
let e = s;
|
|
13
|
+
for (; e && u.has(e.type); )
|
|
14
|
+
e = e.expression;
|
|
15
|
+
return e ? e.type === "Literal" ? e.value === "middle" ? e : null : e.type === "TemplateLiteral" && e.expressions.length === 0 && e.quasis.length === 1 && e.quasis[0].value.cooked === "middle" ? e : null : null;
|
|
13
16
|
}
|
|
14
|
-
var
|
|
15
|
-
create(
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
node:
|
|
17
|
+
var o = {
|
|
18
|
+
create(s) {
|
|
19
|
+
function e(t, i) {
|
|
20
|
+
s.report({
|
|
21
|
+
node: t,
|
|
19
22
|
messageId: "useMedium",
|
|
20
23
|
data: { prop: i },
|
|
21
|
-
fix: (r) => r.replaceText(
|
|
24
|
+
fix: (r) => r.replaceText(t, '"medium"')
|
|
22
25
|
});
|
|
23
26
|
}
|
|
24
27
|
return {
|
|
25
|
-
JSXAttribute(
|
|
26
|
-
const i =
|
|
27
|
-
if (typeof i != "string" || !
|
|
28
|
+
JSXAttribute(t) {
|
|
29
|
+
const i = t.name?.name;
|
|
30
|
+
if (typeof i != "string" || !l.has(i))
|
|
28
31
|
return;
|
|
29
|
-
const r =
|
|
30
|
-
|
|
32
|
+
const r = t.value?.type === "JSXExpressionContainer" ? t.value.expression : t.value, n = a(r);
|
|
33
|
+
n && e(n, i);
|
|
31
34
|
},
|
|
32
|
-
Property(
|
|
33
|
-
if (
|
|
35
|
+
Property(t) {
|
|
36
|
+
if (t.computed)
|
|
34
37
|
return;
|
|
35
|
-
const i =
|
|
36
|
-
if (typeof i != "string" || !
|
|
38
|
+
const i = t.key?.type === "Identifier" ? t.key.name : t.key?.type === "Literal" && typeof t.key.value == "string" ? t.key.value : null;
|
|
39
|
+
if (typeof i != "string" || !l.has(i))
|
|
37
40
|
return;
|
|
38
|
-
const r =
|
|
39
|
-
r &&
|
|
41
|
+
const r = a(t.value);
|
|
42
|
+
r && e(r, i);
|
|
40
43
|
}
|
|
41
44
|
};
|
|
42
45
|
},
|
|
@@ -47,7 +50,7 @@ var p = {
|
|
|
47
50
|
messages: { useMedium: 'Use "medium" instead of "middle" for `{{prop}}`.' },
|
|
48
51
|
schema: []
|
|
49
52
|
}
|
|
50
|
-
},
|
|
53
|
+
}, p = { rules: { "no-legacy-middle-size": o } };
|
|
51
54
|
export {
|
|
52
|
-
|
|
55
|
+
p as localPlugin
|
|
53
56
|
};
|
package/dist/es/vite/index.js
CHANGED
|
@@ -30,31 +30,9 @@ var x = class {
|
|
|
30
30
|
...r
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
-
registerPlugin(r) {
|
|
34
|
-
this.plugins.push(r);
|
|
35
|
-
}
|
|
36
|
-
registerPlugins(r) {
|
|
37
|
-
for (const s of r)
|
|
38
|
-
this.plugins.push(s);
|
|
39
|
-
}
|
|
40
|
-
getRegisteredPlugins() {
|
|
41
|
-
return this.plugins.map(({ name: r, description: s }) => ({
|
|
42
|
-
name: r,
|
|
43
|
-
description: s
|
|
44
|
-
}));
|
|
45
|
-
}
|
|
46
|
-
transform(r, s) {
|
|
47
|
-
if (!this.shouldProcessFile(s) || this.plugins.length === 0)
|
|
48
|
-
return null;
|
|
49
|
-
try {
|
|
50
|
-
return this.executeTransform(r, s);
|
|
51
|
-
} catch (e) {
|
|
52
|
-
return console.warn(`${this.options.logPrefix}: Error processing ${s}:`, e), null;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
33
|
shouldProcessFile(r) {
|
|
56
34
|
const { include: s, exclude: e } = this.options;
|
|
57
|
-
return
|
|
35
|
+
return e && u(e, r) ? !1 : !s || u(s, r);
|
|
58
36
|
}
|
|
59
37
|
buildTransformInfo(r, s) {
|
|
60
38
|
const e = r.split("/").slice(-3).join("/"), n = P(s, a(r));
|
|
@@ -98,6 +76,28 @@ var x = class {
|
|
|
98
76
|
logs: n
|
|
99
77
|
};
|
|
100
78
|
}
|
|
79
|
+
registerPlugin(r) {
|
|
80
|
+
this.plugins.push(r);
|
|
81
|
+
}
|
|
82
|
+
registerPlugins(r) {
|
|
83
|
+
for (const s of r)
|
|
84
|
+
this.plugins.push(s);
|
|
85
|
+
}
|
|
86
|
+
getRegisteredPlugins() {
|
|
87
|
+
return this.plugins.map(({ name: r, description: s }) => ({
|
|
88
|
+
name: r,
|
|
89
|
+
description: s
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
transform(r, s) {
|
|
93
|
+
if (!this.shouldProcessFile(s) || this.plugins.length === 0)
|
|
94
|
+
return null;
|
|
95
|
+
try {
|
|
96
|
+
return this.executeTransform(r, s);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
return console.warn(`${this.options.logPrefix}: Error processing ${s}:`, e), null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
101
|
};
|
|
102
102
|
export {
|
|
103
103
|
x as AutoEnhanceCore
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AutoEnhanceCore as s } from "./core.js";
|
|
2
|
-
import "./plugins/operation-column-width.js";
|
|
2
|
+
import { operationColumnWidthPlugin as u } from "./plugins/operation-column-width.js";
|
|
3
3
|
import { types as l } from "recast";
|
|
4
4
|
function f({ plugins: r, ...t } = {}) {
|
|
5
5
|
const o = new s(t);
|
|
@@ -23,5 +23,6 @@ function f({ plugins: r, ...t } = {}) {
|
|
|
23
23
|
}
|
|
24
24
|
export {
|
|
25
25
|
f as createAutoEnhancePlugin,
|
|
26
|
+
u as operationColumnWidthPlugin,
|
|
26
27
|
l as types
|
|
27
28
|
};
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { types as t, visit as l } from "recast";
|
|
2
|
-
var x = /[\
|
|
2
|
+
var x = /[\u{4E00}-\u{9FFF}\u{3400}-\u{4DBF}\u{FF00}-\u{FFEF}]/u, T = "operationColumn", E = "OperationButton", I = ["@vef-framework-react/components", "@vef-framework-react/starter"];
|
|
3
3
|
function C(r) {
|
|
4
4
|
return I.some((e) => r === e || r.startsWith(`${e}/`));
|
|
5
5
|
}
|
|
6
6
|
function g(r) {
|
|
7
7
|
const e = /* @__PURE__ */ new Map();
|
|
8
8
|
return l(r, { visitImportDeclaration(n) {
|
|
9
|
-
const
|
|
10
|
-
if (typeof
|
|
9
|
+
const i = n.node.source.value;
|
|
10
|
+
if (typeof i != "string" || !C(i))
|
|
11
11
|
return this.traverse(n), !1;
|
|
12
|
-
|
|
12
|
+
const o = n.node.specifiers || [];
|
|
13
|
+
for (const a of o) {
|
|
13
14
|
if (!t.namedTypes.ImportSpecifier.check(a))
|
|
14
15
|
continue;
|
|
15
|
-
const { imported:
|
|
16
|
-
t.namedTypes.Identifier.check(
|
|
16
|
+
const { imported: s, local: c } = a;
|
|
17
|
+
t.namedTypes.Identifier.check(s) && t.namedTypes.Identifier.check(c) && s.name === E && e.set(c.name, s.name);
|
|
17
18
|
}
|
|
18
19
|
return this.traverse(n), !1;
|
|
19
20
|
} }), e;
|
|
@@ -33,45 +34,46 @@ function S(r) {
|
|
|
33
34
|
};
|
|
34
35
|
let e = 0;
|
|
35
36
|
const n = r.length;
|
|
36
|
-
for (const [
|
|
37
|
-
let
|
|
38
|
-
|
|
39
|
-
const c =
|
|
40
|
-
|
|
37
|
+
for (const [o, a] of r.entries()) {
|
|
38
|
+
let s = 16;
|
|
39
|
+
a.hasIcon && (s += 16, a.textContent && (s += 8)), a.textContent && (s += O(a.textContent));
|
|
40
|
+
const c = a.hasIcon && !a.textContent ? 32 : 64;
|
|
41
|
+
s = Math.max(s, c), e += s, o < n - 1 && (e += 8);
|
|
41
42
|
}
|
|
42
43
|
e += 16;
|
|
43
|
-
const
|
|
44
|
+
const i = Math.ceil(e / 8) * 8;
|
|
44
45
|
return {
|
|
45
|
-
calculatedWidth:
|
|
46
|
+
calculatedWidth: i,
|
|
46
47
|
buttonCount: n,
|
|
47
|
-
analysis: `${n} buttons, calculated: ${e}px, final: ${
|
|
48
|
+
analysis: `${n} buttons, calculated: ${e}px, final: ${i}px`
|
|
48
49
|
};
|
|
49
50
|
}
|
|
50
51
|
function w(r, e) {
|
|
51
52
|
const { openingElement: n } = r;
|
|
52
53
|
if (!t.namedTypes.JSXIdentifier.check(n.name))
|
|
53
54
|
return null;
|
|
54
|
-
const
|
|
55
|
-
if (!e.has(
|
|
55
|
+
const i = n.name.name;
|
|
56
|
+
if (!e.has(i))
|
|
56
57
|
return null;
|
|
57
|
-
const
|
|
58
|
+
const o = {
|
|
58
59
|
hasIcon: !1,
|
|
59
60
|
textContent: ""
|
|
60
|
-
};
|
|
61
|
-
for (const
|
|
62
|
-
if (t.namedTypes.JSXAttribute.check(
|
|
63
|
-
|
|
61
|
+
}, a = n.attributes || [];
|
|
62
|
+
for (const c of a)
|
|
63
|
+
if (t.namedTypes.JSXAttribute.check(c) && t.namedTypes.JSXIdentifier.check(c.name) && c.name.name === "icon") {
|
|
64
|
+
o.hasIcon = !0;
|
|
64
65
|
break;
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const s = r.children || [];
|
|
68
|
+
for (const c of s)
|
|
69
|
+
t.namedTypes.JSXText.check(c) ? o.textContent += c.value.trim() : t.namedTypes.JSXExpressionContainer.check(c) && t.namedTypes.StringLiteral.check(c.expression) && (o.textContent += c.expression.value);
|
|
70
|
+
return o;
|
|
69
71
|
}
|
|
70
72
|
function M(r, e) {
|
|
71
73
|
const n = [];
|
|
72
|
-
return l(r, { visitJSXElement(
|
|
73
|
-
const
|
|
74
|
-
return
|
|
74
|
+
return l(r, { visitJSXElement(i) {
|
|
75
|
+
const o = w(i.node, e);
|
|
76
|
+
return o && n.push(o), this.traverse(i), !1;
|
|
75
77
|
} }), n;
|
|
76
78
|
}
|
|
77
79
|
function F(r) {
|
|
@@ -106,37 +108,37 @@ function j(r) {
|
|
|
106
108
|
if (t.namedTypes.ObjectExpression.check(n))
|
|
107
109
|
return n;
|
|
108
110
|
if (t.namedTypes.BlockStatement.check(n)) {
|
|
109
|
-
for (const
|
|
110
|
-
if (t.namedTypes.ReturnStatement.check(
|
|
111
|
-
return
|
|
111
|
+
for (const i of n.body)
|
|
112
|
+
if (t.namedTypes.ReturnStatement.check(i) && t.namedTypes.ObjectExpression.check(i.argument))
|
|
113
|
+
return i.argument;
|
|
112
114
|
}
|
|
113
115
|
return null;
|
|
114
116
|
}
|
|
115
117
|
function J(r) {
|
|
116
118
|
const e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
117
119
|
return l(r, {
|
|
118
|
-
visitFunctionDeclaration(
|
|
119
|
-
const { node:
|
|
120
|
-
return t.namedTypes.Identifier.check(
|
|
120
|
+
visitFunctionDeclaration(i) {
|
|
121
|
+
const { node: o } = i;
|
|
122
|
+
return t.namedTypes.Identifier.check(o.id) && e.set(o.id.name, o.body), this.traverse(i), !1;
|
|
121
123
|
},
|
|
122
|
-
visitVariableDeclarator(
|
|
123
|
-
const { node:
|
|
124
|
-
if (!t.namedTypes.Identifier.check(
|
|
125
|
-
return this.traverse(
|
|
126
|
-
const
|
|
127
|
-
if (t.namedTypes.ArrowFunctionExpression.check(
|
|
128
|
-
return e.set(
|
|
129
|
-
if (t.namedTypes.ObjectExpression.check(
|
|
130
|
-
return n.set(
|
|
131
|
-
if (t.namedTypes.CallExpression.check(
|
|
132
|
-
const c = A(
|
|
133
|
-
return c && e.set(
|
|
124
|
+
visitVariableDeclarator(i) {
|
|
125
|
+
const { node: o } = i;
|
|
126
|
+
if (!t.namedTypes.Identifier.check(o.id) || !o.init)
|
|
127
|
+
return this.traverse(i), !1;
|
|
128
|
+
const a = o.id.name, { init: s } = o;
|
|
129
|
+
if (t.namedTypes.ArrowFunctionExpression.check(s) || t.namedTypes.FunctionExpression.check(s))
|
|
130
|
+
return e.set(a, s.body), this.traverse(i), !1;
|
|
131
|
+
if (t.namedTypes.ObjectExpression.check(s))
|
|
132
|
+
return n.set(a, s), this.traverse(i), !1;
|
|
133
|
+
if (t.namedTypes.CallExpression.check(s) && b(s, "useCallback")) {
|
|
134
|
+
const c = A(s);
|
|
135
|
+
return c && e.set(a, c), this.traverse(i), !1;
|
|
134
136
|
}
|
|
135
|
-
if (t.namedTypes.CallExpression.check(
|
|
136
|
-
const c = j(
|
|
137
|
-
return c && n.set(
|
|
137
|
+
if (t.namedTypes.CallExpression.check(s) && b(s, "useMemo")) {
|
|
138
|
+
const c = j(s);
|
|
139
|
+
return c && n.set(a, c), this.traverse(i), !1;
|
|
138
140
|
}
|
|
139
|
-
return this.traverse(
|
|
141
|
+
return this.traverse(i), !1;
|
|
140
142
|
}
|
|
141
143
|
}), {
|
|
142
144
|
functionMap: e,
|
|
@@ -150,9 +152,9 @@ function P(r, e) {
|
|
|
150
152
|
if (t.namedTypes.ArrowFunctionExpression.check(n) || t.namedTypes.FunctionExpression.check(n))
|
|
151
153
|
return n.body;
|
|
152
154
|
if (t.namedTypes.Identifier.check(n)) {
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
155
|
-
return
|
|
155
|
+
const i = e.get(n.name);
|
|
156
|
+
if (i)
|
|
157
|
+
return i;
|
|
156
158
|
}
|
|
157
159
|
return null;
|
|
158
160
|
}
|
|
@@ -161,8 +163,8 @@ function X(r) {
|
|
|
161
163
|
if (t.namedTypes.JSXIdentifier.check(e.name))
|
|
162
164
|
return e.name.name;
|
|
163
165
|
if (t.namedTypes.JSXMemberExpression.check(e.name)) {
|
|
164
|
-
const { object: n, property:
|
|
165
|
-
return `${
|
|
166
|
+
const { object: n, property: i } = e.name, o = t.namedTypes.JSXIdentifier.check(n) ? n.name : "?", a = t.namedTypes.JSXIdentifier.check(i) ? i.name : "?";
|
|
167
|
+
return `${o}.${a}`;
|
|
166
168
|
}
|
|
167
169
|
return "Unknown";
|
|
168
170
|
}
|
|
@@ -188,37 +190,37 @@ var $ = {
|
|
|
188
190
|
hasChanges: !1,
|
|
189
191
|
logs: []
|
|
190
192
|
};
|
|
191
|
-
const { functionMap: n, objectMap:
|
|
192
|
-
let
|
|
193
|
-
const
|
|
194
|
-
return l(r.ast, { visitJSXAttribute(
|
|
195
|
-
const c =
|
|
193
|
+
const { functionMap: n, objectMap: i } = J(r.ast);
|
|
194
|
+
let o = !1;
|
|
195
|
+
const a = [];
|
|
196
|
+
return l(r.ast, { visitJSXAttribute(s) {
|
|
197
|
+
const c = s.node;
|
|
196
198
|
if (!t.namedTypes.JSXIdentifier.check(c.name) || c.name.name !== T)
|
|
197
|
-
return this.traverse(
|
|
199
|
+
return this.traverse(s), !1;
|
|
198
200
|
if (!t.namedTypes.JSXExpressionContainer.check(c.value))
|
|
199
|
-
return this.traverse(
|
|
201
|
+
return this.traverse(s), !1;
|
|
200
202
|
const { expression: f } = c.value;
|
|
201
203
|
let u = null;
|
|
202
|
-
if (t.namedTypes.ObjectExpression.check(f) ? u = f : t.namedTypes.Identifier.check(f) && (u =
|
|
203
|
-
return this.traverse(
|
|
204
|
+
if (t.namedTypes.ObjectExpression.check(f) ? u = f : t.namedTypes.Identifier.check(f) && (u = i.get(f.name) ?? null), !u)
|
|
205
|
+
return this.traverse(s), !1;
|
|
204
206
|
if (F(u))
|
|
205
|
-
return this.traverse(
|
|
207
|
+
return this.traverse(s), !1;
|
|
206
208
|
const d = N(u);
|
|
207
209
|
if (!d)
|
|
208
|
-
return this.traverse(
|
|
210
|
+
return this.traverse(s), !1;
|
|
209
211
|
const m = P(d, n);
|
|
210
212
|
if (!m)
|
|
211
|
-
return this.traverse(
|
|
213
|
+
return this.traverse(s), !1;
|
|
212
214
|
const p = M(m, e);
|
|
213
215
|
if (p.length === 0)
|
|
214
|
-
return this.traverse(
|
|
216
|
+
return this.traverse(s), !1;
|
|
215
217
|
const { calculatedWidth: h, analysis: y } = S(p), k = t.builders.objectProperty(t.builders.identifier("width"), t.builders.numericLiteral(h));
|
|
216
|
-
k.comments = [t.builders.commentLine(` Auto-calculated: ${y} `, !0, !1)], u.properties.unshift(k),
|
|
217
|
-
const v = W(
|
|
218
|
-
return
|
|
218
|
+
k.comments = [t.builders.commentLine(` Auto-calculated: ${y} `, !0, !1)], u.properties.unshift(k), o = !0;
|
|
219
|
+
const v = W(s);
|
|
220
|
+
return a.push(`[${v}]: ${r.fileName}`, ` -> Operation column auto-width: ${h}px (${y})`), this.traverse(s), !1;
|
|
219
221
|
} }), {
|
|
220
|
-
hasChanges:
|
|
221
|
-
logs:
|
|
222
|
+
hasChanges: o,
|
|
223
|
+
logs: a
|
|
222
224
|
};
|
|
223
225
|
}
|
|
224
226
|
};
|
|
@@ -8,13 +8,13 @@ export declare class AutoEnhanceCore {
|
|
|
8
8
|
private plugins;
|
|
9
9
|
private options;
|
|
10
10
|
constructor(options?: Except<AutoEnhanceOptions, "plugins">);
|
|
11
|
-
registerPlugin(plugin: AutoEnhancePlugin): void;
|
|
12
|
-
registerPlugins(plugins: AutoEnhancePlugin[]): void;
|
|
13
|
-
getRegisteredPlugins(): Array<Pick<AutoEnhancePlugin, "name" | "description">>;
|
|
14
|
-
transform(code: string, id: string): TransformResult | null;
|
|
15
11
|
private shouldProcessFile;
|
|
16
12
|
private buildTransformInfo;
|
|
17
13
|
private executeTransform;
|
|
18
14
|
private getActivePlugins;
|
|
19
15
|
private runPlugins;
|
|
16
|
+
registerPlugin(plugin: AutoEnhancePlugin): void;
|
|
17
|
+
registerPlugins(plugins: AutoEnhancePlugin[]): void;
|
|
18
|
+
getRegisteredPlugins(): Array<Pick<AutoEnhancePlugin, "name" | "description">>;
|
|
19
|
+
transform(code: string, id: string): TransformResult | null;
|
|
20
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vef-framework-react/dev",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Dev tools for VEF framework",
|
|
6
6
|
"keywords": [
|
|
@@ -46,49 +46,49 @@
|
|
|
46
46
|
"@babel/core": "^7.29.7",
|
|
47
47
|
"@babel/parser": "^7.29.7",
|
|
48
48
|
"@babel/traverse": "^7.29.7",
|
|
49
|
-
"@coldsmirk/commitlint-config": "^0.
|
|
50
|
-
"@coldsmirk/eslint-config": "^0.
|
|
51
|
-
"@coldsmirk/stylelint-config": "^0.
|
|
49
|
+
"@coldsmirk/commitlint-config": "^0.4.1",
|
|
50
|
+
"@coldsmirk/eslint-config": "^0.4.1",
|
|
51
|
+
"@coldsmirk/stylelint-config": "^0.4.1",
|
|
52
52
|
"@emotion/babel-plugin": "^11.13.5",
|
|
53
53
|
"@rolldown/plugin-babel": "^0.2.3",
|
|
54
54
|
"@svgr/plugin-svgo": "^8.1.0",
|
|
55
|
-
"@tanstack/eslint-plugin-query": "^5.101.
|
|
55
|
+
"@tanstack/eslint-plugin-query": "^5.101.2",
|
|
56
56
|
"@tanstack/eslint-plugin-router": "^1.162.0",
|
|
57
|
-
"@tanstack/router-plugin": "^1.168.
|
|
58
|
-
"@vitejs/plugin-react": "^6.0.
|
|
57
|
+
"@tanstack/router-plugin": "^1.168.19",
|
|
58
|
+
"@vitejs/plugin-react": "^6.0.3",
|
|
59
59
|
"babel-plugin-react-compiler": "1.0.0",
|
|
60
60
|
"chalk": "^5.6.2",
|
|
61
61
|
"commander": "^15.0.0",
|
|
62
62
|
"consola": "^3.4.2",
|
|
63
63
|
"dotenv": "^17.4.2",
|
|
64
64
|
"execa": "^9.6.1",
|
|
65
|
-
"fs-extra": "^11.3.
|
|
65
|
+
"fs-extra": "^11.3.6",
|
|
66
66
|
"html-minifier-terser": "^7.2.0",
|
|
67
67
|
"jiti": "^2.7.0",
|
|
68
68
|
"jotai-babel": "^0.2.0",
|
|
69
|
-
"ora": "^9.4.
|
|
69
|
+
"ora": "^9.4.1",
|
|
70
70
|
"prompts": "^2.4.2",
|
|
71
71
|
"radashi": "^12.9.0",
|
|
72
|
-
"recast": "^0.23.
|
|
72
|
+
"recast": "^0.23.12",
|
|
73
73
|
"sass-embedded": "^1.100.0",
|
|
74
74
|
"unplugin-config": "^0.1.5",
|
|
75
75
|
"unplugin-icons": "^23.0.1",
|
|
76
|
-
"vite-plugin-eslint2": "^5.
|
|
76
|
+
"vite-plugin-eslint2": "^5.3.0",
|
|
77
77
|
"vite-plugin-inspect": "^11.4.1",
|
|
78
|
-
"vite-plugin-stylelint": "^6.
|
|
78
|
+
"vite-plugin-stylelint": "^6.3.0",
|
|
79
79
|
"vite-plugin-svgr": "^5.2.0"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@commitlint/cli": "^21.0
|
|
82
|
+
"@commitlint/cli": "^21.2.0",
|
|
83
83
|
"@types/html-minifier-terser": "^7.0.2",
|
|
84
84
|
"@types/prompts": "^2.4.9",
|
|
85
|
-
"eslint": "^10.
|
|
85
|
+
"eslint": "^10.6.0",
|
|
86
86
|
"husky": "^9.1.7",
|
|
87
|
-
"lint-staged": "^17.0.
|
|
88
|
-
"stylelint": "^17.
|
|
87
|
+
"lint-staged": "^17.0.8",
|
|
88
|
+
"stylelint": "^17.14.0",
|
|
89
89
|
"tsup": "^8.5.1",
|
|
90
90
|
"type-fest": "^5.7.0",
|
|
91
|
-
"vite": "^8.
|
|
91
|
+
"vite": "^8.1.3"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"@commitlint/cli": "^21.0.0",
|