Skip to content

Commit

Permalink
fix: disable broken app and add safeguards (#1859)
Browse files Browse the repository at this point in the history
* chore: disable snailfm app

* fix: prevent disabled apps from being processed
  • Loading branch information
erickzhao authored Aug 18, 2021
1 parent a339f1a commit ac664e2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 31 deletions.
1 change: 1 addition & 0 deletions apps/snailfm/snailfm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ keywords:
- music
- NCS
- simple
disabled: true # broken icon
21 changes: 13 additions & 8 deletions lib/raw-app-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ module.exports = function getSlugs() {
.isDirectory()
})
.sort()
.map((slug) => {
.reduce((slugs, slug) => {
const yamlFile = path.join(__dirname, `../apps/${slug}/${slug}.yml`)
const app = Object.assign(
{
const meta = yaml.load(fs.readFileSync(yamlFile))

if (meta.disabled) {
return slugs
} else {
const app = {
slug: slug,
iconPath: path.join(__dirname, `../apps/${slug}/${slug}-icon.png`),
},
yaml.load(fs.readFileSync(yamlFile))
)
return app
})
...meta
}
return [...slugs, app]
}

}, [])
}
8 changes: 7 additions & 1 deletion script/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ fs.readdirSync(path.join(__dirname, '../apps'))
})
.forEach((slug) => {
const yamlFile = path.join(__dirname, `../apps/${slug}/${slug}.yml`)
const meta = yaml.load(fs.readFileSync(yamlFile))

if (meta.disabled) {
return;
}

const app = Object.assign(
{ slug: slug },
yaml.load(fs.readFileSync(yamlFile)),
meta,
{
icon: `${slug}-icon.png`,
icon32: `${slug}-icon-32.png`,
Expand Down
62 changes: 40 additions & 22 deletions script/resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ const fs = require('fs')
const recursiveReadSync = require('recursive-readdir-sync')
const imagemin = require('imagemin')
const imageminPngquant = require('imagemin-pngquant')
const icons = recursiveReadSync(path.join(__dirname, '../apps')).filter(
(file) => file.match(/icon\.png/)
)
const yaml = require('js-yaml')

process.stdout.write(`Resizing ${icons.length} icons...`)

function resize(file, size) {
async function resize(file, size) {
const newFile = file.replace('.png', `-${size}.png`)

// skip files that are up to date
Expand All @@ -30,19 +26,41 @@ function resize(file, size) {
.then((buf) => fs.writeFileSync(newFile, buf))
}

const resizes = icons
.map((icon) => resize(icon, 32))
.concat(icons.map((icon) => resize(icon, 64)))
.concat(icons.map((icon) => resize(icon, 128)))
.concat(icons.map((icon) => resize(icon, 256)))

Promise.all(resizes)
.then(function (results) {
process.stdout.write(` Done.`)
process.exit()
})
.catch(function (err) {
console.error('Error resizing icons!')
console.error(err)
process.exit()
})
async function main() {
const icons = recursiveReadSync(path.join(__dirname, '../apps')).filter(
(file) => file.match(/icon\.png/)
)

console.log(`Resizing ${icons.length} icons...`)
const resizes = icons
.reduce((acc, icon) => {
const iconName = path.basename(icon)

// skip disabled app
const yamlFile = path.join(icon.replace('-icon.png', '.yml'))
const { disabled } = yaml.load(fs.readFileSync(yamlFile))
if (disabled) {
return acc
}

return {
...acc,
[iconName]: [resize(icon, 32), resize(icon, 64), resize(icon, 128), resize(icon, 256)]
}
}, {})

for (const icon in resizes) {
const promises = await Promise.allSettled(Object.values(resizes[icon]))
const failed = promises.filter(p => p.status === 'rejected')

if (failed.length > 0) {
console.error(`🔴 Failed to resize icons for icon "${icon}"!`)
for (const { reason } of failed) {
console.log(reason)
}
process.exit(1)
}
}
}

main();

0 comments on commit ac664e2

Please sign in to comment.