@openelement/create 1.0.0-alpha.14 → 1.0.0-alpha.16
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 +61 -51
- 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 -14
- package/src/version.js +2 -10
- package/templates/.node-version +1 -0
- package/templates/AGENTS.md.tmpl +46 -0
- package/templates/README.tmpl +36 -145
- package/templates/app/head.tsx.tmpl +11 -26
- package/templates/app/islands/live-timer.css +2 -20
- package/templates/app/islands/live-timer.tsx.tmpl +49 -43
- package/templates/app/islands/my-counter.css +2 -29
- package/templates/app/islands/my-counter.tsx.tmpl +43 -34
- package/templates/app/layout.tsx.tmpl +79 -0
- package/templates/app/routes/404.tsx.tmpl +20 -8
- package/templates/app/routes/about.tsx.tmpl +34 -3
- package/templates/app/routes/api/ping.ts.tmpl +2 -3
- package/templates/app/routes/index.tsx.tmpl +32 -3
- package/templates/app/styles/theme.css +81 -77
- package/templates/gitignore.tmpl +2 -0
- package/templates/openelement.config.ts.tmpl +16 -28
- package/templates/package.json.tmpl +8 -6
- package/templates/tests/ping.test.ts.tmpl +15 -0
- package/templates/tsconfig.json.tmpl +2 -2
- package/templates/vite.config.ts.tmpl +7 -14
- package/templates/app/components/badges.css +0 -24
- package/templates/app/components/page-404.css +0 -21
- package/templates/app/components/page-404.tsx.tmpl +0 -28
- package/templates/app/components/page-about.css +0 -72
- package/templates/app/components/page-about.tsx.tmpl +0 -77
- package/templates/app/components/page-home.css +0 -135
- package/templates/app/components/page-home.tsx.tmpl +0 -116
- package/templates/app/components/site-chrome.css +0 -68
- package/templates/app/islands/app-shell.tsx.tmpl +0 -54
- package/templates/app/styles/recipes.css +0 -43
- package/templates/pnpm-workspace.yaml.tmpl +0 -29
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,33 +88,26 @@ 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
|
-
["pnpm-workspace.yaml.tmpl", "pnpm-workspace.yaml"],
|
|
44
98
|
["openelement.config.ts.tmpl", "openelement.config.ts"],
|
|
45
99
|
["app/styles/theme.css", "app/styles/theme.css"],
|
|
46
|
-
["app/styles/recipes.css", "app/styles/recipes.css"],
|
|
47
100
|
["app/head.tsx.tmpl", "app/head.tsx"],
|
|
48
|
-
["app/components/page-home.css", "app/components/page-home.css"],
|
|
49
|
-
["app/components/page-about.css", "app/components/page-about.css"],
|
|
50
|
-
["app/components/page-404.css", "app/components/page-404.css"],
|
|
51
|
-
["app/components/badges.css", "app/components/badges.css"],
|
|
52
|
-
["app/components/site-chrome.css", "app/components/site-chrome.css"],
|
|
53
|
-
["app/components/page-home.tsx.tmpl", "app/components/page-home.tsx"],
|
|
54
|
-
["app/components/page-about.tsx.tmpl", "app/components/page-about.tsx"],
|
|
55
|
-
["app/components/page-404.tsx.tmpl", "app/components/page-404.tsx"],
|
|
56
101
|
["app/routes/index.tsx.tmpl", "app/routes/index.tsx"],
|
|
57
102
|
["app/routes/about.tsx.tmpl", "app/routes/about.tsx"],
|
|
58
103
|
["app/routes/404.tsx.tmpl", "app/routes/404.tsx"],
|
|
59
104
|
["app/routes/api/ping.ts.tmpl", "app/routes/api/ping.ts"],
|
|
105
|
+
["tests/ping.test.ts.tmpl", "tests/ping.test.ts"],
|
|
60
106
|
["app/islands/my-counter.tsx.tmpl", "app/islands/my-counter.tsx"],
|
|
61
107
|
["app/islands/my-counter.css", "app/islands/my-counter.css"],
|
|
62
108
|
["app/islands/live-timer.tsx.tmpl", "app/islands/live-timer.tsx"],
|
|
63
109
|
["app/islands/live-timer.css", "app/islands/live-timer.css"],
|
|
64
|
-
["app/
|
|
110
|
+
["app/layout.tsx.tmpl", "app/layout.tsx"]
|
|
65
111
|
];
|
|
66
112
|
function versionTokens(v) {
|
|
67
113
|
return {
|
|
@@ -76,7 +122,6 @@ async function buildTemplates(v, projectName) {
|
|
|
76
122
|
const templatesBase = new URL("../templates/", import.meta.url);
|
|
77
123
|
const tokens = {
|
|
78
124
|
...versionTokens(v),
|
|
79
|
-
["${v.vite}"]: VITE_STARTER_PIN,
|
|
80
125
|
["${name}"]: projectName
|
|
81
126
|
};
|
|
82
127
|
const entries = await Promise.all(TEMPLATE_FILES.map(async ([source, target]) => {
|
|
@@ -89,4 +134,4 @@ async function buildTemplates(v, projectName) {
|
|
|
89
134
|
return Object.fromEntries(Object.entries(out).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
90
135
|
}
|
|
91
136
|
//#endregion
|
|
92
|
-
export { assertUnifiedProductVersions, buildTemplates, resolveVersions, validateProjectName };
|
|
137
|
+
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.16";
|
|
12
4
|
//#endregion
|
|
13
|
-
export { CREATE_VERSION
|
|
5
|
+
export { CREATE_VERSION };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
24.18.0
|
|
@@ -0,0 +1,46 @@
|
|
|
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 and dist-public/ upload directory
|
|
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 tests for the request-time API
|
|
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/` — where page-scope components live when you add one
|
|
30
|
+
(the shipped pages are server functions in `app/routes/`).
|
|
31
|
+
- `app/layout.tsx` — the shared document chrome every page renders inside.
|
|
32
|
+
- `app/head.tsx` — document head entries a config URL list cannot express.
|
|
33
|
+
- `openelement.config.ts` — framework options (head, i18n, middleware, ...).
|
|
34
|
+
- `public/` — authored files for the public deployment.
|
|
35
|
+
- `tests/` — application tests run by Node’s built-in test runner.
|
|
36
|
+
|
|
37
|
+
## Rules
|
|
38
|
+
|
|
39
|
+
- Treat `dist/` and `dist-public/` as generated build output.
|
|
40
|
+
- Islands run in the browser. Importing `node:*` from an island fails the build
|
|
41
|
+
by design — server-only code belongs in route loaders and actions.
|
|
42
|
+
- A page that mounts no island ships no island JavaScript; keep static surfaces
|
|
43
|
+
static instead of widening the island graph.
|
|
44
|
+
- Run `npx oe publish --check` before uploading `dist-public/`. Keep `dist/server/` and `dist/publish-manifest.json` in the application environment.
|
|
45
|
+
- Keep `npm run typecheck`, `npm run lint`, `npm run test` and `npm run build`
|
|
46
|
+
green after a change; `npm run check` is not a script in this scaffold.
|
package/templates/README.tmpl
CHANGED
|
@@ -1,157 +1,48 @@
|
|
|
1
|
-
# openElement
|
|
1
|
+
# openElement starter
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
scaffold it elsewhere with `npm create @openelement <project-name>` —
|
|
5
|
-
a static-first openElement app that shows its own costs. The landing page
|
|
6
|
-
carries two islands (`my-counter`, an interactive counter, and `live-timer`,
|
|
7
|
-
a client-only elapsed-time readout); every other page, including `/about`,
|
|
8
|
-
is prerendered HTML and CSS with no islands at all. The badge on each
|
|
9
|
-
section names what it costs the client.
|
|
3
|
+
Start the dev server and open the URL it prints.
|
|
10
4
|
|
|
11
|
-
|
|
5
|
+
```sh
|
|
6
|
+
npm run dev
|
|
7
|
+
```
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
excludes it and deleting it is safe — the next run recreates it.
|
|
9
|
+
Edit the heading in `app/routes/index.tsx` and save. The dev server updates the
|
|
10
|
+
home page. Then try the counter in `app/islands/my-counter.tsx` or add a route
|
|
11
|
+
under `app/routes/`.
|
|
17
12
|
|
|
18
|
-
The
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
Use Node.js 24.2 or newer. The scaffold pins the recommended development
|
|
14
|
+
version in `.node-version`. If you skipped installation, run the install
|
|
15
|
+
command printed by the CLI first. Use the same package manager for installs
|
|
16
|
+
and scripts.
|
|
22
17
|
|
|
23
|
-
##
|
|
18
|
+
## Find the examples
|
|
24
19
|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
20
|
+
| Path | What it does |
|
|
21
|
+
| ---------------------------- | -------------------------------------------------------------- |
|
|
22
|
+
| `app/routes/index.tsx` | Prerenders `/` and hosts the counter and timer. |
|
|
23
|
+
| `app/islands/my-counter.tsx` | Renders the counter on the server and hydrates on idle. |
|
|
24
|
+
| `app/islands/live-timer.tsx` | Mounts the timer in the browser with `ssr: false`. |
|
|
25
|
+
| `app/routes/about.tsx` | Prerenders `/about` without islands of its own. |
|
|
26
|
+
| `app/routes/api/ping.ts` | Serves JSON from the request-time route `/api/ping`. |
|
|
27
|
+
| `app/routes/404.tsx` | Renders the fallback page for unmatched paths. |
|
|
28
|
+
| `app/layout.tsx` | Wraps every page in the shared header, main region and footer. |
|
|
29
|
+
| `app/styles/theme.css` | Defines the palette and Tailwind theme tokens. |
|
|
30
|
+
| `app/head.tsx` | Adds shared metadata and links to the document head. |
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
map honest.
|
|
36
|
-
|
|
37
|
-
> Cost honesty: the island client is emitted app-wide today. A page without
|
|
38
|
-
> islands (like `/about`) carries no island hosts and renders nothing
|
|
39
|
-
> interactive, but the shared loader — and with the current app-wide
|
|
40
|
-
> hydration manifest, the island chunks themselves — still ride along in its
|
|
41
|
-
> network panel. Per-page pruning is framework work, not something a template
|
|
42
|
-
> can opt into; the page is authored so it becomes fully silent the moment
|
|
43
|
-
> the framework ships it.
|
|
44
|
-
|
|
45
|
-
## Where things live
|
|
46
|
-
|
|
47
|
-
Framework options have exactly one home: `openelement.config.ts`. It is
|
|
48
|
-
optional and nearly empty — every option it omits comes from a file
|
|
49
|
-
convention:
|
|
50
|
-
|
|
51
|
-
| Option | Convention |
|
|
52
|
-
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
53
|
-
| design tokens | `app/styles/theme.css` (the @theme role sheet) |
|
|
54
|
-
| app shell | `app/islands/app-shell.tsx` (the shared site chrome every page renders inside) |
|
|
55
|
-
| document head content | `app/head.tsx` (meta tags, preloads, inline CSS) |
|
|
56
|
-
| site title | the `name` field of `package.json` |
|
|
57
|
-
| static-shape recipes | `app/styles/recipes.css` (zero-interaction badge/callout/card/tabs shapes as plain HTML+CSS — the @openelement/ui components retired to these recipes in #1557) |
|
|
58
|
-
|
|
59
|
-
Passing framework options inline to `openElement()` while the config file
|
|
60
|
-
carries options is a hard error, and an unknown key fails the build with the
|
|
61
|
-
accepted-key list. `vite.config.ts` stays Vite-only: `plugins: [...openElement()]`.
|
|
62
|
-
|
|
63
|
-
- `app/routes/` — page routes, one file per URL. The default renderIntent is
|
|
64
|
-
`static`: prerendered at build time (SSG). `/about` and `/` are static.
|
|
65
|
-
- `app/routes/api/` — request-time server routes. `/api/ping` is a plain
|
|
66
|
-
WinterCG-shaped handler returning `Response.json`.
|
|
67
|
-
- `app/components/` — compiled page elements and their style sheets
|
|
68
|
-
(page CSS lives in `.css` files next to each element; pages import and
|
|
69
|
-
array them in `static styles`, sharing `site-chrome.css`/`badges.css`).
|
|
70
|
-
- `app/islands/` — client islands, the only code that ships JavaScript. Each
|
|
71
|
-
island declares its hydration strategy (`idle`, `load`, `visible`,
|
|
72
|
-
client-only) through `defineIslandConfig`. The directory also hosts
|
|
73
|
-
`app-shell.tsx` — not an island itself, but the auto-registered application
|
|
74
|
-
shell (see below).
|
|
75
|
-
- `app/islands/app-shell.tsx` — the site chrome every page renders inside:
|
|
76
|
-
the header, the `main` content region, and the footer live here exactly
|
|
77
|
-
once instead of being copied onto each page. The build registers the shell
|
|
78
|
-
automatically and projects each page's render into its default slot, so a
|
|
79
|
-
page module carries only its own content. The shell is a convention: delete
|
|
80
|
-
the file and pages still render (carrying their own chrome again), or opt
|
|
81
|
-
out explicitly with `appShell: false` in `openelement.config.ts`.
|
|
82
|
-
- `app/styles/theme.css` — the @theme role sheet: Tailwind-ON roles, the starter palette aliases, dark and forced-colors pairs. Dev serves it directly; the build compiles it through the router's Tailwind preset.
|
|
83
|
-
Dark values ride `prefers-color-scheme`; no theme runtime.
|
|
84
|
-
- `app/styles/recipes.css` — documented plain HTML+CSS recipes for the
|
|
85
|
-
zero-interaction shapes (badge, callout, card, CSS-only tabs) that retired
|
|
86
|
-
from `@openelement/ui` (#1557). Delete the blocks you do not use: static
|
|
87
|
-
content never justifies a custom element.
|
|
88
|
-
- `app/head.tsx` — structural head content the URL list cannot express.
|
|
32
|
+
A page with no islands of its own can still load the app-wide claim bootstrap
|
|
33
|
+
when other pages in the app use islands.
|
|
89
34
|
|
|
90
35
|
## Scripts
|
|
91
36
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
- `
|
|
95
|
-
- `
|
|
96
|
-
- `
|
|
97
|
-
- `pnpm typecheck` — type-check every route/component file (`tsc --noEmit`).
|
|
98
|
-
The check covers the whole `app/` directory (`tsconfig.json`), so new files
|
|
99
|
-
are picked up automatically.
|
|
100
|
-
- `pnpm test` — run Node's built-in test runner (the starter ships none).
|
|
101
|
-
- `pnpm build` — production build into `dist/`: prerendered HTML for every
|
|
102
|
-
static route, plus the request-time server when the app has one.
|
|
103
|
-
- `pnpm start` — serve the production build.
|
|
104
|
-
|
|
105
|
-
`build` and `start` run the router CLI's short `oe` bin from the
|
|
106
|
-
`@openelement/router` dependency (`oe build` / `oe start`; the same entry is
|
|
107
|
-
installed as `openelement`, so both spellings work). The CLI also carries a
|
|
108
|
-
static-only `oe start --mode=preview`, which refuses a build that has a
|
|
109
|
-
request-time server.
|
|
110
|
-
|
|
111
|
-
The Vite tree itself is catalog-managed: `pnpm-workspace.yaml` points `vite`
|
|
112
|
-
at the Vite+ core (`@voidzero-dev/vite-plus-core`) through a catalog entry
|
|
113
|
-
and a `vite@*` override, so every peer that asks for vite resolves the same
|
|
114
|
-
Vite+ build — there is no direct `vite` devDependency to pin.
|
|
115
|
-
|
|
116
|
-
## Styling ownership
|
|
117
|
-
|
|
118
|
-
Global design tokens and the document baseline (`body`, `::selection`) live
|
|
119
|
-
in `app/styles/theme.css`. The app shell owns the shared chrome sheet
|
|
120
|
-
(`app/components/site-chrome.css`), arrayed in its `static styles`. Pages use
|
|
121
|
-
light roots and own their rules in `static styles`, arrayed from imported
|
|
122
|
-
`.css` files (#1558 — the one style authoring form): the server inlines each
|
|
123
|
-
page's sheets into the SSR output as a `@scope(<page-tag>)` style block, so
|
|
124
|
-
pages are fully styled with zero client JavaScript. Islands carry their own
|
|
125
|
-
`.css` sheets the same way; in island chunks those ride the style-asset
|
|
126
|
-
protocol as real `.css` assets.
|
|
127
|
-
|
|
128
|
-
## Brand assets
|
|
129
|
-
|
|
130
|
-
`public/openelement-mark.svg` is the openElement brand mark shipped with the
|
|
131
|
-
starter — the config file references it as the favicon, or delete it if
|
|
132
|
-
unused.
|
|
133
|
-
|
|
134
|
-
## Dependency notes
|
|
37
|
+
- `npm test` checks the ping route with the Node.js test runner.
|
|
38
|
+
- `npm run typecheck` type-checks application code, tests and configuration.
|
|
39
|
+
- `npm run fmt` formats the source. `npm run lint` checks it.
|
|
40
|
+
- `npm run build` writes the public upload directory `dist-public/` and the request-time server in `dist/server/`. Run `npx oe publish --check` before uploading public files.
|
|
41
|
+
- `npm start` serves the production build.
|
|
135
42
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
the `pnpm-workspace.yaml` catalog), the Tailwind-ON build-time pins, the
|
|
140
|
-
dev-server pair — `@hono/vite-dev-server` (loaded lazily by the dev server)
|
|
141
|
-
and its `hono` peer — and the `typescript` pin. None of them resolve under a
|
|
142
|
-
production install: `npm install --omit=dev` in a production image installs
|
|
143
|
-
only the runtime pair. The generated server entry itself imports no
|
|
144
|
-
HTTP framework — it composes on the internal WinterCG layer (#1560); `hono`
|
|
145
|
-
is an optional peer of `@openelement/router`, and `@openelement/router/hono`
|
|
146
|
-
(`createHonoAdapter`) is the one opt-in if you ever want to mount the built
|
|
147
|
-
handler inside your own Hono app. For Nitro deployments, the built handler
|
|
148
|
-
bridges through the `@openelement/router/nitro-mount` subpath of the one
|
|
149
|
-
`@openelement/router` dependency. Do not remove them.
|
|
43
|
+
Framework options live in `openelement.config.ts`. Vite configuration lives in
|
|
44
|
+
`vite.config.ts`. The router writes its working files to `.openElement/` and
|
|
45
|
+
recreates the directory as needed.
|
|
150
46
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
supply-chain window that withholds freshly published versions — with the
|
|
154
|
-
exemptions this project starts with (the `@openelement` packages at the
|
|
155
|
-
version it was generated from, plus `vite-plus`). pnpm rewrites the file when
|
|
156
|
-
you approve more packages inside that window; keep it and review the
|
|
157
|
-
exemptions it lists.
|
|
47
|
+
To create another project, use `npm create @openelement <project-name>`.
|
|
48
|
+
[Documentation](https://openelement.org)
|
|
@@ -1,32 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* app/head.tsx —
|
|
2
|
+
* app/head.tsx — structural document-head content: the entries a URL list
|
|
3
|
+
* cannot express (here, the color-scheme declaration).
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* a
|
|
5
|
+
* Entries are DATA and are emitted in the order written: `{ meta: {...} }` is
|
|
6
|
+
* one meta tag, `{ link: { rel, href } }` one link tag, `{ style: 'css' }` one
|
|
7
|
+
* inline style block. The build compiles this module, so it can import CSS by
|
|
8
|
+
* URL and pull local constants — but it must not use host APIs: its output is
|
|
9
|
+
* a build artifact.
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* The module is compiled by the build, so it can import CSS by URL
|
|
16
|
-
* (`import css from './site.css?raw'`) and pull constants from local modules.
|
|
17
|
-
* It must not use host APIs (no Deno, no Node): its output is a build artifact,
|
|
18
|
-
* so a runtime read would make the document depend on the build machine.
|
|
19
|
-
*
|
|
20
|
-
* `head` in openelement.config.ts already covers the title, description,
|
|
21
|
-
* favicon and the og:/twitter: pairs; `head.scripts` / `head.stylesheets`
|
|
22
|
-
* cover external scripts and stylesheets. This file is for what neither can
|
|
23
|
-
* express — here, the color-scheme declaration. A route module's `head`
|
|
24
|
-
* resolves at render time: its title and description update only <title> and
|
|
25
|
-
* the meta description. The og:* tags keep the site-wide defaults except
|
|
26
|
-
* where the route's `head.meta` declares the same `property="og:…"` — that
|
|
27
|
-
* property's site default is then not emitted (the route's own tag is the
|
|
28
|
-
* only one, in prerendered and request-rendered HTML alike). `name=` meta
|
|
29
|
-
* entries (e.g. twitter:card) never suppress a site default.
|
|
11
|
+
* Title, description, favicon and the og:/twitter: pairs come from `head` in
|
|
12
|
+
* openelement.config.ts. A route's own `head.meta` overrides a site default
|
|
13
|
+
* with the same property; `name=` entries never suppress one. Delete this file
|
|
14
|
+
* and the starter still builds — it is a convention, not a requirement.
|
|
30
15
|
*/
|
|
31
16
|
export default [
|
|
32
17
|
// Declaring the color scheme the starter supports lets the browser pick the
|
|
@@ -1,23 +1,5 @@
|
|
|
1
|
+
/* The island shadow host's box; the row and clock are authored as Tailwind
|
|
2
|
+
utilities in live-timer.tsx. */
|
|
1
3
|
:host {
|
|
2
4
|
display: inline-block;
|
|
3
5
|
}
|
|
4
|
-
.timer-row {
|
|
5
|
-
display: inline-flex;
|
|
6
|
-
gap: 0.6rem;
|
|
7
|
-
align-items: baseline;
|
|
8
|
-
}
|
|
9
|
-
/* #1582: the selector names the id the class renders (#elapsed) — a
|
|
10
|
-
`.value` selector matched nothing, so the clock lost its brand color
|
|
11
|
-
and tabular figures. */
|
|
12
|
-
#elapsed {
|
|
13
|
-
min-width: 6ch;
|
|
14
|
-
text-align: right;
|
|
15
|
-
font-variant-numeric: tabular-nums;
|
|
16
|
-
font-weight: 600;
|
|
17
|
-
font-size: 1.4rem;
|
|
18
|
-
color: var(--brand);
|
|
19
|
-
}
|
|
20
|
-
.unit {
|
|
21
|
-
color: var(--ink-soft);
|
|
22
|
-
font-size: 0.85rem;
|
|
23
|
-
}
|