@jwn-js/vite-plugin-schema 1.0.1 → 1.0.3
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/package.json +3 -2
- package/plugin/index.js +2 -2
- package/plugin/index.mjs +2 -2
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.3",
|
|
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",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"private": false,
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "yarn docs && node scripts/build.mjs",
|
|
14
|
-
"docs": "typedoc --includeVersion --excludePrivate --out docs src/plugin/index.mts"
|
|
14
|
+
"docs": "typedoc --includeVersion --excludePrivate --out docs src/plugin/index.mts",
|
|
15
|
+
"publish:npm": "yarn publish dist --access public "
|
|
15
16
|
},
|
|
16
17
|
"dependencies": {
|
|
17
18
|
"chalk": "4",
|
package/plugin/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var d=require("node:fs/promises"),l=require("node:path"),g=require("json5"),h=require("node:crypto"),x=require("ts-morph"),w=require("chalk");const f=async(a,{extensions:n=[".ts",".mts"],filter:t,exclude:e=/\.spec/}={})=>{const r=await d.readdir(l.resolve(a),{withFileTypes:!0});return(await Promise.all(r.map(async s=>{const c="./"+l.join(a,s.name);if(s.isDirectory())return f(c,{extensions:n,filter:t});const i=l.extname(c).toLowerCase(),o=l.parse(c).name;return n.includes(i)&&(!t||t.test(o))&&(!e||!e.test(o))?c:[]}))).flat()},y=(a,{extensions:n=[".ts",".mts"],filter:t,exclude:e=/\.spec/}={})=>{const r=l.extname(a).toLowerCase(),s=l.parse(a).name;return!!(n.includes(r)&&(!t||t.test(s))&&(!e||!e.test(s)))},v=a=>{const n=new x.Project,t=[];for(const e of a)n.addSourceFileAtPath(e).getClasses().forEach(r=>{const s=r.getDecorator("routeController");if(s){const c=s.getArguments()[0]?.getText().replace(/['"]/g,"")||"";r.getName()&&(t.push({name:c,component:e,subactions:[]}),r.getMethods().forEach(i=>{const o=i.getDecorator("routeAction");if(o){const u=o.getArguments()[0]?.getText().replace(/['"]/g,"");t[t.length-1].subactions.push({name:i.getName(),action:u})}}))}});return t},p=async(a,n,{extensions:t=[".ts",".mts"],filter:e,exclude:r=/\.spec/}={})=>{const s=await f(a,{extensions:t,filter:e,exclude:r}),c=v(s);let i=g.stringify(c,null,2);s.forEach(m=>{i=i.replaceAll(m,`() => import("${m}")`)});const o=`// 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"] = ${i};`;await d.writeFile(l.resolve(n),o);const u=await j(o);return{files:s,hash:u}},j=async a=>{const n=h.webcrypto,t=new TextEncoder().encode(a),e=await n.subtle.digest("SHA-1",t);return Array.from(new Uint8Array(e)).map(r=>r.toString(16).padStart(2,"0")).join("")},A=a=>{let n="",t=[];const e=Object.assign({},{extensions:[".ts",".mts"]},a);return{name:"vite-plugin-routes-jwn-js",async config(r,{command:s}){({files:t,hash:n}=await p(e.path,e.schema,{extensions:e.extensions,filter:e.filter,exclude:e.exclude}))},async handleHotUpdate({server:r,modules:s,timestamp:c}){let i=!1;if(s.forEach(o=>{y(o.file,{extensions:e.extensions,filter:e.filter,exclude:e.exclude})&&(i=!0)}),i){let o="";({files:t,hash:o}=await p(e.path,e.schema,{filter:e.filter,exclude:e.exclude})),n!==o&&(r.ws.send({type:"full-reload"}),n=o,console.log(w.green("Route changed. Reloading page.")))}}}};exports.vitePluginRoutesJwnJs=A;
|
package/plugin/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{writeFile as g,readdir as
|
|
1
|
+
import{writeFile as g,readdir as h}from"node:fs/promises";import{extname as u,parse as f,resolve as p,join as w}from"node:path";import y from"json5";import j from"node:crypto";import{Project as A}from"ts-morph";import S from"chalk";const d=async(a,{extensions:o=[".ts",".mts"],filter:t,exclude:e=/\.spec/}={})=>{const n=await h(p(a),{withFileTypes:!0});return(await Promise.all(n.map(async s=>{const c="./"+w(a,s.name);if(s.isDirectory())return d(c,{extensions:o,filter:t});const i=u(c).toLowerCase(),r=f(c).name;return o.includes(i)&&(!t||t.test(r))&&(!e||!e.test(r))?c:[]}))).flat()},b=(a,{extensions:o=[".ts",".mts"],filter:t,exclude:e=/\.spec/}={})=>{const n=u(a).toLowerCase(),s=f(a).name;return!!(o.includes(n)&&(!t||t.test(s))&&(!e||!e.test(s)))},E=a=>{const o=new A,t=[];for(const e of a)o.addSourceFileAtPath(e).getClasses().forEach(n=>{const s=n.getDecorator("routeController");if(s){const c=s.getArguments()[0]?.getText().replace(/['"]/g,"")||"";n.getName()&&(t.push({name:c,component:e,subactions:[]}),n.getMethods().forEach(i=>{const r=i.getDecorator("routeAction");if(r){const l=r.getArguments()[0]?.getText().replace(/['"]/g,"");t[t.length-1].subactions.push({name:i.getName(),action:l})}}))}});return t},x=async(a,o,{extensions:t=[".ts",".mts"],filter:e,exclude:n=/\.spec/}={})=>{const s=await d(a,{extensions:t,filter:e,exclude:n}),c=E(s);let i=y.stringify(c,null,2);s.forEach(m=>{i=i.replaceAll(m,`() => import("${m}")`)});const r=`// 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"] = ${i};`;await g(p(o),r);const l=await v(r);return{files:s,hash:l}},v=async a=>{const o=j.webcrypto,t=new TextEncoder().encode(a),e=await o.subtle.digest("SHA-1",t);return Array.from(new Uint8Array(e)).map(n=>n.toString(16).padStart(2,"0")).join("")},C=a=>{let o="",t=[];const e=Object.assign({},{extensions:[".ts",".mts"]},a);return{name:"vite-plugin-routes-jwn-js",async config(n,{command:s}){({files:t,hash:o}=await x(e.path,e.schema,{extensions:e.extensions,filter:e.filter,exclude:e.exclude}))},async handleHotUpdate({server:n,modules:s,timestamp:c}){let i=!1;if(s.forEach(r=>{b(r.file,{extensions:e.extensions,filter:e.filter,exclude:e.exclude})&&(i=!0)}),i){let r="";({files:t,hash:r}=await x(e.path,e.schema,{filter:e.filter,exclude:e.exclude})),o!==r&&(n.ws.send({type:"full-reload"}),o=r,console.log(S.green("Route changed. Reloading page.")))}}}};export{C as vitePluginRoutesJwnJs};
|