@jwn-js/vite-plugin-schema 1.0.7 → 1.0.9
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/decorators/index.d.ts +2 -1
- package/decorators/index.js +1 -1
- package/decorators/index.mjs +1 -1
- package/package.json +5 -2
- package/plugin/index.d.ts +1 -0
- package/plugin/index.js +2 -2
- package/plugin/index.mjs +2 -2
package/decorators/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
declare const routeController: (controller: string) => (inputClass: any) => void;
|
|
2
|
+
declare const routeBinding: (controller: string) => (inputClass: any) => void;
|
|
2
3
|
declare const routeAction: (action: string) => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) => void;
|
|
3
4
|
|
|
4
|
-
export { routeAction, routeController };
|
|
5
|
+
export { routeAction, routeBinding, routeController };
|
package/decorators/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const r=t=>o=>{},e=t=>(o,
|
|
1
|
+
"use strict";const r=t=>o=>{},n=t=>o=>{},e=t=>(o,i,u)=>{};exports.routeAction=e,exports.routeBinding=n,exports.routeController=r;
|
package/decorators/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const r=o=>t=>{},e=
|
|
1
|
+
const r=t=>o=>{},n=t=>o=>{},e=t=>(o,i,u)=>{};export{e as routeAction,n as routeBinding,r as routeController};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jwn-js/vite-plugin-schema",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Auto schema for @jwn-js/common utils for build server on node js",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "yarn docs && node scripts/build.mjs",
|
|
14
14
|
"docs": "typedoc --includeVersion --excludePrivate --out docs src/plugin/index.mts",
|
|
15
|
-
"publish:npm": "yarn publish dist --access public
|
|
15
|
+
"publish:npm": "yarn publish dist --access public",
|
|
16
|
+
"test": "vitest run"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
19
|
"chalk": "4",
|
|
@@ -20,11 +21,13 @@
|
|
|
20
21
|
"ts-morph": "^27.0.2"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
24
|
+
"@jwn-js/common": "^2.4.1",
|
|
23
25
|
"@rollup/plugin-alias": "^6.0.0",
|
|
24
26
|
"@rollup/plugin-json": "^6.1.0",
|
|
25
27
|
"@types/node": "^25.2.2",
|
|
26
28
|
"esbuild": "^0.27.3",
|
|
27
29
|
"fs-extra": "^11.3.3",
|
|
30
|
+
"jsdom": "^28.0.0",
|
|
28
31
|
"rollup": "^4.57.1",
|
|
29
32
|
"rollup-plugin-dts": "^6.3.0",
|
|
30
33
|
"rollup-plugin-esbuild": "^6.2.1",
|
package/plugin/index.d.ts
CHANGED
package/plugin/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=require("node:fs/promises"),u=require("node:path"),g=require("json5"),h=require("node:crypto"),w=require("ts-morph"),y=require("chalk");const p=async(i,{extensions:o=[".ts",".mts"],filter:t,exclude:e=/\.spec/,prefix:n=""}={})=>{const a=await m.readdir(u.resolve(i),{withFileTypes:!0});return(await Promise.all(a.map(async c=>{const s=n+u.join(i,c.name);if(c.isDirectory())return p(s,{extensions:o,filter:t,prefix:n});const r=u.extname(s).toLowerCase(),l=u.parse(s).name;return o.includes(r)&&(!t||t.test(l))&&(!e||!e.test(l))?s:[]}))).flat()},v=(i,{extensions:o=[".ts",".mts"],filter:t,exclude:e=/\.spec/}={})=>{const n=u.extname(i).toLowerCase(),a=u.parse(i).name;return!!(o.includes(n)&&(!t||t.test(a))&&(!e||!e.test(a)))},A=i=>{const o=new w.Project,t=[];for(const e of i)o.addSourceFileAtPath(e).getClasses().forEach(n=>{const a=n.getDecorator("routeController");if(a){const c=a.getArguments()[0]?.getText().replace(/['"]/g,"")||"";n.getName()&&(t.push({name:c,component:e,subactions:[]}),n.getMethods().forEach(s=>{const r=s.getDecorator("routeAction");if(r){const l=r.getArguments()[0]?.getText().replace(/['"]/g,"");t[t.length-1].subactions.push({name:s.getName(),action:l})}}))}});for(const e of i)o.addSourceFileAtPath(e).getClasses().forEach(n=>{const a=n.getDecorator("routeBinding");if(a){const c=a.getArguments()[0]?.getText().replace(/['"]/g,"")||"";if(n.getName()){const s=t.findIndex(r=>r.name===c);s!==-1&&(t[s]={name:t[s].name,component:t[s].component,binding:e,subactions:t[s].subactions})}}});return t},d=async(i,o,{extensions:t=[".ts",".mts"],filter:e,exclude:n=/\.spec/,prefix:a=""}={})=>{const c=await p(i,{extensions:t,filter:e,exclude:n,prefix:a}),s=A(c);let r=g.stringify(s,null,2);c.forEach(f=>{r=r.replaceAll(`'${f}'`,`() => import("${f}")`)});const l=`// Auto generated file. Do not edit manually
|
|
2
2
|
|
|
3
3
|
import type {Schema} from "@jwn-js/common";
|
|
4
4
|
|
|
5
|
-
export const controllers: Schema["controllers"] = ${
|
|
5
|
+
export const controllers: Schema["controllers"] = ${r};`;await m.writeFile(u.resolve(o),l);const x=await b(l);return{files:c,hash:x}},b=async i=>{const o=h.webcrypto,t=new TextEncoder().encode(i),e=await o.subtle.digest("SHA-1",t);return Array.from(new Uint8Array(e)).map(n=>n.toString(16).padStart(2,"0")).join("")},j=i=>{let o="",t=[];const e=Object.assign({},{extensions:[".ts",".mts"]},i);return{name:"vite-plugin-routes-jwn-js",async config(n,{command:a}){({files:t,hash:o}=await d(e.path,e.schema,{extensions:e.extensions,filter:e.filter,exclude:e.exclude,prefix:e.prefix}))},async handleHotUpdate({server:n,modules:a,timestamp:c}){let s=!1;if(a.forEach(r=>{v(r.file,{extensions:e.extensions,filter:e.filter,exclude:e.exclude})&&(s=!0)}),s){let r="";({files:t,hash:r}=await d(e.path,e.schema,{extensions:e.extensions,filter:e.filter,exclude:e.exclude,prefix:e.prefix})),o!==r&&(n.ws.send({type:"full-reload"}),o=r,console.log(y.green("Route changed. Reloading page.")))}}}};exports.vitePluginRoutesJwnJs=j;
|
package/plugin/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{writeFile as
|
|
1
|
+
import{writeFile as h,readdir as w}from"node:fs/promises";import{extname as f,parse as u,resolve as p,join as y}from"node:path";import A from"json5";import b from"node:crypto";import{Project as j}from"ts-morph";import S from"chalk";const x=async(a,{extensions:r=[".ts",".mts"],filter:t,exclude:e=/\.spec/,prefix:n=""}={})=>{const i=await w(p(a),{withFileTypes:!0});return(await Promise.all(i.map(async c=>{const s=n+y(a,c.name);if(c.isDirectory())return x(s,{extensions:r,filter:t,prefix:n});const o=f(s).toLowerCase(),l=u(s).name;return r.includes(o)&&(!t||t.test(l))&&(!e||!e.test(l))?s:[]}))).flat()},E=(a,{extensions:r=[".ts",".mts"],filter:t,exclude:e=/\.spec/}={})=>{const n=f(a).toLowerCase(),i=u(a).name;return!!(r.includes(n)&&(!t||t.test(i))&&(!e||!e.test(i)))},C=a=>{const r=new j,t=[];for(const e of a)r.addSourceFileAtPath(e).getClasses().forEach(n=>{const i=n.getDecorator("routeController");if(i){const c=i.getArguments()[0]?.getText().replace(/['"]/g,"")||"";n.getName()&&(t.push({name:c,component:e,subactions:[]}),n.getMethods().forEach(s=>{const o=s.getDecorator("routeAction");if(o){const l=o.getArguments()[0]?.getText().replace(/['"]/g,"");t[t.length-1].subactions.push({name:s.getName(),action:l})}}))}});for(const e of a)r.addSourceFileAtPath(e).getClasses().forEach(n=>{const i=n.getDecorator("routeBinding");if(i){const c=i.getArguments()[0]?.getText().replace(/['"]/g,"")||"";if(n.getName()){const s=t.findIndex(o=>o.name===c);s!==-1&&(t[s]={name:t[s].name,component:t[s].component,binding:e,subactions:t[s].subactions})}}});return t},d=async(a,r,{extensions:t=[".ts",".mts"],filter:e,exclude:n=/\.spec/,prefix:i=""}={})=>{const c=await x(a,{extensions:t,filter:e,exclude:n,prefix:i}),s=C(c);let o=A.stringify(s,null,2);c.forEach(m=>{o=o.replaceAll(`'${m}'`,`() => import("${m}")`)});const l=`// Auto generated file. Do not edit manually
|
|
2
2
|
|
|
3
3
|
import type {Schema} from "@jwn-js/common";
|
|
4
4
|
|
|
5
|
-
export const controllers: Schema["controllers"] = ${
|
|
5
|
+
export const controllers: Schema["controllers"] = ${o};`;await h(p(r),l);const g=await D(l);return{files:c,hash:g}},D=async a=>{const r=b.webcrypto,t=new TextEncoder().encode(a),e=await r.subtle.digest("SHA-1",t);return Array.from(new Uint8Array(e)).map(n=>n.toString(16).padStart(2,"0")).join("")},F=a=>{let r="",t=[];const e=Object.assign({},{extensions:[".ts",".mts"]},a);return{name:"vite-plugin-routes-jwn-js",async config(n,{command:i}){({files:t,hash:r}=await d(e.path,e.schema,{extensions:e.extensions,filter:e.filter,exclude:e.exclude,prefix:e.prefix}))},async handleHotUpdate({server:n,modules:i,timestamp:c}){let s=!1;if(i.forEach(o=>{E(o.file,{extensions:e.extensions,filter:e.filter,exclude:e.exclude})&&(s=!0)}),s){let o="";({files:t,hash:o}=await d(e.path,e.schema,{extensions:e.extensions,filter:e.filter,exclude:e.exclude,prefix:e.prefix})),r!==o&&(n.ws.send({type:"full-reload"}),r=o,console.log(S.green("Route changed. Reloading page.")))}}}};export{F as vitePluginRoutesJwnJs};
|