@ijuantm/simpl-addon 2.4.3 → 2.4.5
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/install.js +47 -40
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -89,14 +89,12 @@ const showHelp = () => {
|
|
|
89
89
|
console.log();
|
|
90
90
|
log(` ${COLORS.bold}Usage:${COLORS.reset}`, 'blue');
|
|
91
91
|
log(` ${COLORS.dim}npx @ijuantm/simpl-addon${COLORS.reset}`);
|
|
92
|
+
log(` ${COLORS.dim}npx @ijuantm/simpl-addon <add-on>${COLORS.reset}`);
|
|
92
93
|
log(` ${COLORS.dim}npx @ijuantm/simpl-addon --help${COLORS.reset}`);
|
|
93
94
|
console.log();
|
|
94
95
|
log(` ${COLORS.bold}Commands:${COLORS.reset}`, 'blue');
|
|
95
96
|
log(` ${COLORS.dim}--help, -h${COLORS.reset} Show this help message`);
|
|
96
97
|
console.log();
|
|
97
|
-
log(` ${COLORS.bold}Examples:${COLORS.reset}`, 'blue');
|
|
98
|
-
log(` ${COLORS.dim}npx @ijuantm/simpl-addon${COLORS.reset}`);
|
|
99
|
-
console.log();
|
|
100
98
|
log(` ${COLORS.bold}Note:${COLORS.reset}`, 'blue');
|
|
101
99
|
log(` Run this command from the root of your Simpl project.`);
|
|
102
100
|
log(` The add-on version will match your Simpl framework version.`);
|
|
@@ -136,13 +134,13 @@ const extractMarkers = (content) => {
|
|
|
136
134
|
const markers = [];
|
|
137
135
|
|
|
138
136
|
content.split('\n').forEach((line, i) => {
|
|
139
|
-
const afterMatch = line.match(/@addon-insert:after\s*\(\s*["'](.+?)
|
|
140
|
-
const beforeMatch = line.match(/@addon-insert:before\s*\(\s*["'](.+?)
|
|
141
|
-
const replaceMatch = line.match(/@addon-insert:replace\s*\(\s*["'](.+?)
|
|
137
|
+
const afterMatch = line.match(/@addon-insert:after\s*\(\s*(["'])(.+?)\1\s*\)/);
|
|
138
|
+
const beforeMatch = line.match(/@addon-insert:before\s*\(\s*(["'])(.+?)\1\s*\)/);
|
|
139
|
+
const replaceMatch = line.match(/@addon-insert:replace\s*\(\s*(["'])(.+?)\1\s*\)/);
|
|
142
140
|
|
|
143
|
-
if (afterMatch) markers.push({type: 'after', lineIndex: i, searchText: afterMatch[
|
|
144
|
-
else if (beforeMatch) markers.push({type: 'before', lineIndex: i, searchText: beforeMatch[
|
|
145
|
-
else if (replaceMatch) markers.push({type: 'replace', lineIndex: i, markerName: replaceMatch[
|
|
141
|
+
if (afterMatch) markers.push({type: 'after', lineIndex: i, searchText: afterMatch[2]});
|
|
142
|
+
else if (beforeMatch) markers.push({type: 'before', lineIndex: i, searchText: beforeMatch[2]});
|
|
143
|
+
else if (replaceMatch) markers.push({type: 'replace', lineIndex: i, markerName: replaceMatch[2]});
|
|
146
144
|
else if (line.includes('@addon-insert:prepend')) markers.push({type: 'prepend', lineIndex: i});
|
|
147
145
|
else if (line.includes('@addon-insert:append')) markers.push({type: 'append', lineIndex: i});
|
|
148
146
|
});
|
|
@@ -262,11 +260,6 @@ const mergeFile = (targetPath, addonContent, markers, isEnv = false) => {
|
|
|
262
260
|
return {modified: newContent !== targetContent, operations};
|
|
263
261
|
};
|
|
264
262
|
|
|
265
|
-
const truncateText = (text, maxLength = 80) => {
|
|
266
|
-
if (text.length <= maxLength) return text;
|
|
267
|
-
return text.substring(0, maxLength - 3) + '...';
|
|
268
|
-
};
|
|
269
|
-
|
|
270
263
|
const printMergeResults = (relativePath, isEnv, result) => {
|
|
271
264
|
const indent = ' ';
|
|
272
265
|
const varText = isEnv ? 'environment variable' : 'line';
|
|
@@ -278,10 +271,10 @@ const printMergeResults = (relativePath, isEnv, result) => {
|
|
|
278
271
|
if (op.type === 'prepend') log(`${indent}${COLORS.green}✓${COLORS.reset} Prepended ${COLORS.bold}${op.lines}${COLORS.reset} ${varText}${op.lines !== 1 ? 's' : ''} to file start`);
|
|
279
272
|
else if (op.type === 'append') log(`${indent}${COLORS.green}✓${COLORS.reset} Appended ${COLORS.bold}${op.lines}${COLORS.reset} ${varText}${op.lines !== 1 ? 's' : ''} to file end`);
|
|
280
273
|
else if (op.type === 'replace') log(`${indent}${COLORS.green}✓${COLORS.reset} Replaced marker ${COLORS.cyan}${op.markerName}${COLORS.reset} with ${COLORS.bold}${op.lines}${COLORS.reset} ${varText}${op.lines !== 1 ? 's' : ''}`);
|
|
281
|
-
else if (op.type === 'after') log(`${indent}${COLORS.green}✓${COLORS.reset} Inserted ${COLORS.bold}${op.lines}${COLORS.reset} ${varText}${op.lines !== 1 ? 's' : ''} ${COLORS.cyan}after${COLORS.reset} ${COLORS.dim}${
|
|
282
|
-
else if (op.type === 'before') log(`${indent}${COLORS.green}✓${COLORS.reset} Inserted ${COLORS.bold}${op.lines}${COLORS.reset} ${varText}${op.lines !== 1 ? 's' : ''} ${COLORS.cyan}before${COLORS.reset} ${COLORS.dim}${
|
|
274
|
+
else if (op.type === 'after') log(`${indent}${COLORS.green}✓${COLORS.reset} Inserted ${COLORS.bold}${op.lines}${COLORS.reset} ${varText}${op.lines !== 1 ? 's' : ''} ${COLORS.cyan}after${COLORS.reset} ${COLORS.dim}${op.searchText}${COLORS.reset}`);
|
|
275
|
+
else if (op.type === 'before') log(`${indent}${COLORS.green}✓${COLORS.reset} Inserted ${COLORS.bold}${op.lines}${COLORS.reset} ${varText}${op.lines !== 1 ? 's' : ''} ${COLORS.cyan}before${COLORS.reset} ${COLORS.dim}${op.searchText}${COLORS.reset}`);
|
|
283
276
|
} else if (op.type === 'notfound') {
|
|
284
|
-
const target = op.markerName ? `marker ${COLORS.dim}${op.markerName}${COLORS.reset}` : `${COLORS.dim}${
|
|
277
|
+
const target = op.markerName ? `marker ${COLORS.dim}${op.markerName}${COLORS.reset}` : `${COLORS.dim}${op.searchText}${COLORS.reset}`;
|
|
285
278
|
log(`${indent}${COLORS.yellow}⚠${COLORS.reset} ${COLORS.yellow}Could not find target:${COLORS.reset} ${target}`);
|
|
286
279
|
} else log(`${indent}${COLORS.gray}○${COLORS.reset} ${COLORS.dim}Content already exists (${op.type})${COLORS.reset}`);
|
|
287
280
|
});
|
|
@@ -398,6 +391,8 @@ const main = async () => {
|
|
|
398
391
|
process.exit(0);
|
|
399
392
|
}
|
|
400
393
|
|
|
394
|
+
const directName = firstArg && !firstArg.startsWith('-') ? firstArg : null;
|
|
395
|
+
|
|
401
396
|
let version;
|
|
402
397
|
|
|
403
398
|
try {
|
|
@@ -457,7 +452,7 @@ const main = async () => {
|
|
|
457
452
|
process.exit(1);
|
|
458
453
|
}
|
|
459
454
|
|
|
460
|
-
log('
|
|
455
|
+
log(' 🧰 Fetching available add-ons...', 'bold');
|
|
461
456
|
|
|
462
457
|
let addons;
|
|
463
458
|
|
|
@@ -479,34 +474,46 @@ const main = async () => {
|
|
|
479
474
|
process.exit(0);
|
|
480
475
|
}
|
|
481
476
|
|
|
482
|
-
log(` ${COLORS.bold}Available add-ons:${COLORS.reset}`, 'blue');
|
|
483
|
-
addons.forEach((name, index) => log(` ${COLORS.cyan}${index + 1}.${COLORS.reset} ${name}`));
|
|
484
|
-
console.log();
|
|
485
|
-
|
|
486
477
|
let addonName;
|
|
487
478
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
if (!input) {
|
|
492
|
-
log(` ${COLORS.red}✗${COLORS.reset} Selection cannot be empty`, 'red');
|
|
479
|
+
if (directName) {
|
|
480
|
+
if (!addons.includes(directName)) {
|
|
481
|
+
log(` ${COLORS.red}✗${COLORS.reset} Add-on ${COLORS.bold}${directName}${COLORS.reset} not found`, 'red');
|
|
493
482
|
console.log();
|
|
494
|
-
|
|
483
|
+
log(` ${COLORS.bold}Available add-ons:${COLORS.reset}`, 'blue');
|
|
484
|
+
addons.forEach((name, index) => log(` ${COLORS.cyan}${index + 1}.${COLORS.reset} ${name}`));
|
|
485
|
+
console.log();
|
|
486
|
+
process.exit(1);
|
|
495
487
|
}
|
|
488
|
+
addonName = directName;
|
|
489
|
+
} else {
|
|
490
|
+
log(` ${COLORS.bold}Available add-ons:${COLORS.reset}`, 'blue');
|
|
491
|
+
addons.forEach((name, index) => log(` ${COLORS.cyan}${index + 1}.${COLORS.reset} ${name}`));
|
|
492
|
+
console.log();
|
|
496
493
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
addonName = addons[numInput - 1];
|
|
500
|
-
break;
|
|
501
|
-
}
|
|
494
|
+
while (true) {
|
|
495
|
+
const input = await promptUser(` Add-on to install ${COLORS.dim}(name or number)${COLORS.reset}`);
|
|
502
496
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
497
|
+
if (!input) {
|
|
498
|
+
log(` ${COLORS.red}✗${COLORS.reset} Selection cannot be empty`, 'red');
|
|
499
|
+
console.log();
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
507
502
|
|
|
508
|
-
|
|
509
|
-
|
|
503
|
+
const numInput = parseInt(input, 10);
|
|
504
|
+
if (!isNaN(numInput) && numInput >= 1 && numInput <= addons.length) {
|
|
505
|
+
addonName = addons[numInput - 1];
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
if (addons.includes(input)) {
|
|
510
|
+
addonName = input;
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
log(` ${COLORS.red}✗${COLORS.reset} Invalid selection "${input}"`, 'red');
|
|
515
|
+
console.log();
|
|
516
|
+
}
|
|
510
517
|
}
|
|
511
518
|
|
|
512
519
|
console.log();
|
|
@@ -514,7 +521,7 @@ const main = async () => {
|
|
|
514
521
|
log(` │ ${COLORS.bold}Installing: ${COLORS.cyan}${addonName}${COLORS.reset} ${COLORS.dim}(v${version})${COLORS.reset}${' '.repeat(44 - addonName.length - version.length)}│`);
|
|
515
522
|
log(` ╰${'─'.repeat(62)}╯`);
|
|
516
523
|
console.log();
|
|
517
|
-
log(
|
|
524
|
+
log(` 📦 Downloading ${COLORS.cyan}${addonName}${COLORS.reset} add-on...`, 'bold');
|
|
518
525
|
|
|
519
526
|
let copied, skipped, toMerge;
|
|
520
527
|
|