@vited/create 0.0.3 → 0.0.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ### Added
6
+
7
+ - Generate `docs/favicon.svg` for new projects without overwriting an existing favicon.
8
+
9
+ ## 0.0.4 - 2026-10-28
10
+
11
+ ### Fixed
12
+
13
+ - Upgrade existing React and React DOM dependencies to React 19 when initializing a Vited project.
14
+
3
15
  ## 0.0.3 - 2026-10-28
4
16
 
5
17
  ### Fixed
package/README.md CHANGED
@@ -33,8 +33,20 @@ pnpm dlx @vited/create my-docs \
33
33
  --no-install
34
34
  ```
35
35
 
36
- The generated project includes `vited.config.ts`, a `docs` directory, and
37
- `docs:dev` / `docs:build` scripts. `@vited/core` provides the HTML shell, so no
38
- `index.html` is added to the project. Existing package scripts and documentation
39
- files are preserved. An existing `vited.config.ts` is not overwritten.
36
+ The generated project includes `vited.config.ts`, a `docs` directory with a
37
+ default `favicon.svg`, and `docs:dev` / `docs:build` scripts. `@vited/core`
38
+ provides the HTML shell, so no `index.html` is added to the project. Existing
39
+ package scripts and documentation files are preserved. The generated
40
+ `.gitignore` ignores the default `docs_dist` build output. The starter
41
+ documentation is English in `docs/README.md` with a Chinese translation in
42
+ `docs/README.zh.md`. An existing `vited.config.ts` is not overwritten.
40
43
  If it already exists, `vited-new.config.ts` is created or overwritten for comparison.
44
+ When installing with pnpm, the required `@swc/core` and `esbuild` build scripts
45
+ are approved automatically to comply with pnpm's build-script policy.
46
+
47
+ When a GitHub repository is detected from the `origin` remote or the
48
+ `repository` field in `package.json`, create adds a GitHub Pages workflow and
49
+ sets the Vite and Vited base URLs to the repository path. The workflow deploys
50
+ the `docs_dist` build output. User and organization sites named
51
+ `<owner>.github.io` use the root URL. In the repository settings,
52
+ select **Settings → Pages → Source → GitHub Actions** to enable the workflow.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
+ type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
1
2
  export declare const THEMES: readonly ["@vited/theme-mantine"];
2
3
  export type Theme = (typeof THEMES)[number];
3
- export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun';
4
4
  export type ProjectMode = 'create' | 'init';
5
5
  export interface CreateOptions {
6
6
  directory: string;
@@ -15,4 +15,5 @@ export interface CreateResult {
15
15
  }
16
16
  export declare function resolvePackageManager(projectPath: string, environment?: NodeJS.ProcessEnv): Promise<PackageManager>;
17
17
  export declare function create({ directory, theme, packageManager, install }: CreateOptions): Promise<CreateResult>;
18
- export declare function installPackages(projectPath: string, packageManager: PackageManager): Promise<void>;
18
+ export declare function installPackages(projectPath: string, packageManager: PackageManager): Promise<void>;
19
+ export type { PackageManager };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { t as THEMES, n as create, r as installPackages, i as resolvePackageManager } from "./src-Ch1B-4Rg.mjs";
1
+ export { t as THEMES, n as create, r as installPackages, i as resolvePackageManager } from "./src-BAeU7i-K.mjs";
@@ -1,8 +1,164 @@
1
- import { spawn } from "node:child_process";
1
+ import { execFile, spawn } from "node:child_process";
2
2
  import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import process from "node:process";
5
+ import { URL } from "node:url";
6
+ import { promisify } from "node:util";
5
7
  import i18next from "i18next";
8
+ // src/github.ts
9
+ const execFileAsync = promisify(execFile);
10
+ async function getGitHubPagesSetup(projectPath, repository, packageManager) {
11
+ const githubRepository = await findGitHubRepository(projectPath, repository);
12
+ if (!githubRepository) return;
13
+ return {
14
+ base: getGitHubBaseURL(githubRepository),
15
+ workflow: makeGitHubPagesWorkflow(packageManager)
16
+ };
17
+ }
18
+ async function writeGitHubPagesWorkflow(projectPath, content) {
19
+ const workflowPath = path.join(projectPath, ".github", "workflows", "pages.yaml");
20
+ await mkdir(path.dirname(workflowPath), { recursive: true });
21
+ try {
22
+ await writeFile(workflowPath, content, { flag: "wx" });
23
+ } catch (error) {
24
+ if (!isNodeError$1(error, "EEXIST")) throw error;
25
+ }
26
+ }
27
+ async function findGitHubRepository(projectPath, repository) {
28
+ let originURL;
29
+ try {
30
+ originURL = (await execFileAsync("git", [
31
+ "remote",
32
+ "get-url",
33
+ "origin"
34
+ ], {
35
+ cwd: projectPath,
36
+ encoding: "utf8"
37
+ })).stdout.trim();
38
+ } catch (error) {
39
+ if (!isExpectedGitLookupFailure(error)) throw error;
40
+ }
41
+ return parseGitHubRepository(originURL) ?? parseGitHubRepository(getRepositoryURL(repository));
42
+ }
43
+ function isExpectedGitLookupFailure(error) {
44
+ if (isNodeError$1(error, "ENOENT")) return true;
45
+ if (!isRecord$1(error)) return false;
46
+ const code = error["code"];
47
+ return typeof code === "number" && [2, 128].includes(code);
48
+ }
49
+ function getRepositoryURL(repository) {
50
+ if (typeof repository === "string") return repository;
51
+ if (isRecord$1(repository) && typeof repository["url"] === "string") return repository["url"];
52
+ }
53
+ function parseGitHubRepository(repositoryURL) {
54
+ if (!repositoryURL) return;
55
+ const value = repositoryURL.trim().replace(/^git\+/, "");
56
+ const scpMatch = /^(?:[^@/]+@)?github\.com:([^/]+)\/([^/?#]+)$/i.exec(value);
57
+ const shorthandMatch = /^(?:github:)?([^/]+)\/([^/?#]+)$/i.exec(value);
58
+ const shorthand = scpMatch ?? shorthandMatch;
59
+ if (shorthand?.[1] && shorthand[2]) return makeGitHubRepository(shorthand[1], shorthand[2]);
60
+ let url;
61
+ try {
62
+ url = new URL(value);
63
+ } catch (error) {
64
+ if (error instanceof TypeError) return;
65
+ throw error;
66
+ }
67
+ if (url.hostname.toLowerCase() !== "github.com" || ![
68
+ "git:",
69
+ "http:",
70
+ "https:",
71
+ "ssh:"
72
+ ].includes(url.protocol)) return;
73
+ const pathSegments = url.pathname.split("/").filter(Boolean);
74
+ if (pathSegments.length !== 2) return;
75
+ const [owner, name] = pathSegments;
76
+ if (!owner || !name) return;
77
+ return makeGitHubRepository(owner, name);
78
+ }
79
+ function makeGitHubRepository(owner, name) {
80
+ return {
81
+ owner,
82
+ name: name.replace(/\.git$/i, "")
83
+ };
84
+ }
85
+ function getGitHubBaseURL(repository) {
86
+ return repository.name.toLowerCase() === `${repository.owner.toLowerCase()}.github.io` ? "/" : `/${repository.name}/`;
87
+ }
88
+ function makeGitHubPagesWorkflow(packageManager) {
89
+ const setupPackageManagerSteps = {
90
+ npm: [],
91
+ pnpm: [" - uses: pnpm/action-setup@v4"],
92
+ yarn: [" - run: corepack enable"],
93
+ bun: [" - uses: oven-sh/setup-bun@v2"]
94
+ }[packageManager];
95
+ const installSteps = {
96
+ npm: [" - run: npm install"],
97
+ pnpm: [" - run: pnpm approve-builds @swc/core esbuild", " - run: pnpm install"],
98
+ yarn: [" - run: yarn install"],
99
+ bun: [" - run: bun install"]
100
+ }[packageManager];
101
+ const buildCommand = {
102
+ npm: "npm run docs:build",
103
+ pnpm: "pnpm run docs:build",
104
+ yarn: "yarn docs:build",
105
+ bun: "bun run docs:build"
106
+ }[packageManager];
107
+ return [
108
+ "name: Deploy docs to GitHub Pages",
109
+ "",
110
+ "on:",
111
+ " push:",
112
+ " branches:",
113
+ " - main",
114
+ " - master",
115
+ " workflow_dispatch:",
116
+ "",
117
+ "permissions:",
118
+ " contents: read",
119
+ " pages: write",
120
+ "",
121
+ "concurrency:",
122
+ " group: github-pages",
123
+ " cancel-in-progress: false",
124
+ "",
125
+ "jobs:",
126
+ " build:",
127
+ " runs-on: ubuntu-latest",
128
+ " steps:",
129
+ " - uses: actions/checkout@v6",
130
+ " - uses: actions/setup-node@v6",
131
+ " with:",
132
+ " node-version: 22",
133
+ ...setupPackageManagerSteps,
134
+ " - uses: actions/configure-pages@v5",
135
+ ...installSteps,
136
+ ` - run: ${buildCommand}`,
137
+ " - uses: actions/upload-pages-artifact@v4",
138
+ " with:",
139
+ " path: ./docs_dist",
140
+ "",
141
+ " deploy:",
142
+ " environment:",
143
+ " name: github-pages",
144
+ " url: ${{ steps.deployment.outputs.page_url }}",
145
+ " runs-on: ubuntu-latest",
146
+ " needs: build",
147
+ " permissions:",
148
+ " pages: write",
149
+ " id-token: write",
150
+ " steps:",
151
+ " - id: deployment",
152
+ " uses: actions/deploy-pages@v4",
153
+ ""
154
+ ].join("\n");
155
+ }
156
+ function isNodeError$1(error, code) {
157
+ return error instanceof Error && "code" in error && error.code === code;
158
+ }
159
+ function isRecord$1(value) {
160
+ return typeof value === "object" && value === Object(value) && !Array.isArray(value);
161
+ }
6
162
  // src/i18n.ts
7
163
  const LANGUAGES = ["en", "zh"];
8
164
  const resources = {
@@ -32,7 +188,7 @@ const resources = {
32
188
  invalidPackageManagerType: "Invalid package.json: packageManager must be a string in {{path}}",
33
189
  unsupportedPackageManager: "Unsupported package manager in {{path}}: {{packageManager}}",
34
190
  multipleLockfiles: "Multiple package manager lockfiles found in {{path}}. Set packageManager in package.json.",
35
- installFailed: "{{packageManager}} install exited with code {{code}}",
191
+ commandFailed: "{{command}} exited with code {{code}}",
36
192
  projectNotDirectory: "Project path is not a directory: {{path}}",
37
193
  docsNotDirectory: "Cannot create documentation: {{path}} is not a directory.",
38
194
  invalidPackageJson: "Invalid package.json: expected a JSON object in {{path}}",
@@ -67,7 +223,7 @@ const resources = {
67
223
  invalidPackageManagerType: "package.json 配置无效:{{path}} 中的 packageManager 必须是字符串",
68
224
  unsupportedPackageManager: "{{path}} 中配置了不支持的包管理器:{{packageManager}}",
69
225
  multipleLockfiles: "{{path}} 中存在多个包管理器锁文件,请在 package.json 中设置 packageManager。",
70
- installFailed: "{{packageManager}} install 退出,代码为 {{code}}",
226
+ commandFailed: "{{command}} 退出,代码为 {{code}}",
71
227
  projectNotDirectory: "项目路径不是目录:{{path}}",
72
228
  docsNotDirectory: "无法创建文档:{{path}} 不是目录。",
73
229
  invalidPackageJson: "package.json 无效:{{path}} 应为 JSON 对象",
@@ -99,12 +255,12 @@ function t(key, options) {
99
255
  }
100
256
  // src/index.ts
101
257
  const THEMES = ["@vited/theme-mantine"];
258
+ const defaultReactVersion = "^19.3.1";
259
+ const reactPackages = ["react", "react-dom"];
102
260
  const vitedPackages = {
103
261
  "@vited/cli": "^0.1.0",
104
262
  "@vited/core": "^0.1.0",
105
- "@vited/theme-mantine": "^0.1.0",
106
- react: "^19.3.1",
107
- "react-dom": "^19.3.1",
263
+ "@vited/theme-mantine": "^0.2.0",
108
264
  vite: "^8.3.5"
109
265
  };
110
266
  const packageManagerLockfiles = {
@@ -152,12 +308,18 @@ async function create({ directory, theme, packageManager, install }) {
152
308
  const packageJsonPath = path.join(projectPath, "package.json");
153
309
  const packageJson = await readProjectPackageJson(packageJsonPath, projectPath);
154
310
  addVitedConfiguration(packageJson, projectPath, theme);
311
+ const githubPages = await getGitHubPagesSetup(projectPath, packageJson["repository"], packageManager);
312
+ const base = githubPages?.base;
155
313
  await mkdir(projectPath, { recursive: true });
314
+ await ensureGitignoreEntry(projectPath, "docs_dist");
156
315
  const docsPath = path.join(projectPath, "docs");
157
316
  await mkdir(docsPath, { recursive: true });
158
317
  await writeFile(packageJsonPath, `${JSON.stringify(packageJson, void 0, 2)}\n`);
159
- await writeFile(configPath, makeVitedConfig(packageJson, theme), { flag: overwriteConfig ? "w" : "wx" });
160
- await writeIfMissing(path.join(docsPath, "README.md"), makeReadme(packageJson));
318
+ await writeFile(configPath, makeVitedConfig(packageJson, theme, base), { flag: overwriteConfig ? "w" : "wx" });
319
+ await writeIfMissing(path.join(docsPath, "favicon.svg"), await readFile(new URL("../favicon.svg", import.meta.url), "utf8"));
320
+ await writeIfMissing(path.join(docsPath, "README.md"), makeReadme(packageJson, "en"));
321
+ await writeIfMissing(path.join(docsPath, "README.zh.md"), makeReadme(packageJson, "zh"));
322
+ if (githubPages) await writeGitHubPagesWorkflow(projectPath, githubPages.workflow);
161
323
  if (install) await installPackages(projectPath, packageManager);
162
324
  return {
163
325
  projectPath,
@@ -166,18 +328,28 @@ async function create({ directory, theme, packageManager, install }) {
166
328
  };
167
329
  }
168
330
  async function installPackages(projectPath, packageManager) {
331
+ if (packageManager === "pnpm") await runPackageCommand("pnpm", [
332
+ "approve-builds",
333
+ "@swc/core",
334
+ "esbuild"
335
+ ], projectPath);
336
+ await runPackageCommand(packageManager, ["install"], projectPath);
337
+ }
338
+ async function runPackageCommand(packageManager, args, projectPath) {
339
+ const command = [packageManager, ...args].join(" ");
340
+ const createCommandError = (code) => new Error(t("errors.commandFailed", {
341
+ command,
342
+ code: code === null ? "unknown" : code
343
+ }));
169
344
  await new Promise((resolve, reject) => {
170
- const child = spawn(packageManager, ["install"], {
345
+ const child = spawn(packageManager, args, {
171
346
  cwd: projectPath,
172
347
  stdio: "inherit"
173
348
  });
174
349
  child.once("error", reject);
175
350
  child.once("close", (code) => {
176
351
  if (code === 0) resolve();
177
- else reject(new Error(t("errors.installFailed", {
178
- packageManager,
179
- code: code === null ? "unknown" : code
180
- })));
352
+ else reject(createCommandError(code));
181
353
  });
182
354
  });
183
355
  }
@@ -244,6 +416,12 @@ function addVitedConfiguration(packageJson, projectPath, theme) {
244
416
  if (name === "@vited/theme-mantine" && theme !== name) continue;
245
417
  if (dependencies[name] === void 0 && devDependencies[name] === void 0) devDependencies[name] = version;
246
418
  }
419
+ const reactTarget = reactPackages.some((name) => dependencies[name] !== void 0) ? dependencies : devDependencies;
420
+ const reactOther = reactTarget === dependencies ? devDependencies : dependencies;
421
+ for (const name of reactPackages) {
422
+ reactTarget[name] = defaultReactVersion;
423
+ delete reactOther[name];
424
+ }
247
425
  packageJson["devDependencies"] = devDependencies;
248
426
  }
249
427
  function getRecord(value, name) {
@@ -278,12 +456,13 @@ async function fileExists(filePath) {
278
456
  function toPackageName(value) {
279
457
  return value.toLowerCase().replaceAll(/[^a-z0-9._-]+/g, "-").replaceAll(/^-+|-+$/g, "") || "vited-docs";
280
458
  }
281
- function makeVitedConfig(packageJson, theme) {
459
+ function makeVitedConfig(packageJson, theme, base) {
282
460
  const title = typeof packageJson["name"] === "string" && packageJson["name"].length > 0 ? packageJson["name"] : "Vited documentation";
283
461
  return [
284
462
  "import { defineConfig } from '@vited/core';",
285
463
  "",
286
464
  "export default defineConfig({",
465
+ ` base: ${JSON.stringify(base ?? "/")},`,
287
466
  " docs: {",
288
467
  ` title: ${JSON.stringify(title)},`,
289
468
  ` theme: ${JSON.stringify(theme)},`,
@@ -292,8 +471,8 @@ function makeVitedConfig(packageJson, theme) {
292
471
  ""
293
472
  ].join("\n");
294
473
  }
295
- function makeReadme(packageJson) {
296
- return `# ${typeof packageJson["name"] === "string" && packageJson["name"].length > 0 ? packageJson["name"] : "Vited documentation"}\n\n${t("template.docsWelcome")}\n`;
474
+ function makeReadme(packageJson, language) {
475
+ return `# ${typeof packageJson["name"] === "string" && packageJson["name"].length > 0 ? packageJson["name"] : "Vited documentation"}\n\n${t("template.docsWelcome", { lng: language })}\n`;
297
476
  }
