@ng-annotate/angular 0.3.4 → 0.3.6
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/package.json +1 -1
- package/schematics/ng-add/index.js +31 -10
- package/schematics/ng-add/index.ts +32 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-annotate/angular",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"schematics": "./schematics/collection.json",
|
|
5
5
|
"description": "Angular library for ng-annotate-mcp — browser overlay for annotating components and routing instructions to an AI agent",
|
|
6
6
|
"keywords": [
|
|
@@ -3,6 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = default_1;
|
|
4
4
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
5
|
const tasks_1 = require("@angular-devkit/schematics/tasks");
|
|
6
|
+
/** Insert `newImport` on the line after the last import statement (handles multi-line imports and blank lines between groups). */
|
|
7
|
+
function insertAfterLastImport(content, newImport) {
|
|
8
|
+
const lines = content.split('\n');
|
|
9
|
+
let lastImportLine = -1;
|
|
10
|
+
let inImport = false;
|
|
11
|
+
for (let i = 0; i < lines.length; i++) {
|
|
12
|
+
if (/^import\s/.test(lines[i]))
|
|
13
|
+
inImport = true;
|
|
14
|
+
if (inImport) {
|
|
15
|
+
lastImportLine = i;
|
|
16
|
+
if (lines[i].includes(';'))
|
|
17
|
+
inImport = false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (lastImportLine < 0)
|
|
21
|
+
return newImport + '\n' + content;
|
|
22
|
+
lines.splice(lastImportLine + 1, 0, newImport);
|
|
23
|
+
return lines.join('\n');
|
|
24
|
+
}
|
|
25
|
+
/** Insert `newProvider` as the first item in the `providers: [...]` array, preserving indentation style. */
|
|
26
|
+
function insertIntoProviders(content, newProvider) {
|
|
27
|
+
return content.replace(/^(\s*)providers\s*:\s*\[/m, (match, indent) => {
|
|
28
|
+
return `${indent}providers: [\n${indent} ${newProvider},`;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
6
31
|
const MIN_ANGULAR_MAJOR = 21;
|
|
7
32
|
function checkAngularVersion() {
|
|
8
33
|
return (tree) => {
|
|
@@ -24,9 +49,9 @@ function addVitePlugin() {
|
|
|
24
49
|
const candidates = ['vite.config.ts', 'vite.config.js', 'vite.config.mts'];
|
|
25
50
|
const viteConfigPath = candidates.find((p) => tree.exists(p));
|
|
26
51
|
if (!viteConfigPath) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
52
|
+
const created = `import { defineConfig } from 'vite';\nimport { ngAnnotateMcp } from '@ng-annotate/vite-plugin';\n\nexport default defineConfig({\n plugins: [...ngAnnotateMcp()],\n});\n`;
|
|
53
|
+
tree.create('vite.config.ts', created);
|
|
54
|
+
context.logger.info('✅ Created vite.config.ts with ngAnnotateMcp()');
|
|
30
55
|
return;
|
|
31
56
|
}
|
|
32
57
|
let content = tree.read(viteConfigPath).toString('utf-8');
|
|
@@ -34,9 +59,7 @@ function addVitePlugin() {
|
|
|
34
59
|
context.logger.info('@ng-annotate/vite-plugin vite plugin already present, skipping.');
|
|
35
60
|
return;
|
|
36
61
|
}
|
|
37
|
-
|
|
38
|
-
content = content.replace(/(^import .+$(\r?\n)?)+/m, (match) => match + "import { ngAnnotateMcp } from '@ng-annotate/vite-plugin';\n");
|
|
39
|
-
// Insert spread into plugins array (handles `plugins: [` or `plugins:[`)
|
|
62
|
+
content = insertAfterLastImport(content, "import { ngAnnotateMcp } from '@ng-annotate/vite-plugin';");
|
|
40
63
|
content = content.replace(/plugins\s*:\s*\[/, 'plugins: [...ngAnnotateMcp(), ');
|
|
41
64
|
tree.overwrite(viteConfigPath, content);
|
|
42
65
|
context.logger.info(`✅ Added ngAnnotateMcp() to ${viteConfigPath}`);
|
|
@@ -61,10 +84,8 @@ function addProviders() {
|
|
|
61
84
|
context.logger.info('provideNgAnnotate already present, skipping.');
|
|
62
85
|
return;
|
|
63
86
|
}
|
|
64
|
-
|
|
65
|
-
content = content
|
|
66
|
-
// Insert into providers array
|
|
67
|
-
content = content.replace(/providers\s*:\s*\[/, 'providers: [\n provideNgAnnotate(),');
|
|
87
|
+
content = insertAfterLastImport(content, "import { provideNgAnnotate } from '@ng-annotate/angular';");
|
|
88
|
+
content = insertIntoProviders(content, 'provideNgAnnotate()');
|
|
68
89
|
tree.overwrite(appConfigPath, content);
|
|
69
90
|
context.logger.info(`✅ Added provideNgAnnotate() to ${appConfigPath}`);
|
|
70
91
|
};
|
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import { Rule, SchematicContext, Tree, chain, SchematicsException } from '@angular-devkit/schematics';
|
|
2
2
|
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
|
|
3
3
|
|
|
4
|
+
/** Insert `newImport` on the line after the last import statement (handles multi-line imports and blank lines between groups). */
|
|
5
|
+
function insertAfterLastImport(content: string, newImport: string): string {
|
|
6
|
+
const lines = content.split('\n');
|
|
7
|
+
let lastImportLine = -1;
|
|
8
|
+
let inImport = false;
|
|
9
|
+
|
|
10
|
+
for (let i = 0; i < lines.length; i++) {
|
|
11
|
+
if (/^import\s/.test(lines[i])) inImport = true;
|
|
12
|
+
if (inImport) {
|
|
13
|
+
lastImportLine = i;
|
|
14
|
+
if (lines[i].includes(';')) inImport = false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (lastImportLine < 0) return newImport + '\n' + content;
|
|
19
|
+
lines.splice(lastImportLine + 1, 0, newImport);
|
|
20
|
+
return lines.join('\n');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Insert `newProvider` as the first item in the `providers: [...]` array, preserving indentation style. */
|
|
24
|
+
function insertIntoProviders(content: string, newProvider: string): string {
|
|
25
|
+
return content.replace(/^(\s*)providers\s*:\s*\[/m, (match, indent) => {
|
|
26
|
+
return `${indent}providers: [\n${indent} ${newProvider},`;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
4
30
|
interface Options {
|
|
5
31
|
aiTool: 'claude-code' | 'vscode' | 'both' | 'other';
|
|
6
32
|
}
|
|
@@ -36,11 +62,9 @@ function addVitePlugin(): Rule {
|
|
|
36
62
|
const viteConfigPath = candidates.find((p) => tree.exists(p));
|
|
37
63
|
|
|
38
64
|
if (!viteConfigPath) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
' plugins: [...ngAnnotateMcp()]',
|
|
43
|
-
);
|
|
65
|
+
const created = `import { defineConfig } from 'vite';\nimport { ngAnnotateMcp } from '@ng-annotate/vite-plugin';\n\nexport default defineConfig({\n plugins: [...ngAnnotateMcp()],\n});\n`;
|
|
66
|
+
tree.create('vite.config.ts', created);
|
|
67
|
+
context.logger.info('✅ Created vite.config.ts with ngAnnotateMcp()');
|
|
44
68
|
return;
|
|
45
69
|
}
|
|
46
70
|
|
|
@@ -51,13 +75,7 @@ function addVitePlugin(): Rule {
|
|
|
51
75
|
return;
|
|
52
76
|
}
|
|
53
77
|
|
|
54
|
-
|
|
55
|
-
content = content.replace(
|
|
56
|
-
/(^import .+$(\r?\n)?)+/m,
|
|
57
|
-
(match) => match + "import { ngAnnotateMcp } from '@ng-annotate/vite-plugin';\n",
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
// Insert spread into plugins array (handles `plugins: [` or `plugins:[`)
|
|
78
|
+
content = insertAfterLastImport(content, "import { ngAnnotateMcp } from '@ng-annotate/vite-plugin';");
|
|
61
79
|
content = content.replace(/plugins\s*:\s*\[/, 'plugins: [...ngAnnotateMcp(), ');
|
|
62
80
|
|
|
63
81
|
tree.overwrite(viteConfigPath, content);
|
|
@@ -90,14 +108,8 @@ function addProviders(): Rule {
|
|
|
90
108
|
return;
|
|
91
109
|
}
|
|
92
110
|
|
|
93
|
-
|
|
94
|
-
content = content
|
|
95
|
-
/(^import .+$(\r?\n)?)+/m,
|
|
96
|
-
(match) => match + "import { provideNgAnnotate } from '@ng-annotate/angular';\n",
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
// Insert into providers array
|
|
100
|
-
content = content.replace(/providers\s*:\s*\[/, 'providers: [\n provideNgAnnotate(),');
|
|
111
|
+
content = insertAfterLastImport(content, "import { provideNgAnnotate } from '@ng-annotate/angular';");
|
|
112
|
+
content = insertIntoProviders(content, 'provideNgAnnotate()');
|
|
101
113
|
|
|
102
114
|
tree.overwrite(appConfigPath, content);
|
|
103
115
|
context.logger.info(`✅ Added provideNgAnnotate() to ${appConfigPath}`);
|