haraps 1.0.10 → 1.0.11

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 (2) hide show
  1. package/bin/index.js +45 -6
  2. package/package.json +7 -2
package/bin/index.js CHANGED
@@ -13,15 +13,54 @@ function ensureDir(dir) {
13
13
  }
14
14
  }
15
15
 
16
- function writeFile(filePath, content, skipIfExists = false) {
16
+ function writeFile(filePath, content, checkIfExists = false) {
17
17
  const fullPath = path.resolve(process.cwd(), filePath);
18
- if (skipIfExists && fs.existsSync(fullPath)) {
19
- console.log(`⏭️ Skipped: ${filePath} (already exists)`);
20
- return;
18
+ const newContent = content.trim() + '\n';
19
+
20
+ if (checkIfExists && fs.existsSync(fullPath)) {
21
+ const oldContent = fs.readFileSync(fullPath, 'utf8');
22
+ if (oldContent === newContent) {
23
+ console.log(`⏭️ Skipped: ${filePath} (identical content)`);
24
+ return;
25
+ }
26
+
27
+ console.log(`\n⚠️ File ${filePath} already exists and differs from the scaffolded version.`);
28
+
29
+ try {
30
+ const diff = require('diff');
31
+ const clc = require('cli-color');
32
+ const changes = diff.diffLines(oldContent, newContent);
33
+
34
+ console.log('\n--- Diff (Green: additions, Red: deletions) ---');
35
+ changes.forEach((part) => {
36
+ const color = part.added ? clc.green : part.removed ? clc.red : clc.blackBright;
37
+ const prefix = part.added ? '+ ' : part.removed ? '- ' : ' ';
38
+ const lines = part.value.split('\n');
39
+ if (lines[lines.length - 1] === '') lines.pop();
40
+ lines.forEach(l => console.log(color(prefix + l)));
41
+ });
42
+ console.log('-----------------------------------------------\n');
43
+ } catch (e) {
44
+ console.log("(Diff skipped, required packages missing)");
45
+ }
46
+
47
+ let answer = 'n';
48
+ try {
49
+ const readlineSync = require('readline-sync');
50
+ answer = readlineSync.question(`Do you want to overwrite ${filePath}? [y/N]: `);
51
+ } catch (e) {
52
+ answer = 'n';
53
+ }
54
+
55
+ if (answer.toLowerCase() !== 'y') {
56
+ console.log(`⏭️ Skipped: ${filePath} (user chose to keep existing)`);
57
+ return;
58
+ }
21
59
  }
60
+
22
61
  ensureDir(path.dirname(fullPath));
23
- fs.writeFileSync(fullPath, content.trim() + '\n', 'utf8');
24
- console.log(`✅ Created: ${filePath}`);
62
+ fs.writeFileSync(fullPath, newContent, 'utf8');
63
+ console.log(`✅ Created/Updated: ${filePath}`);
25
64
  }
26
65
 
27
66
  // 1. Dev Scripts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haraps",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "NPM package to scaffold standard development environment, deployment scripts, AGENTS.md guidelines, and core workflows for a Next.js frontend + Rust Cloudflare Worker backend.",
5
5
  "main": "bin/index.js",
6
6
  "bin": {
@@ -11,5 +11,10 @@
11
11
  },
12
12
  "keywords": [],
13
13
  "author": "",
14
- "license": "ISC"
14
+ "license": "ISC",
15
+ "dependencies": {
16
+ "cli-color": "^2.0.4",
17
+ "diff": "^9.0.0",
18
+ "readline-sync": "^1.4.10"
19
+ }
15
20
  }