{"size": 822, "ext": "js", "max_stars_repo_path": "packages/cli/neft-cli/src/builder/icon.js", "max_stars_repo_name": "Neft-io/neftio", "max_stars_repo_stars_event_min_datetime": "2016-02-24T16:26:58.000Z", "max_stars_repo_stars_event_max_datetime": "2019-02-27T09:05:09.000Z", "max_issues_repo_path": "packages/cli/neft-cli/src/builder/icon.js", "max_issues_repo_name": "Neft-io/neft-cli", "max_issues_repo_issues_event_min_datetime": "2016-02-18T18:23:38.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-01T16:28:33.000Z", "max_forks_repo_path": "packages/cli/neft-cli/src/builder/icon.js", "max_forks_repo_name": "neftjs/neft", "max_forks_repo_forks_event_min_datetime": "2016-03-31T10:17:47.000Z", "max_forks_repo_forks_event_max_datetime": "2016-03-31T10:17:47.000Z"}
{"max_stars_count": 23, "max_issues_count": 255, "max_forks_count": 1, "avg_line_length": 30.4444444444, "max_line_length": 76, "alphanum_fraction": 0.700729927}
const fs = require('fs-extra')
const path = require('path')
const sharp = require('sharp')
const { realpath, outputDir } = require('../config')

const resizeImage = (filepath, width, height, output) => sharp(filepath)
  .resize(width, height)
  .toFile(output)

exports.generateIcons = async ({ target, icons, manifest }) => {
  if (!manifest.icon) return
  const icon = path.join(realpath, '/manifest', manifest.icon)
  const output = path.join(outputDir, '/icon/', target)

  // create output
  await fs.ensureDir(output)

  // create icon files
  const promises = icons.map(async (definition) => {
    const fileOutput = path.join(output, definition.out)
    await fs.ensureDir(path.dirname(fileOutput))
    await resizeImage(icon, definition.width, definition.height, fileOutput)
  })

  await Promise.all(promises)
}
