@plugin-web-update-notification/umijs
Version:
Umi plugin for detect web page updates and notify.
2 lines • 2.15 kB
JavaScript
import{resolve as c}from"path";import{copyFileSync as j,mkdirSync as I,readFileSync as b,writeFileSync as h}from"fs";import{DIRECTORY_NAME as n,INJECT_SCRIPT_FILE_NAME as a,INJECT_SCRIPT_TAG_ID as _,INJECT_STYLE_FILE_NAME as d,JSON_FILE_NAME as E,NOTIFICATION_ANCHOR_CLASS_NAME as k,generateJSONFileContent as A,generateJsFileContent as v,getFileHash as y,getVersion as $}from"@plugin-web-update-notification/core";var r="@plugin-web-update-notification/umijs";var B=t=>{t.describe({key:"webUpdateNotification",config:{schema(e){return e.object({versionType:e.string(),customVersion:e.string(),checkInterval:e.number(),logVersion:e.boolean(),checkOnWindowFocus:e.boolean(),checkImmediately:e.boolean(),checkOnLoadFileError:e.boolean(),injectFileBase:e.string(),customNotificationHTML:e.string(),notificationProps:{title:e.string(),description:e.string(),buttonText:e.string(),dismissButtonText:e.string()},notificationConfig:{primaryColor:e.string(),secondaryColor:e.string(),placement:e.string()},silence:e.boolean(),locale:e.string(),localeData:e.object(),hiddenDefaultNotification:e.boolean(),hiddenDismissButton:e.boolean()})}},enableBy(){return t.env==="production"&&t?.userConfig.webUpdateNotification}});let s=t.userConfig?.webUpdateNotification||{};s.injectFileBase===void 0&&(s.injectFileBase=t.userConfig.publicPath||"/");let{versionType:o,customNotificationHTML:N,hiddenDefaultNotification:u,injectFileBase:p="/",customVersion:F,silence:C}=s,i="";if(o==="custom"?i=$(o,F):i=$(o),!i||t.env!=="production")return;let w=c("node_modules",r,"dist",`${a}.js`),l=v(b(w,"utf8").toString(),i,s),f=y(l),m=c("node_modules",r,"dist",`${d}.css`),g=y(b(m,"utf8").toString());t.addHTMLLinks(()=>N||u?[]:[{rel:"stylesheet",href:`${p}${n}/${d}.${g}.css`}]),t.onBuildComplete(()=>{let e=c(t.userConfig.outputPath||"dist");I(`${e}/${n}`),j(m,`${e}/${n}/${d}.${g}.css`),h(`${e}/${n}/${a}.${f}.js`,l),h(`${e}/${n}/${E}.json`,A(i,C))}),t.modifyHTML(e=>(u||e("body").append(`<div class="${k}"></div>`),e("head").prepend(`<script data-id="${_}" data-v="${i}" src="${p}${n}/${a}.${f}.js"></script>`),e))};export{B as default};
//# sourceMappingURL=index.mjs.map