@openelement/create 1.0.0-alpha.13 → 1.0.0-alpha.15
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 +49 -19
- package/package.json +1 -1
- package/src/cli.js +159 -76
- package/src/node-version.js +102 -0
- package/src/pm.js +143 -9
- package/src/template-builder.js +59 -6
- package/src/version.js +2 -10
- package/templates/.node-version +1 -0
- package/templates/AGENTS.md.tmpl +44 -0
- package/templates/README.tmpl +140 -74
- package/templates/app/components/page-404.css +5 -7
- package/templates/app/components/page-404.tsx.tmpl +16 -37
- package/templates/app/components/page-about.css +5 -15
- package/templates/app/components/page-about.tsx.tmpl +86 -82
- package/templates/app/components/page-home.css +5 -23
- package/templates/app/components/page-home.tsx.tmpl +137 -114
- package/templates/app/components/site-chrome.css +5 -15
- package/templates/app/head.tsx.tmpl +12 -23
- package/templates/app/islands/live-timer.css +5 -9
- package/templates/app/islands/live-timer.tsx.tmpl +31 -21
- package/templates/app/islands/my-counter.css +5 -11
- package/templates/app/islands/my-counter.tsx.tmpl +26 -13
- package/templates/app/layout.tsx.tmpl +68 -0
- package/templates/app/routes/404.tsx.tmpl +7 -10
- package/templates/app/routes/about.tsx.tmpl +4 -4
- package/templates/app/routes/api/ping.ts.tmpl +4 -5
- package/templates/app/routes/index.tsx.tmpl +4 -4
- package/templates/app/styles/theme.css +64 -79
- package/templates/openelement.config.ts.tmpl +21 -33
- package/templates/package.json.tmpl +14 -10
- package/templates/tsconfig.json.tmpl +1 -1
- package/templates/vite.config.ts.tmpl +9 -7
- package/templates/app/components/badges.css +0 -5
- package/templates/app/styles/recipes.css +0 -43
package/src/pm.js
CHANGED
|
@@ -7,8 +7,52 @@ import process from "node:process";
|
|
|
7
7
|
* A separate module (not cli.ts): the module is imported by the tests, and
|
|
8
8
|
* cli.ts executes the CLI at import time (top-level main), so anything the
|
|
9
9
|
* tests need to call must live beside it, not inside it.
|
|
10
|
+
*
|
|
11
|
+
* Manager-neutral since alpha.15. The scaffold used to pin pnpm through a
|
|
12
|
+
* `catalog:` specifier in its own pnpm-workspace.yaml, and `catalog:` is a
|
|
13
|
+
* pnpm-only protocol — npm rejects the manifest with EUNSUPPORTEDPROTOCOL —
|
|
14
|
+
* so the probe had exactly one answer and a missing pnpm failed the run with
|
|
15
|
+
* a requirement. The template now ships explicit version pins, no
|
|
16
|
+
* `packageManager` field, and no workspace file, so any of the four common
|
|
17
|
+
* managers installs it unchanged.
|
|
18
|
+
*
|
|
19
|
+
* Detection has TWO sources, in order (TPL-02):
|
|
20
|
+
*
|
|
21
|
+
* 1. the INVOKING manager — the wrapper this run was started through. A
|
|
22
|
+
* packed `npm create @openelement` run used to print (and drive) `pnpm`
|
|
23
|
+
* whenever pnpm merely sat on PATH, which is surprising at best and
|
|
24
|
+
* wrong when the user's workflow is npm: the next-steps box must spell
|
|
25
|
+
* the manager the user actually chose. The signals are the ones every
|
|
26
|
+
* manager exports to its child (`npm_config_user_agent`, then
|
|
27
|
+
* `npm_execpath`, then the argv[1] runner name);
|
|
28
|
+
* 2. the PATH probe, in preference order pnpm, npm, yarn, bun — the
|
|
29
|
+
* fallback for a DIRECT `node`/`openelement-create` run, where no
|
|
30
|
+
* wrapper named itself.
|
|
31
|
+
*
|
|
32
|
+
* Only a PATH with none of the four AND no invoking manager fails.
|
|
33
|
+
*
|
|
34
|
+
* The module also owns the two lifecycle COMMAND spellings the CLI prints and
|
|
35
|
+
* every documented quickstart repeats (install dependencies, run dev): one
|
|
36
|
+
* builder each, so the handoff box and the guides cannot drift apart on
|
|
37
|
+
* package-manager spelling. With no manager named they fall back to the
|
|
38
|
+
* universal `npm` spelling — every one of the four runs the same scripts.
|
|
10
39
|
*/
|
|
11
|
-
/**
|
|
40
|
+
/** The managers the install step can drive, in detection order. */
|
|
41
|
+
const PACKAGE_MANAGERS = [
|
|
42
|
+
"pnpm",
|
|
43
|
+
"npm",
|
|
44
|
+
"yarn",
|
|
45
|
+
"bun"
|
|
46
|
+
];
|
|
47
|
+
/** `<pm> install` — the command a consumer runs when the scaffold skipped it. */
|
|
48
|
+
function installDependenciesCommand(pm = null) {
|
|
49
|
+
return `${pm ?? "npm"} install`;
|
|
50
|
+
}
|
|
51
|
+
/** `<pm> run dev` — the command every documented quickstart spells. */
|
|
52
|
+
function devCommand(pm = null) {
|
|
53
|
+
return `${pm ?? "npm"} run dev`;
|
|
54
|
+
}
|
|
55
|
+
/** Probe `<pm> --version`; an off-PATH binary gives ENOENT. */
|
|
12
56
|
function packageManagerAvailable(pm) {
|
|
13
57
|
const probe = spawnSync(pm, ["--version"], {
|
|
14
58
|
stdio: "ignore",
|
|
@@ -17,14 +61,104 @@ function packageManagerAvailable(pm) {
|
|
|
17
61
|
return probe.error === void 0 && probe.status === 0;
|
|
18
62
|
}
|
|
19
63
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
64
|
+
* The first available manager in {@link PACKAGE_MANAGERS} order, or `null`
|
|
65
|
+
* when none of the four is on PATH. The probe is injectable so the order (and
|
|
66
|
+
* the total miss) can be pinned without rewriting PATH.
|
|
67
|
+
*/
|
|
68
|
+
function detectPackageManager(probe = packageManagerAvailable) {
|
|
69
|
+
for (const pm of PACKAGE_MANAGERS) if (probe(pm)) return pm;
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
/** The set form of {@link PACKAGE_MANAGERS}, for name lookups. */
|
|
73
|
+
const PACKAGE_MANAGER_NAMES = new Set(PACKAGE_MANAGERS);
|
|
74
|
+
/** One manager name from a signal, or `null` when the name is not one of ours. */
|
|
75
|
+
function managerNamed(name) {
|
|
76
|
+
const candidate = name?.trim().toLowerCase();
|
|
77
|
+
if (candidate === void 0 || candidate === "" || !PACKAGE_MANAGER_NAMES.has(candidate)) return null;
|
|
78
|
+
return candidate;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The runner file names that map to a manager. `npx`/`pnpm dlx`/`bunx` are
|
|
82
|
+
* runners of their manager, and `npm create` executes through npm's own
|
|
83
|
+
* `npm-cli.js`; `corepack` is deliberately absent — it is a shim over another
|
|
84
|
+
* manager, not a manager to spell commands for.
|
|
85
|
+
*/
|
|
86
|
+
const RUNNER_MANAGERS = {
|
|
87
|
+
npm: "npm",
|
|
88
|
+
"npm-cli.js": "npm",
|
|
89
|
+
npx: "npm",
|
|
90
|
+
"npx-cli.js": "npm",
|
|
91
|
+
pnpm: "pnpm",
|
|
92
|
+
"pnpm.cjs": "pnpm",
|
|
93
|
+
"pnpm.js": "pnpm",
|
|
94
|
+
pnpx: "pnpm",
|
|
95
|
+
yarn: "yarn",
|
|
96
|
+
"yarn.js": "yarn",
|
|
97
|
+
"yarn.cjs": "yarn",
|
|
98
|
+
yarnpkg: "yarn",
|
|
99
|
+
bun: "bun",
|
|
100
|
+
bunx: "bun"
|
|
101
|
+
};
|
|
102
|
+
/** The last path segment of a POSIX or Windows path. */
|
|
103
|
+
function lastPathSegment(path) {
|
|
104
|
+
const normalized = path.replace(/\\+/g, "/");
|
|
105
|
+
return normalized.slice(normalized.lastIndexOf("/") + 1);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The manager named by `npm_config_user_agent` — the signal every one of the
|
|
109
|
+
* four exports to its children, shaped `<name>/<version> <rest>` (npm's own
|
|
110
|
+
* agent, for example, is `npm/11.6.0 node/v24.18.0 darwin arm64 workspaces/false`).
|
|
111
|
+
*/
|
|
112
|
+
function invokingManagerFromUserAgent(userAgent) {
|
|
113
|
+
if (userAgent === void 0 || userAgent.trim() === "") return null;
|
|
114
|
+
return managerNamed(userAgent.trim().split(/[\s/]/, 1)[0]);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The manager named by `npm_execpath` — the absolute path of the manager's
|
|
118
|
+
* own entry script (`…/npm/bin/npm-cli.js`, `…/pnpm/bin/pnpm.cjs`,
|
|
119
|
+
* `…/yarn/bin/yarn.js`, `…/bun`). Matched on the basename with the manager
|
|
120
|
+
* names checked before npm's, because `pnpm` contains `npm`.
|
|
121
|
+
*/
|
|
122
|
+
function invokingManagerFromExecPath(execPath) {
|
|
123
|
+
if (execPath === void 0 || execPath === "") return null;
|
|
124
|
+
const file = lastPathSegment(execPath).toLowerCase();
|
|
125
|
+
if (file.includes("pnpm")) return "pnpm";
|
|
126
|
+
if (file.includes("yarn")) return "yarn";
|
|
127
|
+
if (file.includes("bun")) return "bun";
|
|
128
|
+
if (file.includes("npm") || file.includes("npx")) return "npm";
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The manager named by `process.argv[1]` — the runner script itself when the
|
|
133
|
+
* CLI is executed through a manager binary rather than through its own node
|
|
134
|
+
* entry. A direct `node …/cli.ts` run names the CLI file, which matches
|
|
135
|
+
* nothing by construction.
|
|
136
|
+
*/
|
|
137
|
+
function invokingManagerFromArgv1(argv) {
|
|
138
|
+
const runner = argv[1];
|
|
139
|
+
if (runner === void 0 || runner === "") return null;
|
|
140
|
+
return RUNNER_MANAGERS[lastPathSegment(runner).toLowerCase()] ?? null;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The manager this run was INVOKED through, or `null` when no wrapper named
|
|
144
|
+
* itself (a direct `node` execution). Signals are read in the order every
|
|
145
|
+
* manager's environment makes reliable: the user agent first (it names the
|
|
146
|
+
* wrapper unambiguously), then the exec path, then the argv[1] runner name.
|
|
147
|
+
* Both inputs are injectable, so the precedence is pinned without touching
|
|
148
|
+
* the host's real environment or argv.
|
|
149
|
+
*/
|
|
150
|
+
function detectInvokingPackageManager(env = process.env, argv = process.argv) {
|
|
151
|
+
return invokingManagerFromUserAgent(env.npm_config_user_agent) ?? invokingManagerFromExecPath(env.npm_execpath) ?? invokingManagerFromArgv1(argv);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The manager a run should use, in the two-source order the module header
|
|
155
|
+
* documents: the INVOKING manager when one named itself, otherwise the first
|
|
156
|
+
* of the four on PATH. `null` means "neither a wrapper nor a PATH" — the one
|
|
157
|
+
* case the CLI reports as a failure (or falls back to npm's universal spelling
|
|
158
|
+
* for, in a --no-install handoff).
|
|
23
159
|
*/
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
console.error("error: No package manager found (probed pnpm, then npm). Install one of them, then run the install step manually inside the project directory.");
|
|
27
|
-
process.exit(1);
|
|
160
|
+
function resolvePackageManager(options = {}) {
|
|
161
|
+
return detectInvokingPackageManager(options.env ?? process.env, options.argv ?? process.argv) ?? detectPackageManager(options.probe);
|
|
28
162
|
}
|
|
29
163
|
//#endregion
|
|
30
|
-
export { detectPackageManager };
|
|
164
|
+
export { PACKAGE_MANAGERS, detectInvokingPackageManager, detectPackageManager, devCommand, installDependenciesCommand, packageManagerAvailable, resolvePackageManager };
|
package/src/template-builder.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CREATE_VERSION
|
|
1
|
+
import { CREATE_VERSION } from "./version.js";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
//#region src/template-builder.ts
|
|
4
4
|
const MAX_PROJECT_NAME_LENGTH = 214;
|
|
@@ -17,6 +17,59 @@ function validateProjectName(name) {
|
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
+
* The project name for an in-place scaffold (`npm create @openelement .`),
|
|
21
|
+
* derived from the directory's own name and lowered into the package-name
|
|
22
|
+
* grammar {@linkcode validateProjectName} enforces: a host directory called
|
|
23
|
+
* `My App` still generates a legal `my-app` manifest. The result is always a
|
|
24
|
+
* valid name, so the in-place path never fails on the host's directory name;
|
|
25
|
+
* a directory with no usable characters at all (a filesystem root) falls back
|
|
26
|
+
* to `app`.
|
|
27
|
+
*/
|
|
28
|
+
function inPlaceProjectName(directory) {
|
|
29
|
+
let normalized = "";
|
|
30
|
+
for (const char of directory) {
|
|
31
|
+
const mapped = char === "\\" ? "/" : char;
|
|
32
|
+
if (mapped === "/" && normalized.endsWith("/")) continue;
|
|
33
|
+
normalized += mapped;
|
|
34
|
+
}
|
|
35
|
+
let normalizedEnd = normalized.length;
|
|
36
|
+
while (normalizedEnd > 0 && normalized[normalizedEnd - 1] === "/") normalizedEnd -= 1;
|
|
37
|
+
const trimmed = normalized.slice(0, normalizedEnd);
|
|
38
|
+
const base = trimmed.slice(trimmed.lastIndexOf("/") + 1);
|
|
39
|
+
let slug = "";
|
|
40
|
+
let inIllegalRun = false;
|
|
41
|
+
for (const char of base.toLowerCase()) if (char >= "a" && char <= "z" || char >= "0" && char <= "9" || char === "." || char === "_" || char === "-") {
|
|
42
|
+
slug += char;
|
|
43
|
+
inIllegalRun = false;
|
|
44
|
+
} else if (!inIllegalRun) {
|
|
45
|
+
slug += "-";
|
|
46
|
+
inIllegalRun = true;
|
|
47
|
+
}
|
|
48
|
+
let dedotted = "";
|
|
49
|
+
let dots = 0;
|
|
50
|
+
for (const char of slug) {
|
|
51
|
+
if (char === ".") {
|
|
52
|
+
dots += 1;
|
|
53
|
+
if (dots > 1) continue;
|
|
54
|
+
} else dots = 0;
|
|
55
|
+
dedotted += char;
|
|
56
|
+
}
|
|
57
|
+
let start = 0;
|
|
58
|
+
while (start < dedotted.length) {
|
|
59
|
+
const char = dedotted[start];
|
|
60
|
+
if (char >= "a" && char <= "z" || char >= "0" && char <= "9") break;
|
|
61
|
+
start += 1;
|
|
62
|
+
}
|
|
63
|
+
let end = dedotted.length;
|
|
64
|
+
while (end > start) {
|
|
65
|
+
const char = dedotted[end - 1];
|
|
66
|
+
if (char === "-" || char === "." || char === "_") end -= 1;
|
|
67
|
+
else break;
|
|
68
|
+
}
|
|
69
|
+
const cleaned = dedotted.slice(start, end).slice(0, MAX_PROJECT_NAME_LENGTH);
|
|
70
|
+
return cleaned === "" ? "app" : cleaned;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
20
73
|
* The published starter relies on the support-package same-version release
|
|
21
74
|
* invariant. Package-graph and release-prepare gates verify that invariant;
|
|
22
75
|
* Create deliberately has no runtime registry fallback or mixed-version mode.
|
|
@@ -35,19 +88,19 @@ function assertUnifiedProductVersions(versions) {
|
|
|
35
88
|
}
|
|
36
89
|
const TEMPLATE_FILES = [
|
|
37
90
|
["gitignore.tmpl", ".gitignore"],
|
|
91
|
+
[".node-version", ".node-version"],
|
|
38
92
|
["README.tmpl", "README.md"],
|
|
93
|
+
["AGENTS.md.tmpl", "AGENTS.md"],
|
|
39
94
|
["public/openelement-mark.svg", "public/openelement-mark.svg"],
|
|
40
95
|
["package.json.tmpl", "package.json"],
|
|
41
96
|
["tsconfig.json.tmpl", "tsconfig.json"],
|
|
42
97
|
["vite.config.ts.tmpl", "vite.config.ts"],
|
|
43
98
|
["openelement.config.ts.tmpl", "openelement.config.ts"],
|
|
44
99
|
["app/styles/theme.css", "app/styles/theme.css"],
|
|
45
|
-
["app/styles/recipes.css", "app/styles/recipes.css"],
|
|
46
100
|
["app/head.tsx.tmpl", "app/head.tsx"],
|
|
47
101
|
["app/components/page-home.css", "app/components/page-home.css"],
|
|
48
102
|
["app/components/page-about.css", "app/components/page-about.css"],
|
|
49
103
|
["app/components/page-404.css", "app/components/page-404.css"],
|
|
50
|
-
["app/components/badges.css", "app/components/badges.css"],
|
|
51
104
|
["app/components/site-chrome.css", "app/components/site-chrome.css"],
|
|
52
105
|
["app/components/page-home.tsx.tmpl", "app/components/page-home.tsx"],
|
|
53
106
|
["app/components/page-about.tsx.tmpl", "app/components/page-about.tsx"],
|
|
@@ -59,7 +112,8 @@ const TEMPLATE_FILES = [
|
|
|
59
112
|
["app/islands/my-counter.tsx.tmpl", "app/islands/my-counter.tsx"],
|
|
60
113
|
["app/islands/my-counter.css", "app/islands/my-counter.css"],
|
|
61
114
|
["app/islands/live-timer.tsx.tmpl", "app/islands/live-timer.tsx"],
|
|
62
|
-
["app/islands/live-timer.css", "app/islands/live-timer.css"]
|
|
115
|
+
["app/islands/live-timer.css", "app/islands/live-timer.css"],
|
|
116
|
+
["app/layout.tsx.tmpl", "app/layout.tsx"]
|
|
63
117
|
];
|
|
64
118
|
function versionTokens(v) {
|
|
65
119
|
return {
|
|
@@ -74,7 +128,6 @@ async function buildTemplates(v, projectName) {
|
|
|
74
128
|
const templatesBase = new URL("../templates/", import.meta.url);
|
|
75
129
|
const tokens = {
|
|
76
130
|
...versionTokens(v),
|
|
77
|
-
["${v.vite}"]: VITE_STARTER_PIN,
|
|
78
131
|
["${name}"]: projectName
|
|
79
132
|
};
|
|
80
133
|
const entries = await Promise.all(TEMPLATE_FILES.map(async ([source, target]) => {
|
|
@@ -87,4 +140,4 @@ async function buildTemplates(v, projectName) {
|
|
|
87
140
|
return Object.fromEntries(Object.entries(out).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
88
141
|
}
|
|
89
142
|
//#endregion
|
|
90
|
-
export { assertUnifiedProductVersions, buildTemplates, resolveVersions, validateProjectName };
|
|
143
|
+
export { TEMPLATE_FILES, assertUnifiedProductVersions, buildTemplates, inPlaceProjectName, resolveVersions, validateProjectName };
|
package/src/version.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
//#region src/version.ts
|
|
2
2
|
/** The published CLI version, embedded so packed npm installs are self-contained. */
|
|
3
|
-
const CREATE_VERSION = "1.0.0-alpha.
|
|
4
|
-
/**
|
|
5
|
-
* The Vite release pinned into the generated starter's package.json (the
|
|
6
|
-
* `${v.vite}` scaffold token in the npm/pnpm starter). Embedded for the same
|
|
7
|
-
* reason as CREATE_VERSION (packed npm installs are self-contained); the
|
|
8
|
-
* repository's Vite-pin check (deps:vite-check in the repo tooling package) anchors this copy
|
|
9
|
-
* to the canonical dev pin.
|
|
10
|
-
*/
|
|
11
|
-
const VITE_STARTER_PIN = "8.0.16";
|
|
3
|
+
const CREATE_VERSION = "1.0.0-alpha.15";
|
|
12
4
|
//#endregion
|
|
13
|
-
export { CREATE_VERSION
|
|
5
|
+
export { CREATE_VERSION };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
24.18.0
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
An openElement application. This file is the entry pointer for AI coding agents
|
|
4
|
+
working in this project.
|
|
5
|
+
|
|
6
|
+
## Start here
|
|
7
|
+
|
|
8
|
+
- Agent and consumer index: <https://openelement.org/llms.txt>
|
|
9
|
+
- Getting started: <https://openelement.org/guide/getting-started>
|
|
10
|
+
- API reference (packages, exports, custom elements, config): <https://openelement.org/reference>
|
|
11
|
+
- Diagnostics (the `OEC` codes the compiler and runtime emit): <https://openelement.org/errors>
|
|
12
|
+
|
|
13
|
+
## Commands
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm run dev # dev server with HMR
|
|
17
|
+
npm run build # production build into dist/
|
|
18
|
+
npm run start # serve the built output (and request-time routes)
|
|
19
|
+
npm run typecheck # tsc --noEmit
|
|
20
|
+
npm run lint # oxlint
|
|
21
|
+
npm run test # node --test
|
|
22
|
+
npm run fmt # oxfmt
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Project layout
|
|
26
|
+
|
|
27
|
+
- `app/routes/` — pages (default export) and form actions.
|
|
28
|
+
- `app/islands/` — interactive islands; each one hydrates with its declared strategy.
|
|
29
|
+
- `app/components/` — presentational components and their root CSS.
|
|
30
|
+
- `app/layout.tsx` — the shared document chrome every page renders inside.
|
|
31
|
+
- `app/head.tsx` — document head entries a config URL list cannot express.
|
|
32
|
+
- `openelement.config.ts` — framework options (head, i18n, middleware, ...).
|
|
33
|
+
- `public/` — copied verbatim into `dist/`.
|
|
34
|
+
|
|
35
|
+
## Rules
|
|
36
|
+
|
|
37
|
+
- Never edit `dist/` by hand: it is build output.
|
|
38
|
+
- Islands run in the browser. Importing `node:*` from an island fails the build
|
|
39
|
+
by design — server-only code belongs in route loaders and actions.
|
|
40
|
+
- A page that mounts no island ships no island JavaScript; keep static surfaces
|
|
41
|
+
static instead of widening the island graph.
|
|
42
|
+
- `dist/server/` is private server code; never publish it as a static asset.
|
|
43
|
+
- Keep `npm run typecheck`, `npm run lint`, `npm run test` and `npm run build`
|
|
44
|
+
green after a change; `npm run check` is not a script in this scaffold.
|
package/templates/README.tmpl
CHANGED
|
@@ -5,42 +5,59 @@ scaffold it elsewhere with `npm create @openelement <project-name>` —
|
|
|
5
5
|
a static-first openElement app that shows its own costs. The landing page
|
|
6
6
|
carries two islands (`my-counter`, an interactive counter, and `live-timer`,
|
|
7
7
|
a client-only elapsed-time readout); every other page, including `/about`,
|
|
8
|
-
is prerendered HTML and CSS with no islands
|
|
9
|
-
|
|
8
|
+
is prerendered HTML and CSS with no islands of its own — no island chunk is
|
|
9
|
+
executed there (a linked page's chunks can still be prefetched); the only
|
|
10
|
+
script such a page executes is the app-wide claim bootstrap (about 2 KB
|
|
11
|
+
gzipped) that runs while the app has any island. The badge on each section
|
|
12
|
+
names what it costs the client.
|
|
10
13
|
|
|
11
14
|
Docs and guides: https://openelement.org
|
|
12
15
|
|
|
16
|
+
Requires **Node.js 24.2+ (24.18.0 recommended)** and any one package manager:
|
|
17
|
+
npm, pnpm, yarn, or bun. Node 24.2 is the floor the packed framework packages
|
|
18
|
+
declare in their `engines` and CI exercises; 24.18.0 is the line this template
|
|
19
|
+
is verified on, pinned by the scaffold's own `.node-version`. The generated
|
|
20
|
+
project pins no package manager: every script is a plain command, so whichever
|
|
21
|
+
manager you install with runs them all.
|
|
22
|
+
|
|
13
23
|
One directory is generated rather than source: `.openElement/` at the project
|
|
14
24
|
root holds the build's internal state (head-convention bookkeeping and build
|
|
15
|
-
plans).
|
|
25
|
+
plans). The dev server and the build write it as needed; the `.gitignore`
|
|
16
26
|
excludes it and deleting it is safe — the next run recreates it.
|
|
17
27
|
|
|
18
28
|
The `@openelement/element` and `@openelement/router` dependencies carry caret
|
|
19
|
-
ranges over the `1.0.0`
|
|
20
|
-
|
|
29
|
+
ranges over the `1.0.0` prerelease this starter was generated from, so a
|
|
30
|
+
dependency update picks up later `1.0.0` prereleases (and the final `1.0.0`)
|
|
21
31
|
without editing this file.
|
|
22
32
|
|
|
33
|
+
Nothing here is tied to one package manager: the manifest declares no
|
|
34
|
+
`packageManager`, every script is a plain command, and the scaffold ships no
|
|
35
|
+
`pnpm-workspace.yaml`. Install with npm, pnpm, yarn, or bun — whichever one
|
|
36
|
+
runs first writes its lockfile, and every command below works the same.
|
|
37
|
+
|
|
23
38
|
## The JS cost map
|
|
24
39
|
|
|
25
|
-
| Surface
|
|
26
|
-
|
|
|
27
|
-
| `/` hero + architecture sections
|
|
28
|
-
| `/` counter island (`my-counter`)
|
|
29
|
-
| `/` live timer island (`live-timer`) | yes, client-only
|
|
30
|
-
| `/about`
|
|
31
|
-
| `/api/ping`
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
>
|
|
39
|
-
>
|
|
40
|
-
>
|
|
41
|
-
>
|
|
42
|
-
>
|
|
43
|
-
> the
|
|
40
|
+
| Surface | Ships JavaScript? | Why |
|
|
41
|
+
| ------------------------------------ | --------------------- | ------------------------------------------------- |
|
|
42
|
+
| `/` hero + architecture sections | no | prerendered markup, styled with CSS |
|
|
43
|
+
| `/` counter island (`my-counter`) | yes, hydrates on idle | the one interactive piece |
|
|
44
|
+
| `/` live timer island (`live-timer`) | yes, client-only | a live clock has nothing to prerender |
|
|
45
|
+
| `/about` | no islands of its own | fully static SSG output, no island chunk executes |
|
|
46
|
+
| `/api/ping` | no (server) | a plain `Request → Response` handler |
|
|
47
|
+
| `/404` (unmatched paths) | no (server) | dynamic 404 from the styled 404 page |
|
|
48
|
+
|
|
49
|
+
The badge on each section is a Tailwind utility string on the span itself
|
|
50
|
+
(`bg-ok/8 text-ok` for a static section, `bg-brand-soft text-brand` for an
|
|
51
|
+
interactive one) — copy the span onto new sections and keep the map honest.
|
|
52
|
+
|
|
53
|
+
> Cost honesty: the island client is emitted app-wide today, so a page
|
|
54
|
+
> without islands (like `/about`) still carries the ~2 KB gzipped app-wide
|
|
55
|
+
> claim bootstrap — but no island chunk executes and no element-runtime
|
|
56
|
+
> preload is added for it: the build records islands per page and the client
|
|
57
|
+
> only activates tags the page hosts. Fetches can still be broader than
|
|
58
|
+
> execution when the reader follows a link, because the target page's chunks
|
|
59
|
+
> may be prefetched; what a page executes is always limited to its own
|
|
60
|
+
> registered islands.
|
|
44
61
|
|
|
45
62
|
## Where things live
|
|
46
63
|
|
|
@@ -48,12 +65,12 @@ Framework options have exactly one home: `openelement.config.ts`. It is
|
|
|
48
65
|
optional and nearly empty — every option it omits comes from a file
|
|
49
66
|
convention:
|
|
50
67
|
|
|
51
|
-
| Option
|
|
52
|
-
|
|
|
53
|
-
| design tokens
|
|
54
|
-
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
68
|
+
| Option | Convention |
|
|
69
|
+
| --------------------- | ------------------------------------------------------------------- |
|
|
70
|
+
| design tokens | `app/styles/theme.css` (the @theme role sheet) |
|
|
71
|
+
| layout | `app/layout.tsx` (the shared site chrome every page renders inside) |
|
|
72
|
+
| document head content | `app/head.tsx` (meta tags, preloads, inline CSS) |
|
|
73
|
+
| site title | the `name` field of `package.json` |
|
|
57
74
|
|
|
58
75
|
Passing framework options inline to `openElement()` while the config file
|
|
59
76
|
carries options is a hard error, and an unknown key fails the build with the
|
|
@@ -63,45 +80,90 @@ accepted-key list. `vite.config.ts` stays Vite-only: `plugins: [...openElement()
|
|
|
63
80
|
`static`: prerendered at build time (SSG). `/about` and `/` are static.
|
|
64
81
|
- `app/routes/api/` — request-time server routes. `/api/ping` is a plain
|
|
65
82
|
WinterCG-shaped handler returning `Response.json`.
|
|
66
|
-
- `app/components/` — compiled page elements
|
|
67
|
-
|
|
68
|
-
|
|
83
|
+
- `app/components/` — compiled page elements. Presentation is authored as
|
|
84
|
+
Tailwind utility classes in the markup; each element's `.css` sheet carries
|
|
85
|
+
only its root's box rule, which has no markup to carry it.
|
|
69
86
|
- `app/islands/` — client islands, the only code that ships JavaScript. Each
|
|
70
87
|
island declares its hydration strategy (`idle`, `load`, `visible`,
|
|
71
88
|
client-only) through `defineIslandConfig`.
|
|
72
|
-
- `app/
|
|
89
|
+
- `app/layout.tsx` — the auto-registered layout, not an island itself: the
|
|
90
|
+
site chrome every page renders inside. The header, the `main` content
|
|
91
|
+
block, and the footer live here exactly once instead of being copied onto
|
|
92
|
+
each page. The build registers the layout automatically and projects each
|
|
93
|
+
page's render into its default slot, so a page module carries only its own
|
|
94
|
+
content. The layout is a convention: delete the file and pages still render
|
|
95
|
+
(carrying their own chrome again), or opt out explicitly with `layout: false`
|
|
96
|
+
in `openelement.config.ts`.
|
|
97
|
+
- `app/styles/theme.css` — the @theme role sheet: Tailwind-ON roles, the
|
|
98
|
+
starter palette (`bg-paper`, `text-brand`, `border-line`, …), dark and
|
|
99
|
+
forced-colors pairs, and the document base (`body`, `::selection`). Dev
|
|
100
|
+
serves the compiled result at `/.openElement/tailwind.css` and the build
|
|
101
|
+
emits it as the content-hashed document stylesheet the head links — both
|
|
102
|
+
through the official `@tailwindcss/vite` pipeline.
|
|
73
103
|
Dark values ride `prefers-color-scheme`; no theme runtime.
|
|
74
|
-
- `app/styles/recipes.css` — documented plain HTML+CSS recipes for the
|
|
75
|
-
zero-interaction shapes (badge, callout, card, CSS-only tabs) that retired
|
|
76
|
-
from `@openelement/ui` (#1557). Delete the blocks you do not use: static
|
|
77
|
-
content never justifies a custom element.
|
|
78
104
|
- `app/head.tsx` — structural head content the URL list cannot express.
|
|
79
105
|
|
|
80
106
|
## Scripts
|
|
81
107
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
- `
|
|
87
|
-
- `
|
|
108
|
+
Every script is a plain command, so every one of them runs under any package
|
|
109
|
+
manager (`npm run dev`, `pnpm run dev`, `yarn run dev`, `bun run dev` — this
|
|
110
|
+
file spells them as `npm run …`):
|
|
111
|
+
|
|
112
|
+
- `npm run dev` — start the Vite dev server (`oe dev`).
|
|
113
|
+
- `npm run fmt` — format the sources (`oxfmt`).
|
|
114
|
+
- `npm run lint` — lint the sources (`oxlint`).
|
|
115
|
+
- `npm run typecheck` — type-check every route/component file (`tsc --noEmit`).
|
|
116
|
+
The check covers the whole `app/` directory (`tsconfig.json`), so new files
|
|
117
|
+
are picked up automatically.
|
|
118
|
+
- `npm test` — run Node's built-in test runner (the starter ships none).
|
|
119
|
+
- `npm run build` — production build into `dist/`: prerendered HTML for every
|
|
88
120
|
static route, plus the request-time server when the app has one.
|
|
89
|
-
- `
|
|
121
|
+
- `npm start` — serve the production build.
|
|
122
|
+
|
|
123
|
+
`dev`, `build`, and `start` run the router CLI's short `oe` bin from the
|
|
124
|
+
`@openelement/router` dependency (`oe dev` / `oe build` / `oe start`; the same
|
|
125
|
+
entry is installed as `openelement`, so both spellings work). `oe dev` boots the
|
|
126
|
+
framework's own dev server — the SSR dev middleware, HMR, and the Tailwind
|
|
127
|
+
pipeline — with no extra wrapper, and `oe start --mode=preview` is the
|
|
128
|
+
static-only serve mode that refuses a build carrying a request-time server.
|
|
129
|
+
|
|
130
|
+
`oxfmt` and `oxlint` run with their defaults: both skip markdown, JSON, YAML,
|
|
131
|
+
and CSS, so `npx oxfmt --check` and `npx oxlint` pass on a fresh scaffold.
|
|
132
|
+
|
|
133
|
+
The Vite tree is one direct devDependency pin (`"vite": "8.0.16"` — the same
|
|
134
|
+
version `@openelement/router` resolves against), so every peer that asks for
|
|
135
|
+
Vite gets that copy. There is no workspace catalog and no `vite@*` override:
|
|
136
|
+
a pin plus the router's own aligned dependency is what keeps the tree single.
|
|
90
137
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
138
|
+
### Package manager
|
|
139
|
+
|
|
140
|
+
Install with whichever manager you prefer; the first install decides the
|
|
141
|
+
lockfile and everything afterwards follows it. The manifest deliberately
|
|
142
|
+
carries no `packageManager` field: with the field absent, the manager you run
|
|
143
|
+
first is the one that owns the project. The commands in this file are spelled
|
|
144
|
+
`npm run …` only because npm's spelling works unchanged under all four.
|
|
95
145
|
|
|
96
146
|
## Styling ownership
|
|
97
147
|
|
|
98
|
-
|
|
99
|
-
in
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
client JavaScript
|
|
104
|
-
|
|
148
|
+
Styling is utility-first: presentation is authored as Tailwind utility
|
|
149
|
+
classes directly in the markup, and nothing else in the app spells it out.
|
|
150
|
+
The compiler admits those static tokens and the build generates the CSS — the
|
|
151
|
+
document stylesheet for light-root pages and the layout, one shared component
|
|
152
|
+
stylesheet for the shadow-root islands — so every page is fully styled with
|
|
153
|
+
zero client JavaScript and no CSS text ships inside JavaScript.
|
|
154
|
+
|
|
155
|
+
Two things stay CSS, and each has a reason:
|
|
156
|
+
|
|
157
|
+
- `app/styles/theme.css` — the design tokens and the document base (`body`,
|
|
158
|
+
`::selection`, the dark and forced-colors pairs). The document shell's
|
|
159
|
+
`body` is not authored markup, so no class can carry it.
|
|
160
|
+
- the per-element `.css` sheet — one `:host` rule for the element's own box.
|
|
161
|
+
A custom element is `display: inline` by default and the host tag is not
|
|
162
|
+
authored markup either.
|
|
163
|
+
|
|
164
|
+
The `.css` + `static styles` authoring path stays fully available — array any
|
|
165
|
+
sheet you want and the server inlines it into the SSR output as a
|
|
166
|
+
`@scope(<tag>)` block — the starter simply has no need for it.
|
|
105
167
|
|
|
106
168
|
## Brand assets
|
|
107
169
|
|
|
@@ -112,21 +174,25 @@ unused.
|
|
|
112
174
|
## Dependency notes
|
|
113
175
|
|
|
114
176
|
`@openelement/element` and `@openelement/router` are the runtime dependencies
|
|
115
|
-
your app imports.
|
|
116
|
-
the
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
177
|
+
your app imports. Everything else this manifest declares rides devDependencies:
|
|
178
|
+
`vite` (the tree the router's `oe dev` / `oe build` drive), `oxfmt` and `oxlint`
|
|
179
|
+
(the `fmt` / `lint` scripts), the Tailwind-ON build-time pins, the dev-server
|
|
180
|
+
pair — `@hono/vite-dev-server` (loaded lazily by the dev server) and its `hono`
|
|
181
|
+
peer — and the `typescript` pin.
|
|
182
|
+
|
|
183
|
+
`npm install --omit=dev` drops what this manifest declares as devDependencies —
|
|
184
|
+
the Tailwind pair, `oxfmt`, `oxlint`, the Vite pin, `hono` — but it does not
|
|
185
|
+
shrink the install to the runtime pair: `@openelement/router` declares its own
|
|
186
|
+
dependencies (the compiler, the protocol package, TypeScript, PostCSS, `mime`,
|
|
187
|
+
`pathe`) and npm installs those in a production install too. Vite, Element,
|
|
188
|
+
`hono`, `marked` and `@hono/vite-dev-server` are optional peers of the router
|
|
189
|
+
and are never auto-installed, so a `--omit=dev` tree has no Vite: run the build
|
|
190
|
+
from the full install and ship only its output.
|
|
191
|
+
|
|
192
|
+
The generated server entry itself imports no HTTP framework — it composes on
|
|
193
|
+
the internal WinterCG layer — and `hono` is only an optional peer of
|
|
194
|
+
`@openelement/router`: `@openelement/router/hono` (`createHonoAdapter`) is the
|
|
195
|
+
one opt-in if you ever want to mount the built handler inside your own Hono
|
|
196
|
+
app. For Nitro deployments, the built handler bridges through the
|
|
197
|
+
`@openelement/router/nitro-mount` subpath of the one `@openelement/router`
|
|
198
|
+
dependency. Do not remove them.
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
a:hover { text-decoration: underline; }
|
|
7
|
-
|
|
1
|
+
/* The page-404 light root's box: a custom element is inline by default and
|
|
2
|
+
the host tag is not authored markup, so no utility can carry it. */
|
|
3
|
+
:host {
|
|
4
|
+
display: block;
|
|
5
|
+
}
|