@openelement/create 1.0.0-alpha.1 → 1.0.0-alpha.11
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 +99 -28
- package/package.json +15 -4
- package/src/cli.d.ts +1 -1
- package/src/cli.js +254 -65
- package/src/install-command.d.ts +50 -0
- package/src/install-command.js +52 -0
- package/src/pm.js +30 -0
- package/src/template-builder.js +78 -174
- package/src/version.js +12 -6
- package/templates/README.tmpl +110 -47
- package/templates/app/components/badges.css +5 -0
- package/templates/app/components/page-404.css +7 -0
- package/templates/app/components/page-404.tsx.tmpl +32 -11
- package/templates/app/components/page-about.css +15 -0
- package/templates/app/components/page-about.tsx.tmpl +93 -0
- package/templates/app/components/page-home.css +23 -0
- package/templates/app/components/page-home.tsx.tmpl +114 -40
- package/templates/app/components/site-chrome.css +15 -0
- package/templates/app/head.tsx.tmpl +32 -0
- package/templates/app/islands/live-timer.css +6 -0
- package/templates/app/islands/live-timer.tsx.tmpl +54 -0
- package/templates/app/islands/my-counter.css +11 -0
- package/templates/app/islands/my-counter.tsx.tmpl +5 -4
- package/templates/app/routes/about.tsx.tmpl +10 -0
- package/templates/app/routes/api/ping.ts.tmpl +12 -0
- package/templates/app/routes/index.tsx.tmpl +2 -2
- package/templates/app/styles/recipes.css +43 -0
- package/templates/app/styles/theme.css +170 -0
- package/templates/gitignore.tmpl +1 -0
- package/templates/openelement.config.ts.tmpl +39 -0
- package/templates/package.json.tmpl +26 -1
- package/templates/tsconfig.json.tmpl +16 -0
- package/templates/vite.config.ts.tmpl +6 -32
- package/templates/app/components/page-blog-index.tsx.tmpl +0 -39
- package/templates/app/components/page-blog-welcome.tsx.tmpl +0 -57
- package/templates/app/components/page-contact.tsx.tmpl +0 -49
- package/templates/app/components/page-freshness.tsx.tmpl +0 -26
- package/templates/app/components/page-styles.ts.tmpl +0 -166
- package/templates/app/islands/app-shell.tsx.tmpl +0 -58
- package/templates/app/islands/only-ticker.tsx.tmpl +0 -34
- package/templates/app/routes/api/health.ts.tmpl +0 -7
- package/templates/app/routes/blog/index.tsx.tmpl +0 -10
- package/templates/app/routes/blog/welcome.tsx.tmpl +0 -7
- package/templates/app/routes/contact.tsx.tmpl +0 -36
- package/templates/app/routes/freshness.tsx.tmpl +0 -17
- package/templates/deno.json.tmpl +0 -25
package/README.md
CHANGED
|
@@ -2,30 +2,78 @@
|
|
|
2
2
|
|
|
3
3
|
Project scaffolding CLI for openElement applications.
|
|
4
4
|
|
|
5
|
+
Docs and guides: <https://openelement.org>.
|
|
6
|
+
|
|
5
7
|
> 1.0 Alpha line: the supported creation entry for Element and Router. The
|
|
6
|
-
> published npm versions and dist-tags are
|
|
7
|
-
> `
|
|
8
|
-
>
|
|
8
|
+
> published npm versions and dist-tags are registry truth (query them with
|
|
9
|
+
> `npm view @openelement/create dist-tags`); `latest` stays on the stable 0.43
|
|
10
|
+
> line until a separately admitted stable release.
|
|
9
11
|
|
|
10
|
-
`@openelement/create` generates a new openElement project
|
|
11
|
-
|
|
12
|
+
`@openelement/create` generates a new openElement project from ONE template —
|
|
13
|
+
the showcase starter: a static-first landing page with two islands, a fully
|
|
14
|
+
static About page, an `/api/ping` server route, and a pure-CSS design-token
|
|
15
|
+
sheet (no Tailwind, no template variants). The generated project is a plain
|
|
16
|
+
Node/pnpm project.
|
|
12
17
|
|
|
13
18
|
## Usage (1.0 Alpha)
|
|
14
19
|
|
|
15
20
|
```bash
|
|
16
|
-
|
|
17
|
-
cd my-app
|
|
18
|
-
deno task dev
|
|
21
|
+
npm create @openelement@alpha my-app
|
|
19
22
|
```
|
|
20
23
|
|
|
21
|
-
The
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
The CLI scaffolds, initializes git (when git is available), detects a package
|
|
25
|
+
manager (pnpm first, then npm), installs dependencies, and prints a boxed
|
|
26
|
+
handoff with the next commands. Flags (all optional):
|
|
27
|
+
|
|
28
|
+
| Flag | Default | Meaning |
|
|
29
|
+
| --- | --- | --- |
|
|
30
|
+
| `-t, --template <name>` | `showcase` | the template to scaffold; skips the interactive confirmation |
|
|
31
|
+
| `--install` / `--no-install` | install | dependency installation after scaffolding |
|
|
32
|
+
| `--start` | off | start the dev server after a successful install |
|
|
33
|
+
| `--git` / `--no-git` | git init | initialize a git repository (requires the scaffold's `.gitignore`) |
|
|
34
|
+
|
|
35
|
+
On a TTY the CLI asks exactly one question — confirming the template (Enter
|
|
36
|
+
accepts the default). Non-interactive runs (CI, packed consumers) skip the
|
|
37
|
+
prompt and take the defaults; pass `-t` to pin the template explicitly.
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx @openelement/create@alpha my-app --no-install --no-git -t showcase
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`npm create @openelement@alpha` rides npm's initializer alias: a bare `@scope`
|
|
44
|
+
resolves to `@scope/create` at the same tag, so the canonical spelling names
|
|
45
|
+
the scope, and npm runs this package's generator. The version `@alpha` resolves
|
|
46
|
+
to is registered in
|
|
47
|
+
`the tracked release-state manifest` (currently `1.0.0-alpha.10`, a new baseline —
|
|
48
|
+
not a 0.x upgrade, with no migration path from 0.x). Pin that exact version
|
|
49
|
+
when reproducibility matters (verify against the live registry with
|
|
50
|
+
`npm view @openelement/create dist-tags.alpha`):
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm create @openelement@1.0.0-alpha.10 my-app
|
|
54
|
+
```
|
|
26
55
|
|
|
27
56
|
The generated starter pins the exact `@openelement/*` versions it was built
|
|
28
|
-
from in its `
|
|
57
|
+
from in its `package.json` dependencies.
|
|
58
|
+
|
|
59
|
+
The canonical install command is exported from `@openelement/create/install-command` (one builder, every documented copy derives from it).
|
|
60
|
+
|
|
61
|
+
## The bootstrap is a plain npm invocation; the generated project is Node
|
|
62
|
+
|
|
63
|
+
The documented bootstrap runs the generator through `npm create` (or the
|
|
64
|
+
`npx` short form, or `pnpm dlx`) — plain Node tooling, no second runtime.
|
|
65
|
+
Node.js 24.2+ is the only host requirement for both the bootstrap and the
|
|
66
|
+
generated project. The packed package ships two equivalent npm bins
|
|
67
|
+
(`openelement-create`, `create-openelement`, both the same entry), so the pnpm
|
|
68
|
+
form must name one explicitly:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npx @openelement/create@alpha my-app
|
|
72
|
+
pnpm dlx --package=@openelement/create@alpha openelement-create my-app
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The scaffolded project itself is Node-native: Node.js 24.2+ and
|
|
76
|
+
pnpm run its scripts.
|
|
29
77
|
|
|
30
78
|
## Stable 0.43 (maintenance line)
|
|
31
79
|
|
|
@@ -34,30 +82,53 @@ A versionless install resolves the npm `latest` dist-tag to it; pin the line
|
|
|
34
82
|
explicitly instead:
|
|
35
83
|
|
|
36
84
|
```bash
|
|
37
|
-
|
|
85
|
+
npm create @openelement@0.43 my-app
|
|
38
86
|
```
|
|
39
87
|
|
|
40
88
|
## Requirements
|
|
41
89
|
|
|
42
|
-
**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
90
|
+
- **Bootstrap:** Node.js 24.2+ with npm (or pnpm for the `pnpm dlx` variant) —
|
|
91
|
+
the verified floor this repository exercises in CI.
|
|
92
|
+
- **Generated project:** Node.js 24.2+ (the floor the packed `@openelement/*`
|
|
93
|
+
engines declare and CI exercises; `.node-version` pins the development
|
|
94
|
+
line) and pnpm for the lifecycle scripts.
|
|
95
|
+
- **git (optional):** `git init` runs by default and skips silently when git
|
|
96
|
+
is not on PATH.
|
|
47
97
|
|
|
48
98
|
## What It Creates
|
|
49
99
|
|
|
50
|
-
- `
|
|
51
|
-
|
|
52
|
-
- `
|
|
53
|
-
|
|
54
|
-
|
|
100
|
+
- `package.json` - starter dependencies (exact `@openelement/*` release pins)
|
|
101
|
+
and the lifecycle scripts (`dev`/`check`/`test`/`build`/`start`/`preview`)
|
|
102
|
+
- `tsconfig.json` - the type-check surface for `pnpm check`: JSX authoring
|
|
103
|
+
through the element import source, whole-`app/` coverage
|
|
104
|
+
- `vite.config.ts` - Vite build configuration only; framework options still
|
|
105
|
+
have exactly one home:
|
|
106
|
+
- `openelement.config.ts` - the framework options. It is OPTIONAL and nearly
|
|
107
|
+
empty by default; every option it omits comes from a file convention —
|
|
108
|
+
design tokens from `app/styles/theme.css` (the @theme role sheet), structural document-head
|
|
109
|
+
content from `app/head.tsx`, the site title from `package.json`. Passing
|
|
110
|
+
framework options inline to `openElement()` while this file carries options
|
|
111
|
+
is a hard error, and an unknown key fails the build with the accepted-key
|
|
112
|
+
list.
|
|
113
|
+
- `app/` - the showcase application:
|
|
114
|
+
- `app/routes/` — page routes (`/`, `/about`, the styled 404), prerendered
|
|
115
|
+
at build time (SSG)
|
|
116
|
+
- `app/routes/api/ping.ts` — a request-time server route returning
|
|
117
|
+
`Response.json`
|
|
118
|
+
- `app/islands/` — the two islands (`my-counter` hydrating on idle,
|
|
119
|
+
`live-timer` client-only), the only code that ships JavaScript
|
|
120
|
+
- `app/components/` — compiled page elements and their style sheets
|
|
121
|
+
(`.css` files next to each element; `site-chrome.css`/`badges.css` are
|
|
122
|
+
the shared sheets)
|
|
123
|
+
- `app/styles/theme.css` — the @theme role sheet, Tailwind-ON single-default
|
|
124
|
+
scaffold form (dark values ride
|
|
125
|
+
`prefers-color-scheme`)
|
|
55
126
|
- `public/` - static assets
|
|
56
127
|
- `README.md` and `.gitignore` - starter docs and ignore rules
|
|
57
128
|
|
|
58
|
-
The generated
|
|
59
|
-
the starter surface. Advanced contracts remain available through the
|
|
60
|
-
workspace packages when a project needs them.
|
|
129
|
+
The generated dependency set intentionally keeps protocol and build internals
|
|
130
|
+
out of the starter surface. Advanced contracts remain available through the
|
|
131
|
+
published workspace packages when a project needs them.
|
|
61
132
|
|
|
62
133
|
## License
|
|
63
134
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openelement/create",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/cli.js",
|
|
6
6
|
"types": "./src/cli.d.ts",
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
"types": "./src/cli.d.ts",
|
|
10
10
|
"import": "./src/cli.js",
|
|
11
11
|
"default": "./src/cli.js"
|
|
12
|
+
},
|
|
13
|
+
"./install-command": {
|
|
14
|
+
"types": "./src/install-command.d.ts",
|
|
15
|
+
"import": "./src/install-command.js",
|
|
16
|
+
"default": "./src/install-command.js"
|
|
12
17
|
}
|
|
13
18
|
},
|
|
14
19
|
"repository": {
|
|
@@ -22,9 +27,15 @@
|
|
|
22
27
|
"keywords": [
|
|
23
28
|
"openelement",
|
|
24
29
|
"web-components",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
30
|
+
"scaffolding",
|
|
31
|
+
"generator",
|
|
32
|
+
"starter"
|
|
33
|
+
],
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=24.2"
|
|
36
|
+
},
|
|
37
|
+
"sideEffects": [
|
|
38
|
+
"./src/cli.js"
|
|
28
39
|
],
|
|
29
40
|
"bin": {
|
|
30
41
|
"openelement-create": "./src/cli.js",
|
package/src/cli.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {}
|
package/src/cli.js
CHANGED
|
@@ -1,79 +1,268 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { buildTemplates, resolveVersions, validateProjectName } from "./template-builder.js";
|
|
3
|
+
import { createInstallCommand } from "./install-command.js";
|
|
4
|
+
import { detectPackageManager } from "./pm.js";
|
|
5
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { mkdir, stat, writeFile } from "node:fs/promises";
|
|
8
|
+
import process from "node:process";
|
|
9
|
+
import readline from "node:readline/promises";
|
|
10
|
+
//#region src/cli.ts
|
|
2
11
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
* @openelement/create - project scaffold for the openElement framework.
|
|
13
|
+
*
|
|
14
|
+
* The install command this CLI documents is built by ./install-command.ts
|
|
15
|
+
* (#1414): usage output, the guides and the homepage all render that one
|
|
16
|
+
* string, so the documented command cannot drift from the shipped flags.
|
|
17
|
+
*
|
|
18
|
+
* One template (#1530): the showcase starter — a static-first landing page
|
|
19
|
+
* with two islands, a fully static About page, and an /api/ping server route.
|
|
20
|
+
* The interactive surface is one confirmation (the template) on a TTY; every
|
|
21
|
+
* other behavior is a flag with a default, so CI and packed consumers run
|
|
22
|
+
* without a prompt.
|
|
23
|
+
*
|
|
24
|
+
* Post-scaffold lifecycle: git init (default), dependency install via the
|
|
25
|
+
* detected package manager (pnpm first, then npm — default on), an optional
|
|
26
|
+
* dev-server start (--start), and a boxed handoff naming the next commands.
|
|
27
|
+
*
|
|
28
|
+
* L9: every failure mode exits 1 with one actionable message — never a
|
|
29
|
+
* runtime stack trace.
|
|
30
|
+
*/
|
|
31
|
+
/** The one scaffold template (#1530). `-t/--template` pins it non-interactively. */
|
|
32
|
+
const TEMPLATE_NAME = "showcase";
|
|
33
|
+
const DOCS_URL = "https://openelement.org";
|
|
14
34
|
function errorMessage(error) {
|
|
15
|
-
|
|
35
|
+
return error instanceof Error ? error.message : String(error);
|
|
36
|
+
}
|
|
37
|
+
/** node:fs error shape for "path does not exist". */
|
|
38
|
+
function isNotFound(error) {
|
|
39
|
+
return error.code === "ENOENT";
|
|
40
|
+
}
|
|
41
|
+
/** node:fs error shapes for "not permitted". */
|
|
42
|
+
function isPermissionDenied(error) {
|
|
43
|
+
const code = error.code;
|
|
44
|
+
return code === "EACCES" || code === "EPERM";
|
|
16
45
|
}
|
|
17
46
|
function fail(message) {
|
|
18
|
-
|
|
19
|
-
|
|
47
|
+
console.error(`error: ${message}`);
|
|
48
|
+
process.exit(1);
|
|
20
49
|
}
|
|
21
50
|
function joinPosix(...parts) {
|
|
22
|
-
|
|
51
|
+
return parts.join("/").replace(/\/{2,}/g, "/");
|
|
23
52
|
}
|
|
24
53
|
function dirnameOf(path) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
54
|
+
const idx = path.replace(/\\+/g, "/").lastIndexOf("/");
|
|
55
|
+
if (idx <= 0) return ".";
|
|
56
|
+
return path.slice(0, idx);
|
|
57
|
+
}
|
|
58
|
+
/** Pairwise flag reconciliation: a flag and its negation cannot both appear. */
|
|
59
|
+
function setExclusiveFlag(current, incoming, pair) {
|
|
60
|
+
if (current !== void 0 && current !== incoming) fail(`--${incoming ? "" : "no-"}${pair} and --${incoming ? "no-" : ""}${pair} are mutually exclusive.`);
|
|
61
|
+
return incoming;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The CLI flags and the project-name positional, parsed without a library.
|
|
65
|
+
* Unknown dash-args are rejected (L9) instead of silently ignored; only
|
|
66
|
+
* --help/-h short-circuits before parsing.
|
|
67
|
+
*/
|
|
68
|
+
function parseArgs(argv) {
|
|
69
|
+
const flags = {
|
|
70
|
+
start: false,
|
|
71
|
+
help: false
|
|
72
|
+
};
|
|
73
|
+
for (let i = 0; i < argv.length; i++) {
|
|
74
|
+
let arg = argv[i];
|
|
75
|
+
if (arg.startsWith("--template=")) {
|
|
76
|
+
argv = [
|
|
77
|
+
...argv.slice(0, i),
|
|
78
|
+
"--template",
|
|
79
|
+
arg.slice(11),
|
|
80
|
+
...argv.slice(i + 1)
|
|
81
|
+
];
|
|
82
|
+
arg = "--template";
|
|
83
|
+
}
|
|
84
|
+
switch (arg) {
|
|
85
|
+
case "-h":
|
|
86
|
+
case "--help":
|
|
87
|
+
flags.help = true;
|
|
88
|
+
break;
|
|
89
|
+
case "-t":
|
|
90
|
+
case "--template": {
|
|
91
|
+
const value = argv[++i];
|
|
92
|
+
if (value === void 0) fail(`--template requires a value (the template name).`);
|
|
93
|
+
flags.template = value;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case "--install":
|
|
97
|
+
flags.install = setExclusiveFlag(flags.install, true, "install");
|
|
98
|
+
break;
|
|
99
|
+
case "--no-install":
|
|
100
|
+
flags.install = setExclusiveFlag(flags.install, false, "install");
|
|
101
|
+
break;
|
|
102
|
+
case "--start":
|
|
103
|
+
flags.start = true;
|
|
104
|
+
break;
|
|
105
|
+
case "--git":
|
|
106
|
+
flags.git = setExclusiveFlag(flags.git, true, "git");
|
|
107
|
+
break;
|
|
108
|
+
case "--no-git":
|
|
109
|
+
flags.git = setExclusiveFlag(flags.git, false, "git");
|
|
110
|
+
break;
|
|
111
|
+
default:
|
|
112
|
+
if (arg.startsWith("-")) fail(`Unknown flag "${arg}". Run with --help to see the available flags (a project name is a bare positional).`);
|
|
113
|
+
if (flags.name !== void 0) fail(`Unexpected extra argument "${arg}" — the project name is the single positional.`);
|
|
114
|
+
flags.name = arg;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return flags;
|
|
118
|
+
}
|
|
119
|
+
function printUsage() {
|
|
120
|
+
console.log(`Usage (Alpha): ${createInstallCommand()}`);
|
|
121
|
+
console.log("(a versionless install resolves the stable 0.43 line)");
|
|
122
|
+
console.log(` -t, --template <name> scaffold template (default: ${TEMPLATE_NAME})`);
|
|
123
|
+
console.log(" --install / --no-install");
|
|
124
|
+
console.log(" install dependencies after scaffolding (default: install)");
|
|
125
|
+
console.log(" --start start the dev server after a successful install");
|
|
126
|
+
console.log(" --git / --no-git initialize a git repository (default: git init)");
|
|
127
|
+
console.log(" -h, --help show this help");
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Resolve the template: a flag wins without prompting; a TTY confirms the
|
|
131
|
+
* choice with the one scaffold question (default accepts); a non-TTY run
|
|
132
|
+
* (CI, packed consumers) takes the default without prompting.
|
|
133
|
+
*/
|
|
134
|
+
async function resolveTemplate(flag) {
|
|
135
|
+
if (flag !== void 0) {
|
|
136
|
+
if (flag !== TEMPLATE_NAME) fail(`Unknown template "${flag}". The available template is: ${TEMPLATE_NAME}.`);
|
|
137
|
+
return flag;
|
|
138
|
+
}
|
|
139
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) return TEMPLATE_NAME;
|
|
140
|
+
const rl = readline.createInterface({
|
|
141
|
+
input: process.stdin,
|
|
142
|
+
output: process.stdout
|
|
143
|
+
});
|
|
144
|
+
try {
|
|
145
|
+
for (;;) {
|
|
146
|
+
const answer = (await rl.question(`Template to scaffold (${TEMPLATE_NAME}): `)).trim();
|
|
147
|
+
if (answer === "") return TEMPLATE_NAME;
|
|
148
|
+
if (answer === TEMPLATE_NAME) return answer;
|
|
149
|
+
console.info(` unknown template "${answer}" — available: ${TEMPLATE_NAME}`);
|
|
150
|
+
}
|
|
151
|
+
} finally {
|
|
152
|
+
rl.close();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* `git init` in the scaffolded project. Git unavailable (ENOENT) is a silent
|
|
157
|
+
* skip (the ask's contract); any other failure prints one note line and keeps
|
|
158
|
+
* the scaffold successful — the repository is a convenience, not the product.
|
|
159
|
+
*/
|
|
160
|
+
function initGitRepository(targetDir, relativeTarget) {
|
|
161
|
+
const result = spawnSync("git", ["init"], {
|
|
162
|
+
cwd: targetDir,
|
|
163
|
+
stdio: "ignore"
|
|
164
|
+
});
|
|
165
|
+
if (result.error !== void 0) {
|
|
166
|
+
if (result.error.code === "ENOENT") return;
|
|
167
|
+
console.info(` note: git init could not run (${errorMessage(result.error)}); skipping.`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (result.status !== 0) {
|
|
171
|
+
console.info(` note: git init exited ${result.status ?? "unknown"} in ${relativeTarget}; skipping.`);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
console.info(" initialized git repository (with .gitignore)");
|
|
175
|
+
}
|
|
176
|
+
/** The boxed end-of-run handoff: where to go, what to run, where to read. */
|
|
177
|
+
function printHandoff(relativeTarget, pm, startRequested) {
|
|
178
|
+
const devCommand = pm ? `${pm} run dev` : "pnpm run dev";
|
|
179
|
+
const lines = [
|
|
180
|
+
"openElement project ready",
|
|
181
|
+
"",
|
|
182
|
+
`cd ${relativeTarget}`,
|
|
183
|
+
`${devCommand} # start the dev server`,
|
|
184
|
+
"",
|
|
185
|
+
`Docs: ${DOCS_URL}`
|
|
186
|
+
];
|
|
187
|
+
if (startRequested) lines.push("", "The dev server is starting — press Ctrl-C to stop it.");
|
|
188
|
+
const width = Math.max(...lines.map((line) => line.length));
|
|
189
|
+
console.info(`┌─${"─".repeat(width)}─┐`);
|
|
190
|
+
for (const line of lines) console.info(`│ ${line.padEnd(width)} │`);
|
|
191
|
+
console.info(`└─${"─".repeat(width)}─┘`);
|
|
29
192
|
}
|
|
30
193
|
async function main() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
194
|
+
const flags = parseArgs(process.argv.slice(2));
|
|
195
|
+
if (flags.help) {
|
|
196
|
+
printUsage();
|
|
197
|
+
process.exit(0);
|
|
198
|
+
}
|
|
199
|
+
if (flags.start && flags.install === false) fail("--start needs the dependencies installed; drop --no-install (or scaffold first and run the dev server manually inside the project directory).");
|
|
200
|
+
const name = flags.name;
|
|
201
|
+
if (!name) {
|
|
202
|
+
console.error("error: a project name is required.");
|
|
203
|
+
console.error("");
|
|
204
|
+
printUsage();
|
|
205
|
+
process.exit(1);
|
|
206
|
+
}
|
|
207
|
+
const invalid = validateProjectName(name);
|
|
208
|
+
if (invalid) fail(`Invalid project name "${name}". ${invalid}`);
|
|
209
|
+
const targetDir = `${process.cwd().replace(/\/+$/, "")}/${name}`;
|
|
210
|
+
const relativeTarget = name;
|
|
211
|
+
if (!relativeTarget || relativeTarget.includes("..") || relativeTarget.includes("/") || relativeTarget.includes("\\") || /^[a-zA-Z]:/.test(relativeTarget) || relativeTarget.startsWith("/")) fail(`Refusing to create project outside the current directory: ${name}`);
|
|
212
|
+
try {
|
|
213
|
+
await stat(targetDir);
|
|
214
|
+
fail(`Directory "${name}" already exists. Choose a different name or remove the existing directory.`);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
if (!isNotFound(error)) throw new Error(`Could not inspect target directory "${name}": ${errorMessage(error)}`);
|
|
217
|
+
}
|
|
218
|
+
const template = await resolveTemplate(flags.template);
|
|
219
|
+
const v = resolveVersions();
|
|
220
|
+
try {
|
|
221
|
+
await mkdir(targetDir, { recursive: true });
|
|
222
|
+
const TPL = await buildTemplates(v, name);
|
|
223
|
+
for (const [path, content] of Object.entries(TPL)) {
|
|
224
|
+
const fullPath = joinPosix(targetDir, path);
|
|
225
|
+
await mkdir(dirnameOf(fullPath), { recursive: true });
|
|
226
|
+
await writeFile(fullPath, content, "utf8");
|
|
227
|
+
console.info(` created ${path}`);
|
|
228
|
+
}
|
|
229
|
+
} catch (error) {
|
|
230
|
+
const detail = isPermissionDenied(error) ? `Permission denied. Check write permissions for ${targetDir}.` : errorMessage(error);
|
|
231
|
+
throw new Error(`Failed to write project files in "${name}": ${detail} Remove the partially created directory before retrying.`);
|
|
232
|
+
}
|
|
233
|
+
console.info(`\nopenElement project created at ./${relativeTarget}/ (template: ${template})`);
|
|
234
|
+
if (flags.git !== false) {
|
|
235
|
+
if (!existsSync(joinPosix(targetDir, ".gitignore"))) fail("The scaffold did not write .gitignore; refusing to initialize a repository that would track build output. Remove the directory and retry.");
|
|
236
|
+
initGitRepository(targetDir, relativeTarget);
|
|
237
|
+
}
|
|
238
|
+
let pm = null;
|
|
239
|
+
if (flags.install !== false) {
|
|
240
|
+
pm = detectPackageManager();
|
|
241
|
+
console.info(`\nInstalling dependencies with ${pm}...`);
|
|
242
|
+
const install = spawnSync(pm, ["install"], {
|
|
243
|
+
cwd: targetDir,
|
|
244
|
+
stdio: "inherit",
|
|
245
|
+
shell: process.platform === "win32"
|
|
246
|
+
});
|
|
247
|
+
if (install.error !== void 0) fail(`Could not run ${pm} (${errorMessage(install.error)}). The project files are complete at ./${relativeTarget}/ — install manually with: cd ${relativeTarget} && ${pm} install`);
|
|
248
|
+
if (install.status !== 0) fail(`${pm} install exited ${install.status ?? "unknown"}. The project files are complete at ./${relativeTarget}/ — inspect the output above, then retry manually with: cd ${relativeTarget} && ${pm} install`);
|
|
249
|
+
}
|
|
250
|
+
printHandoff(relativeTarget, pm, flags.start);
|
|
251
|
+
if (flags.start) {
|
|
252
|
+
if (pm === null) fail("--start needs a package manager; installation was skipped.");
|
|
253
|
+
const dev = spawn(pm, ["run", "dev"], {
|
|
254
|
+
cwd: targetDir,
|
|
255
|
+
stdio: "inherit",
|
|
256
|
+
shell: process.platform === "win32"
|
|
257
|
+
});
|
|
258
|
+
const code = await new Promise((resolve) => dev.once("exit", (c) => resolve(c ?? 1)));
|
|
259
|
+
process.exitCode = code;
|
|
260
|
+
}
|
|
74
261
|
}
|
|
75
262
|
try {
|
|
76
|
-
|
|
263
|
+
await main();
|
|
77
264
|
} catch (error) {
|
|
78
|
-
|
|
265
|
+
fail(errorMessage(error));
|
|
79
266
|
}
|
|
267
|
+
//#endregion
|
|
268
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//#region src/install-command.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The canonical install command — the ONE source every documented copy of it
|
|
4
|
+
* derives from (#1414 item 5).
|
|
5
|
+
*
|
|
6
|
+
* The command is data about this CLI, so it lives beside the CLI: `cli.ts`
|
|
7
|
+
* prints it in its usage output, the site's documentation generator inlines it
|
|
8
|
+
* into the guides and the homepage, and the install-command gate
|
|
9
|
+
* (the site's install-command generator --check) fails when any curated copy
|
|
10
|
+
* in the repository differs from this string. There is no second spelling to
|
|
11
|
+
* drift.
|
|
12
|
+
*
|
|
13
|
+
* This module is deliberately side-effect free (no top-level CLI execution):
|
|
14
|
+
* it is imported by the site build as well as by the CLI itself.
|
|
15
|
+
*/
|
|
16
|
+
/** The npm specifier the generator is published under. */
|
|
17
|
+
export declare const CREATE_PACKAGE_SPECIFIER = "@openelement/create";
|
|
18
|
+
/**
|
|
19
|
+
* The scope `npm create` resolves to {@linkcode CREATE_PACKAGE_SPECIFIER}:
|
|
20
|
+
* npm's initializer alias maps a bare `@scope` (optionally `@scope@<tag>`) to
|
|
21
|
+
* `@scope/create` at the same tag, so the canonical spelling never repeats the
|
|
22
|
+
* `/create` suffix (owner-verified against npm's init alias rules).
|
|
23
|
+
*/
|
|
24
|
+
export declare const CREATE_NPM_CREATE_SCOPE = "@openelement";
|
|
25
|
+
/** The dist-tag the documented install resolves; the exact version is registry truth. */
|
|
26
|
+
export declare const CREATE_INSTALL_TAG = "alpha";
|
|
27
|
+
/** Placeholder the usage text and the docs use in place of a project name. */
|
|
28
|
+
export declare const CREATE_PROJECT_PLACEHOLDER = "<project-name>";
|
|
29
|
+
/**
|
|
30
|
+
* The documented install command shapes, all verified against the published
|
|
31
|
+
* two-bin artifact (bins `openelement-create` and `create-openelement`, both
|
|
32
|
+
* `src/cli.js`; npm 11 / pnpm 12):
|
|
33
|
+
* - canonical: `npm create @openelement@<tag> <name>` — npm's `@scope`
|
|
34
|
+
* initializer alias resolves it to `@openelement/create@<tag>` (#1507
|
|
35
|
+
* revision, 2026-10-05; the former canonical `npm exec <pkg>@<tag> -- <name>`
|
|
36
|
+
* remains a verified spelling through the same artifact)
|
|
37
|
+
* - short form: `npx <pkg>@<tag> <name>`
|
|
38
|
+
* - pnpm: `pnpm dlx --package=<pkg>@<tag> openelement-create <name>` — the
|
|
39
|
+
* explicit `--package` plus bin is required because the packed package
|
|
40
|
+
* ships two bins, so a bare `pnpm dlx <pkg>` cannot resolve one (and no
|
|
41
|
+
* package named `create-openelement` exists on the registry).
|
|
42
|
+
*
|
|
43
|
+
* Owner ruling 2026-10-03: the former Deno bootstrap (`deno run` of the npm
|
|
44
|
+
* specifier) is retired with the Deno consumer surface; the generator is
|
|
45
|
+
* invoked through plain Node tooling.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createInstallCommand(projectName?: string, options?: {
|
|
48
|
+
tag?: string;
|
|
49
|
+
}): string;
|
|
50
|
+
//#endregion
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/install-command.ts
|
|
2
|
+
/**
|
|
3
|
+
* The canonical install command — the ONE source every documented copy of it
|
|
4
|
+
* derives from (#1414 item 5).
|
|
5
|
+
*
|
|
6
|
+
* The command is data about this CLI, so it lives beside the CLI: `cli.ts`
|
|
7
|
+
* prints it in its usage output, the site's documentation generator inlines it
|
|
8
|
+
* into the guides and the homepage, and the install-command gate
|
|
9
|
+
* (the site's install-command generator --check) fails when any curated copy
|
|
10
|
+
* in the repository differs from this string. There is no second spelling to
|
|
11
|
+
* drift.
|
|
12
|
+
*
|
|
13
|
+
* This module is deliberately side-effect free (no top-level CLI execution):
|
|
14
|
+
* it is imported by the site build as well as by the CLI itself.
|
|
15
|
+
*/
|
|
16
|
+
/** The npm specifier the generator is published under. */
|
|
17
|
+
const CREATE_PACKAGE_SPECIFIER = "@openelement/create";
|
|
18
|
+
/**
|
|
19
|
+
* The scope `npm create` resolves to {@linkcode CREATE_PACKAGE_SPECIFIER}:
|
|
20
|
+
* npm's initializer alias maps a bare `@scope` (optionally `@scope@<tag>`) to
|
|
21
|
+
* `@scope/create` at the same tag, so the canonical spelling never repeats the
|
|
22
|
+
* `/create` suffix (owner-verified against npm's init alias rules).
|
|
23
|
+
*/
|
|
24
|
+
const CREATE_NPM_CREATE_SCOPE = "@openelement";
|
|
25
|
+
/** The dist-tag the documented install resolves; the exact version is registry truth. */
|
|
26
|
+
const CREATE_INSTALL_TAG = "alpha";
|
|
27
|
+
/** Placeholder the usage text and the docs use in place of a project name. */
|
|
28
|
+
const CREATE_PROJECT_PLACEHOLDER = "<project-name>";
|
|
29
|
+
/**
|
|
30
|
+
* The documented install command shapes, all verified against the published
|
|
31
|
+
* two-bin artifact (bins `openelement-create` and `create-openelement`, both
|
|
32
|
+
* `src/cli.js`; npm 11 / pnpm 12):
|
|
33
|
+
* - canonical: `npm create @openelement@<tag> <name>` — npm's `@scope`
|
|
34
|
+
* initializer alias resolves it to `@openelement/create@<tag>` (#1507
|
|
35
|
+
* revision, 2026-10-05; the former canonical `npm exec <pkg>@<tag> -- <name>`
|
|
36
|
+
* remains a verified spelling through the same artifact)
|
|
37
|
+
* - short form: `npx <pkg>@<tag> <name>`
|
|
38
|
+
* - pnpm: `pnpm dlx --package=<pkg>@<tag> openelement-create <name>` — the
|
|
39
|
+
* explicit `--package` plus bin is required because the packed package
|
|
40
|
+
* ships two bins, so a bare `pnpm dlx <pkg>` cannot resolve one (and no
|
|
41
|
+
* package named `create-openelement` exists on the registry).
|
|
42
|
+
*
|
|
43
|
+
* Owner ruling 2026-10-03: the former Deno bootstrap (`deno run` of the npm
|
|
44
|
+
* specifier) is retired with the Deno consumer surface; the generator is
|
|
45
|
+
* invoked through plain Node tooling.
|
|
46
|
+
*/
|
|
47
|
+
function createInstallCommand(projectName = CREATE_PROJECT_PLACEHOLDER, options = {}) {
|
|
48
|
+
const tag = options.tag ?? "alpha";
|
|
49
|
+
return `npm create ${CREATE_NPM_CREATE_SCOPE}@${tag} ${projectName}`;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { CREATE_INSTALL_TAG, CREATE_NPM_CREATE_SCOPE, CREATE_PACKAGE_SPECIFIER, CREATE_PROJECT_PLACEHOLDER, createInstallCommand };
|