vite-plugin-qrcode 0.0.2 → 0.1.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 CHANGED
@@ -51,6 +51,23 @@ vite --host
51
51
 
52
52
  ```
53
53
 
54
+ ## Options
55
+
56
+ ### filter
57
+
58
+ A function that allows you to select addresses to show QR-Codes for in case you have multiple interfaces
59
+
60
+ Example:
61
+
62
+ ```js
63
+ // vite.config.js
64
+ import { qrcode } from 'vite-plugin-qrcode';
65
+
66
+ export default defineConfig({
67
+ plugins: [qrcode({ filter: (ip) => ip === '192.168.1.1' })]
68
+ });
69
+ ```
70
+
54
71
  ## License
55
72
 
56
73
  [MIT](./LICENSE)
package/dist/index.cjs CHANGED
@@ -6,34 +6,34 @@ var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
8
  var __export = (target, all) => {
9
- __markAsModule(target);
10
9
  for (var name in all)
11
10
  __defProp(target, name, { get: all[name], enumerable: true });
12
11
  };
13
- var __reExport = (target, module2, desc) => {
12
+ var __reExport = (target, module2, copyDefault, desc) => {
14
13
  if (module2 && typeof module2 === "object" || typeof module2 === "function") {
15
14
  for (let key of __getOwnPropNames(module2))
16
- if (!__hasOwnProp.call(target, key) && key !== "default")
15
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
17
16
  __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
18
17
  }
19
18
  return target;
20
19
  };
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);
20
+ var __toESM = (module2, isNodeMode) => {
21
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
23
22
  };
23
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
+ return (module2, temp) => {
25
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
+ };
27
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
24
28
 
25
29
  // src/index.ts
26
- __export(exports, {
30
+ var src_exports = {};
31
+ __export(src_exports, {
27
32
  qrcode: () => qrcode
28
33
  });
29
-
30
- // ../../node_modules/.pnpm/tsup@5.2.1_typescript@4.4.3/node_modules/tsup/assets/cjs_shims.js
31
- var importMetaUrlShim = typeof document === "undefined" ? new (require("url")).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
32
-
33
- // src/index.ts
34
- var import_os = __toModule(require("os"));
35
- var import_qrcode_terminal = __toModule(require("qrcode-terminal"));
36
- function qrcode() {
34
+ var import_os = __toESM(require("os"), 1);
35
+ var import_qrcode_terminal = __toESM(require("qrcode-terminal"), 1);
36
+ function qrcode(options = {}) {
37
37
  return {
38
38
  name: "vite-plugin-qrcode",
39
39
  apply: "serve",
@@ -44,7 +44,7 @@ function qrcode() {
44
44
  const isRestart = arguments[1] === true;
45
45
  if (!isRestart) {
46
46
  (_a = server.httpServer) == null ? void 0 : _a.on("listening", () => {
47
- setTimeout(() => logQrcode(server), 0);
47
+ setTimeout(() => logQrcode(server, options), 0);
48
48
  });
49
49
  }
50
50
  return _listen.apply(this, arguments);
@@ -52,8 +52,8 @@ function qrcode() {
52
52
  }
53
53
  };
54
54
  }
55
- function logQrcode(server) {
56
- const networkUrls = getNetworkUrls(server);
55
+ function logQrcode(server, options) {
56
+ const networkUrls = getNetworkUrls(server, options);
57
57
  if (networkUrls.length === 0)
58
58
  return;
59
59
  const info = server.config.logger.info;
@@ -66,9 +66,9 @@ function logQrcode(server) {
66
66
  }
67
67
  }
68
68
  function cyan(str) {
69
- return `${str}`;
69
+ return `\x1B[36m${str}\x1B[0m`;
70
70
  }
71
- function getNetworkUrls(server) {
71
+ function getNetworkUrls(server, options) {
72
72
  var _a;
73
73
  const address = (_a = server.httpServer) == null ? void 0 : _a.address();
74
74
  if (!isAddressInfo(address))
@@ -79,7 +79,7 @@ function getNetworkUrls(server) {
79
79
  const protocol = server.config.server.https ? "https" : "http";
80
80
  const port = address.port;
81
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}`);
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") && (!options.filter || options.filter(detail.address))).map((detail) => `${protocol}://${detail.address}:${port}${base}`);
83
83
  }
