@batijs/build 0.0.1
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/README.md +3 -0
- package/dist/chunk-3EUYSS5H.js +107 -0
- package/dist/chunk-5XFUXMWM.js +24 -0
- package/dist/chunk-U7QQNTGA.js +26 -0
- package/dist/eval.d.ts +3 -0
- package/dist/eval.js +6 -0
- package/dist/exec.d.ts +5 -0
- package/dist/exec.js +103 -0
- package/dist/parse.d.ts +11 -0
- package/dist/parse.js +14 -0
- package/dist/testUtils.d.ts +6 -0
- package/dist/testUtils.js +837 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +8 -0
- package/files/!VIKE_FRAMEWORK/pages/about/+Page.ts +4 -0
- package/files/!VIKE_FRAMEWORK/pages/index/+Page.ts +10 -0
- package/files/!VIKE_FRAMEWORK/renderer/+config.ts +3 -0
- package/files/!VIKE_FRAMEWORK/renderer/+onPageTransitionEnd.ts +5 -0
- package/files/!VIKE_FRAMEWORK/renderer/+onPageTransitionStart.ts +5 -0
- package/files/!VIKE_FRAMEWORK/renderer/+onRenderClient.ts +28 -0
- package/files/!VIKE_FRAMEWORK/renderer/+onRenderHtml.ts +16 -0
- package/files/!VIKE_FRAMEWORK/renderer/+passToClient.ts +1 -0
- package/files/!VIKE_FRAMEWORK/renderer/PageLayout.css +16 -0
- package/files/!VIKE_FRAMEWORK/renderer/PageLayout.ts +68 -0
- package/files/!VIKE_FRAMEWORK/renderer/getTitle.ts +34 -0
- package/files/!VIKE_FRAMEWORK/renderer/types.ts +12 -0
- package/files/$package.json.ts +55 -0
- package/files/$tsconfig.json.ts +27 -0
- package/files/vite.config.ts +11 -0
- package/global.d.ts +13 -0
- package/package.json +46 -0
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare function lazyGetter<T, K extends string, U>(obj: T, key: K, getter: () => U): asserts obj is T & {
|
|
2
|
+
[k in K]: U;
|
|
3
|
+
};
|
|
4
|
+
type MapGetter<T extends Record<string, () => any>> = {
|
|
5
|
+
[K in keyof T]: ReturnType<T[K]>;
|
|
6
|
+
};
|
|
7
|
+
declare function lazyfy<T extends Record<string, () => any>>(obj: T): MapGetter<T>;
|
|
8
|
+
|
|
9
|
+
export { lazyGetter, lazyfy };
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export default onRenderClient;
|
|
2
|
+
|
|
3
|
+
import { getTitle } from "./getTitle";
|
|
4
|
+
import type { PageContextClient } from "./types";
|
|
5
|
+
import { PageLayout } from "./PageLayout";
|
|
6
|
+
|
|
7
|
+
async function onRenderClient(pageContext: PageContextClient) {
|
|
8
|
+
if (!pageContext.isHydration) {
|
|
9
|
+
const { Page } = pageContext;
|
|
10
|
+
const pageHtml = PageLayout(Page);
|
|
11
|
+
document.getElementById("page-view")!.innerHTML = pageHtml;
|
|
12
|
+
}
|
|
13
|
+
hydrateCounters();
|
|
14
|
+
|
|
15
|
+
const title = getTitle(pageContext);
|
|
16
|
+
if (title !== null) {
|
|
17
|
+
document.title = title;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function hydrateCounters() {
|
|
22
|
+
document.querySelectorAll(".counter").forEach((counter) => {
|
|
23
|
+
let count = 0;
|
|
24
|
+
(counter as HTMLElement).onclick = () => {
|
|
25
|
+
counter.textContent = `Counter ${++count}`;
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default onRenderHtml;
|
|
2
|
+
|
|
3
|
+
import { escapeInject, dangerouslySkipEscape } from "vite-plugin-ssr/server";
|
|
4
|
+
import { PageLayout } from "./PageLayout";
|
|
5
|
+
import type { PageContextServer } from "./types";
|
|
6
|
+
|
|
7
|
+
async function onRenderHtml(pageContext: PageContextServer) {
|
|
8
|
+
const { Page } = pageContext;
|
|
9
|
+
const pageHtml = PageLayout(Page);
|
|
10
|
+
return escapeInject`<!DOCTYPE html>
|
|
11
|
+
<html>
|
|
12
|
+
<body>
|
|
13
|
+
<div id="page-view">${dangerouslySkipEscape(pageHtml)}</div>
|
|
14
|
+
</body>
|
|
15
|
+
</html>`;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default ["title"];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export { PageLayout };
|
|
2
|
+
|
|
3
|
+
import "./PageLayout.css";
|
|
4
|
+
|
|
5
|
+
function PageLayout(children: string) {
|
|
6
|
+
return Layout(
|
|
7
|
+
[
|
|
8
|
+
Sidebar(
|
|
9
|
+
// prettier-ignore
|
|
10
|
+
[
|
|
11
|
+
'<a class="navitem" href="/">Home</a>',
|
|
12
|
+
'<a class="navitem" href="/about">About</a>'
|
|
13
|
+
].join('\n')
|
|
14
|
+
),
|
|
15
|
+
Content(children),
|
|
16
|
+
].join("\n")
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function Layout(children: string) {
|
|
21
|
+
// prettier-ignore
|
|
22
|
+
return (
|
|
23
|
+
`<div
|
|
24
|
+
style="${[
|
|
25
|
+
'display: flex',
|
|
26
|
+
'max-width: 900px',
|
|
27
|
+
'margin: auto'
|
|
28
|
+
].join(';')}"
|
|
29
|
+
>
|
|
30
|
+
${children}
|
|
31
|
+
</div>`
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function Sidebar(children: string) {
|
|
36
|
+
// prettier-ignore
|
|
37
|
+
return (
|
|
38
|
+
`<div
|
|
39
|
+
style="${[
|
|
40
|
+
'padding: 20px',
|
|
41
|
+
'padding-top: 42px',
|
|
42
|
+
'flex-shrink: 0',
|
|
43
|
+
'display: flex',
|
|
44
|
+
'flex-direction: column',
|
|
45
|
+
'align-items: center',
|
|
46
|
+
'line-height: 1.8em',
|
|
47
|
+
].join(';')}"
|
|
48
|
+
>
|
|
49
|
+
${children}
|
|
50
|
+
</div>`
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function Content(children: string) {
|
|
55
|
+
// prettier-ignore
|
|
56
|
+
return (
|
|
57
|
+
`<div
|
|
58
|
+
style="${[
|
|
59
|
+
'padding: 20px',
|
|
60
|
+
'padding-bottom: 50px',
|
|
61
|
+
'border-left: 2px solid #eee',
|
|
62
|
+
'min-height: 100vh'
|
|
63
|
+
].join(';')}"
|
|
64
|
+
>
|
|
65
|
+
${children}
|
|
66
|
+
</div>`
|
|
67
|
+
)
|
|
68
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export { getTitle };
|
|
2
|
+
|
|
3
|
+
import type { ConfigEntries } from "vite-plugin-ssr/types";
|
|
4
|
+
|
|
5
|
+
function getTitle(pageContext: {
|
|
6
|
+
title?: unknown;
|
|
7
|
+
config: Record<string, unknown>;
|
|
8
|
+
configEntries: ConfigEntries;
|
|
9
|
+
}): null | string {
|
|
10
|
+
if (typeof pageContext.title === "string") {
|
|
11
|
+
return pageContext.title;
|
|
12
|
+
}
|
|
13
|
+
if (pageContext.title) {
|
|
14
|
+
throw new Error("pageContext.title should be a string");
|
|
15
|
+
}
|
|
16
|
+
const { title } = pageContext.config;
|
|
17
|
+
if (typeof title === "string") {
|
|
18
|
+
return title;
|
|
19
|
+
}
|
|
20
|
+
if (!title) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const { configDefinedAt } = pageContext.configEntries.title![0]!;
|
|
24
|
+
if (typeof title === "function") {
|
|
25
|
+
const val = title(pageContext);
|
|
26
|
+
if (typeof val === "string") {
|
|
27
|
+
return val;
|
|
28
|
+
}
|
|
29
|
+
if (val) {
|
|
30
|
+
throw new Error(configDefinedAt + " should return a string");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw new Error(configDefinedAt + " should be a string or a function returning a string");
|
|
34
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type { PageContextServer };
|
|
2
|
+
export type { PageContextClient };
|
|
3
|
+
export type { PageContext };
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
PageContextBuiltIn,
|
|
7
|
+
PageContextBuiltInClientWithClientRouting as PageContextBuiltInClient,
|
|
8
|
+
} from "vite-plugin-ssr/types";
|
|
9
|
+
|
|
10
|
+
type PageContextServer = PageContextBuiltIn;
|
|
11
|
+
type PageContextClient = PageContextBuiltInClient;
|
|
12
|
+
type PageContext = PageContextClient | PageContextServer;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export interface SimplePackageJson {
|
|
2
|
+
name: string;
|
|
3
|
+
version: string;
|
|
4
|
+
description: string;
|
|
5
|
+
type: "module";
|
|
6
|
+
scripts: Record<string, string>;
|
|
7
|
+
keywords: string[];
|
|
8
|
+
author: string;
|
|
9
|
+
devDependencies: Record<string, string>;
|
|
10
|
+
dependencies: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default function getPackageJson() {
|
|
14
|
+
const content: SimplePackageJson = {
|
|
15
|
+
name: "PLACEHOLDER",
|
|
16
|
+
version: "0.0.1",
|
|
17
|
+
description: "",
|
|
18
|
+
type: "module",
|
|
19
|
+
scripts: {
|
|
20
|
+
dev: "vite",
|
|
21
|
+
build: "vite build",
|
|
22
|
+
preview: "vite build && vite preview",
|
|
23
|
+
},
|
|
24
|
+
keywords: [],
|
|
25
|
+
author: "",
|
|
26
|
+
devDependencies: {
|
|
27
|
+
"@types/node": "^18.0.0",
|
|
28
|
+
typescript: "^5.0.0",
|
|
29
|
+
vite: "^4.0.0",
|
|
30
|
+
"vite-plugin-ssr": "^0.4.0",
|
|
31
|
+
},
|
|
32
|
+
dependencies: {},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
if (import.meta.VIKE_FRAMEWORK === "react") {
|
|
36
|
+
content.dependencies = {
|
|
37
|
+
"@vitejs/plugin-react": "^3.0.0",
|
|
38
|
+
react: "^18.0.0",
|
|
39
|
+
"react-dom": "^18.0.0",
|
|
40
|
+
};
|
|
41
|
+
content.devDependencies = {
|
|
42
|
+
"@types/react": "^18.0.0",
|
|
43
|
+
"@types/react-dom": "^18.0.0",
|
|
44
|
+
};
|
|
45
|
+
} else if (import.meta.VIKE_FRAMEWORK === "solid") {
|
|
46
|
+
content.dependencies = {
|
|
47
|
+
"solid-js": "^1.0.0",
|
|
48
|
+
};
|
|
49
|
+
content.devDependencies = {
|
|
50
|
+
"vite-plugin-solid": "^2.0.0",
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return content;
|
|
55
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default function getTsConfig() {
|
|
2
|
+
let content: Record<string, unknown> = {
|
|
3
|
+
compilerOptions: {
|
|
4
|
+
strict: true,
|
|
5
|
+
allowJs: true,
|
|
6
|
+
checkJs: true,
|
|
7
|
+
esModuleInterop: true,
|
|
8
|
+
forceConsistentCasingInFileNames: true,
|
|
9
|
+
resolveJsonModule: true,
|
|
10
|
+
skipLibCheck: true,
|
|
11
|
+
sourceMap: true,
|
|
12
|
+
module: "ESNext",
|
|
13
|
+
moduleResolution: "Node",
|
|
14
|
+
target: "ES2020",
|
|
15
|
+
lib: ["DOM", "DOM.Iterable", "ESNext"],
|
|
16
|
+
types: ["vite/client"],
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
if (import.meta.VIKE_FRAMEWORK === "react") {
|
|
21
|
+
content = { ...content, jsx: "react" };
|
|
22
|
+
} else if (import.meta.VIKE_FRAMEWORK === "solid") {
|
|
23
|
+
content = { ...content, jsx: "preserve", jsxImportSource: "solid-js" };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return content;
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import ssr from "vite-plugin-ssr/plugin";
|
|
2
|
+
import react from "@vitejs/plugin-react";
|
|
3
|
+
import solid from "vite-plugin-solid";
|
|
4
|
+
import { defineConfig } from "vite";
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
plugins: [
|
|
8
|
+
...(import.meta.VIKE_FRAMEWORK === "react" ? [react()] : import.meta.VIKE_FRAMEWORK === "solid" ? [solid()] : []),
|
|
9
|
+
ssr(),
|
|
10
|
+
],
|
|
11
|
+
});
|
package/global.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface VikeMeta {
|
|
2
|
+
VIKE_REMOVE?: undefined;
|
|
3
|
+
VIKE_FRAMEWORK?: "react" | "solid" | "vue";
|
|
4
|
+
VIKE_DATABASE?: "edgedb" | "prisma" | string;
|
|
5
|
+
VIKE_AUTH?: "authjs" | string;
|
|
6
|
+
VIKE_ERROR_TRACKING?: "logrocket" | "sentry" | string;
|
|
7
|
+
VIKE_TYPESCRIPT?: boolean;
|
|
8
|
+
VIKE_CLIENT_ROUTING?: boolean;
|
|
9
|
+
VIKE_RPC?: "telefunc" | "trpc";
|
|
10
|
+
VIKE_PRERENDERING?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface ImportMeta extends VikeMeta {}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@batijs/build",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [],
|
|
7
|
+
"author": "",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/node": "^16.0.0",
|
|
11
|
+
"@vitejs/plugin-react": "^3.1.0",
|
|
12
|
+
"solid-js": "^1.7.2",
|
|
13
|
+
"tsup": "^6.7.0",
|
|
14
|
+
"tsx": "^3.12.6",
|
|
15
|
+
"uvu": "^0.5.6",
|
|
16
|
+
"vite": "^4.2.1",
|
|
17
|
+
"vite-plugin-solid": "^2.7.0",
|
|
18
|
+
"vite-plugin-ssr": "^0.4.111"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@babel/parser": "^7.21.4",
|
|
22
|
+
"recast": "^0.22.0",
|
|
23
|
+
"typescript": "^5.0.3"
|
|
24
|
+
},
|
|
25
|
+
"main": "./dist/exec.js",
|
|
26
|
+
"module": "./dist/exec.js",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": "./dist/exec.js"
|
|
29
|
+
},
|
|
30
|
+
"typesVersions": {
|
|
31
|
+
"*": {
|
|
32
|
+
".": [
|
|
33
|
+
"./dist/exec.d.ts"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist/",
|
|
39
|
+
"files/",
|
|
40
|
+
"global.d.ts"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"test": "tsx node_modules/uvu/bin.js tests",
|
|
44
|
+
"build": "tsup"
|
|
45
|
+
}
|
|
46
|
+
}
|