Skip to content

Commit

Permalink
QR codes for documentation and sources on startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail committed Oct 1, 2024
1 parent 77f6a53 commit 77280dc
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 31 deletions.
27 changes: 27 additions & 0 deletions LICENSE-3RD-PARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/antfu>

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.
2 changes: 1 addition & 1 deletion coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
38 changes: 38 additions & 0 deletions src/startup-logo.ts
Original file line number Diff line number Diff line change
@@ -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<boolean>(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(
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/startup-logo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
19 changes: 18 additions & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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),
};
},
},
Expand Down
36 changes: 8 additions & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand All @@ -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==
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down

0 comments on commit 77280dc

Please sign in to comment.