{"size": 2750, "ext": "js", "max_stars_repo_path": "packages/perspective-workspace/build.js", "max_stars_repo_name": "jpmorganchase/perspective", "max_stars_repo_stars_event_min_datetime": "2017-12-08T22:38:48.000Z", "max_stars_repo_stars_event_max_datetime": "2019-04-29T19:29:31.000Z", "max_issues_repo_path": "packages/perspective-workspace/build.js", "max_issues_repo_name": "jpmorganchase/perspective", "max_issues_repo_issues_event_min_datetime": "2018-01-19T22:27:09.000Z", "max_issues_repo_issues_event_max_datetime": "2019-04-27T00:16:00.000Z", "max_forks_repo_path": "packages/perspective-workspace/build.js", "max_forks_repo_name": "jpmorganchase/perspective", "max_forks_repo_forks_event_min_datetime": "2017-12-08T20:57:50.000Z", "max_forks_repo_forks_event_max_datetime": "2019-04-23T07:57:05.000Z"}
{"max_stars_count": 1821, "max_issues_count": 278, "max_forks_count": 125, "avg_line_length": 29.5698924731, "max_line_length": 79, "alphanum_fraction": 0.5389090909}
const {lessLoader} = require("esbuild-plugin-less");
const {execSync} = require("child_process");

const {InlineCSSPlugin} = require("@finos/perspective-build/inline_css");
const {NodeModulesExternal} = require("@finos/perspective-build/external");
const {IgnoreCSSPlugin} = require("@finos/perspective-build/ignore_css");
const {IgnoreFontsPlugin} = require("@finos/perspective-build/ignore_fonts");
const {WasmPlugin} = require("@finos/perspective-build/wasm");
const {WorkerPlugin} = require("@finos/perspective-build/worker");
const {ResolvePlugin} = require("@finos/perspective-build/resolve");
const {build} = require("@finos/perspective-build/build");

const BUILD = [
    {
        entryPoints: [
            "src/themes/material.less",
            "src/themes/material-dark.less",
        ],
        plugins: [lessLoader()],
        outdir: "dist/css",
    },
    {
        entryPoints: ["src/js/perspective-workspace.js"],
        define: {
            global: "window",
        },
        format: "esm",
        plugins: [
            InlineCSSPlugin(),
            IgnoreCSSPlugin(),
            IgnoreFontsPlugin(),

            // Inlining `lumino` and importing the `.ts` source saves _50kb_
            NodeModulesExternal("@lumino"),
        ],
        loader: {
            ".html": "text",
        },
        external: ["*.wasm"],
        outfile: "dist/esm/perspective-workspace.js",
    },
    {
        entryPoints: ["src/js/perspective-workspace.js"],
        define: {
            global: "window",
        },
        plugins: [
            InlineCSSPlugin(),
            IgnoreCSSPlugin(),
            IgnoreFontsPlugin(),
            WasmPlugin(true),
            WorkerPlugin(true),
        ],
        format: "iife",
        loader: {
            ".html": "text",
        },
        outfile: "dist/umd/perspective-workspace.js",
    },
    {
        entryPoints: ["src/js/perspective-workspace.js"],
        define: {
            global: "window",
        },
        plugins: [
            ResolvePlugin({
                "@finos/perspective":
                    "@finos/perspective/dist/esm/perspective.js",
                "@finos/perspective-viewer":
                    "@finos/perspective-viewer/dist/esm/perspective-viewer.js",
            }),
            InlineCSSPlugin(),
            IgnoreCSSPlugin(),
            IgnoreFontsPlugin(),
            WasmPlugin(false),
            WorkerPlugin(false),
        ],
        format: "esm",
        splitting: true,
        loader: {
            ".html": "text",
        },
        outdir: "dist/cdn",
    },
];

async function build_all() {
    await Promise.all(BUILD.map(build)).catch(() => process.exit(1));
    execSync("cpy dist/css/* dist/umd");
}

build_all();
