@cordfuse/nux-qr-tool 1.2.0 → 1.3.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 +2 -2
- package/dist/qr-generator.js +17 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,12 +41,12 @@ npm install @cordfuse/nux-qr-tool
|
|
|
41
41
|
## CLI Usage
|
|
42
42
|
|
|
43
43
|
```bash
|
|
44
|
-
npx @cordfuse/nux-qr-tool <preset-json-file> [--output <dir>]
|
|
44
|
+
npx @cordfuse/nux-qr-tool <preset-json-file> [--output <dir>] [--app-name <name>] [--app-version <ver>]
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
Reads the preset JSON, encodes the NUX QR payload, generates a decorated PNG, writes it to `<dir>/<artist>-<song>.png`, and prints the full output path to stdout.
|
|
48
48
|
|
|
49
|
-
The output directory defaults to the current working directory. Use `--output` (or `-o`) to write elsewhere.
|
|
49
|
+
The output directory defaults to the current working directory. Use `--output` (or `-o`) to write elsewhere. Use `--app-name` and `--app-version` to override the branding shown in the card header (defaults to `ToneAI` and the package version).
|
|
50
50
|
|
|
51
51
|
### Example
|
|
52
52
|
|
package/dist/qr-generator.js
CHANGED
|
@@ -6107,13 +6107,25 @@ async function decorateQR(qrPng, artist, song, deviceId, deviceName, options) {
|
|
|
6107
6107
|
ctx.fillText(line2, cx, footerTop + FOOTER_H * 0.7, TOTAL_W - PADDING * 2);
|
|
6108
6108
|
return canvas.toBuffer("image/png");
|
|
6109
6109
|
}
|
|
6110
|
+
function parseFlag(args, ...flags) {
|
|
6111
|
+
const idx = args.findIndex((a) => flags.includes(a));
|
|
6112
|
+
return idx !== -1 ? args[idx + 1] : undefined;
|
|
6113
|
+
}
|
|
6110
6114
|
async function main() {
|
|
6111
6115
|
const args = process.argv.slice(2);
|
|
6112
|
-
const
|
|
6113
|
-
const
|
|
6114
|
-
|
|
6116
|
+
const flagNames = ["--output", "-o", "--app-name", "--app-version"];
|
|
6117
|
+
const flagValueIdxs = new Set;
|
|
6118
|
+
flagNames.forEach((f) => {
|
|
6119
|
+
const i = args.indexOf(f);
|
|
6120
|
+
if (i !== -1)
|
|
6121
|
+
flagValueIdxs.add(i + 1);
|
|
6122
|
+
});
|
|
6123
|
+
const outDir = resolve(parseFlag(args, "--output", "-o") ?? process.cwd());
|
|
6124
|
+
const appName = parseFlag(args, "--app-name");
|
|
6125
|
+
const appVersion = parseFlag(args, "--app-version");
|
|
6126
|
+
const jsonPath = args.find((a, i) => !a.startsWith("-") && !flagValueIdxs.has(i));
|
|
6115
6127
|
if (!jsonPath) {
|
|
6116
|
-
console.error("Usage: npx @cordfuse/nux-qr-tool <params-json-file> [--output <dir>]");
|
|
6128
|
+
console.error("Usage: npx @cordfuse/nux-qr-tool <params-json-file> [--output <dir>] [--app-name <name>] [--app-version <ver>]");
|
|
6117
6129
|
process.exit(1);
|
|
6118
6130
|
}
|
|
6119
6131
|
const raw = JSON.parse(readFileSync(resolve(jsonPath), "utf8"));
|
|
@@ -6130,7 +6142,7 @@ async function main() {
|
|
|
6130
6142
|
margin: 4,
|
|
6131
6143
|
color: { dark: "#000000", light: "#ffffff" }
|
|
6132
6144
|
});
|
|
6133
|
-
const decorated = await decorateQR(qrPng, params.artist, params.song, params.device, device.displayName);
|
|
6145
|
+
const decorated = await decorateQR(qrPng, params.artist, params.song, params.device, device.displayName, { ...appName ? { appName } : {}, ...appVersion ? { appVersion } : {} });
|
|
6134
6146
|
const slug = `${params.artist}-${params.song}`.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 60);
|
|
6135
6147
|
mkdirSync(outDir, { recursive: true });
|
|
6136
6148
|
const outPath = join(outDir, `${slug}.png`);
|