umi-plugin-goldjetjsupdate
Version:
Umi plugin for detect web page updates and notify in goldjet's project.
2 lines • 2.17 kB
JavaScript
import{resolve as c}from"path";import{copyFileSync as T,mkdirSync as I,readFileSync as b,writeFileSync as h}from"fs";import{DIRECTORY_NAME as n,INJECT_SCRIPT_FILE_NAME as a,INJECT_STYLE_FILE_NAME as u,JSON_FILE_NAME as _,NOTIFICATION_ANCHOR_CLASS_NAME as k,generateJSONFileContent as E,generateJsFileContent as v,getFileHash as y,getVersion as $}from"@plugin-web-update-notification/core";var r="umi-plugin-goldjetjsupdate";var x=t=>`window.pluginWebUpdateNotice_version = '${t}';`,H=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:d,injectFileBase:p="/",customVersion:w,silence:F}=s,i="";if(o==="custom"?i=$(o,w):i=$(o),!i||t.env!=="production")return;let j=c("node_modules",r,"dist",`${a}.js`),l=v(b(j,"utf8").toString(),i,s),f=y(l),m=c("node_modules",r,"dist",`${u}.css`),g=y(b(m,"utf8").toString());t.addHTMLLinks(()=>N||d?[]:[{rel:"stylesheet",href:`${p}${n}/${u}.${g}.css`}]),t.addHTMLHeadScripts(()=>{let e=[];return e.push({content:x(i)}),e.push({src:`${p}${n}/${a}.${f}.js`}),e}),t.onBuildComplete(()=>{let e=c(t.userConfig.outputPath||"dist");I(`${e}/${n}`),T(m,`${e}/${n}/${u}.${g}.css`),h(`${e}/${n}/${a}.${f}.js`,l),h(`${e}/${n}/${_}.json`,E(i,F))}),t.modifyHTML(e=>(d||e("body").append(`<div class="${k}"></div>`),e))};export{H as default};
//# sourceMappingURL=index.mjs.map