Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

1.1 KB
Raw Blame
#!/usr/bin/env node

import {writeFile} from "node:fs/promises";
import path from "node:path";
import {fileURLToPath} from "node:url";

import {getUserAgentRegex} from "browserslist-useragent-regexp";

const root_dir = fileURLToPath(new URL("../..", import.meta.url));
const output_path = path.join(root_dir, "web", "generated", "supported_browser_regex.ts");
// Since browserlistrc is not in the root, it will not be autodetected.
const browserslist_config = path.join(root_dir, "web", ".browserslistrc");

async function main(): Promise<void> {
    const baselineRegex = getUserAgentRegex({
        config: browserslist_config,
        allowHigherVersions: true,
    });
    const allBrowsersRegex = getUserAgentRegex({
        browsers: ">= 0%",
        allowHigherVersions: true,
    });
    const contents =
        `// This file is generated by tools/setup/build_supported_browser_regex.ts\n` +
        `// Do not edit this file directly.\n` +
        `export const baselineBrowserRegex = ${baselineRegex.toString()};\n` +
        `export const allBrowsersRegex = ${allBrowsersRegex.toString()};\n`;

    await writeFile(output_path, contents);
}

await main();