298
477
  async function writeIfMissing(filePath, content) {
299
478
  try {
@@ -302,4 +481,20 @@ async function writeIfMissing(filePath, content) {
302
481
  if (!isNodeError(error, "EEXIST")) throw error;
303
482
  }
304
483
  }
484
+ async function ensureGitignoreEntry(projectPath, entry) {
485
+ const gitignorePath = path.join(projectPath, ".gitignore");
486
+ let contents;
487
+ try {
488
+ contents = await readFile(gitignorePath, "utf8");
489
+ } catch (error) {
490
+ if (!isNodeError(error, "ENOENT")) throw error;
491
+ contents = "";
492
+ }
493
+ if (contents.split(/\r?\n/).some((line) => {
494
+ return line.trim().replaceAll(/^\/+|\/+$/g, "") === entry;
495
+ })) return;
496
+ const lineEnding = contents.includes("\r\n") ? "\r\n" : "\n";
497
+ const separator = contents.length > 0 && !contents.endsWith("\n") ? lineEnding : "";
498
+ await writeFile(gitignorePath, `${contents}${separator}${entry}${lineEnding}`);
499
+ }
305
500
  export { LANGUAGES as a, t as c, resolvePackageManager as i, create as n, isLanguage as o, installPackages as r, setLanguage as s, THEMES as t };
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { a as LANGUAGES, c as t, i as resolvePackageManager, n as create, o as isLanguage, s as setLanguage, t as THEMES } from "./src-Ch1B-4Rg.mjs";
2
+ import { a as LANGUAGES, c as t, i as resolvePackageManager, n as create, o as isLanguage, s as setLanguage, t as THEMES } from "./src-BAeU7i-K.mjs";
3
3
  import process from "node:process";
4
4
  import console from "node:console";
5
5
  import { Command, Option } from "commander";
6
6
  import { cancel, confirm, intro, isCancel, outro, select, text } from "@clack/prompts";
7
7
  // package.json
8
- var version = "0.0.3";
8
+ var version = "0.0.4";
9
9
  // src/interactive.ts
10
10
  async function runInteractive() {
11
11
  if (!process.stdin.isTTY || !process.stdout.isTTY) throw new Error(t("interactive.terminalRequired"));
package/favicon.svg ADDED
@@ -0,0 +1,20 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128">
2
+ <defs>
3
+ <linearGradient id="bolt" x1="30" y1="14" x2="95" y2="107" gradientUnits="userSpaceOnUse">
4
+ <stop stop-color="#ffe76b" />
5
+ <stop offset=".38" stop-color="#ff9a43" />
6
+ <stop offset=".72" stop-color="#d94fe8" />
7
+ <stop offset="1" stop-color="#6657f5" />
8
+ </linearGradient>
9
+ <clipPath id="shape">
10
+ <path d="M75 8 29 62h27l-9 58 53-70H73L94 8H75Z" />
11
+ </clipPath>
12
+ </defs>
13
+ <path d="M75 8 29 62h27l-9 58 53-70H73L94 8H75Z" fill="url(#bolt)" />
14
+ <g clip-path="url(#shape)">
15
+ <path d="M22 18h61L56 62H22Z" fill="#fff1a1" opacity=".58" />
16
+ <path d="m56 62 17-14h28l-53 72 9-58Z" fill="#654ce1" opacity=".5" />
17
+ <path d="m73 8 21 0-21 42H55Z" fill="#fff" opacity=".18" />
18
+ <path d="m56 62 17-14-26 72 9-58Z" fill="#ff6b5b" opacity=".45" />
19
+ </g>
20
+ </svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vited/create",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Create and initialize Vited documentation projects",
5
5
  "keywords": [
6
6
  "cli",
@@ -27,6 +27,7 @@
27
27
  },
28
28
  "files": [
29
29
  "dist",
30
+ "favicon.svg",
30
31
  "CHANGELOG.md",
31
32
  "LICENSE",
32
33
  "README.md"
@@ -46,14 +47,13 @@
46
47
  "i18next": "^26.5.11"
47
48
  },
48
49
  "devDependencies": {
49
- "@guoyunhe/editorconfig": "^0.3.0",
50
50
  "@guoyunhe/oxfmt-config": "^1.1.0",
51
51
  "@tsconfig/node20": "^20.1.2",
52
52
  "@tsconfig/strictest": "^2.0.2",
53
53
  "@types/node": "^20.5.8",
54
54
  "@vited/cli": "^0.1.0",
55
55
  "@vited/core": "^0.1.0",
56
- "@vited/theme-mantine": "^0.1.0",
56
+ "@vited/theme-mantine": "^0.2.0",
57
57
  "husky": "^9.1.7",
58
58
  "lint-staged": "^17.6.0",
59
59
  "oxfmt": "^0.75.0",