Skip to content

Commit fec3287

Browse files
committed
build(ui-icons): remove fs-extra dep
1 parent 5b1abb3 commit fec3287

File tree

5 files changed

+38
-69
lines changed

5 files changed

+38
-69
lines changed

package-lock.json

Lines changed: 0 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/calcite-ui-icons/bin/build.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
const fs = require("fs-extra");
1+
const { existsSync, mkdirSync } = require("fs");
22
const optimize = require("./optimize");
33
const generatePathFile = require("./path-data");
44

55
module.exports = function () {
6-
fs.ensureDirSync("js");
6+
if (!existsSync("js")) {
7+
mkdirSync("js");
8+
}
79

810
return optimize("*.svg")
911
.then(() => optimize("icons/*.svg", true))

packages/calcite-ui-icons/bin/optimize.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fs = require("fs-extra");
1+
const { readFile, writeFile } = require("fs/promises");
22
const { glob } = require("glob");
33
const SVGO = require("svgo");
44
const progress = require("cli-progress");
@@ -32,18 +32,17 @@ let options = {
3232
* @return {Promise}
3333
*/
3434
function optimizeIcons(filePaths, svgo, bar) {
35-
var num = 0;
35+
let num = 0;
3636
return Promise.all(
37-
filePaths.map((path) => {
38-
return fs
39-
.readFile(path, "utf-8")
37+
filePaths.map((path) =>
38+
readFile(path, "utf-8")
4039
.then((svg) => svgo.optimize(svg, { path }))
4140
.then((result) => {
4241
num++;
4342
bar.update(num);
44-
return fs.writeFile(path, result.data, "utf-8");
45-
});
46-
}),
43+
return writeFile(path, result.data, "utf-8");
44+
}),
45+
),
4746
);
4847
}
4948

