vibefast-cli 0.1.3 → 0.2.0

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.
Files changed (78) hide show
  1. package/AUTO-DETECT-DEPS.md +607 -0
  2. package/CHANGELOG.md +86 -0
  3. package/FINAL-PACKAGE-STRATEGY.md +583 -0
  4. package/FINAL-SIMPLE-PLAN.md +487 -0
  5. package/FLOW-DIAGRAM.md +1629 -0
  6. package/GOTCHAS-AND-RISKS.md +801 -0
  7. package/IMPLEMENTATION-COMPLETE.md +477 -0
  8. package/IMPLEMENTATION-PLAN.md +1360 -0
  9. package/PRE-PUBLISH-CHECKLIST.md +558 -0
  10. package/PRODUCTION-READINESS.md +684 -0
  11. package/PRODUCTION-TEST-RESULTS.md +465 -0
  12. package/README.md +73 -7
  13. package/READY-TO-PUBLISH.md +419 -0
  14. package/SIMPLIFIED-PLAN.md +578 -0
  15. package/TEST-SUMMARY.md +261 -0
  16. package/USER-MODIFICATIONS.md +448 -0
  17. package/cloudflare-worker/worker.js +39 -11
  18. package/dist/commands/add.d.ts.map +1 -1
  19. package/dist/commands/add.js +192 -15
  20. package/dist/commands/add.js.map +1 -1
  21. package/dist/commands/checklist.d.ts +3 -0
  22. package/dist/commands/checklist.d.ts.map +1 -0
  23. package/dist/commands/checklist.js +64 -0
  24. package/dist/commands/checklist.js.map +1 -0
  25. package/dist/commands/remove.d.ts.map +1 -1
  26. package/dist/commands/remove.js +85 -2
  27. package/dist/commands/remove.js.map +1 -1
  28. package/dist/commands/status.d.ts +3 -0
  29. package/dist/commands/status.d.ts.map +1 -0
  30. package/dist/commands/status.js +40 -0
  31. package/dist/commands/status.js.map +1 -0
  32. package/dist/core/__tests__/fsx.test.d.ts +2 -0
  33. package/dist/core/__tests__/fsx.test.d.ts.map +1 -0
  34. package/dist/core/__tests__/fsx.test.js +79 -0
  35. package/dist/core/__tests__/fsx.test.js.map +1 -0
  36. package/dist/core/__tests__/hash.test.d.ts +2 -0
  37. package/dist/core/__tests__/hash.test.d.ts.map +1 -0
  38. package/dist/core/__tests__/hash.test.js +84 -0
  39. package/dist/core/__tests__/hash.test.js.map +1 -0
  40. package/dist/core/__tests__/journal.test.js +65 -0
  41. package/dist/core/__tests__/journal.test.js.map +1 -1
  42. package/dist/core/__tests__/prompt.test.d.ts +2 -0
  43. package/dist/core/__tests__/prompt.test.d.ts.map +1 -0
  44. package/dist/core/__tests__/prompt.test.js +56 -0
  45. package/dist/core/__tests__/prompt.test.js.map +1 -0
  46. package/dist/core/fsx.d.ts +7 -1
  47. package/dist/core/fsx.d.ts.map +1 -1
  48. package/dist/core/fsx.js +18 -3
  49. package/dist/core/fsx.js.map +1 -1
  50. package/dist/core/hash.d.ts +13 -0
  51. package/dist/core/hash.d.ts.map +1 -0
  52. package/dist/core/hash.js +69 -0
  53. package/dist/core/hash.js.map +1 -0
  54. package/dist/core/journal.d.ts +10 -1
  55. package/dist/core/journal.d.ts.map +1 -1
  56. package/dist/core/journal.js +23 -1
  57. package/dist/core/journal.js.map +1 -1
  58. package/dist/core/prompt.d.ts +11 -0
  59. package/dist/core/prompt.d.ts.map +1 -0
  60. package/dist/core/prompt.js +34 -0
  61. package/dist/core/prompt.js.map +1 -0
  62. package/dist/index.js +5 -1
  63. package/dist/index.js.map +1 -1
  64. package/package.json +3 -1
  65. package/src/commands/add.ts +234 -16
  66. package/src/commands/checklist.ts +71 -0
  67. package/src/commands/remove.ts +105 -3
  68. package/src/commands/status.ts +47 -0
  69. package/src/core/__tests__/fsx.test.ts +101 -0
  70. package/src/core/__tests__/hash.test.ts +112 -0
  71. package/src/core/__tests__/journal.test.ts +76 -0
  72. package/src/core/__tests__/prompt.test.ts +72 -0
  73. package/src/core/fsx.ts +38 -5
  74. package/src/core/hash.ts +84 -0
  75. package/src/core/journal.ts +40 -2
  76. package/src/core/prompt.ts +40 -0
  77. package/src/index.ts +5 -1
  78. package/text.md +27 -0
