vite-plugin-qrcode 0.0.2 → 0.2.0
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/README.md +17 -23
- package/dist/index.cjs +24 -53
- package/dist/index.d.ts +16 -2
- package/dist/index.js +12 -35
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -24,31 +24,25 @@ export default defineConfig({
|
|
|
24
24
|
```bash
|
|
25
25
|
# start vite with host to show qrcode
|
|
26
26
|
vite --host
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
<img height="360" alt="CLI output" src="https://user-images.githubusercontent.com/34116392/181014171-aa511838-8122-48cf-ad9c-39f0368ee616.png" />
|
|
30
|
+
|
|
31
|
+
## Options
|
|
27
32
|
|
|
28
|
-
|
|
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
|
-
█▄▄▄▄▄▄▄█▄██▄██▄▄▄█▄██▄██▄█
|
|
33
|
+
### filter
|
|
51
34
|
|
|
35
|
+
A function that allows you to select addresses to show QR-Codes for in case you have multiple interfaces
|
|
36
|
+
|
|
37
|
+
Example:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
// vite.config.js
|
|
41
|
+
import { qrcode } from 'vite-plugin-qrcode';
|
|
42
|
+
|
|
43
|
+
export default defineConfig({
|
|
44
|
+
plugins: [qrcode({ filter: (url) => url === 'http://192.168.1.1:4173' })]
|
|
45
|
+
});
|
|
52
46
|
```
|
|
53
47
|
|
|
54
48
|
## License
|
package/dist/index.cjs
CHANGED
|
@@ -4,36 +4,29 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
7
|
var __export = (target, all) => {
|
|
9
|
-
__markAsModule(target);
|
|
10
8
|
for (var name in all)
|
|
11
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
10
|
};
|
|
13
|
-
var
|
|
14
|
-
if (
|
|
15
|
-
for (let key of __getOwnPropNames(
|
|
16
|
-
if (!__hasOwnProp.call(
|
|
17
|
-
__defProp(
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
16
|
}
|
|
19
|
-
return
|
|
20
|
-
};
|
|
21
|
-
var __toModule = (module2) => {
|
|
22
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
17
|
+
return to;
|
|
23
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
21
|
|
|
25
22
|
// src/index.ts
|
|
26
|
-
|
|
23
|
+
var src_exports = {};
|
|
24
|
+
__export(src_exports, {
|
|
27
25
|
qrcode: () => qrcode
|
|
28
26
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// src/index.ts
|
|
34
|
-
var import_os = __toModule(require("os"));
|
|
35
|
-
var import_qrcode_terminal = __toModule(require("qrcode-terminal"));
|
|
36
|
-
function qrcode() {
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
var import_qrcode_terminal = __toESM(require("qrcode-terminal"), 1);
|
|
29
|
+
function qrcode(options = {}) {
|
|
37
30
|
return {
|
|
38
31
|
name: "vite-plugin-qrcode",
|
|
39
32
|
apply: "serve",
|
|
@@ -44,7 +37,7 @@ function qrcode() {
|
|
|
44
37
|
const isRestart = arguments[1] === true;
|
|
45
38
|
if (!isRestart) {
|
|
46
39
|
(_a = server.httpServer) == null ? void 0 : _a.on("listening", () => {
|
|
47
|
-
setTimeout(() => logQrcode(server), 0);
|
|
40
|
+
setTimeout(() => logQrcode(server, options), 0);
|
|
48
41
|
});
|
|
49
42
|
}
|
|
50
43
|
return _listen.apply(this, arguments);
|
|
@@ -52,12 +45,18 @@ function qrcode() {
|
|
|
52
45
|
}
|
|
53
46
|
};
|
|
54
47
|
}
|
|
55
|
-
function logQrcode(server) {
|
|
56
|
-
|
|
48
|
+
function logQrcode(server, options) {
|
|
49
|
+
var _a;
|
|
50
|
+
let networkUrls = (_a = server.resolvedUrls) == null ? void 0 : _a.network;
|
|
51
|
+
if (!networkUrls)
|
|
52
|
+
return;
|
|
53
|
+
if (options.filter) {
|
|
54
|
+
networkUrls = networkUrls.filter(options.filter);
|
|
55
|
+
}
|
|
57
56
|
if (networkUrls.length === 0)
|
|
58
57
|
return;
|
|
59
58
|
const info = server.config.logger.info;
|
|
60
|
-
info(" Visit page on mobile:");
|
|
59
|
+
info("\n Visit page on mobile:");
|
|
61
60
|
for (const url of networkUrls) {
|
|
62
61
|
import_qrcode_terminal.default.generate(url, { small: true }, (result) => {
|
|
63
62
|
info(` ${cyan(url)}
|
|
@@ -66,35 +65,7 @@ function logQrcode(server) {
|
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
function cyan(str) {
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
function getNetworkUrls(server) {
|
|
72
|
-
var _a;
|
|
73
|
-
const address = (_a = server.httpServer) == null ? void 0 : _a.address();
|
|
74
|
-
if (!isAddressInfo(address))
|
|
75
|
-
return [];
|
|
76
|
-
const hostname = resolveHostname(server.config.server.host);
|
|
77
|
-
if (hostname.host === "127.0.0.1")
|
|
78
|
-
return [];
|
|
79
|
-
const protocol = server.config.server.https ? "https" : "http";
|
|
80
|
-
const port = address.port;
|
|
81
|
-
const base = server.config.base;
|
|
82
|
-
return Object.values(import_os.default.networkInterfaces()).flatMap((nInterface) => nInterface != null ? nInterface : []).filter((detail) => detail && detail.address && detail.family === "IPv4" && !detail.address.includes("127.0.0.1")).map((detail) => `${protocol}://${detail.address}:${port}${base}`);
|
|
83
|
-
}
|
|
84
|
-
function isAddressInfo(v) {
|
|
85
|
-
return v.address;
|
|
86
|
-
}
|
|
87
|
-
function resolveHostname(optionsHost) {
|
|
88
|
-
let host;
|
|
89
|
-
if (optionsHost === void 0 || optionsHost === false || optionsHost === "localhost") {
|
|
90
|
-
host = "127.0.0.1";
|
|
91
|
-
} else if (optionsHost === true) {
|
|
92
|
-
host = void 0;
|
|
93
|
-
} else {
|
|
94
|
-
host = optionsHost;
|
|
95
|
-
}
|
|
96
|
-
const name = optionsHost !== "127.0.0.1" && host === "127.0.0.1" || host === "0.0.0.0" || host === "::" || host === void 0 ? "localhost" : host;
|
|
97
|
-
return { host, name };
|
|
68
|
+
return `\x1B[36m${str}\x1B[0m`;
|
|
98
69
|
}
|
|
99
70
|
// Annotate the CommonJS export names for ESM import in node:
|
|
100
71
|
0 && (module.exports = {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
-
declare function qrcode(): Plugin;
|
|
3
|
+
declare function qrcode(options?: PluginOptions): Plugin;
|
|
4
|
+
interface PluginOptions {
|
|
5
|
+
/**
|
|
6
|
+
* filter list of shown QR codes. Useful if you have multiple interfaces and only need one
|
|
7
|
+
*
|
|
8
|
+
* examples:
|
|
9
|
+
* url => url.startsWith('http://192.')
|
|
10
|
+
* url => !url.startsWith('http://172.)
|
|
11
|
+
* url => url === 'http://192.168.1.70:4173'
|
|
12
|
+
*
|
|
13
|
+
* @param url {string} ip address
|
|
14
|
+
* @returns {boolean}
|
|
15
|
+
*/
|
|
16
|
+
filter?: (url: string) => boolean;
|
|
17
|
+
}
|
|
4
18
|
|
|
5
|
-
export { qrcode };
|
|
19
|
+
export { PluginOptions, qrcode };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import os from "os";
|
|
3
2
|
import qr from "qrcode-terminal";
|
|
4
|
-
function qrcode() {
|
|
3
|
+
function qrcode(options = {}) {
|
|
5
4
|
return {
|
|
6
5
|
name: "vite-plugin-qrcode",
|
|
7
6
|
apply: "serve",
|
|
@@ -12,7 +11,7 @@ function qrcode() {
|
|
|
12
11
|
const isRestart = arguments[1] === true;
|
|
13
12
|
if (!isRestart) {
|
|
14
13
|
(_a = server.httpServer) == null ? void 0 : _a.on("listening", () => {
|
|
15
|
-
setTimeout(() => logQrcode(server), 0);
|
|
14
|
+
setTimeout(() => logQrcode(server, options), 0);
|
|
16
15
|
});
|
|
17
16
|
}
|
|
18
17
|
return _listen.apply(this, arguments);
|
|
@@ -20,12 +19,18 @@ function qrcode() {
|
|
|
20
19
|
}
|
|
21
20
|
};
|
|
22
21
|
}
|
|
23
|
-
function logQrcode(server) {
|
|
24
|
-
|
|
22
|
+
function logQrcode(server, options) {
|
|
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)}
|
|
@@ -34,35 +39,7 @@ function logQrcode(server) {
|
|
|
34
39
|
}
|
|
35
40
|
}
|
|
36
41
|
function cyan(str) {
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
function getNetworkUrls(server) {
|
|
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.address.includes("127.0.0.1")).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 };
|
|
42
|
+
return `\x1B[36m${str}\x1B[0m`;
|
|
66
43
|
}
|
|
67
44
|
export {
|
|
68
45
|
qrcode
|
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.0
|
|
4
|
+
"version": "0.2.0",
|
|
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,17 +40,17 @@
|
|
|
40
40
|
"qrcode-terminal": "^0.12.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"vite": "^
|
|
43
|
+
"vite": "^3.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/qrcode-terminal": "^0.12.0",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"vite": "^
|
|
47
|
+
"rollup": "^2.77.1",
|
|
48
|
+
"uvu": "^0.5.6",
|
|
49
|
+
"vite": "^3.0.3"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"dev": "tsup-node --sourcemap --watch src",
|
|
53
53
|
"build": "tsup-node --dts",
|
|
54
|
-
"test": "
|
|
54
|
+
"test": "tsm node_modules/uvu/bin.js tests"
|
|
55
55
|
}
|
|
56
56
|
}
|