@@ -58,10 +57,13 @@ module.exports = function (files, remove) {
5857
return Promise.resolve(true);
5958
}
6059
options.plugins[0] = { cleanupIDs: { remove } };
61-
svgo = new SVGO(options);
60+
let svgo = new SVGO(options);
6261
return glob(files).then((iconPaths) => {
6362
const format = " \x1b[32m {bar} {percentage}% | {value}/{total} \x1b[0m";
64-
const bar = new progress.SingleBar({ format }, progress.Presets.shades_classic);
63+
const bar = new progress.SingleBar(
64+
{ format },
65+
progress.Presets.shades_classic,
66+
);
6567
bar.start(iconPaths.length, 0);
6668
return optimizeIcons(iconPaths, svgo, bar).then(() => {
6769
bar.stop();

packages/calcite-ui-icons/bin/path-data.js

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const camelCase = require("camelcase");
2-
const fs = require("fs-extra");
2+
const {
3+
promises: { writeFile, readFile },
4+
readFileSync,
5+
} = require("fs");
36
const { glob } = require("glob");
47
const { parse } = require("svgson");
58
const path = require("path");
@@ -30,10 +33,11 @@ function formatSVG(svg) {
3033
function getPaths(svg) {
3134
const bbPaths = ["M0 0h16v16H0z", "M0 0h24v24H0z", "M0 0h32v32H0z"];
3235
return svg.children
33-
.filter(
34-
(child) => child.name === "path" && bbPaths.indexOf(child.attributes.d) === -1,
35-
) // filter out bounding box paths
36-
.map((child) => ({ opacity: child.attributes.opacity, d: child.attributes.d }));
36+
.filter((child) => child.name === "path" && bbPaths.indexOf(child.attributes.d) === -1) // filter out bounding box paths
37+
.map((child) => ({
38+
opacity: child.attributes.opacity,
39+
d: child.attributes.d,
40+
}));
3741
}
3842

3943
/**
@@ -64,17 +68,12 @@ function getSize(name) {
6468
*/
6569
function readSVG(fileName) {
6670
return new Promise((resolve, reject) =>
67-
fs
68-
.readFile(fileName, "utf-8")
69-
.then((svg) =>
70-
parse(svg).then((contents) => resolve({ file: fileName, contents })),
71-
),
71+
readFile(fileName, "utf-8").then((svg) => parse(svg).then((contents) => resolve({ file: fileName, contents }))),
7272
);
7373
}
7474

7575
module.exports = function generatePathFile() {
76-
let banner =
77-
"// File generated automatically by path-data.js, do not edit directly\n";
76+
let banner = "// File generated automatically by path-data.js, do not edit directly\n";
7877
let jsFile = `${banner}`;
7978
let tsFile = `
8079
${banner}
@@ -89,11 +88,10 @@ export type CalciteIconPath = string | CalciteMultiPathEntry[];
8988
.then((files) => files.map(formatSVG))
9089
.then((files) => {
9190
let icons = {};
92-
let keywords = JSON.parse(fs.readFileSync("docs/keywords.json", "utf-8"));
91+
let keywords = JSON.parse(readFileSync("docs/keywords.json", "utf-8"));
9392
files.forEach((file) => {
9493
// add to json file
95-
icons[file.variant] = icons[file.variant] ||
96-
keywords[file.variant] || { alias: [], category: "", release: "" };
94+
icons[file.variant] = icons[file.variant] || keywords[file.variant] || { alias: [], category: "", release: "" };
9795
var icon = icons[file.variant];
9896
const firstPath = file.paths[0] || { d: "" }; // back up for "blank" icon
9997
const paths = file.paths.length > 1 ? file.paths : firstPath.d;
@@ -109,12 +107,8 @@ export type CalciteIconPath = string | CalciteMultiPathEntry[];
109107
}
110108
}
111109
// add to ts and js files
112-
const variant = file.variant.match(/^\d/)
113-
? `i${file.variant}`
114-
: file.variant;
115-
const camelCaseName = camelCase(
116-
`${file.filled ? base : variant}-${file.size}${file.filled ? "-f" : ""}`,
117-
);
110+
const variant = file.variant.match(/^\d/) ? `i${file.variant}` : file.variant;
111+
const camelCaseName = camelCase(`${file.filled ? base : variant}-${file.size}${file.filled ? "-f" : ""}`);
118112
jsFile += `export {${camelCaseName}} from "./js/${camelCaseName}.js";\n`;
119113

120114
let contents, tsContents;
@@ -129,18 +123,14 @@ export type CalciteIconPath = string | CalciteMultiPathEntry[];
129123
tsContents = `export const ${camelCaseName}: CalciteMultiPathEntry[];\n`;
130124
}
131125

132-
fs.writeFile(`js/${camelCaseName}.js`, contents, "utf8");
133-
fs.writeFile(`js/${camelCaseName}.d.ts`, tsContents, "utf8");
134-
fs.writeFile(`js/${camelCaseName}.json`, JSON.stringify(paths), "utf8");
126+
writeFile(`js/${camelCaseName}.js`, contents, "utf8");
127+
writeFile(`js/${camelCaseName}.d.ts`, tsContents, "utf8");
128+
writeFile(`js/${camelCaseName}.json`, JSON.stringify(paths), "utf8");
135129
});
136130
let promises = [
137-
fs.writeFile(
138-
"docs/icons.json",
139-
JSON.stringify({ version, icons }),
140-
"utf8",
141-
),
142-
fs.writeFile("index.d.ts", tsFile, "utf8"),
143-
fs.writeFile("index.js", jsFile, "utf8"),
131+
writeFile("docs/icons.json", JSON.stringify({ version, icons }), "utf8"),
132+
writeFile("index.d.ts", tsFile, "utf8"),
133+
writeFile("index.js", jsFile, "utf8"),
144134
];
145135
return Promise.all(promises);
146136
});

packages/calcite-ui-icons/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"convert-all-desktop:size": "node bin/convert-mobile.js -o \"../desktop-output\" -i \"16\" -s",
4848
"convert-all-ios": "node bin/convert-mobile.js -o \"../mobile-output\" -p \"ios\" -i \"24\"",
4949
"convert-all-ios:size": "node bin/convert-mobile.js -o \"../mobile-output\" -p \"ios\" -s",
50-
"copy-assets": "cpy \"../../node_modules/calcite-web/dist/js/calcite-web.min.js\" \"../../node_modules/calcite-web/dist/css/calcite-web.min.css\" \"./docs/resources\" --flat",
50+
"copy-assets": "cpy \"./node_modules/calcite-web/dist/js/calcite-web.min.js\" \"./node_modules/calcite-web/dist/css/calcite-web.min.css\" \"./docs/resources\" --flat",
5151
"optimize": "node bin/cli.js",
5252
"spriter": "node bin/spriter.js",
5353
"start": "npm run copy-assets && node bin/server.js"
@@ -58,7 +58,6 @@
5858
"camelcase": "6.3.0",
5959
"cli-progress": "^3.12.0",
6060
"debounce": "^2.1.0",
61-
"fs-extra": "7.0.1",
6261
"glob": "^11.0.0",
6362
"svg2img": "1.0.0-beta.2",
6463
"svgo": "^1.3.0",

0 commit comments

Comments
 (0)