@moneko/core 3.44.11-beta.0 → 3.44.11-beta.1
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/lib/commom/ca.d.mts +1 -0
- package/lib/commom/ca.mjs +1 -1
- package/lib/commom/host.d.mts +4 -0
- package/lib/commom/host.mjs +19 -0
- package/package.json +1 -1
package/lib/commom/ca.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ import { join, relative } from 'node:path';
|
|
|
3
3
|
import { platform } from 'node:process';
|
|
4
4
|
import { promisify } from 'node:util';
|
|
5
5
|
import { type CertificateResult, fileExists, generateCert, loadFile, normalCertificateAuthority, println, saveFile } from '@moneko/utils';
|
|
6
|
+
import { hostHelp } from './host.mjs';
|
|
6
7
|
import log from './log.mjs';
|
|
7
8
|
import paths from './paths.mjs';
|
|
8
9
|
type ExecPromise = (command: string) => PromiseWithChild<{
|
package/lib/commom/ca.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{exec as t}from"node:child_process";import{join as
|
|
1
|
+
import{exec as t}from"node:child_process";import{join as r,relative as e}from"node:path";import{platform as o}from"node:process";import{promisify as i}from"node:util";import{fileExists as a,generateCert as n,loadFile as s,normalCertificateAuthority as c,println as l,saveFile as m}from"@moneko/utils";import{hostHelp as u}from"./host.mjs";import f from"./log.mjs";import p from"./paths.mjs";let d=i(t);async function y(t){try{if("darwin"===o){let{stdout:r}=await d(`security find-certificate -c "${t}" -a`);return r.length>0}if("win32"===o){let{stdout:r}=await d(`certutil -store -user Root | findstr /C:"${t}"`);return r.length>0}}catch(t){f(t)}return!1}function h(t,r,e){if(t&&!e.includes("already exists")){f(t);return}}export function installCA(r){return"darwin"===o?t(`sudo security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" "${r}"`,h):"win32"===o?t(`certutil -addstore -user "Root" "${r}"`,h):void l(`⚠️ 暂不支持自动安装 CA 的平台: ${o}`)}export async function setupCert(t="localhost",o=!0){let i=e(p.programPath,`${p.corePath}/cert/cert.pem`),l=e(p.programPath,`${p.corePath}/cert/key.pem`),f=!a(i)||!a(l);if(f){let t=c();await Promise.all([m(i,t.cert),m(l,t.key)])}o&&(!await y("Local Root Certificate Authority - Moneko")||f)&&installCA(i);let d=r(p.CA_DIR,`${t}_cert.pem`),h=r(p.CA_DIR,`${t}_key.pem`);if(f||!a(d)||!a(h)){let r=await Promise.all([s(i),s(l)]),e=n(r[0],r[1],t);await Promise.all([m(d,e.cert),m(h,e.key)])}let w=await Promise.all([s(d),s(h)]);return u(t),{cert:w[0],key:w[1]}}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import{addHost as s,checkHost as t,getHostsPath as o,ink as e,println as l}from"@moneko/utils";import r from"./log.mjs";export function hostHelp(c){let i="127.0.0.1";if(t(i,c)||s(i,c),!t(i,c)){let s=`
|
|
2
|
+
${e("🚦 域名解析配置提醒","yellow",{bold:!0})}
|
|
3
|
+
|
|
4
|
+
检测到您正在使用本地域名:${e(c,"yellow")},但系统未找到对应的本地解析记录
|
|
5
|
+
|
|
6
|
+
📝 请按以下步骤操作:
|
|
7
|
+
|
|
8
|
+
1. 使用文本编辑器【以管理员身份】打开 hosts 文件:
|
|
9
|
+
|
|
10
|
+
${e("hosts 文件地址:","242")} ${e(o(),"208")}
|
|
11
|
+
|
|
12
|
+
2. 在文件末尾添加解析规则:
|
|
13
|
+
|
|
14
|
+
${e(i,"39")} ${e(c,"39")}
|
|
15
|
+
|
|
16
|
+
3. 保存文件后,建议刷新DNS缓存:
|
|
17
|
+
|
|
18
|
+
${e(function(){switch(process.platform){case"darwin":return"sudo dscacheutil -flushcache";case"win32":return"ipconfig /flushdns";default:return"sudo systemctl restart systemd-resolved"}}(),"208")}
|
|
19
|
+
`;l(s),r(s)}}
|