@ekg_gg/devkit 0.0.13 → 0.0.14
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/index.mjs +8 -8
- package/package.json +5 -3
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import e from"yargs";import{hideBin as t}from"yargs/helpers";import n from"node:fs/promises";import
|
|
2
|
+
import e from"yargs";import{hideBin as t}from"yargs/helpers";import n from"ajv/dist/2020";import r from"chalk";import i from"node:fs/promises";import a from"node:path";import{build as o}from"tsdown";import{fileURLToPath as s}from"node:url";import{z as c}from"zod/v4";import{createServer as l}from"vite";c.object({width:c.number().min(0).default(1e3),height:c.number().min(0).default(1e3),settings:c.record(c.string(),c.unknown()).default({}),events:c.record(c.string(),c.unknown()).default({})});const u=c.object({$schema:c.literal(`https://ekg.gg/schemas/manifest.json`).default(`https://ekg.gg/schemas/manifest.json`),name:c.string().optional(),version:c.string().optional(),description:c.string().optional(),template:c.string().default(``),css:c.string().default(``),js:c.string().default(``),assets:c.record(c.string(),c.object({type:c.string().default(``),file:c.string().default(``)})).optional(),settings:c.record(c.string(),c.looseObject({type:c.string().default(``),name:c.string().default(``),description:c.string().optional()})).optional()});async function d(e,t){let n=a.resolve(e),r=await f(n),i=a.join(r,`manifest.json`),o=s(new URL(`..`,import.meta.url)),c=t?o:a.join(o,`..`,`..`),l=a.join(o,t?`client`:`dist`),u=e=>a.relative(l,e),d=a.join(o,`.runtime`);return{root:n,ekg:d,state:a.join(d,`state.json`),widget:r,manifest:i,node_modules:c,server:l,relative:u}}async function f(e){for await(let t of i.glob(`${e}/**/manifest.json`))if(!t.includes(`.runtime`)&&!t.includes(`dist`))return a.dirname(t);throw`No manifest.json found in ${e}`}async function p(e,t){let n=[`assets/js/devkit.d.ts`,`assets/js/devkit.js`,`assets/js/widget-worker.js`,`assets/js/emscripten-module.wasm`,`schemas/events.json`,`schemas/manifest.json`];await i.mkdir(e,{recursive:!0});try{await i.writeFile(a.join(e,`state.json`),`{}`,{flag:`wx`})}catch{}let r=await Promise.allSettled(n.map(t=>i.stat(`${e}/${a.basename(t)}`))),o=r.every(e=>e.status===`fulfilled`&&e.value.isFile());if(!(r.every(e=>e.status===`fulfilled`&&e.value.isFile()&&e.value.mtimeMs>Date.now()-6048e5)&&!t))try{await Promise.all(n.map(t=>m(e,t)))}catch(e){if(o&&!t)console.log(`Failed to update EKG types and devkit binary. Continuing with existing files.`);else throw`Failed to download devkit: ${e}`}}async function m(e,t){let n=await(await fetch(`https://ekg.gg/${t}`)).bytes();await i.writeFile(`${e}/${a.basename(t)}`,n)}async function h(e,t){let n=(e,t)=>`/// <reference types="@ekg_gg/devkit" />
|
|
3
3
|
|
|
4
4
|
declare namespace EKG {
|
|
5
5
|
interface WidgetAssets ${e}
|
|
6
6
|
interface WidgetSettings ${t}
|
|
7
7
|
}
|
|
8
|
-
`,
|
|
9
|
-
export { manager } from '/@fs${
|
|
10
|
-
export { default as EventSchema } from '/@fs${
|
|
8
|
+
`,r=(e,t)=>{let n=Object.entries(e).map(([e,n])=>` ${e}: ${t(n)}\n`).join(``);return n?`{\n${n} }`:`{}`},o=e=>{if(e.choices)return Object.keys(e.choices).map(e=>JSON.stringify(e)).join(` | `);switch(e.type){case`string`:case`color`:case`image`:return`string`;case`string_array`:case`color_array`:return`string[]`;case`decimal`:case`integer`:return`number`;case`decimal_array`:case`integer_array`:return`number[]`;case`boolean`:return`boolean`;default:return`any`}};try{let s=await i.readFile(t),c=u.parse(JSON.parse(s.toString(`utf8`))),l=r(c.assets??{},()=>`string`),d=r(c.settings??{},o);await i.writeFile(a.join(e,`ekg.d.ts`),n(l,d))}catch{try{await i.writeFile(a.join(e,`ekg.d.ts`),n(`{}`,`{}`),{flag:`wx`})}catch{}}}async function g(e,t){let s=await d(e,t);await p(s.ekg);let c=new n({allErrors:!0,discriminator:!0}),l=JSON.parse(await i.readFile(a.join(s.ekg,`manifest.json`),{encoding:`utf8`}));l.properties.settings.additionalProperties.unevaluatedProperties=!0;let u=c.compile(l),f=await _(s.manifest);if(!u(f)&&u.errors){console.log(r.red(`Invalid manifest.json`));for(let e of u.errors)console.log(r.red(`${r.bold(e.instancePath.slice(1))}: ${e.message}`));process.exit(1)}let m=new Set([`manifest.json`,f.css,f.template]);for(let e of Object.values(f.assets??{}))m.add(e.file);for(let e of Object.values(f.settings??{}))[`image`].includes(e.type)&&e.default&&m.add(e.default);let h=(await Promise.all(m.values().map(async e=>{try{if((await i.stat(a.join(s.widget,e))).isFile())return null}catch{}return e}))).filter(e=>e!==null);if(h.length){for(let e of h)console.log(r.red(`Missing file: ${r.bold(e)}`));process.exit(1)}let g=a.extname(f.js);try{await o({config:!1,tsconfig:!1,logLevel:`error`,outDir:a.join(s.root,`dist`),copy:m.values().map(e=>({from:a.join(s.widget,e),to:a.join(s.root,`dist`,e)})).toArray(),entry:a.join(s.widget,f.js),loader:{[g]:`ts`},outExtensions:()=>({js:g}),format:`esm`,platform:`neutral`,target:`esnext`,dts:!1})}catch(e){if(typeof e==`object`&&e&&`errors`in e&&Array.isArray(e.errors))for(let t of e.errors)t instanceof Error?console.log(t.message):console.error(t);else console.error(e);process.exit(1)}console.log(r.green(`${r.bold(`Success!`)} Widget files were written to ${a.join(s.root,`dist`)}`))}async function _(e){try{return JSON.parse(await i.readFile(e,{encoding:`utf8`}))}catch(e){console.log(r.red(`Failed to read widget's manifest.json`)),console.error(e),process.exit(1)}}async function v(e,t){let n=await d(e,t);await p(n.ekg);let r=await l({configFile:t?`vite.config.ts`:!1,root:n.server,define:{"import.meta.hot":!1},server:{fs:{allow:[n.node_modules,n.widget]},watch:{ignored:[`!${n.ekg}/**`]}},plugins:[{name:`EKG Dev Kit`,configureServer(e){e.ws.on(`ekg:state`,e=>{i.writeFile(n.state,JSON.stringify(e,null,2)).catch(e=>console.error(`Failed to write state file.`,e))}),e.ws.on(`ekg:manifest`,e=>{i.writeFile(n.manifest,JSON.stringify(e,null,2)).catch(e=>console.error(`Failed to write manifest file.`,e))})},resolveId(e){if(e.startsWith(`ekg:`))return`\0${e}`},load(e){let t=[`json`,`css`,`hbs`].join(`|`);switch(e){case`\0ekg:devkit`:return`
|
|
9
|
+
export { manager } from '/@fs${n.ekg}/devkit.js'
|
|
10
|
+
export { default as EventSchema } from '/@fs${n.ekg}/events.json'
|
|
11
11
|
`;case`\0ekg:widget`:return`
|
|
12
|
-
export { default as state } from '/@fs${
|
|
12
|
+
export { default as state } from '/@fs${n.state}?raw'
|
|
13
13
|
|
|
14
14
|
const inline = import.meta.glob(['./**', '!**/*.(${t})'], {
|
|
15
|
-
base: '${
|
|
15
|
+
base: '${n.relative(n.widget)}',
|
|
16
16
|
query: '?inline',
|
|
17
17
|
import: 'default',
|
|
18
18
|
exhaustive: true,
|
|
@@ -20,7 +20,7 @@ declare namespace EKG {
|
|
|
20
20
|
})
|
|
21
21
|
|
|
22
22
|
const raw = import.meta.glob(['./**/*.(${t})'], {
|
|
23
|
-
base: '${
|
|
23
|
+
base: '${n.relative(n.widget)}',
|
|
24
24
|
query: '?raw',
|
|
25
25
|
import: 'default',
|
|
26
26
|
exhaustive: true,
|
|
@@ -28,4 +28,4 @@ declare namespace EKG {
|
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
export const widget = { ...inline, ...raw }
|
|
31
|
-
`}},transform(e,t){if(t.startsWith(
|
|
31
|
+
`}},transform(e,t){if(t.startsWith(n.widget)&&!t.startsWith(n.ekg)){let n=a.extname(t.replace(/\?inline$/,``));if(/\.[mc]?[tj]s$/.test(n))return{code:`export default ${JSON.stringify(e)}`}}}}]});r.watcher.add(n.manifest),r.watcher.on(`change`,e=>e===n.manifest&&h(n.root,n.manifest)),await h(n.root,n.manifest),await r.listen(),r.printUrls(),r.bindCLIShortcuts({print:!0})}async function y(e,t){let n=await d(e,!1);await p(n.ekg,t),await h(n.root,n.manifest)}e(t(process.argv)).command(`dev [dir]`,`Runs the EKG devkit, watching for changes`,e=>e.positional(`dir`,{type:`string`,describe:`Folder to watch`,default:`.`}).option(`dev`,{alias:`d`,type:`boolean`,description:`Internal option when developing the EKG CLI`,hidden:!0}),e=>v(e.dir,e.dev??!1)).command(`build [dir]`,`Builds the widget into a directory ready for uploading to EKG`,e=>e.positional(`dir`,{type:`string`,describe:`Folder to watch`,default:`.`}).option(`dev`,{alias:`d`,type:`boolean`,description:`Internal option when developing the EKG CLI`,hidden:!0}),e=>g(e.dir,e.dev??!1)).command(`sync [dir]`,`Regenerates the EKG types`,e=>e.positional(`dir`,{type:`string`,describe:`Folder to watch`,default:`.`}).option(`force`,{alias:`f`,type:`boolean`,description:`Force downloading types and devkit binary from EKG servers`}),({dir:e,force:t})=>y(e,t)).demandCommand().help().parse();export{};
|
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekg_gg/devkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": "dist/index.mjs",
|
|
6
6
|
"types": ".runtime/devkit.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"dev": "bun run cli/index.ts dev --dev",
|
|
9
|
+
"dev-build": "bun run cli/index.ts build --dev",
|
|
9
10
|
"build": "tsdown && vite build"
|
|
10
11
|
},
|
|
11
12
|
"dependencies": {
|
|
12
13
|
"@fontsource-variable/inter": "^5.2.8",
|
|
14
|
+
"ajv": "^8.17.1",
|
|
15
|
+
"chalk": "^5.6.2",
|
|
16
|
+
"tsdown": "^0.16.1",
|
|
13
17
|
"vite": "npm:rolldown-vite@7.1.14",
|
|
14
18
|
"yargs": "^18.0.0",
|
|
15
19
|
"zod": "^4.1.12"
|
|
@@ -24,7 +28,6 @@
|
|
|
24
28
|
"@types/react-dom": "^19.1.9",
|
|
25
29
|
"@types/yargs": "^17.0.34",
|
|
26
30
|
"@vitejs/plugin-react": "^5.0.4",
|
|
27
|
-
"ajv": "^8.17.1",
|
|
28
31
|
"babel-plugin-react-compiler": "^19.1.0-rc.3",
|
|
29
32
|
"class-variance-authority": "^0.7.1",
|
|
30
33
|
"clsx": "^2.1.1",
|
|
@@ -39,7 +42,6 @@
|
|
|
39
42
|
"react-error-boundary": "^6.0.0",
|
|
40
43
|
"tailwind-merge": "^3.3.1",
|
|
41
44
|
"tailwindcss": "^4.1.16",
|
|
42
|
-
"tsdown": "^0.16.1",
|
|
43
45
|
"tw-animate-css": "^1.4.0",
|
|
44
46
|
"typescript": "~5.9.3",
|
|
45
47
|
"typescript-eslint": "^8.45.0"
|