nexscope 1.0.1 → 1.0.3
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/src/commands/install.js +24 -23
package/package.json
CHANGED
package/src/commands/install.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const { spawn } = require('child_process');
|
|
4
|
-
const https = require('https');
|
|
5
4
|
const { Listr } = require('listr2');
|
|
6
5
|
|
|
7
6
|
const SKILLS_REPO = 'nexscope-ai/eCommerce-Skills';
|
|
8
|
-
const REPO_API = 'https://api.github.com/repos/nexscope-ai/eCommerce-Skills/contents';
|
|
9
7
|
|
|
10
8
|
function printHelp() {
|
|
11
9
|
console.log(`
|
|
@@ -30,22 +28,16 @@ Examples:
|
|
|
30
28
|
`);
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
function get(url) {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
https.get(url, { headers: { 'User-Agent': 'nexscope-cli' } }, (res) => {
|
|
36
|
-
let data = '';
|
|
37
|
-
res.on('data', (chunk) => (data += chunk));
|
|
38
|
-
res.on('end', () => {
|
|
39
|
-
if (res.statusCode === 200) resolve(data);
|
|
40
|
-
else reject(new Error(`HTTP ${res.statusCode}: ${url}`));
|
|
41
|
-
});
|
|
42
|
-
}).on('error', reject);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
31
|
async function fetchSkillList() {
|
|
47
|
-
const
|
|
48
|
-
|
|
32
|
+
const output = await spawnAsync('npx', ['skills', 'add', SKILLS_REPO, '--list']);
|
|
33
|
+
// Strip ANSI escape codes and extract skill names from lines like "│ <skill-name>"
|
|
34
|
+
const clean = output.replace(/\x1B\[[0-9;?]*[a-zA-Z]/g, '');
|
|
35
|
+
const skills = [];
|
|
36
|
+
for (const line of clean.split('\n')) {
|
|
37
|
+
const match = line.match(/[│|]\s{4}([a-z][a-z0-9-]+)\s*$/);
|
|
38
|
+
if (match) skills.push(match[1]);
|
|
39
|
+
}
|
|
40
|
+
return skills;
|
|
49
41
|
}
|
|
50
42
|
|
|
51
43
|
function parseDirFlags(args) {
|
|
@@ -89,6 +81,10 @@ function runSkillsSync(skillsArgs) {
|
|
|
89
81
|
});
|
|
90
82
|
}
|
|
91
83
|
|
|
84
|
+
function runSkillsSilent(skillsArgs) {
|
|
85
|
+
return spawnAsync('npx', ['skills', ...skillsArgs]);
|
|
86
|
+
}
|
|
87
|
+
|
|
92
88
|
async function run(args) {
|
|
93
89
|
if (args.includes('--help') || args.includes('-h')) {
|
|
94
90
|
printHelp();
|
|
@@ -112,15 +108,20 @@ async function run(args) {
|
|
|
112
108
|
}
|
|
113
109
|
|
|
114
110
|
const installed = await getInstalledSkills(dirFlags);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
|
|
112
|
+
const tasks = new Listr([{
|
|
113
|
+
title: skillName,
|
|
114
|
+
skip: () => installed.includes(skillName) ? 'Already installed' : false,
|
|
115
|
+
task: () => runSkillsSilent(['add', SKILLS_REPO, '--skill', skillName, '-y', ...dirFlags]),
|
|
116
|
+
}], { exitOnError: false });
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
await tasks.run();
|
|
120
|
+
} catch {
|
|
121
|
+
// error already shown by listr2
|
|
119
122
|
}
|
|
120
123
|
|
|
121
|
-
const code = await runSkillsSync(['add', SKILLS_REPO, '--skill', skillName, '-y', ...dirFlags]);
|
|
122
124
|
printThankYou();
|
|
123
|
-
process.exit(code || 0);
|
|
124
125
|
} else {
|
|
125
126
|
process.stdout.write('Fetching skill list... ');
|
|
126
127
|
const [skills, installed] = await Promise.all([
|