grg-kit-cli 0.6.15 → 0.6.16
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/commands/init.js +70 -10
- package/package.json +1 -1
package/commands/init.js
CHANGED
|
@@ -10,6 +10,71 @@ const { RESOURCES, REPO } = require('../config/resources');
|
|
|
10
10
|
|
|
11
11
|
const execAsync = promisify(exec);
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Strip comments and trailing commas from JSON (for tsconfig.json parsing)
|
|
15
|
+
* Handles: block comments, line comments, and trailing commas
|
|
16
|
+
* Preserves // inside strings (like URLs)
|
|
17
|
+
*/
|
|
18
|
+
function stripJsonComments(jsonString) {
|
|
19
|
+
let result = '';
|
|
20
|
+
let i = 0;
|
|
21
|
+
let inString = false;
|
|
22
|
+
let stringChar = '';
|
|
23
|
+
|
|
24
|
+
while (i < jsonString.length) {
|
|
25
|
+
const char = jsonString[i];
|
|
26
|
+
const nextChar = jsonString[i + 1];
|
|
27
|
+
|
|
28
|
+
// Handle string boundaries
|
|
29
|
+
if ((char === '"' || char === "'") && (i === 0 || jsonString[i - 1] !== '\\')) {
|
|
30
|
+
if (!inString) {
|
|
31
|
+
inString = true;
|
|
32
|
+
stringChar = char;
|
|
33
|
+
} else if (char === stringChar) {
|
|
34
|
+
inString = false;
|
|
35
|
+
}
|
|
36
|
+
result += char;
|
|
37
|
+
i++;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Inside a string, copy everything
|
|
42
|
+
if (inString) {
|
|
43
|
+
result += char;
|
|
44
|
+
i++;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Block comment /* ... */
|
|
49
|
+
if (char === '/' && nextChar === '*') {
|
|
50
|
+
const endIndex = jsonString.indexOf('*/', i + 2);
|
|
51
|
+
if (endIndex !== -1) {
|
|
52
|
+
i = endIndex + 2;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Line comment // ...
|
|
58
|
+
if (char === '/' && nextChar === '/') {
|
|
59
|
+
const endIndex = jsonString.indexOf('\n', i);
|
|
60
|
+
if (endIndex !== -1) {
|
|
61
|
+
i = endIndex;
|
|
62
|
+
continue;
|
|
63
|
+
} else {
|
|
64
|
+
break; // Comment goes to end of file
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
result += char;
|
|
69
|
+
i++;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Remove trailing commas before } or ]
|
|
73
|
+
result = result.replace(/,(\s*[}\]])/g, '$1');
|
|
74
|
+
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
13
78
|
/**
|
|
14
79
|
* Download a file from a URL
|
|
15
80
|
*/
|
|
@@ -82,7 +147,7 @@ async function init(options) {
|
|
|
82
147
|
// Step 2: Install Tailwind CSS v4
|
|
83
148
|
spinner.start('Installing Tailwind CSS v4...');
|
|
84
149
|
try {
|
|
85
|
-
await execAsync('npm install tailwindcss @tailwindcss/postcss postcss --
|
|
150
|
+
await execAsync('npm install tailwindcss @tailwindcss/postcss postcss --legacy-peer-deps');
|
|
86
151
|
spinner.succeed(chalk.green('✓ Tailwind CSS v4 installed'));
|
|
87
152
|
} catch (error) {
|
|
88
153
|
spinner.fail(chalk.red('Failed to install Tailwind CSS v4'));
|
|
@@ -107,7 +172,7 @@ async function init(options) {
|
|
|
107
172
|
// Step 4: Install Spartan-NG CLI
|
|
108
173
|
spinner.start('Installing Spartan-NG CLI...');
|
|
109
174
|
try {
|
|
110
|
-
await execAsync('npm install -D @spartan-ng/cli');
|
|
175
|
+
await execAsync('npm install -D @spartan-ng/cli --legacy-peer-deps');
|
|
111
176
|
spinner.succeed(chalk.green('✓ Spartan-NG CLI installed'));
|
|
112
177
|
} catch (error) {
|
|
113
178
|
spinner.fail(chalk.red('Failed to install Spartan-NG CLI'));
|
|
@@ -135,14 +200,9 @@ async function init(options) {
|
|
|
135
200
|
let tsconfigContent = await fs.readFile(tsconfigPath, 'utf-8');
|
|
136
201
|
|
|
137
202
|
// Strip comments from tsconfig (Angular generates tsconfig with comments)
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
.replace(/^\s*\/\/.*/gm, ''); // Remove line comments (only at start of line after whitespace)
|
|
142
|
-
|
|
143
|
-
// Remove trailing commas (common in tsconfig files)
|
|
144
|
-
tsconfigContent = tsconfigContent
|
|
145
|
-
.replace(/,(\s*[}\]])/g, '$1');
|
|
203
|
+
// This handles: /* block comments */, // line comments, and trailing commas
|
|
204
|
+
// We need to be careful not to strip // inside strings
|
|
205
|
+
tsconfigContent = stripJsonComments(tsconfigContent);
|
|
146
206
|
|
|
147
207
|
const tsconfig = JSON.parse(tsconfigContent);
|
|
148
208
|
|