xplorajs 0.3.2 → 0.3.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.
- package/dist/cli.js +1 -1
- package/dist/commands/build.js +3 -0
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/dev.js.map +1 -1
- package/package.json +2 -1
package/dist/cli.js
CHANGED
package/dist/commands/build.js
CHANGED
|
@@ -40,6 +40,9 @@ export async function build() {
|
|
|
40
40
|
await mkdir(join(process.cwd(), "dist"), {
|
|
41
41
|
recursive: true
|
|
42
42
|
});
|
|
43
|
+
await mkdir(join(process.cwd(), ".xplora"), {
|
|
44
|
+
recursive: true
|
|
45
|
+
});
|
|
43
46
|
const pages = await glob("src/app/**/*.tsx", {
|
|
44
47
|
ignore: [
|
|
45
48
|
"**/node_modules/**"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/build.ts"],"sourcesContent":["import { mkdir, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { glob } from \"fast-glob\";\nimport React from \"react\";\nimport { generateStaticPage } from \"xplorajs-react\";\n\ninterface Route {\n
|
|
1
|
+
{"version":3,"sources":["../../src/commands/build.ts"],"sourcesContent":["import { mkdir, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { glob } from \"fast-glob\";\nimport React from \"react\";\nimport { generateStaticPage } from \"xplorajs-react\";\n\ninterface Route {\n\tpath: string;\n\tfile: string;\n\tisDynamic: boolean;\n\tparams: string[];\n}\n\nfunction convertToRoute(filePath: string): Route {\n\tconst relativePath = filePath.replace(\"src/app/\", \"\");\n\tconst path = relativePath\n\t\t.replace(/\\.tsx$/, \"\")\n\t\t.replace(/\\/page$/, \"\")\n\t\t.replace(/\\[([^\\]]+)\\]/g, \":$1\");\n\n\tconst params = (relativePath.match(/\\[([^\\]]+)\\]/g) || []).map((param) =>\n\t\tparam.slice(1, -1),\n\t);\n\n\treturn {\n\t\tpath: path === \"page\" ? \"/\" : `/${path}`,\n\t\tfile: filePath,\n\t\tisDynamic: params.length > 0,\n\t\tparams,\n\t};\n}\n\nasync function processPage(page: string, route: Route) {\n\ttry {\n\t\tconst module = await import(join(process.cwd(), page));\n\t\tconst PageComponent = module.default;\n\n\t\tconst getStaticProps = module.getStaticProps;\n\t\tlet props = {};\n\n\t\tif (getStaticProps) {\n\t\t\tconst result = await getStaticProps();\n\t\t\tprops = result.props;\n\t\t}\n\n\t\tconst outputPath = join(process.cwd(), \"dist\", route.path, \"index.html\");\n\t\tawait generateStaticPage({\n\t\t\tcomponent: React.createElement(PageComponent, props),\n\t\t\toutputPath,\n\t\t\tprops,\n\t\t});\n\n\t\tconsole.log(`Generated ${outputPath}`);\n\t} catch (error) {\n\t\tconsole.error(`Error processing ${page}:`, error);\n\t}\n}\n\nexport async function build() {\n\tconsole.log(\"Building application...\");\n\n\tawait mkdir(join(process.cwd(), \"dist\"), { recursive: true });\n\tawait mkdir(join(process.cwd(), \".xplora\"), { recursive: true });\n\n\tconst pages = await glob(\"src/app/**/*.tsx\", {\n\t\tignore: [\"**/node_modules/**\"],\n\t});\n\n\tconst routes: Route[] = [];\n\n\tfor (const page of pages) {\n\t\tconst route = convertToRoute(page);\n\t\troutes.push(route);\n\t\tawait processPage(page, route);\n\t}\n\n\tconst routesConfig = {\n\t\troutes,\n\t\tgeneratedAt: new Date().toISOString(),\n\t};\n\n\tawait writeFile(\n\t\tjoin(process.cwd(), \".xplora\", \"routes.json\"),\n\t\tJSON.stringify(routesConfig, null, 2),\n\t);\n\n\tconsole.log(\"Build completed!\");\n\tconsole.log(\"Routes:\", routes.map((r) => r.path).join(\"\\n\"));\n}\n"],"names":["mkdir","writeFile","join","glob","React","generateStaticPage","convertToRoute","filePath","relativePath","replace","path","params","match","map","param","slice","file","isDynamic","length","processPage","page","route","module","process","cwd","PageComponent","default","getStaticProps","props","result","outputPath","component","createElement","console","log","error","build","recursive","pages","ignore","routes","push","routesConfig","generatedAt","Date","toISOString","JS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AC,EAAEe;IAC5C;AACD;AAEA,OAAO,eAAeC;IACrBH,QAAQC,GAAG,CAAC;IAEZ,MAAMlC,MAAME,KAAKqB,QAAQC,GAAG,IAAI,SAAS;QAAEa,WAAW;IAAK;IAC3D,MAAMrC,MAAME,KAAKqB,QAAQC,GAAG,IAAI,YAAY;QAAEa,WAAW;IAAK;IAE9D,MAAMC,QAAQ,MAAMnC,KAAK,oBAAoB;QAC5CoC,QAAQ;YAAC;SAAqB;IAC/B;IAEA,MAAMC,SAAkB,EAAE;IAE1B,KAAK,MAAMpB,QAAQkB,MAAO;QACzB,MAAMjB,QAAQf,eAAec;QAC7BoB,OAAOC,IAAI,CAACpB;QACZ,MAAMF,YAAYC,MAAMC;IACzB;IAEA,MAAMqB,eAAe;QACpBF;QACAG,aAAa,IAAIC,OAAOC,WAAW;IACpC;IAEA,MAAM5C,UACLC,KAAKqB,QAAQC,GAAG,IAAI,WAAW,gBAC/BsB,KAAKC,SAAS,CAACL,cAAc,MAAM;IAGpCT,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC,WAAWM,OAAO3B,GAAG,CAAC,CAACmC,IAAMA,EAAEtC,IAAI,EAAER,IAAI,CAAC;AACvD"}
|
package/dist/commands/dev.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/dev.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { serve } from \"bun\";\nimport { watch } from \"chokidar\";\nimport React from \"react\";\nimport type { ComponentType } from \"react\";\nimport { WebSocketServer } from \"ws\";\nimport { renderToStream } from \"xplorajs-react\";\nimport { build } from \"./build\";\n\n// biome-ignore lint/suspicious/noExplicitAny: <intended>\nconst pages = new Map<string, ComponentType<Record<string, any>>>();\n\nasync function loadPages() {\n
|
|
1
|
+
{"version":3,"sources":["../../src/commands/dev.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { serve } from \"bun\";\nimport { watch } from \"chokidar\";\nimport React from \"react\";\nimport type { ComponentType } from \"react\";\nimport { WebSocketServer } from \"ws\";\nimport { renderToStream } from \"xplorajs-react\";\nimport { build } from \"./build\";\n\n// biome-ignore lint/suspicious/noExplicitAny: <intended>\nconst pages = new Map<string, ComponentType<Record<string, any>>>();\n\nasync function loadPages() {\n\tpages.clear();\n\tconst routes = await loadRoutes();\n\n\tfor (const route of routes) {\n\t\tconst abs = join(process.cwd(), route.file);\n\t\tdelete import.meta.require?.cache?.[abs];\n\t\tpages.set(\n\t\t\troute.path,\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: <intended>\n\t\t\t(await import(abs)).default as ComponentType<Record<string, any>>,\n\t\t);\n\t}\n}\n\nasync function loadRoutes() {\n\ttry {\n\t\tconst routesPath = join(process.cwd(), \".xplora\", \"routes.json\");\n\t\tconst routesContent = readFileSync(routesPath, \"utf-8\");\n\t\treturn JSON.parse(routesContent).routes;\n\t} catch {\n\t\treturn [];\n\t}\n}\n\nexport async function dev() {\n\tconsole.log(\"Starting development server...\");\n\n\tconst wss = new WebSocketServer({ port: 3001 });\n\n\tconst watcher = watch([\"src/**/*\"], {\n\t\tignored: /(^|[\\/\\\\])\\../,\n\t\tpersistent: true,\n\t});\n\n\twatcher.on(\"change\", async (path: string) => {\n\t\tconsole.log(`File ${path} has been changed`);\n\t\tawait build();\n\t\tawait loadPages();\n\n\t\tfor (const client of wss.clients) {\n\t\t\tif (client.readyState === WebSocket.OPEN) {\n\t\t\t\tclient.send(JSON.stringify({ type: \"reload\" }));\n\t\t\t}\n\t\t}\n\t});\n\n\tawait build();\n\tawait loadPages();\n\n\tserve({\n\t\tport: 3000,\n\t\tdevelopment: true,\n\t\tasync fetch(req: Request) {\n\t\t\tconst url = new URL(req.url);\n\t\t\tconst path = url.pathname;\n\n\t\t\tif (path === \"/\") {\n\t\t\t\treturn new Response(\"Hello from XploraJS!\");\n\t\t\t}\n\n\t\t\tif (path.startsWith(\"/assets/\")) {\n\t\t\t\tconst f = Bun.file(join(process.cwd(), \"dist\", path));\n\t\t\t\tif (await f.exists()) return new Response(f);\n\t\t\t}\n\n\t\t\tconst Page = pages.get(path);\n\t\t\tif (!Page) return new Response(\"Not Found\", { status: 404 });\n\n\t\t\tconst stream = await renderToStream(React.createElement(Page));\n\n\t\t\tconst head = `<!DOCTYPE html><html><head>\n\t\t\t\t<meta charset=\"utf-8\"/>\n\t\t\t\t<link rel=\"stylesheet\" href=\"/assets/style.css\"/>\n\t\t\t\t<script>window.process={env:{NODE_ENV:\"development\"}};</script>\n\t\t\t\t</head><body><div id=\"root\">`;\n\n\t\t\tconst foot = `</div>\n\t\t\t\t<script type=\"module\">\n\t\t\t\t\timport * as RefreshRuntime from \"https://esm.sh/react-refresh@0.17.0/runtime\";\n\t\t\t\t\tif (window.process?.env?.NODE_ENV === \"development\") {\n\t\t\t\t\t\tconsole.log(\"Fast refresh runtime loaded in development mode\");\n\t\t\t\t\t}\n\t\t\t\t\tRefreshRuntime.injectIntoGlobalHook(window);\n\t\t\t\t\twindow.$RefreshReg$=()=>{};\n\t\t\t\t\twindow.$RefreshSig$=()=>t=>t;\n\t\t\t\t</script>\n\t\t\t\t<script>\n\t\t\t\t\tconst ws=new WebSocket(\"ws://localhost:3001\");\n\t\t\t\t\tws.onmessage=async e=>{\n\t\t\t\t\t\tif(e.data===\"css\"){\n\t\t\t\t\t\t\tdocument.querySelectorAll('link[rel=\"stylesheet\"]').forEach(l=>l.href=\"/assets/style.css?v=\"+Date.now());\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(e.data===\"reload\"){\n\t\t\t\t\t\t\tconsole.log(\"Reloading...\");\n\t\t\t\t\t\t\tlocation.reload();\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t</script>\n\t\t\t</body></html>`;\n\n\t\t\treturn new Response(\n\t\t\t\tnew ReadableStream({\n\t\t\t\t\tstart(ctrl) {\n\t\t\t\t\t\tctrl.enqueue(new TextEncoder().encode(head));\n\t\t\t\t\t\tif (typeof stream === \"string\") {\n\t\t\t\t\t\t\tctrl.enqueue(new TextEncoder().encode(stream));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstream.pipeTo(\n\t\t\t\t\t\t\t\tnew WritableStream({\n\t\t\t\t\t\t\t\t\twrite(c) {\n\t\t\t\t\t\t\t\t\t\tctrl.enqueue(c);\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tclose() {\n\t\t\t\t\t\t\t\t\t\tctrl.enqueue(new TextEncoder().encode(foot));\n\t\t\t\t\t\t\t\t\t\tctrl.close();\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\t{ headers: { \"Content-Type\": \"text/html; charset=utf-8\" } },\n\t\t\t);\n\t\t},\n\t});\n\n\tconsole.log(\"Development server running at http://localhost:3000\");\n}\n"],"names":["readFileSync","join","serve","watch","React","WebSocketServer","renderToStream","build","pages","Map","loadPages","clear","routes","loadRoutes","route","abs","process","cwd","file","require","cache","set","path","default","routesPath","routesContent","JSON","parse","dev","console","log","wss","port","watcher","ignored","persistent","on","client","clients","readyState","WebSocket","OPEN","send","stringify","type","development","fetch","req","url","URL","pathname","Response","startsWith","f","Bun","exists","Page","get","status","stream","createElement","head","foot","ReadableStream","start","ctrl","enqueue","TextEncoder","encode","pipeTo","WritableStream","write","c","close","headers"],"mappings":"AAAA,SAASA,YAAY,QAAQ,UAAU;AACvC,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,KAAK,QAAQ,MAAM;AAC5B,SAASC,KAAK,QAAQ,WAAW;AACjC,OAAOC,WAAW,QAAQ;AAE1B,SAASC,eAAe,QAAQ,KAAK;AACrC,SAASC,cAAc,QAAQ,iBAAiB;AAChD,SAASC,KAAK,QAAQ,UAAU;AAGhC,MAAMC,QAAQ,IAAIC;AAElB,eAAeC;IACdF,MAAMG,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AEA,IAAI7B,KAAK8B,UAAU,CAAC,aAAa;gBAChC,MAAMC,IAAIC,IAAIpC,IAAI,CAACjB,KAAKe,QAAQC,GAAG,IAAI,QAAQK;gBAC/C,IAAI,MAAM+B,EAAEE,MAAM,IAAI,OAAO,IAAIJ,SAASE;YAC3C;YAEA,MAAMG,OAAOhD,MAAMiD,GAAG,CAACnC;YACvB,IAAI,CAACkC,MAAM,OAAO,IAAIL,SAAS,aAAa;gBAAEO,QAAQ;YAAI;YAE1D,MAAMC,SAAS,MAAMrD,eAAeF,MAAMwD,aAAa,CAACJ;YAExD,MAAMK,OAAO,CAAC;;;;gCAIe,CAAC;YAE9B,MAAMC,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;iBAsBA,CAAC;YAEf,OAAO,IAAIX,SACV,IAAIY,eAAe;gBAClBC,OAAMC,IAAI;oBACTA,KAAKC,OAAO,CAAC,IAAIC,cAAcC,MAAM,CAACP;oBACtC,IAAI,OAAOF,WAAW,UAAU;wBAC/BM,KAAKC,OAAO,CAAC,IAAIC,cAAcC,MAAM,CAACT;oBACvC,OAAO;wBACNA,OAAOU,MAAM,CACZ,IAAIC,eAAe;4BAClBC,OAAMC,CAAC;gCACNP,KAAKC,OAAO,CAACM;4BACd;4BACAC;gCACCR,KAAKC,OAAO,CAAC,IAAIC,cAAcC,MAAM,CAACN;gCACtCG,KAAKQ,KAAK;4BACX;wBACD;oBAEF;gBACD;YACD,IACA;gBAAEC,SAAS;oBAAE,gBAAgB;gBAA2B;YAAE;QAE5D;IACD;IAEA7C,QAAQC,GAAG,CAAC;AACb"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xplorajs",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"dev": "bun run build --watch",
|
|
16
16
|
"build": "swc src -d dist --config-file .swcrc && tsc --emitDeclarationOnly",
|
|
17
|
+
"postbuild": "bun run ./scripts/fix-shebang.js",
|
|
17
18
|
"prepublishOnly": "bun run build"
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|