Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v4] [icons] fix: reduce file size of generated paths files #4998

Merged
merged 1 commit into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/icons/scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
const fs = require("fs");
const path = require("path");

const COPYRIGHT_HEADER = "/*\n * Copyright 2021 Palantir Technologies, Inc. All rights reserved.\n */\n";
const RESOURCES_DIR = path.resolve(__dirname, "../../../resources/icons");
const GENERATED_SRC_DIR = path.resolve(__dirname, "../src/generated");
const NS = "bp4";
Expand All @@ -29,12 +28,11 @@ const NS = "bp4";
*/
function writeLinesToFile(filename, ...lines) {
const outputPath = path.join(GENERATED_SRC_DIR, filename);
const contents = [COPYRIGHT_HEADER, ...lines, ""].join("\n");
const contents = [...lines, ""].join("\n");
fs.writeFileSync(outputPath, contents);
}

module.exports = {
COPYRIGHT_HEADER,
RESOURCES_DIR,
GENERATED_SRC_DIR,
NS,
Expand Down
8 changes: 6 additions & 2 deletions packages/icons/scripts/generate-icon-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ const ICON_NAMES = ICONS_METADATA.map(icon => icon.iconName);
const iconPaths = await getIconPaths(iconSize);

for (const [iconName, pathStrings] of Object.entries(iconPaths)) {
const line = pathStrings.length > 0
? `export default [${pathStrings.join(", ")}];`
// special case for "blank" icon - we need an explicit typedef
: `const p: string[] = []; export default p;`

writeLinesToFile(
`${iconSize}px/paths/${iconName}.ts`,
`const paths: string[] = [${pathStrings.join(", ")}];`,
"export default paths;",
line,
);
}

Expand Down