Skip to content

Commit 990aad9

Browse files
committed
qr code to svg
1 parent 5536553 commit 990aad9

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

bun.lockb

6.89 KB
Binary file not shown.

bundle.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ export async function bundle() {
33
entrypoints: ["./src/index.ts"],
44
outdir: "./out",
55
target: "browser",
6+
define: {
7+
// Lord forgive me
8+
TextEncoder: "import_text_encoder.TextEncoder",
9+
},
610
});
711
if (!res.success) {
812
console.dir(res);

deploy.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ type Params = {
88
clasp_json_path: string;
99
clasp_cmd: string;
1010
description: string;
11+
deploy: boolean;
1112
};
1213

1314
function clasp(p: Params) {
1415
// Uses raw to avoid escaping
15-
return { raw: `${p.clasp_cmd} -P ${p.clasp_json_path}`};
16+
return { raw: `${p.clasp_cmd} -P ${p.clasp_json_path}` };
1617
}
1718

1819
async function createVersion(p: Params) {
@@ -61,17 +62,22 @@ function log(message: unknown) {
6162
description: {
6263
type: "string",
6364
},
65+
"deploy-version": {
66+
type: "boolean",
67+
},
6468
},
6569
strict: true,
6670
allowPositionals: true,
6771
});
6872
const clasp_json_path = values["project-path"] ?? ".clasp.json";
6973
const clasp_cmd = values["clasp-cmd"] ?? "./node_modules/.bin/clasp";
7074
const description = values.description ?? "auto-deployed";
75+
const deploy = values["deploy-version"] ?? false;
7176
const params: Params = {
7277
clasp_json_path,
7378
clasp_cmd,
7479
description,
80+
deploy,
7581
};
7682
log(params);
7783

@@ -81,9 +87,12 @@ function log(message: unknown) {
8187
log("pushing changes...");
8288
await pushCode(params);
8389
log("pushed changes");
84-
const version = await createVersion(params);
85-
log(`created version "${version}"`);
86-
log(`deploying version "${version}"...`);
87-
await deployVersion(params, version, description);
88-
log(`deployed version "${version}"`);
90+
91+
if (deploy) {
92+
const version = await createVersion(params);
93+
log(`created version "${version}"`);
94+
log(`deploying version "${version}"...`);
95+
await deployVersion(params, version, description);
96+
log(`deployed version "${version}"`);
97+
}
8998
})();

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"format": "biome format --write",
1010
"lint": "biome lint --write",
1111
"lint:unsafe": "biome lint --write --unsafe",
12-
1312
"create": "clasp create",
1413
"login": "clasp login",
1514
"help": "clasp create --help",
@@ -33,6 +32,8 @@
3332
"typescript": "^5.0.0"
3433
},
3534
"dependencies": {
36-
"lodash": "^4.17.21"
35+
"lodash": "^4.17.21",
36+
"qrcode": "^1.5.4",
37+
"text-encoder": "^0.0.4"
3738
}
3839
}

src/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import "text-encoder";
2+
import QRCode from "qrcode";
3+
14
type Range = GoogleAppsScript.Spreadsheet.Range;
25

36
/**
@@ -78,3 +81,8 @@ export function setLink(range: Range, url: string, label?: string) {
7881
.build();
7982
range.setRichTextValue(richValue);
8083
}
84+
85+
export async function qrCodeSvg(text: string) {
86+
return await QRCode.toString(text, { type: "svg" });
87+
}
88+

0 commit comments

Comments
 (0)