@coreframe/vite 0.1.3 → 0.1.4

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.
@@ -0,0 +1,15 @@
1
+ import { Plugin } from "vite";
2
+
3
+ //#region dashboard.d.ts
4
+ type CoreframeDashboardPluginOptions = {
5
+ clientDist?: string;
6
+ env?: NodeJS.ProcessEnv;
7
+ projectRoot?: string;
8
+ };
9
+ declare function coreframeDashboardPlugin({
10
+ clientDist,
11
+ env,
12
+ projectRoot
13
+ }?: CoreframeDashboardPluginOptions): Plugin;
14
+ //#endregion
15
+ export { CoreframeDashboardPluginOptions, coreframeDashboardPlugin };
@@ -0,0 +1 @@
1
+ import{cp as e,readFile as t}from"node:fs/promises";import{basename as n,join as r,resolve as i}from"node:path";import{createDashboardRequestHandler as a,resolveDashboardClientDist as o}from"@coreframe/dashboard/server";import{readProjectConfig as s}from"@coreframe/scripts/config";const c=`/__dashboard`;function l({clientDist:t=o(),env:i=process.env,projectRoot:s=process.cwd()}={}){return{name:`coreframe:dashboard`,async config(){return{define:{__COREFRAME_DASHBOARD_BUILD__:JSON.stringify(await d(s,i))}}},configureServer(e){let n=a({clientDist:t,projectRoot:s});return e.middlewares.use(async(e,t,r)=>{if(!e.url||!u(e.url)){r();return}await n.handle(e,t)}),e.httpServer?.once(`close`,()=>{n.dispose()}),()=>{let t=e.printUrls.bind(e);e.printUrls=()=>{t();let n=e.resolvedUrls?.local[0];n&&e.config.logger.info(` ➜ Dashboard: ${new URL(c,n)}`)}}},async writeBundle(i){!i.dir||n(i.dir)!==`client`||await e(t,r(i.dir,c.slice(1)),{force:!0,recursive:!0})}}}function u(e){let t=new URL(e,`http://coreframe.local`).pathname;return t===c||t.startsWith(`${c}/`)}async function d(e,n){let[r,a]=await Promise.all([t(i(e,`package.json`),`utf8`),s({cwd:e})]),o=JSON.parse(r),c=Object.entries(a.worker?.environment??{}).flatMap(([e,t])=>t.kind===`generated`?[]:[{description:t.description,kind:t.kind,name:e,requiredIn:t.requiredIn??[]}]);return{applicationName:o.name??`Coreframe application`,applicationVersion:o.version,commit:n.GITHUB_SHA,configuration:c,coreframeVersion:o.engines?.coreframe,deployUrls:{production:a.deploy?.environments?.production?.url,staging:a.deploy?.environments?.staging?.url}}}export{l as coreframeDashboardPlugin};
package/dist/icons.js CHANGED
@@ -1,4 +1,4 @@
1
- import{readFile as e}from"node:fs/promises";import{createHash as t}from"node:crypto";import{isAbsolute as n,relative as r,resolve as i}from"node:path";import{buildParsedSVG as a,parseSVGContent as o}from"@iconify/utils";import{loadNodeIcon as s}from"@iconify/utils/lib/loader/node-loader";import c from"unplugin-icons/vite";const l=`src/assets/icons`,u=`\0coreframe:sprite-icon:`,d=`__COREFRAME_SPRITE_URL__`,f=/^[a-z0-9]+(?:-[a-z0-9]+)*$/;function p(t={}){let n=i(t.appIconsDirectory??l);async function r(t){if(f.test(t))try{let r=await e(i(n,`${t}.svg`),`utf8`);S(r,`app/${t}`);let s=o(r);if(!s||!a(s))throw Error(`Icon \`app/${t}\` must contain a valid viewBox`);return r}catch(e){if(O(e)&&e.code===`ENOENT`)return;throw e}}return[m({options:t,loadAppIcon:r,setAppIconsDirectory(e){n=e}}),c({compiler:`jsx`,jsx:`react`,customCollections:{app:r}})]}function m({options:e,loadAppIcon:t,setAppIconsDirectory:n}){let r=new Map,a=``,o,c;return{name:`coreframe:icons`,enforce:`pre`,configResolved(t){o=t,a=w(t.root,e.appIconsDirectory??l),n(a)},resolveId(e){let t=g(e);return t?`${u}${encodeURIComponent(JSON.stringify(t))}.js`:null},async load(e){let n=h(e);if(!n)return null;n.collection===`app`&&this.addWatchFile(i(a,`${n.icon}.svg`));let c=n.collection===`app`?await t(n.icon):await s(n.collection,n.icon,{addXmlNs:!1,autoInstall:!1,cwd:o.root,scale:1.2});if(!c)throw Error(`Icon \`${n.collection}/${n.icon}\` not found`);let l=_(c,n.collection,n.icon);return r.set(l.id,l),v(l,n.props,o.command===`serve`)},renderStart(){o.command!==`build`||r.size===0||(c=this.emitFile({type:`asset`,name:`coreframe-icons.svg`,source:y(r.values())}))},renderChunk(e){if(!e.includes(d))return null;if(!c)throw Error(`Coreframe sprite asset was not emitted before chunk rendering`);let t=b(o.base,this.getFileName(c));return e.replaceAll(d,t)},handleHotUpdate(e){if(T(a,e.file)){for(let t of e.server.moduleGraph.idToModuleMap.values())(t.id?.includes(`~icons/app/`)||t.id?.startsWith(u))&&e.server.moduleGraph.invalidateModule(t);return e.server.ws.send({type:`full-reload`}),[]}}}}function h(e){if(!e.startsWith(u)||!e.endsWith(`.js`))return null;let t=e.slice(23,-3);return JSON.parse(decodeURIComponent(t))}function g(e){let t=e.indexOf(`?`);if(t===-1)return null;let n=new URLSearchParams(e.slice(t+1));if(!n.has(`sprite`))return null;n.delete(`sprite`);let r=e.slice(0,t).replace(/^\/?(?:~icons|virtual:icons|virtual\/icons)\//,``).replace(/\.\w+$/,``).split(`/`);if(r.length!==2||r.some(e=>!f.test(e)))throw Error(`Invalid sprite icon import: ${e}`);let i=Object.create(null);return n.forEach((e,t)=>{if(t===`raw`)throw Error(`An icon import cannot use both ?sprite and ?raw`);if(t===`style`)throw Error(`Pass sprite icon styles through the component style prop`);i[C(t)]=e}),{collection:r[0],icon:r[1],props:i}}function _(e,n,r){S(e,`${n}/${r}`);let i=o(e),s=i&&a(i);if(!i||!s)throw Error(`Icon \`${n}/${r}\` must contain a valid viewBox`);let c=`coreframe-icon-${n}-${r}-${t(`sha256`).update(`${n}/${r}\0${s.attributes.viewBox}\0${s.body}`).digest(`hex`).slice(0,12)}`,l=x(s.body,c),u=i.attribs.preserveAspectRatio?` preserveAspectRatio="${E(i.attribs.preserveAspectRatio)}"`:``;return{id:c,markup:`<symbol id="${c}" viewBox="${E(s.attributes.viewBox)}"${u}>${l}</symbol>`,viewBox:s.attributes.viewBox,width:s.attributes.width,height:s.attributes.height}}function v(e,t,n){let r={...e.width?{width:e.width}:{},...e.height?{height:e.height}:{},...t},i=n?`\nregisterSpriteSymbol(${JSON.stringify({id:e.id,markup:e.markup})})\n`:``,a=n?`import { registerSpriteSymbol, SpriteIcon } from "@coreframe/lib/sprite-icon"`:`import { SpriteIcon } from "@coreframe/lib/sprite-icon"`,o=n?`#${e.id}`:`${d}#${e.id}`;return`${a}
1
+ import{readFile as e}from"node:fs/promises";import{isAbsolute as t,relative as n,resolve as r}from"node:path";import{createHash as i}from"node:crypto";import{buildParsedSVG as a,parseSVGContent as o}from"@iconify/utils";import{loadNodeIcon as s}from"@iconify/utils/lib/loader/node-loader";import c from"unplugin-icons/vite";const l=`src/assets/icons`,u=`\0coreframe:sprite-icon:`,d=`__COREFRAME_SPRITE_URL__`,f=/^[a-z0-9]+(?:-[a-z0-9]+)*$/;function p(t={}){let n=r(t.appIconsDirectory??l);async function i(t){if(f.test(t))try{let i=await e(r(n,`${t}.svg`),`utf8`);S(i,`app/${t}`);let s=o(i);if(!s||!a(s))throw Error(`Icon \`app/${t}\` must contain a valid viewBox`);return i}catch(e){if(O(e)&&e.code===`ENOENT`)return;throw e}}return[m({options:t,loadAppIcon:i,setAppIconsDirectory(e){n=e}}),c({compiler:`jsx`,jsx:`react`,customCollections:{app:i}})]}function m({options:e,loadAppIcon:t,setAppIconsDirectory:n}){let i=new Map,a=``,o,c;return{name:`coreframe:icons`,enforce:`pre`,configResolved(t){o=t,a=w(t.root,e.appIconsDirectory??l),n(a)},resolveId(e){let t=g(e);return t?`${u}${encodeURIComponent(JSON.stringify(t))}.js`:null},async load(e){let n=h(e);if(!n)return null;n.collection===`app`&&this.addWatchFile(r(a,`${n.icon}.svg`));let c=n.collection===`app`?await t(n.icon):await s(n.collection,n.icon,{addXmlNs:!1,autoInstall:!1,cwd:o.root,scale:1.2});if(!c)throw Error(`Icon \`${n.collection}/${n.icon}\` not found`);let l=_(c,n.collection,n.icon);return i.set(l.id,l),v(l,n.props,o.command===`serve`)},renderStart(){o.command!==`build`||i.size===0||(c=this.emitFile({type:`asset`,name:`coreframe-icons.svg`,source:y(i.values())}))},renderChunk(e){if(!e.includes(d))return null;if(!c)throw Error(`Coreframe sprite asset was not emitted before chunk rendering`);let t=b(o.base,this.getFileName(c));return e.replaceAll(d,t)},handleHotUpdate(e){if(T(a,e.file)){for(let t of e.server.moduleGraph.idToModuleMap.values())(t.id?.includes(`~icons/app/`)||t.id?.startsWith(u))&&e.server.moduleGraph.invalidateModule(t);return e.server.ws.send({type:`full-reload`}),[]}}}}function h(e){if(!e.startsWith(u)||!e.endsWith(`.js`))return null;let t=e.slice(23,-3);return JSON.parse(decodeURIComponent(t))}function g(e){let t=e.indexOf(`?`);if(t===-1)return null;let n=new URLSearchParams(e.slice(t+1));if(!n.has(`sprite`))return null;n.delete(`sprite`);let r=e.slice(0,t).replace(/^\/?(?:~icons|virtual:icons|virtual\/icons)\//,``).replace(/\.\w+$/,``).split(`/`);if(r.length!==2||r.some(e=>!f.test(e)))throw Error(`Invalid sprite icon import: ${e}`);let i=Object.create(null);return n.forEach((e,t)=>{if(t===`raw`)throw Error(`An icon import cannot use both ?sprite and ?raw`);if(t===`style`)throw Error(`Pass sprite icon styles through the component style prop`);i[C(t)]=e}),{collection:r[0],icon:r[1],props:i}}function _(e,t,n){S(e,`${t}/${n}`);let r=o(e),s=r&&a(r);if(!r||!s)throw Error(`Icon \`${t}/${n}\` must contain a valid viewBox`);let c=`coreframe-icon-${t}-${n}-${i(`sha256`).update(`${t}/${n}\0${s.attributes.viewBox}\0${s.body}`).digest(`hex`).slice(0,12)}`,l=x(s.body,c),u=r.attribs.preserveAspectRatio?` preserveAspectRatio="${E(r.attribs.preserveAspectRatio)}"`:``;return{id:c,markup:`<symbol id="${c}" viewBox="${E(s.attributes.viewBox)}"${u}>${l}</symbol>`,viewBox:s.attributes.viewBox,width:s.attributes.width,height:s.attributes.height}}function v(e,t,n){let r={...e.width?{width:e.width}:{},...e.height?{height:e.height}:{},...t},i=n?`\nregisterSpriteSymbol(${JSON.stringify({id:e.id,markup:e.markup})})\n`:``,a=n?`import { registerSpriteSymbol, SpriteIcon } from "@coreframe/lib/sprite-icon"`:`import { SpriteIcon } from "@coreframe/lib/sprite-icon"`,o=n?`#${e.id}`:`${d}#${e.id}`;return`${a}
2
2
  import { createElement } from "react"
3
3
  ${i}
4
4
  const defaultProps = ${JSON.stringify(r)}
@@ -11,4 +11,4 @@ export default function CoreframeSpriteIcon(props) {
11
11
  viewBox: "${e.viewBox}",
12
12
  })
13
13
  }
14
- `}function y(e){return`<svg xmlns="http://www.w3.org/2000/svg" id="coreframe-icon-sprite">${Array.from(e,e=>e.markup).join(``)}</svg>`}function b(e,t){return`${e.endsWith(`/`)?e:`${e}/`}${t}`}function x(e,t){let n=Array.from(e.matchAll(/\bid=(['"])(.*?)\1/g),e=>e[2]),r=e;for(let[e,i]of n.entries()){let n=D(i),a=`${t}-${e+1}`;r=r.replace(RegExp(`\\bid=(['"])${n}\\1`,`g`),`id="${a}"`).replace(RegExp(`(["#;])${n}(?=[)"']|\\.[a-z])`,`g`),`$1${a}`)}return r}function S(e,t){if(/<(?:script|foreignObject)\b/i.test(e)||/\son[a-z]+\s*=/i.test(e))throw Error(`Icon \`${t}\` contains executable SVG content`);if(/\b(?:href|xlink:href)\s*=\s*['"](?!#)/i.test(e))throw Error(`Icon \`${t}\` contains an external SVG reference`)}function C(e){return e===`class`?`className`:e.startsWith(`aria-`)||e.startsWith(`data-`)?e:e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function w(e,t){return n(t)?t:i(e,t)}function T(e,t){let i=r(e,t);return i!==``&&!i.startsWith(`..`)&&!n(i)}function E(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`"`,`&quot;`)}function D(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function O(e){return e instanceof Error&&`code`in e}export{p as coreframeIconsPlugin};
14
+ `}function y(e){return`<svg xmlns="http://www.w3.org/2000/svg" id="coreframe-icon-sprite">${Array.from(e,e=>e.markup).join(``)}</svg>`}function b(e,t){return`${e.endsWith(`/`)?e:`${e}/`}${t}`}function x(e,t){let n=Array.from(e.matchAll(/\bid=(['"])(.*?)\1/g),e=>e[2]),r=e;for(let[e,i]of n.entries()){let n=D(i),a=`${t}-${e+1}`;r=r.replace(RegExp(`\\bid=(['"])${n}\\1`,`g`),`id="${a}"`).replace(RegExp(`(["#;])${n}(?=[)"']|\\.[a-z])`,`g`),`$1${a}`)}return r}function S(e,t){if(/<(?:script|foreignObject)\b/i.test(e)||/\son[a-z]+\s*=/i.test(e))throw Error(`Icon \`${t}\` contains executable SVG content`);if(/\b(?:href|xlink:href)\s*=\s*['"](?!#)/i.test(e))throw Error(`Icon \`${t}\` contains an external SVG reference`)}function C(e){return e===`class`?`className`:e.startsWith(`aria-`)||e.startsWith(`data-`)?e:e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function w(e,n){return t(n)?n:r(e,n)}function T(e,r){let i=n(e,r);return i!==``&&!i.startsWith(`..`)&&!t(i)}function E(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`"`,`&quot;`)}function D(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function O(e){return e instanceof Error&&`code`in e}export{p as coreframeIconsPlugin};
package/dist/preset.js CHANGED
@@ -1 +1 @@
1
- import{coreframeAssetsPlugin as e}from"./assets.js";import{coreframeIconsPlugin as t}from"./icons.js";import{coreframeManagedDevPlugin as n}from"./managed-dev.js";function r(){return[e(),...t(),n()]}export{r as coreframeVitePreset};
1
+ import{coreframeAssetsPlugin as e}from"./assets.js";import{coreframeDashboardPlugin as t}from"./dashboard.js";import{coreframeIconsPlugin as n}from"./icons.js";import{coreframeManagedDevPlugin as r}from"./managed-dev.js";function i(){return[e(),...n(),r(),t()]}export{i as coreframeVitePreset};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreframe/vite",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/airlock-labs/coreframe.git",
@@ -19,6 +19,10 @@
19
19
  "types": "./dist/assets.d.ts",
20
20
  "default": "./dist/assets.js"
21
21
  },
22
+ "./dashboard": {
23
+ "types": "./dist/dashboard.d.ts",
24
+ "default": "./dist/dashboard.js"
25
+ },
22
26
  "./icons": {
23
27
  "types": "./dist/icons.d.ts",
24
28
  "default": "./dist/icons.js"
@@ -41,8 +45,9 @@
41
45
  "@svgr/core": "^8.1.0",
42
46
  "@svgr/plugin-jsx": "^8.1.0",
43
47
  "unplugin-icons": "^23.0.1",
44
- "@coreframe/scripts": "^0.1.18",
45
- "@coreframe/lib": "^0.1.4"
48
+ "@coreframe/dashboard": "^0.0.0",
49
+ "@coreframe/lib": "^0.1.4",
50
+ "@coreframe/scripts": "^0.1.19"
46
51
  },
47
52
  "devDependencies": {
48
53
  "@types/node": "^26.1.0",