magector 1.2.6 → 1.2.7

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/package.json +5 -5
  2. package/src/init.js +33 -24
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magector",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "description": "Semantic code search for Magento 2 — index, search, MCP server",
5
5
  "type": "module",
6
6
  "main": "src/mcp-server.js",
@@ -31,10 +31,10 @@
31
31
  "ruvector": "^0.1.96"
32
32
  },
33
33
  "optionalDependencies": {
34
- "@magector/cli-darwin-arm64": "1.2.6",
35
- "@magector/cli-linux-x64": "1.2.6",
36
- "@magector/cli-linux-arm64": "1.2.6",
37
- "@magector/cli-win32-x64": "1.2.6"
34
+ "@magector/cli-darwin-arm64": "1.2.7",
35
+ "@magector/cli-linux-x64": "1.2.7",
36
+ "@magector/cli-linux-arm64": "1.2.7",
37
+ "@magector/cli-win32-x64": "1.2.7"
38
38
  },
39
39
  "keywords": [
40
40
  "magento",
package/src/init.js CHANGED
@@ -95,6 +95,35 @@ function writeMcpConfig(projectPath, ides, dbPath) {
95
95
  /**
96
96
  * Write IDE rules files.
97
97
  */
98
+ /**
99
+ * Replace the Magector section in an existing file, or append if not present.
100
+ * Magector sections are delimited by marker comments.
101
+ */
102
+ function upsertMagectorSection(filePath, content, markerStart, markerEnd) {
103
+ if (!existsSync(filePath)) {
104
+ writeFileSync(filePath, markerStart + '\n' + content + markerEnd + '\n');
105
+ return 'created';
106
+ }
107
+ const existing = readFileSync(filePath, 'utf-8');
108
+ const startIdx = existing.indexOf(markerStart);
109
+ const endIdx = existing.indexOf(markerEnd);
110
+ if (startIdx !== -1 && endIdx !== -1) {
111
+ const updated = existing.slice(0, startIdx) + markerStart + '\n' + content + existing.slice(endIdx);
112
+ writeFileSync(filePath, updated);
113
+ return 'updated';
114
+ }
115
+ if (existing.includes('Magector')) {
116
+ // Legacy format without markers — append fresh section
117
+ appendFileSync(filePath, '\n\n' + markerStart + '\n' + content + markerEnd + '\n');
118
+ return 'updated';
119
+ }
120
+ appendFileSync(filePath, '\n\n' + markerStart + '\n' + content + markerEnd + '\n');
121
+ return 'appended';
122
+ }
123
+
124
+ const MARKER_START = '<!-- magector:start -->';
125
+ const MARKER_END = '<!-- magector:end -->';
126
+
98
127
  function writeRules(projectPath, ides) {
99
128
  const written = [];
100
129
 
@@ -103,34 +132,14 @@ function writeRules(projectPath, ides) {
103
132
 
104
133
  if (writeCursor) {
105
134
  const rulesPath = path.join(projectPath, '.cursorrules');
106
- if (!existsSync(rulesPath)) {
107
- writeFileSync(rulesPath, CURSORRULES);
108
- written.push('.cursorrules (created)');
109
- } else {
110
- const existing = readFileSync(rulesPath, 'utf-8');
111
- if (!existing.includes('Magector')) {
112
- appendFileSync(rulesPath, '\n\n' + CURSORRULES);
113
- written.push('.cursorrules (appended)');
114
- } else {
115
- written.push('.cursorrules (already configured)');
116
- }
117
- }
135
+ const result = upsertMagectorSection(rulesPath, CURSORRULES, MARKER_START, MARKER_END);
136
+ written.push(`.cursorrules (${result})`);
118
137
  }
119
138
 
120
139
  if (writeClaude) {
121
140
  const claudePath = path.join(projectPath, 'CLAUDE.md');
122
- if (!existsSync(claudePath)) {
123
- writeFileSync(claudePath, CLAUDE_MD);
124
- written.push('CLAUDE.md (created)');
125
- } else {
126
- const existing = readFileSync(claudePath, 'utf-8');
127
- if (!existing.includes('Magector')) {
128
- appendFileSync(claudePath, '\n\n' + CLAUDE_MD);
129
- written.push('CLAUDE.md (appended)');
130
- } else {
131
- written.push('CLAUDE.md (already configured)');
132
- }
133
- }
141
+ const result = upsertMagectorSection(claudePath, CLAUDE_MD, MARKER_START, MARKER_END);
142
+ written.push(`CLAUDE.md (${result})`);
134
143
  }
135
144
 
136
145
  return written;