@deveco-test/deveco-cli 1.3.0-Test.7 → 1.3.0-Test.9

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.
@@ -1,5 +1,5 @@
1
- import*as h from"fs";import*as T from"path";import Pi from"adm-zip";import Oi from"proper-lockfile";import Li from"ora";import*as w from"fs";import*as at from"path";var Bt=["harmonyos-guides","harmonyos-references","best-practices","harmonyos-faqs","harmonyos-releases","harmonyos-roadmap"],dt={"harmonyos-guides":"\u5F00\u53D1\u6307\u5357","harmonyos-references":"API\u53C2\u8003","best-practices":"\u6700\u4F73\u5B9E\u8DF5","harmonyos-faqs":"FAQ","harmonyos-releases":"\u7248\u672C\u8BF4\u660E","harmonyos-roadmap":"\u53D8\u66F4\u9884\u544A"};var H="1.9.1",Qi=48*1024*1024,Ae=280,we=6,De=100,Ie=3,Te=28,Mt=10,Ce=/API参考|APIReference/i;var Re=6,mt=700,kt=250,vt=400,Ne=1320,Pe=120,Oe=450,Le=250,Be=500,Me=480,ke=80,ve=200,Fe=60,ze=200,He=40,je=200,Ue=200,Ze=40,j=500,$e=Object.fromEntries(Bt.map((t,e)=>[dt[t],e])),O=Object.fromEntries(Bt.map((t,e)=>[t,e]));import*as K from"fs";import*as m from"path";import{fileURLToPath as Ye}from"url";import*as L from"fs";import*as Qe from"path";import{homedir as Sr}from"os";import*as Ge from"fs";import*as E from"path";function Y(t,e){let n=E.relative(e,t);return n===""||!E.isAbsolute(n)&&!n.startsWith(`..${E.sep}`)&&n!==".."}function U(t){let e=E.resolve(t),n=[],r=e;for(;;)try{let o=Ge.realpathSync(r);return n.length===0?o:E.join(o,...n.reverse())}catch(o){if(o.code!=="ENOENT")throw o;let i=E.dirname(r);if(i===r)return e;n.push(E.basename(r)),r=i}}function Xe(t,e){let n=U(e),r=U(t);return Y(r,n)?r:null}function Ft(t){let e=t.trim();return(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))&&(e=e.slice(1,-1).trim()),e}function We(t){let e=Ft(t);if(!e)throw new Error("Path must not be empty.");return U(e)}var yr="deveco-cli",zt,k=class extends Error{constructor(e){super(e),this.name="CliDataDirError"}};function qe(){let t=process.env.DEVECO_CLI_DATA_DIR,n=(t===void 0||t===""?"":Ft(t))||Qe.join(Sr(),".local","share",yr);try{return We(n)}catch(r){throw new k(r instanceof Error?r.message:String(r))}}async function Je(){let t=qe();await L.promises.mkdir(t,{recursive:!0});let e;try{e=await L.promises.realpath(t)}catch(r){throw new k(`DEVECO_CLI_DATA_DIR is not usable: ${r instanceof Error?r.message:String(r)}`)}if(!(await L.promises.stat(e)).isDirectory())throw new k("DEVECO_CLI_DATA_DIR must be a writable directory.");return zt=e,e}function V(){if(zt!==void 0)return zt;let t=qe();try{if(L.existsSync(t))return L.realpathSync(t)}catch{}return t}var xr="docs";function Z(){return m.join(V(),xr)}function g(){return m.join(Z(),".index")}function ft(){return m.join(g(),"build.lock")}function tt(){return m.join(g(),"build-status.json")}function $(){return m.join(g(),"build-meta.json")}function G(){return m.join(g(),"search.db")}function et(){return m.join(g(),"sqlite-backend.json")}function nt(){return m.join(g(),"jieba-backend.json")}function C(){return m.join(g(),".tmp")}function Er(){return m.join(V(),"logs")}function Ht(){return m.join(Er(),"doc-init.log")}function _r(t,e){let n=e;for(;!n.endsWith(`${m.sep}dist`)&&n!==m.dirname(n);)n=m.dirname(n);return n}function Ve(t,e){return m.dirname(_r(t,e))}function Ke(){let t=Ye(import.meta.url),e=m.dirname(t);return t.includes(`${m.sep}dist${m.sep}`)?Ve(t,e):m.join(e,"..","..","..")}function br(...t){let e=Ye(import.meta.url),n=m.dirname(e);return e.includes(`${m.sep}dist${m.sep}`)?[m.join(Ve(e,n),...t)]:[m.join(n,"..","..","..",...t)]}function tn(...t){let e=Ke(),n=K.realpathSync(e);for(let r of br(...t))try{let o=K.lstatSync(r);if(o.isSymbolicLink()||!o.isFile())throw new Error(`Unsafe documentation package asset: ${t.join("/")} must be a regular file.`);let i=K.realpathSync(r);if(!Y(i,n))throw new Error(`Unsafe documentation package asset: ${t.join("/")} is outside the package.`);return i}catch(o){if(o.code!=="ENOENT")throw o}return null}function v(){return tn("docs.zip")}function jt(){return tn("index.zip")}function en(){return m.join(Ke(),"index","data")}import*as R from"fs";import*as F from"path";var N=["harmonyos-terms.txt","harmonyos-synonyms.json","harmonyos-stopwords.txt"],Ut=class extends Error{constructor(e){super(e),this.name="LexiconNotFoundError"}};var Zt=null;function $t(t){Zt=t}function nn(){if(Zt)return Zt;let t=g();if(N.every(o=>R.existsSync(F.join(t,o))))return t;let n=en();if(N.every(o=>R.existsSync(F.join(n,o))))return n;throw new Ut("Lexicon files not found. Install the documentation index first (index.zip).")}function rt(t){let e=F.join(nn(),t);return R.readFileSync(e,"utf-8")}function rn(t,e){return R.readFileSync(F.join(e,t),"utf-8")}async function on(t,e=nn()){await R.promises.mkdir(t,{recursive:!0});for(let n of N){let r=F.join(e,n),o=F.join(t,n);await R.promises.copyFile(r,o)}}import*as Gt from"fs";import*as Ar from"yauzl";function Xt(){let t=v();return t!==null&&Gt.existsSync(t)}import*as y from"fs";import*as P from"path";import sn from"adm-zip";import*as ot from"fs";import*as gt from"path";var pt=class extends Error{constructor(e){super(`Unsafe documentation path: ${e}`),this.name="DocPathSafetyError"}};function qt(t){return t instanceof k||t instanceof pt||t instanceof Error&&(t.name==="CliDataDirError"||t.name==="DocPathSafetyError")}function Jt(t){return new pt(t)}function wr(){return U(V())}function Qt(t,e,n){let r=Xe(t,e);if(r===null)throw Jt(`${n} resolves outside the data directory.`);return r}async function Wt(t,e){await ot.promises.mkdir(t,{recursive:!0});let n=Qt(t,e,"directory");if(!(await ot.promises.stat(n)).isDirectory())throw Jt("path must be a directory.")}function it(t){let e=wr();try{let n=Qt(t,e,"file");if(!ot.statSync(n).isFile())throw Jt("path must be a regular file.")}catch(n){if(n.code==="ENOENT"){Qt(gt.dirname(t),e,"file parent");return}throw n}}async function st(t={}){let e=t.mode??"write",n=await Je();await Wt(Z(),n),await Wt(g(),n),e==="write"&&await Wt(C(),n);for(let r of[G(),$(),tt(),ft(),nt(),et(),...N.map(o=>gt.join(g(),o))])it(r)}var Yt=["search.db","build-meta.json",...N],Dr=["corpus.json","corpus-offsets.json","orama.dpack"];async function Ir(t){for(let e of Dr)await y.promises.rm(P.join(t,e),{force:!0})}async function Tr(t){let e=await y.promises.readdir(t,{withFileTypes:!0});for(let n of e)n.name!==".index"&&await y.promises.rm(P.join(t,n.name),{recursive:!0,force:!0})}function an(t){let n=new sn(t).getEntry("build-meta.json");if(!n)throw new Error("index.zip is missing build-meta.json");return JSON.parse(n.getData().toString("utf-8"))}async function Cr(t){let e=g();await y.promises.mkdir(e,{recursive:!0});for(let n of Yt){let r=P.join(e,n);await y.promises.rm(r,{force:!0}),await y.promises.rename(P.join(t,n),r)}await Ir(e),await y.promises.rm(C(),{recursive:!0,force:!0})}function cn(t){let e=jt();if(!e)return!1;try{let n=an(e);return n.indexVersion===H&&n.docsZipSha256===t&&n.segmentCount>0}catch{return!1}}async function un(t){await st({mode:"write"});let e=jt();if(!e)throw new Error("index.zip not found");let n=an(e);if(n.docsZipSha256!==t)throw new Error("Bundled index.zip does not match docs.zip. Rebuild index.zip with npm run build:index.");if(n.segmentCount<=0)throw new Error("Bundled index.zip is empty");let r=C();await y.promises.rm(r,{recursive:!0,force:!0}),await y.promises.mkdir(r,{recursive:!0});let o=new sn(e);for(let s of Yt){let a=o.getEntry(s);if(!a)throw new Error(`index.zip is missing ${s}`);await y.promises.writeFile(P.join(r,s),a.getData())}let i=JSON.parse(await y.promises.readFile(P.join(r,"build-meta.json"),"utf-8"));if(!y.existsSync(P.join(r,"search.db")))throw new Error("index.zip is missing search.db");return await Cr(r),await y.promises.mkdir(Z(),{recursive:!0}),await Tr(Z()),i}async function ln(){await y.promises.rm(C(),{recursive:!0,force:!0});let t=g();for(let e of Yt)await y.promises.rm(P.join(t,e),{force:!0})}import{createHash as dn}from"crypto";import*as mn from"fs";async function ht(t){return new Promise((e,n)=>{let r=dn("sha256"),o=mn.createReadStream(t);o.on("data",i=>r.update(i)),o.on("error",n),o.on("end",()=>e(r.digest("hex")))})}function fn(t){return dn("sha256").update(t,"utf8").digest("hex")}function pn(t,e){let n=e?rn(t,e):rt(t);return fn(n)}function St(t){return pn("harmonyos-synonyms.json",t)}function yt(t){return pn("harmonyos-terms.txt",t)}var Rr={state:"idle",phase:0,phaseLabel:"Idle",current:0,total:0,message:"",startedAt:0,updatedAt:0,error:null};async function gn(){try{let t=await w.promises.readFile(tt(),"utf-8");return JSON.parse(t)}catch{return{...Rr}}}async function Vt(t){let e=tt();await w.promises.mkdir(at.dirname(e),{recursive:!0}),await w.promises.writeFile(e,JSON.stringify(t,null,2))}function hn(t){let e=Date.now();return{state:"extracting",phase:1,phaseLabel:"Extracting documentation",current:0,total:0,message:t,startedAt:e,updatedAt:e,error:null}}async function B(t){let n={...await gn(),...t,updatedAt:Date.now()};return await Vt(n),n}async function Kt(){let t=v();return t?ht(t):null}async function te(){try{let t=await w.promises.readFile($(),"utf-8");return JSON.parse(t)}catch{return null}}async function ee(t=!1){if(t)return"no-index";let e=await te();if(!e||e.segmentCount===0)return"no-index";let n=await Kt();return n&&e.docsZipSha256!==n?"docs-changed":e.indexVersion!==H?"engine-upgraded":e.termsHash!==yt()?"terms-changed":e.synonymsHash!==St()?"synonyms-changed":null}function ne(){if(!Xt()||!w.existsSync(G())||!w.existsSync($()))return!1;let t=at.dirname(G());if(!N.every(e=>w.existsSync(at.join(t,e))))return!1;try{let e=w.readFileSync($(),"utf-8");return JSON.parse(e).segmentCount>0}catch{return!1}}async function Sn(t=!1){return t?!0:Xt()?ne()?await ee()!==null:!0:!1}import*as x from"fs";import*as lr from"os";import*as _ from"path";var yn=new Set(["picker","dialog","sheet","panel","popup","menu","layout","view","gesture","animation","transition","recognizer","manager","kit"]);var xn=new Set(["a","an","and","api","app","application","arkts","arkui","for","get","harmonyos","how","in","oh","ohos","on","or","set","the","to","use","using","what","when","where","which","with","without","data","file","main","model","name","network","stage","system","type","user"]),En=new Set(["ability","extension","module","service","context","options","config","info","event","code","state","type","data","request","response","client","server","handler","helper","utils","factory","builder","listener","callback","observer","provider","consumer","delegate","adapter","driver","buffer","stream","channel","session","task","worker","controller","component","container","attribute","descriptor","modifier","validator","parser","formatter","encoder","decoder","filter","converter","generator","iterator","dispatcher","resolver","scanner","tracker","monitor","scheduler","renderer","loader","subscriber","proxy","button","surface","stack","heap","map","set","array","list"]);var Nr=/@ohos\.[a-z][a-zA-Z0-9.]+/gi,Pr=/\b[a-z][a-z0-9]*[A-Z][a-zA-Z0-9]+\b/g,Or=/[A-Z][a-zA-Z0-9]{2,}/g,Lr=/@[A-Z][a-zA-Z0-9]*/g,Br=/[a-z][a-zA-Z0-9]*\.[a-zA-Z][a-zA-Z0-9]+/g,_n=6,Mr=/^[a-z][a-z0-9]{2,}$/,kr=/^([a-z][a-z0-9]{2,})\s+([a-z][a-z0-9]{2,})$/,vr=/^@ohos\.[a-z][a-zA-Z0-9.]+$/i,Fr=/^[a-z][a-z0-9]*[A-Z][a-zA-Z0-9]+$/,zr=/^[A-Z][a-zA-Z0-9]+$/;function re(t){return vr.test(t)}function Hr(t){return Fr.test(t)&&t.length>=_n}function jr(t){return zr.test(t)}function oe(t){return re(t)||Hr(t)||jr(t)}function Ur(t){let e=t.trim().toLowerCase();return En.has(e)?!1:yn.has(e)}function Zr(t,e){let n=e.trim().charAt(0).toUpperCase(),r=e.trim().slice(1).toLowerCase();return`${t.trim().toLowerCase()}${n}${r}`}function xt(t){let n=t.replace(/^@ohos\./i,"").split(".").filter(Boolean);return n[n.length-1]?.trim()||void 0}function ie(t){return[...t.matchAll(Nr)].map(e=>e[0])}function se(t,e=_n){let n=[];for(let r of t.matchAll(Pr))r[0].length>=e&&n.push(r[0]);return n}function X(t){return t.filter(e=>{let n=e.toLowerCase();return!t.some(r=>{if(r===e)return!1;let o=r.toLowerCase();return o.length>n.length&&o.endsWith(n)&&n.length>=4})})}function D(t,e){let n=e.trim();if(!n)return;t.add(n);let r=n.toLowerCase();r!==n&&t.add(r)}function $r(t){let e=new Set;D(e,t);let n=xt(t);return n&&D(e,n),X([...e])}function ae(t){if(re(t))return $r(t);let e=new Set;return D(e,t),X([...e])}function ce(t){let e=t.trim();if(/[A-Z]/.test(e))return null;let n=e.match(kr);if(!n)return null;let r=n[1].toLowerCase(),o=n[2].toLowerCase();if(!Mr.test(r)||xn.has(r)||!Ur(o))return null;let i=Zr(r,o);return{first:r,second:o,camelCase:i,lower:i.toLowerCase()}}function bn(t){let e=ce(t.trim());return!e||e.second!=="manager"?null:e}function ue(t,e,n){let r=n.toLowerCase(),o=new RegExp(`@ohos\\.[^\\s(]*${n}`,"i");for(let i of[t,e])if(i&&(i.toLowerCase().includes(r)||o.test(i)))return!0;return!1}function An(t){let e=t.trim();if(oe(e))return ae(e);let n=new Set;for(let r of ie(t)){D(n,r);let o=xt(r);o&&D(n,o)}for(let r of se(t))D(n,r);for(let r of t.matchAll(Lr))n.add(r[0]);for(let r of t.matchAll(Br))n.add(r[0]);for(let r of t.matchAll(Or))r[0].length>=4&&n.add(r[0]);return X([...n])}function wn(t){let e=t.trim();if(oe(e))return ae(e);let n=new Set,r=ce(e);r&&D(n,r.camelCase);for(let o of An(e))n.add(o);for(let o of e.matchAll(/\b[a-z][a-zA-Z0-9]{3,}\b/g)){let i=o[0];i!==i.toLowerCase()&&n.add(i)}return X([...n])}var I={pureApiSymbol:/^[A-Z][a-zA-Z0-9]+$/,stageModelExact:/^Stage\s*模型$/i,stageModelEnglishExact:/^stage\s+model$/i,stageModel:/Stage\s*模型/i,stageModelEntryPage:/Stage\s*模型.*EntryAbility.*(页面|新页面)/,declarePermissionBoost:/声明.*权限|应用权限.*声明|如何声明应用权限/,declarePermissionCatalog:/如何声明应用权限/,declarePermissionTokens:/如何声明应用权限|声明应用权限/,uiAbilityLifecycleBoost:/UIAbility.*生命周期|生命周期.*UIAbility|UIAblity/i,uiAbilityLifecycleCatalog:/UIAblity.*生命周期|UIAbility.*生命周期/i,entryAbilityPage:/EntryAbility.*(页面|启动|跳转|新页面)/,stateDecoratorBoost:/@State|@Prop|@Link|@Provide|@Consume/,stateDecoratorCatalog:/@State\s*装饰器|@Prop\s*装饰器|@Link\s*装饰器/,stateManagement:/状态管理原理/,routerRoute:/Router\s+路由/,dialogPopupExact:/^Dialog\s+弹窗$/,dialogPopupBoost:/Dialog\s+弹窗/};function In(t){return I.pureApiSymbol.test(t.trim())}function Dn(t){let e=t.trim();return I.stageModelExact.test(e)||I.stageModelEnglishExact.test(e)}var Gr=[{matches:t=>I.uiAbilityLifecycleBoost.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.85},{catalog:"harmonyos-references",multiplier:.65},{catalog:"harmonyos-faqs",multiplier:.82}]},{matches:t=>Dn(t),weights:[{catalog:"harmonyos-guides",multiplier:1.85},{catalog:"harmonyos-references",multiplier:.55},{catalog:"harmonyos-faqs",multiplier:.85}]},{matches:t=>!Dn(t)&&I.stageModel.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.65},{catalog:"harmonyos-references",multiplier:.65}]},{matches:t=>I.entryAbilityPage.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.75},{catalog:"harmonyos-references",multiplier:.48}]},{matches:t=>I.declarePermissionBoost.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.65},{catalog:"best-practices",multiplier:.68}]},{matches:t=>I.stateDecoratorBoost.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.75},{catalog:"harmonyos-references",multiplier:.42}]},{matches:t=>I.stateManagement.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.6},{catalog:"best-practices",multiplier:.78}]},{matches:t=>I.routerRoute.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.65},{catalog:"harmonyos-references",multiplier:1.4},{catalog:"harmonyos-faqs",multiplier:.72},{catalog:"best-practices",multiplier:.72}]},{matches:t=>I.dialogPopupBoost.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.65},{catalog:"harmonyos-faqs",multiplier:.72},{catalog:"best-practices",multiplier:.72}]}];function Xr(t,e){for(let{catalog:n,multiplier:r}of e){let o=O[n];t.set(o,(t.get(o)??1)*r)}}function Tn(t,e){for(let n of Gr)n.matches(t)&&Xr(e,n.weights)}import*as W from"fs";import*as Rn from"path";function z(t){process.env.DEVECO_CLI_DEBUG&&console.log(`[DEBUG] ${t}`)}var Et=null,le=null,de=null;function Wr(){return W.existsSync(nt())}function Qr(t){let e=nt(),n={backend:"jieba-wasm",reason:"native-jieba-load-failed",message:t,createdAt:new Date().toISOString()};W.mkdirSync(Rn.dirname(e),{recursive:!0}),it(e),W.writeFileSync(e,JSON.stringify(n,null,2))}function qr(){if(Et)return Et;let t=rt("harmonyos-stopwords.txt");return Et=new Set(t.split(`
2
- `).map(e=>e.trim()).filter(Boolean)),Et}function Jr(t){let e=[];for(let n=0;n<t.length;n++){let r=t[n]?.trim();if(!r)continue;let o=t[n+1]?.trim();if(r==="@"&&o&&/^[A-Z][a-zA-Z0-9]*$/.test(o)){e.push(`@${o}`),n+=1;continue}e.push(r)}return e}function Yr(t){let e=qr(),n=[];for(let r of Jr(t)){let o=r.trim();!o||e.has(o)||(n.push(o.toLowerCase()),/[A-Z]/.test(o)&&/[a-zA-Z]/.test(o)&&n.push(o))}return n}async function Nn(t){let{dict:e}=await import("@node-rs/jieba/dict.js"),n=t.withDict(e),r=rt("harmonyos-terms.txt");return n.loadDict(Buffer.from(r,"utf-8")),n}async function Vr(){let{Jieba:t}=await import("@node-rs/jieba");return Nn(t)}async function Cn(){let{Jieba:t}=await import("@node-rs/jieba-wasm32-wasi");return Nn(t)}async function Kr(){if(Wr())return await Cn();try{let e=await Vr();return z("doc-index: using @node-rs/jieba backend"),e}catch(e){let n=e instanceof Error?e.message:String(e);Qr(n),z(`doc-index: @node-rs/jieba unavailable (${n}); falling back to wasm32-wasi`)}let t=await Cn();return z("doc-index: using @node-rs/jieba-wasm32-wasi backend"),t}async function Q(){return le||(de||(de=Kr().then(t=>(le=t,t))),de)}async function to(t){let e=await Q();return Yr(e.cutForSearch(t,!0))}async function _t(t,e){let n=t.trim();if(!n||e<=0)return"";let r=(await to(n)).join(" ");return r.length<=e?r:r.slice(0,e)}async function eo(t,e){let n=[];for(let o of t){let i=o.trim();i&&(n.push(i.toLowerCase()),/[A-Z]/.test(i)&&n.push(i))}let r=[...new Set(n)].join(" ");return r.length<=e?r:r.slice(0,e)}async function bt(t){let e=!!t.sectionTitle.trim(),n=t.titleTokens.trim(),r=e?Me:Ne,o=e?ve:Oe,i=e?await eo(t.apiSymbols,o):await _t(t.apiSymbols.join(" "),o),a=(await Promise.all([_t(n,e?ke:Pe),Promise.resolve(i),_t(t.headingsText,e?Fe:Le),_t(t.bodySample,e?ze:Be)])).filter(Boolean).join(" ");return a.length<=r?a:a.slice(0,r)}var Pn=["harmonyos-releases","harmonyos-roadmap"],no=new Set(Pn.map(t=>O[t])),Ba=Pn.map(t=>`${dt[t]}/`);function ro(t){return no.has(t)}function On(t){let e=[],n=[];for(let r of t)ro(r.catalog_id)?n.push(r):e.push(r);return[...e,...n]}var oo=[{pattern:/@ohos\./i,catalog:"harmonyos-references",multiplier:1.5},{pattern:/@[A-Z][a-zA-Z]+/,catalog:"harmonyos-guides",multiplier:1.35},{pattern:/(如何|怎么|怎样|步骤)/,catalog:"harmonyos-guides",multiplier:1.45},{pattern:/(生命周期|原理|概述|什么是|模型|介绍)/,catalog:"harmonyos-guides",multiplier:1.35},{pattern:/(报错|失败|错误|异常|排查)/,catalog:"harmonyos-guides",multiplier:1.25},{pattern:/(报错|失败|FAQ)/i,catalog:"harmonyos-faqs",multiplier:1.2},{pattern:/(构建|签名|打包|发布|上架|应用市场|hvigor|ohpm)/i,catalog:"harmonyos-guides",multiplier:1.3},{pattern:/(行为变更|changelog|升级|适配|版本说明)/i,catalog:"harmonyos-releases",multiplier:1.3},{pattern:/(路由|弹窗|手势|页面|权限|装饰器)/,catalog:"harmonyos-guides",multiplier:1.25,skipForPureApiSymbol:!0}];function ct(t,e,n){let r=O[e];t.set(r,(t.get(r)??1)*n)}function io(t,e){let n=t.trim(),r=/[\u4e00-\u9fff]/.test(n),o=/\b[A-Z][a-zA-Z0-9]{2,}\b/.test(n),i=/\b[a-z][a-zA-Z0-9]{3,}\b/.test(n);if(r&&(o||i)){ct(e,"harmonyos-guides",1.45),ct(e,"harmonyos-references",1.35);return}(o||i)&&ct(e,"harmonyos-references",1.55),/\b[A-Z][a-zA-Z]*(Gesture|Dialog|Sheet|Transition|Recognizer)\b/.test(n)&&ct(e,"harmonyos-references",1.75)}function Ln(t){let e=new Map,n=t.trim();if(!n)return e;let r=In(n);io(n,e),Tn(n,e);for(let o of oo)o.pattern.test(n)&&(o.skipForPureApiSymbol&&r||ct(e,o.catalog,o.multiplier));return e}import*as J from"fs";import*as jn from"path";var so=[" ","\u3002","\uFF0C","\uFF1B","\u3001",".","!","?"];function Bn(t,e){let n=-1;for(let r of so){let o=t.lastIndexOf(r);o>n&&(n=o)}return n>=e?n:-1}function Mn(t,e){let n=t.trim();if(n.length<=e)return{text:n,excerptTruncated:!1};let r=n.slice(0,e),o=Bn(r,e-20),i=o>=0?o:e;return{text:n.slice(0,i).trimEnd(),excerptTruncated:!0}}function kn(t,e,n={}){let{maxLen:r=Ue,contextChars:o=Ze,excerptTruncated:i=!1}=n,s=t.replace(/\s+/g," ").trim();if(!s)return"";if(s.length<=r)return i?`${s}...`:s;let a=e.split(/\s+/).map(Lt=>Lt.trim()).filter(Boolean),c=0;for(let Lt of a){let be=s.toLowerCase().indexOf(Lt.toLowerCase());if(be>=0){c=be;break}}let f=Math.max(0,c-o),p=Math.min(s.length,f+r),u=s.slice(f,p),b=Bn(u,r-25);b>=0&&(p=f+b);let S=s.slice(f,p).trim(),A=f>0?"...":"",hr=p<s.length||i?"...":"";return`${A}${S}${hr}`}var ao=`
1
+ import*as x from"fs";import*as Q from"path";import Ci from"proper-lockfile";import Ri from"ora";import*as b from"fs";import*as ot from"path";var Ot=["harmonyos-guides","harmonyos-references","best-practices","harmonyos-faqs","harmonyos-releases","harmonyos-roadmap"],ct={"harmonyos-guides":"\u5F00\u53D1\u6307\u5357","harmonyos-references":"API\u53C2\u8003","best-practices":"\u6700\u4F73\u5B9E\u8DF5","harmonyos-faqs":"FAQ","harmonyos-releases":"\u7248\u672C\u8BF4\u660E","harmonyos-roadmap":"\u53D8\u66F4\u9884\u544A"};var F="1.9.1",Ui=48*1024*1024,Ae=280,De=6,Ie=100,Te=3,we=28,Pt=10,Ce=/API参考|APIReference/i;var Re=6,ut=700,Lt=250,Bt=400,Ne=1320,Oe=120,Pe=450,Le=250,Be=500,Me=480,ke=80,Fe=200,ve=60,ze=200,He=40,je=200,Ze=200,Ue=40,v=500,$e=Object.fromEntries(Ot.map((t,e)=>[ct[t],e])),R=Object.fromEntries(Ot.map((t,e)=>[t,e]));import*as J from"fs";import*as m from"path";import{fileURLToPath as Ye}from"url";import*as N from"fs";import*as Qe from"path";import{homedir as pr}from"os";import*as Ge from"fs";import*as y from"path";function Mt(t,e){let n=y.relative(e,t);return n===""||!y.isAbsolute(n)&&!n.startsWith(`..${y.sep}`)&&n!==".."}function z(t){let e=y.resolve(t),n=[],r=e;for(;;)try{let o=Ge.realpathSync(r);return n.length===0?o:y.join(o,...n.reverse())}catch(o){if(o.code!=="ENOENT")throw o;let i=y.dirname(r);if(i===r)return e;n.push(y.basename(r)),r=i}}function Xe(t,e){let n=z(e),r=z(t);return Mt(r,n)?r:null}function kt(t){let e=t.trim();return(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))&&(e=e.slice(1,-1).trim()),e}function We(t){let e=kt(t);if(!e)throw new Error("Path must not be empty.");return z(e)}var gr="deveco-cli",Ft,L=class extends Error{constructor(e){super(e),this.name="CliDataDirError"}};function qe(){let t=process.env.DEVECO_CLI_DATA_DIR,n=(t===void 0||t===""?"":kt(t))||Qe.join(pr(),".local","share",gr);try{return We(n)}catch(r){throw new L(r instanceof Error?r.message:String(r))}}async function Je(){let t=qe();await N.promises.mkdir(t,{recursive:!0});let e;try{e=await N.promises.realpath(t)}catch(r){throw new L(`DEVECO_CLI_DATA_DIR is not usable: ${r instanceof Error?r.message:String(r)}`)}if(!(await N.promises.stat(e)).isDirectory())throw new L("DEVECO_CLI_DATA_DIR must be a writable directory.");return Ft=e,e}function q(){if(Ft!==void 0)return Ft;let t=qe();try{if(N.existsSync(t))return N.realpathSync(t)}catch{}return t}var hr="docs";function H(){return m.join(q(),hr)}function g(){return m.join(H(),".index")}function lt(){return m.join(g(),"build.lock")}function Y(){return m.join(g(),"build-status.json")}function j(){return m.join(g(),"build-meta.json")}function Z(){return m.join(g(),"search.db")}function V(){return m.join(g(),"sqlite-backend.json")}function K(){return m.join(g(),"jieba-backend.json")}function I(){return m.join(g(),".tmp")}function Sr(){return m.join(q(),"logs")}function vt(){return m.join(Sr(),"doc-init.log")}function yr(t,e){let n=e;for(;!n.endsWith(`${m.sep}dist`)&&n!==m.dirname(n);)n=m.dirname(n);return n}function Ve(t,e){return m.dirname(yr(t,e))}function Ke(){let t=Ye(import.meta.url),e=m.dirname(t);return t.includes(`${m.sep}dist${m.sep}`)?Ve(t,e):m.join(e,"..","..","..")}function xr(...t){let e=Ye(import.meta.url),n=m.dirname(e);return e.includes(`${m.sep}dist${m.sep}`)?[m.join(Ve(e,n),...t)]:[m.join(n,"..","..","..",...t)]}function tn(...t){let e=Ke(),n=J.realpathSync(e);for(let r of xr(...t))try{let o=J.lstatSync(r);if(o.isSymbolicLink()||!o.isFile())throw new Error(`Unsafe documentation package asset: ${t.join("/")} must be a regular file.`);let i=J.realpathSync(r);if(!Mt(i,n))throw new Error(`Unsafe documentation package asset: ${t.join("/")} is outside the package.`);return i}catch(o){if(o.code!=="ENOENT")throw o}return null}function B(){return tn("docs.zip")}function zt(){return tn("index.zip")}function en(){return m.join(Ke(),"index","data")}import*as T from"fs";import*as M from"path";var w=["harmonyos-terms.txt","harmonyos-synonyms.json","harmonyos-stopwords.txt"],Ht=class extends Error{constructor(e){super(e),this.name="LexiconNotFoundError"}};var jt=null;function Zt(t){jt=t}function nn(){if(jt)return jt;let t=g();if(w.every(o=>T.existsSync(M.join(t,o))))return t;let n=en();if(w.every(o=>T.existsSync(M.join(n,o))))return n;throw new Ht("Lexicon files not found. Install the documentation index first (index.zip).")}function tt(t){let e=M.join(nn(),t);return T.readFileSync(e,"utf-8")}function rn(t,e){return T.readFileSync(M.join(e,t),"utf-8")}async function on(t,e=nn()){await T.promises.mkdir(t,{recursive:!0});for(let n of w){let r=M.join(e,n),o=M.join(t,n);await T.promises.copyFile(r,o)}}import*as Ut from"fs";import*as Er from"yauzl";function $t(){let t=B();return t!==null&&Ut.existsSync(t)}import*as S from"fs";import*as C from"path";import sn from"adm-zip";import*as et from"fs";import*as mt from"path";var dt=class extends Error{constructor(e){super(`Unsafe documentation path: ${e}`),this.name="DocPathSafetyError"}};function Wt(t){return t instanceof L||t instanceof dt||t instanceof Error&&(t.name==="CliDataDirError"||t.name==="DocPathSafetyError")}function Qt(t){return new dt(t)}function _r(){return z(q())}function Xt(t,e,n){let r=Xe(t,e);if(r===null)throw Qt(`${n} resolves outside the data directory.`);return r}async function Gt(t,e){await et.promises.mkdir(t,{recursive:!0});let n=Xt(t,e,"directory");if(!(await et.promises.stat(n)).isDirectory())throw Qt("path must be a directory.")}function nt(t){let e=_r();try{let n=Xt(t,e,"file");if(!et.statSync(n).isFile())throw Qt("path must be a regular file.")}catch(n){if(n.code==="ENOENT"){Xt(mt.dirname(t),e,"file parent");return}throw n}}async function rt(t={}){let e=t.mode??"write",n=await Je();await Gt(H(),n),await Gt(g(),n),e==="write"&&await Gt(I(),n);for(let r of[Z(),j(),Y(),lt(),K(),V(),...w.map(o=>mt.join(g(),o))])nt(r)}var qt=["search.db","build-meta.json",...w],br=["corpus.json","corpus-offsets.json","orama.dpack"];async function Ar(t){for(let e of br)await S.promises.rm(C.join(t,e),{force:!0})}async function Dr(t){let e=await S.promises.readdir(t,{withFileTypes:!0});for(let n of e)n.name!==".index"&&await S.promises.rm(C.join(t,n.name),{recursive:!0,force:!0})}function an(t){let n=new sn(t).getEntry("build-meta.json");if(!n)throw new Error("index.zip is missing build-meta.json");return JSON.parse(n.getData().toString("utf-8"))}async function Ir(t){let e=g();await S.promises.mkdir(e,{recursive:!0});for(let n of qt){let r=C.join(e,n);await S.promises.rm(r,{force:!0}),await S.promises.rename(C.join(t,n),r)}await Ar(e),await S.promises.rm(I(),{recursive:!0,force:!0})}function cn(t){let e=zt();if(!e)return!1;try{let n=an(e);return n.indexVersion===F&&n.docsZipSha256===t&&n.segmentCount>0}catch{return!1}}async function un(t){await rt({mode:"write"});let e=zt();if(!e)throw new Error("index.zip not found");let n=an(e);if(n.docsZipSha256!==t)throw new Error("Bundled index.zip does not match docs.zip. Rebuild index.zip with npm run build:index.");if(n.segmentCount<=0)throw new Error("Bundled index.zip is empty");let r=I();await S.promises.rm(r,{recursive:!0,force:!0}),await S.promises.mkdir(r,{recursive:!0});let o=new sn(e);for(let s of qt){let a=o.getEntry(s);if(!a)throw new Error(`index.zip is missing ${s}`);await S.promises.writeFile(C.join(r,s),a.getData())}let i=JSON.parse(await S.promises.readFile(C.join(r,"build-meta.json"),"utf-8"));if(!S.existsSync(C.join(r,"search.db")))throw new Error("index.zip is missing search.db");return await Ir(r),await S.promises.mkdir(H(),{recursive:!0}),await Dr(H()),i}async function ln(){await S.promises.rm(I(),{recursive:!0,force:!0});let t=g();for(let e of qt)await S.promises.rm(C.join(t,e),{force:!0})}import{createHash as dn}from"crypto";import*as mn from"fs";async function ft(t){return new Promise((e,n)=>{let r=dn("sha256"),o=mn.createReadStream(t);o.on("data",i=>r.update(i)),o.on("error",n),o.on("end",()=>e(r.digest("hex")))})}function fn(t){return dn("sha256").update(t,"utf8").digest("hex")}function pn(t,e){let n=e?rn(t,e):tt(t);return fn(n)}function pt(t){return pn("harmonyos-synonyms.json",t)}function gt(t){return pn("harmonyos-terms.txt",t)}var Tr={state:"idle",phase:0,phaseLabel:"Idle",current:0,total:0,message:"",startedAt:0,updatedAt:0,error:null};async function gn(){try{let t=await b.promises.readFile(Y(),"utf-8");return JSON.parse(t)}catch{return{...Tr}}}async function Jt(t){let e=Y();await b.promises.mkdir(ot.dirname(e),{recursive:!0}),await b.promises.writeFile(e,JSON.stringify(t,null,2))}function hn(t){let e=Date.now();return{state:"extracting",phase:1,phaseLabel:"Extracting documentation",current:0,total:0,message:t,startedAt:e,updatedAt:e,error:null}}async function O(t){let n={...await gn(),...t,updatedAt:Date.now()};return await Jt(n),n}async function Yt(){let t=B();return t?ft(t):null}async function Vt(){try{let t=await b.promises.readFile(j(),"utf-8");return JSON.parse(t)}catch{return null}}async function Kt(t=!1){if(t)return"no-index";let e=await Vt();if(!e||e.segmentCount===0)return"no-index";let n=await Yt();return n&&e.docsZipSha256!==n?"docs-changed":e.indexVersion!==F?"engine-upgraded":e.termsHash!==gt()?"terms-changed":e.synonymsHash!==pt()?"synonyms-changed":null}function te(){if(!$t()||!b.existsSync(Z())||!b.existsSync(j()))return!1;let t=ot.dirname(Z());if(!w.every(e=>b.existsSync(ot.join(t,e))))return!1;try{let e=b.readFileSync(j(),"utf-8");return JSON.parse(e).segmentCount>0}catch{return!1}}async function Sn(t=!1){return t?!0:$t()?te()?await Kt()!==null:!0:!1}import*as xe from"fs";import*as Ee from"path";import Ei from"adm-zip";var yn=new Set(["picker","dialog","sheet","panel","popup","menu","layout","view","gesture","animation","transition","recognizer","manager","kit"]);var xn=new Set(["a","an","and","api","app","application","arkts","arkui","for","get","harmonyos","how","in","oh","ohos","on","or","set","the","to","use","using","what","when","where","which","with","without","data","file","main","model","name","network","stage","system","type","user"]),En=new Set(["ability","extension","module","service","context","options","config","info","event","code","state","type","data","request","response","client","server","handler","helper","utils","factory","builder","listener","callback","observer","provider","consumer","delegate","adapter","driver","buffer","stream","channel","session","task","worker","controller","component","container","attribute","descriptor","modifier","validator","parser","formatter","encoder","decoder","filter","converter","generator","iterator","dispatcher","resolver","scanner","tracker","monitor","scheduler","renderer","loader","subscriber","proxy","button","surface","stack","heap","map","set","array","list"]);var wr=/@ohos\.[a-z][a-zA-Z0-9.]+/gi,Cr=/\b[a-z][a-z0-9]*[A-Z][a-zA-Z0-9]+\b/g,Rr=/[A-Z][a-zA-Z0-9]{2,}/g,Nr=/@[A-Z][a-zA-Z0-9]*/g,Or=/[a-z][a-zA-Z0-9]*\.[a-zA-Z][a-zA-Z0-9]+/g,_n=6,Pr=/^[a-z][a-z0-9]{2,}$/,Lr=/^([a-z][a-z0-9]{2,})\s+([a-z][a-z0-9]{2,})$/,Br=/^@ohos\.[a-z][a-zA-Z0-9.]+$/i,Mr=/^[a-z][a-z0-9]*[A-Z][a-zA-Z0-9]+$/,kr=/^[A-Z][a-zA-Z0-9]+$/;function ee(t){return Br.test(t)}function Fr(t){return Mr.test(t)&&t.length>=_n}function vr(t){return kr.test(t)}function ne(t){return ee(t)||Fr(t)||vr(t)}function zr(t){let e=t.trim().toLowerCase();return En.has(e)?!1:yn.has(e)}function Hr(t,e){let n=e.trim().charAt(0).toUpperCase(),r=e.trim().slice(1).toLowerCase();return`${t.trim().toLowerCase()}${n}${r}`}function ht(t){let n=t.replace(/^@ohos\./i,"").split(".").filter(Boolean);return n[n.length-1]?.trim()||void 0}function re(t){return[...t.matchAll(wr)].map(e=>e[0])}function oe(t,e=_n){let n=[];for(let r of t.matchAll(Cr))r[0].length>=e&&n.push(r[0]);return n}function U(t){return t.filter(e=>{let n=e.toLowerCase();return!t.some(r=>{if(r===e)return!1;let o=r.toLowerCase();return o.length>n.length&&o.endsWith(n)&&n.length>=4})})}function A(t,e){let n=e.trim();if(!n)return;t.add(n);let r=n.toLowerCase();r!==n&&t.add(r)}function jr(t){let e=new Set;A(e,t);let n=ht(t);return n&&A(e,n),U([...e])}function ie(t){if(ee(t))return jr(t);let e=new Set;return A(e,t),U([...e])}function se(t){let e=t.trim();if(/[A-Z]/.test(e))return null;let n=e.match(Lr);if(!n)return null;let r=n[1].toLowerCase(),o=n[2].toLowerCase();if(!Pr.test(r)||xn.has(r)||!zr(o))return null;let i=Hr(r,o);return{first:r,second:o,camelCase:i,lower:i.toLowerCase()}}function bn(t){let e=se(t.trim());return!e||e.second!=="manager"?null:e}function ae(t,e,n){let r=n.toLowerCase(),o=new RegExp(`@ohos\\.[^\\s(]*${n}`,"i");for(let i of[t,e])if(i&&(i.toLowerCase().includes(r)||o.test(i)))return!0;return!1}function An(t){let e=t.trim();if(ne(e))return ie(e);let n=new Set;for(let r of re(t)){A(n,r);let o=ht(r);o&&A(n,o)}for(let r of oe(t))A(n,r);for(let r of t.matchAll(Nr))n.add(r[0]);for(let r of t.matchAll(Or))n.add(r[0]);for(let r of t.matchAll(Rr))r[0].length>=4&&n.add(r[0]);return U([...n])}function Dn(t){let e=t.trim();if(ne(e))return ie(e);let n=new Set,r=se(e);r&&A(n,r.camelCase);for(let o of An(e))n.add(o);for(let o of e.matchAll(/\b[a-z][a-zA-Z0-9]{3,}\b/g)){let i=o[0];i!==i.toLowerCase()&&n.add(i)}return U([...n])}var D={pureApiSymbol:/^[A-Z][a-zA-Z0-9]+$/,stageModelExact:/^Stage\s*模型$/i,stageModelEnglishExact:/^stage\s+model$/i,stageModel:/Stage\s*模型/i,stageModelEntryPage:/Stage\s*模型.*EntryAbility.*(页面|新页面)/,declarePermissionBoost:/声明.*权限|应用权限.*声明|如何声明应用权限/,declarePermissionCatalog:/如何声明应用权限/,declarePermissionTokens:/如何声明应用权限|声明应用权限/,uiAbilityLifecycleBoost:/UIAbility.*生命周期|生命周期.*UIAbility|UIAblity/i,uiAbilityLifecycleCatalog:/UIAblity.*生命周期|UIAbility.*生命周期/i,entryAbilityPage:/EntryAbility.*(页面|启动|跳转|新页面)/,stateDecoratorBoost:/@State|@Prop|@Link|@Provide|@Consume/,stateDecoratorCatalog:/@State\s*装饰器|@Prop\s*装饰器|@Link\s*装饰器/,stateManagement:/状态管理原理/,routerRoute:/Router\s+路由/,dialogPopupExact:/^Dialog\s+弹窗$/,dialogPopupBoost:/Dialog\s+弹窗/};function Tn(t){return D.pureApiSymbol.test(t.trim())}function In(t){let e=t.trim();return D.stageModelExact.test(e)||D.stageModelEnglishExact.test(e)}var Zr=[{matches:t=>D.uiAbilityLifecycleBoost.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.85},{catalog:"harmonyos-references",multiplier:.65},{catalog:"harmonyos-faqs",multiplier:.82}]},{matches:t=>In(t),weights:[{catalog:"harmonyos-guides",multiplier:1.85},{catalog:"harmonyos-references",multiplier:.55},{catalog:"harmonyos-faqs",multiplier:.85}]},{matches:t=>!In(t)&&D.stageModel.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.65},{catalog:"harmonyos-references",multiplier:.65}]},{matches:t=>D.entryAbilityPage.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.75},{catalog:"harmonyos-references",multiplier:.48}]},{matches:t=>D.declarePermissionBoost.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.65},{catalog:"best-practices",multiplier:.68}]},{matches:t=>D.stateDecoratorBoost.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.75},{catalog:"harmonyos-references",multiplier:.42}]},{matches:t=>D.stateManagement.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.6},{catalog:"best-practices",multiplier:.78}]},{matches:t=>D.routerRoute.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.65},{catalog:"harmonyos-references",multiplier:1.4},{catalog:"harmonyos-faqs",multiplier:.72},{catalog:"best-practices",multiplier:.72}]},{matches:t=>D.dialogPopupBoost.test(t),weights:[{catalog:"harmonyos-guides",multiplier:1.65},{catalog:"harmonyos-faqs",multiplier:.72},{catalog:"best-practices",multiplier:.72}]}];function Ur(t,e){for(let{catalog:n,multiplier:r}of e){let o=R[n];t.set(o,(t.get(o)??1)*r)}}function wn(t,e){for(let n of Zr)n.matches(t)&&Ur(e,n.weights)}import*as $ from"fs";import*as Rn from"path";function k(t){if(process.env.DEVECO_CLI_DEBUG){let e=typeof t=="function"?t():t;console.log(`[DEBUG] ${e}`)}}var St=null,ce=null,ue=null;function $r(){return $.existsSync(K())}function Gr(t){let e=K(),n={backend:"jieba-wasm",reason:"native-jieba-load-failed",message:t,createdAt:new Date().toISOString()};$.mkdirSync(Rn.dirname(e),{recursive:!0}),nt(e),$.writeFileSync(e,JSON.stringify(n,null,2))}function Xr(){if(St)return St;let t=tt("harmonyos-stopwords.txt");return St=new Set(t.split(`
2
+ `).map(e=>e.trim()).filter(Boolean)),St}function Wr(t){let e=[];for(let n=0;n<t.length;n++){let r=t[n]?.trim();if(!r)continue;let o=t[n+1]?.trim();if(r==="@"&&o&&/^[A-Z][a-zA-Z0-9]*$/.test(o)){e.push(`@${o}`),n+=1;continue}e.push(r)}return e}function Qr(t){let e=Xr(),n=[];for(let r of Wr(t)){let o=r.trim();!o||e.has(o)||(n.push(o.toLowerCase()),/[A-Z]/.test(o)&&/[a-zA-Z]/.test(o)&&n.push(o))}return n}async function Nn(t){let{dict:e}=await import("@node-rs/jieba/dict.js"),n=t.withDict(e),r=tt("harmonyos-terms.txt");return n.loadDict(Buffer.from(r,"utf-8")),n}async function qr(){let{Jieba:t}=await import("@node-rs/jieba");return Nn(t)}async function Cn(){let{Jieba:t}=await import("@node-rs/jieba-wasm32-wasi");return Nn(t)}async function Jr(){if($r())return await Cn();try{let e=await qr();return k("doc-index: using @node-rs/jieba backend"),e}catch(e){let n=e instanceof Error?e.message:String(e);Gr(n),k(`doc-index: @node-rs/jieba unavailable (${n}); falling back to wasm32-wasi`)}let t=await Cn();return k("doc-index: using @node-rs/jieba-wasm32-wasi backend"),t}async function G(){return ce||(ue||(ue=Jr().then(t=>(ce=t,t))),ue)}async function Yr(t){let e=await G();return Qr(e.cutForSearch(t,!0))}async function yt(t,e){let n=t.trim();if(!n||e<=0)return"";let r=(await Yr(n)).join(" ");return r.length<=e?r:r.slice(0,e)}async function Vr(t,e){let n=[];for(let o of t){let i=o.trim();i&&(n.push(i.toLowerCase()),/[A-Z]/.test(i)&&n.push(i))}let r=[...new Set(n)].join(" ");return r.length<=e?r:r.slice(0,e)}async function xt(t){let e=!!t.sectionTitle.trim(),n=t.titleTokens.trim(),r=e?Me:Ne,o=e?Fe:Pe,i=e?await Vr(t.apiSymbols,o):await yt(t.apiSymbols.join(" "),o),a=(await Promise.all([yt(n,e?ke:Oe),Promise.resolve(i),yt(t.headingsText,e?ve:Le),yt(t.bodySample,e?ze:Be)])).filter(Boolean).join(" ");return a.length<=r?a:a.slice(0,r)}var On=["harmonyos-releases","harmonyos-roadmap"],Kr=new Set(On.map(t=>R[t])),Ra=On.map(t=>`${ct[t]}/`);function to(t){return Kr.has(t)}function Pn(t){let e=[],n=[];for(let r of t)to(r.catalog_id)?n.push(r):e.push(r);return[...e,...n]}var eo=[{pattern:/@ohos\./i,catalog:"harmonyos-references",multiplier:1.5},{pattern:/@[A-Z][a-zA-Z]+/,catalog:"harmonyos-guides",multiplier:1.35},{pattern:/(如何|怎么|怎样|步骤)/,catalog:"harmonyos-guides",multiplier:1.45},{pattern:/(生命周期|原理|概述|什么是|模型|介绍)/,catalog:"harmonyos-guides",multiplier:1.35},{pattern:/(报错|失败|错误|异常|排查)/,catalog:"harmonyos-guides",multiplier:1.25},{pattern:/(报错|失败|FAQ)/i,catalog:"harmonyos-faqs",multiplier:1.2},{pattern:/(构建|签名|打包|发布|上架|应用市场|hvigor|ohpm)/i,catalog:"harmonyos-guides",multiplier:1.3},{pattern:/(行为变更|changelog|升级|适配|版本说明)/i,catalog:"harmonyos-releases",multiplier:1.3},{pattern:/(路由|弹窗|手势|页面|权限|装饰器)/,catalog:"harmonyos-guides",multiplier:1.25,skipForPureApiSymbol:!0}];function it(t,e,n){let r=R[e];t.set(r,(t.get(r)??1)*n)}function no(t,e){let n=t.trim(),r=/[\u4e00-\u9fff]/.test(n),o=/\b[A-Z][a-zA-Z0-9]{2,}\b/.test(n),i=/\b[a-z][a-zA-Z0-9]{3,}\b/.test(n);if(r&&(o||i)){it(e,"harmonyos-guides",1.45),it(e,"harmonyos-references",1.35);return}(o||i)&&it(e,"harmonyos-references",1.55),/\b[A-Z][a-zA-Z]*(Gesture|Dialog|Sheet|Transition|Recognizer)\b/.test(n)&&it(e,"harmonyos-references",1.75)}function Ln(t){let e=new Map,n=t.trim();if(!n)return e;let r=Tn(n);no(n,e),wn(n,e);for(let o of eo)o.pattern.test(n)&&(o.skipForPureApiSymbol&&r||it(e,o.catalog,o.multiplier));return e}import*as W from"fs";import*as jn from"path";var ro=[" ","\u3002","\uFF0C","\uFF1B","\u3001",".","!","?"];function Bn(t,e){let n=-1;for(let r of ro){let o=t.lastIndexOf(r);o>n&&(n=o)}return n>=e?n:-1}function Mn(t,e){let n=t.trim();if(n.length<=e)return{text:n,excerptTruncated:!1};let r=n.slice(0,e),o=Bn(r,e-20),i=o>=0?o:e;return{text:n.slice(0,i).trimEnd(),excerptTruncated:!0}}function kn(t,e,n={}){let{maxLen:r=Ze,contextChars:o=Ue,excerptTruncated:i=!1}=n,s=t.replace(/\s+/g," ").trim();if(!s)return"";if(s.length<=r)return i?`${s}...`:s;let a=e.split(/\s+/).map(Nt=>Nt.trim()).filter(Boolean),c=0;for(let Nt of a){let be=s.toLowerCase().indexOf(Nt.toLowerCase());if(be>=0){c=be;break}}let f=Math.max(0,c-o),p=Math.min(s.length,f+r),u=s.slice(f,p),E=Bn(u,r-25);E>=0&&(p=f+E);let h=s.slice(f,p).trim(),_=f>0?"...":"",fr=p<s.length||i?"...":"";return`${_}${h}${fr}`}var oo=`
3
3
  SELECT d.document_id, d.doc_title, s.section_title, s.lead_text, s.excerpt_truncated,
4
4
  d.catalog_id, bm25(segments_fts) AS bm25
5
5
  FROM segments_fts
@@ -8,7 +8,7 @@ import*as h from"fs";import*as T from"path";import Pi from"adm-zip";import Oi fr
8
8
  WHERE segments_fts MATCH ?
9
9
  ORDER BY bm25(segments_fts)
10
10
  LIMIT ?
11
- `,co=`
11
+ `,io=`
12
12
  SELECT d.document_id, d.doc_title, s.section_title, s.lead_text, s.excerpt_truncated,
13
13
  d.catalog_id, bm25(segments_fts) AS bm25
14
14
  FROM segments_fts
@@ -17,7 +17,7 @@ import*as h from"fs";import*as T from"path";import Pi from"adm-zip";import Oi fr
17
17
  WHERE segments_fts MATCH ? AND d.catalog_id = ?
18
18
  ORDER BY bm25(segments_fts)
19
19
  LIMIT ?
20
- `,uo=3.5,lo=1.4,mo=4,fo=1.8,po=1.35,go=3.5,ho=1.8,So=120,vn=6;function fe(t){return t.toLowerCase().replace(/[^\p{L}\p{N}@.]+/gu,"")}function yo(t){return t.split(/[^\p{L}\p{N}@.]+/u).map(fe).filter(e=>e.length>=2)}function xo(t,e){return e.length>1&&e.every(n=>t.includes(n))}function Eo(t){return/^[a-z0-9]{1,4}$/.test(t.trim().toLowerCase())}function _o(t,e){return t===e?go:t.startsWith(e)||t.includes(`@ohos.${e}`)?ho:1}function bo(t,e){let n=fe(e);if(n.length<2)return 1;let r=fe(t.doc_title);if(Eo(e))return _o(r,n);if(r.includes(n))return mo;if(n.length>=vn&&r.includes(n.slice(0,vn)))return fo;let o=yo(e);return xo(r,o)?po:1}function Ao(t,e){return e<=1?t:t<0?t*e:t/e}function At(t,e,n,r){let o=t.bm25/(e.get(t.catalog_id)??1);return o=Ao(o,bo(t,n)),r&&ue(t.doc_title,t.section_title,r)&&(o/=uo,t.catalog_id===O["harmonyos-references"]&&(o/=lo)),o}function me(t,e,n,r){return t.reduce((o,i)=>At(i,e,n,r)<At(o,e,n,r)?i:o)}function wo(t,e){return e.some(n=>t.section_title.includes(n)||t.doc_title.includes(n))}function Do(t,e,n,r,o){if(o){let i=t.filter(s=>ue(s.doc_title,s.section_title,o));if(i.length>0)return me(i,n,r,o)}if(e.length>0){let i=t.filter(s=>wo(s,e));if(i.length>0)return me(i,n,r,o)}return me(t,n,r,o)}function Fn(t,e,n,r,o){let i=Ln(e),s=wn(e),c=bn(e)?.camelCase,f=new Map;for(let S of t){let A=f.get(S.document_id)??[];A.push(S),f.set(S.document_id,A)}let p=[];for(let S of f.values())p.push(Do(S,s,i,n,c));let u=p.sort((S,A)=>At(S,i,n,c)-At(A,i,n,c));return(o?On(u):u).slice(0,r)}function wt(t,e,n,r,o,i){let s=e?O[e]:void 0,a=Math.max(n,n*Re,So),c=s===void 0?t.all(ao,r,a):t.all(co,r,s,a);return(s===void 0?Fn(c,i,o,n,!0):Fn(c,i,o,n,!1)).map(p=>({title:p.doc_title,documentId:p.document_id,sectionTitle:p.section_title||void 0,snippet:kn(p.lead_text,o,{excerptTruncated:!!p.excerpt_truncated})}))}var Dt=`
20
+ `,so=3.5,ao=1.4,co=4,uo=1.8,lo=1.35,mo=3.5,fo=1.8,po=120,Fn=6;function de(t){return t.toLowerCase().replace(/[^\p{L}\p{N}@.]+/gu,"")}function go(t){return t.split(/[^\p{L}\p{N}@.]+/u).map(de).filter(e=>e.length>=2)}function ho(t,e){return e.length>1&&e.every(n=>t.includes(n))}function So(t){return/^[a-z0-9]{1,4}$/.test(t.trim().toLowerCase())}function yo(t,e){return t===e?mo:t.startsWith(e)||t.includes(`@ohos.${e}`)?fo:1}function xo(t,e){let n=de(e);if(n.length<2)return 1;let r=de(t.doc_title);if(So(e))return yo(r,n);if(r.includes(n))return co;if(n.length>=Fn&&r.includes(n.slice(0,Fn)))return uo;let o=go(e);return ho(r,o)?lo:1}function Eo(t,e){return e<=1?t:t<0?t*e:t/e}function Et(t,e,n,r){let o=t.bm25/(e.get(t.catalog_id)??1);return o=Eo(o,xo(t,n)),r&&ae(t.doc_title,t.section_title,r)&&(o/=so,t.catalog_id===R["harmonyos-references"]&&(o/=ao)),o}function le(t,e,n,r){return t.reduce((o,i)=>Et(i,e,n,r)<Et(o,e,n,r)?i:o)}function _o(t,e){return e.some(n=>t.section_title.includes(n)||t.doc_title.includes(n))}function bo(t,e,n,r,o){if(o){let i=t.filter(s=>ae(s.doc_title,s.section_title,o));if(i.length>0)return le(i,n,r,o)}if(e.length>0){let i=t.filter(s=>_o(s,e));if(i.length>0)return le(i,n,r,o)}return le(t,n,r,o)}function vn(t,e,n,r,o){let i=Ln(e),s=Dn(e),c=bn(e)?.camelCase,f=new Map;for(let h of t){let _=f.get(h.document_id)??[];_.push(h),f.set(h.document_id,_)}let p=[];for(let h of f.values())p.push(bo(h,s,i,n,c));let u=p.sort((h,_)=>Et(h,i,n,c)-Et(_,i,n,c));return(o?Pn(u):u).slice(0,r)}function _t(t,e,n,r,o,i){let s=e?R[e]:void 0,a=Math.max(n,n*Re,po),c=s===void 0?t.all(oo,r,a):t.all(io,r,s,a);return(s===void 0?vn(c,i,o,n,!0):vn(c,i,o,n,!1)).map(p=>({title:p.doc_title,documentId:p.document_id,sectionTitle:p.section_title||void 0,snippet:kn(p.lead_text,o,{excerptTruncated:!!p.excerpt_truncated})}))}var bt=`
21
21
  CREATE TABLE documents (
22
22
  id INTEGER PRIMARY KEY,
23
23
  document_id TEXT NOT NULL UNIQUE,
@@ -55,11 +55,11 @@ CREATE TRIGGER segments_au AFTER UPDATE ON segments BEGIN
55
55
  END;
56
56
 
57
57
  CREATE INDEX segments_doc_id_idx ON segments(doc_id);
58
- `;var q=null,pe=null;function Io(){q?.close(),q=null,pe=null}function To(t,e){if(q&&pe===e)return q;q?.close();let n=new t(e,{readonly:!0,fileMustExist:!0});return q=n,pe=e,n.pragma("mmap_size = 268435456"),n.pragma("cache_size = -8000"),n.pragma("query_only = ON"),n}function Co(t,e){let n=new t(e);return n.pragma("journal_mode = OFF"),n.pragma("synchronous = OFF"),n.pragma("temp_store = MEMORY"),n.exec(Dt),n}function Ro(t,e,n){let r=e.get(n.documentId);if(r!==void 0)return r;let i=t.prepare("SELECT id FROM documents WHERE document_id = ?").get(n.documentId);if(i)return e.set(n.documentId,i.id),i.id;let a=t.prepare(`
58
+ `;var X=null,me=null;function Ao(){X?.close(),X=null,me=null}function Do(t,e){if(X&&me===e)return X;X?.close();let n=new t(e,{readonly:!0,fileMustExist:!0});return X=n,me=e,n.pragma("mmap_size = 268435456"),n.pragma("cache_size = -8000"),n.pragma("query_only = ON"),n}function Io(t,e){let n=new t(e);return n.pragma("journal_mode = OFF"),n.pragma("synchronous = OFF"),n.pragma("temp_store = MEMORY"),n.exec(bt),n}function To(t,e,n){let r=e.get(n.documentId);if(r!==void 0)return r;let i=t.prepare("SELECT id FROM documents WHERE document_id = ?").get(n.documentId);if(i)return e.set(n.documentId,i.id),i.id;let a=t.prepare(`
59
59
  INSERT INTO documents(document_id, catalog_id, doc_title)
60
60
  VALUES (?, ?, ?)
61
- `).run(n.documentId,n.catalogId,n.docTitle),c=Number(a.lastInsertRowid);return e.set(n.documentId,c),c}async function No(t,e,n,r){await Q();let o=Co(t,e),i=new Map,s=o.prepare(`
61
+ `).run(n.documentId,n.catalogId,n.docTitle),c=Number(a.lastInsertRowid);return e.set(n.documentId,c),c}async function wo(t,e,n,r){await G();let o=Io(t,e),i=new Map,s=o.prepare(`
62
62
  INSERT INTO segments(doc_id, section_title, lead_text, search_text, excerpt_truncated)
63
63
  VALUES (?, ?, ?, ?, ?)
64
- `),a=n.length;for(let c=0;c<a;c+=j){let f=n.slice(c,c+j),p=await Promise.all(f.map(async b=>({source:b,searchText:await bt(b)})));o.transaction(b=>{for(let S of b){let A=Ro(o,i,S.source);s.run(A,S.source.sectionTitle,S.source.leadText,S.searchText,S.source.excerptTruncated?1:0)}})(p),await r?.(Math.min(c+f.length,a),a)}o.exec("ANALYZE"),o.exec("VACUUM"),o.close()}function Po(t,e,n,r,o,i,s){let a=To(t,e);return wt({all(c,...f){return a.prepare(c).all(...f)}},n,r,o,i,s)}async function zn(){let e=(await import("better-sqlite3")).default;return{kind:"better-sqlite3",resetCache:Io,buildSearchIndex:(n,r,o)=>No(e,n,r,o),searchIndex:(n,r,o,i,s,a,c)=>Promise.resolve(Po(e,i,r,o,s,a,c))}}import{readFile as Oo,stat as Lo,writeFile as Bo}from"fs/promises";var ge=null,M=null;async function he(){return ge||(ge=(async()=>{let t=(await import("@sqlite.org/sqlite-wasm")).default;return t()})()),ge}function Mo(t){return{all(e,...n){let r=t.prepare(e);n.length>0&&r.bind(n);let o=[];for(;r.step();)o.push(r.get({}));return r.finalize(),o}}}async function ko(t){let e=await Lo(t);if(M&&M.dbPath===t&&M.mtimeMs===e.mtimeMs)return M.db;M?.db.close();let n=await he(),r=n.capi,o=n.wasm,i=new Uint8Array(await Oo(t)),s=o.allocFromTypedArray(i),a=new n.oo1.DB(":memory:"),c=r.SQLITE_DESERIALIZE_READONLY|r.SQLITE_DESERIALIZE_RESIZEABLE|r.SQLITE_DESERIALIZE_FREEONCLOSE;return r.sqlite3_deserialize(a.pointer,"main",s,i.byteLength,i.byteLength,c),M={dbPath:t,mtimeMs:e.mtimeMs,db:a},a}function Hn(){M?.db.close(),M=null}async function vo(t,e,n,r){t.exec("BEGIN");for(let o of r){let i=n(o.source);e.bind([i,o.source.sectionTitle,o.source.leadText,o.searchText,o.source.excerptTruncated?1:0]),e.step(),e.reset()}t.exec("COMMIT")}function Fo(t,e,n){return r=>{let o=e.get(r.documentId);if(o!==void 0)return o;let i=t.selectValue("SELECT id FROM documents WHERE document_id = ?",[r.documentId]);if(i!=null){let a=Number(i);return e.set(r.documentId,a),a}n.bind([r.documentId,r.catalogId,r.docTitle]),n.step(),n.reset();let s=Number(t.selectValue("SELECT last_insert_rowid()"));return e.set(r.documentId,s),s}}async function zo(t,e,n){await Q();let r=await he(),o=new r.oo1.DB(":memory:","c");o.exec(Dt);let i=new Map,s=o.prepare("INSERT INTO documents(document_id, catalog_id, doc_title) VALUES (?, ?, ?)"),a=o.prepare("INSERT INTO segments(doc_id, section_title, lead_text, search_text, excerpt_truncated) VALUES (?, ?, ?, ?, ?)"),c=Fo(o,i,s),f=e.length;for(let u=0;u<f;u+=j){let b=e.slice(u,u+j),S=await Promise.all(b.map(async A=>({source:A,searchText:await bt(A)})));await vo(o,a,c,S),await n?.(Math.min(u+b.length,f),f)}o.exec("ANALYZE");let p=r.capi.sqlite3_js_db_export(o);await Bo(t,p),o.close(),Hn()}async function Ho(t,e,n,r,o,i){let s=await ko(t);return wt(Mo(s),e,n,r,o,i)}async function Se(){return await he(),{kind:"sqlite-wasm",resetCache:Hn,buildSearchIndex:zo,searchIndex:(t,e,n,r,o,i,s)=>Ho(r,e,n,o,i,s)}}var It=null,ye=null;function jo(){return J.existsSync(et())}function Uo(t){let e=et(),n={backend:"sqlite-wasm",reason:"better-sqlite3-load-failed",message:t,createdAt:new Date().toISOString()};J.mkdirSync(jn.dirname(e),{recursive:!0}),it(e),J.writeFileSync(e,JSON.stringify(n,null,2))}async function Zo(){if(jo())return Se();try{let t=await zn();return z("doc-index: using better-sqlite3 SQLite backend"),t}catch(t){let e=t instanceof Error?t.message:String(t);Uo(e),z(`doc-index: better-sqlite3 unavailable (${e}); falling back to sqlite-wasm`)}return Se()}async function xe(){return It||(It=Zo().then(t=>(ye=t,t))),It}function Un(){ye?.resetCache(),It=null,ye=null}function Tt(){Un()}async function Zn(t,e,n){await(await xe()).buildSearchIndex(t,e,n)}import{unified as Yn}from"unified";import Vn from"remark-parse";import Kn from"remark-gfm";import{toString as Rt}from"mdast-util-to-string";var $o=/^(.+?)(\d+\+)?(对象|枚举|错误码)说明$/,Go=/^\[h2\]([A-Za-z][A-Za-z0-9]*)(\d+\+)?$/,Xo=/^(.{2,20}?)\s*[((]([A-Za-z][a-zA-Z0-9]{1,40})[))]\s*$/,Wo=/^([A-Za-z@][A-Za-z0-9@]*?)(\d+\+)?$/,Qo=/^(系统能力|元服务API|参数|返回值|说明|\*\*|表格|\|)/;function Ct(t){let e=t.trim(),n=e.match(Wo);return n?n[1]:e}function qo(t){let e=t.match($o);if(!e)return;let n=Ct(e[1].trim());return{displayTitle:t,symbolName:n,searchExtras:[n,e[3]]}}function Jo(t){let e=Ct(t.replace(/\([^)]*\)$/,""));if(/^[A-Z][A-Za-z0-9]*$/.test(e))return{displayTitle:t,symbolName:e,searchExtras:[e]};if(/^[A-Z][A-Za-z0-9]*(\([^)]*\))?$/.test(t))return{displayTitle:t,symbolName:e,searchExtras:[e]}}function ut(t){let e=t.trim();return e?qo(e)??(()=>{let n=e.match(Go);if(n){let r=n[1];return{displayTitle:e,symbolName:r,searchExtras:[r]}}})()??(()=>{let n=e.match(Xo);if(!n)return;let r=n[1].trim(),o=n[2].trim();return{displayTitle:e,symbolName:o,searchExtras:[r,o]}})()??Jo(e)??{displayTitle:e,searchExtras:[]}:{displayTitle:"",searchExtras:[]}}function Yo(t){if(t.length<2||t.length>36||Qo.test(t))return!1;let e=[...t.replace(/\s/g,"")];return e.length===0?!1:e.filter(r=>new RegExp("\\p{Script=Han}","u").test(r)).length/e.length>=.4}function $n(t){for(let e of t){let n=e.trim().replace(/[。.!!??;;]+$/u,"").trim();if(Yo(n))return n}return""}function Gn(t,e,n){let r=[t,...n.searchExtras,e].filter(Boolean);return[...new Set(r)].join(" ")}var Vo=/[A-Z][a-zA-Z0-9]+(?:\.[a-zA-Z][a-zA-Z0-9]+)*/g,lt=/@[A-Z][a-zA-Z]+/g,Ko=/^[A-Z][A-Za-z0-9]*\.[A-Za-z][A-Za-z0-9]+/,ti=/^[A-Z][A-Za-z0-9]+(?:\([^)]*\))?$/,ei=/^[a-z0-9]+(?:[-_][a-z0-9]+)+$/,ni=new Set(["API","Action","Code","Connect","Connection","Context","Direction","Element","Elements","Entry","Focused","Module","Modules","Name","Names","Stage","Type","Types","Value","Values","Rect","Error"]),ri=new Set(["HAP","HSP","HAR","NAPI","CAPI","NDK","ArkTS","ArkUI","OHPM"]),oi=new Set(["JSON","Object","Array","Promise","console","Math","Date","String","Number","Boolean","Error","Function","Map","Set","RegExp"]);function tr(t,e){let n=new Set,r=[t,...e];for(let o of r){for(let i of ie(o)){D(n,i);let s=xt(i);s&&D(n,s)}for(let i of se(o))D(n,i);for(let i of o.matchAll(Vo)){let s=i[0];ii(s)&&n.add(s)}for(let i of o.matchAll(lt))n.add(i[0])}return X([...n])}function ii(t){let e=t.trim();if(!e||lt.test(e))return!!e;if(e.includes(".")){let n=e.split(".")[0]??"";return oi.has(n)?!1:/^[A-Z]/.test(n)}return ni.has(e)?!1:ri.has(e)?!0:e.length<=3?!1:/^[A-Z][a-z]+[A-Z]/.test(e)?!0:e.length>=6&&/^[A-Z][A-Za-z0-9]+$/.test(e)}function Xn(t){let e=t.trim();return!!(!e||ei.test(e)||e.length>28&&!/[A-Z\u4e00-\u9fff]/.test(e)&&/^[a-z0-9_-]+$/.test(e))}function er(t,e){let n=e.jsonTitle?.trim(),r=ui(t,"").trim(),o=e.fileName.trim();return n&&!Xn(n)?n:r&&!Xn(r)?r:n||r||o}function nr(t){return Ko.test(t.trim())}function Ee(t){let e=t.trim().replace(/\([^)]*\)$/,""),n=Ct(e);return ti.test(n)}function Nt(t){let e=t.trim();return e?lt.test(e)||nr(e)||Ee(e)?!0:!!ut(e).symbolName:!1}function si(t){let e=t.trim();return!(!e||nr(e)||Ee(e))}function ai(t){let e=new Set,n=[];for(let r of t){let o=r.trim();!si(o)||e.has(o)||(e.add(o),n.push(o))}return n}function Wn(t){if(!t.includes("."))return 0;let e=t.split(".").pop()??"";return/^[a-z]/.test(e)?1:2}function ci(t,e){let n=Wn(t)-Wn(e);return n!==0?n:t.localeCompare(e)}function rr(t,e=[]){let n=[...new Set(e.map(i=>i.trim()).filter(Boolean))],r=new Set(n),o=[...new Set(t.map(i=>i.trim()).filter(Boolean))].filter(i=>!r.has(i));return o.sort(ci),[...n,...o].slice(0,He)}function Pt(t){return t.replace(/\s+/g," ").trim()}function Qn(t){return t.replace(/\\([\\`*_{}[\]()#+.!-])/g,"$1")}function ui(t,e=""){let n=t.split(/\r?\n/),r=0;for(;r<n.length&&!n[r].trim();)r+=1;if(r>=n.length)return e;let o=Qn(n[r].trim()),i=o.match(/^#+\s+(.+)$/);if(i)return Qn(i[1].trim());if(r+1<n.length){let s=n[r+1].trim();if(/^=+$/.test(s)||/^-+$/.test(s))return o}return o||e}function or(t){let e=Pt(t.join(" "));if(e.length<=mt)return e;let n=e.slice(0,mt);return e.length<=mt+kt?n:`${n} ${e.slice(-kt)}`}function li(t){let e=ai(t).join(" ");return e.length<=vt?e:e.slice(0,vt)}function ir(t){let e=Pt(t),{text:n,excerptTruncated:r}=Mn(e,je);return{leadText:n,excerptTruncated:r}}function di(t,e){let{leadText:n,excerptTruncated:r}=ir(t);return{leadText:n,excerptTruncated:r||!!e.trim()}}function sr(t,e){if(t.type==="code"){e.codeBlocks.push(t.value??"");return}if("children"in t&&Array.isArray(t.children)){for(let r of t.children)sr(r,e);return}let n=Pt(Rt(t));n&&e.bodyParts.push(n)}function mi(t){let e=Yn().use(Vn).use(Kn).parse(t),n=[],r=null,o=()=>{r&&((r.sectionTitle||r.bodyParts.length||r.codeBlocks.length)&&n.push(r),r=null)},i=()=>{r||(r={sectionTitle:"",bodyParts:[],codeBlocks:[]})};for(let s of e.children){if(s.type==="heading"){let a=s,c=Rt(a).trim();if(a.depth>=4&&c&&Nt(c)){o(),r={sectionTitle:c,bodyParts:[],codeBlocks:[]};continue}i(),c&&r.bodyParts.push(c);continue}i(),sr(s,r)}return o(),n.length===0?[{sectionTitle:"",bodyParts:[],codeBlocks:[]}]:n}function fi(t){return Ce.test(t)}function pi(t){return t.filter(e=>e.sectionTitle&&Nt(e.sectionTitle)).length}function gi(t){return{sectionTitle:t.map(e=>e.sectionTitle.trim()).join(" | "),bodyParts:t.flatMap(e=>e.bodyParts).slice(0,40),codeBlocks:t.flatMap(e=>e.codeBlocks).slice(0,8)}}function qn(t){let e=t.trim();return!e||lt.test(e)?lt.test(e):/对象说明$|枚举说明$/.test(e)?!0:Ee(e)}function hi(t){let e=t.filter(u=>!u.sectionTitle||!Nt(u.sectionTitle)),n=t.filter(u=>u.sectionTitle&&Nt(u.sectionTitle)),r=n.filter(u=>qn(u.sectionTitle)),o=n.filter(u=>!qn(u.sectionTitle)),i=Math.max(0,Te-r.length),s=o.slice(0,i),a=o.slice(i),c=a.filter(u=>Jn(u.sectionTitle)),f=a.filter(u=>!Jn(u.sectionTitle)),p=[];for(let u=0;u<f.length;u+=Mt)p.push(gi(f.slice(u,u+Mt)));return[...e,...r,...s,...c,...p]}function Si(t,e,n){let r=t.split(/\r?\n/).length,o=pi(e);return o===0?!1:fi(n)?r>=De&&o>=Ie:r>=Ae&&o>=we}var yi=/^\[h2\][A-Za-z]/;function Jn(t){return yi.test(t.trim())}function ar(t){if(!t.includes(" | ")){let n=ut(t);return n.symbolName?[n.symbolName]:[]}let e=[];for(let n of t.split(" | ")){let r=ut(n.trim()).symbolName;r&&e.push(r)}return e}function xi(t,e,n,r){let o=ar(t),i=tr(n,r);return e.symbolName&&i.push(e.symbolName),rr([...o,...i],o)}function Ei(t,e){let n=or(t.bodyParts),r=t.sectionTitle.trim(),o=ut(r),i=$n(t.bodyParts),s=Gn(r,i,o),a=ar(r),c=r?a.length>0?`${e.docTitle} ${a.join(" ")}`:`${e.docTitle} ${o.symbolName??r}`:e.docTitle,f=[e.docTitle,s,...t.bodyParts].join(" "),{leadText:p,excerptTruncated:u}=di(n,r);return{documentId:e.documentId,catalogId:e.catalogId,docTitle:e.docTitle,sectionTitle:r,titleTokens:c,headingsText:s,apiSymbols:xi(r,o,f,t.codeBlocks),bodySample:n,leadText:p,excerptTruncated:u}}function cr(t,e){for(let n of t){if(n.type==="heading"){let o=Rt(n).trim();o&&e.headings.push(o);continue}if(n.type==="code"){e.codeBlocks.push(n.value??"");continue}if("children"in n&&Array.isArray(n.children)){cr(n.children,e);continue}let r=Pt(Rt(n));r&&e.bodyParts.push(r)}}function _i(t){let e=Yn().use(Vn).use(Kn).parse(t),n={headings:[],bodyParts:[],codeBlocks:[]};return cr(e.children,n),n}function bi(t,e){let n=_i(t),r=e.docTitle?.trim()||e.documentId,o=or(n.bodyParts),i=[r,...n.headings,o].join(" "),{leadText:s,excerptTruncated:a}=ir(o);return{documentId:e.documentId,catalogId:e.catalogId,docTitle:r,sectionTitle:"",titleTokens:r,headingsText:li(n.headings),apiSymbols:rr(tr(i,n.codeBlocks)),bodySample:o,leadText:s,excerptTruncated:a}}function ur(t,e){let n=e.docTitle?.trim()||e.documentId,r=mi(t);return Si(t,r,e.documentId)?hi(r).filter(o=>o.sectionTitle||o.bodyParts.length>0||o.codeBlocks.length>0).map(o=>Ei(o,{...e,docTitle:n})):[bi(t,{...e,docTitle:n})]}async function Ai(t){let e=[];async function n(r){let o=await x.promises.readdir(r,{withFileTypes:!0});for(let i of o){if(i.name.startsWith("."))continue;let s=_.join(r,i.name);i.isDirectory()?await n(s):i.isFile()&&i.name.endsWith(".md")&&e.push(s)}}return await n(t),e}function wi(t,e){let n=_.relative(e,t).split(_.sep).join("/").split("/");if(n[0]==="docs"&&(n=n.slice(1)),n.length<2)return null;let r=n[0],o=$e[r];if(o===void 0)return null;let i=n[n.length-1].replace(/\.md$/,"");return n[n.length-1]=i,{documentId:n.join("/"),catalogId:o,docTitle:i}}async function Di(t){let e=t.replace(/\.md$/,".json");try{let n=await x.promises.readFile(e,"utf-8");return JSON.parse(n).title?.trim()||void 0}catch{return}}async function Ii(t,e){let n=wi(t,e);if(!n)return[];let r=await x.promises.readFile(t,"utf-8"),o=er(r,{jsonTitle:await Di(t),fileName:n.docTitle});return ur(r,{...n,docTitle:o})}async function Ti(t,e,n){let r=_.join(e,"search.db");return await Zn(r,t,async(o,i)=>{await n?.({current:o,total:i,message:`Building search index\u2026 ${o.toLocaleString()} / ${i.toLocaleString()} segments`})}),t.length}async function Ci(t){let e=await Ai(t),n=[];for(let r of e){let o=await Ii(r,t);n.push(...o)}return n}function Ri(t,e){return{indexVersion:H,docsZipSha256:t.docsZipSha256,termsHash:t.termsHash,synonymsHash:t.synonymsHash,segmentCount:e,builtAt:Date.now(),builtBy:t.builtBy}}async function dr(t){t.lexiconDir&&$t(t.lexiconDir);try{let e=await Ci(t.docsDir);await t.onProgress?.({current:0,total:e.length,message:`Building search index\u2026 0 / ${e.length.toLocaleString()} segments`}),await x.promises.mkdir(t.tmpDir,{recursive:!0});let n=await Ti(e,t.tmpDir,t.onProgress),r=Ri(t,n);return await x.promises.writeFile(_.join(t.tmpDir,"build-meta.json"),JSON.stringify(r,null,2)),await on(t.tmpDir),r}finally{t.lexiconDir&&$t(null)}}async function mr(){return x.promises.mkdtemp(_.join(lr.tmpdir(),"deveco-docs-"))}async function Ni(t,e){try{await x.promises.rename(t,e)}catch(n){let r=n.code;if(r!=="EPERM"&&r!=="EXDEV")throw n;await x.promises.cp(t,e,{recursive:!0}),await x.promises.rm(t,{recursive:!0,force:!0})}}async function fr(t){let e=_.join(t,"docs");try{await x.promises.access(e)}catch{return}let n=new Set(["docs","docs.zip"]);for(let r of await x.promises.readdir(e,{withFileTypes:!0})){if(n.has(r.name))continue;let o=_.join(e,r.name),i=_.join(t,r.name);await x.promises.rm(i,{recursive:!0,force:!0}),await Ni(o,i)}await x.promises.rm(_.join(e,"docs"),{recursive:!0,force:!0}),await x.promises.rm(_.join(e,"docs.zip"),{force:!0}),await x.promises.rm(e,{recursive:!0,force:!0})}async function gr(t){let e=Ht();await h.promises.mkdir(T.dirname(e),{recursive:!0}),await h.promises.appendFile(e,`${new Date().toISOString()} ${t}
65
- `)}async function Bi(t){let e=v();if(!e)throw new Error("docs.zip not found");await h.promises.rm(t,{recursive:!0,force:!0}),await h.promises.mkdir(t,{recursive:!0});let n=T.resolve(t),r=new Pi(e);for(let o of r.getEntries()){let i=T.resolve(n,o.entryName);if(!Y(i,n))throw new Error(`Unsafe docs.zip entry path: ${o.entryName}`);if(o.isDirectory){await h.promises.mkdir(i,{recursive:!0});continue}await h.promises.mkdir(T.dirname(i),{recursive:!0}),await h.promises.writeFile(i,o.getData())}await fr(t)}async function Mi(){await st({mode:"write"});let t=g(),e=C(),n=await h.promises.readdir(e);for(let r of n){let o=T.join(t,r);await h.promises.rm(o,{force:!0}),await h.promises.rename(T.join(e,r),o)}await h.promises.rm(e,{recursive:!0,force:!0}),await h.promises.rm(T.join(t,"orama.dpack"),{force:!0})}async function pr(t,e,n){e?.start(n),await B({state:"installing",phase:1,phaseLabel:"Installing index",message:n}),await un(t),Tt(),e&&(e.text="Documentation index installed.")}async function ki(t,e){try{return await pr(t,e,"Installing documentation index\u2026"),await _e(e),!0}catch(n){if(qt(n))throw n}try{return await ln(),Tt(),await pr(t,e,"Retrying documentation index install\u2026"),await _e(e),!0}catch(n){if(qt(n))throw n;let r=n instanceof Error?n.message:String(n);return await gr(`Bundled index install failed; falling back to local rebuild: ${r}`),!1}}async function vi(t,e,n){let r=C(),o=await mr();await h.promises.mkdir(g(),{recursive:!0}),await h.promises.rm(r,{recursive:!0,force:!0}),n?.start("Building search index\u2026"),await B({state:"indexing",phase:2,phaseLabel:"Building search index",message:"Building search index\u2026"});try{await Bi(o),await dr({docsDir:o,tmpDir:r,docsZipSha256:e,termsHash:yt(),synonymsHash:St(),builtBy:t.builtBy??"doc-init",onProgress:async i=>{n&&(n.text=i.message),await B({state:"indexing",current:i.current,total:i.total,message:i.message})}})}finally{await h.promises.rm(o,{recursive:!0,force:!0})}await B({state:"persisting",phase:3,phaseLabel:"Persisting index",message:"Persisting index\u2026"}),await Mi(),Tt()}async function _e(t){await B({state:"done",phase:3,phaseLabel:"Done",message:"Documentation ready.",error:null}),t?.succeed("Documentation ready.")}async function Fi(t){let e=await te(),n=e?`Documentation already up to date. Documents: ${e.segmentCount.toLocaleString()}`:"Documentation already up to date.";t?.succeed(n),await B({state:"done",message:n,error:null})}async function zi(t,e){let n=t instanceof Error?t.message:String(t);throw await B({state:"error",error:n}),await gr(`ERROR: ${n}`),e?.fail(n),t}async function Hi(){let t=g();await h.promises.mkdir(t,{recursive:!0});let e=ft();return h.existsSync(e)||await h.promises.writeFile(e,"","utf-8"),e}async function ji(){let t=await Hi();return Oi.lock(t,{stale:1800*1e3})}async function Ui(){let t=v(),e=(t?await ht(t):null)??await Kt();if(!e)throw new Error("docs.zip not found");return e}async function Zi(t,e){let n=await Ui(),r=t.force||await Sn(t.force),o=await ee(t.force);if(!r&&!o&&ne()){await Fi(e);return}!t.force&&cn(n)&&await ki(n,e)||(await vi(t,n,e),await _e(e))}var Ot=class{static async run(e={}){let n=e.background??!1,o=e.quiet??n?void 0:Li({text:"Checking documentation\u2026",color:"cyan"}),i;try{e.assumeStorageSafe||await st({mode:"write"}),i=await ji(),await Vt(hn("Starting documentation setup\u2026")),await Zi(e,o)}catch(s){if(i)return zi(s,o);throw s}finally{i&&await i()}}};var $i=process.env.DEVECO_CLI_POSTINSTALL?"postinstall":"doc-init";Ot.run({background:!0,builtBy:$i}).then(()=>{process.exit(0)}).catch(()=>{process.exit(1)});
64
+ `),a=n.length;for(let c=0;c<a;c+=v){let f=n.slice(c,c+v),p=await Promise.all(f.map(async E=>({source:E,searchText:await xt(E)})));o.transaction(E=>{for(let h of E){let _=To(o,i,h.source);s.run(_,h.source.sectionTitle,h.source.leadText,h.searchText,h.source.excerptTruncated?1:0)}})(p),await r?.(Math.min(c+f.length,a),a)}o.exec("ANALYZE"),o.exec("VACUUM"),o.close()}function Co(t,e,n,r,o,i,s){let a=Do(t,e);return _t({all(c,...f){return a.prepare(c).all(...f)}},n,r,o,i,s)}async function zn(){let e=(await import("better-sqlite3")).default;return{kind:"better-sqlite3",resetCache:Ao,buildSearchIndex:(n,r,o)=>wo(e,n,r,o),searchIndex:(n,r,o,i,s,a,c)=>Promise.resolve(Co(e,i,r,o,s,a,c))}}import{readFile as Ro,stat as No,writeFile as Oo}from"fs/promises";var fe=null,P=null;async function pe(){return fe||(fe=(async()=>{let t=(await import("@sqlite.org/sqlite-wasm")).default;return t()})()),fe}function Po(t){return{all(e,...n){let r=t.prepare(e);n.length>0&&r.bind(n);let o=[];for(;r.step();)o.push(r.get({}));return r.finalize(),o}}}async function Lo(t){let e=await No(t);if(P&&P.dbPath===t&&P.mtimeMs===e.mtimeMs)return P.db;P?.db.close();let n=await pe(),r=n.capi,o=n.wasm,i=new Uint8Array(await Ro(t)),s=o.allocFromTypedArray(i),a=new n.oo1.DB(":memory:"),c=r.SQLITE_DESERIALIZE_READONLY|r.SQLITE_DESERIALIZE_RESIZEABLE|r.SQLITE_DESERIALIZE_FREEONCLOSE;return r.sqlite3_deserialize(a.pointer,"main",s,i.byteLength,i.byteLength,c),P={dbPath:t,mtimeMs:e.mtimeMs,db:a},a}function Hn(){P?.db.close(),P=null}async function Bo(t,e,n,r){t.exec("BEGIN");for(let o of r){let i=n(o.source);e.bind([i,o.source.sectionTitle,o.source.leadText,o.searchText,o.source.excerptTruncated?1:0]),e.step(),e.reset()}t.exec("COMMIT")}function Mo(t,e,n){return r=>{let o=e.get(r.documentId);if(o!==void 0)return o;let i=t.selectValue("SELECT id FROM documents WHERE document_id = ?",[r.documentId]);if(i!=null){let a=Number(i);return e.set(r.documentId,a),a}n.bind([r.documentId,r.catalogId,r.docTitle]),n.step(),n.reset();let s=Number(t.selectValue("SELECT last_insert_rowid()"));return e.set(r.documentId,s),s}}async function ko(t,e,n){await G();let r=await pe(),o=new r.oo1.DB(":memory:","c");o.exec(bt);let i=new Map,s=o.prepare("INSERT INTO documents(document_id, catalog_id, doc_title) VALUES (?, ?, ?)"),a=o.prepare("INSERT INTO segments(doc_id, section_title, lead_text, search_text, excerpt_truncated) VALUES (?, ?, ?, ?, ?)"),c=Mo(o,i,s),f=e.length;for(let u=0;u<f;u+=v){let E=e.slice(u,u+v),h=await Promise.all(E.map(async _=>({source:_,searchText:await xt(_)})));await Bo(o,a,c,h),await n?.(Math.min(u+E.length,f),f)}o.exec("ANALYZE");let p=r.capi.sqlite3_js_db_export(o);await Oo(t,p),o.close(),Hn()}async function Fo(t,e,n,r,o,i){let s=await Lo(t);return _t(Po(s),e,n,r,o,i)}async function ge(){return await pe(),{kind:"sqlite-wasm",resetCache:Hn,buildSearchIndex:ko,searchIndex:(t,e,n,r,o,i,s)=>Fo(r,e,n,o,i,s)}}var At=null,he=null;function vo(){return W.existsSync(V())}function zo(t){let e=V(),n={backend:"sqlite-wasm",reason:"better-sqlite3-load-failed",message:t,createdAt:new Date().toISOString()};W.mkdirSync(jn.dirname(e),{recursive:!0}),nt(e),W.writeFileSync(e,JSON.stringify(n,null,2))}async function Ho(){if(vo())return ge();try{let t=await zn();return k("doc-index: using better-sqlite3 SQLite backend"),t}catch(t){let e=t instanceof Error?t.message:String(t);zo(e),k(`doc-index: better-sqlite3 unavailable (${e}); falling back to sqlite-wasm`)}return ge()}async function Se(){return At||(At=Ho().then(t=>(he=t,t))),At}function Zn(){he?.resetCache(),At=null,he=null}function Dt(){Zn()}async function Un(t,e,n){await(await Se()).buildSearchIndex(t,e,n)}import{unified as Yn}from"unified";import Vn from"remark-parse";import Kn from"remark-gfm";import{toString as Tt}from"mdast-util-to-string";var jo=/^(.+?)(\d+\+)?(对象|枚举|错误码)说明$/,Zo=/^\[h2\]([A-Za-z][A-Za-z0-9]*)(\d+\+)?$/,Uo=/^(.{2,20}?)\s*[((]([A-Za-z][a-zA-Z0-9]{1,40})[))]\s*$/,$o=/^([A-Za-z@][A-Za-z0-9@]*?)(\d+\+)?$/,Go=/^(系统能力|元服务API|参数|返回值|说明|\*\*|表格|\|)/;function It(t){let e=t.trim(),n=e.match($o);return n?n[1]:e}function Xo(t){let e=t.match(jo);if(!e)return;let n=It(e[1].trim());return{displayTitle:t,symbolName:n,searchExtras:[n,e[3]]}}function Wo(t){let e=It(t.replace(/\([^)]*\)$/,""));if(/^[A-Z][A-Za-z0-9]*$/.test(e))return{displayTitle:t,symbolName:e,searchExtras:[e]};if(/^[A-Z][A-Za-z0-9]*(\([^)]*\))?$/.test(t))return{displayTitle:t,symbolName:e,searchExtras:[e]}}function st(t){let e=t.trim();return e?Xo(e)??(()=>{let n=e.match(Zo);if(n){let r=n[1];return{displayTitle:e,symbolName:r,searchExtras:[r]}}})()??(()=>{let n=e.match(Uo);if(!n)return;let r=n[1].trim(),o=n[2].trim();return{displayTitle:e,symbolName:o,searchExtras:[r,o]}})()??Wo(e)??{displayTitle:e,searchExtras:[]}:{displayTitle:"",searchExtras:[]}}function Qo(t){if(t.length<2||t.length>36||Go.test(t))return!1;let e=[...t.replace(/\s/g,"")];return e.length===0?!1:e.filter(r=>new RegExp("\\p{Script=Han}","u").test(r)).length/e.length>=.4}function $n(t){for(let e of t){let n=e.trim().replace(/[。.!!??;;]+$/u,"").trim();if(Qo(n))return n}return""}function Gn(t,e,n){let r=[t,...n.searchExtras,e].filter(Boolean);return[...new Set(r)].join(" ")}var qo=/[A-Z][a-zA-Z0-9]+(?:\.[a-zA-Z][a-zA-Z0-9]+)*/g,at=/@[A-Z][a-zA-Z]+/g,Jo=/^[A-Z][A-Za-z0-9]*\.[A-Za-z][A-Za-z0-9]+/,Yo=/^[A-Z][A-Za-z0-9]+(?:\([^)]*\))?$/,Vo=/^[a-z0-9]+(?:[-_][a-z0-9]+)+$/,Ko=new Set(["API","Action","Code","Connect","Connection","Context","Direction","Element","Elements","Entry","Focused","Module","Modules","Name","Names","Stage","Type","Types","Value","Values","Rect","Error"]),ti=new Set(["HAP","HSP","HAR","NAPI","CAPI","NDK","ArkTS","ArkUI","OHPM"]),ei=new Set(["JSON","Object","Array","Promise","console","Math","Date","String","Number","Boolean","Error","Function","Map","Set","RegExp"]);function tr(t,e){let n=new Set,r=[t,...e];for(let o of r){for(let i of re(o)){A(n,i);let s=ht(i);s&&A(n,s)}for(let i of oe(o))A(n,i);for(let i of o.matchAll(qo)){let s=i[0];ni(s)&&n.add(s)}for(let i of o.matchAll(at))n.add(i[0])}return U([...n])}function ni(t){let e=t.trim();if(!e||at.test(e))return!!e;if(e.includes(".")){let n=e.split(".")[0]??"";return ei.has(n)?!1:/^[A-Z]/.test(n)}return Ko.has(e)?!1:ti.has(e)?!0:e.length<=3?!1:/^[A-Z][a-z]+[A-Z]/.test(e)?!0:e.length>=6&&/^[A-Z][A-Za-z0-9]+$/.test(e)}function Xn(t){let e=t.trim();return!!(!e||Vo.test(e)||e.length>28&&!/[A-Z\u4e00-\u9fff]/.test(e)&&/^[a-z0-9_-]+$/.test(e))}function er(t,e){let n=e.jsonTitle?.trim(),r=si(t,"").trim(),o=e.fileName.trim();return n&&!Xn(n)?n:r&&!Xn(r)?r:n||r||o}function nr(t){return Jo.test(t.trim())}function ye(t){let e=t.trim().replace(/\([^)]*\)$/,""),n=It(e);return Yo.test(n)}function wt(t){let e=t.trim();return e?at.test(e)||nr(e)||ye(e)?!0:!!st(e).symbolName:!1}function ri(t){let e=t.trim();return!(!e||nr(e)||ye(e))}function oi(t){let e=new Set,n=[];for(let r of t){let o=r.trim();!ri(o)||e.has(o)||(e.add(o),n.push(o))}return n}function Wn(t){if(!t.includes("."))return 0;let e=t.split(".").pop()??"";return/^[a-z]/.test(e)?1:2}function ii(t,e){let n=Wn(t)-Wn(e);return n!==0?n:t.localeCompare(e)}function rr(t,e=[]){let n=[...new Set(e.map(i=>i.trim()).filter(Boolean))],r=new Set(n),o=[...new Set(t.map(i=>i.trim()).filter(Boolean))].filter(i=>!r.has(i));return o.sort(ii),[...n,...o].slice(0,He)}function Ct(t){return t.replace(/\s+/g," ").trim()}function Qn(t){return t.replace(/\\([\\`*_{}[\]()#+.!-])/g,"$1")}function si(t,e=""){let n=t.split(/\r?\n/),r=0;for(;r<n.length&&!n[r].trim();)r+=1;if(r>=n.length)return e;let o=Qn(n[r].trim()),i=o.match(/^#+\s+(.+)$/);if(i)return Qn(i[1].trim());if(r+1<n.length){let s=n[r+1].trim();if(/^=+$/.test(s)||/^-+$/.test(s))return o}return o||e}function or(t){let e=Ct(t.join(" "));if(e.length<=ut)return e;let n=e.slice(0,ut);return e.length<=ut+Lt?n:`${n} ${e.slice(-Lt)}`}function ai(t){let e=oi(t).join(" ");return e.length<=Bt?e:e.slice(0,Bt)}function ir(t){let e=Ct(t),{text:n,excerptTruncated:r}=Mn(e,je);return{leadText:n,excerptTruncated:r}}function ci(t,e){let{leadText:n,excerptTruncated:r}=ir(t);return{leadText:n,excerptTruncated:r||!!e.trim()}}function sr(t,e){if(t.type==="code"){e.codeBlocks.push(t.value??"");return}if("children"in t&&Array.isArray(t.children)){for(let r of t.children)sr(r,e);return}let n=Ct(Tt(t));n&&e.bodyParts.push(n)}function ui(t){let e=Yn().use(Vn).use(Kn).parse(t),n=[],r=null,o=()=>{r&&((r.sectionTitle||r.bodyParts.length||r.codeBlocks.length)&&n.push(r),r=null)},i=()=>{r||(r={sectionTitle:"",bodyParts:[],codeBlocks:[]})};for(let s of e.children){if(s.type==="heading"){let a=s,c=Tt(a).trim();if(a.depth>=4&&c&&wt(c)){o(),r={sectionTitle:c,bodyParts:[],codeBlocks:[]};continue}i(),c&&r.bodyParts.push(c);continue}i(),sr(s,r)}return o(),n.length===0?[{sectionTitle:"",bodyParts:[],codeBlocks:[]}]:n}function li(t){return Ce.test(t)}function di(t){return t.filter(e=>e.sectionTitle&&wt(e.sectionTitle)).length}function mi(t){return{sectionTitle:t.map(e=>e.sectionTitle.trim()).join(" | "),bodyParts:t.flatMap(e=>e.bodyParts).slice(0,40),codeBlocks:t.flatMap(e=>e.codeBlocks).slice(0,8)}}function qn(t){let e=t.trim();return!e||at.test(e)?at.test(e):/对象说明$|枚举说明$/.test(e)?!0:ye(e)}function fi(t){let e=t.filter(u=>!u.sectionTitle||!wt(u.sectionTitle)),n=t.filter(u=>u.sectionTitle&&wt(u.sectionTitle)),r=n.filter(u=>qn(u.sectionTitle)),o=n.filter(u=>!qn(u.sectionTitle)),i=Math.max(0,we-r.length),s=o.slice(0,i),a=o.slice(i),c=a.filter(u=>Jn(u.sectionTitle)),f=a.filter(u=>!Jn(u.sectionTitle)),p=[];for(let u=0;u<f.length;u+=Pt)p.push(mi(f.slice(u,u+Pt)));return[...e,...r,...s,...c,...p]}function pi(t,e,n){let r=t.split(/\r?\n/).length,o=di(e);return o===0?!1:li(n)?r>=Ie&&o>=Te:r>=Ae&&o>=De}var gi=/^\[h2\][A-Za-z]/;function Jn(t){return gi.test(t.trim())}function ar(t){if(!t.includes(" | ")){let n=st(t);return n.symbolName?[n.symbolName]:[]}let e=[];for(let n of t.split(" | ")){let r=st(n.trim()).symbolName;r&&e.push(r)}return e}function hi(t,e,n,r){let o=ar(t),i=tr(n,r);return e.symbolName&&i.push(e.symbolName),rr([...o,...i],o)}function Si(t,e){let n=or(t.bodyParts),r=t.sectionTitle.trim(),o=st(r),i=$n(t.bodyParts),s=Gn(r,i,o),a=ar(r),c=r?a.length>0?`${e.docTitle} ${a.join(" ")}`:`${e.docTitle} ${o.symbolName??r}`:e.docTitle,f=[e.docTitle,s,...t.bodyParts].join(" "),{leadText:p,excerptTruncated:u}=ci(n,r);return{documentId:e.documentId,catalogId:e.catalogId,docTitle:e.docTitle,sectionTitle:r,titleTokens:c,headingsText:s,apiSymbols:hi(r,o,f,t.codeBlocks),bodySample:n,leadText:p,excerptTruncated:u}}function cr(t,e){for(let n of t){if(n.type==="heading"){let o=Tt(n).trim();o&&e.headings.push(o);continue}if(n.type==="code"){e.codeBlocks.push(n.value??"");continue}if("children"in n&&Array.isArray(n.children)){cr(n.children,e);continue}let r=Ct(Tt(n));r&&e.bodyParts.push(r)}}function yi(t){let e=Yn().use(Vn).use(Kn).parse(t),n={headings:[],bodyParts:[],codeBlocks:[]};return cr(e.children,n),n}function xi(t,e){let n=yi(t),r=e.docTitle?.trim()||e.documentId,o=or(n.bodyParts),i=[r,...n.headings,o].join(" "),{leadText:s,excerptTruncated:a}=ir(o);return{documentId:e.documentId,catalogId:e.catalogId,docTitle:r,sectionTitle:"",titleTokens:r,headingsText:ai(n.headings),apiSymbols:rr(tr(i,n.codeBlocks)),bodySample:o,leadText:s,excerptTruncated:a}}function ur(t,e){let n=e.docTitle?.trim()||e.documentId,r=ui(t);return pi(t,r,e.documentId)?fi(r).filter(o=>o.sectionTitle||o.bodyParts.length>0||o.codeBlocks.length>0).map(o=>Si(o,{...e,docTitle:n})):[xi(t,{...e,docTitle:n})]}async function _i(t,e,n){let r=Ee.join(e,"search.db");return await Un(r,t,async(o,i)=>{await n?.({current:o,total:i,message:`Building search index\u2026 ${o.toLocaleString()} / ${i.toLocaleString()} segments`})}),t.length}function bi(t){return t.getEntries().filter(e=>e.isDirectory||!e.entryName.endsWith(".md")?!1:e.entryName.split("/").every(r=>!r.startsWith(".")))}function Ai(t){let e=t.split("/");if(e[0]==="docs"&&(e=e.slice(1)),e.length<2)return null;let n=e[0],r=$e[n];if(r===void 0)return null;let o=e[e.length-1].replace(/\.md$/,"");return e[e.length-1]=o,{documentId:e.join("/"),catalogId:r,docTitle:o}}function Di(t,e){let n=e.replace(/\.md$/,".json"),r=t.getEntry(n);if(r)try{return JSON.parse(r.getData().toString("utf-8")).title?.trim()||void 0}catch{return}}function Ii(t,e){let n=Ai(t.entryName);if(!n)return[];let r=t.getData().toString("utf-8"),o=er(r,{jsonTitle:Di(e,t.entryName),fileName:n.docTitle});return ur(r,{...n,docTitle:o})}async function Ti(t){let e=new Ei(t),n=bi(e),r=[];for(let o of n){let i=Ii(o,e);r.push(...i)}return r}function wi(t,e){return{indexVersion:F,docsZipSha256:t.docsZipSha256,termsHash:t.termsHash,synonymsHash:t.synonymsHash,segmentCount:e,builtAt:Date.now(),builtBy:t.builtBy}}async function lr(t){t.lexiconDir&&Zt(t.lexiconDir);try{let e=await Ti(t.docsZipPath);await t.onProgress?.({current:0,total:e.length,message:`Building search index\u2026 0 / ${e.length.toLocaleString()} segments`}),await xe.promises.mkdir(t.tmpDir,{recursive:!0});let n=await _i(e,t.tmpDir,t.onProgress),r=wi(t,n);return await xe.promises.writeFile(Ee.join(t.tmpDir,"build-meta.json"),JSON.stringify(r,null,2)),await on(t.tmpDir),r}finally{t.lexiconDir&&Zt(null)}}async function mr(t){let e=vt();await x.promises.mkdir(Q.dirname(e),{recursive:!0}),await x.promises.appendFile(e,`${new Date().toISOString()} ${t}
65
+ `)}async function Ni(){await rt({mode:"write"});let t=g(),e=I(),n=await x.promises.readdir(e);for(let r of n){let o=Q.join(t,r);await x.promises.rm(o,{force:!0}),await x.promises.rename(Q.join(e,r),o)}await x.promises.rm(e,{recursive:!0,force:!0}),await x.promises.rm(Q.join(t,"orama.dpack"),{force:!0})}async function dr(t,e,n){e?.start(n),await O({state:"installing",phase:1,phaseLabel:"Installing index",message:n}),await un(t),Dt(),e&&(e.text="Documentation index installed.")}async function Oi(t,e){try{return await dr(t,e,"Installing documentation index\u2026"),await _e(e),!0}catch(n){if(Wt(n))throw n}try{return await ln(),Dt(),await dr(t,e,"Retrying documentation index install\u2026"),await _e(e),!0}catch(n){if(Wt(n))throw n;let r=n instanceof Error?n.message:String(n);return await mr(`Bundled index install failed; falling back to local rebuild: ${r}`),!1}}async function Pi(t,e,n){let r=I(),o=B();if(!o)throw new Error("docs.zip not found");await x.promises.mkdir(g(),{recursive:!0}),await x.promises.rm(r,{recursive:!0,force:!0}),n?.start("Building search index\u2026"),await O({state:"indexing",phase:2,phaseLabel:"Building search index",message:"Building search index\u2026"}),await lr({docsZipPath:o,tmpDir:r,docsZipSha256:e,termsHash:gt(),synonymsHash:pt(),builtBy:t.builtBy??"doc-init",onProgress:async i=>{n&&(n.text=i.message),await O({state:"indexing",current:i.current,total:i.total,message:i.message})}}),await O({state:"persisting",phase:3,phaseLabel:"Persisting index",message:"Persisting index\u2026"}),await Ni(),Dt()}async function _e(t){await O({state:"done",phase:3,phaseLabel:"Done",message:"Documentation ready.",error:null}),t?.succeed("Documentation ready.")}async function Li(t){let e=await Vt(),n=e?`Documentation already up to date. Documents: ${e.segmentCount.toLocaleString()}`:"Documentation already up to date.";t?.succeed(n),await O({state:"done",message:n,error:null})}async function Bi(t,e){let n=t instanceof Error?t.message:String(t);throw await O({state:"error",error:n}),await mr(`ERROR: ${n}`),e?.fail(n),t}async function Mi(){let t=g();await x.promises.mkdir(t,{recursive:!0});let e=lt();return x.existsSync(e)||await x.promises.writeFile(e,"","utf-8"),e}async function ki(){let t=await Mi();return Ci.lock(t,{stale:1800*1e3})}async function Fi(){let t=B(),e=(t?await ft(t):null)??await Yt();if(!e)throw new Error("docs.zip not found");return e}async function vi(t,e){let n=await Fi(),r=t.force||await Sn(t.force),o=await Kt(t.force);if(!r&&!o&&te()){await Li(e);return}!t.force&&cn(n)&&await Oi(n,e)||(await Pi(t,n,e),await _e(e))}var Rt=class{static async run(e={}){let n=e.background??!1,o=e.quiet??n?void 0:Ri({text:"Checking documentation\u2026",color:"cyan"}),i;try{e.assumeStorageSafe||await rt({mode:"write"}),i=await ki(),await Jt(hn("Starting documentation setup\u2026")),await vi(e,o)}catch(s){throw i&&await Bi(s,o),s}finally{i&&await i()}}};var zi=process.env.DEVECO_CLI_POSTINSTALL?"postinstall":"doc-init";Rt.run({background:!0,builtBy:zi}).then(()=>{process.exit(0)}).catch(()=>{process.exit(1)});
package/index.zip CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deveco-test/deveco-cli",
3
- "version": "1.3.0-Test.7",
3
+ "version": "1.3.0-Test.9",
4
4
  "description": "HarmonyOS application development command line tool",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -48,11 +48,14 @@
48
48
  "@eslint/js": "^10.0.1",
49
49
  "@types/adm-zip": "^0.5.8",
50
50
  "@types/better-sqlite3": "^7.6.13",
51
- "@types/yauzl": "^2.10.3",
52
51
  "@types/fs-extra": "^11.0.4",
53
52
  "@types/global-agent": "^3.0.0",
54
53
  "@types/node": "^25.6.0",
54
+ "@types/node-forge": "^1.3.14",
55
+ "@types/proper-lockfile": "^4.1.4",
56
+ "@types/semver": "^7.7.1",
55
57
  "@types/turndown": "^5.0.5",
58
+ "@types/yauzl": "^2.10.3",
56
59
  "eslint": "^10.2.1",
57
60
  "generate-license-file": "^4.2.1",
58
61
  "husky": "^9.1.7",
@@ -61,7 +64,6 @@
61
64
  "tsx": "^4.21.0",
62
65
  "turndown": "^7.2.4",
63
66
  "typescript": "^6.0.3",
64
- "@types/node-forge": "^1.3.14",
65
67
  "typescript-eslint": "^8.59.1"
66
68
  },
67
69
  "dependencies": {
@@ -77,21 +79,22 @@
77
79
  "global-agent": "^4.1.3",
78
80
  "json5": "^2.2.3",
79
81
  "mdast-util-to-string": "^4.0.0",
82
+ "node-forge": "^1.4.0",
80
83
  "ora": "^9.4.0",
81
84
  "p-limit": "^5.0.0",
82
85
  "proper-lockfile": "^4.1.2",
83
86
  "regedit": "^5.1.4",
84
87
  "remark-gfm": "^4.0.1",
85
88
  "remark-parse": "^11.0.0",
89
+ "semver": "^7.8.5",
86
90
  "smol-toml": "^1.6.1",
87
91
  "unified": "^11.0.5",
88
92
  "yauzl": "^3.2.0",
89
- "node-forge": "^1.4.0",
90
93
  "zod": "^4.4.3"
91
94
  },
92
95
  "optionalDependencies": {
93
- "better-sqlite3": "^12.11.1",
94
- "@node-rs/jieba-wasm32-wasi": "2.0.1"
96
+ "@node-rs/jieba-wasm32-wasi": "2.0.1",
97
+ "better-sqlite3": "^12.11.1"
95
98
  },
96
99
  "overrides": {
97
100
  "dotenv": "16.4.7"