@x-withu/page-withu 0.1.0 → 0.1.2

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/bin/page-withu.js CHANGED
@@ -16,6 +16,17 @@ const templateDir = path.resolve(__dirname, '../template');
16
16
  const manifestName = '.page-withu.json';
17
17
  const managedRoots = ['src'];
18
18
  const managedFiles = ['index.html', 'vite.config.js'];
19
+ const generatedGitignore = `node_modules/
20
+ dist/
21
+
22
+ .env
23
+ .env.*
24
+ !.env.example
25
+ *.local
26
+
27
+ .DS_Store
28
+ .idea/
29
+ `;
19
30
 
20
31
  const program = new Command();
21
32
 
@@ -48,7 +59,11 @@ async function listFiles(dir) {
48
59
  }
49
60
 
50
61
  async function listManagedTemplateFiles() {
51
- const files = [...managedFiles];
62
+ const files = [];
63
+
64
+ for (const file of managedFiles) {
65
+ if (await fs.pathExists(path.join(templateDir, file))) files.push(file);
66
+ }
52
67
 
53
68
  for (const root of managedRoots) {
54
69
  const rootPath = path.join(templateDir, root);
@@ -126,6 +141,19 @@ async function loadManifest(projectDir) {
126
141
  return fs.readJson(manifestPath);
127
142
  }
128
143
 
144
+ async function ensureGeneratedGitignore(projectDir, dryRun) {
145
+ const gitignorePath = path.join(projectDir, '.gitignore');
146
+ const npmignorePath = path.join(projectDir, '.npmignore');
147
+ const hasGitignore = await fs.pathExists(gitignorePath);
148
+ const hasNpmignore = await fs.pathExists(npmignorePath);
149
+
150
+ if (dryRun) return !hasGitignore || hasNpmignore;
151
+ if (hasNpmignore) await fs.remove(npmignorePath);
152
+ if (!hasGitignore) await fs.writeFile(gitignorePath, generatedGitignore);
153
+
154
+ return !hasGitignore || hasNpmignore;
155
+ }
156
+
129
157
  async function shouldOverwriteConflict(file, options) {
130
158
  if (options.force) return true;
131
159
  if (options.yes || options.dryRun) return false;
@@ -222,14 +250,15 @@ function printUpdateSummary(summary, dryRun) {
222
250
  if (summary.added.length) console.log(chalk.green(`${label} ${summary.added.length} missing file(s).`));
223
251
  if (summary.updated.length) console.log(chalk.green(`${label} ${summary.updated.length} template file(s).`));
224
252
  if (summary.packageChanged) console.log(chalk.green(`${label} package.json dependencies and scripts.`));
253
+ if (summary.gitignoreChanged) console.log(chalk.green(`${label} .gitignore.`));
225
254
  if (summary.skipped.length) {
226
255
  console.log(chalk.yellow(`Skipped ${summary.skipped.length} file(s) with local changes:`));
227
256
  for (const file of summary.skipped) console.log(chalk.yellow(` - ${file}`));
228
257
  }
229
- if (!summary.added.length && !summary.updated.length && !summary.packageChanged && !summary.skipped.length) {
258
+ if (!summary.added.length && !summary.updated.length && !summary.packageChanged && !summary.gitignoreChanged && !summary.skipped.length) {
230
259
  console.log(chalk.green('Page With U project is already up to date.'));
231
260
  }
232
- if (!dryRun && (summary.added.length || summary.updated.length || summary.packageChanged)) {
261
+ if (!dryRun && (summary.added.length || summary.updated.length || summary.packageChanged || summary.gitignoreChanged)) {
233
262
  console.log(chalk.cyan('\nNext steps:'));
234
263
  console.log(chalk.cyan(' npm install'));
235
264
  console.log(chalk.cyan(' npm run build'));
@@ -329,6 +358,7 @@ program
329
358
  await fs.writeJson(pkgPath, projectPkg, { spaces: 2 });
330
359
 
331
360
  await fs.ensureDir(path.join(fullPath, 'content/blog'));
361
+ await ensureGeneratedGitignore(fullPath, false);
332
362
  await writeManifest(fullPath, false);
333
363
 
334
364
  spinner.succeed(chalk.green(`Successfully created PageWithU project in ${targetDir}!`));
@@ -366,10 +396,11 @@ program
366
396
  const previousManifest = await loadManifest(projectDir);
367
397
  const updates = await planTemplateUpdates(projectDir, options);
368
398
  const packageChanged = await mergePackage(projectDir, options.dryRun);
399
+ const gitignoreChanged = await ensureGeneratedGitignore(projectDir, options.dryRun);
369
400
 
370
401
  if (!options.dryRun) await writeManifest(projectDir, false, previousManifest);
371
402
 
372
- printUpdateSummary({ ...updates, packageChanged }, options.dryRun);
403
+ printUpdateSummary({ ...updates, packageChanged, gitignoreChanged }, options.dryRun);
373
404
  } catch (err) {
374
405
  spinner.fail(chalk.red('Failed to update project.'));
375
406
  console.error(err);
package/docs/deploy.md CHANGED
@@ -38,19 +38,60 @@ npm run preview
38
38
 
39
39
  ## 部署到 GitHub Pages
40
40
 
41
- 本仓库已经内置 GitHub Pages 自动部署流程:
41
+ GitHub Pages 适合把你生成好的个人主页托管到 GitHub 仓库中。
42
+
43
+ ### 方式一:使用 GitHub Actions 自动部署
44
+
45
+ 在你自己的主页项目中创建部署工作流:
42
46
 
43
47
  ```text
44
48
  .github/workflows/deploy-pages.yml
45
49
  ```
46
50
 
47
- 它会在推送到 `main` 分支时自动执行:
48
-
49
- 1. 进入 `template/`。
50
- 2. 执行 `npm ci` 安装模板依赖。
51
- 3. 使用 `BASE_PATH=/page-withu/ npm run build` 构建模板。
52
- 4. 上传 `template/dist/`。
53
- 5. 发布到 GitHub Pages。
51
+ 示例内容:
52
+
53
+ ```yaml
54
+ name: Deploy to GitHub Pages
55
+
56
+ on:
57
+ push:
58
+ branches: [main]
59
+ workflow_dispatch:
60
+
61
+ permissions:
62
+ contents: read
63
+ pages: write
64
+ id-token: write
65
+
66
+ concurrency:
67
+ group: pages
68
+ cancel-in-progress: false
69
+
70
+ jobs:
71
+ build:
72
+ runs-on: ubuntu-latest
73
+ steps:
74
+ - uses: actions/checkout@v4
75
+ - uses: actions/setup-node@v4
76
+ with:
77
+ node-version: 20
78
+ cache: npm
79
+ - run: npm ci
80
+ - run: npm run build
81
+ - uses: actions/upload-pages-artifact@v3
82
+ with:
83
+ path: dist
84
+
85
+ deploy:
86
+ needs: build
87
+ runs-on: ubuntu-latest
88
+ environment:
89
+ name: github-pages
90
+ url: ${{ steps.deployment.outputs.page_url }}
91
+ steps:
92
+ - id: deployment
93
+ uses: actions/deploy-pages@v4
94
+ ```
54
95
 
55
96
  首次使用前,需要在 GitHub 仓库中打开:
56
97
 
@@ -58,24 +99,23 @@ npm run preview
58
99
  Settings → Pages → Build and deployment → Source → GitHub Actions
59
100
  ```
60
101
 
61
- 配置完成后,每次推送到 `main` 分支都会自动更新:
102
+ 配置完成后,每次推送到 `main` 分支都会自动构建并发布你的站点。
62
103
 
63
- ```text
64
- https://explorer-dong.github.io/page-withu/
65
- ```
104
+ 如果仓库名不是用于根域名的 `用户名.github.io`,通常需要给构建命令设置子路径。例如仓库名是 `my-homepage`:
66
105
 
67
- 如果想手动触发部署,也可以在 GitHub Actions 页面选择 `Deploy Template to GitHub Pages`,然后点击 `Run workflow`。
106
+ ```yaml
107
+ - run: BASE_PATH=/my-homepage/ npm run build
108
+ ```
68
109
 
69
- ### 手动上传 dist
110
+ ### 方式二:手动上传 dist
70
111
 
71
112
  如果不想使用 GitHub Actions,也可以本地构建后手动上传 `dist/`。
72
113
 
73
114
  ```bash
74
- cd template
75
- BASE_PATH=/page-withu/ npm run build
115
+ npm run build
76
116
  ```
77
117
 
78
- 然后把 `template/dist/` 内容上传到用于 GitHub Pages 的发布分支或目录。
118
+ 然后把 `dist/` 内容上传到用于 GitHub Pages 的发布分支或目录。
79
119
 
80
120
  ## 部署到 Cloudflare Pages
81
121
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-withu/page-withu",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "A lightweight, elegant personal homepage generator.",
5
5
  "repository": {
6
6
  "type": "git",