Skip to content

Commit 74cc864

Browse files
committed
only log if icons changed
1 parent 3e02fbd commit 74cc864

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

other/build-icons.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ async function generateIconFiles() {
3636

3737
const iconNames = files.map(file => iconName(file))
3838

39-
const spriteUpToDate = iconNames.every(name => currentSprite.includes(`id=${name}`))
40-
const typesUpToDate = iconNames.every(name => currentTypes.includes(`"${name}"`))
39+
const spriteUpToDate = iconNames.every(name =>
40+
currentSprite.includes(`id=${name}`),
41+
)
42+
const typesUpToDate = iconNames.every(name =>
43+
currentTypes.includes(`"${name}"`),
44+
)
4145

4246
if (spriteUpToDate && typesUpToDate) {
4347
console.log(`Icons are up to date`)
@@ -48,7 +52,7 @@ async function generateIconFiles() {
4852

4953
await fsExtra.emptyDir(outputDir)
5054

51-
await generateSvgSprite({
55+
const changedSprite = await generateSvgSprite({
5256
files,
5357
inputDir,
5458
outputPath: spriteFilepath,
@@ -66,11 +70,14 @@ async function generateIconFiles() {
6670
export type IconName =
6771
\t| ${stringifiedIconNames.join('\n\t| ')};
6872
`
69-
await writeIfChanged(typeOutputFilepath, typeOutputContent)
73+
const changedTypes = await writeIfChanged(
74+
typeOutputFilepath,
75+
typeOutputContent,
76+
)
7077

7178
logVerbose(`Manifest saved to ${path.relative(cwd, typeOutputFilepath)}`)
7279

73-
await writeIfChanged(
80+
const changedIconReadme = await writeIfChanged(
7481
path.join(outputDir, 'README.md'),
7582
`# Icons
7683
@@ -79,7 +86,9 @@ This directory contains SVG icons that are used by the app.
7986
Everything in this directory is generated by \`npm run build:icons\`.
8087
`,
8188
)
82-
console.log(`Generated ${files.length} icons`)
89+
if (changedIconReadme || changedSprite || changedTypes) {
90+
console.log(`Generated ${files.length} icons`)
91+
}
8392
}
8493

8594
function iconName(file: string) {
@@ -137,6 +146,6 @@ async function writeIfChanged(filepath: string, newContent: string) {
137146
const currentContent = await fsExtra
138147
.readFile(filepath, 'utf8')
139148
.catch(() => '')
140-
if (currentContent === newContent) return
149+
if (currentContent === newContent) return false
141150
await fsExtra.writeFile(filepath, newContent, 'utf8')
142151
}

0 commit comments

Comments
 (0)