-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlive.js
More file actions
47 lines (38 loc) · 1.24 KB
/
live.js
File metadata and controls
47 lines (38 loc) · 1.24 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
const readline = require('readline');
const { execSync } = require('child_process');
const html = process.env.npm_package_config_html || 'index.html';
const options = [
{ key: '1', alias: 'F', name: 'Firefox', browser: 'firefox' },
{ key: '2', alias: 'C', name: 'Chrome', browser: 'chrome' },
{ key: '3', alias: 'E', name: 'Edge', browser: 'msedge' }
];
function printMenu() {
console.log('\nSelecciona un navegador:\n');
options.forEach(opt => {
console.log(` [${opt.key}] ${opt.name} (${opt.alias})`);
});
console.log(' [Enter] por defecto: Edge');
}
function run(browser) {
console.log(`\n🚀 Abriendo "${html}" con live-server en ${browser}...\n`);
execSync(`live-server ${html} --browser=${browser}`, { stdio: 'inherit' });
}
function getBrowserFromKey(key) {
const match = options.find(opt =>
opt.key === key || opt.alias.toLowerCase() === key.toLowerCase()
);
return match?.browser || 'msedge';
}
printMenu();
readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);
process.stdin.on('keypress', (str, key) => {
process.stdin.setRawMode(false);
process.stdin.pause();
if (key.name === 'return') {
run('msedge');
} else {
const browser = getBrowserFromKey(str);
run(browser);
}
});