-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.js
More file actions
executable file
·263 lines (239 loc) · 9.74 KB
/
Copy pathinstall.js
File metadata and controls
executable file
·263 lines (239 loc) · 9.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/usr/bin/env node
/**
* html-effectiveness installer
*
* Usage:
* npx html-effectiveness # interactive: pick targets
* npx html-effectiveness --cursor # install to ~/.cursor/skills/
* npx html-effectiveness --claude # install to ~/.claude/skills/
* npx html-effectiveness --all # install to both
* npx html-effectiveness --project . # install to ./.cursor/skills/ + ./.claude/skills/
* npx html-effectiveness --dry-run # show what would happen, no writes
* npx html-effectiveness --uninstall # remove from all known locations
*
* What it copies:
* <package>/skills/ → <target>/html-effectiveness/
* <package>/templates/ → <target>/html-effectiveness/templates/
*
* The skills/ folder is the actual Skill (with SKILL.md as router),
* templates/ is bundled alongside so SKILL.md's relative ../templates/* refs work.
*/
const fs = require('fs');
const path = require('path');
const os = require('os');
const readline = require('readline');
const PKG_ROOT = __dirname;
const SKILL_NAME = 'html-effectiveness';
const VERSION = require('./package.json').version;
const COLORS = {
reset: '\x1b[0m',
dim: '\x1b[2m',
bold: '\x1b[1m',
cyan: '\x1b[36m',
green: '\x1b[32m',
yellow: '\x1b[33m',
red: '\x1b[31m',
gray: '\x1b[90m',
};
const c = (color, s) => process.stdout.isTTY ? `${COLORS[color]}${s}${COLORS.reset}` : s;
function parseArgs(argv) {
const args = { targets: [], dryRun: false, uninstall: false, project: null, force: false, help: false };
for (let i = 2; i < argv.length; i++) {
const a = argv[i];
if (a === '--cursor') args.targets.push('cursor');
else if (a === '--claude') args.targets.push('claude');
else if (a === '--all') args.targets.push('cursor', 'claude');
else if (a === '--project') { args.project = argv[++i] || '.'; }
else if (a === '--dry-run' || a === '-n') args.dryRun = true;
else if (a === '--uninstall') args.uninstall = true;
else if (a === '--force' || a === '-f') args.force = true;
else if (a === '--help' || a === '-h') args.help = true;
else if (a === '--version' || a === '-v') { console.log(VERSION); process.exit(0); }
else { console.error(c('red', `Unknown flag: ${a}`)); process.exit(1); }
}
return args;
}
function showHelp() {
console.log(`
${c('bold', 'html-effectiveness')} v${VERSION}
Agent Skill installer for Cursor & Claude Code.
${c('bold', 'Usage:')}
npx html-effectiveness [options]
${c('bold', 'Options:')}
${c('cyan', '--cursor')} Install to ~/.cursor/skills/${SKILL_NAME}/
${c('cyan', '--claude')} Install to ~/.claude/skills/${SKILL_NAME}/
${c('cyan', '--all')} Install to both Cursor and Claude
${c('cyan', '--project <dir>')} Install to <dir>/.cursor/skills/ and <dir>/.claude/skills/
${c('cyan', '--uninstall')} Remove from all known locations
${c('cyan', '--force, -f')} Overwrite existing installation without asking
${c('cyan', '--dry-run, -n')} Show what would happen, no writes
${c('cyan', '--version, -v')} Print version
${c('cyan', '--help, -h')} Show this help
${c('bold', 'Examples:')}
npx html-effectiveness --all
npx html-effectiveness --project .
npx html-effectiveness --uninstall
`);
}
function expandHome(p) {
if (!p) return p;
if (p.startsWith('~/')) return path.join(os.homedir(), p.slice(2));
return p;
}
function getTargetDirs(args) {
const targets = [];
if (args.project) {
const root = path.resolve(args.project);
targets.push({ kind: 'cursor (project)', dir: path.join(root, '.cursor', 'skills', SKILL_NAME) });
targets.push({ kind: 'claude (project)', dir: path.join(root, '.claude', 'skills', SKILL_NAME) });
}
if (args.targets.includes('cursor')) {
targets.push({ kind: 'cursor (user)', dir: path.join(os.homedir(), '.cursor', 'skills', SKILL_NAME) });
}
if (args.targets.includes('claude')) {
targets.push({ kind: 'claude (user)', dir: path.join(os.homedir(), '.claude', 'skills', SKILL_NAME) });
}
return targets;
}
function ask(question) {
return new Promise(resolve => {
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
rl.question(question, answer => { rl.close(); resolve(answer.trim()); });
});
}
async function pickTargetsInteractive() {
console.log(c('bold', `\nhtml-effectiveness v${VERSION}`));
console.log(c('gray', 'Where do you want to install?\n'));
console.log(` ${c('cyan', '1')}. Cursor only ${c('gray', '(~/.cursor/skills/)')}`);
console.log(` ${c('cyan', '2')}. Claude Code only ${c('gray', '(~/.claude/skills/)')}`);
console.log(` ${c('cyan', '3')}. Both (recommended)`);
console.log(` ${c('cyan', '4')}. This project ${c('gray', '(./.cursor + ./.claude)')}`);
console.log(` ${c('cyan', 'q')}. Quit\n`);
const ans = (await ask(c('cyan', '> '))).toLowerCase();
const args = { targets: [], project: null };
if (ans === '1') args.targets = ['cursor'];
else if (ans === '2') args.targets = ['claude'];
else if (ans === '3' || ans === '') args.targets = ['cursor', 'claude'];
else if (ans === '4') args.project = '.';
else { console.log('Cancelled.'); process.exit(0); }
return args;
}
function countFiles(dir) {
let n = 0;
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
if (e.isDirectory()) n += countFiles(path.join(dir, e.name));
else if (e.isFile()) n++;
}
return n;
}
function copyDir(src, dest) {
fs.cpSync(src, dest, { recursive: true, force: true, errorOnExist: false });
}
function checkNode() {
const required = [16, 7, 0];
const current = process.versions.node.split('.').map(Number);
for (let i = 0; i < required.length; i++) {
if (current[i] > required[i]) return;
if (current[i] < required[i]) {
console.error(c('red',
`Node ${process.versions.node} is too old. html-effectiveness requires Node >= 16.7.0 ` +
`(uses fs.cpSync). Please upgrade.`));
process.exit(1);
}
}
}
function rimrafSync(dir) {
if (!fs.existsSync(dir)) return false;
fs.rmSync(dir, { recursive: true, force: true });
return true;
}
async function install(args) {
const targets = getTargetDirs(args);
if (targets.length === 0) { console.error(c('red', 'No targets specified.')); process.exit(1); }
console.log(c('bold', `\nInstalling html-effectiveness v${VERSION}\n`));
const skillsSrc = path.join(PKG_ROOT, 'skills');
const templatesSrc = path.join(PKG_ROOT, 'templates');
if (!fs.existsSync(skillsSrc)) {
console.error(c('red', `Source missing: ${skillsSrc}`));
process.exit(1);
}
for (const t of targets) {
console.log(`${c('cyan', '→')} ${t.kind}: ${c('gray', t.dir)}`);
if (fs.existsSync(t.dir)) {
if (args.force) {
console.log(` ${c('yellow', 'overwrite')} (--force)`);
if (!args.dryRun) rimrafSync(t.dir);
} else if (!args.dryRun) {
const ans = await ask(` ${c('yellow', 'exists, overwrite?')} [y/N] `);
if (ans.toLowerCase() !== 'y') { console.log(` ${c('gray', 'skipped')}\n`); continue; }
rimrafSync(t.dir);
}
}
if (args.dryRun) {
const skillsCount = countFiles(skillsSrc);
const tplCount = fs.existsSync(templatesSrc) ? countFiles(templatesSrc) : 0;
console.log(` ${c('gray', '[dry-run] would copy:')}`);
console.log(` ${c('gray', ' ' + skillsSrc + '/ → ' + t.dir + '/')} (${skillsCount} files)`);
if (tplCount) {
console.log(` ${c('gray', ' ' + templatesSrc + '/ → ' + path.join(t.dir, 'templates') + '/')} (${tplCount} files)`);
}
} else {
copyDir(skillsSrc, t.dir);
let total = countFiles(t.dir);
if (fs.existsSync(templatesSrc)) {
copyDir(templatesSrc, path.join(t.dir, 'templates'));
total = countFiles(t.dir);
}
console.log(` ${c('green', '✓')} ${total} files`);
}
console.log('');
}
if (!args.dryRun) {
console.log(c('green', 'Done.\n'));
console.log(c('gray', 'Restart your agent (Cursor / Claude Code) to pick up the new skill.'));
console.log(c('gray', 'The skill auto-activates when output is spatial / parallel / interactive.\n'));
} else {
console.log(c('yellow', 'Dry run complete. No files written.\n'));
}
}
async function uninstall(args) {
console.log(c('bold', `\nUninstalling html-effectiveness\n`));
const candidates = [
{ kind: 'cursor (user)', dir: path.join(os.homedir(), '.cursor', 'skills', SKILL_NAME) },
{ kind: 'claude (user)', dir: path.join(os.homedir(), '.claude', 'skills', SKILL_NAME) },
];
if (args.project) {
const root = path.resolve(args.project);
candidates.push({ kind: 'cursor (project)', dir: path.join(root, '.cursor', 'skills', SKILL_NAME) });
candidates.push({ kind: 'claude (project)', dir: path.join(root, '.claude', 'skills', SKILL_NAME) });
}
let removed = 0;
for (const t of candidates) {
if (!fs.existsSync(t.dir)) {
console.log(`${c('gray', '·')} ${t.kind}: not installed`);
continue;
}
console.log(`${c('cyan', '→')} ${t.kind}: ${c('gray', t.dir)}`);
if (args.dryRun) {
console.log(` ${c('gray', '[dry-run] would remove')}`);
} else {
rimrafSync(t.dir);
console.log(` ${c('green', '✓ removed')}`);
removed++;
}
}
console.log('');
if (!args.dryRun) console.log(c('green', `Removed ${removed} installation(s).\n`));
}
async function main() {
checkNode();
const args = parseArgs(process.argv);
if (args.help) { showHelp(); return; }
if (args.uninstall) { await uninstall(args); return; }
if (args.targets.length === 0 && !args.project) {
const picked = await pickTargetsInteractive();
Object.assign(args, picked);
}
await install(args);
}
main().catch(err => { console.error(c('red', err.stack || err.message)); process.exit(1); });