@vited/create 0.0.4 → 0.0.6

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,11 @@
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
+
3
9
  ## 0.0.4 - 2026-10-28
4
10
 
5
11
  ### Fixed
package/README.md CHANGED
@@ -33,10 +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.
41
44
  When installing with pnpm, the required `@swc/core` and `esbuild` build scripts
42
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-BWiFwqr3.mjs";
1
+ export { t as THEMES, n as create, r as installPackages, i as resolvePackageManager } from "./src-KPLQg03-.mjs";
@@ -1,8 +1,204 @@
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";
7
+ import { stringify } from "yaml";
5
8
  import i18next from "i18next";
9
+ // src/github.ts
10
+ const defaultPnpmVersion = 12;
11
+ const execFileAsync = promisify(execFile);
12
+ async function getGitHubPagesSetup(projectPath, packageJson, packageManager) {
13
+ const githubRepository = await findGitHubRepository(projectPath, getRepositoryURL(packageJson));
14
+ if (!githubRepository) return;
15
+ return {
16
+ base: getGitHubBaseURL(githubRepository),
17
+ workflow: makeGitHubPagesWorkflow(packageManager, getPnpmVersion(packageJson))
18
+ };
19
+ }
20
+ async function writeGitHubPagesWorkflow(projectPath, content) {
21
+ const workflowPath = path.join(projectPath, ".github", "workflows", "pages.yaml");
22
+ await mkdir(path.dirname(workflowPath), { recursive: true });
23
+ try {
24
+ await writeFile(workflowPath, content, { flag: "wx" });
25
+ } catch (error) {
26
+ if (!isNodeError$1(error, "EEXIST")) throw error;
27
+ }
28
+ }
29
+ async function findGitHubRepository(projectPath, repositoryURL) {
30
+ let originURL;
31
+ try {
32
+ originURL = (await execFileAsync("git", [
33
+ "remote",
34
+ "get-url",
35
+ "origin"
36
+ ], {
37
+ cwd: projectPath,
38
+ encoding: "utf8"
39
+ })).stdout.trim();
40
+ } catch (error) {
41
+ if (!isExpectedGitLookupFailure(error)) throw error;
42
+ }
43
+ return parseGitHubRepository(originURL) ?? parseGitHubRepository(repositoryURL);
44
+ }
45
+ function isExpectedGitLookupFailure(error) {
46
+ if (isNodeError$1(error, "ENOENT")) return true;
47
+ if (!isRecord$1(error)) return false;
48
+ const code = error["code"];
49
+ return typeof code === "number" && [2, 128].includes(code);
50
+ }
51
+ function getRepositoryURL(packageJson) {
52
+ if (!isRecord$1(packageJson)) return;
53
+ return getURLValue(packageJson["repository"]);
54
+ }
55
+ function getURLValue(repository) {
56
+ if (typeof repository === "string") return repository;
57
+ if (isRecord$1(repository) && typeof repository["url"] === "string") return repository["url"];
58
+ }
59
+ function parseGitHubRepository(repositoryURL) {
60
+ if (!repositoryURL) return;
61
+ const value = repositoryURL.trim().replace(/^git\+/, "");
62
+ const scpMatch = /^(?:[^@/]+@)?github\.com:([^/]+)\/([^/?#]+)$/i.exec(value);
63
+ const shorthandMatch = /^(?:github:)?([^/]+)\/([^/?#]+)$/i.exec(value);
64
+ const shorthand = scpMatch ?? shorthandMatch;
65
+ if (shorthand?.[1] && shorthand[2]) return makeGitHubRepository(shorthand[1], shorthand[2]);
66
+ let url;
67
+ try {
68
+ url = new URL(value);
69
+ } catch (error) {
70
+ if (error instanceof TypeError) return;
71
+ throw error;
72
+ }
73
+ if (url.hostname.toLowerCase() !== "github.com" || ![
74
+ "git:",
75
+ "http:",
76
+ "https:",
77
+ "ssh:"
78
+ ].includes(url.protocol)) return;
79
+ const pathSegments = url.pathname.split("/").filter(Boolean);
80
+ if (pathSegments.length !== 2) return;
81
+ const [owner, name] = pathSegments;
82
+ if (!owner || !name) return;
83
+ return makeGitHubRepository(owner, name);
84
+ }
85
+ function makeGitHubRepository(owner, name) {
86
+ return {
87
+ owner,
88
+ name: name.replace(/\.git$/i, "")
89
+ };
90
+ }
91
+ function getGitHubBaseURL(repository) {
92
+ return repository.name.toLowerCase() === `${repository.owner.toLowerCase()}.github.io` ? "/" : `/${repository.name}/`;
93
+ }
94
+ function getPnpmVersion(packageJson) {
95
+ if (!isRecord$1(packageJson)) return defaultPnpmVersion;
96
+ const packageManager = packageJson["packageManager"];
97
+ if (typeof packageManager === "string" && /^pnpm[@/]/.test(packageManager)) {
98
+ const version = parseVersion(packageManager);
99
+ if (version) return version;
100
+ }
101
+ const devEngines = packageJson["devEngines"];
102
+ if (isRecord$1(devEngines)) {
103
+ const devEngine = devEngines["packageManager"];
104
+ if (isRecord$1(devEngine) && devEngine["name"] === "pnpm") {
105
+ const version = parseVersion(devEngine["version"]);
106
+ if (version) return version;
107
+ }
108
+ }
109
+ const engines = packageJson["engines"];
110
+ if (isRecord$1(engines)) {
111
+ const version = parseVersion(engines["pnpm"]);
112
+ if (version) return version;
113
+ }
114
+ return defaultPnpmVersion;
115
+ }
116
+ function parseVersion(value) {
117
+ if (typeof value !== "string") return;
118
+ return /\d+(?:\.\d+){0,2}/.exec(value)?.[0];
119
+ }
120
+ function makeGitHubPagesWorkflow(packageManager, pnpmVersion) {
121
+ const setupPackageManagerStepsByPackageManager = {
122
+ npm: [],
123
+ pnpm: [{
124
+ uses: "pnpm/action-setup@v4",
125
+ with: { version: pnpmVersion }
126
+ }],
127
+ yarn: [{ run: "corepack enable" }],
128
+ bun: [{ uses: "oven-sh/setup-bun@v2" }]
129
+ };
130
+ const installStepsByPackageManager = {
131
+ npm: [{ run: "npm install" }],
132
+ pnpm: [{ run: "pnpm approve-builds @swc/core esbuild" }, { run: "pnpm install" }],
133
+ yarn: [{ run: "yarn install" }],
134
+ bun: [{ run: "bun install" }]
135
+ };
136
+ const setupPackageManagerSteps = setupPackageManagerStepsByPackageManager[packageManager];
137
+ const installSteps = installStepsByPackageManager[packageManager];
138
+ const buildCommand = {
139
+ npm: "npm run docs:build",
140
+ pnpm: "pnpm run docs:build",
141
+ yarn: "yarn docs:build",
142
+ bun: "bun run docs:build"
143
+ }[packageManager];
144
+ return stringify({
145
+ name: "Pages",
146
+ on: {
147
+ push: { branches: ["main", "master"] },
148
+ workflow_dispatch: {}
149
+ },
150
+ permissions: {
151
+ contents: "read",
152
+ pages: "write"
153
+ },
154
+ concurrency: {
155
+ group: "github-pages",
156
+ "cancel-in-progress": false
157
+ },
158
+ jobs: {
159
+ build: {
160
+ "runs-on": "ubuntu-latest",
161
+ steps: [
162
+ { uses: "actions/checkout@v6" },
163
+ {
164
+ uses: "actions/setup-node@v6",
165
+ with: { "node-version": 22 }
166
+ },
167
+ ...setupPackageManagerSteps,
168
+ { uses: "actions/configure-pages@v5" },
169
+ ...installSteps,
170
+ { run: buildCommand },
171
+ {
172
+ uses: "actions/upload-pages-artifact@v4",
173
+ with: { path: "./docs_dist" }
174
+ }
175
+ ]
176
+ },
177
+ deploy: {
178
+ environment: {
179
+ name: "github-pages",
180
+ url: "${{ steps.deployment.outputs.page_url }}"
181
+ },
182
+ "runs-on": "ubuntu-latest",
183
+ needs: "build",
184
+ permissions: {
185
+ pages: "write",
186
+ "id-token": "write"
187
+ },
188
+ steps: [{
189
+ id: "deployment",
190
+ uses: "actions/deploy-pages@v4"
191
+ }]
192
+ }
193
+ }
194
+ });
195
+ }
196
+ function isNodeError$1(error, code) {
197
+ return error instanceof Error && "code" in error && error.code === code;
198
+ }
199
+ function isRecord$1(value) {
200
+ return typeof value === "object" && value === Object(value) && !Array.isArray(value);
201
+ }
6
202
  // src/i18n.ts
7
203
  const LANGUAGES = ["en", "zh"];
8
204
  const resources = {
@@ -152,12 +348,18 @@ async function create({ directory, theme, packageManager, install }) {
152
348
  const packageJsonPath = path.join(projectPath, "package.json");
153
349
  const packageJson = await readProjectPackageJson(packageJsonPath, projectPath);
154
350
  addVitedConfiguration(packageJson, projectPath, theme);
351
+ const githubPages = await getGitHubPagesSetup(projectPath, packageJson, packageManager);
352
+ const base = githubPages?.base;
155
353
  await mkdir(projectPath, { recursive: true });
354
+ await ensureGitignoreEntry(projectPath, "docs_dist");
156
355
  const docsPath = path.join(projectPath, "docs");
157
356
  await mkdir(docsPath, { recursive: true });
158
357
  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));
358
+ await writeFile(configPath, makeVitedConfig(packageJson, theme, base), { flag: overwriteConfig ? "w" : "wx" });
359
+ await writeIfMissing(path.join(docsPath, "favicon.svg"), await readFile(new URL("../favicon.svg", import.meta.url), "utf8"));
360
+ await writeIfMissing(path.join(docsPath, "README.md"), makeReadme(packageJson, "en"));
361
+ await writeIfMissing(path.join(docsPath, "README.zh.md"), makeReadme(packageJson, "zh"));
362
+ if (githubPages) await writeGitHubPagesWorkflow(projectPath, githubPages.workflow);
161
363
  if (install) await installPackages(projectPath, packageManager);
162
364
  return {
163
365
  projectPath,
@@ -294,12 +496,13 @@ async function fileExists(filePath) {
294
496
  function toPackageName(value) {
295
497
  return value.toLowerCase().replaceAll(/[^a-z0-9._-]+/g, "-").replaceAll(/^-+|-+$/g, "") || "vited-docs";
296
498
  }
297
- function makeVitedConfig(packageJson, theme) {
499
+ function makeVitedConfig(packageJson, theme, base) {
298
500
  const title = typeof packageJson["name"] === "string" && packageJson["name"].length > 0 ? packageJson["name"] : "Vited documentation";
299
501
  return [
300
502
  "import { defineConfig } from '@vited/core';",
301
503
  "",
302
504
  "export default defineConfig({",
505
+ ` base: ${JSON.stringify(base ?? "/")},`,
303
506
  " docs: {",
304
507
  ` title: ${JSON.stringify(title)},`,
305
508
  ` theme: ${JSON.stringify(theme)},`,
@@ -308,8 +511,8 @@ function makeVitedConfig(packageJson, theme) {
308
511
  ""
309
512
  ].join("\n");
310
513
  }
311
- function makeReadme(packageJson) {
312
- return `# ${typeof packageJson["name"] === "string" && packageJson["name"].length > 0 ? packageJson["name"] : "Vited documentation"}\n\n${t("template.docsWelcome")}\n`;
514
+ function makeReadme(packageJson, language) {
515
+ return `# ${typeof packageJson["name"] === "string" && packageJson["name"].length > 0 ? packageJson["name"] : "Vited documentation"}\n\n${t("template.docsWelcome", { lng: language })}\n`;
313
516
  }
314
517
  async function writeIfMissing(filePath, content) {
315
518
  try {
@@ -318,4 +521,20 @@ async function writeIfMissing(filePath, content) {
318
521
  if (!isNodeError(error, "EEXIST")) throw error;
319
522
  }
320
523
  }
524
+ async function ensureGitignoreEntry(projectPath, entry) {
525
+ const gitignorePath = path.join(projectPath, ".gitignore");
526
+ let contents;
527
+ try {
528
+ contents = await readFile(gitignorePath, "utf8");
529
+ } catch (error) {
530
+ if (!isNodeError(error, "ENOENT")) throw error;
531
+ contents = "";
532
+ }
533
+ if (contents.split(/\r?\n/).some((line) => {
534
+ return line.trim().replaceAll(/^\/+|\/+$/g, "") === entry;
535
+ })) return;
536
+ const lineEnding = contents.includes("\r\n") ? "\r\n" : "\n";
537
+ const separator = contents.length > 0 && !contents.endsWith("\n") ? lineEnding : "";
538
+ await writeFile(gitignorePath, `${contents}${separator}${entry}${lineEnding}`);
539
+ }
321
540
  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-BWiFwqr3.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-KPLQg03-.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.4";
8
+ var version = "0.0.6";
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.4",
3
+ "version": "0.0.6",
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"
@@ -43,10 +44,10 @@
43
44
  "dependencies": {
44
45
  "@clack/prompts": "^1.8.1",
45
46
  "commander": "^11.0.0",
46
- "i18next": "^26.5.11"
47
+ "i18next": "^26.5.11",
48
+ "yaml": "^2.9.1"
47
49
  },
48
50
  "devDependencies": {
49
- "@guoyunhe/editorconfig": "^0.3.0",
50
51
  "@guoyunhe/oxfmt-config": "^1.1.0",
51
52
  "@tsconfig/node20": "^20.1.2",
52
53
  "@tsconfig/strictest": "^2.0.2",