From 77280dc11cd536f813c8f9b2d141608495c26cf0 Mon Sep 17 00:00:00 2001 From: Robin Tail Date: Tue, 1 Oct 2024 20:10:26 +0200 Subject: [PATCH] QR codes for documentation and sources on startup. --- LICENSE-3RD-PARTY.md | 27 +++++++++++++++++++++++ coverage.svg | 2 +- package.json | 1 + src/startup-logo.ts | 38 +++++++++++++++++++++++++++++++++ tests/unit/startup-logo.spec.ts | 2 +- tsup.config.ts | 19 ++++++++++++++++- yarn.lock | 36 +++++++------------------------ 7 files changed, 94 insertions(+), 31 deletions(-) diff --git a/LICENSE-3RD-PARTY.md b/LICENSE-3RD-PARTY.md index 808a6f458..64a065633 100644 --- a/LICENSE-3RD-PARTY.md +++ b/LICENSE-3RD-PARTY.md @@ -64,3 +64,30 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +## uqr + +https://github.com/unjs/uqr + +MIT License + +Copyright (c) Project Nayuki +Copyright (c) 2023 Anthony Fu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/coverage.svg b/coverage.svg index 5bb55be2e..e7da0c4c2 100644 --- a/coverage.svg +++ b/coverage.svg @@ -1 +1 @@ -Coverage: 100%Coverage100% \ No newline at end of file +Coverage: 98.55%Coverage98.55% \ No newline at end of file diff --git a/package.json b/package.json index afe053793..63098832e 100644 --- a/package.json +++ b/package.json @@ -156,6 +156,7 @@ "typescript": "^5.5.2", "typescript-eslint": "^8.0.0", "undici": "^6.19.8", + "uqr": "^0.1.2", "vitest": "^2.0.3", "zod": "^3.23.0" }, diff --git a/src/startup-logo.ts b/src/startup-logo.ts index 95456834b..dedb32d58 100644 --- a/src/startup-logo.ts +++ b/src/startup-logo.ts @@ -1,5 +1,41 @@ import { Ansis, gray, hex, italic, whiteBright } from "ansis"; +const unbin = (subject: unknown) => { + if (!Array.isArray(subject)) return []; + const bools = subject.map((encoded) => + typeof encoded === "number" + ? encoded + .toString(2) + .split("") + .map((bit) => bit === "1") + : [], + ); + const size = Math.max(...bools.map((row) => row.length)); + return bools.map((row) => + Array(size - row.length + 1) + .fill(false) // restores margin of leading zeros + .concat(row), + ); +}; + +const render = (data: unknown) => { + const result = unbin(data); + const at = (x: number, y: number) => + y < result.length && x < result[y].length ? result[y][x] : true; + const lines: string[] = []; + for (let row = 0; row < result.length; row += 2) { + let line = ""; + for (let col = 0; col < result[row].length; col++) { + if (!at(col, row) && !at(col, row + 1)) line += "\u2588"; + else if (!at(col, row) && at(col, row + 1)) line += "\u2580"; + else if (at(col, row) && !at(col, row + 1)) line += "\u2584"; + else line += " "; + } + lines.push(line); + } + return lines.join("\n"); +}; + export const getStartupLogo = () => { const proud = italic("Proudly supports transgender community.".padStart(109)); const slogan = italic( @@ -36,6 +72,8 @@ export const getStartupLogo = () => { 888${proud} ${dedicationMessage}888${slogan} ${thanks} +${render(process.env.DOCS_QR)} +${render(process.env.GITHUB_QR)} `; return logo diff --git a/tests/unit/startup-logo.spec.ts b/tests/unit/startup-logo.spec.ts index c0469477f..f3e071e23 100644 --- a/tests/unit/startup-logo.spec.ts +++ b/tests/unit/startup-logo.spec.ts @@ -3,7 +3,7 @@ import { getStartupLogo } from "../../src/startup-logo"; describe("Startup logo", () => { describe("getStartupLogo()", () => { test("should return the logo", () => { - expect(getStartupLogo().split("\n").length).toBe(14); + expect(getStartupLogo().split("\n").length).toBe(16); }); }); }); diff --git a/tsup.config.ts b/tsup.config.ts index 32e898207..0b170eda7 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,9 +1,22 @@ import { defineConfig, Options } from "tsup"; import { version, engines, name } from "./package.json"; import semver from "semver"; +import { encode, QrCodeGenerateResult } from "uqr"; const minNode = semver.minVersion(engines.node)!; +const toBin = ({ data }: QrCodeGenerateResult) => + data.map((row) => parseInt(row.map((bit) => (bit ? "1" : "0")).join(""), 2)); + +const qrOptions = { minVersion: 4, maxVersion: 4, boostEcc: true }; +const qrDocs = toBin(encode(`https://ez.robintail.cz/v${version}`, qrOptions)); +const qrGithub = toBin( + encode( + `https://github.com/RobinTail/express-zod-api/tree/v${version}`, + qrOptions, + ), +); + const commons: Options = { format: ["cjs", "esm"], splitting: false, @@ -31,7 +44,11 @@ export default defineConfig([ options.supported["dynamic-import"] = false; } options.define = { - "process.env.TSUP_BUILD": `"v${version} (${format.toUpperCase()})"`, + "process.env.TSUP_BUILD": JSON.stringify( + `v${version} (${format.toUpperCase()})`, + ), + "process.env.DOCS_QR": JSON.stringify(qrDocs), + "process.env.GITHUB_QR": JSON.stringify(qrGithub), }; }, }, diff --git a/yarn.lock b/yarn.lock index 9c79c9c56..792bbd10a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3323,16 +3323,7 @@ streamsearch@^1.1.0: resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-1.1.0.tgz#404dd1e2247ca94af554e841a8ef0eaa238da764" integrity sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg== -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -string-width@^4.1.0, string-width@^4.2.0: +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -3350,14 +3341,7 @@ string-width@^5.0.1, string-width@^5.1.2: emoji-regex "^9.2.2" strip-ansi "^7.0.1" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - -strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -3678,6 +3662,11 @@ update-browserslist-db@^1.1.0: escalade "^3.1.2" picocolors "^1.0.1" +uqr@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/uqr/-/uqr-0.1.2.tgz#5c6cd5dcff9581f9bb35b982cb89e2c483a41d7d" + integrity sha512-MJu7ypHq6QasgF5YRTjqscSzQp/W11zoUk6kvmlH+fmWEs63Y0Eib13hYFwAzagRJcVY8WVnlV+eBDUGMJ5IbA== + uri-js@^4.2.2: version "4.4.1" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e" @@ -3788,16 +3777,7 @@ word-wrap@^1.2.5: resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34" integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - -wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==