@x-withu/page-withu 0.1.1 → 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 +36 -5
- package/package.json +1 -2
- package/template/.gitignore +0 -10
package/bin/page-withu.js
CHANGED
|
@@ -15,7 +15,18 @@ const __dirname = path.dirname(__filename);
|
|
|
15
15
|
const templateDir = path.resolve(__dirname, '../template');
|
|
16
16
|
const manifestName = '.page-withu.json';
|
|
17
17
|
const managedRoots = ['src'];
|
|
18
|
-
const managedFiles = ['
|
|
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 = [
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-withu/page-withu",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A lightweight, elegant personal homepage generator.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
"template/content/",
|
|
17
17
|
"template/src/",
|
|
18
18
|
"template/index.html",
|
|
19
|
-
"template/.gitignore",
|
|
20
19
|
"template/package.json",
|
|
21
20
|
"template/vite.config.js",
|
|
22
21
|
"docs/",
|