feat: 增加 cert:generate 和 arduino:install 脚本
This commit is contained in:
32
scripts/cert-generate.js
Normal file
32
scripts/cert-generate.js
Normal 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();
|
||||
Reference in New Issue
Block a user