@zikojs/server 0.1.0 → 0.4.0
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 +47 -63
- package/src/index.js +1 -4
- package/src/middlewares/index.js +2 -0
- package/src/middlewares/setupEnvironmentMiddleware.js +37 -0
- package/src/middlewares/trailingSlashMiddleware.js +103 -0
- package/src/server/index.js +86 -105
- package/src/server-only-utils/globImports.d.ts +73 -0
- package/src/server-only-utils/globImports.js +50 -0
- package/src/server-only-utils/index.js +1 -9
- package/README.md +0 -72
- package/src/code-splitter/directives.js +0 -5
- package/src/code-splitter/index.js +0 -1
- package/src/config/index.js +0 -13
- package/src/count.sh +0 -9
- package/src/entry-client/index.js +0 -45
- package/src/entry-server/index.js +0 -39
- package/src/prerender/index.js +0 -63
- package/src/server/api-handler.js +0 -22
- package/src/server/dev-server.js +0 -21
- package/src/server/response.js +0 -6
- package/src/server/setup-middleware.js +0 -21
- package/src/server-only-utils/glob-imports.js +0 -47
- package/src/server-only-utils/import-middlwares.js +0 -29
- package/src/server-only-utils/import-prerendered-routes.js +0 -11
- package/src/server-only-utils/index.d.ts.txt +0 -3
- package/src/server-only-utils/manifest-parser.js +0 -22
- package/src/server-only-utils/read-files.js +0 -20
- package/src/server-only-utils/renderDomToString.js +0 -8
- package/src/server-only-utils/renderToString.js +0 -8
- package/src/server-only-utils/resolve-static-routes.js +0 -64
- package/src/server-only-utils/write-to-dist.js +0 -24
- package/src/setup/files-content.js +0 -53
- package/src/setup/generate-hydration-map.js +0 -3
- package/src/setup/generate-routes.js +0 -22
- package/src/setup/index.js +0 -3
- package/src/setup/setup-ziko-folder.js +0 -16
- package/src/template.js +0 -14
- package/src/utils/api.js +0 -7
- package/src/utils/html-template.js +0 -19
- package/src/utils/index.js +0 -4
- package/src/utils/isAsync.js +0 -3
- package/src/utils/normalize-path.js +0 -21
- package/src/utils/routes-matcher.js +0 -216
- package/src/vite/index.js +0 -1
- package/src/vite/vite_setup.js +0 -37
- package/types/global.d.ts +0 -11
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './directives.js'
|
package/src/config/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { defineConfig as defineViteConfig } from "vite";
|
|
2
|
-
import { vite_setup } from "../vite/index.js";
|
|
3
|
-
export function defineConfig({ outDir = "dist" } = {}) {
|
|
4
|
-
return defineViteConfig(({ command, mode }) => {
|
|
5
|
-
const base_config = vite_setup({
|
|
6
|
-
outDir,
|
|
7
|
-
mode,
|
|
8
|
-
});
|
|
9
|
-
base_config.plugins = base_config.plugins || [];
|
|
10
|
-
base_config.aaa = 10
|
|
11
|
-
return base_config;
|
|
12
|
-
});
|
|
13
|
-
}
|
package/src/count.sh
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Count total lines in all .js and .ts files, excluding dist and node_modules
|
|
4
|
-
total_lines=$(find . -type f \( -name "*.js" -o -name "*.ts" \) \
|
|
5
|
-
-not -path "*/node_modules/*" \
|
|
6
|
-
-not -path "*/dist/*" \
|
|
7
|
-
-exec wc -l {} + | awk '{total += $1} END {print total}')
|
|
8
|
-
|
|
9
|
-
echo "Total JS + TS lines: $total_lines"
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
normalize_path,
|
|
3
|
-
routesMatcher,
|
|
4
|
-
dynamicRoutesParser,
|
|
5
|
-
isDynamic,
|
|
6
|
-
} from "../utils/index.js";
|
|
7
|
-
|
|
8
|
-
export function EntryClient({ base = '', pages } = {}) {
|
|
9
|
-
|
|
10
|
-
if (import.meta.env.DEV) pages = import.meta.glob("/src/pages/**/*{.js,.mdz}");
|
|
11
|
-
pages = import.meta.glob("/src/pages/**/*{.js,.mdz}");
|
|
12
|
-
addEventListener("load", async () => {
|
|
13
|
-
const data = JSON.parse(document.head.querySelector('script#ziko-data')?.textContent ?? "{}")
|
|
14
|
-
globalThis.Ziko = data;
|
|
15
|
-
const root = "./pages/";
|
|
16
|
-
async function hydrate(path) {
|
|
17
|
-
if (path.endsWith("/")) path = path.slice(0, -1);
|
|
18
|
-
const matchEntry = Object.entries(pages).find(([route]) =>
|
|
19
|
-
routesMatcher(normalize_path(route, root), `/${path}`)
|
|
20
|
-
);
|
|
21
|
-
if (!matchEntry) return;
|
|
22
|
-
|
|
23
|
-
const [mask, moduleImport] = matchEntry;
|
|
24
|
-
|
|
25
|
-
const module = await moduleImport();
|
|
26
|
-
let UIElement;
|
|
27
|
-
|
|
28
|
-
if (isDynamic(mask)) {
|
|
29
|
-
const params = dynamicRoutesParser(mask, `/${path}`);
|
|
30
|
-
UIElement = await module.default(params);
|
|
31
|
-
} else {
|
|
32
|
-
UIElement = await module.default();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
UIElement.unmount();
|
|
36
|
-
|
|
37
|
-
const elementsToHydrate = [...document.querySelectorAll('[data-hydration-index]')];
|
|
38
|
-
elementsToHydrate.forEach(el => {
|
|
39
|
-
el.replaceWith(__Ziko__.__HYDRATION__.store.get(+el.dataset.hydrationIndex)().element);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
hydrate(location.pathname.slice(1));
|
|
44
|
-
});
|
|
45
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
renderToString,
|
|
3
|
-
globImports,
|
|
4
|
-
readFiles,
|
|
5
|
-
} from "../server-only-utils/index.js";
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
routesMatcher,
|
|
9
|
-
dynamicRoutesParser,
|
|
10
|
-
isDynamic
|
|
11
|
-
} from "../utils/routes-matcher.js";
|
|
12
|
-
|
|
13
|
-
export function EntryServer() {
|
|
14
|
-
return async function render(path, req, res) {
|
|
15
|
-
if(path.endsWith("/")) path = path.slice(0, -1);
|
|
16
|
-
// const all_files = await readFiles()
|
|
17
|
-
const pairs = await globImports("./src/pages/**/*{.js,.mdz}")
|
|
18
|
-
|
|
19
|
-
let [mask, module] = Object.entries(pairs).find(([route]) => routesMatcher(route, `/${path}`));
|
|
20
|
-
let UIElement, ui, params;
|
|
21
|
-
if (isDynamic(mask)) params = dynamicRoutesParser(mask, `/${path}`);
|
|
22
|
-
const {Component, GET, POST, DELETE, UPDATE, head, prerender} = await module
|
|
23
|
-
if(Component){
|
|
24
|
-
UIElement = params ? await Component.call(this, params) : await Component();
|
|
25
|
-
ui = renderToString(UIElement);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
head,
|
|
30
|
-
ui,
|
|
31
|
-
prerender,
|
|
32
|
-
hydration_map : __Ziko__.__HYDRATION__,
|
|
33
|
-
GET,
|
|
34
|
-
POST,
|
|
35
|
-
DELETE,
|
|
36
|
-
UPDATE,
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
}
|
package/src/prerender/index.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
globImports,
|
|
3
|
-
renderToString,
|
|
4
|
-
writeToDist,
|
|
5
|
-
ManifestParser,
|
|
6
|
-
resolveStaticRoutes,
|
|
7
|
-
} from "ziko-server/server-only-utils";
|
|
8
|
-
|
|
9
|
-
import { routesGrouper } from "../utils/routes-matcher.js";
|
|
10
|
-
|
|
11
|
-
const StaticRoutesMap = {
|
|
12
|
-
"/blog/[...slug]":[
|
|
13
|
-
{ slug : 1 },
|
|
14
|
-
{ slug : 2 },
|
|
15
|
-
{ slug : 3 }
|
|
16
|
-
],
|
|
17
|
-
"/bb/[lang]/dd/[id]":[
|
|
18
|
-
{ lang : "en", id : 1},
|
|
19
|
-
{ lang : "en", id : 2},
|
|
20
|
-
{ lang : "en", id : 3},
|
|
21
|
-
{ lang : "fr", id : 1},
|
|
22
|
-
{ lang : "fr", id : 2},
|
|
23
|
-
{ lang : "fr", id : 3}
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
async function prerender({outDir = 'dist'} = "") {
|
|
30
|
-
const PRERENDERED_ROUTES = []
|
|
31
|
-
const pages = await globImports("./src/pages/**/*{.js,.ts,.mdz}")
|
|
32
|
-
const StaticPages = await resolveStaticRoutes(pages, StaticRoutesMap)
|
|
33
|
-
|
|
34
|
-
const grouped = routesGrouper(pages)
|
|
35
|
-
|
|
36
|
-
const Manifest = new ManifestParser(`${outDir}/.client/.vite/manifest.json`)
|
|
37
|
-
for(let route in grouped.static){
|
|
38
|
-
const Page = grouped.static[route];
|
|
39
|
-
const {Component, head} = Page
|
|
40
|
-
if(Component){
|
|
41
|
-
const res = await Component();
|
|
42
|
-
const ui = renderToString(res)
|
|
43
|
-
PRERENDERED_ROUTES.push(route)
|
|
44
|
-
writeToDist({route, ui, head, entry_client_path : Manifest.EntryClientFile, outDir})
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
for(let route in StaticPages){
|
|
48
|
-
const Page = StaticPages[route];
|
|
49
|
-
const {Component, head} = Page
|
|
50
|
-
if(Component){
|
|
51
|
-
const res = await Component();
|
|
52
|
-
const ui = renderToString(res)
|
|
53
|
-
PRERENDERED_ROUTES.push(route)
|
|
54
|
-
// console.log({hi :__Ziko__.__HYDRATION__.store, route})
|
|
55
|
-
// __Ziko__.__HYDRATION__.reset()
|
|
56
|
-
writeToDist({route, ui, head, entry_client_path : Manifest.EntryClientFile, outDir})
|
|
57
|
-
}
|
|
58
|
-
// console.log(PRERENDERED_ROUTES)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
export { prerender }
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export async function API_HANDLER(fn, req, res) {
|
|
2
|
-
const result = await fn(req, res);
|
|
3
|
-
|
|
4
|
-
if (result instanceof Response) {
|
|
5
|
-
const body = await result.text();
|
|
6
|
-
res
|
|
7
|
-
.status(result.status || 200)
|
|
8
|
-
.set(Object.fromEntries(result.headers.entries()))
|
|
9
|
-
.send(body);
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
if (typeof result === "object" && result !== null) {
|
|
13
|
-
res.json(result);
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (["string", "number", "boolean"].includes(typeof result)) {
|
|
17
|
-
res.send(String(result));
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
if (result === undefined) return;
|
|
21
|
-
res.status(500).send("Unsupported response type");
|
|
22
|
-
}
|
package/src/server/dev-server.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export const dev_server = async (app, base)=>{
|
|
2
|
-
const { createServer } = await import("vite");
|
|
3
|
-
let vite = await createServer({
|
|
4
|
-
server: { middlewareMode: true },
|
|
5
|
-
appType: "custom",
|
|
6
|
-
base,
|
|
7
|
-
});
|
|
8
|
-
app.use(vite.middlewares);
|
|
9
|
-
return vite
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// import {join} from 'path'
|
|
13
|
-
// export const prod_server = async (app, base, baseDir)=>{
|
|
14
|
-
// const compression = (await import("compression")).default;
|
|
15
|
-
// const sirv = (await import("sirv")).default;
|
|
16
|
-
// app.use(compression());
|
|
17
|
-
// app.use(
|
|
18
|
-
// base,
|
|
19
|
-
// sirv(join(baseDir, "./dist/.client"), { extensions: [] }),
|
|
20
|
-
// );
|
|
21
|
-
// }
|
package/src/server/response.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// import { join } from 'path';
|
|
2
|
-
// import { pathToFileURL } from 'url';
|
|
3
|
-
// const ziko_config_path = pathToFileURL(join(process.cwd(), 'ziko.config.js')).href;
|
|
4
|
-
|
|
5
|
-
export function SetupMiddleware(req, res, next) {
|
|
6
|
-
const protocol = req.protocol || (req.connection.encrypted ? 'https' : 'http');
|
|
7
|
-
const host = req.headers.host;
|
|
8
|
-
const origin = `${protocol}://${host}`
|
|
9
|
-
globalThis.Ziko = {
|
|
10
|
-
engine: 'zikojs',
|
|
11
|
-
isProd : process.env.NODE_ENV === "production",
|
|
12
|
-
url : req.url,
|
|
13
|
-
protocol,
|
|
14
|
-
host,
|
|
15
|
-
origin,
|
|
16
|
-
locals: {},
|
|
17
|
-
};
|
|
18
|
-
if(globalThis?.__Ziko__) __Ziko__.__HYDRATION__.reset();
|
|
19
|
-
Object.assign(req, {Ziko})
|
|
20
|
-
next();
|
|
21
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import fg from 'fast-glob';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { pathToFileURL } from 'url';
|
|
4
|
-
import { normalize_path } from '../utils/normalize-path.js';
|
|
5
|
-
|
|
6
|
-
export async function globImports(pattern = './src/pages/**/*.{js,ts,jsx,tsx,mdz}', { cwd = process.cwd() , root = "./pages/"} = {}) {
|
|
7
|
-
const files = await fg(pattern, { cwd });
|
|
8
|
-
const modules = {};
|
|
9
|
-
|
|
10
|
-
for (const file of files) {
|
|
11
|
-
const absPath = path.resolve(cwd, file);
|
|
12
|
-
const fileUrl = pathToFileURL(absPath).href;
|
|
13
|
-
const key = './' + file.replace(/\\/g, '/');
|
|
14
|
-
modules[key] = () => import(/* @vite-ignore */fileUrl);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const routes = Object.keys(modules);
|
|
18
|
-
|
|
19
|
-
const pairs = {};
|
|
20
|
-
for (let i = 0; i < routes.length; i++) {
|
|
21
|
-
const module = await modules[routes[i]]();
|
|
22
|
-
const {
|
|
23
|
-
default : Component,
|
|
24
|
-
head,
|
|
25
|
-
prerender,
|
|
26
|
-
GET,
|
|
27
|
-
POST,
|
|
28
|
-
PUT,
|
|
29
|
-
DELETE,
|
|
30
|
-
PATCH
|
|
31
|
-
} = await module
|
|
32
|
-
|
|
33
|
-
Object.assign(pairs, {
|
|
34
|
-
[normalize_path(routes[i], root)]: {
|
|
35
|
-
...(Component && {Component}),
|
|
36
|
-
...(head && {head}),
|
|
37
|
-
...(prerender !== undefined && {prerender}),
|
|
38
|
-
...(GET && {GET}),
|
|
39
|
-
...(POST && {POST}),
|
|
40
|
-
...(PUT && {PUT}),
|
|
41
|
-
...(PATCH && {PATCH}),
|
|
42
|
-
...(DELETE && {DELETE}),
|
|
43
|
-
} });
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return pairs
|
|
47
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { pathToFileURL } from 'url';
|
|
4
|
-
|
|
5
|
-
export async function importMiddlewares({ cwd = process.cwd() } = {}) {
|
|
6
|
-
const possibleFiles = [
|
|
7
|
-
path.join(cwd, 'src', 'middleware.js'),
|
|
8
|
-
path.join(cwd, 'src', 'middleware.ts')
|
|
9
|
-
];
|
|
10
|
-
|
|
11
|
-
for (const file of possibleFiles) {
|
|
12
|
-
if (fs.existsSync(file)) {
|
|
13
|
-
const fileUrl = pathToFileURL(file).href;
|
|
14
|
-
const module = await import(/* @vite-ignore */ fileUrl);
|
|
15
|
-
|
|
16
|
-
const middlewares = {};
|
|
17
|
-
for (const [key, value] of Object.entries(module)) {
|
|
18
|
-
if (typeof value === 'function') {
|
|
19
|
-
middlewares[key] = value;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return middlewares;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// No middleware file found
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { join } from 'path';
|
|
2
|
-
import { pathToFileURL } from 'url';
|
|
3
|
-
|
|
4
|
-
export async function importPrerenderedRoutes({ cwd = process.cwd(), isProduction } = {}) {
|
|
5
|
-
const file = isProduction
|
|
6
|
-
? join(cwd, 'dist/.server/prerenderd-routes.js')
|
|
7
|
-
: join(cwd, '.ziko/cache/.prerenderd-routes.js')
|
|
8
|
-
const FileUrl = pathToFileURL(file).href;
|
|
9
|
-
const module = await import(/* @vite-ignore */ FileUrl);
|
|
10
|
-
return module?.PRERENDERED_ROUTES || []
|
|
11
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {readFileSync, existsSync} from 'fs';
|
|
2
|
-
import {join} from 'path';
|
|
3
|
-
|
|
4
|
-
export class ManifestParser {
|
|
5
|
-
constructor(relative_path){
|
|
6
|
-
this.#init(relative_path)
|
|
7
|
-
}
|
|
8
|
-
#init(relative_path){
|
|
9
|
-
const file = join(process.cwd(), relative_path);
|
|
10
|
-
if (existsSync(file)) this.manifest = JSON.parse(readFileSync(file, "utf-8"));
|
|
11
|
-
else {
|
|
12
|
-
console.error(`Manifest file not found: ${file}`)
|
|
13
|
-
this.manifest = null
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
get EntryClientFile(){
|
|
17
|
-
return this.manifest['.ziko/entry-client.js'].file
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// const manifest = new ManifestParser('./dist/client/.vite/manifest.json')
|
|
22
|
-
// console.log(manifest.files)
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import fg from "fast-glob";
|
|
2
|
-
import { readFile } from "fs/promises";
|
|
3
|
-
import { resolve, relative } from "path";
|
|
4
|
-
|
|
5
|
-
export async function readFiles(pattern = './src/**/*.{js,ts}', { cwd = process.cwd() , root = "./pages/"} = {}) {
|
|
6
|
-
const files = await fg(pattern, { cwd });
|
|
7
|
-
const absoluteRoot = resolve(root);
|
|
8
|
-
console.log({files})
|
|
9
|
-
const modules = {};
|
|
10
|
-
|
|
11
|
-
const result = new Map()
|
|
12
|
-
for (const file of files) {
|
|
13
|
-
const code = await readFile(file, "utf8");
|
|
14
|
-
if(!code.includes('use client')) continue;
|
|
15
|
-
// Normalize route to something like "src/pages/index.js"
|
|
16
|
-
const route = relative(absoluteRoot, file).replace(/\\/g, "/");
|
|
17
|
-
result.set(route, code);
|
|
18
|
-
}
|
|
19
|
-
console.log(result)
|
|
20
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
export async function resolveStaticRoutes(routes, StaticRoutesMap) {
|
|
2
|
-
const result = {};
|
|
3
|
-
|
|
4
|
-
for (const [routePattern, handler] of Object.entries(routes)) {
|
|
5
|
-
const { Component, prerender, head } = handler;
|
|
6
|
-
if(!Component || prerender === false) continue;
|
|
7
|
-
const staticParamsList = StaticRoutesMap[routePattern];
|
|
8
|
-
if (staticParamsList && /\[.*\]/.test(routePattern)) {
|
|
9
|
-
for (const params of staticParamsList) {
|
|
10
|
-
let resolvedRoute = routePattern;
|
|
11
|
-
|
|
12
|
-
// Handle [...param] → can include slashes
|
|
13
|
-
resolvedRoute = resolvedRoute.replace(/\[\.\.\.(\w+)\]/g, (_, key) => {
|
|
14
|
-
return encodeURIComponent(params[key])?.replace(/%2F/g, '/');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// Handle [param]+ or [param]
|
|
18
|
-
resolvedRoute = resolvedRoute.replace(/\[(\w+)\]\+?/g, (_, key) => {
|
|
19
|
-
return encodeURIComponent(params[key]);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
result[resolvedRoute] = {
|
|
23
|
-
Component : () => Component(params),
|
|
24
|
-
head
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
result[routePattern] = {
|
|
29
|
-
Component,
|
|
30
|
-
head
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// DEMO
|
|
40
|
-
|
|
41
|
-
// const StaticRoutesMap = {
|
|
42
|
-
// "/blog/[...slug]": [
|
|
43
|
-
// { slug: "2025/oct/post1" },
|
|
44
|
-
// { slug: "2025/oct/post2" },
|
|
45
|
-
// { slug: "2025/nov/post3" }
|
|
46
|
-
// ],
|
|
47
|
-
// "/user/[id]+": [
|
|
48
|
-
// { id: 1 },
|
|
49
|
-
// { id: 2 },
|
|
50
|
-
// { id: 3 }
|
|
51
|
-
// ],
|
|
52
|
-
// "/product/[category]/[id]": [
|
|
53
|
-
// { category: "books", id: 12 },
|
|
54
|
-
// { category: "tech", id: 5 }
|
|
55
|
-
// ]
|
|
56
|
-
// };
|
|
57
|
-
|
|
58
|
-
// const routes = {
|
|
59
|
-
// "/blog/[...slug]": (params) => `Blog page for ${params.slug}`,
|
|
60
|
-
// "/user/[id]+": (params) => `User ${params.id}`,
|
|
61
|
-
// "/product/[category]/[id]": (params) => `Product ${params.category} #${params.id}`
|
|
62
|
-
// };
|
|
63
|
-
|
|
64
|
-
// resolveStaticRoutes(routes, StaticRoutesMap).then(console.log);
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {mkdir, writeFile} from 'fs/promises';
|
|
2
|
-
import {join, dirname} from 'path';
|
|
3
|
-
|
|
4
|
-
export async function writeToDist({route, ui, head, outDir = 'dist', entry_client_path = ''}={}) {
|
|
5
|
-
entry_client_path = `/.client/${entry_client_path}`
|
|
6
|
-
const out = `
|
|
7
|
-
<!doctype html>
|
|
8
|
-
<html>
|
|
9
|
-
<head>
|
|
10
|
-
<script type="module" src="${entry_client_path}"></script>
|
|
11
|
-
<script type='application/json' id='ziko-data'>
|
|
12
|
-
${JSON.stringify(globalThis?.Ziko ?? {}, null, 2)}
|
|
13
|
-
</script>
|
|
14
|
-
</head>
|
|
15
|
-
<body>
|
|
16
|
-
${ui}
|
|
17
|
-
</body>
|
|
18
|
-
</html>
|
|
19
|
-
`
|
|
20
|
-
const filePath = join(outDir, route === '/' ? '' : route, 'index.html');
|
|
21
|
-
await mkdir(dirname(filePath), { recursive: true });
|
|
22
|
-
await writeFile(filePath, out, 'utf8');
|
|
23
|
-
console.log(`✔️ Saved ${route} → ${filePath}`);
|
|
24
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const HTMLINDEX = `
|
|
2
|
-
<!doctype html>
|
|
3
|
-
<html>
|
|
4
|
-
<head>
|
|
5
|
-
<title>Ziko - App </title>
|
|
6
|
-
<meta charset="UTF-8" />
|
|
7
|
-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
8
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
9
|
-
<script type="module" src="/.ziko/entry-client.js"></script>
|
|
10
|
-
<!--app-head-->
|
|
11
|
-
</head>
|
|
12
|
-
<body>
|
|
13
|
-
<!--app-html-->
|
|
14
|
-
</body>
|
|
15
|
-
</html>
|
|
16
|
-
`.trim()
|
|
17
|
-
|
|
18
|
-
const SERVER = `
|
|
19
|
-
import { createServer } from "ziko-server/server";
|
|
20
|
-
createServer()
|
|
21
|
-
`.trim()
|
|
22
|
-
|
|
23
|
-
const ENTRY_SERVER = `
|
|
24
|
-
import {EntryServer} from "ziko-server/entry-server";
|
|
25
|
-
export default EntryServer
|
|
26
|
-
`.trim()
|
|
27
|
-
|
|
28
|
-
const ENTRY_CLIENT = `
|
|
29
|
-
import {EntryClient} from "ziko-server/entry-client";
|
|
30
|
-
EntryClient({
|
|
31
|
-
base : new URL(".", import.meta.url).pathname
|
|
32
|
-
})
|
|
33
|
-
`.trim()
|
|
34
|
-
|
|
35
|
-
const PRERENDER_SCRIPT = `
|
|
36
|
-
import {prerender} from 'ziko-server'
|
|
37
|
-
prerender()
|
|
38
|
-
`
|
|
39
|
-
|
|
40
|
-
const GENERATE_ROUTES_SCRIPT = `
|
|
41
|
-
import { generate_routes } from "ziko-server/setup";
|
|
42
|
-
generate_routes()
|
|
43
|
-
`
|
|
44
|
-
|
|
45
|
-
export const Files_Content = {
|
|
46
|
-
'index.html': HTMLINDEX,
|
|
47
|
-
'server.js' : SERVER,
|
|
48
|
-
'entry-server.js' : ENTRY_SERVER,
|
|
49
|
-
'entry-client.js' : ENTRY_CLIENT,
|
|
50
|
-
'scripts/prerender.js' : PRERENDER_SCRIPT,
|
|
51
|
-
'scripts/generate-routes.js' : GENERATE_ROUTES_SCRIPT,
|
|
52
|
-
'cache/.keep' : null
|
|
53
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {writeFileSync} from "fs"
|
|
2
|
-
import { join } from "path";
|
|
3
|
-
|
|
4
|
-
const __pages__ = {
|
|
5
|
-
"/src/pages/index.js": () => import("/src/pages/index.js"),
|
|
6
|
-
"/src/pages/me.js": () => import("/src/pages/me.js"),
|
|
7
|
-
"/src/pages/about/index.js": () => import("/src/pages/about/index.js"),
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export function generate_routes(){
|
|
11
|
-
const Pages = stringify(__pages__);
|
|
12
|
-
const Output = `export const pages = ${Pages}`
|
|
13
|
-
const path = join(process.cwd(), './.ziko/cache/.generated-routes.js')
|
|
14
|
-
writeFileSync(path, Output)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function stringify(obj) {
|
|
18
|
-
const entries = Object.entries(obj).map(
|
|
19
|
-
([key, val]) => ` "${key}": ${val.toString()}`
|
|
20
|
-
);
|
|
21
|
-
return `{\n${entries.join(",\n")}\n}`;
|
|
22
|
-
}
|
package/src/setup/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { mkdir, writeFile } from 'fs/promises';
|
|
2
|
-
import { dirname, join } from 'path';
|
|
3
|
-
import { Files_Content } from './files-content.js';
|
|
4
|
-
|
|
5
|
-
export async function setup_ziko_folder(basePath) {
|
|
6
|
-
for (const [file, content] of Object.entries(Files_Content)) {
|
|
7
|
-
const fullPath = join(basePath, file);
|
|
8
|
-
const dir = dirname(fullPath);
|
|
9
|
-
await mkdir(dir, { recursive: true });
|
|
10
|
-
try {
|
|
11
|
-
const existing = await readFile(fullPath, 'utf8');
|
|
12
|
-
if (existing === content) continue;
|
|
13
|
-
} catch {}
|
|
14
|
-
await writeFile(fullPath, content ?? '', 'utf8');
|
|
15
|
-
}
|
|
16
|
-
}
|
package/src/template.js
DELETED
package/src/utils/api.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export const HTMLTemplate = `
|
|
2
|
-
<!doctype html>
|
|
3
|
-
<html lang="en">
|
|
4
|
-
<head>
|
|
5
|
-
<title>Z</title>
|
|
6
|
-
<meta charset="UTF-8" />
|
|
7
|
-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
8
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
9
|
-
<meta name="description" content="test ziko-ssr"/>
|
|
10
|
-
<title>Vite App</title>
|
|
11
|
-
<!--app-head-->
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<!--app-html-->
|
|
15
|
-
<script type="module" src="/src/entry-client.js" async></script>
|
|
16
|
-
<!-- <script type="module" src="node_modules/ziko-server/entry/client.js" async></script> -->
|
|
17
|
-
</body>
|
|
18
|
-
</html>
|
|
19
|
-
`
|
package/src/utils/index.js
DELETED
package/src/utils/isAsync.js
DELETED