84
84
  function isAddressInfo(v) {
85
85
  return v.address;
@@ -96,6 +96,7 @@ function resolveHostname(optionsHost) {
96
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
97
  return { host, name };
98
98
  }
99
+ module.exports = __toCommonJS(src_exports);
99
100
  // Annotate the CommonJS export names for ESM import in node:
100
101
  0 && (module.exports = {
101
102
  qrcode
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
+ * ip => ip.startsWith('192.')
10
+ * ip => !ip.startsWith('172.)
11
+ * ip => ip === '192.168.1.70'
12
+ *
13
+ * @param ip {string} ip address
14
+ * @returns {boolean}
15
+ */
16
+ filter?: (ip: string) => boolean;
17
+ }
4
18
 
5
- export { qrcode };
19
+ export { PluginOptions, qrcode };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/index.ts
2
2
  import os from "os";
3
3
  import qr from "qrcode-terminal";
4
- function qrcode() {
4
+ function qrcode(options = {}) {
5
5
  return {
6
6
  name: "vite-plugin-qrcode",
7
7
  apply: "serve",
@@ -12,7 +12,7 @@ function qrcode() {
12
12
  const isRestart = arguments[1] === true;
13
13
  if (!isRestart) {
14
14
  (_a = server.httpServer) == null ? void 0 : _a.on("listening", () => {
15
- setTimeout(() => logQrcode(server), 0);
15
+ setTimeout(() => logQrcode(server, options), 0);
16
16
  });
17
17
  }
18
18
  return _listen.apply(this, arguments);
@@ -20,8 +20,8 @@ function qrcode() {
20
20
  }
21
21
  };
22
22
  }
23
- function logQrcode(server) {
24
- const networkUrls = getNetworkUrls(server);
23
+ function logQrcode(server, options) {
24
+ const networkUrls = getNetworkUrls(server, options);
25
25
  if (networkUrls.length === 0)
26
26
  return;
27
27
  const info = server.config.logger.info;
@@ -34,9 +34,9 @@ function logQrcode(server) {
34
34
  }
35
35
  }
36
36
  function cyan(str) {
37
- return `${str}`;
37
+ return `\x1B[36m${str}\x1B[0m`;
38
38
  }
39
- function getNetworkUrls(server) {
39
+ function getNetworkUrls(server, options) {
40
40
  var _a;
41
41
  const address = (_a = server.httpServer) == null ? void 0 : _a.address();
42
42
  if (!isAddressInfo(address))
@@ -47,7 +47,7 @@ function getNetworkUrls(server) {
47
47
  const protocol = server.config.server.https ? "https" : "http";
48
48
  const port = address.port;
49
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}`);
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") && (!options.filter || options.filter(detail.address))).map((detail) => `${protocol}://${detail.address}:${port}${base}`);
51
51
  }
52
52
  function isAddressInfo(v) {
53
53
  return v.address;
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.2",
4
+ "version": "0.1.0",
5
5
  "license": "MIT",
6
6
  "author": "bluwy",
7
7
  "type": "module",
@@ -44,13 +44,14 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/qrcode-terminal": "^0.12.0",
47
- "uvu": "^0.5.1",
48
- "rollup": "^2.57.0",
49
- "vite": "^2.6.1"
47
+ "rollup": "^2.70.0",
48
+ "uvu": "^0.5.3",
49
+ "vite": "^2.8.6"
50
50
  },
51
51
  "scripts": {
52
52
  "dev": "tsup-node --sourcemap --watch src",
53
53
  "build": "tsup-node --dts",
54
- "test": "esmo node_modules/uvu/bin.js tests"
55
- }
54
+ "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"
56
57
  }