@@ -2,15 +2,19 @@ import { Command } from 'commander';
2
2
  import { log } from '../core/log.js';
3
3
  import { getPaths } from '../core/paths.js';
4
4
  import { validateSignature, validateTarget } from '../core/validate.js';
5
- import { getEntry, removeEntry } from '../core/journal.js';
5
+ import { getEntry, removeEntry, FileEntry } from '../core/journal.js';
6
6
  import { deleteFile } from '../core/fsx.js';
7
7
  import { removeNavLinkNative, removeNavLinkWeb } from '../core/codemod.js';
8
+ import { hashFile } from '../core/hash.js';
9
+ import { promptYesNo } from '../core/prompt.js';
8
10
 
9
11
  export const removeCommand = new Command('remove')
10
12
  .description('Remove a VibeFast feature from your project')
11
13
  .argument('<feature>', 'Feature name to remove')
12
14
  .option('--target <target>', 'Target platform (native or web)', 'native')
13
15
  .option('--dry-run', 'Preview changes without applying')
16
+ .option('--force', 'Skip modification check')
17
+ .option('--yes', 'Answer yes to all prompts')
14
18
  .action(async (feature: string, options) => {
15
19
  try {
16
20
  const paths = getPaths();
@@ -35,8 +39,99 @@ export const removeCommand = new Command('remove')
35
39
 
36
40
  log.info(`Removing ${feature} from ${target}...`);
37
41
 
42
+ // Check for modifications (unless --force)
43
+ if (!options.force && !options.dryRun) {
44
+ log.info('Checking for file modifications...');
45
+
46
+ const modifiedFiles: Array<{ path: string; status: 'modified' | 'deleted' }> = [];
47
+
48
+ // Get file paths from entry
49
+ const filePaths = Array.isArray(entry.files) && entry.files.length > 0
50
+ ? typeof entry.files[0] === 'string'
51
+ ? entry.files as string[]
52
+ : (entry.files as FileEntry[]).map(f => f.path)
53
+ : [];
54
+
55
+ const fileHashes = Array.isArray(entry.files) && entry.files.length > 0 && typeof entry.files[0] !== 'string'
56
+ ? new Map((entry.files as FileEntry[]).map(f => [f.path, f.hash]))
57
+ : new Map<string, string>();
58
+
59
+ for (const filePath of filePaths) {
60
+ const originalHash = fileHashes.get(filePath);
61
+
62
+ // Skip if we don't have original hash (old journal format)
63
+ if (!originalHash) continue;
64
+
65
+ const currentHash = await hashFile(filePath);
66
+
67
+ if (currentHash === '') {
68
+ // File was deleted by user
69
+ modifiedFiles.push({ path: filePath, status: 'deleted' });
70
+ } else if (currentHash !== originalHash) {
71
+ // File was modified by user
72
+ modifiedFiles.push({ path: filePath, status: 'modified' });
73
+ }
74
+ }
75
+
76
+ // Warn about modifications
77
+ if (modifiedFiles.length > 0) {
78
+ log.plain('');
79
+ log.warn('⚠ WARNING: The following files were changed:');
80
+ log.plain('');
81
+
82
+ const modified = modifiedFiles.filter(f => f.status === 'modified');
83
+ const deleted = modifiedFiles.filter(f => f.status === 'deleted');
84
+
85
+ if (modified.length > 0) {
86
+ log.plain(' Modified by you:');
87
+ modified.slice(0, 10).forEach(f => {
88
+ const relativePath = f.path.replace(paths.cwd + '/', '');
89
+ log.plain(` • ${relativePath}`);
90
+ });
91
+ if (modified.length > 10) {
92
+ log.plain(` ... and ${modified.length - 10} more`);
93
+ }
94
+ }
95
+
96
+ if (deleted.length > 0) {
97
+ log.plain('');
98
+ log.plain(' Already deleted:');
99
+ deleted.slice(0, 5).forEach(f => {
100
+ const relativePath = f.path.replace(paths.cwd + '/', '');
101
+ log.plain(` • ${relativePath}`);
102
+ });
103
+ if (deleted.length > 5) {
104
+ log.plain(` ... and ${deleted.length - 5} more`);
105
+ }
106
+ }
107
+
108
+ log.plain('');
109
+ log.warn('⚠ Your changes will be LOST if you continue!');
110
+ log.info('💡 Make sure you have committed to Git.');
111
+ log.plain('');
112
+
113
+ if (!options.yes) {
114
+ const shouldContinue = promptYesNo(
115
+ 'Continue with removal? (y/N): ',
116
+ false
117
+ );
118
+
119
+ if (!shouldContinue) {
120
+ log.info('Removal cancelled');
121
+ return;
122
+ }
123
+ }
124
+ }
125
+ }
126
+
38
127
  // Delete files
39
- for (const file of entry.files) {
128
+ const filePaths = Array.isArray(entry.files) && entry.files.length > 0
129
+ ? typeof entry.files[0] === 'string'
130
+ ? entry.files as string[]
131
+ : (entry.files as FileEntry[]).map(f => f.path)
132
+ : [];
133
+
134
+ for (const file of filePaths) {
40
135
  log.info(`Deleting ${file}`);
41
136
  if (!options.dryRun) {
42
137
  await deleteFile(file);
@@ -66,7 +161,14 @@ export const removeCommand = new Command('remove')
66
161
  }
67
162
 
68
163
  log.success(`${feature} removed successfully!`);
69
- log.info(`Files deleted: ${entry.files.length}`);
164
+
165
+ const fileCount = Array.isArray(entry.files) && entry.files.length > 0
166
+ ? typeof entry.files[0] === 'string'
167
+ ? entry.files.length
168
+ : (entry.files as FileEntry[]).length
169
+ : 0;
170
+
171
+ log.info(`Files deleted: ${fileCount}`);
70
172
 
71
173
  if (options.dryRun) {
72
174
  log.warn('This was a dry run. Run without --dry-run to apply changes.');
@@ -0,0 +1,47 @@
1
+ import { Command } from 'commander';
2
+ import { log } from '../core/log.js';
3
+ import { getPaths } from '../core/paths.js';
4
+ import { readJournal, FileEntry } from '../core/journal.js';
5
+
6
+ export const statusCommand = new Command('status')
7
+ .description('Show installed features and their status')
8
+ .action(async () => {
9
+ try {
10
+ const paths = getPaths();
11
+ const journal = await readJournal(paths.journalFile);
12
+
13
+ if (journal.entries.length === 0) {
14
+ log.info('No features installed yet');
15
+ log.info('Run "vf list" to see available features');
16
+ return;
17
+ }
18
+
19
+ log.info('Installed features:');
20
+ log.plain('');
21
+
22
+ for (const entry of journal.entries) {
23
+ const version = entry.manifest?.version || 'unknown';
24
+ const fileCount = Array.isArray(entry.files) && entry.files.length > 0
25
+ ? typeof entry.files[0] === 'string'
26
+ ? entry.files.length
27
+ : (entry.files as FileEntry[]).length
28
+ : 0;
29
+
30
+ log.plain(` ✓ ${entry.feature} (v${version}) - ${entry.target}`);
31
+ log.plain(` Files: ${fileCount}`);
32
+ log.plain(` Installed: ${new Date(entry.ts).toLocaleDateString()}`);
33
+
34
+ if (entry.manifest?.manualSteps && entry.manifest.manualSteps.length > 0) {
35
+ log.plain(` ⚠ Has manual setup steps (run: vf checklist ${entry.feature})`);
36
+ }
37
+
38
+ log.plain('');
39
+ }
40
+
41
+ log.info(`Total: ${journal.entries.length} feature(s) installed`);
42
+
43
+ } catch (error: any) {
44
+ log.error(`Failed to show status: ${error.message}`);
45
+ process.exit(1);
46
+ }
47
+ });
@@ -0,0 +1,101 @@
1
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
+ import { copyTree, exists } from '../fsx.js';
3
+ import { writeFile, mkdir, rm } from 'fs/promises';
4
+ import { join } from 'path';
5
+ import { tmpdir } from 'os';
6
+
7
+ describe('fsx', () => {
8
+ let testDir: string;
9
+ let srcDir: string;
10
+ let destDir: string;
11
+
12
+ beforeEach(async () => {
13
+ testDir = join(tmpdir(), `vibefast-test-${Date.now()}`);
14
+ srcDir = join(testDir, 'src');
15
+ destDir = join(testDir, 'dest');
16
+
17
+ await mkdir(srcDir, { recursive: true });
18
+ await mkdir(destDir, { recursive: true });
19
+ });
20
+
21
+ afterEach(async () => {
22
+ await rm(testDir, { recursive: true, force: true });
23
+ });
24
+
25
+ describe('copyTree', () => {
26
+ it('should copy files successfully', async () => {
27
+ const file1 = join(srcDir, 'file1.txt');
28
+ const file2 = join(srcDir, 'file2.txt');
29
+
30
+ await writeFile(file1, 'content 1');
31
+ await writeFile(file2, 'content 2');
32
+
33
+ const result = await copyTree(srcDir, destDir);
34
+
35
+ expect(result.files).toHaveLength(2);
36
+ expect(result.conflicts).toHaveLength(0);
37
+ expect(result.skipped).toHaveLength(0);
38
+
39
+ expect(await exists(join(destDir, 'file1.txt'))).toBe(true);
40
+ expect(await exists(join(destDir, 'file2.txt'))).toBe(true);
41
+ });
42
+
43
+ it('should detect conflicts', async () => {
44
+ const srcFile = join(srcDir, 'file.txt');
45
+ const destFile = join(destDir, 'file.txt');
46
+
47
+ await writeFile(srcFile, 'new content');
48
+ await writeFile(destFile, 'existing content');
49
+
50
+ try {
51
+ await copyTree(srcDir, destDir);
52
+ expect.fail('Should have thrown error');
53
+ } catch (error: any) {
54
+ expect(error.message).toContain('File exists');
55
+ }
56
+ });
57
+
58
+ it('should overwrite with force flag', async () => {
59
+ // Create source file
60
+ await writeFile(join(srcDir, 'file.txt'), 'new content');
61
+
62
+ // Create existing destination file
63
+ await writeFile(join(destDir, 'file.txt'), 'existing content');
64
+
65
+ const result = await copyTree(srcDir, destDir, { force: true });
66
+
67
+ expect(result.files).toHaveLength(1);
68
+ expect(result.conflicts).toHaveLength(1);
69
+ expect(result.skipped).toHaveLength(0);
70
+ });
71
+
72
+ it('should handle dry-run mode', async () => {
73
+ const file1 = join(srcDir, 'file1.txt');
74
+ await writeFile(file1, 'content');
75
+
76
+ const result = await copyTree(srcDir, destDir, { dryRun: true });
77
+
78
+ expect(result.files).toHaveLength(1);
79
+ expect(await exists(join(destDir, 'file1.txt'))).toBe(false); // Not actually copied
80
+ });
81
+
82
+ it('should copy nested directories', async () => {
83
+ const nestedDir = join(srcDir, 'nested');
84
+ await mkdir(nestedDir);
85
+ await writeFile(join(nestedDir, 'file.txt'), 'content');
86
+
87
+ const result = await copyTree(srcDir, destDir);
88
+
89
+ expect(result.files).toHaveLength(1);
90
+ expect(await exists(join(destDir, 'nested', 'file.txt'))).toBe(true);
91
+ });
92
+
93
+ it('should handle empty directory', async () => {
94
+ const result = await copyTree(srcDir, destDir);
95
+
96
+ expect(result.files).toHaveLength(0);
97
+ expect(result.conflicts).toHaveLength(0);
98
+ expect(result.skipped).toHaveLength(0);
99
+ });
100
+ });
101
+ });
@@ -0,0 +1,112 @@
1
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
+ import { hashFile, hashFiles } from '../hash.js';
3
+ import { writeFile, unlink, mkdir, rm } from 'fs/promises';
4
+ import { join } from 'path';
5
+ import { tmpdir } from 'os';
6
+
7
+ describe('hash', () => {
8
+ let testDir: string;
9
+
10
+ beforeEach(async () => {
11
+ testDir = join(tmpdir(), `vibefast-test-${Date.now()}`);
12
+ await mkdir(testDir, { recursive: true });
13
+ });
14
+
15
+ afterEach(async () => {
16
+ await rm(testDir, { recursive: true, force: true });
17
+ });
18
+
19
+ describe('hashFile', () => {
20
+ it('should hash file content correctly', async () => {
21
+ const testFile = join(testDir, 'test.txt');
22
+ await writeFile(testFile, 'hello world');
23
+
24
+ const hash = await hashFile(testFile);
25
+
26
+ // SHA-256 of "hello world"
27
+ expect(hash).toBe('b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9');
28
+ });
29
+
30
+ it('should return empty string for non-existent file', async () => {
31
+ const hash = await hashFile(join(testDir, 'does-not-exist.txt'));
32
+ expect(hash).toBe('');
33
+ });
34
+
35
+ it('should detect file modifications', async () => {
36
+ const testFile = join(testDir, 'test.txt');
37
+ await writeFile(testFile, 'original');
38
+
39
+ const hash1 = await hashFile(testFile);
40
+
41
+ await writeFile(testFile, 'modified');
42
+
43
+ const hash2 = await hashFile(testFile);
44
+
45
+ expect(hash1).not.toBe(hash2);
46
+ expect(hash1).not.toBe('');
47
+ expect(hash2).not.toBe('');
48
+ });
49
+
50
+ it('should produce same hash for same content', async () => {
51
+ const file1 = join(testDir, 'file1.txt');
52
+ const file2 = join(testDir, 'file2.txt');
53
+
54
+ await writeFile(file1, 'same content');
55
+ await writeFile(file2, 'same content');
56
+
57
+ const hash1 = await hashFile(file1);
58
+ const hash2 = await hashFile(file2);
59
+
60
+ expect(hash1).toBe(hash2);
61
+ });
62
+ });
63
+
64
+ describe('hashFiles', () => {
65
+ it('should hash multiple files', async () => {
66
+ const file1 = join(testDir, 'file1.txt');
67
+ const file2 = join(testDir, 'file2.txt');
68
+
69
+ await writeFile(file1, 'content 1');
70
+ await writeFile(file2, 'content 2');
71
+
72
+ const hashes = await hashFiles([file1, file2]);
73
+
74
+ expect(hashes.size).toBe(2);
75
+ expect(hashes.get(file1)).toBeTruthy();
76
+ expect(hashes.get(file2)).toBeTruthy();
77
+ expect(hashes.get(file1)).not.toBe(hashes.get(file2));
78
+ });
79
+
80
+ it('should skip binary files', async () => {
81
+ const textFile = join(testDir, 'file.txt');
82
+ const imageFile = join(testDir, 'image.png');
83
+
84
+ await writeFile(textFile, 'text content');
85
+ await writeFile(imageFile, 'fake image data');
86
+
87
+ const hashes = await hashFiles([textFile, imageFile]);
88
+
89
+ expect(hashes.size).toBe(2);
90
+ expect(hashes.get(textFile)).toBeTruthy();
91
+ expect(hashes.get(imageFile)).toBe(''); // Empty hash for binary
92
+ });
93
+
94
+ it('should handle empty array', async () => {
95
+ const hashes = await hashFiles([]);
96
+ expect(hashes.size).toBe(0);
97
+ });
98
+
99
+ it('should handle non-existent files gracefully', async () => {
100
+ const existingFile = join(testDir, 'exists.txt');
101
+ const missingFile = join(testDir, 'missing.txt');
102
+
103
+ await writeFile(existingFile, 'content');
104
+
105
+ const hashes = await hashFiles([existingFile, missingFile]);
106
+
107
+ expect(hashes.size).toBe(1);
108
+ expect(hashes.get(existingFile)).toBeTruthy();
109
+ expect(hashes.has(missingFile)).toBe(false);
110
+ });
111
+ });
112
+ });
@@ -116,4 +116,80 @@ describe('journal', () => {
116
116
  expect(found).not.toBeNull();
117
117
  expect(found?.feature).toBe('test');
118
118
  });
119
+
120
+ it('should handle new format with file hashes', async () => {
121
+ const entry = {
122
+ feature: 'charts',
123
+ target: 'native' as const,
124
+ files: [
125
+ { path: '/file1.ts', hash: 'abc123' },
126
+ { path: '/file2.ts', hash: 'def456' },
127
+ ],
128
+ insertedNav: true,
129
+ ts: Date.now(),
130
+ };
131
+
132
+ await addEntry(journalPath, entry);
133
+ const journal = await readJournal(journalPath);
134
+
135
+ expect(journal.entries).toHaveLength(1);
136
+ expect(journal.entries[0].files).toHaveLength(2);
137
+ expect(journal.entries[0].files[0]).toHaveProperty('path');
138
+ expect(journal.entries[0].files[0]).toHaveProperty('hash');
139
+ });
140
+
141
+ it('should migrate old format to new format', async () => {
142
+ // Write old format manually
143
+ const oldJournal = {
144
+ entries: [
145
+ {
146
+ feature: 'old-feature',
147
+ target: 'native' as const,
148
+ files: ['/file1.ts', '/file2.ts'], // Old format: array of strings
149
+ insertedNav: true,
150
+ ts: Date.now(),
151
+ },
152
+ ],
153
+ };
154
+
155
+ await writeJournal(journalPath, oldJournal as any);
156
+
157
+ // Read should auto-migrate
158
+ const journal = await readJournal(journalPath);
159
+
160
+ expect(journal.entries).toHaveLength(1);
161
+ expect(journal.entries[0].files).toHaveLength(2);
162
+
163
+ // Should be converted to new format
164
+ const firstFile = journal.entries[0].files[0];
165
+ expect(firstFile).toHaveProperty('path');
166
+ expect(firstFile).toHaveProperty('hash');
167
+ });
168
+
169
+ it('should store manifest data', async () => {
170
+ const entry = {
171
+ feature: 'sentry',
172
+ target: 'native' as const,
173
+ files: [{ path: '/file.ts', hash: 'abc' }],
174
+ insertedNav: true,
175
+ ts: Date.now(),
176
+ manifest: {
177
+ version: '1.0.0',
178
+ manualSteps: [
179
+ { title: 'Step 1', description: 'Do something' },
180
+ ],
181
+ env: [
182
+ { key: 'API_KEY', description: 'Your API key', example: 'xxx' },
183
+ ],
184
+ },
185
+ };
186
+
187
+ await addEntry(journalPath, entry);
188
+ const found = await getEntry(journalPath, 'sentry', 'native');
189
+
190
+ expect(found?.manifest).toBeDefined();
191
+ expect(found?.manifest?.version).toBe('1.0.0');
192
+ expect(found?.manifest?.manualSteps).toHaveLength(1);
193
+ expect(found?.manifest?.env).toHaveLength(1);
194
+ });
119
195
  });
@@ -0,0 +1,72 @@
1
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
+ import { promptYesNo } from '../prompt.js';
3
+
4
+ describe('prompt', () => {
5
+ let originalIsTTY: boolean | undefined;
6
+ let originalCI: string | undefined;
7
+
8
+ beforeEach(() => {
9
+ originalIsTTY = process.stdin.isTTY;
10
+ originalCI = process.env.CI;
11
+ });
12
+
13
+ afterEach(() => {
14
+ if (originalIsTTY !== undefined) {
15
+ (process.stdin as any).isTTY = originalIsTTY;
16
+ }
17
+ if (originalCI !== undefined) {
18
+ process.env.CI = originalCI;
19
+ } else {
20
+ delete process.env.CI;
21
+ }
22
+ });
23
+
24
+ describe('promptYesNo', () => {
25
+ it('should return default value in non-TTY environment', () => {
26
+ (process.stdin as any).isTTY = false;
27
+
28
+ const result = promptYesNo('Continue?', true);
29
+ expect(result).toBe(true);
30
+
31
+ const result2 = promptYesNo('Continue?', false);
32
+ expect(result2).toBe(false);
33
+ });
34
+
35
+ it('should return default value in CI environment', () => {
36
+ process.env.CI = 'true';
37
+
38
+ const result = promptYesNo('Continue?', true);
39
+ expect(result).toBe(true);
40
+
41
+ const result2 = promptYesNo('Continue?', false);
42
+ expect(result2).toBe(false);
43
+ });
44
+
45
+ it('should detect GitHub Actions', () => {
46
+ process.env.GITHUB_ACTIONS = 'true';
47
+
48
+ const result = promptYesNo('Continue?', false);
49
+ expect(result).toBe(false);
50
+
51
+ delete process.env.GITHUB_ACTIONS;
52
+ });
53
+
54
+ it('should detect GitLab CI', () => {
55
+ process.env.GITLAB_CI = 'true';
56
+
57
+ const result = promptYesNo('Continue?', false);
58
+ expect(result).toBe(false);
59
+
60
+ delete process.env.GITLAB_CI;
61
+ });
62
+
63
+ it('should detect CircleCI', () => {
64
+ process.env.CIRCLECI = 'true';
65
+
66
+ const result = promptYesNo('Continue?', false);
67
+ expect(result).toBe(false);
68
+
69
+ delete process.env.CIRCLECI;
70
+ });
71
+ });
72
+ });
package/src/core/fsx.ts CHANGED
@@ -44,12 +44,24 @@ export async function deleteFile(path: string): Promise<void> {
44
44
  }
45
45
  }
46
46
 
47
+ export interface CopyResult {
48
+ files: string[];
49
+ conflicts: string[];
50
+ skipped: string[];
51
+ }
52
+
47
53
  export async function copyTree(
48
54
  src: string,
49
55
  dest: string,
50
- options?: { dryRun?: boolean; force?: boolean }
51
- ): Promise<string[]> {
56
+ options?: {
57
+ dryRun?: boolean;
58
+ force?: boolean;
59
+ interactive?: boolean;
60
+ }
61
+ ): Promise<CopyResult> {
52
62
  const copied: string[] = [];
63
+ const conflicts: string[] = [];
64
+ const skipped: string[] = [];
53
65
 
54
66
  async function copyRecursive(srcPath: string, destPath: string) {
55
67
  const stats = await stat(srcPath);
@@ -64,9 +76,30 @@ export async function copyTree(
64
76
  }
65
77
  } else {
66
78
  const destExists = await exists(destPath);
67
- if (destExists && !options?.force) {
68
- throw new Error(`File exists: ${destPath}. Use --force to overwrite.`);
79
+
80
+ if (destExists) {
81
+ conflicts.push(destPath);
82
+
83
+ // If not force and not interactive, throw error
84
+ if (!options?.force && !options?.interactive) {
85
+ throw new Error(`File exists: ${destPath}. Use --force to overwrite.`);
86
+ }
87
+
88
+ // If interactive and not dry-run, ask user
89
+ if (options?.interactive && !options?.dryRun) {
90
+ const { promptYesNo } = await import('./prompt.js');
91
+ const shouldOverwrite = promptYesNo(
92
+ `Overwrite ${destPath}? (y/N): `,
93
+ false
94
+ );
95
+
96
+ if (!shouldOverwrite) {
97
+ skipped.push(destPath);
98
+ return; // Skip this file
99
+ }
100
+ }
69
101
  }
102
+
70
103
  if (!options?.dryRun) {
71
104
  await ensureDir(dirname(destPath));
72
105
  await copyFile(srcPath, destPath);
@@ -76,5 +109,5 @@ export async function copyTree(
76
109
  }
77
110
 
78
111
  await copyRecursive(src, dest);
79
- return copied;
112
+ return { files: copied, conflicts, skipped };
80
113
  }