Skip to content

Commit 9ce4bae

Browse files
author
hHolyMolly
committed
feat: interactive project setup for degit users
- Ask project name on pnpm install (or auto-detect from directory) - Update package.json (name, version, remove license/prepare) - Remove .github/workflows automatically - Self-delete after setup
1 parent 42dfdce commit 9ce4bae

2 files changed

Lines changed: 43 additions & 6 deletions

File tree

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ gulp/
9292
└── utils/
9393
├── index.js # Re-exports
9494
├── logger.js # Console logger with ANSI colors + notifications
95-
├── prepare.js # Post-install cleanup for degit users
95+
├── prepare.js # Post-install setup for degit users (self-deleting)
9696
└── stream.js # sizeReporter, sourcemapsInit/Write, noop
9797
```
9898

gulp/utils/prepare.js

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
1-
import { existsSync, rmSync } from 'node:fs';
1+
import { existsSync, rmSync, readFileSync, writeFileSync } from 'node:fs';
2+
import { basename, resolve } from 'node:path';
3+
import { fileURLToPath } from 'node:url';
24

3-
// When installed via degit (no .git directory), remove CI-specific files
4-
// that are only needed for the template repository itself
5-
if (!existsSync('.git') && existsSync('.github/workflows')) {
6-
rmSync('.github/workflows', { recursive: true });
5+
// Only runs for degit-cloned projects (no .git directory)
6+
if (!existsSync('.git')) {
7+
// 1. Remove CI workflows (template-repo only)
8+
if (existsSync('.github/workflows')) {
9+
rmSync('.github/workflows', { recursive: true });
10+
}
11+
12+
// 2. Ask for project name (interactive) or use directory name (CI/non-TTY)
13+
const dirName = basename(resolve('.'));
14+
let projectName = dirName;
15+
16+
if (process.stdin.isTTY) {
17+
try {
18+
const { createInterface } = await import('node:readline/promises');
19+
const rl = createInterface({ input: process.stdin, output: process.stdout });
20+
const answer = await rl.question(`\n📦 Project name (${dirName}): `);
21+
if (answer.trim()) projectName = answer.trim();
22+
rl.close();
23+
} catch {
24+
// Non-interactive fallback — use directory name
25+
}
26+
}
27+
28+
// 3. Update package.json for the new project
29+
const pkg = JSON.parse(readFileSync('package.json', 'utf8'));
30+
pkg.name = projectName;
31+
pkg.version = '1.0.0';
32+
pkg.description = '';
33+
pkg.author = '';
34+
delete pkg.license;
35+
delete pkg.scripts.prepare;
36+
writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
37+
38+
// 4. Self-cleanup
39+
try {
40+
rmSync(fileURLToPath(import.meta.url), { force: true });
41+
} catch {}
42+
43+
console.log(`\n✅ Project "${projectName}" is ready! Run: pnpm dev\n`);
744
}

0 commit comments

Comments
 (0)