feat: 增加 cert:generatearduino:install 脚本

This commit is contained in:
王立帮
2025-05-08 23:18:05 +08:00
parent a7bc967378
commit c79fcd89dc
31 changed files with 1270 additions and 194 deletions

32
scripts/cert-generate.js Normal file
View File

@@ -0,0 +1,32 @@
import os from 'node:os';
import path from 'node:path';
import shell from 'shelljs';
import fsExtra from 'fs-extra';
export function getDefaultHosts() {
const interfaceDict = os.networkInterfaces();
const addresses = [];
for (const key in interfaceDict) {
const interfaces = interfaceDict[key];
if (interfaces) {
for (const item of interfaces) {
const family = item.family;
if (family === 'IPv4') {
addresses.push(item.address);
}
}
}
}
return ['localhost', ...addresses];
}
export function generateCertificate() {
const certPath = path.resolve(process.cwd(), 'certs');
fsExtra.ensureDirSync(certPath);
shell.cd(certPath);
shell.exec(`mkcert -key-file server.key -cert-file server.crt ${getDefaultHosts().join(' ')}`);
console.log('new certificate generated successfully!');
}
generateCertificate();