Merged in fix/STAY-135 (pull request #3368)
Fix/STAY-135 & STAY-127 * fix: make quantity and delivery separate steps in mobile * fix: update design for delivery step in ancillary flow * fix: add error state for missing time * fix: only allow points or cash payment for ancillaries * fix: break out stepper to design system * fix: update design of select quantity step in add ancillaries flow * fix: add error states for quantity * fix: handle insufficient points case * fix: update stepper to include optional disabledMessage tooltip * fix: handle validations * fix: change name to camel case Approved-by: Bianca Widstam Approved-by: Chuma Mcphoy (We Ahead)
This commit is contained in:
@@ -1,26 +1,27 @@
|
||||
import crypto from "node:crypto";
|
||||
import { createWriteStream } from "node:fs";
|
||||
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { Readable } from "node:stream";
|
||||
import { pipeline } from "node:stream/promises";
|
||||
import crypto from "node:crypto"
|
||||
import { createWriteStream } from "node:fs"
|
||||
import { mkdir, readFile, rm, writeFile } from "node:fs/promises"
|
||||
import { join, resolve } from "node:path"
|
||||
import { Readable } from "node:stream"
|
||||
import { pipeline } from "node:stream/promises"
|
||||
|
||||
import stringify from "json-stable-stringify-without-jsonify";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import stringify from "json-stable-stringify-without-jsonify"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = resolve(__filename, "..");
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = resolve(__filename, "..")
|
||||
|
||||
// Defines where the font lives
|
||||
const FONT_DIR = resolve(__dirname, "../shared/fonts/material-symbols");
|
||||
const FONT_DIR = resolve(__dirname, "../shared/fonts/material-symbols")
|
||||
|
||||
// Defines the settings for the font
|
||||
const FONT_BASE_URL = `https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@24,400,0..1,0`;
|
||||
const FONT_BASE_URL = `https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@24,400,0..1,0`
|
||||
|
||||
// Defines the subset of icons for the font
|
||||
const icons = [
|
||||
"accessibility",
|
||||
"accessible",
|
||||
"acute",
|
||||
"add_circle",
|
||||
"add",
|
||||
"air_purifier_gen",
|
||||
@@ -231,16 +232,16 @@ const icons = [
|
||||
"water_full",
|
||||
"wifi",
|
||||
"yard",
|
||||
].sort();
|
||||
].sort()
|
||||
|
||||
function createHash(value: unknown) {
|
||||
const stringified = stringify(value);
|
||||
const hash = crypto.createHash("sha256");
|
||||
hash.update(stringified);
|
||||
return hash.digest("hex");
|
||||
const stringified = stringify(value)
|
||||
const hash = crypto.createHash("sha256")
|
||||
hash.update(stringified)
|
||||
return hash.digest("hex")
|
||||
}
|
||||
|
||||
const hash = createHash(icons).substring(0, 8);
|
||||
const hash = createHash(icons).substring(0, 8)
|
||||
|
||||
async function fetchIconUrl(url: string) {
|
||||
const response = await fetch(url, {
|
||||
@@ -250,105 +251,105 @@ async function fetchIconUrl(url: string) {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
console.error(`Unable to fetch woff2 for ${url}`);
|
||||
process.exit(1);
|
||||
console.error(`Unable to fetch woff2 for ${url}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const text = await response.text();
|
||||
const text = await response.text()
|
||||
|
||||
const isWoff2 = /format\('woff2'\)/.test(text);
|
||||
const isWoff2 = /format\('woff2'\)/.test(text)
|
||||
if (!isWoff2) {
|
||||
console.error(`Unable to identify woff2 font in response`);
|
||||
process.exit(1);
|
||||
console.error(`Unable to identify woff2 font in response`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const srcUrl = text.match(/src: url\(([^)]+)\)/);
|
||||
const srcUrl = text.match(/src: url\(([^)]+)\)/)
|
||||
|
||||
if (srcUrl && srcUrl[1]) {
|
||||
return srcUrl[1];
|
||||
return srcUrl[1]
|
||||
}
|
||||
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
|
||||
async function download(url: string, destFolder: string) {
|
||||
const dest = resolve(join(destFolder, `/rounded-${hash}.woff2`));
|
||||
const dest = resolve(join(destFolder, `/rounded-${hash}.woff2`))
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
const response = await fetch(url)
|
||||
|
||||
if (!response.ok) {
|
||||
console.error(`Unable to fetch ${url}`);
|
||||
process.exit(1);
|
||||
console.error(`Unable to fetch ${url}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (!response.body) {
|
||||
console.error(`Bad response from ${url}`);
|
||||
process.exit(1);
|
||||
console.error(`Bad response from ${url}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const fileStream = createWriteStream(dest);
|
||||
const fileStream = createWriteStream(dest)
|
||||
|
||||
// @ts-expect-error: type mismatch
|
||||
const readableNodeStream = Readable.fromWeb(response.body);
|
||||
const readableNodeStream = Readable.fromWeb(response.body)
|
||||
|
||||
await pipeline(readableNodeStream, fileStream);
|
||||
await pipeline(readableNodeStream, fileStream)
|
||||
} catch (error) {
|
||||
console.error(`Error downloading file from ${url}:`, error);
|
||||
process.exit(1);
|
||||
console.error(`Error downloading file from ${url}:`, error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
async function cleanFontDirs() {
|
||||
await rm(FONT_DIR, { recursive: true, force: true });
|
||||
await mkdir(FONT_DIR, { recursive: true });
|
||||
await rm(FONT_DIR, { recursive: true, force: true })
|
||||
await mkdir(FONT_DIR, { recursive: true })
|
||||
await writeFile(
|
||||
join(FONT_DIR, ".auto-generated"),
|
||||
`Auto-generated, do not edit. Use scripts/material-symbols-update.mts to update.\nhash=${hash}\ncreated=${new Date().toISOString()}\n`,
|
||||
{ encoding: "utf-8" },
|
||||
);
|
||||
{ encoding: "utf-8" }
|
||||
)
|
||||
}
|
||||
|
||||
async function updateFontCSS() {
|
||||
const file = resolve(__dirname, "../packages/design-system/lib/fonts.css");
|
||||
const file = resolve(__dirname, "../packages/design-system/lib/fonts.css")
|
||||
|
||||
const css = await readFile(file, {
|
||||
encoding: "utf-8",
|
||||
});
|
||||
})
|
||||
|
||||
await writeFile(
|
||||
file,
|
||||
css.replace(
|
||||
/url\(\/_static\/shared\/fonts\/material-symbols\/rounded[^)]+\)/,
|
||||
`url(/_static/shared/fonts/material-symbols/rounded-${hash}.woff2)`,
|
||||
`url(/_static/shared/fonts/material-symbols/rounded-${hash}.woff2)`
|
||||
),
|
||||
{
|
||||
encoding: "utf-8",
|
||||
},
|
||||
);
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const fontUrl = `${FONT_BASE_URL}&icon_names=${icons.join(",")}&display=block`;
|
||||
const fontUrl = `${FONT_BASE_URL}&icon_names=${icons.join(",")}&display=block`
|
||||
|
||||
const iconUrl = await fetchIconUrl(fontUrl);
|
||||
const iconUrl = await fetchIconUrl(fontUrl)
|
||||
|
||||
if (iconUrl) {
|
||||
await cleanFontDirs();
|
||||
await cleanFontDirs()
|
||||
|
||||
await download(iconUrl, FONT_DIR);
|
||||
await download(iconUrl, FONT_DIR)
|
||||
|
||||
await updateFontCSS();
|
||||
await updateFontCSS()
|
||||
|
||||
console.log("Successfully updated icons!");
|
||||
process.exit(0);
|
||||
console.log("Successfully updated icons!")
|
||||
process.exit(0)
|
||||
} else {
|
||||
console.error(
|
||||
`Unable to find the icon font src URL in CSS response from Google Fonts at ${fontUrl}`,
|
||||
);
|
||||
`Unable to find the icon font src URL in CSS response from Google Fonts at ${fontUrl}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user