vite-plugin-url-copy
Advanced tools
Comparing version 1.1.1 to 1.1.2
import { Plugin } from 'vite'; | ||
type DeepRequired<T> = { | ||
[P in keyof T]-?: DeepRequired<T[P]>; | ||
}; | ||
interface CopyOptions { | ||
@@ -15,3 +12,3 @@ disabled?: boolean; | ||
*/ | ||
custom?: string | undefined; | ||
custom?: string | ((URL: string) => string); | ||
} | ||
@@ -23,3 +20,3 @@ interface QRCodeOptions { | ||
*/ | ||
custom?: string; | ||
custom?: string | ((URL: string) => string); | ||
} | ||
@@ -32,3 +29,2 @@ interface Options { | ||
} | ||
type ResolveOptions = DeepRequired<Options>; | ||
@@ -40,2 +36,2 @@ /** | ||
export { type Options, type ResolveOptions, VitePluginServerUrl as default }; | ||
export { type Options, VitePluginServerUrl as default }; |
@@ -1,8 +0,8 @@ | ||
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+=` | ||
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(c,i){for(const r of Object.keys(c))if(x(c[r])){const n=o(c[r],i[r]);if(n)return n}else if(c[r]!==i[r])return e=!0,e;return e}return o(t,v),e&&(v=t),e}const k=10;let b=0;async function m(t){const e=t.resolvedUrls;if(b>=k)throw new Error("timeout");return e?(b=0,e):(b++,await h(),m(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[c,i]of p.entries())o+=d("blue",i),c!==e-1&&(o+=` | ||
`);l(` | ||
`),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===` | ||
`),w.box({title:U,message:o,style:{padding:1,borderColor:"gray",borderStyle:"rounded"}}),p.length=0}const j=(t,e)=>{const{custom:o,mode:c,disabled:i}=e.copy,r=e.debug;if(!i)return f(async()=>{let n="",u=!1;typeof o=="string"&&o&&(u=!0,n=o),typeof o=="function"&&(u=!0,n=o(t[c][0])),n||(n=t[c][0]);const s=u?"cutsom":c;if(r&&C(`copy: ${s} - ${n}`,`copy: ${JSON.stringify(e.copy)}`),!n){await h(),$.warn(`url-copy: ${c} mode URL is undefined, Please check your vite configuration.`);return}return await(await import("clipboardy")).default.write(n),l(d("green",` | ||
\u2714 `),d("bgGreen",` \xB7${s}\xB7 already copied to clipboard - ${n} `)),n}).catch(n=>{$.warn(`url-copy: ${n}`)})},g="network",q=(t,e)=>{const{custom:o,disabled:c}=e.qrcode,i=e.debug;if(c)return;let r="",n=!1;if(typeof o=="string"&&o&&(n=!0,r=o),typeof o=="function"&&(n=!0,r=o(t[g][0])),r||(r=t[g][0]),i&&C(`qrcode: ${n?"cutsom":g} - ${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,y)=>(y||(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 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}; | ||
\u2714 `),d("bgGreen",` \xB7QRCode\xB7 of the ${g} - ${r} `),` | ||
`),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:c={},debug:i}=t,{disabled:r,copy:n,qrcode:u,debug:s}=Q;return{copy:{...n,...o},qrcode:{...u,...c},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 c=o.listen,i=o;i.listen=function(...r){const[n,u]=r;return f(async()=>{const s=await c.apply(this,r),a=await m(s);return f(async()=>{const y=s.config.server.port,R=P({port:y,...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 c=await m(o);await j(c,e),q(c,e),O(e.debug)})})}}}export{N as default}; |
{ | ||
"name": "vite-plugin-url-copy", | ||
"type": "module", | ||
"version": "1.1.1", | ||
"packageManager": "pnpm@8.13.1", | ||
"version": "1.1.2", | ||
"packageManager": "pnpm@8.15.1", | ||
"description": "Auto copy the Vite server URL and generate a QR code for easy access during dev or preview", | ||
@@ -22,3 +22,4 @@ "author": "XioDone", | ||
"QRCode", | ||
"copy server url" | ||
"copy server url", | ||
"vite-plugin-url-copy" | ||
], | ||
@@ -46,2 +47,4 @@ "exports": { | ||
"lint": "eslint .", | ||
"lint:fix": "eslint --fix .", | ||
"postinstall": "npx simple-git-hooks", | ||
"c": "rm pnpm-lock.yaml package-lock.json & rm -rf node_modules dist example/node_modules" | ||
@@ -58,11 +61,19 @@ }, | ||
"devDependencies": { | ||
"@antfu/eslint-config": "^2.6.1", | ||
"@types/node": "^20.10.6", | ||
"bumpp": "^9.2.1", | ||
"@antfu/eslint-config": "^2.6.4", | ||
"@types/node": "^20.11.16", | ||
"bumpp": "^9.3.0", | ||
"eslint": "^8.56.0", | ||
"lint-staged": "^15.2.2", | ||
"simple-git-hooks": "^2.9.0", | ||
"tsup": "^8.0.1", | ||
"typescript": "^5.3.3", | ||
"unbuild": "^2.0.0", | ||
"vite": "^5.0.10" | ||
"vite": "^5.0.12" | ||
}, | ||
"simple-git-hooks": { | ||
"pre-commit": "pnpm lint-staged" | ||
}, | ||
"lint-staged": { | ||
"*": "eslint --fix" | ||
} | ||
} |
@@ -6,3 +6,3 @@ <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://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> | ||
@@ -58,3 +58,3 @@ </p> | ||
host: true, | ||
}, | ||
} | ||
}) | ||
@@ -86,21 +86,26 @@ ``` | ||
- [Example](./example) | ||
- Refer to the [type definitions](./src/types.ts) for more options | ||
```ts | ||
ServerUrlCopy({ | ||
copy: { | ||
// 'local' | 'network', default 'local' | ||
// 'local' | 'network' | ||
mode: 'local', | ||
// Custom any string to copy when the server start, It will overwrite the server URL | ||
// Custom string to copy when the server start, It will overwrite the server URL | ||
// custom?: string | ((URL: string) => string) | ||
custom: '', | ||
// Disable Copy, default false | ||
// Disable Copy | ||
disabled: false, | ||
}, | ||
qrcode: { | ||
// Custom any string for the generate network QR code, It will overwrite the server URL | ||
// Custom string for the generate network QR code, It will overwrite the server URL | ||
// custom?: string | ((URL: string) => string) | ||
custom: '', | ||
// Disable QRCode, default true | ||
// Disable QRCode | ||
disabled: true, | ||
}, | ||
// Disable plugin, default false | ||
// Disable plugin | ||
disabled: false, | ||
// Log config info, default false | ||
// Log config info | ||
debug: false, | ||
@@ -112,3 +117,3 @@ }) | ||
```js | ||
```jsonc | ||
// package.json | ||
@@ -120,3 +125,5 @@ { | ||
} | ||
``` | ||
```ts | ||
// or vite.config.ts | ||
@@ -133,6 +140,6 @@ export default defineConfig({ | ||
Hey there! If you enjoy my project, please give me a ⭐️. It means a lot to me! Thank you once again for your support! 😊 | ||
Hey there! If you enjoy my project, please give me a ⭐️. Thanks! | ||
## License | ||
[MIT](./LICENSE) License © 2023 [XioDone](https://github.com/XioDone) | ||
[MIT](./LICENSE) License © 2023-PRESENT [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
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
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
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
13942
140
10
64
1