@deveco-test/hmos-deveco-cli 0.2.1 → 0.2.2

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 H from"path";import ei from"adm-zip";import ni from"proper-lockfile";import ri from"ora";import*as b from"fs";import*as j from"path";var ht=["harmonyos-guides","harmonyos-references","best-practices","harmonyos-faqs","harmonyos-releases","harmonyos-roadmap"],G={"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 X="1.9.1",xi=48*1024*1024,te=280,ee=6,ne=100,re=3,oe=28,St=10,ie=/API参考|APIReference/i;var se=6,W=700,yt=250,xt=400,ae=1320,ce=120,ue=450,le=250,de=500,me=480,fe=80,pe=200,ge=60,he=200,Se=40,ye=200,xe=200,_e=40,B=500,Ee=Object.fromEntries(ht.map((t,e)=>[G[t],e])),w=Object.fromEntries(ht.map((t,e)=>[t,e]));import*as be from"fs";import*as m from"path";import{fileURLToPath as Te}from"url";import*as Q from"path";import{homedir as Zn}from"os";var Un="deveco-cli";function $n(t){let e=t.trim();return(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))&&(e=e.slice(1,-1).trim()),e}function Ae(){return Q.join(Zn(),".local","share",Un)}function _t(){let t=process.env.DEVECO_CLI_DATA_DIR;if(t===void 0||t==="")return Ae();let e=$n(t);return e?Q.resolve(e):Ae()}var Gn="docs";function q(){return m.join(_t(),Gn)}function x(){return m.join(q(),".index")}function Ie(){return m.join(x(),"build.lock")}function Et(){return m.join(x(),"build-status.json")}function Y(){return m.join(x(),"build-meta.json")}function V(){return m.join(x(),"search.db")}function M(){return m.join(x(),".tmp")}function Xn(){return m.join(_t(),"logs")}function At(){return m.join(Xn(),"doc-init.log")}function Wn(t,e){let n=e;for(;!n.endsWith(`${m.sep}dist`)&&n!==m.dirname(n);)n=m.dirname(n);return n}function De(t,e){return m.dirname(Wn(t,e))}function Qn(){let t=Te(import.meta.url),e=m.dirname(t);return t.includes(`${m.sep}dist${m.sep}`)?De(t,e):m.join(e,"..","..","..")}function qn(...t){let e=Te(import.meta.url),n=m.dirname(e);return e.includes(`${m.sep}dist${m.sep}`)?[m.join(De(e,n),...t)]:[m.join(n,"..","..","..",...t)]}function we(...t){for(let e of qn(...t))if(be.existsSync(e))return e;return null}function O(){return we("docs.zip")}function bt(){return we("index.zip")}function Ce(){return m.join(Qn(),"index","data")}import*as D from"fs";import*as L from"path";var P=["harmonyos-terms.txt","harmonyos-synonyms.json","harmonyos-stopwords.txt"],Tt=class extends Error{constructor(e){super(e),this.name="LexiconNotFoundError"}};var It=null;function Dt(t){It=t}function Re(){if(It)return It;let t=x();if(P.every(o=>D.existsSync(L.join(t,o))))return t;let n=Ce();if(P.every(o=>D.existsSync(L.join(n,o))))return n;throw new Tt("Lexicon files not found. Install the documentation index first (index.zip).")}function k(t){let e=L.join(Re(),t);return D.readFileSync(e,"utf-8")}function Ne(t,e){return D.readFileSync(L.join(e,t),"utf-8")}async function Oe(t,e=Re()){await D.promises.mkdir(t,{recursive:!0});for(let n of P){let r=L.join(e,n),o=L.join(t,n);await D.promises.copyFile(r,o)}}import*as wt from"fs";import*as Yn from"yauzl";function Ct(){let t=O();return t!==null&&wt.existsSync(t)}import*as S from"fs";import*as C from"path";import Le from"adm-zip";var Pe=["search.db","build-meta.json",...P],Vn=["corpus.json","corpus-offsets.json","orama.dpack"];async function Kn(t){for(let e of Vn)await S.promises.rm(C.join(t,e),{force:!0})}async function Jn(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 tr(t){let n=new Le(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 er(t){let e=x();await S.promises.mkdir(e,{recursive:!0});for(let n of Pe){let r=C.join(e,n);await S.promises.rm(r,{force:!0}),await S.promises.rename(C.join(t,n),r)}await Kn(e),await S.promises.rm(M(),{recursive:!0,force:!0})}function Rt(){let t=bt();return t!==null&&S.existsSync(t)}async function Be(t){let e=bt();if(!e)throw new Error("index.zip not found");let n=tr(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=M();await S.promises.rm(r,{recursive:!0,force:!0}),await S.promises.mkdir(r,{recursive:!0});let o=new Le(e);for(let s of Pe){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 er(r),await S.promises.mkdir(q(),{recursive:!0}),await Jn(q()),i}import{createHash as Me}from"crypto";import*as ke from"fs";async function K(t){return new Promise((e,n)=>{let r=Me("sha256"),o=ke.createReadStream(t);o.on("data",i=>r.update(i)),o.on("error",n),o.on("end",()=>e(r.digest("hex")))})}function Fe(t){return Me("sha256").update(t,"utf8").digest("hex")}function ve(t,e){let n=e?Ne(t,e):k(t);return Fe(n)}function J(t){return ve("harmonyos-synonyms.json",t)}function tt(t){return ve("harmonyos-terms.txt",t)}var nr={state:"idle",phase:0,phaseLabel:"Idle",current:0,total:0,message:"",startedAt:0,updatedAt:0,error:null};async function ze(){try{let t=await b.promises.readFile(Et(),"utf-8");return JSON.parse(t)}catch{return{...nr}}}async function Nt(t){let e=Et();await b.promises.mkdir(j.dirname(e),{recursive:!0}),await b.promises.writeFile(e,JSON.stringify(t,null,2))}function He(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 R(t){let n={...await ze(),...t,updatedAt:Date.now()};return await Nt(n),n}async function Ot(){let t=O();return t?K(t):null}async function Lt(){try{let t=await b.promises.readFile(Y(),"utf-8");return JSON.parse(t)}catch{return null}}async function Pt(t=!1){if(t)return"no-index";let e=await Lt();if(!e||e.segmentCount===0)return"no-index";let n=await Ot();return n&&e.docsZipSha256!==n?"docs-changed":e.indexVersion!==X?"engine-upgraded":e.termsHash!==tt()?"terms-changed":e.synonymsHash!==J()?"synonyms-changed":null}function Bt(){if(!Ct()||!b.existsSync(V())||!b.existsSync(Y()))return!1;let t=j.dirname(V());if(!P.every(e=>b.existsSync(j.join(t,e))))return!1;try{let e=b.readFileSync(Y(),"utf-8");return JSON.parse(e).segmentCount>0}catch{return!1}}async function je(t=!1){return t?!0:Ct()?Bt()?await Pt()!==null:!0:!1}import*as y from"fs";import*as kn from"os";import*as _ from"path";var Ze=new Set(["picker","dialog","sheet","panel","popup","menu","layout","view","gesture","animation","transition","recognizer","manager","kit"]);var Ue=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"]),$e=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 rr=/@ohos\.[a-z][a-zA-Z0-9.]+/gi,or=/\b[a-z][a-z0-9]*[A-Z][a-zA-Z0-9]+\b/g,ir=/[A-Z][a-zA-Z0-9]{2,}/g,sr=/@[A-Z][a-zA-Z0-9]*/g,ar=/[a-z][a-zA-Z0-9]*\.[a-zA-Z][a-zA-Z0-9]+/g,Ge=6,cr=/^[a-z][a-z0-9]{2,}$/,ur=/^([a-z][a-z0-9]{2,})\s+([a-z][a-z0-9]{2,})$/,lr=/^@ohos\.[a-z][a-zA-Z0-9.]+$/i,dr=/^[a-z][a-z0-9]*[A-Z][a-zA-Z0-9]+$/,mr=/^[A-Z][a-zA-Z0-9]+$/;function Mt(t){return lr.test(t)}function fr(t){return dr.test(t)&&t.length>=Ge}function pr(t){return mr.test(t)}function kt(t){return Mt(t)||fr(t)||pr(t)}function gr(t){let e=t.trim().toLowerCase();return $e.has(e)?!1:Ze.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 et(t){let n=t.replace(/^@ohos\./i,"").split(".").filter(Boolean);return n[n.length-1]?.trim()||void 0}function Ft(t){return[...t.matchAll(rr)].map(e=>e[0])}function vt(t,e=Ge){let n=[];for(let r of t.matchAll(or))r[0].length>=e&&n.push(r[0]);return n}function F(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 T(t,e){let n=e.trim();if(!n)return;t.add(n);let r=n.toLowerCase();r!==n&&t.add(r)}function Sr(t){let e=new Set;T(e,t);let n=et(t);return n&&T(e,n),F([...e])}function zt(t){if(Mt(t))return Sr(t);let e=new Set;return T(e,t),F([...e])}function Ht(t){let e=t.trim();if(/[A-Z]/.test(e))return null;let n=e.match(ur);if(!n)return null;let r=n[1].toLowerCase(),o=n[2].toLowerCase();if(!cr.test(r)||Ue.has(r)||!gr(o))return null;let i=hr(r,o);return{first:r,second:o,camelCase:i,lower:i.toLowerCase()}}function Xe(t){let e=Ht(t.trim());return!e||e.second!=="manager"?null:e}function jt(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 We(t){let e=t.trim();if(kt(e))return zt(e);let n=new Set;for(let r of Ft(t)){T(n,r);let o=et(r);o&&T(n,o)}for(let r of vt(t))T(n,r);for(let r of t.matchAll(sr))n.add(r[0]);for(let r of t.matchAll(ar))n.add(r[0]);for(let r of t.matchAll(ir))r[0].length>=4&&n.add(r[0]);return F([...n])}function Qe(t){let e=t.trim();if(kt(e))return zt(e);let n=new Set,r=Ht(e);r&&T(n,r.camelCase);for(let o of We(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 F([...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 Ye(t){return I.pureApiSymbol.test(t.trim())}function qe(t){let e=t.trim();return I.stageModelExact.test(e)||I.stageModelEnglishExact.test(e)}var yr=[{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=>qe(t),weights:[{catalog:"harmonyos-guides",multiplier:1.85},{catalog:"harmonyos-references",multiplier:.55},{catalog:"harmonyos-faqs",multiplier:.85}]},{matches:t=>!qe(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=w[n];t.set(o,(t.get(o)??1)*r)}}function Ve(t,e){for(let n of yr)n.matches(t)&&xr(e,n.weights)}import*as Ke from"os";function Zt(){return _r()==="openharmony"}function _r(){return Ke.platform()}var nt=null,tn=null,$t=null,Je=!1,Ut=null;function Er(){if(nt)return nt;let t=k("harmonyos-stopwords.txt");return nt=new Set(t.split(`
2
- `).map(e=>e.trim()).filter(Boolean)),nt}function Ar(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 br(t){let e=Er(),n=[];for(let r of Ar(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 Tr(){let t=await import("jieba-wasm");tn=t.cut,$t=t.cut_for_search;let e=k("harmonyos-terms.txt");t.with_dict(e)}async function Ir(){let{Jieba:t}=await import("@node-rs/jieba"),{dict:e}=await import("@node-rs/jieba/dict.js"),n=t.withDict(e),r=k("harmonyos-terms.txt");n.loadDict(Buffer.from(r,"utf-8")),tn=n.cut.bind(n),$t=n.cutForSearch.bind(n)}async function v(){Je||(Ut||(Ut=(Zt()?Tr():Ir()).then(()=>{Je=!0})),await Ut)}async function Dr(t){return await v(),br($t(t,!0))}async function rt(t,e){let n=t.trim();if(!n||e<=0)return"";let r=(await Dr(n)).join(" ");return r.length<=e?r:r.slice(0,e)}async function wr(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 ot(t){let e=!!t.sectionTitle.trim(),n=t.titleTokens.trim(),r=e?me:ae,o=e?pe:ue,i=e?await wr(t.apiSymbols,o):await rt(t.apiSymbols.join(" "),o),a=(await Promise.all([rt(n,e?fe:ce),Promise.resolve(i),rt(t.headingsText,e?ge:le),rt(t.bodySample,e?he:de)])).filter(Boolean).join(" ");return a.length<=r?a:a.slice(0,r)}var en=["harmonyos-releases","harmonyos-roadmap"],Cr=new Set(en.map(t=>w[t])),js=en.map(t=>`${G[t]}/`);function Rr(t){return Cr.has(t)}function nn(t){let e=[],n=[];for(let r of t)Rr(r.catalog_id)?n.push(r):e.push(r);return[...e,...n]}var Nr=[{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 Z(t,e,n){let r=w[e];t.set(r,(t.get(r)??1)*n)}function Or(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)){Z(e,"harmonyos-guides",1.45),Z(e,"harmonyos-references",1.35);return}(o||i)&&Z(e,"harmonyos-references",1.55),/\b[A-Z][a-zA-Z]*(Gesture|Dialog|Sheet|Transition|Recognizer)\b/.test(n)&&Z(e,"harmonyos-references",1.75)}function rn(t){let e=new Map,n=t.trim();if(!n)return e;let r=Ye(n);Or(n,e),Ve(n,e);for(let o of Nr)o.pattern.test(n)&&(o.skipForPureApiSymbol&&r||Z(e,o.catalog,o.multiplier));return e}function it(t){process.env.DEVECO_CLI_DEBUG&&console.log(`[DEBUG] ${t}`)}var Lr=[" ","\u3002","\uFF0C","\uFF1B","\u3001",".","!","?"];function on(t,e){let n=-1;for(let r of Lr){let o=t.lastIndexOf(r);o>n&&(n=o)}return n>=e?n:-1}function sn(t,e){let n=t.trim();if(n.length<=e)return{text:n,excerptTruncated:!1};let r=n.slice(0,e),o=on(r,e-20),i=o>=0?o:e;return{text:n.slice(0,i).trimEnd(),excerptTruncated:!0}}function an(t,e,n={}){let{maxLen:r=xe,contextChars:o=_e,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(gt=>gt.trim()).filter(Boolean),c=0;for(let gt of a){let Jt=s.toLowerCase().indexOf(gt.toLowerCase());if(Jt>=0){c=Jt;break}}let f=Math.max(0,c-o),p=Math.min(s.length,f+r),u=s.slice(f,p),E=on(u,r-25);E>=0&&(p=f+E);let g=s.slice(f,p).trim(),A=f>0?"...":"",jn=p<s.length||i?"...":"";return`${A}${g}${jn}`}var Pr=`
1
+ import*as h from"fs";import*as H from"path";import ei from"adm-zip";import ni from"proper-lockfile";import ri from"ora";import*as b from"fs";import*as j from"path";var ht=["harmonyos-guides","harmonyos-references","best-practices","harmonyos-faqs","harmonyos-releases","harmonyos-roadmap"],G={"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 X="1.9.1",xi=48*1024*1024,te=280,ee=6,ne=100,re=3,oe=28,St=10,ie=/API参考|APIReference/i;var se=6,W=700,yt=250,xt=400,ae=1320,ce=120,ue=450,le=250,de=500,me=480,fe=80,pe=200,ge=60,he=200,Se=40,ye=200,xe=200,_e=40,B=500,Ee=Object.fromEntries(ht.map((t,e)=>[G[t],e])),w=Object.fromEntries(ht.map((t,e)=>[t,e]));import*as be from"fs";import*as m from"path";import{fileURLToPath as Te}from"url";import*as Q from"path";import{homedir as Zn}from"os";var Un="deveco-cli";function $n(t){let e=t.trim();return(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))&&(e=e.slice(1,-1).trim()),e}function Ae(){return Q.join(Zn(),".local","share",Un)}function _t(){let t=process.env.DEVECO_CLI_DATA_DIR;if(t===void 0||t==="")return Ae();let e=$n(t);return e?Q.resolve(e):Ae()}var Gn="docs";function q(){return m.join(_t(),Gn)}function x(){return m.join(q(),".index")}function Ie(){return m.join(x(),"build.lock")}function Et(){return m.join(x(),"build-status.json")}function Y(){return m.join(x(),"build-meta.json")}function V(){return m.join(x(),"search.db")}function M(){return m.join(x(),".tmp")}function Xn(){return m.join(_t(),"logs")}function At(){return m.join(Xn(),"doc-init.log")}function Wn(t,e){let n=e;for(;!n.endsWith(`${m.sep}dist`)&&n!==m.dirname(n);)n=m.dirname(n);return n}function De(t,e){return m.dirname(Wn(t,e))}function Qn(){let t=Te(import.meta.url),e=m.dirname(t);return t.includes(`${m.sep}dist${m.sep}`)?De(t,e):m.join(e,"..","..","..")}function qn(...t){let e=Te(import.meta.url),n=m.dirname(e);return e.includes(`${m.sep}dist${m.sep}`)?[m.join(De(e,n),...t)]:[m.join(n,"..","..","..",...t)]}function we(...t){for(let e of qn(...t))if(be.existsSync(e))return e;return null}function L(){return we("docs.zip")}function bt(){return we("index.zip")}function Ce(){return m.join(Qn(),"index","data")}import*as D from"fs";import*as O from"path";var P=["harmonyos-terms.txt","harmonyos-synonyms.json","harmonyos-stopwords.txt"],Tt=class extends Error{constructor(e){super(e),this.name="LexiconNotFoundError"}};var It=null;function Dt(t){It=t}function Re(){if(It)return It;let t=x();if(P.every(o=>D.existsSync(O.join(t,o))))return t;let n=Ce();if(P.every(o=>D.existsSync(O.join(n,o))))return n;throw new Tt("Lexicon files not found. Install the documentation index first (index.zip).")}function k(t){let e=O.join(Re(),t);return D.readFileSync(e,"utf-8")}function Ne(t,e){return D.readFileSync(O.join(e,t),"utf-8")}async function Le(t,e=Re()){await D.promises.mkdir(t,{recursive:!0});for(let n of P){let r=O.join(e,n),o=O.join(t,n);await D.promises.copyFile(r,o)}}import*as wt from"fs";import*as Yn from"yauzl";function Ct(){let t=L();return t!==null&&wt.existsSync(t)}import*as S from"fs";import*as C from"path";import Oe from"adm-zip";var Pe=["search.db","build-meta.json",...P],Vn=["corpus.json","corpus-offsets.json","orama.dpack"];async function Kn(t){for(let e of Vn)await S.promises.rm(C.join(t,e),{force:!0})}async function Jn(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 tr(t){let n=new Oe(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 er(t){let e=x();await S.promises.mkdir(e,{recursive:!0});for(let n of Pe){let r=C.join(e,n);await S.promises.rm(r,{force:!0}),await S.promises.rename(C.join(t,n),r)}await Kn(e),await S.promises.rm(M(),{recursive:!0,force:!0})}function Rt(){let t=bt();return t!==null&&S.existsSync(t)}async function Be(t){let e=bt();if(!e)throw new Error("index.zip not found");let n=tr(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=M();await S.promises.rm(r,{recursive:!0,force:!0}),await S.promises.mkdir(r,{recursive:!0});let o=new Oe(e);for(let s of Pe){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 er(r),await S.promises.mkdir(q(),{recursive:!0}),await Jn(q()),i}import{createHash as Me}from"crypto";import*as ke from"fs";async function K(t){return new Promise((e,n)=>{let r=Me("sha256"),o=ke.createReadStream(t);o.on("data",i=>r.update(i)),o.on("error",n),o.on("end",()=>e(r.digest("hex")))})}function Fe(t){return Me("sha256").update(t,"utf8").digest("hex")}function ve(t,e){let n=e?Ne(t,e):k(t);return Fe(n)}function J(t){return ve("harmonyos-synonyms.json",t)}function tt(t){return ve("harmonyos-terms.txt",t)}var nr={state:"idle",phase:0,phaseLabel:"Idle",current:0,total:0,message:"",startedAt:0,updatedAt:0,error:null};async function ze(){try{let t=await b.promises.readFile(Et(),"utf-8");return JSON.parse(t)}catch{return{...nr}}}async function Nt(t){let e=Et();await b.promises.mkdir(j.dirname(e),{recursive:!0}),await b.promises.writeFile(e,JSON.stringify(t,null,2))}function He(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 R(t){let n={...await ze(),...t,updatedAt:Date.now()};return await Nt(n),n}async function Lt(){let t=L();return t?K(t):null}async function Ot(){try{let t=await b.promises.readFile(Y(),"utf-8");return JSON.parse(t)}catch{return null}}async function Pt(t=!1){if(t)return"no-index";let e=await Ot();if(!e||e.segmentCount===0)return"no-index";let n=await Lt();return n&&e.docsZipSha256!==n?"docs-changed":e.indexVersion!==X?"engine-upgraded":e.termsHash!==tt()?"terms-changed":e.synonymsHash!==J()?"synonyms-changed":null}function Bt(){if(!Ct()||!b.existsSync(V())||!b.existsSync(Y()))return!1;let t=j.dirname(V());if(!P.every(e=>b.existsSync(j.join(t,e))))return!1;try{let e=b.readFileSync(Y(),"utf-8");return JSON.parse(e).segmentCount>0}catch{return!1}}async function je(t=!1){return t?!0:Ct()?Bt()?await Pt()!==null:!0:!1}import*as y from"fs";import*as kn from"os";import*as _ from"path";var Ze=new Set(["picker","dialog","sheet","panel","popup","menu","layout","view","gesture","animation","transition","recognizer","manager","kit"]);var Ue=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"]),$e=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 rr=/@ohos\.[a-z][a-zA-Z0-9.]+/gi,or=/\b[a-z][a-z0-9]*[A-Z][a-zA-Z0-9]+\b/g,ir=/[A-Z][a-zA-Z0-9]{2,}/g,sr=/@[A-Z][a-zA-Z0-9]*/g,ar=/[a-z][a-zA-Z0-9]*\.[a-zA-Z][a-zA-Z0-9]+/g,Ge=6,cr=/^[a-z][a-z0-9]{2,}$/,ur=/^([a-z][a-z0-9]{2,})\s+([a-z][a-z0-9]{2,})$/,lr=/^@ohos\.[a-z][a-zA-Z0-9.]+$/i,dr=/^[a-z][a-z0-9]*[A-Z][a-zA-Z0-9]+$/,mr=/^[A-Z][a-zA-Z0-9]+$/;function Mt(t){return lr.test(t)}function fr(t){return dr.test(t)&&t.length>=Ge}function pr(t){return mr.test(t)}function kt(t){return Mt(t)||fr(t)||pr(t)}function gr(t){let e=t.trim().toLowerCase();return $e.has(e)?!1:Ze.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 et(t){let n=t.replace(/^@ohos\./i,"").split(".").filter(Boolean);return n[n.length-1]?.trim()||void 0}function Ft(t){return[...t.matchAll(rr)].map(e=>e[0])}function vt(t,e=Ge){let n=[];for(let r of t.matchAll(or))r[0].length>=e&&n.push(r[0]);return n}function F(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 T(t,e){let n=e.trim();if(!n)return;t.add(n);let r=n.toLowerCase();r!==n&&t.add(r)}function Sr(t){let e=new Set;T(e,t);let n=et(t);return n&&T(e,n),F([...e])}function zt(t){if(Mt(t))return Sr(t);let e=new Set;return T(e,t),F([...e])}function Ht(t){let e=t.trim();if(/[A-Z]/.test(e))return null;let n=e.match(ur);if(!n)return null;let r=n[1].toLowerCase(),o=n[2].toLowerCase();if(!cr.test(r)||Ue.has(r)||!gr(o))return null;let i=hr(r,o);return{first:r,second:o,camelCase:i,lower:i.toLowerCase()}}function Xe(t){let e=Ht(t.trim());return!e||e.second!=="manager"?null:e}function jt(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 We(t){let e=t.trim();if(kt(e))return zt(e);let n=new Set;for(let r of Ft(t)){T(n,r);let o=et(r);o&&T(n,o)}for(let r of vt(t))T(n,r);for(let r of t.matchAll(sr))n.add(r[0]);for(let r of t.matchAll(ar))n.add(r[0]);for(let r of t.matchAll(ir))r[0].length>=4&&n.add(r[0]);return F([...n])}function Qe(t){let e=t.trim();if(kt(e))return zt(e);let n=new Set,r=Ht(e);r&&T(n,r.camelCase);for(let o of We(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 F([...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 Ye(t){return I.pureApiSymbol.test(t.trim())}function qe(t){let e=t.trim();return I.stageModelExact.test(e)||I.stageModelEnglishExact.test(e)}var yr=[{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=>qe(t),weights:[{catalog:"harmonyos-guides",multiplier:1.85},{catalog:"harmonyos-references",multiplier:.55},{catalog:"harmonyos-faqs",multiplier:.85}]},{matches:t=>!qe(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=w[n];t.set(o,(t.get(o)??1)*r)}}function Ve(t,e){for(let n of yr)n.matches(t)&&xr(e,n.weights)}import*as Ke from"os";function Zt(){return _r().toLowerCase().includes("openharmony")}function _r(){return Ke.platform()}var nt=null,tn=null,$t=null,Je=!1,Ut=null;function Er(){if(nt)return nt;let t=k("harmonyos-stopwords.txt");return nt=new Set(t.split(`
2
+ `).map(e=>e.trim()).filter(Boolean)),nt}function Ar(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 br(t){let e=Er(),n=[];for(let r of Ar(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 Tr(){let t=await import("jieba-wasm");tn=t.cut,$t=t.cut_for_search;let e=k("harmonyos-terms.txt");t.with_dict(e)}async function Ir(){let{Jieba:t}=await import("@node-rs/jieba"),{dict:e}=await import("@node-rs/jieba/dict.js"),n=t.withDict(e),r=k("harmonyos-terms.txt");n.loadDict(Buffer.from(r,"utf-8")),tn=n.cut.bind(n),$t=n.cutForSearch.bind(n)}async function v(){Je||(Ut||(Ut=(Zt()?Tr():Ir()).then(()=>{Je=!0})),await Ut)}async function Dr(t){return await v(),br($t(t,!0))}async function rt(t,e){let n=t.trim();if(!n||e<=0)return"";let r=(await Dr(n)).join(" ");return r.length<=e?r:r.slice(0,e)}async function wr(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 ot(t){let e=!!t.sectionTitle.trim(),n=t.titleTokens.trim(),r=e?me:ae,o=e?pe:ue,i=e?await wr(t.apiSymbols,o):await rt(t.apiSymbols.join(" "),o),a=(await Promise.all([rt(n,e?fe:ce),Promise.resolve(i),rt(t.headingsText,e?ge:le),rt(t.bodySample,e?he:de)])).filter(Boolean).join(" ");return a.length<=r?a:a.slice(0,r)}var en=["harmonyos-releases","harmonyos-roadmap"],Cr=new Set(en.map(t=>w[t])),js=en.map(t=>`${G[t]}/`);function Rr(t){return Cr.has(t)}function nn(t){let e=[],n=[];for(let r of t)Rr(r.catalog_id)?n.push(r):e.push(r);return[...e,...n]}var Nr=[{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 Z(t,e,n){let r=w[e];t.set(r,(t.get(r)??1)*n)}function Lr(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)){Z(e,"harmonyos-guides",1.45),Z(e,"harmonyos-references",1.35);return}(o||i)&&Z(e,"harmonyos-references",1.55),/\b[A-Z][a-zA-Z]*(Gesture|Dialog|Sheet|Transition|Recognizer)\b/.test(n)&&Z(e,"harmonyos-references",1.75)}function rn(t){let e=new Map,n=t.trim();if(!n)return e;let r=Ye(n);Lr(n,e),Ve(n,e);for(let o of Nr)o.pattern.test(n)&&(o.skipForPureApiSymbol&&r||Z(e,o.catalog,o.multiplier));return e}function it(t){process.env.DEVECO_CLI_DEBUG&&console.log(`[DEBUG] ${t}`)}var Or=[" ","\u3002","\uFF0C","\uFF1B","\u3001",".","!","?"];function on(t,e){let n=-1;for(let r of Or){let o=t.lastIndexOf(r);o>n&&(n=o)}return n>=e?n:-1}function sn(t,e){let n=t.trim();if(n.length<=e)return{text:n,excerptTruncated:!1};let r=n.slice(0,e),o=on(r,e-20),i=o>=0?o:e;return{text:n.slice(0,i).trimEnd(),excerptTruncated:!0}}function an(t,e,n={}){let{maxLen:r=xe,contextChars:o=_e,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(gt=>gt.trim()).filter(Boolean),c=0;for(let gt of a){let Jt=s.toLowerCase().indexOf(gt.toLowerCase());if(Jt>=0){c=Jt;break}}let f=Math.max(0,c-o),p=Math.min(s.length,f+r),u=s.slice(f,p),E=on(u,r-25);E>=0&&(p=f+E);let g=s.slice(f,p).trim(),A=f>0?"...":"",jn=p<s.length||i?"...":"";return`${A}${g}${jn}`}var Pr=`
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
@@ -61,5 +61,5 @@ CREATE INDEX segments_doc_id_idx ON segments(doc_id);
61
61
  `).run(n.documentId,n.catalogId,n.docTitle),c=Number(a.lastInsertRowid);return e.set(n.documentId,c),c}async function eo(t,e,n,r){await v();let o=Jr(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+=B){let f=n.slice(c,c+B),p=await Promise.all(f.map(async E=>({source:E,searchText:await ot(E)})));o.transaction(E=>{for(let g of E){let A=to(o,i,g.source);s.run(A,g.source.sectionTitle,g.source.leadText,g.searchText,g.source.excerptTruncated?1:0)}})(p),await r?.(Math.min(c+f.length,a),a)}o.exec("ANALYZE"),o.exec("VACUUM"),o.close()}function no(t,e,n,r,o,i,s){let a=Kr(t,e);return at({all(c,...f){return a.prepare(c).all(...f)}},n,r,o,i,s)}async function ln(){let e=(await import("better-sqlite3")).default;return{kind:"better-sqlite3",resetCache:Vr,buildSearchIndex:(n,r,o)=>eo(e,n,r,o),searchIndex:(n,r,o,i,s,a,c)=>Promise.resolve(no(e,i,r,o,s,a,c))}}import{readFile as ro,stat as oo,writeFile as io}from"fs/promises";var Qt=null,N=null;async function qt(){return Qt||(Qt=(async()=>{let t=(await import("@sqlite.org/sqlite-wasm")).default;return t()})()),Qt}function so(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 ao(t){let e=await oo(t);if(N&&N.dbPath===t&&N.mtimeMs===e.mtimeMs)return N.db;N?.db.close();let n=await qt(),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),N={dbPath:t,mtimeMs:e.mtimeMs,db:a},a}function dn(){N?.db.close(),N=null}async function co(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 uo(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 lo(t,e,n){await v();let r=await qt(),o=new r.oo1.DB(":memory:","c");o.exec(ct);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=uo(o,i,s),f=e.length;for(let u=0;u<f;u+=B){let E=e.slice(u,u+B),g=await Promise.all(E.map(async A=>({source:A,searchText:await ot(A)})));await co(o,a,c,g),await n?.(Math.min(u+E.length,f),f)}o.exec("ANALYZE");let p=r.capi.sqlite3_js_db_export(o);await io(t,p),o.close(),dn()}async function mo(t,e,n,r,o,i){let s=await ao(t);return at(so(s),e,n,r,o,i)}async function mn(){return await qt(),{kind:"sqlite-wasm",resetCache:dn,buildSearchIndex:lo,searchIndex:(t,e,n,r,o,i,s)=>mo(r,e,n,o,i,s)}}var ut=null,Yt=null;async function fo(){try{let e=await ln();return it("doc-index: using better-sqlite3 SQLite backend"),e}catch(e){it(`doc-index: better-sqlite3 unavailable (${e.message}); falling back to sqlite-wasm`)}let t=await mn();return it("doc-index: using @sqlite.org/sqlite-wasm SQLite backend"),t}async function Vt(){return ut||(ut=fo().then(t=>(Yt=t,t))),ut}function fn(){Yt?.resetCache(),ut=null,Yt=null}function pn(){fn()}async function gn(t,e,n){await(await Vt()).buildSearchIndex(t,e,n)}import{unified as bn}from"unified";import Tn from"remark-parse";import In from"remark-gfm";import{toString as dt}from"mdast-util-to-string";var po=/^(.+?)(\d+\+)?(对象|枚举|错误码)说明$/,go=/^\[h2\]([A-Za-z][A-Za-z0-9]*)(\d+\+)?$/,ho=/^(.{2,20}?)\s*[((]([A-Za-z][a-zA-Z0-9]{1,40})[))]\s*$/,So=/^([A-Za-z@][A-Za-z0-9@]*?)(\d+\+)?$/,yo=/^(系统能力|元服务API|参数|返回值|说明|\*\*|表格|\|)/;function lt(t){let e=t.trim(),n=e.match(So);return n?n[1]:e}function xo(t){let e=t.match(po);if(!e)return;let n=lt(e[1].trim());return{displayTitle:t,symbolName:n,searchExtras:[n,e[3]]}}function _o(t){let e=lt(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 U(t){let e=t.trim();return e?xo(e)??(()=>{let n=e.match(go);if(n){let r=n[1];return{displayTitle:e,symbolName:r,searchExtras:[r]}}})()??(()=>{let n=e.match(ho);if(!n)return;let r=n[1].trim(),o=n[2].trim();return{displayTitle:e,symbolName:o,searchExtras:[r,o]}})()??_o(e)??{displayTitle:e,searchExtras:[]}:{displayTitle:"",searchExtras:[]}}function Eo(t){if(t.length<2||t.length>36||yo.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 hn(t){for(let e of t){let n=e.trim().replace(/[。.!!??;;]+$/u,"").trim();if(Eo(n))return n}return""}function Sn(t,e,n){let r=[t,...n.searchExtras,e].filter(Boolean);return[...new Set(r)].join(" ")}var Ao=/[A-Z][a-zA-Z0-9]+(?:\.[a-zA-Z][a-zA-Z0-9]+)*/g,$=/@[A-Z][a-zA-Z]+/g,bo=/^[A-Z][A-Za-z0-9]*\.[A-Za-z][A-Za-z0-9]+/,To=/^[A-Z][A-Za-z0-9]+(?:\([^)]*\))?$/,Io=/^[a-z0-9]+(?:[-_][a-z0-9]+)+$/,Do=new Set(["API","Action","Code","Connect","Connection","Context","Direction","Element","Elements","Entry","Focused","Module","Modules","Name","Names","Stage","Type","Types","Value","Values","Rect","Error"]),wo=new Set(["HAP","HSP","HAR","NAPI","CAPI","NDK","ArkTS","ArkUI","OHPM"]),Co=new Set(["JSON","Object","Array","Promise","console","Math","Date","String","Number","Boolean","Error","Function","Map","Set","RegExp"]);function Dn(t,e){let n=new Set,r=[t,...e];for(let o of r){for(let i of Ft(o)){T(n,i);let s=et(i);s&&T(n,s)}for(let i of vt(o))T(n,i);for(let i of o.matchAll(Ao)){let s=i[0];Ro(s)&&n.add(s)}for(let i of o.matchAll($))n.add(i[0])}return F([...n])}function Ro(t){let e=t.trim();if(!e||$.test(e))return!!e;if(e.includes(".")){let n=e.split(".")[0]??"";return Co.has(n)?!1:/^[A-Z]/.test(n)}return Do.has(e)?!1:wo.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 yn(t){let e=t.trim();return!!(!e||Io.test(e)||e.length>28&&!/[A-Z\u4e00-\u9fff]/.test(e)&&/^[a-z0-9_-]+$/.test(e))}function wn(t,e){let n=e.jsonTitle?.trim(),r=Po(t,"").trim(),o=e.fileName.trim();return n&&!yn(n)?n:r&&!yn(r)?r:n||r||o}function Cn(t){return bo.test(t.trim())}function Kt(t){let e=t.trim().replace(/\([^)]*\)$/,""),n=lt(e);return To.test(n)}function mt(t){let e=t.trim();return e?$.test(e)||Cn(e)||Kt(e)?!0:!!U(e).symbolName:!1}function No(t){let e=t.trim();return!(!e||Cn(e)||Kt(e))}function Oo(t){let e=new Set,n=[];for(let r of t){let o=r.trim();!No(o)||e.has(o)||(e.add(o),n.push(o))}return n}function xn(t){if(!t.includes("."))return 0;let e=t.split(".").pop()??"";return/^[a-z]/.test(e)?1:2}function Lo(t,e){let n=xn(t)-xn(e);return n!==0?n:t.localeCompare(e)}function Rn(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(Lo),[...n,...o].slice(0,Se)}function ft(t){return t.replace(/\s+/g," ").trim()}function _n(t){return t.replace(/\\([\\`*_{}[\]()#+.!-])/g,"$1")}function Po(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=_n(n[r].trim()),i=o.match(/^#+\s+(.+)$/);if(i)return _n(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 Nn(t){let e=ft(t.join(" "));if(e.length<=W)return e;let n=e.slice(0,W);return e.length<=W+yt?n:`${n} ${e.slice(-yt)}`}function Bo(t){let e=Oo(t).join(" ");return e.length<=xt?e:e.slice(0,xt)}function On(t){let e=ft(t),{text:n,excerptTruncated:r}=sn(e,ye);return{leadText:n,excerptTruncated:r}}function Mo(t,e){let{leadText:n,excerptTruncated:r}=On(t);return{leadText:n,excerptTruncated:r||!!e.trim()}}function Ln(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)Ln(r,e);return}let n=ft(dt(t));n&&e.bodyParts.push(n)}function ko(t){let e=bn().use(Tn).use(In).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=dt(a).trim();if(a.depth>=4&&c&&mt(c)){o(),r={sectionTitle:c,bodyParts:[],codeBlocks:[]};continue}i(),c&&r.bodyParts.push(c);continue}i(),Ln(s,r)}return o(),n.length===0?[{sectionTitle:"",bodyParts:[],codeBlocks:[]}]:n}function Fo(t){return ie.test(t)}function vo(t){return t.filter(e=>e.sectionTitle&&mt(e.sectionTitle)).length}function zo(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 En(t){let e=t.trim();return!e||$.test(e)?$.test(e):/对象说明$|枚举说明$/.test(e)?!0:Kt(e)}function Ho(t){let e=t.filter(u=>!u.sectionTitle||!mt(u.sectionTitle)),n=t.filter(u=>u.sectionTitle&&mt(u.sectionTitle)),r=n.filter(u=>En(u.sectionTitle)),o=n.filter(u=>!En(u.sectionTitle)),i=Math.max(0,oe-r.length),s=o.slice(0,i),a=o.slice(i),c=a.filter(u=>An(u.sectionTitle)),f=a.filter(u=>!An(u.sectionTitle)),p=[];for(let u=0;u<f.length;u+=St)p.push(zo(f.slice(u,u+St)));return[...e,...r,...s,...c,...p]}function jo(t,e,n){let r=t.split(/\r?\n/).length,o=vo(e);return o===0?!1:Fo(n)?r>=ne&&o>=re:r>=te&&o>=ee}var Zo=/^\[h2\][A-Za-z]/;function An(t){return Zo.test(t.trim())}function Pn(t){if(!t.includes(" | ")){let n=U(t);return n.symbolName?[n.symbolName]:[]}let e=[];for(let n of t.split(" | ")){let r=U(n.trim()).symbolName;r&&e.push(r)}return e}function Uo(t,e,n,r){let o=Pn(t),i=Dn(n,r);return e.symbolName&&i.push(e.symbolName),Rn([...o,...i],o)}function $o(t,e){let n=Nn(t.bodyParts),r=t.sectionTitle.trim(),o=U(r),i=hn(t.bodyParts),s=Sn(r,i,o),a=Pn(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}=Mo(n,r);return{documentId:e.documentId,catalogId:e.catalogId,docTitle:e.docTitle,sectionTitle:r,titleTokens:c,headingsText:s,apiSymbols:Uo(r,o,f,t.codeBlocks),bodySample:n,leadText:p,excerptTruncated:u}}function Bn(t,e){for(let n of t){if(n.type==="heading"){let o=dt(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)){Bn(n.children,e);continue}let r=ft(dt(n));r&&e.bodyParts.push(r)}}function Go(t){let e=bn().use(Tn).use(In).parse(t),n={headings:[],bodyParts:[],codeBlocks:[]};return Bn(e.children,n),n}function Xo(t,e){let n=Go(t),r=e.docTitle?.trim()||e.documentId,o=Nn(n.bodyParts),i=[r,...n.headings,o].join(" "),{leadText:s,excerptTruncated:a}=On(o);return{documentId:e.documentId,catalogId:e.catalogId,docTitle:r,sectionTitle:"",titleTokens:r,headingsText:Bo(n.headings),apiSymbols:Rn(Dn(i,n.codeBlocks)),bodySample:o,leadText:s,excerptTruncated:a}}function Mn(t,e){let n=e.docTitle?.trim()||e.documentId,r=ko(t);return jo(t,r,e.documentId)?Ho(r).filter(o=>o.sectionTitle||o.bodyParts.length>0||o.codeBlocks.length>0).map(o=>$o(o,{...e,docTitle:n})):[Xo(t,{...e,docTitle:n})]}async function Wo(t){let e=[];async function n(r){let o=await y.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 Qo(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=Ee[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 qo(t){let e=t.replace(/\.md$/,".json");try{let n=await y.promises.readFile(e,"utf-8");return JSON.parse(n).title?.trim()||void 0}catch{return}}async function Yo(t,e){let n=Qo(t,e);if(!n)return[];let r=await y.promises.readFile(t,"utf-8"),o=wn(r,{jsonTitle:await qo(t),fileName:n.docTitle});return Mn(r,{...n,docTitle:o})}async function Vo(t,e,n){let r=_.join(e,"search.db");return await gn(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 Ko(t){let e=await Wo(t),n=[];for(let r of e){let o=await Yo(r,t);n.push(...o)}return n}function Jo(t,e){return{indexVersion:X,docsZipSha256:t.docsZipSha256,termsHash:t.termsHash,synonymsHash:t.synonymsHash,segmentCount:e,builtAt:Date.now(),builtBy:t.builtBy}}async function Fn(t){t.lexiconDir&&Dt(t.lexiconDir);try{let e=await Ko(t.docsDir);await t.onProgress?.({current:0,total:e.length,message:`Building search index\u2026 0 / ${e.length.toLocaleString()} segments`}),await y.promises.mkdir(t.tmpDir,{recursive:!0});let n=await Vo(e,t.tmpDir,t.onProgress),r=Jo(t,n);return await y.promises.writeFile(_.join(t.tmpDir,"build-meta.json"),JSON.stringify(r,null,2)),await Oe(t.tmpDir),r}finally{t.lexiconDir&&Dt(null)}}async function vn(){return y.promises.mkdtemp(_.join(kn.tmpdir(),"deveco-docs-"))}async function ti(t,e){try{await y.promises.rename(t,e)}catch(n){let r=n.code;if(r!=="EPERM"&&r!=="EXDEV")throw n;await y.promises.cp(t,e,{recursive:!0}),await y.promises.rm(t,{recursive:!0,force:!0})}}async function zn(t){let e=_.join(t,"docs");try{await y.promises.access(e)}catch{return}let n=new Set(["docs","docs.zip"]);for(let r of await y.promises.readdir(e,{withFileTypes:!0})){if(n.has(r.name))continue;let o=_.join(e,r.name),i=_.join(t,r.name);await y.promises.rm(i,{recursive:!0,force:!0}),await ti(o,i)}await y.promises.rm(_.join(e,"docs"),{recursive:!0,force:!0}),await y.promises.rm(_.join(e,"docs.zip"),{force:!0}),await y.promises.rm(e,{recursive:!0,force:!0})}async function oi(t){let e=At();await h.promises.mkdir(H.dirname(e),{recursive:!0}),await h.promises.appendFile(e,`${new Date().toISOString()} ${t}
65
- `)}async function ii(t){let e=O();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}),new ei(e).extractAllTo(t,!0),await zn(t)}async function si(){let t=x(),e=M(),n=await h.promises.readdir(e);for(let r of n){let o=H.join(t,r);await h.promises.rm(o,{force:!0}),await h.promises.rename(H.join(e,r),o)}await h.promises.rm(e,{recursive:!0,force:!0}),await h.promises.rm(H.join(t,"orama.dpack"),{force:!0})}async function ai(t,e){e?.start("Installing documentation index\u2026"),await R({state:"installing",phase:1,phaseLabel:"Installing index",message:"Installing documentation index\u2026"}),await Be(t),e&&(e.text="Documentation index installed.")}async function ci(t,e,n){let r=M(),o=await vn();await h.promises.mkdir(x(),{recursive:!0}),await h.promises.rm(r,{recursive:!0,force:!0}),n?.start("Building search index\u2026"),await R({state:"indexing",phase:2,phaseLabel:"Building search index",message:"Building search index\u2026"});try{await ii(o),await Fn({docsDir:o,tmpDir:r,docsZipSha256:e,termsHash:tt(),synonymsHash:J(),builtBy:t.builtBy??"doc-init",onProgress:async i=>{n&&(n.text=i.message),await R({state:"indexing",current:i.current,total:i.total,message:i.message})}})}finally{await h.promises.rm(o,{recursive:!0,force:!0})}await R({state:"persisting",phase:3,phaseLabel:"Persisting index",message:"Persisting index\u2026"}),await si(),pn()}async function Hn(t){await R({state:"done",phase:3,phaseLabel:"Done",message:"Documentation ready.",error:null}),t?.succeed("Documentation ready.")}async function ui(t){let e=await Lt(),n=e?`Documentation already up to date. Documents: ${e.segmentCount.toLocaleString()}`:"Documentation already up to date.";t?.succeed(n),await R({state:"done",message:n,error:null})}async function li(t,e){let n=t instanceof Error?t.message:String(t);throw await R({state:"error",error:n}),await oi(`ERROR: ${n}`),e?.fail(n),t}async function di(){let t=x();await h.promises.mkdir(t,{recursive:!0});let e=Ie();return h.existsSync(e)||await h.promises.writeFile(e,"","utf-8"),e}async function mi(){let t=await di();return ni.lock(t,{stale:1800*1e3})}async function fi(){let t=O(),e=(t?await K(t):null)??await Ot();if(!e)throw new Error("docs.zip not found");return e}async function pi(t,e){let n=await fi(),r=t.force||await je(t.force),o=await Pt(t.force);if(!r&&!o&&Bt()){await ui(e);return}if(Rt()&&!t.force){await ai(n,e),await Hn(e);return}await ci(t,n,e),await Hn(e)}var pt=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{i=await mi(),await Nt(He("Starting documentation setup\u2026")),await pi(e,o)}catch(s){await li(s,o)}finally{i&&await i()}}};var gi=process.env.DEVECO_CLI_POSTINSTALL?"postinstall":"doc-init";pt.run({background:!0,builtBy:gi}).catch(()=>{process.exit(1)});
64
+ `),a=n.length;for(let c=0;c<a;c+=B){let f=n.slice(c,c+B),p=await Promise.all(f.map(async E=>({source:E,searchText:await ot(E)})));o.transaction(E=>{for(let g of E){let A=to(o,i,g.source);s.run(A,g.source.sectionTitle,g.source.leadText,g.searchText,g.source.excerptTruncated?1:0)}})(p),await r?.(Math.min(c+f.length,a),a)}o.exec("ANALYZE"),o.exec("VACUUM"),o.close()}function no(t,e,n,r,o,i,s){let a=Kr(t,e);return at({all(c,...f){return a.prepare(c).all(...f)}},n,r,o,i,s)}async function ln(){let e=(await import("better-sqlite3")).default;return{kind:"better-sqlite3",resetCache:Vr,buildSearchIndex:(n,r,o)=>eo(e,n,r,o),searchIndex:(n,r,o,i,s,a,c)=>Promise.resolve(no(e,i,r,o,s,a,c))}}import{readFile as ro,stat as oo,writeFile as io}from"fs/promises";var Qt=null,N=null;async function qt(){return Qt||(Qt=(async()=>{let t=(await import("@sqlite.org/sqlite-wasm")).default;return t()})()),Qt}function so(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 ao(t){let e=await oo(t);if(N&&N.dbPath===t&&N.mtimeMs===e.mtimeMs)return N.db;N?.db.close();let n=await qt(),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),N={dbPath:t,mtimeMs:e.mtimeMs,db:a},a}function dn(){N?.db.close(),N=null}async function co(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 uo(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 lo(t,e,n){await v();let r=await qt(),o=new r.oo1.DB(":memory:","c");o.exec(ct);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=uo(o,i,s),f=e.length;for(let u=0;u<f;u+=B){let E=e.slice(u,u+B),g=await Promise.all(E.map(async A=>({source:A,searchText:await ot(A)})));await co(o,a,c,g),await n?.(Math.min(u+E.length,f),f)}o.exec("ANALYZE");let p=r.capi.sqlite3_js_db_export(o);await io(t,p),o.close(),dn()}async function mo(t,e,n,r,o,i){let s=await ao(t);return at(so(s),e,n,r,o,i)}async function mn(){return await qt(),{kind:"sqlite-wasm",resetCache:dn,buildSearchIndex:lo,searchIndex:(t,e,n,r,o,i,s)=>mo(r,e,n,o,i,s)}}var ut=null,Yt=null;async function fo(){try{let e=await ln();return it("doc-index: using better-sqlite3 SQLite backend"),e}catch(e){it(`doc-index: better-sqlite3 unavailable (${e.message}); falling back to sqlite-wasm`)}let t=await mn();return it("doc-index: using @sqlite.org/sqlite-wasm SQLite backend"),t}async function Vt(){return ut||(ut=fo().then(t=>(Yt=t,t))),ut}function fn(){Yt?.resetCache(),ut=null,Yt=null}function pn(){fn()}async function gn(t,e,n){await(await Vt()).buildSearchIndex(t,e,n)}import{unified as bn}from"unified";import Tn from"remark-parse";import In from"remark-gfm";import{toString as dt}from"mdast-util-to-string";var po=/^(.+?)(\d+\+)?(对象|枚举|错误码)说明$/,go=/^\[h2\]([A-Za-z][A-Za-z0-9]*)(\d+\+)?$/,ho=/^(.{2,20}?)\s*[((]([A-Za-z][a-zA-Z0-9]{1,40})[))]\s*$/,So=/^([A-Za-z@][A-Za-z0-9@]*?)(\d+\+)?$/,yo=/^(系统能力|元服务API|参数|返回值|说明|\*\*|表格|\|)/;function lt(t){let e=t.trim(),n=e.match(So);return n?n[1]:e}function xo(t){let e=t.match(po);if(!e)return;let n=lt(e[1].trim());return{displayTitle:t,symbolName:n,searchExtras:[n,e[3]]}}function _o(t){let e=lt(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 U(t){let e=t.trim();return e?xo(e)??(()=>{let n=e.match(go);if(n){let r=n[1];return{displayTitle:e,symbolName:r,searchExtras:[r]}}})()??(()=>{let n=e.match(ho);if(!n)return;let r=n[1].trim(),o=n[2].trim();return{displayTitle:e,symbolName:o,searchExtras:[r,o]}})()??_o(e)??{displayTitle:e,searchExtras:[]}:{displayTitle:"",searchExtras:[]}}function Eo(t){if(t.length<2||t.length>36||yo.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 hn(t){for(let e of t){let n=e.trim().replace(/[。.!!??;;]+$/u,"").trim();if(Eo(n))return n}return""}function Sn(t,e,n){let r=[t,...n.searchExtras,e].filter(Boolean);return[...new Set(r)].join(" ")}var Ao=/[A-Z][a-zA-Z0-9]+(?:\.[a-zA-Z][a-zA-Z0-9]+)*/g,$=/@[A-Z][a-zA-Z]+/g,bo=/^[A-Z][A-Za-z0-9]*\.[A-Za-z][A-Za-z0-9]+/,To=/^[A-Z][A-Za-z0-9]+(?:\([^)]*\))?$/,Io=/^[a-z0-9]+(?:[-_][a-z0-9]+)+$/,Do=new Set(["API","Action","Code","Connect","Connection","Context","Direction","Element","Elements","Entry","Focused","Module","Modules","Name","Names","Stage","Type","Types","Value","Values","Rect","Error"]),wo=new Set(["HAP","HSP","HAR","NAPI","CAPI","NDK","ArkTS","ArkUI","OHPM"]),Co=new Set(["JSON","Object","Array","Promise","console","Math","Date","String","Number","Boolean","Error","Function","Map","Set","RegExp"]);function Dn(t,e){let n=new Set,r=[t,...e];for(let o of r){for(let i of Ft(o)){T(n,i);let s=et(i);s&&T(n,s)}for(let i of vt(o))T(n,i);for(let i of o.matchAll(Ao)){let s=i[0];Ro(s)&&n.add(s)}for(let i of o.matchAll($))n.add(i[0])}return F([...n])}function Ro(t){let e=t.trim();if(!e||$.test(e))return!!e;if(e.includes(".")){let n=e.split(".")[0]??"";return Co.has(n)?!1:/^[A-Z]/.test(n)}return Do.has(e)?!1:wo.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 yn(t){let e=t.trim();return!!(!e||Io.test(e)||e.length>28&&!/[A-Z\u4e00-\u9fff]/.test(e)&&/^[a-z0-9_-]+$/.test(e))}function wn(t,e){let n=e.jsonTitle?.trim(),r=Po(t,"").trim(),o=e.fileName.trim();return n&&!yn(n)?n:r&&!yn(r)?r:n||r||o}function Cn(t){return bo.test(t.trim())}function Kt(t){let e=t.trim().replace(/\([^)]*\)$/,""),n=lt(e);return To.test(n)}function mt(t){let e=t.trim();return e?$.test(e)||Cn(e)||Kt(e)?!0:!!U(e).symbolName:!1}function No(t){let e=t.trim();return!(!e||Cn(e)||Kt(e))}function Lo(t){let e=new Set,n=[];for(let r of t){let o=r.trim();!No(o)||e.has(o)||(e.add(o),n.push(o))}return n}function xn(t){if(!t.includes("."))return 0;let e=t.split(".").pop()??"";return/^[a-z]/.test(e)?1:2}function Oo(t,e){let n=xn(t)-xn(e);return n!==0?n:t.localeCompare(e)}function Rn(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(Oo),[...n,...o].slice(0,Se)}function ft(t){return t.replace(/\s+/g," ").trim()}function _n(t){return t.replace(/\\([\\`*_{}[\]()#+.!-])/g,"$1")}function Po(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=_n(n[r].trim()),i=o.match(/^#+\s+(.+)$/);if(i)return _n(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 Nn(t){let e=ft(t.join(" "));if(e.length<=W)return e;let n=e.slice(0,W);return e.length<=W+yt?n:`${n} ${e.slice(-yt)}`}function Bo(t){let e=Lo(t).join(" ");return e.length<=xt?e:e.slice(0,xt)}function Ln(t){let e=ft(t),{text:n,excerptTruncated:r}=sn(e,ye);return{leadText:n,excerptTruncated:r}}function Mo(t,e){let{leadText:n,excerptTruncated:r}=Ln(t);return{leadText:n,excerptTruncated:r||!!e.trim()}}function On(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)On(r,e);return}let n=ft(dt(t));n&&e.bodyParts.push(n)}function ko(t){let e=bn().use(Tn).use(In).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=dt(a).trim();if(a.depth>=4&&c&&mt(c)){o(),r={sectionTitle:c,bodyParts:[],codeBlocks:[]};continue}i(),c&&r.bodyParts.push(c);continue}i(),On(s,r)}return o(),n.length===0?[{sectionTitle:"",bodyParts:[],codeBlocks:[]}]:n}function Fo(t){return ie.test(t)}function vo(t){return t.filter(e=>e.sectionTitle&&mt(e.sectionTitle)).length}function zo(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 En(t){let e=t.trim();return!e||$.test(e)?$.test(e):/对象说明$|枚举说明$/.test(e)?!0:Kt(e)}function Ho(t){let e=t.filter(u=>!u.sectionTitle||!mt(u.sectionTitle)),n=t.filter(u=>u.sectionTitle&&mt(u.sectionTitle)),r=n.filter(u=>En(u.sectionTitle)),o=n.filter(u=>!En(u.sectionTitle)),i=Math.max(0,oe-r.length),s=o.slice(0,i),a=o.slice(i),c=a.filter(u=>An(u.sectionTitle)),f=a.filter(u=>!An(u.sectionTitle)),p=[];for(let u=0;u<f.length;u+=St)p.push(zo(f.slice(u,u+St)));return[...e,...r,...s,...c,...p]}function jo(t,e,n){let r=t.split(/\r?\n/).length,o=vo(e);return o===0?!1:Fo(n)?r>=ne&&o>=re:r>=te&&o>=ee}var Zo=/^\[h2\][A-Za-z]/;function An(t){return Zo.test(t.trim())}function Pn(t){if(!t.includes(" | ")){let n=U(t);return n.symbolName?[n.symbolName]:[]}let e=[];for(let n of t.split(" | ")){let r=U(n.trim()).symbolName;r&&e.push(r)}return e}function Uo(t,e,n,r){let o=Pn(t),i=Dn(n,r);return e.symbolName&&i.push(e.symbolName),Rn([...o,...i],o)}function $o(t,e){let n=Nn(t.bodyParts),r=t.sectionTitle.trim(),o=U(r),i=hn(t.bodyParts),s=Sn(r,i,o),a=Pn(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}=Mo(n,r);return{documentId:e.documentId,catalogId:e.catalogId,docTitle:e.docTitle,sectionTitle:r,titleTokens:c,headingsText:s,apiSymbols:Uo(r,o,f,t.codeBlocks),bodySample:n,leadText:p,excerptTruncated:u}}function Bn(t,e){for(let n of t){if(n.type==="heading"){let o=dt(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)){Bn(n.children,e);continue}let r=ft(dt(n));r&&e.bodyParts.push(r)}}function Go(t){let e=bn().use(Tn).use(In).parse(t),n={headings:[],bodyParts:[],codeBlocks:[]};return Bn(e.children,n),n}function Xo(t,e){let n=Go(t),r=e.docTitle?.trim()||e.documentId,o=Nn(n.bodyParts),i=[r,...n.headings,o].join(" "),{leadText:s,excerptTruncated:a}=Ln(o);return{documentId:e.documentId,catalogId:e.catalogId,docTitle:r,sectionTitle:"",titleTokens:r,headingsText:Bo(n.headings),apiSymbols:Rn(Dn(i,n.codeBlocks)),bodySample:o,leadText:s,excerptTruncated:a}}function Mn(t,e){let n=e.docTitle?.trim()||e.documentId,r=ko(t);return jo(t,r,e.documentId)?Ho(r).filter(o=>o.sectionTitle||o.bodyParts.length>0||o.codeBlocks.length>0).map(o=>$o(o,{...e,docTitle:n})):[Xo(t,{...e,docTitle:n})]}async function Wo(t){let e=[];async function n(r){let o=await y.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 Qo(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=Ee[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 qo(t){let e=t.replace(/\.md$/,".json");try{let n=await y.promises.readFile(e,"utf-8");return JSON.parse(n).title?.trim()||void 0}catch{return}}async function Yo(t,e){let n=Qo(t,e);if(!n)return[];let r=await y.promises.readFile(t,"utf-8"),o=wn(r,{jsonTitle:await qo(t),fileName:n.docTitle});return Mn(r,{...n,docTitle:o})}async function Vo(t,e,n){let r=_.join(e,"search.db");return await gn(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 Ko(t){let e=await Wo(t),n=[];for(let r of e){let o=await Yo(r,t);n.push(...o)}return n}function Jo(t,e){return{indexVersion:X,docsZipSha256:t.docsZipSha256,termsHash:t.termsHash,synonymsHash:t.synonymsHash,segmentCount:e,builtAt:Date.now(),builtBy:t.builtBy}}async function Fn(t){t.lexiconDir&&Dt(t.lexiconDir);try{let e=await Ko(t.docsDir);await t.onProgress?.({current:0,total:e.length,message:`Building search index\u2026 0 / ${e.length.toLocaleString()} segments`}),await y.promises.mkdir(t.tmpDir,{recursive:!0});let n=await Vo(e,t.tmpDir,t.onProgress),r=Jo(t,n);return await y.promises.writeFile(_.join(t.tmpDir,"build-meta.json"),JSON.stringify(r,null,2)),await Le(t.tmpDir),r}finally{t.lexiconDir&&Dt(null)}}async function vn(){return y.promises.mkdtemp(_.join(kn.tmpdir(),"deveco-docs-"))}async function ti(t,e){try{await y.promises.rename(t,e)}catch(n){let r=n.code;if(r!=="EPERM"&&r!=="EXDEV")throw n;await y.promises.cp(t,e,{recursive:!0}),await y.promises.rm(t,{recursive:!0,force:!0})}}async function zn(t){let e=_.join(t,"docs");try{await y.promises.access(e)}catch{return}let n=new Set(["docs","docs.zip"]);for(let r of await y.promises.readdir(e,{withFileTypes:!0})){if(n.has(r.name))continue;let o=_.join(e,r.name),i=_.join(t,r.name);await y.promises.rm(i,{recursive:!0,force:!0}),await ti(o,i)}await y.promises.rm(_.join(e,"docs"),{recursive:!0,force:!0}),await y.promises.rm(_.join(e,"docs.zip"),{force:!0}),await y.promises.rm(e,{recursive:!0,force:!0})}async function oi(t){let e=At();await h.promises.mkdir(H.dirname(e),{recursive:!0}),await h.promises.appendFile(e,`${new Date().toISOString()} ${t}
65
+ `)}async function ii(t){let e=L();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}),new ei(e).extractAllTo(t,!0),await zn(t)}async function si(){let t=x(),e=M(),n=await h.promises.readdir(e);for(let r of n){let o=H.join(t,r);await h.promises.rm(o,{force:!0}),await h.promises.rename(H.join(e,r),o)}await h.promises.rm(e,{recursive:!0,force:!0}),await h.promises.rm(H.join(t,"orama.dpack"),{force:!0})}async function ai(t,e){e?.start("Installing documentation index\u2026"),await R({state:"installing",phase:1,phaseLabel:"Installing index",message:"Installing documentation index\u2026"}),await Be(t),e&&(e.text="Documentation index installed.")}async function ci(t,e,n){let r=M(),o=await vn();await h.promises.mkdir(x(),{recursive:!0}),await h.promises.rm(r,{recursive:!0,force:!0}),n?.start("Building search index\u2026"),await R({state:"indexing",phase:2,phaseLabel:"Building search index",message:"Building search index\u2026"});try{await ii(o),await Fn({docsDir:o,tmpDir:r,docsZipSha256:e,termsHash:tt(),synonymsHash:J(),builtBy:t.builtBy??"doc-init",onProgress:async i=>{n&&(n.text=i.message),await R({state:"indexing",current:i.current,total:i.total,message:i.message})}})}finally{await h.promises.rm(o,{recursive:!0,force:!0})}await R({state:"persisting",phase:3,phaseLabel:"Persisting index",message:"Persisting index\u2026"}),await si(),pn()}async function Hn(t){await R({state:"done",phase:3,phaseLabel:"Done",message:"Documentation ready.",error:null}),t?.succeed("Documentation ready.")}async function ui(t){let e=await Ot(),n=e?`Documentation already up to date. Documents: ${e.segmentCount.toLocaleString()}`:"Documentation already up to date.";t?.succeed(n),await R({state:"done",message:n,error:null})}async function li(t,e){let n=t instanceof Error?t.message:String(t);throw await R({state:"error",error:n}),await oi(`ERROR: ${n}`),e?.fail(n),t}async function di(){let t=x();await h.promises.mkdir(t,{recursive:!0});let e=Ie();return h.existsSync(e)||await h.promises.writeFile(e,"","utf-8"),e}async function mi(){let t=await di();return ni.lock(t,{stale:1800*1e3})}async function fi(){let t=L(),e=(t?await K(t):null)??await Lt();if(!e)throw new Error("docs.zip not found");return e}async function pi(t,e){let n=await fi(),r=t.force||await je(t.force),o=await Pt(t.force);if(!r&&!o&&Bt()){await ui(e);return}if(Rt()&&!t.force){await ai(n,e),await Hn(e);return}await ci(t,n,e),await Hn(e)}var pt=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{i=await mi(),await Nt(He("Starting documentation setup\u2026")),await pi(e,o)}catch(s){await li(s,o)}finally{i&&await i()}}};var gi=process.env.DEVECO_CLI_POSTINSTALL?"postinstall":"doc-init";pt.run({background:!0,builtBy:gi}).catch(()=>{process.exit(1)});
package/docs.zip CHANGED
Binary file
package/index.zip CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deveco-test/hmos-deveco-cli",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "HarmonyOS application development command line tool",
5
5
  "license": "MIT",
6
6
  "type": "module",