Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
4,731 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/node_modules | ||
/.env.local | ||
/.umirc.local.ts | ||
/config/config.local.ts | ||
/src/.umi | ||
/src/.umi-production | ||
/.umi | ||
/.umi-production | ||
/.umi-test | ||
/dist | ||
/.mfsu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
registry=https://registry.npmmirror.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { defineConfig} from 'umi' | ||
import type { Options as WebUpdateNotificationOptions } from '@umijs/plugin-web-update-notification' | ||
|
||
export default { | ||
npmClient: 'pnpm', | ||
plugins: ['@umijs/plugin-web-update-notification'], | ||
webUpdateNotification: { | ||
logHash: true, | ||
notificationProps: { | ||
title: '更新了!!' | ||
} | ||
} as WebUpdateNotificationOptions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"dev": "umi dev", | ||
"build": "umi build", | ||
"postinstall": "umi setup", | ||
"start": "npm run dev", | ||
"preview": "pnpm build && vite preview" | ||
}, | ||
"dependencies": { | ||
"umi": "^4.0.2" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.0.0", | ||
"@types/react-dom": "^18.0.0", | ||
"@umijs/plugin-web-update-notification": "workspace:*", | ||
"typescript": "^4.1.2" | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.navs { | ||
ul { | ||
padding: 0; | ||
list-style: none; | ||
display: flex; | ||
} | ||
li { | ||
margin-right: 1em; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Link, Outlet } from 'umi'; | ||
import styles from './index.less'; | ||
|
||
export default function Layout() { | ||
return ( | ||
<div className={styles.navs}> | ||
<ul> | ||
<li> | ||
<Link to="/">Home</Link> | ||
</li> | ||
<li> | ||
<Link to="/docs">Docs</Link> | ||
</li> | ||
<li> | ||
<a href="https://github.com/umijs/umi">Github</a> | ||
</li> | ||
</ul> | ||
<Outlet /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const DocsPage = () => { | ||
return ( | ||
<div> | ||
<p>This is umi docs.</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DocsPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import yayJpg from '../assets/yay.jpg'; | ||
|
||
export default function HomePage() { | ||
return ( | ||
<div> | ||
<h2>Yay! Welcome to umi!</h2> | ||
<p> | ||
<img src={yayJpg} width="388" /> | ||
</p> | ||
<p> | ||
To get started, edit <code>pages/index.tsx</code> and save to reload. | ||
</p> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "./src/.umi/tsconfig.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import 'umi/typings'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "@umijs/plugin-web-update-notification", | ||
"version": "0.1.1", | ||
"description": "Vite plugin for detect web page updates and notify.", | ||
"author": "Utopia", | ||
"license": "MIT", | ||
"homepage": "https://github.com/GreatAuk/vite-plugin-web-update-notification", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/GreatAuk/vite-plugin-web-update-notification", | ||
"directory": "packages/vite-plugin" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/GreatAuk/vite-plugin-web-update-notification/issues" | ||
}, | ||
"keywords": [ | ||
"vite", | ||
"vite-plugin", | ||
"vite-plugin-web-update-notification", | ||
"web-update-notification" | ||
], | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
} | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"start": "esno src/index.ts", | ||
"build": "tsup", | ||
"dev": "tsup --watch" | ||
}, | ||
"peerDependencies": { | ||
"umi": "*" | ||
}, | ||
"dependencies": { | ||
"@web-update-notification/core": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"umi": "^4.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { resolve } from 'path' | ||
import { copyFileSync, readFileSync, writeFileSync } from 'fs' | ||
import type { IApi } from 'umi' | ||
import type { Options } from '@web-update-notification/core' | ||
import { INJECT_SCRIPT_FILE_NAME, INJECT_STYLE_FILE_NAME, JSON_FILE_NAME, NOTIFICATION_ANCHOR_CLASS_NAME, generateJSONFileContent, getGitCommitHash } from '@web-update-notification/core' | ||
import { name as pkgName } from '../package.json' | ||
|
||
export type { Options } from '@web-update-notification/core' | ||
|
||
const logHashTpl = (commitHash: string) => { | ||
return ` | ||
(function() { | ||
console.log('git-commit-hash: %c${commitHash}', 'color: #1890ff'); | ||
})();` | ||
} | ||
|
||
export function generateScriptContent(options: Options, commitHash: string) { | ||
const filePath = resolve('node_modules', pkgName, 'dist', `${INJECT_SCRIPT_FILE_NAME}.js`) | ||
return `${readFileSync(filePath, 'utf8').toString()} | ||
window.GIT_COMMIT_HASH = "${commitHash}"; | ||
webUpdateCheck_checkAndNotice(${JSON.stringify(options)});` | ||
} | ||
|
||
export default (api: IApi) => { | ||
api.describe({ | ||
key: 'webUpdateNotification', | ||
config: { | ||
schema(Joi) { | ||
return Joi.object({ | ||
/** polling interval(ms), default 10*60*1000 */ | ||
checkInterval: Joi.number(), | ||
/** whether to output commit-hash in console */ | ||
logHash: Joi.boolean(), | ||
customNotificationHTML: Joi.string(), | ||
notificationProps: { | ||
title: Joi.string(), | ||
description: Joi.string(), | ||
buttonText: Joi.string(), | ||
}, | ||
hiddenDefaultNotification: Joi.boolean(), | ||
}) | ||
}, | ||
}, | ||
enableBy({ userConfig }) { | ||
return api.env === 'production' && userConfig.webUpdateNotification | ||
}, | ||
}) | ||
const webUpdateNotificationOptions = (api.userConfig?.webUpdateNotification || {}) as Options | ||
const { logHash, customNotificationHTML, hiddenDefaultNotification } = webUpdateNotificationOptions | ||
|
||
const commitHash = getGitCommitHash() | ||
|
||
// 插件只在生产环境且仓库是 git 仓库时生效 | ||
if (!commitHash || api.env !== 'production') | ||
return | ||
|
||
api.addHTMLLinks(() => { | ||
if (customNotificationHTML || hiddenDefaultNotification) | ||
return [] | ||
|
||
return [ | ||
{ | ||
rel: 'stylesheet', | ||
href: `${INJECT_STYLE_FILE_NAME}.css`, | ||
}, | ||
] | ||
}) | ||
|
||
api.addHTMLScripts(() => { | ||
const scriptList = [] | ||
if (logHash) { | ||
scriptList.push({ | ||
content: logHashTpl(commitHash), | ||
}) | ||
} | ||
return scriptList | ||
}) | ||
|
||
api.onBuildHtmlComplete(() => { | ||
// copy file from @web-update-notification/core/dist/??.css */ to dist/ | ||
const scriptFilePath = resolve('node_modules', pkgName, 'dist', `${INJECT_STYLE_FILE_NAME}.css`) | ||
copyFileSync(scriptFilePath, `dist/${INJECT_STYLE_FILE_NAME}.css`) | ||
|
||
// write js file to dist/ | ||
writeFileSync(`dist/${INJECT_SCRIPT_FILE_NAME}.js`, generateScriptContent(webUpdateNotificationOptions, commitHash)) | ||
|
||
// write version json file to dist/ | ||
writeFileSync(`dist/${JSON_FILE_NAME}.json`, generateJSONFileContent(commitHash)) | ||
}) | ||
|
||
api.modifyHTML(($) => { | ||
if (!hiddenDefaultNotification || !customNotificationHTML) | ||
$('head').append(`<link rel="stylesheet" href="${INJECT_STYLE_FILE_NAME}.css" />`) | ||
|
||
if (!hiddenDefaultNotification) | ||
$('body').append(`<div class="${NOTIFICATION_ANCHOR_CLASS_NAME}"></div></body>`) | ||
|
||
$('body').append(`<script type="module" crossorigin src="${INJECT_SCRIPT_FILE_NAME}.js"></script>`) | ||
return $ | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { resolve } from 'path' | ||
import { defineConfig } from 'tsup' | ||
import { pkgName } from '@web-update-notification/core' | ||
|
||
export default defineConfig((options) => { // The options here is derived from CLI flags. | ||
return { | ||
entry: { | ||
index: 'src/index.ts', | ||
}, | ||
splitting: false, | ||
sourcemap: true, | ||
clean: true, | ||
dts: true, | ||
format: ['cjs', 'esm'], | ||
minify: !options.watch, | ||
onSuccess: `node ${resolve('node_modules', pkgName, 'dist', 'pluginBuildScript.js')}`, | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.