@ijuantm/simpl-addon 2.4.10 → 2.5.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 (3) hide show
  1. package/README.md +1 -0
  2. package/install.js +4 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -44,6 +44,7 @@ new AuthController();
44
44
 
45
45
  - `@addon-insert:after('text')` - Insert content after matching line
46
46
  - `@addon-insert:before('text')` - Insert content before matching line
47
+ - `@addon-insert:replace('text')` - Replace matching line with content
47
48
  - `@addon-insert:prepend` - Add content at the beginning of the file
48
49
  - `@addon-insert:append` - Add content at the end of the file
49
50
 
package/install.js CHANGED
@@ -184,12 +184,6 @@ const findInsertIndex = (lines, searchText, type) => {
184
184
  return -1;
185
185
  };
186
186
 
187
- const findMarkerLine = (lines, markerName) => {
188
- const markerPattern = new RegExp(`@addon-marker\\s*\\(\\s*["']${markerName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}["']\\s*\\)`);
189
- for (let i = 0; i < lines.length; i++) if (markerPattern.test(lines[i])) return i;
190
- return -1;
191
- };
192
-
193
187
  const mergeFile = (targetPath, addonContent, markers, isEnv = false) => {
194
188
  const targetContent = fs.readFileSync(targetPath, 'utf8');
195
189
  const addonLines = addonContent.split('\n');
@@ -230,14 +224,14 @@ const mergeFile = (targetPath, addonContent, markers, isEnv = false) => {
230
224
  operations.push({success: true, type: 'append', lines: lineCount});
231
225
  } else if (marker.type === 'replace' && marker.markerName) {
232
226
  const targetLines = newContent.split('\n');
233
- const markerLine = findMarkerLine(targetLines, marker.markerName);
227
+ const replaceIndex = findInsertIndex(targetLines, marker.markerName, 'before');
234
228
 
235
- if (markerLine === -1) {
236
- operations.push({success: false, type: 'notfound', markerName: marker.markerName});
229
+ if (replaceIndex === -1) {
230
+ operations.push({success: false, type: 'notfound', searchText: marker.markerName});
237
231
  return;
238
232
  }
239
233
 
240
- targetLines.splice(markerLine, 1, ...content);
234
+ targetLines.splice(replaceIndex, 1, ...content);
241
235
  newContent = targetLines.join('\n');
242
236
  operations.push({success: true, type: 'replace', lines: lineCount, markerName: marker.markerName});
243
237
  } else if ((marker.type === 'after' || marker.type === 'before') && marker.searchText) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ijuantm/simpl-addon",
3
3
  "description": "CLI tool to install Simpl framework add-ons.",
4
- "version": "2.4.10",
4
+ "version": "2.5.0",
5
5
  "scripts": {
6
6
  "link": "npm link",
7
7
  "unlink": "npm unlink -g @ijuantm/simpl-addon"