vite-plugin-qrcode 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +3 -26
- package/dist/index.cjs +13 -32
- package/dist/index.d.ts +5 -5
- package/dist/index.js +8 -31
- package/package.json +6 -8
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2022 [these people](https://github.com/svitejs/vite-plugin-qrcode/graphs/contributors)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -24,33 +24,10 @@ export default defineConfig({
|
|
|
24
24
|
```bash
|
|
25
25
|
# start vite with host to show qrcode
|
|
26
26
|
vite --host
|
|
27
|
-
|
|
28
|
-
vite v2.6.1 dev server running at:
|
|
29
|
-
|
|
30
|
-
> Local: http://localhost:3000/
|
|
31
|
-
> Network: http://192.168.2.169:3000/
|
|
32
|
-
|
|
33
|
-
ready in 186ms.
|
|
34
|
-
|
|
35
|
-
Visit page on mobile:
|
|
36
|
-
http://192.168.2.169:3000/
|
|
37
|
-
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
|
|
38
|
-
█ ▄▄▄▄▄ ██▄▄ ▀▄██▄█ ▄▄▄▄▄ █
|
|
39
|
-
█ █ █ █▀▄ █▀ ▀ █ █ █ █
|
|
40
|
-
█ █▄▄▄█ █▄▀ █▄▀ ███ █▄▄▄█ █
|
|
41
|
-
█▄▄▄▄▄▄▄█▄▀▄█ █▄▀▄█▄▄▄▄▄▄▄█
|
|
42
|
-
█ ▄██▀ ▄ █▄ █▄ █ ▀██ ▀▀██
|
|
43
|
-
██▄▀▀█▀▄▄█▄▀ ▄█▀ ▀█▄▄▀ █▄ █
|
|
44
|
-
█ ▀ ▄▄ ▄██▄ █ ▀ ▀▄▄▄████▀▄█
|
|
45
|
-
█ █▀▄█ ▄ ▀█▄▀▄▀▄█▄▀▄▀▄ █
|
|
46
|
-
█▄█████▄█▀█▄ ▄▀▀ ▄▄▄ █ ███
|
|
47
|
-
█ ▄▄▄▄▄ █ ██▄ █ █ █▄█ ▄██▄█
|
|
48
|
-
█ █ █ ██▀ ▀▀▄█▄▄▄ ▄ ▄▀▀█
|
|
49
|
-
█ █▄▄▄█ █▀█▄█ ██▀▀▄▀▀▀█▄█ █
|
|
50
|
-
█▄▄▄▄▄▄▄█▄██▄██▄▄▄█▄██▄██▄█
|
|
51
|
-
|
|
52
27
|
```
|
|
53
28
|
|
|
29
|
+
<img height="360" alt="CLI output" src="https://user-images.githubusercontent.com/34116392/181014171-aa511838-8122-48cf-ad9c-39f0368ee616.png" />
|
|
30
|
+
|
|
54
31
|
## Options
|
|
55
32
|
|
|
56
33
|
### filter
|
|
@@ -64,7 +41,7 @@ Example:
|
|
|
64
41
|
import { qrcode } from 'vite-plugin-qrcode';
|
|
65
42
|
|
|
66
43
|
export default defineConfig({
|
|
67
|
-
plugins: [qrcode({ filter: (
|
|
44
|
+
plugins: [qrcode({ filter: (url) => url === 'http://192.168.1.1:4173' })]
|
|
68
45
|
});
|
|
69
46
|
```
|
|
70
47
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -16,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
17
|
}
|
|
17
18
|
return to;
|
|
18
19
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
20
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
25
|
|
|
22
26
|
// src/index.ts
|
|
@@ -25,7 +29,6 @@ __export(src_exports, {
|
|
|
25
29
|
qrcode: () => qrcode
|
|
26
30
|
});
|
|
27
31
|
module.exports = __toCommonJS(src_exports);
|
|
28
|
-
var import_os = __toESM(require("os"), 1);
|
|
29
32
|
var import_qrcode_terminal = __toESM(require("qrcode-terminal"), 1);
|
|
30
33
|
function qrcode(options = {}) {
|
|
31
34
|
return {
|
|
@@ -47,11 +50,17 @@ function qrcode(options = {}) {
|
|
|
47
50
|
};
|
|
48
51
|
}
|
|
49
52
|
function logQrcode(server, options) {
|
|
50
|
-
|
|
53
|
+
var _a;
|
|
54
|
+
let networkUrls = (_a = server.resolvedUrls) == null ? void 0 : _a.network;
|
|
55
|
+
if (!networkUrls)
|
|
56
|
+
return;
|
|
57
|
+
if (options.filter) {
|
|
58
|
+
networkUrls = networkUrls.filter(options.filter);
|
|
59
|
+
}
|
|
51
60
|
if (networkUrls.length === 0)
|
|
52
61
|
return;
|
|
53
62
|
const info = server.config.logger.info;
|
|
54
|
-
info(" Visit page on mobile:");
|
|
63
|
+
info("\n Visit page on mobile:");
|
|
55
64
|
for (const url of networkUrls) {
|
|
56
65
|
import_qrcode_terminal.default.generate(url, { small: true }, (result) => {
|
|
57
66
|
info(` ${cyan(url)}
|
|
@@ -62,34 +71,6 @@ function logQrcode(server, options) {
|
|
|
62
71
|
function cyan(str) {
|
|
63
72
|
return `\x1B[36m${str}\x1B[0m`;
|
|
64
73
|
}
|
|
65
|
-
function getNetworkUrls(server, options) {
|
|
66
|
-
var _a;
|
|
67
|
-
const address = (_a = server.httpServer) == null ? void 0 : _a.address();
|
|
68
|
-
if (!isAddressInfo(address))
|
|
69
|
-
return [];
|
|
70
|
-
const hostname = resolveHostname(server.config.server.host);
|
|
71
|
-
if (hostname.host === "127.0.0.1")
|
|
72
|
-
return [];
|
|
73
|
-
const protocol = server.config.server.https ? "https" : "http";
|
|
74
|
-
const port = address.port;
|
|
75
|
-
const base = server.config.base;
|
|
76
|
-
return Object.values(import_os.default.networkInterfaces()).flatMap((nInterface) => nInterface != null ? nInterface : []).filter((detail) => detail && detail.address && (detail.family === "IPv4" || detail.family === 4) && !detail.address.includes("127.0.0.1") && (!options.filter || options.filter(detail.address))).map((detail) => `${protocol}://${detail.address}:${port}${base}`);
|
|
77
|
-
}
|
|
78
|
-
function isAddressInfo(v) {
|
|
79
|
-
return v.address;
|
|
80
|
-
}
|
|
81
|
-
function resolveHostname(optionsHost) {
|
|
82
|
-
let host;
|
|
83
|
-
if (optionsHost === void 0 || optionsHost === false || optionsHost === "localhost") {
|
|
84
|
-
host = "127.0.0.1";
|
|
85
|
-
} else if (optionsHost === true) {
|
|
86
|
-
host = void 0;
|
|
87
|
-
} else {
|
|
88
|
-
host = optionsHost;
|
|
89
|
-
}
|
|
90
|
-
const name = optionsHost !== "127.0.0.1" && host === "127.0.0.1" || host === "0.0.0.0" || host === "::" || host === void 0 ? "localhost" : host;
|
|
91
|
-
return { host, name };
|
|
92
|
-
}
|
|
93
74
|
// Annotate the CommonJS export names for ESM import in node:
|
|
94
75
|
0 && (module.exports = {
|
|
95
76
|
qrcode
|
package/dist/index.d.ts
CHANGED
|
@@ -6,14 +6,14 @@ interface PluginOptions {
|
|
|
6
6
|
* filter list of shown QR codes. Useful if you have multiple interfaces and only need one
|
|
7
7
|
*
|
|
8
8
|
* examples:
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* url => url.startsWith('http://192.')
|
|
10
|
+
* url => !url.startsWith('http://172.)
|
|
11
|
+
* url => url === 'http://192.168.1.70:4173'
|
|
12
12
|
*
|
|
13
|
-
* @param
|
|
13
|
+
* @param url {string} ip address
|
|
14
14
|
* @returns {boolean}
|
|
15
15
|
*/
|
|
16
|
-
filter?: (
|
|
16
|
+
filter?: (url: string) => boolean;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export { PluginOptions, qrcode };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import os from "os";
|
|
3
2
|
import qr from "qrcode-terminal";
|
|
4
3
|
function qrcode(options = {}) {
|
|
5
4
|
return {
|
|
@@ -21,11 +20,17 @@ function qrcode(options = {}) {
|
|
|
21
20
|
};
|
|
22
21
|
}
|
|
23
22
|
function logQrcode(server, options) {
|
|
24
|
-
|
|
23
|
+
var _a;
|
|
24
|
+
let networkUrls = (_a = server.resolvedUrls) == null ? void 0 : _a.network;
|
|
25
|
+
if (!networkUrls)
|
|
26
|
+
return;
|
|
27
|
+
if (options.filter) {
|
|
28
|
+
networkUrls = networkUrls.filter(options.filter);
|
|
29
|
+
}
|
|
25
30
|
if (networkUrls.length === 0)
|
|
26
31
|
return;
|
|
27
32
|
const info = server.config.logger.info;
|
|
28
|
-
info(" Visit page on mobile:");
|
|
33
|
+
info("\n Visit page on mobile:");
|
|
29
34
|
for (const url of networkUrls) {
|
|
30
35
|
qr.generate(url, { small: true }, (result) => {
|
|
31
36
|
info(` ${cyan(url)}
|
|
@@ -36,34 +41,6 @@ function logQrcode(server, options) {
|
|
|
36
41
|
function cyan(str) {
|
|
37
42
|
return `\x1B[36m${str}\x1B[0m`;
|
|
38
43
|
}
|
|
39
|
-
function getNetworkUrls(server, options) {
|
|
40
|
-
var _a;
|
|
41
|
-
const address = (_a = server.httpServer) == null ? void 0 : _a.address();
|
|
42
|
-
if (!isAddressInfo(address))
|
|
43
|
-
return [];
|
|
44
|
-
const hostname = resolveHostname(server.config.server.host);
|
|
45
|
-
if (hostname.host === "127.0.0.1")
|
|
46
|
-
return [];
|
|
47
|
-
const protocol = server.config.server.https ? "https" : "http";
|
|
48
|
-
const port = address.port;
|
|
49
|
-
const base = server.config.base;
|
|
50
|
-
return Object.values(os.networkInterfaces()).flatMap((nInterface) => nInterface != null ? nInterface : []).filter((detail) => detail && detail.address && (detail.family === "IPv4" || detail.family === 4) && !detail.address.includes("127.0.0.1") && (!options.filter || options.filter(detail.address))).map((detail) => `${protocol}://${detail.address}:${port}${base}`);
|
|
51
|
-
}
|
|
52
|
-
function isAddressInfo(v) {
|
|
53
|
-
return v.address;
|
|
54
|
-
}
|
|
55
|
-
function resolveHostname(optionsHost) {
|
|
56
|
-
let host;
|
|
57
|
-
if (optionsHost === void 0 || optionsHost === false || optionsHost === "localhost") {
|
|
58
|
-
host = "127.0.0.1";
|
|
59
|
-
} else if (optionsHost === true) {
|
|
60
|
-
host = void 0;
|
|
61
|
-
} else {
|
|
62
|
-
host = optionsHost;
|
|
63
|
-
}
|
|
64
|
-
const name = optionsHost !== "127.0.0.1" && host === "127.0.0.1" || host === "0.0.0.0" || host === "::" || host === void 0 ? "localhost" : host;
|
|
65
|
-
return { host, name };
|
|
66
|
-
}
|
|
67
44
|
export {
|
|
68
45
|
qrcode
|
|
69
46
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-qrcode",
|
|
3
3
|
"description": "Show QR code on server start",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "bluwy",
|
|
7
7
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"engines": {
|
|
22
|
-
"node": "^
|
|
22
|
+
"node": "^14.13.1 || ^16.0.0 || >=18"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|
|
@@ -40,18 +40,16 @@
|
|
|
40
40
|
"qrcode-terminal": "^0.12.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"vite": "^
|
|
43
|
+
"vite": "^3.0.0 || ^4.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/qrcode-terminal": "^0.12.0",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"vite": "^2.9.6"
|
|
47
|
+
"uvu": "^0.5.6",
|
|
48
|
+
"vite": "^4.0.1"
|
|
50
49
|
},
|
|
51
50
|
"scripts": {
|
|
52
51
|
"dev": "tsup-node --sourcemap --watch src",
|
|
53
52
|
"build": "tsup-node --dts",
|
|
54
53
|
"test": "tsm node_modules/uvu/bin.js tests"
|
|
55
|
-
}
|
|
56
|
-
"readme": "# vite-plugin-qrcode\n\nShow QR code on server start.\n\n## Installation\n\n```bash\nnpm install --save-dev vite-plugin-qrcode\n```\n\n## Usage\n\n```js\n// vite.config.js\nimport { qrcode } from 'vite-plugin-qrcode';\n\nexport default defineConfig({\n\tplugins: [\n\t\tqrcode() // only applies in dev mode\n\t]\n});\n```\n\n```bash\n# start vite with host to show qrcode\nvite --host\n\n vite v2.6.1 dev server running at:\n\n > Local: http://localhost:3000/\n > Network: http://192.168.2.169:3000/\n\n ready in 186ms.\n\n Visit page on mobile:\n http://192.168.2.169:3000/\n ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄\n █ ▄▄▄▄▄ ██▄▄ ▀▄██▄█ ▄▄▄▄▄ █\n █ █ █ █▀▄ █▀ ▀ █ █ █ █\n █ █▄▄▄█ █▄▀ █▄▀ ███ █▄▄▄█ █\n █▄▄▄▄▄▄▄█▄▀▄█ █▄▀▄█▄▄▄▄▄▄▄█\n █ ▄██▀ ▄ █▄ █▄ █ ▀██ ▀▀██\n ██▄▀▀█▀▄▄█▄▀ ▄█▀ ▀█▄▄▀ █▄ █\n █ ▀ ▄▄ ▄██▄ █ ▀ ▀▄▄▄████▀▄█\n █ █▀▄█ ▄ ▀█▄▀▄▀▄█▄▀▄▀▄ █\n █▄█████▄█▀█▄ ▄▀▀ ▄▄▄ █ ███\n █ ▄▄▄▄▄ █ ██▄ █ █ █▄█ ▄██▄█\n █ █ █ ██▀ ▀▀▄█▄▄▄ ▄ ▄▀▀█\n █ █▄▄▄█ █▀█▄█ ██▀▀▄▀▀▀█▄█ █\n █▄▄▄▄▄▄▄█▄██▄██▄▄▄█▄██▄██▄█\n\n```\n\n## Options\n\n### filter\n\nA function that allows you to select addresses to show QR-Codes for in case you have multiple interfaces\n\nExample:\n\n```js\n// vite.config.js\nimport { qrcode } from 'vite-plugin-qrcode';\n\nexport default defineConfig({\n\tplugins: [qrcode({ filter: (ip) => ip === '192.168.1.1' })]\n});\n```\n\n## License\n\n[MIT](./LICENSE)\n"
|
|
54
|
+
}
|
|
57
55
|
}
|