vite-plugin-url-copy
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -32,4 +32,7 @@ import { Plugin } from 'vite'; | ||
/** | ||
* Read the {@link https://github.com/XioDone/vite-plugin-url-copy | documentation} for more details. | ||
*/ | ||
declare function VitePluginServerUrl(rawOptions?: Options): Plugin; | ||
export { type Options, type ResolveOptions, VitePluginServerUrl as default }; |
@@ -1,8 +0,8 @@ | ||
import w,{consola as $}from"consola";import S from"clipboardy";import{colorize as d}from"consola/utils";import{renderUnicodeCompact as x}from"uqr";const l=console.log;function P(t){return Object.prototype.toString.call(t)==="[object Object]"}function h(t=0){return new Promise(e=>{setTimeout(()=>{e()},t)})}async function f(t){try{return await t()}catch(e){return Promise.reject(e)}}let v={};function k(t){let e=!1;function o(n,i){for(const r of Object.keys(n))if(P(n[r])){const c=o(n[r],i[r]);if(c)return c}else if(n[r]!==i[r])return e=!0,e;return e}return o(t,v),e&&(v=t),e}const U=10;let y=0;async function b(t){const e=t.resolvedUrls;if(y>=U)throw new Error("timeout");return e?(y=0,e):(y++,await h(),b(t))}const p=[];function C(...t){p.push(...t)}const B=d("blue"," vite-plugin-url-copy_debug ");function O(t){if(!t)return;const e=p.length;let o="";for(const[n,i]of p.entries())o+=d("blue",i),n!==e-1&&(o+=` | ||
import w,{consola as $}from"consola";import{colorize as d}from"consola/utils";import{renderUnicodeCompact as S}from"uqr";const l=console.log;function x(t){return Object.prototype.toString.call(t)==="[object Object]"}function h(t=0){return new Promise(e=>{setTimeout(()=>{e()},t)})}async function f(t){try{return await t()}catch(e){return Promise.reject(e)}}let v={};function P(t){let e=!1;function o(n,i){for(const r of Object.keys(n))if(x(n[r])){const c=o(n[r],i[r]);if(c)return c}else if(n[r]!==i[r])return e=!0,e;return e}return o(t,v),e&&(v=t),e}const k=10;let y=0;async function b(t){const e=t.resolvedUrls;if(y>=k)throw new Error("timeout");return e?(y=0,e):(y++,await h(),b(t))}const p=[];function C(...t){p.push(...t)}const U=d("blue"," vite-plugin-url-copy_debug ");function O(t){if(!t)return;const e=p.length;let o="";for(const[n,i]of p.entries())o+=d("blue",i),n!==e-1&&(o+=` | ||
`);l(` | ||
`),w.box({title:B,message:o,style:{padding:1,borderColor:"gray",borderStyle:"rounded"}}),p.length=0}const j=(t,e)=>{const{custom:o,mode:n,disabled:i}=e.copy,r=e.debug;if(!i)return f(async()=>{let c="",u=!1;typeof o=="string"&&o&&(u=!0,c=o),c||(c=t[n][0]);const s=u?"cutsom":n;if(r&&C(`copy: ${s} - ${c}`,`copy: ${JSON.stringify(e.copy)}`),!c){await h(),$.warn(`url-copy: ${n} mode URL is undefined, Please check your vite configuration.`);return}return await S.write(c),l(d("green",` | ||
\u2714 `),d("bgGreen",` \xB7${s}\xB7 already copied to clipboard - ${c} `)),c}).catch(c=>{$.warn(`url-copy: ${c}`)})},m="network",q=(t,e)=>{const{custom:o,disabled:n}=e.qrcode,i=e.debug;if(n)return;let r="",c=!1;if(typeof o=="string"&&o&&(c=!0,r=o),r||(r=t[m][0]),i&&C(`qrcode: ${c?"cutsom":m} - ${r}`,`qrcode: ${JSON.stringify(e.copy)}`),!r){w.warn("url-copy: QR-Code uses a network URL, Please check your vite configuration.");return}const u=Q(r);let s="";try{s=[...u].map((a,g)=>(g||(a=` ${a}`),a===` | ||
`),w.box({title:U,message:o,style:{padding:1,borderColor:"gray",borderStyle:"rounded"}}),p.length=0}const j=(t,e)=>{const{custom:o,mode:n,disabled:i}=e.copy,r=e.debug;if(!i)return f(async()=>{let c="",u=!1;typeof o=="string"&&o&&(u=!0,c=o),c||(c=t[n][0]);const s=u?"cutsom":n;if(r&&C(`copy: ${s} - ${c}`,`copy: ${JSON.stringify(e.copy)}`),!c){await h(),$.warn(`url-copy: ${n} mode URL is undefined, Please check your vite configuration.`);return}return await(await import("clipboardy")).default.write(c),l(d("green",` | ||
\u2714 `),d("bgGreen",` \xB7${s}\xB7 already copied to clipboard - ${c} `)),c}).catch(c=>{$.warn(`url-copy: ${c}`)})},m="network",q=(t,e)=>{const{custom:o,disabled:n}=e.qrcode,i=e.debug;if(n)return;let r="",c=!1;if(typeof o=="string"&&o&&(c=!0,r=o),r||(r=t[m][0]),i&&C(`qrcode: ${c?"cutsom":m} - ${r}`,`qrcode: ${JSON.stringify(e.copy)}`),!r){w.warn("url-copy: QR-Code uses a network URL, Please check your vite configuration.");return}const u=B(r);let s="";try{s=[...u].map((a,g)=>(g||(a=` ${a}`),a===` | ||
`&&(a=`${a} `),a)).join("")}catch{s=u}l(d("green",` | ||
\u2714 `),d("bgGreen",` \xB7QRCode\xB7 of the ${m} - ${r} `),` | ||
`),l(d("green",s))};function Q(t){return x(t,{ecc:"L",border:1})}const L={copy:{disabled:!1,mode:"local",custom:""},qrcode:{disabled:!0,custom:""},disabled:!1,debug:!1};function N(t){const{disabled:e,copy:o={},qrcode:n={},debug:i}=t,{disabled:r,copy:c,qrcode:u,debug:s}=L;return{copy:{...c,...o},qrcode:{...u,...n},disabled:e??r,debug:i??s}}function E(t={}){const e=N(t);return{name:"server-url-copy",configureServer(o){if(e.disabled)return;const n=o.listen,i=o;i.listen=function(...r){const[c,u]=r;return f(async()=>{const s=await n.apply(this,r),a=await b(s);return f(async()=>{const g=s.config.server.port,R=k({port:g,...e});u&&!R||(await j(a,e),q(a,e),O(e.debug))}),s})}},configurePreviewServer(o){e.disabled||o.httpServer.once("listening",()=>{f(async()=>{const n=await b(o);await j(n,e),q(n,e),O(e.debug)})})}}}export{E as default}; | ||
`),l(d("green",s))};function B(t){return S(t,{ecc:"L",border:1})}const Q={copy:{disabled:!1,mode:"local",custom:""},qrcode:{disabled:!0,custom:""},disabled:!1,debug:!1};function L(t){const{disabled:e,copy:o={},qrcode:n={},debug:i}=t,{disabled:r,copy:c,qrcode:u,debug:s}=Q;return{copy:{...c,...o},qrcode:{...u,...n},disabled:e??r,debug:i??s}}function N(t={}){const e=L(t);return{name:"server-url-copy",configureServer(o){if(e.disabled)return;const n=o.listen,i=o;i.listen=function(...r){const[c,u]=r;return f(async()=>{const s=await n.apply(this,r),a=await b(s);return f(async()=>{const g=s.config.server.port,R=P({port:g,...e});u&&!R||(await j(a,e),q(a,e),O(e.debug))}),s})}},configurePreviewServer(o){e.disabled||o.httpServer.once("listening",()=>{f(async()=>{const n=await b(o);await j(n,e),q(n,e),O(e.debug)})})}}}export{N as default}; |
{ | ||
"name": "vite-plugin-url-copy", | ||
"type": "module", | ||
"version": "1.1.0", | ||
"packageManager": "pnpm@8.12.1", | ||
"description": "Auto copy the vite server url when dev or preview", | ||
"version": "1.1.1", | ||
"packageManager": "pnpm@8.13.1", | ||
"description": "Auto copy the Vite server URL and generate a QR code for easy access during dev or preview", | ||
"author": "XioDone", | ||
@@ -56,4 +56,4 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@antfu/eslint-config": "^2.4.6", | ||
"@types/node": "^20.10.5", | ||
"@antfu/eslint-config": "^2.6.1", | ||
"@types/node": "^20.10.6", | ||
"bumpp": "^9.2.1", | ||
@@ -60,0 +60,0 @@ "eslint": "^8.56.0", |
@@ -6,21 +6,42 @@ <h1 align="center"> | ||
<p align="center"> | ||
<a href="https://github.com/XioDone/vite-plugin-url-copy" target="_blank"><img alt="Github Badge" src="https://img.shields.io/badge/Star---?logo=github&logoColor=aliceblue&labelColor=18181B&color=61C200"></a>   | ||
<a href="https://www.npmjs.com/package/vite-plugin-url-copy" target="_blank"><img src="https://img.shields.io/npm/v/vite-plugin-url-copy.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="Version"></a> | ||
</p> | ||
<p align="center">⚡️ Auto copy the vite server URL & generate a QR code when dev or preview.</p> | ||
<p align="center">⚡️ Auto copy the Vite server URL and generate a QR code for easy access during dev or preview.</p> | ||
<p align="center"><img src="example/public/preview.png" width="100%"></p> | ||
##### Features | ||
- 🌟 Ready to use, supports dev and preview mode. | ||
- 💭 Supports copy server URL (local and network types). | ||
- 📱 Supports generate network URL QR code. | ||
- 💡 Customizable characters for copy or generate QR code. | ||
- 😃 Friendly Hot Reload, When the vite server performs a hot restart, the plugin will be reloaded again only after the plugin's configuration or port has changed. | ||
> [!IMPORTANT] | ||
> Recommended minimum vite version is v4. | ||
> | ||
> Vite CJS Node API deprecated: the CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details. | ||
> | ||
> We recommend configuring ESM as the default, and we will deprecate the CJS build in v2. | ||
## Install | ||
```bash | ||
pnpm i vite-plugin-url-copy -D | ||
``` | ||
## Usage | ||
### Install | ||
- Configure ESM as default in `package.json`, it's up to you | ||
```bash | ||
pnpm i -D vite-plugin-url-copy | ||
```json | ||
{ | ||
"type": "module" | ||
} | ||
``` | ||
Add plugin to your `vite.config.ts` | ||
- Add plugin to your `vite.config.ts` | ||
@@ -41,3 +62,3 @@ ```ts | ||
#### QR code is disabled by default and needs to be explicitly enabled | ||
#### !!! QR code is disabled by default and needs to be explicitly enabled | ||
@@ -48,7 +69,17 @@ ```ts | ||
qrcode: { | ||
disabled: false | ||
} | ||
disabled: false, | ||
}, | ||
}) | ||
``` | ||
- Run | ||
```bash | ||
pnpm dev | ||
#or | ||
pnpm preview | ||
``` | ||
## Configuration | ||
@@ -98,4 +129,8 @@ | ||
## Ending | ||
Hey there! If you enjoy my project, please give me a ⭐️. It means a lot to me! Thank you once again for your support! 😊 | ||
## License | ||
[MIT](./LICENSE) License © 2023 [XioDone](https://github.com/XioDone) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13566
66
133