@evjs/create-app 0.3.1 → 0.3.3

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 CHANGED
@@ -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` are never copied from
50
- templates and should remain ignored by source control.
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 extension data
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
 
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { runCreateAppCli } from "../dist/index.js";
3
+
4
+ try {
5
+ await runCreateAppCli(process.argv);
6
+ } catch (error) {
7
+ console.error(error);
8
+ process.exitCode = 1;
9
+ }
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.1",
3
+ "version": "0.3.3",
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": "dist/index.js"
16
+ "create-evjs-app": "bin/create-evjs-app.js"
17
17
  },
18
18
  "files": [
19
+ "bin",
19
20
  "dist",
20
21
  "templates"
21
22
  ],
@@ -0,0 +1,5 @@
1
+ .ev
2
+ .evjs
3
+ .turbopack
4
+ route-types.d.ts
5
+ plugin-types.d.ts
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-api-routes",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -0,0 +1,5 @@
1
+ .ev
2
+ .evjs
3
+ .turbopack
4
+ route-types.d.ts
5
+ plugin-types.d.ts
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-basic",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -0,0 +1,5 @@
1
+ .ev
2
+ .evjs
3
+ .turbopack
4
+ route-types.d.ts
5
+ plugin-types.d.ts
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-complex-routing",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -0,0 +1,5 @@
1
+ .ev
2
+ .evjs
3
+ .turbopack
4
+ route-types.d.ts
5
+ plugin-types.d.ts
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-custom-ws-transport",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -0,0 +1,5 @@
1
+ .ev
2
+ .evjs
3
+ .turbopack
4
+ route-types.d.ts
5
+ plugin-types.d.ts
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-mpa",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -1,34 +1,38 @@
1
1
  # plugin-authoring
2
2
 
3
- Demonstrates one evjs plugin API combining Application, Page, Route, and
4
- Document extension declarations with the lifecycle hooks used by ordinary
5
- build-time extensions.
6
-
7
- - **top-level `extensions`** — author static, namespaced Application data
8
- - **`page.config.ts`** — author static, namespaced Page and unique-Route data
9
- - **one extension registry** — register Application, Page, Route, and Document owners of one namespace
10
- - **`setup`** — read the resolved Application value before graph analysis
11
- - **`contributions`** — read all four resolved owner bags from semantic graph views
12
- - **`config`** — update framework config before defaults are resolved
13
- - **`bundlerConfig`** — modify the underlying bundler config (type-safe via `utoopack()` helper)
14
- - **`buildStart`** — run logic before compilation begins
15
- - **`buildEnd`** — run logic after compilation completes
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
- Plugins use one `Plugin` shape: declare static capabilities in `describe()` and
22
- add semantic contributions through the corresponding framework APIs.
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.
23
28
 
24
- The application itself uses the canonical model:
29
+ The application itself uses the unified Core 0.3 model:
25
30
  `src/pages/page.tsx` defines `/`, `src/pages/layout.tsx` supplies the SPA root
26
- layout, `ev.config.ts` configures the Application extension, and
27
- `src/pages/page.config.ts` configures the Page and its unique Route. The
28
- Document declaration supplies a default for the SPA's Application-owned
29
- Document; a CSR SPA Page does not own a separate Document. All four owners use
30
- the same `@example/metadata` namespace and schema version. These build-time
31
- 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.
32
36
 
33
37
  ## Run
34
38
 
@@ -38,8 +42,8 @@ npm run dev
38
42
 
39
43
  ## What to look for
40
44
 
41
- 1. The resolved Application `@example/metadata` value in `setup`
42
- 2. The resolved Page, Route, and Document `@example/metadata` values in `contributions`
43
- 3. Console output from `buildStart` and `buildEnd` hooks during build
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
44
48
  4. The `<!-- Built with evjs | file.html | N asset(s) -->` comment in the output HTML (injected by `transformHtml`)
45
- 5. The type-safe `.txt` rule declaration in the `bundlerConfig` hook
49
+ 5. The type-safe `.txt` rule declaration in the `configureBundler` hook
@@ -0,0 +1,5 @@
1
+ .ev
2
+ .evjs
3
+ .turbopack
4
+ route-types.d.ts
5
+ plugin-types.d.ts
@@ -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
- name: "example-metadata-plugin",
7
- describe(api) {
8
- api.applicationExtension<
9
- { enabled: boolean; channel: string },
10
- { enabled?: boolean }
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.config.extensions["@example/metadata"];
21
+ const metadata = ctx.options;
37
22
  console.log(
38
23
  `[example-metadata-plugin] Application value: ${JSON.stringify(metadata)}`,
39
24
  );
40
25
  },
41
- contributions(ctx) {
42
- for (const page of ctx.framework.pages) {
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] Document ${document.id}: ${JSON.stringify(metadata)}`,
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
- * - `config` — update framework config before defaults are resolved
68
- * - `bundlerConfig` — modify the underlying bundler config (type-safe via utoopack() helper)
69
- * - `buildStart` — run logic before compilation begins
70
- * - `buildEnd` — run logic after compilation completes
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
- extensions: {
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.1",
3
+ "version": "0.3.3",
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
- extensions: {
5
- "@example/metadata": {
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
  });
@@ -0,0 +1,10 @@
1
+ .ev
2
+ .evjs
3
+ .turbopack
4
+ route-types.d.ts
5
+ plugin-types.d.ts
6
+
7
+ # SQLite databases
8
+ *.db
9
+ *.db-shm
10
+ *.db-wal
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-with-sqlite",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -0,0 +1,5 @@
1
+ .ev
2
+ .evjs
3
+ .turbopack
4
+ route-types.d.ts
5
+ plugin-types.d.ts
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-with-tailwind",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -0,0 +1,5 @@
1
+ .ev
2
+ .evjs
3
+ .turbopack
4
+ route-types.d.ts
5
+ plugin-types.d.ts
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-with-trpc",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",