@openelement/create 1.0.0-alpha.5 → 1.0.0-alpha.7
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 +2 -2
- package/package.json +1 -1
- package/src/cli.d.ts +1 -1
- package/src/cli.js +61 -67
- package/src/install-command.d.ts +13 -5
- package/src/install-command.js +39 -32
- package/src/template-builder.js +77 -192
- package/src/version.js +11 -6
package/README.md
CHANGED
|
@@ -21,13 +21,13 @@ deno task dev
|
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
The version `@alpha` resolves to is registered in
|
|
24
|
-
`the tracked release-state manifest` (currently `1.0.0-alpha.
|
|
24
|
+
`the tracked release-state manifest` (currently `1.0.0-alpha.5`, a new baseline —
|
|
25
25
|
not a 0.x upgrade, with no migration path from 0.x). Pin that exact version
|
|
26
26
|
when reproducibility matters (verify against the live registry with
|
|
27
27
|
`npm view @openelement/create dist-tags.alpha`):
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
|
-
deno run -A npm:@openelement/create@1.0.0-alpha.
|
|
30
|
+
deno run -A npm:@openelement/create@1.0.0-alpha.5 my-app
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
`--minimum-dependency-age 0` is needed because Deno's default
|
package/package.json
CHANGED
package/src/cli.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {}
|
package/src/cli.js
CHANGED
|
@@ -1,82 +1,76 @@
|
|
|
1
1
|
#!/usr/bin/env -S deno run --allow-read --allow-write
|
|
2
|
+
import { buildTemplates, resolveVersions, validateProjectName } from "./template-builder.js";
|
|
3
|
+
import { createInstallCommand } from "./install-command.js";
|
|
4
|
+
//#region src/cli.ts
|
|
2
5
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import { createInstallCommand } from './install-command.js';
|
|
6
|
+
* @openelement/create - Minimal project scaffold for openElement framework.
|
|
7
|
+
*
|
|
8
|
+
* The install command this CLI documents is built by ./install-command.ts
|
|
9
|
+
* (#1414): usage output, the guides and the homepage all render that one
|
|
10
|
+
* string, so the documented command cannot drift from the shipped flags.
|
|
11
|
+
*
|
|
12
|
+
* openElement Architecture: Keep It Simple, Stupid.
|
|
13
|
+
* One template, zero prompts, instant start.
|
|
14
|
+
*
|
|
15
|
+
* L9: every failure mode exits 1 with one actionable message — never a
|
|
16
|
+
* runtime stack trace.
|
|
17
|
+
*/
|
|
16
18
|
function errorMessage(error) {
|
|
17
|
-
|
|
19
|
+
return error instanceof Error ? error.message : String(error);
|
|
18
20
|
}
|
|
19
21
|
function fail(message) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
console.error(`error: ${message}`);
|
|
23
|
+
Deno.exit(1);
|
|
22
24
|
}
|
|
23
25
|
function joinPosix(...parts) {
|
|
24
|
-
|
|
26
|
+
return parts.join("/").replace(/\/{2,}/g, "/");
|
|
25
27
|
}
|
|
26
28
|
function dirnameOf(path) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return path.slice(0, idx);
|
|
29
|
+
const idx = path.replace(/\\+/g, "/").lastIndexOf("/");
|
|
30
|
+
if (idx <= 0) return ".";
|
|
31
|
+
return path.slice(0, idx);
|
|
31
32
|
}
|
|
32
33
|
async function main() {
|
|
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
|
-
} catch (error) {
|
|
70
|
-
const detail = error instanceof Deno.errors.PermissionDenied ? `Permission denied. Check write permissions for ${targetDir}.` : errorMessage(error);
|
|
71
|
-
throw new Error(`Failed to write project files in "${name}": ${detail} ` + 'Remove the partially created directory before retrying.');
|
|
72
|
-
}
|
|
73
|
-
console.info(`\nopenElement project created at ./${relativeTarget}/`);
|
|
74
|
-
console.info(`\n cd ${relativeTarget}`);
|
|
75
|
-
console.info(' deno task dev');
|
|
76
|
-
console.info(' See README.md for all tasks (check/build/start/preview)');
|
|
34
|
+
const name = Deno.args[0];
|
|
35
|
+
if (!name || name === "--help" || name === "-h") {
|
|
36
|
+
console.log(`Usage (Alpha): ${createInstallCommand()}`);
|
|
37
|
+
console.log("(a versionless install resolves the stable 0.43 line)");
|
|
38
|
+
Deno.exit(name ? 0 : 1);
|
|
39
|
+
}
|
|
40
|
+
const invalid = validateProjectName(name);
|
|
41
|
+
if (invalid) fail(`Invalid project name "${name}". ${invalid}`);
|
|
42
|
+
const targetDir = `${Deno.cwd().replace(/\/+$/, "")}/${name}`;
|
|
43
|
+
const relativeTarget = name;
|
|
44
|
+
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}`);
|
|
45
|
+
try {
|
|
46
|
+
await Deno.stat(targetDir);
|
|
47
|
+
fail(`Directory "${name}" already exists. Choose a different name or remove the existing directory.`);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (!(error instanceof Deno.errors.NotFound)) throw new Error(`Could not inspect target directory "${name}": ${errorMessage(error)}`);
|
|
50
|
+
}
|
|
51
|
+
const v = resolveVersions();
|
|
52
|
+
try {
|
|
53
|
+
await Deno.mkdir(targetDir, { recursive: true });
|
|
54
|
+
const TPL = await buildTemplates(v, name);
|
|
55
|
+
for (const [path, content] of Object.entries(TPL)) {
|
|
56
|
+
const fullPath = joinPosix(targetDir, path);
|
|
57
|
+
await Deno.mkdir(dirnameOf(fullPath), { recursive: true });
|
|
58
|
+
await Deno.writeTextFile(fullPath, content);
|
|
59
|
+
console.info(` created ${path}`);
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const detail = error instanceof Deno.errors.PermissionDenied ? `Permission denied. Check write permissions for ${targetDir}.` : errorMessage(error);
|
|
63
|
+
throw new Error(`Failed to write project files in "${name}": ${detail} Remove the partially created directory before retrying.`);
|
|
64
|
+
}
|
|
65
|
+
console.info(`\nopenElement project created at ./${relativeTarget}/`);
|
|
66
|
+
console.info(`\n cd ${relativeTarget}`);
|
|
67
|
+
console.info(" deno task dev");
|
|
68
|
+
console.info(" See README.md for all tasks (check/build/start/preview)");
|
|
77
69
|
}
|
|
78
70
|
try {
|
|
79
|
-
|
|
71
|
+
await main();
|
|
80
72
|
} catch (error) {
|
|
81
|
-
|
|
73
|
+
fail(errorMessage(error));
|
|
82
74
|
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export {};
|
package/src/install-command.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/install-command.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* The canonical install command — the ONE source every documented copy of it
|
|
3
4
|
* derives from (#1414 item 5).
|
|
@@ -11,8 +12,11 @@
|
|
|
11
12
|
*
|
|
12
13
|
* This module is deliberately side-effect free (no top-level CLI execution, no
|
|
13
14
|
* Deno APIs): it is imported by the site build as well as by the CLI itself.
|
|
14
|
-
*/
|
|
15
|
-
/** The
|
|
15
|
+
*/
|
|
16
|
+
/** The npm specifier the generator is published under. */
|
|
17
|
+
export declare const CREATE_PACKAGE_SPECIFIER = "npm:@openelement/create";
|
|
18
|
+
/** The dist-tag the documented install resolves; the exact version is registry truth. */
|
|
19
|
+
export declare const CREATE_INSTALL_TAG = "alpha";
|
|
16
20
|
/**
|
|
17
21
|
* Deno permissions the bootstrap needs. Owner ruling 2026-09-21: the
|
|
18
22
|
* documented command uses bare `-A` — the consumer scaffolds their own
|
|
@@ -20,14 +24,18 @@
|
|
|
20
24
|
* narrowed the `check-no-allow-all` tripwire to an exact-line exemption for
|
|
21
25
|
* this command). `--minimum-dependency-age 0` is a functional footnote kept
|
|
22
26
|
* in prose where needed, not part of the documented shape.
|
|
23
|
-
*/
|
|
24
|
-
|
|
27
|
+
*/
|
|
28
|
+
export declare const CREATE_INSTALL_PERMISSIONS: readonly string[];
|
|
29
|
+
/** Placeholder the usage text and the docs use in place of a project name. */
|
|
30
|
+
export declare const CREATE_PROJECT_PLACEHOLDER = "<project-name>";
|
|
25
31
|
/**
|
|
26
32
|
* Build the canonical install command for `projectName`.
|
|
27
33
|
*
|
|
28
34
|
* `projectName` defaults to the placeholder so callers that document the
|
|
29
35
|
* command shape (usage output) and callers that show a concrete example share
|
|
30
36
|
* one builder and therefore one flag list.
|
|
31
|
-
*/
|
|
37
|
+
*/
|
|
38
|
+
export declare function createInstallCommand(projectName?: string, options?: {
|
|
32
39
|
tag?: string;
|
|
33
40
|
}): string;
|
|
41
|
+
//#endregion
|
package/src/install-command.js
CHANGED
|
@@ -1,36 +1,43 @@
|
|
|
1
|
+
//#region src/install-command.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/** The
|
|
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, no
|
|
14
|
+
* Deno APIs): 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 = "npm:@openelement/create";
|
|
18
|
+
/** The dist-tag the documented install resolves; the exact version is registry truth. */
|
|
19
|
+
const CREATE_INSTALL_TAG = "alpha";
|
|
16
20
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
* Deno permissions the bootstrap needs. Owner ruling 2026-09-21: the
|
|
22
|
+
* documented command uses bare `-A` — the consumer scaffolds their own
|
|
23
|
+
* project, and the scoped-permission form reads as noise (the same ruling
|
|
24
|
+
* narrowed the `check-no-allow-all` tripwire to an exact-line exemption for
|
|
25
|
+
* this command). `--minimum-dependency-age 0` is a functional footnote kept
|
|
26
|
+
* in prose where needed, not part of the documented shape.
|
|
27
|
+
*/
|
|
28
|
+
const CREATE_INSTALL_PERMISSIONS = [String.fromCharCode(45, 65)];
|
|
29
|
+
/** Placeholder the usage text and the docs use in place of a project name. */
|
|
30
|
+
const CREATE_PROJECT_PLACEHOLDER = "<project-name>";
|
|
27
31
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
* Build the canonical install command for `projectName`.
|
|
33
|
+
*
|
|
34
|
+
* `projectName` defaults to the placeholder so callers that document the
|
|
35
|
+
* command shape (usage output) and callers that show a concrete example share
|
|
36
|
+
* one builder and therefore one flag list.
|
|
37
|
+
*/
|
|
38
|
+
function createInstallCommand(projectName = CREATE_PROJECT_PLACEHOLDER, options = {}) {
|
|
39
|
+
const tag = options.tag ?? "alpha";
|
|
40
|
+
return `deno run ${CREATE_INSTALL_PERMISSIONS.join(" ")} ${CREATE_PACKAGE_SPECIFIER}@${tag} ${projectName}`;
|
|
36
41
|
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { CREATE_INSTALL_PERMISSIONS, CREATE_INSTALL_TAG, CREATE_PACKAGE_SPECIFIER, CREATE_PROJECT_PLACEHOLDER, createInstallCommand };
|
package/src/template-builder.js
CHANGED
|
@@ -1,204 +1,89 @@
|
|
|
1
|
-
import { CREATE_VERSION, VITE_STARTER_PIN } from
|
|
2
|
-
|
|
3
|
-
// directory must stay a legal package name so `npm init`-style flows and
|
|
4
|
-
// registry publication are never blocked by the scaffold itself (L11).
|
|
1
|
+
import { CREATE_VERSION, VITE_STARTER_PIN } from "./version.js";
|
|
2
|
+
//#region src/template-builder.ts
|
|
5
3
|
const MAX_PROJECT_NAME_LENGTH = 214;
|
|
6
4
|
const PROJECT_NAME_PATTERN = /^[a-z0-9][a-z0-9._-]*$/;
|
|
7
5
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (name !== name.toLowerCase()) {
|
|
20
|
-
return 'Project name must be lowercase (npm package names cannot contain uppercase letters).';
|
|
21
|
-
}
|
|
22
|
-
if (!PROJECT_NAME_PATTERN.test(name)) {
|
|
23
|
-
return 'Project name must start with a lowercase letter or number and may only contain ' + 'lowercase letters, numbers, dots, underscores, and hyphens.';
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
6
|
+
* L11: validate the scaffold target name before any filesystem work. Returns
|
|
7
|
+
* an actionable message when the name is unsafe, `null` when it is a legal
|
|
8
|
+
* npm-style package name that cannot escape the current directory.
|
|
9
|
+
*/
|
|
10
|
+
function validateProjectName(name) {
|
|
11
|
+
if (name.length === 0) return "Project name must not be empty.";
|
|
12
|
+
if (name.length > MAX_PROJECT_NAME_LENGTH) return `Project name must be at most ${MAX_PROJECT_NAME_LENGTH} characters (npm package-name limit).`;
|
|
13
|
+
if (name.includes("..")) return "Project name must not contain \"..\" (path traversal is not allowed).";
|
|
14
|
+
if (name !== name.toLowerCase()) return "Project name must be lowercase (npm package names cannot contain uppercase letters).";
|
|
15
|
+
if (!PROJECT_NAME_PATTERN.test(name)) return "Project name must start with a lowercase letter or number and may only contain lowercase letters, numbers, dots, underscores, and hyphens.";
|
|
16
|
+
return null;
|
|
26
17
|
}
|
|
27
18
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
* The published starter relies on the support-package same-version release
|
|
20
|
+
* invariant. Package-graph and release-prepare gates verify that invariant;
|
|
21
|
+
* Create deliberately has no runtime registry fallback or mixed-version mode.
|
|
22
|
+
* Caller-supplied versions are validated by `buildTemplates` below.
|
|
23
|
+
*/
|
|
24
|
+
function resolveVersions() {
|
|
25
|
+
return {
|
|
26
|
+
router: CREATE_VERSION,
|
|
27
|
+
element: CREATE_VERSION
|
|
28
|
+
};
|
|
37
29
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (observed.length !== 1) {
|
|
43
|
-
throw new Error(`Create requires the support-package same-version release invariant; observed ${observed.join(', ')}`);
|
|
44
|
-
}
|
|
45
|
-
return versions;
|
|
30
|
+
function assertUnifiedProductVersions(versions) {
|
|
31
|
+
const observed = [...new Set(Object.values(versions))];
|
|
32
|
+
if (observed.length !== 1) throw new Error(`Create requires the support-package same-version release invariant; observed ${observed.join(", ")}`);
|
|
33
|
+
return versions;
|
|
46
34
|
}
|
|
47
|
-
// [sourceTemplate, targetRelativePath] pairs. The starter manifest is stored
|
|
48
|
-
// as deno.json.tmpl so deno does not treat the templates/ directory as a
|
|
49
|
-
// nested workspace config; it is renamed to deno.json when written.
|
|
50
35
|
const TEMPLATE_FILES = [
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
[
|
|
78
|
-
'vite.config.ts.tmpl',
|
|
79
|
-
'vite.config.ts'
|
|
80
|
-
],
|
|
81
|
-
// #1411: framework options live in openelement.config.ts; the starter ships
|
|
82
|
-
// it near-empty, so every option comes from a file convention until the user
|
|
83
|
-
// overrides one.
|
|
84
|
-
[
|
|
85
|
-
'openelement.config.ts.tmpl',
|
|
86
|
-
'openelement.config.ts'
|
|
87
|
-
],
|
|
88
|
-
[
|
|
89
|
-
'app/styles/tokens.css',
|
|
90
|
-
'app/styles/tokens.css'
|
|
91
|
-
],
|
|
92
|
-
// alpha.4: the structural document-head convention. The config file carries
|
|
93
|
-
// the structured `head` channel (title/description/favicon/scripts); this
|
|
94
|
-
// module carries what a URL list cannot express (meta tags, preloads).
|
|
95
|
-
[
|
|
96
|
-
'app/head.tsx.tmpl',
|
|
97
|
-
'app/head.tsx'
|
|
98
|
-
],
|
|
99
|
-
[
|
|
100
|
-
'app/islands/app-shell.tsx.tmpl',
|
|
101
|
-
'app/islands/app-shell.tsx'
|
|
102
|
-
],
|
|
103
|
-
[
|
|
104
|
-
'app/components/page-styles.ts.tmpl',
|
|
105
|
-
'app/components/page-styles.ts'
|
|
106
|
-
],
|
|
107
|
-
[
|
|
108
|
-
'app/components/page-home.tsx.tmpl',
|
|
109
|
-
'app/components/page-home.tsx'
|
|
110
|
-
],
|
|
111
|
-
[
|
|
112
|
-
'app/components/page-freshness.tsx.tmpl',
|
|
113
|
-
'app/components/page-freshness.tsx'
|
|
114
|
-
],
|
|
115
|
-
[
|
|
116
|
-
'app/components/page-404.tsx.tmpl',
|
|
117
|
-
'app/components/page-404.tsx'
|
|
118
|
-
],
|
|
119
|
-
[
|
|
120
|
-
'app/components/page-contact.tsx.tmpl',
|
|
121
|
-
'app/components/page-contact.tsx'
|
|
122
|
-
],
|
|
123
|
-
[
|
|
124
|
-
'app/components/page-blog-index.tsx.tmpl',
|
|
125
|
-
'app/components/page-blog-index.tsx'
|
|
126
|
-
],
|
|
127
|
-
[
|
|
128
|
-
'app/components/page-blog-welcome.tsx.tmpl',
|
|
129
|
-
'app/components/page-blog-welcome.tsx'
|
|
130
|
-
],
|
|
131
|
-
[
|
|
132
|
-
'app/routes/404.tsx.tmpl',
|
|
133
|
-
'app/routes/404.tsx'
|
|
134
|
-
],
|
|
135
|
-
[
|
|
136
|
-
'app/routes/index.tsx.tmpl',
|
|
137
|
-
'app/routes/index.tsx'
|
|
138
|
-
],
|
|
139
|
-
[
|
|
140
|
-
'app/routes/freshness.tsx.tmpl',
|
|
141
|
-
'app/routes/freshness.tsx'
|
|
142
|
-
],
|
|
143
|
-
[
|
|
144
|
-
'app/routes/contact.tsx.tmpl',
|
|
145
|
-
'app/routes/contact.tsx'
|
|
146
|
-
],
|
|
147
|
-
[
|
|
148
|
-
'app/routes/blog/index.tsx.tmpl',
|
|
149
|
-
'app/routes/blog/index.tsx'
|
|
150
|
-
],
|
|
151
|
-
[
|
|
152
|
-
'app/routes/blog/welcome.tsx.tmpl',
|
|
153
|
-
'app/routes/blog/welcome.tsx'
|
|
154
|
-
],
|
|
155
|
-
[
|
|
156
|
-
'app/routes/api/health.ts.tmpl',
|
|
157
|
-
'app/routes/api/health.ts'
|
|
158
|
-
],
|
|
159
|
-
[
|
|
160
|
-
'app/islands/my-counter.tsx.tmpl',
|
|
161
|
-
'app/islands/my-counter.tsx'
|
|
162
|
-
],
|
|
163
|
-
[
|
|
164
|
-
'app/islands/only-ticker.tsx.tmpl',
|
|
165
|
-
'app/islands/only-ticker.tsx'
|
|
166
|
-
]
|
|
36
|
+
["gitignore.tmpl", ".gitignore"],
|
|
37
|
+
["README.tmpl", "README.md"],
|
|
38
|
+
["public/openelement-mark.svg", "public/openelement-mark.svg"],
|
|
39
|
+
["deno.json.tmpl", "deno.json"],
|
|
40
|
+
["package.json.tmpl", "package.json"],
|
|
41
|
+
["vite.config.ts.tmpl", "vite.config.ts"],
|
|
42
|
+
["openelement.config.ts.tmpl", "openelement.config.ts"],
|
|
43
|
+
["app/styles/tokens.css", "app/styles/tokens.css"],
|
|
44
|
+
["app/head.tsx.tmpl", "app/head.tsx"],
|
|
45
|
+
["app/islands/app-shell.tsx.tmpl", "app/islands/app-shell.tsx"],
|
|
46
|
+
["app/components/page-styles.ts.tmpl", "app/components/page-styles.ts"],
|
|
47
|
+
["app/components/page-home.tsx.tmpl", "app/components/page-home.tsx"],
|
|
48
|
+
["app/components/page-freshness.tsx.tmpl", "app/components/page-freshness.tsx"],
|
|
49
|
+
["app/components/page-404.tsx.tmpl", "app/components/page-404.tsx"],
|
|
50
|
+
["app/components/page-contact.tsx.tmpl", "app/components/page-contact.tsx"],
|
|
51
|
+
["app/components/page-blog-index.tsx.tmpl", "app/components/page-blog-index.tsx"],
|
|
52
|
+
["app/components/page-blog-welcome.tsx.tmpl", "app/components/page-blog-welcome.tsx"],
|
|
53
|
+
["app/routes/404.tsx.tmpl", "app/routes/404.tsx"],
|
|
54
|
+
["app/routes/index.tsx.tmpl", "app/routes/index.tsx"],
|
|
55
|
+
["app/routes/freshness.tsx.tmpl", "app/routes/freshness.tsx"],
|
|
56
|
+
["app/routes/contact.tsx.tmpl", "app/routes/contact.tsx"],
|
|
57
|
+
["app/routes/blog/index.tsx.tmpl", "app/routes/blog/index.tsx"],
|
|
58
|
+
["app/routes/blog/welcome.tsx.tmpl", "app/routes/blog/welcome.tsx"],
|
|
59
|
+
["app/routes/api/health.ts.tmpl", "app/routes/api/health.ts"],
|
|
60
|
+
["app/islands/my-counter.tsx.tmpl", "app/islands/my-counter.tsx"],
|
|
61
|
+
["app/islands/only-ticker.tsx.tmpl", "app/islands/only-ticker.tsx"]
|
|
167
62
|
];
|
|
168
63
|
function versionTokens(v) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
64
|
+
return {
|
|
65
|
+
["${v.router}"]: v.router,
|
|
66
|
+
["${v.element}"]: v.element
|
|
67
|
+
};
|
|
173
68
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
throw new Error(`Unresolved scaffold token in starter template: ${source}`);
|
|
193
|
-
}
|
|
194
|
-
return [
|
|
195
|
-
target,
|
|
196
|
-
content
|
|
197
|
-
];
|
|
198
|
-
}));
|
|
199
|
-
// Code-unit comparison (not localeCompare): deterministic across host
|
|
200
|
-
// locales and matches the test's toSorted() expectation, including
|
|
201
|
-
// uppercase targets like README.md.
|
|
202
|
-
entries.sort(([a], [b])=>a < b ? -1 : a > b ? 1 : 0);
|
|
203
|
-
return Object.fromEntries(entries);
|
|
69
|
+
async function buildTemplates(v, projectName) {
|
|
70
|
+
assertUnifiedProductVersions(v);
|
|
71
|
+
const invalid = validateProjectName(projectName);
|
|
72
|
+
if (invalid) throw new Error(`Invalid project name "${projectName}". ${invalid}`);
|
|
73
|
+
const templatesBase = new URL("../templates/", import.meta.url);
|
|
74
|
+
const tokens = {
|
|
75
|
+
...versionTokens(v),
|
|
76
|
+
["${v.vite}"]: VITE_STARTER_PIN,
|
|
77
|
+
["${name}"]: projectName
|
|
78
|
+
};
|
|
79
|
+
const entries = await Promise.all(TEMPLATE_FILES.map(async ([source, target]) => {
|
|
80
|
+
let content = await Deno.readTextFile(new URL(source, templatesBase));
|
|
81
|
+
for (const [token, value] of Object.entries(tokens)) if (content.includes(token)) content = content.split(token).join(value);
|
|
82
|
+
if (content.includes("${v.") || content.includes("${name}")) throw new Error(`Unresolved scaffold token in starter template: ${source}`);
|
|
83
|
+
return [target, content];
|
|
84
|
+
}));
|
|
85
|
+
entries.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
86
|
+
return Object.fromEntries(entries);
|
|
204
87
|
}
|
|
88
|
+
//#endregion
|
|
89
|
+
export { assertUnifiedProductVersions, buildTemplates, resolveVersions, validateProjectName };
|
package/src/version.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/version.ts
|
|
2
|
+
/** The published CLI version, embedded so packed npm installs are self-contained. */
|
|
3
|
+
const CREATE_VERSION = "1.0.0-alpha.7";
|
|
2
4
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
* The Vite dev release stamped into the generated starter's import map and
|
|
6
|
+
* dev task. Embedded for the same reason as CREATE_VERSION (packed npm
|
|
7
|
+
* installs are self-contained); the repository's Vite-pin check anchors this
|
|
8
|
+
* copy to the canonical dev pin.
|
|
9
|
+
*/
|
|
10
|
+
const VITE_STARTER_PIN = "8.0.16";
|
|
11
|
+
//#endregion
|
|
12
|
+
export { CREATE_VERSION, VITE_STARTER_PIN };
|