-
Notifications
You must be signed in to change notification settings - Fork 38
/
build.js
83 lines (73 loc) · 2.57 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/******************************************************************************
*
* Copyright (c) 2020, the Regular Table Authors.
*
* This file is part of the Regular Table library, distributed under the terms
* of the Apache License 2.0. The full license can be found in the LICENSE
* file.
*
*/
const esbuild = require("esbuild");
const { BuildCss } = require("@prospective.co/procss/target/cjs/procss.js");
const fs = require("fs");
const path_mod = require("path");
const BUILD = [
{
entryPoints: ["src/js/index.js"],
format: "esm",
loader: {
".css": "text",
".html": "text",
},
outfile: "dist/esm/regular-table.js",
target: ["es2021"],
bundle: true,
minify: !process.env.PSP_DEBUG,
minify: true,
sourcemap: true,
metafile: true,
entryNames: "[name]",
chunkNames: "[name]",
assetNames: "[name]",
},
];
// FINOS requires `semgrep`, and will no doubt also soon require glue eating.
function add(builder, path) {
// nosemgrep
builder.add(path, fs.readFileSync(path_mod.join("./src/less", path)).toString());
}
async function compile_css() {
fs.mkdirSync("dist/css", { recursive: true });
const builder1 = new BuildCss("");
add(builder1, "./container.less");
fs.writeFileSync("dist/css/container.css", builder1.compile().get("container.css"));
const builder2 = new BuildCss("");
add(builder2, "./sub-cell-offsets.less");
fs.writeFileSync("dist/css/sub-cell-offsets.css", builder2.compile().get("sub-cell-offsets.css"));
const builder3 = new BuildCss("");
add(builder3, "./sub-cell-scrolling.less");
add(builder3, "./material.less");
fs.writeFileSync("dist/css/material.css", builder3.compile().get("material.css"));
fs.writeFileSync("dist/css/sub-cell-scrolling.css", builder3.compile().get("sub-cell-scrolling.css"));
}
async function build_all() {
await compile_css();
await Promise.all(
BUILD.map(async (x) => {
console.log("");
const result = await esbuild.build(x);
for (const { inputs, bytes } of Object.values(result.metafile.outputs)) {
for (const input of Object.keys(inputs)) {
if (inputs[input].bytesInOutput / bytes < 0.05) {
delete inputs[input];
}
}
}
const text = await esbuild.analyzeMetafile(result.metafile, {
color: true,
});
console.log(text);
})
);
}
build_all();