@evjs/create-app 0.3.0 → 0.3.2
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 +8 -5
- package/bin/create-evjs-app.js +9 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +32 -13
- package/package.json +3 -2
- package/templates/api-routes/_gitignore +5 -0
- package/templates/api-routes/package.json +1 -1
- package/templates/basic/README.md +4 -7
- package/templates/basic/_gitignore +5 -0
- package/templates/basic/package.json +1 -1
- package/templates/complex-routing/README.md +5 -5
- package/templates/complex-routing/_gitignore +5 -0
- package/templates/complex-routing/package.json +1 -1
- package/templates/custom-ws-transport/README.md +8 -3
- package/templates/custom-ws-transport/_gitignore +5 -0
- package/templates/custom-ws-transport/package.json +1 -1
- package/templates/mpa/README.md +3 -7
- package/templates/mpa/_gitignore +5 -0
- package/templates/mpa/package.json +1 -1
- package/templates/plugin-authoring/README.md +29 -27
- package/templates/plugin-authoring/_gitignore +5 -0
- package/templates/plugin-authoring/ev.config.ts +77 -109
- package/templates/plugin-authoring/package.json +2 -2
- package/templates/plugin-authoring/src/pages/page.config.ts +2 -9
- package/templates/with-sqlite/_gitignore +10 -0
- package/templates/with-sqlite/package.json +1 -1
- package/templates/with-tailwind/README.md +1 -1
- package/templates/with-tailwind/_gitignore +5 -0
- package/templates/with-tailwind/package.json +1 -1
- package/templates/with-trpc/README.md +3 -2
- package/templates/with-trpc/_gitignore +5 -0
- package/templates/with-trpc/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npx @evjs/create-app [name] [options]
|
|
|
20
20
|
|
|
21
21
|
## Templates
|
|
22
22
|
|
|
23
|
-
Every template uses the same
|
|
23
|
+
Every template uses the same Page-and-Route authoring model: `page.tsx` anchors,
|
|
24
24
|
optional build-time `page.config.ts` for static title/named metadata and
|
|
25
25
|
rendering, and directory-derived URLs.
|
|
26
26
|
`routing.mode` is the only routing-mode configuration; SPA and MPA
|
|
@@ -46,12 +46,15 @@ npx @evjs/create-app my-new-app
|
|
|
46
46
|
|
|
47
47
|
Follow the interactive prompts to select your features and get started in seconds.
|
|
48
48
|
|
|
49
|
-
Generated framework files such as `src/route-types.d.ts`
|
|
50
|
-
templates and
|
|
49
|
+
Generated framework files such as `src/route-types.d.ts` and
|
|
50
|
+
`src/plugin-types.d.ts` are never copied from templates and remain ignored by
|
|
51
|
+
source control. They deliberately live under `src` rather than `.ev`: standard
|
|
52
|
+
project TypeScript configs include `src`, while `.ev` is generated framework IR
|
|
53
|
+
and is normally outside the TypeScript program.
|
|
51
54
|
|
|
52
55
|
`page.config.ts` is evaluated by evjs during graph construction. It is not a
|
|
53
|
-
browser entry: plugins must explicitly project any configured
|
|
54
|
-
that their runtime needs.
|
|
56
|
+
browser entry: plugins must explicitly project any configured Page plugin
|
|
57
|
+
settings that their runtime needs.
|
|
55
58
|
|
|
56
59
|
## License
|
|
57
60
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
export declare function shouldCopyTemplatePath(src: string): boolean;
|
|
2
|
+
export declare function withGeneratedFrameworkIgnores(source: string): string;
|
|
3
|
+
export declare function restoreScaffoldGitignore(targetDir: string): void;
|
|
3
4
|
export declare function runCreateAppCli(argv?: string[]): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
import fs from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import { fileURLToPath } from "node:url";
|
|
@@ -15,12 +14,43 @@ const templateCopyExcludedBasenames = new Set([
|
|
|
15
14
|
".ev",
|
|
16
15
|
".evjs",
|
|
17
16
|
"route-types.d.ts",
|
|
17
|
+
"plugin-types.d.ts",
|
|
18
18
|
]);
|
|
19
|
+
const generatedFrameworkTypeFiles = [
|
|
20
|
+
"route-types.d.ts",
|
|
21
|
+
"plugin-types.d.ts",
|
|
22
|
+
];
|
|
23
|
+
const packagedTemplateGitignore = "_gitignore";
|
|
19
24
|
export function shouldCopyTemplatePath(src) {
|
|
20
25
|
return !src
|
|
21
26
|
.split(/[\\/]+/)
|
|
22
27
|
.some((segment) => templateCopyExcludedBasenames.has(segment));
|
|
23
28
|
}
|
|
29
|
+
export function withGeneratedFrameworkIgnores(source) {
|
|
30
|
+
const lineEnding = source.includes("\r\n") ? "\r\n" : "\n";
|
|
31
|
+
const ignoredPaths = new Set(source.split(/\r?\n/));
|
|
32
|
+
const missing = generatedFrameworkTypeFiles.filter((file) => !ignoredPaths.has(file));
|
|
33
|
+
if (missing.length === 0)
|
|
34
|
+
return source;
|
|
35
|
+
const separator = source.length === 0 || /\r?\n$/.test(source) ? "" : lineEnding;
|
|
36
|
+
return `${source}${separator}${missing.join(lineEnding)}${lineEnding}`;
|
|
37
|
+
}
|
|
38
|
+
export function restoreScaffoldGitignore(targetDir) {
|
|
39
|
+
const gitignorePath = path.join(targetDir, ".gitignore");
|
|
40
|
+
const packagedGitignorePath = path.join(targetDir, packagedTemplateGitignore);
|
|
41
|
+
let sourcePath = gitignorePath;
|
|
42
|
+
if (fs.existsSync(packagedGitignorePath)) {
|
|
43
|
+
sourcePath = packagedGitignorePath;
|
|
44
|
+
}
|
|
45
|
+
else if (!fs.existsSync(gitignorePath)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const source = fs.readFileSync(sourcePath, "utf-8");
|
|
49
|
+
fs.writeFileSync(gitignorePath, withGeneratedFrameworkIgnores(source));
|
|
50
|
+
if (sourcePath === packagedGitignorePath) {
|
|
51
|
+
fs.rmSync(packagedGitignorePath);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
24
54
|
export async function runCreateAppCli(argv = process.argv) {
|
|
25
55
|
const program = new Command();
|
|
26
56
|
program
|
|
@@ -94,6 +124,7 @@ export async function runCreateAppCli(argv = process.argv) {
|
|
|
94
124
|
dereference: true,
|
|
95
125
|
filter: shouldCopyTemplatePath,
|
|
96
126
|
});
|
|
127
|
+
restoreScaffoldGitignore(targetDir);
|
|
97
128
|
// Post-process package.json: sync @evjs/* versions and set project name
|
|
98
129
|
const pkgPath = path.join(targetDir, "package.json");
|
|
99
130
|
if (fs.existsSync(pkgPath)) {
|
|
@@ -122,15 +153,3 @@ export async function runCreateAppCli(argv = process.argv) {
|
|
|
122
153
|
});
|
|
123
154
|
await program.parseAsync(argv);
|
|
124
155
|
}
|
|
125
|
-
function isDirectExecution() {
|
|
126
|
-
const invokedPath = process.argv[1];
|
|
127
|
-
if (!invokedPath)
|
|
128
|
-
return false;
|
|
129
|
-
return path.resolve(invokedPath) === fileURLToPath(import.meta.url);
|
|
130
|
-
}
|
|
131
|
-
if (isDirectExecution()) {
|
|
132
|
-
runCreateAppCli().catch((error) => {
|
|
133
|
-
console.error(error);
|
|
134
|
-
process.exit(1);
|
|
135
|
-
});
|
|
136
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evjs/create-app",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Scaffold a new evjs project",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
|
-
"create-evjs-app": "
|
|
16
|
+
"create-evjs-app": "bin/create-evjs-app.js"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
|
+
"bin",
|
|
19
20
|
"dist",
|
|
20
21
|
"templates"
|
|
21
22
|
],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# basic
|
|
2
2
|
|
|
3
3
|
The standard starting point for an evjs application. It demonstrates the
|
|
4
|
-
|
|
4
|
+
Page-and-Route file convention alongside server functions.
|
|
5
5
|
|
|
6
6
|
## Run
|
|
7
7
|
|
|
@@ -38,9 +38,6 @@ npm run dev
|
|
|
38
38
|
- `useMutation({ mutationFn: createUser })` for server-side mutations
|
|
39
39
|
- `getFnQueryKey(getUsers)` for cache invalidation
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
route component to its URL directory as `page.tsx`, use
|
|
45
|
-
`routing.mode: "spa"`. Explicit `component`/`routes` config does not define an
|
|
46
|
-
MPA materialization mode.
|
|
41
|
+
This example uses the canonical `routing.mode: "spa"` file-convention profile.
|
|
42
|
+
Explicit `application.routes` is a separate SPA-only input into the same
|
|
43
|
+
normalized graph.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# complex-routing
|
|
2
2
|
|
|
3
|
-
Advanced SPA routing through the same
|
|
3
|
+
Advanced SPA routing through the same Page-and-Route file convention
|
|
4
4
|
used by the basic example.
|
|
5
5
|
|
|
6
6
|
## Run
|
|
@@ -29,7 +29,7 @@ npm run dev
|
|
|
29
29
|
- Redirects through the `/old-blog` Page lifecycle
|
|
30
30
|
- Page hooks such as `usePageParams()` and `usePageSearch()`
|
|
31
31
|
|
|
32
|
-
This example
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
This example uses SPA mode because MPA rejects its dynamic route and
|
|
33
|
+
router-only React facets. Canonical SPA and MPA apps share the same `page.tsx`
|
|
34
|
+
Page-anchor convention; `routing.mode` selects how supported Pages are
|
|
35
|
+
materialized.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# custom-ws-transport
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Client-side `TransportAdapter` example for sending server-function calls over
|
|
4
|
+
WebSocket. This repository does not provide the matching WebSocket server.
|
|
4
5
|
|
|
5
6
|
## Run
|
|
6
7
|
|
|
@@ -8,6 +9,10 @@ Custom WebSocket transport for server function calls.
|
|
|
8
9
|
npm run dev
|
|
9
10
|
```
|
|
10
11
|
|
|
12
|
+
The page shell runs locally, but server-function calls require a same-origin
|
|
13
|
+
`/ws` endpoint that accepts the documented `{ id, fnId, args }` messages and
|
|
14
|
+
returns `{ id, result }` or `{ id, error }`.
|
|
15
|
+
|
|
11
16
|
## Key Files
|
|
12
17
|
|
|
13
18
|
| File | Purpose |
|
|
@@ -22,6 +27,6 @@ npm run dev
|
|
|
22
27
|
|
|
23
28
|
- Custom `TransportAdapter` over WebSocket
|
|
24
29
|
- `initTransport({ adapter: { send } })` extension
|
|
25
|
-
-
|
|
26
|
-
-
|
|
30
|
+
- Request correlation and pending-call cleanup for a custom client protocol
|
|
31
|
+
- The client message contract a matching WebSocket server must implement
|
|
27
32
|
- Transport setup inside the root Page scope
|
package/templates/mpa/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Unified MPA
|
|
2
2
|
|
|
3
|
-
Minimal
|
|
3
|
+
Minimal multi-page application using the same `page.tsx` file
|
|
4
4
|
convention as SPA applications.
|
|
5
5
|
|
|
6
6
|
## Run
|
|
@@ -50,9 +50,5 @@ npm run build
|
|
|
50
50
|
- No `@evjs/client`, `@evjs/server`, or generated `route-types.d.ts`
|
|
51
51
|
dependency is needed for this router-free client output
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
fields, and move remaining plugin-owned values to namespaced extensions.
|
|
56
|
-
Core discovers only canonical Page anchors. Explicit `component`/`routes`
|
|
57
|
-
config remains a SPA-only route-tree input and is not accepted as an MPA
|
|
58
|
-
authoring model.
|
|
53
|
+
Explicit `component`/`routes` config is a SPA-only route-tree input and is not
|
|
54
|
+
accepted as an MPA authoring model.
|
|
@@ -1,36 +1,38 @@
|
|
|
1
1
|
# plugin-authoring
|
|
2
2
|
|
|
3
|
-
Demonstrates
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
- **`
|
|
9
|
-
-
|
|
10
|
-
- **`
|
|
11
|
-
- **`
|
|
12
|
-
- **`
|
|
13
|
-
- **`
|
|
14
|
-
- **`
|
|
15
|
-
- **`
|
|
3
|
+
Demonstrates the typed evjs plugin factory together with ordinary build-time
|
|
4
|
+
lifecycle hooks.
|
|
5
|
+
|
|
6
|
+
- **`definePlugin()`** — declare one stable, short `id` for every plugin-owned surface and return an installable factory
|
|
7
|
+
- **`pluginOptions()`** — declare independent, type-safe Application and Page contracts
|
|
8
|
+
- **`plugins: [metadataPlugin(config)]`** — install and configure the Application in one expression
|
|
9
|
+
- **`page.config.ts#plugins.metadata`** — configure a Page with the same plugin `id` and no plugin import
|
|
10
|
+
- **`src/plugin-types.d.ts`** — generated by evjs as a stable bridge to the static `ev.config.ts` type for Page editor types
|
|
11
|
+
- **`setup`** — read the resolved Application setting before graph analysis
|
|
12
|
+
- **`emitIR`** — iterate only enabled, typed Page settings
|
|
13
|
+
- **`configure`** — update framework config before defaults are resolved
|
|
14
|
+
- **`configureBundler`** — modify the underlying bundler config (type-safe via `utoopack()` helper)
|
|
15
|
+
- **`beforeBuild`** — run after fresh bundler facts, before canonical output is linked
|
|
16
|
+
- **`afterBuild`** — run after canonical output is published
|
|
16
17
|
- **`transformHtml`** — modify the parsed HTML document after asset injection with current HTML context
|
|
17
18
|
|
|
18
19
|
For plugins that need to declare generated `.ev` artifacts and attach them to
|
|
19
20
|
framework slots, see the generated contributions documentation.
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
Application and Page settings do not merge with each other. Within either
|
|
23
|
+
contract, authored fields are deeply merged over that contract's defaults
|
|
24
|
+
before validation. Because this example installs `metadataPlugin()` normally
|
|
25
|
+
and declares Page defaults, omitting `metadata` uses those defaults. A Page may
|
|
26
|
+
use `metadata: false` to disable the plugin or an object to override the
|
|
27
|
+
defaults; `metadata: true` selects the defaults explicitly.
|
|
25
28
|
|
|
26
29
|
The application itself uses the unified Core 0.3 model:
|
|
27
30
|
`src/pages/page.tsx` defines `/`, `src/pages/layout.tsx` supplies the SPA root
|
|
28
|
-
layout, `ev.config.ts`
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
values are not automatically serialized into browser runtime.
|
|
31
|
+
layout, `ev.config.ts` installs both factories, and `src/pages/page.config.ts`
|
|
32
|
+
configures Page behavior. Route and Document effects, when needed, are derived
|
|
33
|
+
from enabled Pages by plugin contributions rather than configured through
|
|
34
|
+
separate owner bags. Page plugin settings are build-time graph values and are
|
|
35
|
+
not automatically serialized into browser runtime.
|
|
34
36
|
|
|
35
37
|
## Run
|
|
36
38
|
|
|
@@ -40,8 +42,8 @@ npm run dev
|
|
|
40
42
|
|
|
41
43
|
## What to look for
|
|
42
44
|
|
|
43
|
-
1. The resolved Application
|
|
44
|
-
2. The
|
|
45
|
-
3. Console output from `
|
|
45
|
+
1. The resolved Application metadata value in `setup`
|
|
46
|
+
2. The enabled, typed Page metadata values in `emitIR`
|
|
47
|
+
3. Console output from `beforeBuild` and `afterBuild` hooks during build
|
|
46
48
|
4. The `<!-- Built with evjs | file.html | N asset(s) -->` comment in the output HTML (injected by `transformHtml`)
|
|
47
|
-
5. The type-safe `.txt` rule declaration in the `
|
|
49
|
+
5. The type-safe `.txt` rule declaration in the `configureBundler` hook
|
|
@@ -1,133 +1,101 @@
|
|
|
1
1
|
import { merge, utoopack } from "@evjs/bundler-utoopack";
|
|
2
2
|
import { defineConfig } from "@evjs/ev";
|
|
3
|
-
import { definePlugin } from "@evjs/ev/plugin";
|
|
3
|
+
import { definePlugin, pluginOptions } from "@evjs/ev/plugin";
|
|
4
|
+
|
|
5
|
+
type ApplicationMetadata = {
|
|
6
|
+
channel: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type PageMetadata = {
|
|
10
|
+
label: string;
|
|
11
|
+
};
|
|
4
12
|
|
|
5
13
|
const metadataPlugin = definePlugin({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
namespace: "@example/metadata",
|
|
13
|
-
schemaVersion: "1",
|
|
14
|
-
defaults: { enabled: false, channel: "web" },
|
|
15
|
-
});
|
|
16
|
-
api.pageExtension({
|
|
17
|
-
namespace: "@example/metadata",
|
|
18
|
-
schemaVersion: "1",
|
|
19
|
-
defaults: { label: "Plugin authoring Page" },
|
|
20
|
-
});
|
|
21
|
-
api.routeExtension({
|
|
22
|
-
namespace: "@example/metadata",
|
|
23
|
-
schemaVersion: "1",
|
|
24
|
-
defaults: ({ routeId }) => ({ label: `Route ${routeId}` }),
|
|
25
|
-
});
|
|
26
|
-
api.documentExtension({
|
|
27
|
-
namespace: "@example/metadata",
|
|
28
|
-
schemaVersion: "1",
|
|
29
|
-
defaults: ({ output }) => ({
|
|
30
|
-
label: `Document ${output}`,
|
|
31
|
-
theme: "light",
|
|
32
|
-
}),
|
|
33
|
-
});
|
|
34
|
-
},
|
|
14
|
+
id: "metadata",
|
|
15
|
+
application: pluginOptions<ApplicationMetadata>({ schemaVersion: "1" }),
|
|
16
|
+
page: pluginOptions<PageMetadata>({
|
|
17
|
+
schemaVersion: "1",
|
|
18
|
+
defaults: { label: "Plugin authoring Page" },
|
|
19
|
+
}),
|
|
35
20
|
setup(ctx) {
|
|
36
|
-
const metadata = ctx.
|
|
21
|
+
const metadata = ctx.options;
|
|
37
22
|
console.log(
|
|
38
23
|
`[example-metadata-plugin] Application value: ${JSON.stringify(metadata)}`,
|
|
39
24
|
);
|
|
40
25
|
},
|
|
41
|
-
|
|
42
|
-
for (const page of ctx.
|
|
43
|
-
const metadata = page.extensions["@example/metadata"];
|
|
44
|
-
console.log(
|
|
45
|
-
`[example-metadata-plugin] Page ${page.id}: ${JSON.stringify(metadata)}`,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
for (const route of ctx.framework.routes) {
|
|
49
|
-
const metadata = route.extensions["@example/metadata"];
|
|
50
|
-
console.log(
|
|
51
|
-
`[example-metadata-plugin] Route ${route.id}: ${JSON.stringify(metadata)}`,
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
for (const document of ctx.framework.documents) {
|
|
55
|
-
const metadata = document.extensions["@example/metadata"];
|
|
26
|
+
emitIR(ctx) {
|
|
27
|
+
for (const { page, options } of ctx.pages) {
|
|
56
28
|
console.log(
|
|
57
|
-
`[example-metadata-plugin]
|
|
29
|
+
`[example-metadata-plugin] Page ${page.id}: ${JSON.stringify(options)}`,
|
|
58
30
|
);
|
|
59
31
|
}
|
|
60
32
|
},
|
|
61
33
|
});
|
|
62
34
|
|
|
35
|
+
const txtPlugin = definePlugin({
|
|
36
|
+
id: "txt",
|
|
37
|
+
configure(config) {
|
|
38
|
+
config.server = {
|
|
39
|
+
...(typeof config.server === "object" ? config.server : {}),
|
|
40
|
+
basePath: "/api",
|
|
41
|
+
};
|
|
42
|
+
return config;
|
|
43
|
+
},
|
|
44
|
+
setup(ctx) {
|
|
45
|
+
console.log(`[example-txt-plugin] mode: ${ctx.mode}`);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
beforeBuild({ isRebuild }) {
|
|
49
|
+
console.log(
|
|
50
|
+
`[example-txt-plugin] ${isRebuild ? "rebuild" : "build"} output starting...`,
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
// Type-safe bundler config mutation via the utoopack helper.
|
|
55
|
+
// This hook only runs when utoopack is the active bundler.
|
|
56
|
+
configureBundler: utoopack((cfg) => {
|
|
57
|
+
// Add custom loaders or rules to utoopack
|
|
58
|
+
merge(cfg, {
|
|
59
|
+
module: { rules: { ".txt": { type: "raw" } } },
|
|
60
|
+
});
|
|
61
|
+
}),
|
|
62
|
+
|
|
63
|
+
afterBuild(result) {
|
|
64
|
+
const appAssets = Object.values(result.output.apps);
|
|
65
|
+
const pageAssets = Object.values(result.output.pages);
|
|
66
|
+
const jsCount = [...appAssets, ...pageAssets].reduce(
|
|
67
|
+
(count, entry) => count + entry.assets.js.length,
|
|
68
|
+
0,
|
|
69
|
+
);
|
|
70
|
+
console.log(
|
|
71
|
+
`[example-txt-plugin] build complete — ${jsCount} JS asset(s)`,
|
|
72
|
+
);
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
// Modify the parsed HTML document after evjs injects script/link tags
|
|
76
|
+
transformHtml(doc, ctx) {
|
|
77
|
+
const assetCount = ctx.assets.js.length + ctx.assets.css.length;
|
|
78
|
+
|
|
79
|
+
const comment = doc.createComment(
|
|
80
|
+
` Built with evjs | ${ctx.fileName} | ${assetCount} asset(s) `,
|
|
81
|
+
);
|
|
82
|
+
doc.head?.appendChild(comment);
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
63
88
|
/**
|
|
64
89
|
* Example: evjs plugin system.
|
|
65
90
|
*
|
|
66
91
|
* Demonstrates common lifecycle hooks:
|
|
67
|
-
* - `
|
|
68
|
-
* - `
|
|
69
|
-
* - `
|
|
70
|
-
* - `
|
|
92
|
+
* - `configure` — update framework config before defaults are resolved
|
|
93
|
+
* - `configureBundler` — modify the underlying bundler config (type-safe via utoopack() helper)
|
|
94
|
+
* - `beforeBuild` — run after fresh bundler facts, before canonical output
|
|
95
|
+
* - `afterBuild` — run after canonical output is published
|
|
71
96
|
* - `transformHtml` — modify the output HTML document after asset injection
|
|
72
97
|
*/
|
|
73
98
|
export default defineConfig({
|
|
74
99
|
routing: { mode: "spa" },
|
|
75
|
-
|
|
76
|
-
"@example/metadata": {
|
|
77
|
-
enabled: true,
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
plugins: [
|
|
81
|
-
metadataPlugin,
|
|
82
|
-
{
|
|
83
|
-
name: "example-txt-plugin",
|
|
84
|
-
config(config) {
|
|
85
|
-
config.server = {
|
|
86
|
-
...(typeof config.server === "object" ? config.server : {}),
|
|
87
|
-
basePath: "/api",
|
|
88
|
-
};
|
|
89
|
-
return config;
|
|
90
|
-
},
|
|
91
|
-
setup(ctx) {
|
|
92
|
-
console.log(`[example-txt-plugin] mode: ${ctx.mode}`);
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
buildStart() {
|
|
96
|
-
console.log("[example-txt-plugin] build starting...");
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
// Type-safe bundler config mutation via the utoopack helper.
|
|
100
|
-
// This hook only runs when utoopack is the active bundler.
|
|
101
|
-
bundlerConfig: utoopack((cfg) => {
|
|
102
|
-
// Add custom loaders or rules to utoopack
|
|
103
|
-
merge(cfg, {
|
|
104
|
-
module: { rules: { ".txt": { type: "raw" } } },
|
|
105
|
-
});
|
|
106
|
-
}),
|
|
107
|
-
|
|
108
|
-
buildEnd(result) {
|
|
109
|
-
const appAssets = Object.values(result.output.apps);
|
|
110
|
-
const pageAssets = Object.values(result.output.pages);
|
|
111
|
-
const jsCount = [...appAssets, ...pageAssets].reduce(
|
|
112
|
-
(count, entry) => count + entry.assets.js.length,
|
|
113
|
-
0,
|
|
114
|
-
);
|
|
115
|
-
console.log(
|
|
116
|
-
`[example-txt-plugin] build complete — ${jsCount} JS asset(s)`,
|
|
117
|
-
);
|
|
118
|
-
},
|
|
119
|
-
|
|
120
|
-
// Modify the parsed HTML document after evjs injects script/link tags
|
|
121
|
-
transformHtml(doc, ctx) {
|
|
122
|
-
const assetCount = ctx.assets.js.length + ctx.assets.css.length;
|
|
123
|
-
|
|
124
|
-
const comment = doc.createComment(
|
|
125
|
-
` Built with evjs | ${ctx.fileName} | ${assetCount} asset(s) `,
|
|
126
|
-
);
|
|
127
|
-
doc.head?.appendChild(comment);
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
],
|
|
100
|
+
plugins: [metadataPlugin({ channel: "web" }), txtPlugin()],
|
|
133
101
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "example-plugin-authoring",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "ev dev",
|
|
7
7
|
"build": "ev build",
|
|
8
|
-
"check-types": "tsc --noEmit"
|
|
8
|
+
"check-types": "ev prepare && tsc --noEmit"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@evjs/ev": "*",
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { definePageConfig } from "@evjs/ev";
|
|
2
2
|
|
|
3
3
|
export default definePageConfig({
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
plugins: {
|
|
5
|
+
metadata: {
|
|
6
6
|
label: "Configured by page.config.ts",
|
|
7
7
|
},
|
|
8
8
|
},
|
|
9
|
-
route: {
|
|
10
|
-
extensions: {
|
|
11
|
-
"@example/metadata": {
|
|
12
|
-
label: "Configured for the home Route",
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
9
|
});
|
|
@@ -15,10 +15,11 @@ npm run dev
|
|
|
15
15
|
| `ev.config.ts` | Selects SPA routing mode |
|
|
16
16
|
| `src/pages/layout.tsx` | File-convention root layout |
|
|
17
17
|
| `src/pages/page.tsx` | UI consuming both tRPC and evjs APIs |
|
|
18
|
-
| `src/
|
|
18
|
+
| `src/trpc.ts` | tRPC router and procedure definitions |
|
|
19
|
+
| `src/apis/trpc.server.ts` | Server-function dispatcher bridge into the tRPC router |
|
|
19
20
|
|
|
20
21
|
## What It Demonstrates
|
|
21
22
|
|
|
22
23
|
- tRPC client + server alongside evjs server functions
|
|
23
|
-
-
|
|
24
|
+
- A `"use server"` bridge dispatching calls into an `@trpc/server` router
|
|
24
25
|
- Both APIs coexist in the same build pipeline
|