preview-stroke.mjs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import fs from 'fs'
  2. import { createScreenshot } from './helpers.mjs'
  3. import { ICONS_SRC_DIR } from './helpers.mjs'
  4. import path from 'path'
  5. const icon = 'ghost',
  6. strokes = ['.25', '.5', '.75', '1', '1.25', '1.5', '1.75', '2', '2.25', '2.5', '2.25'],
  7. svgFileContent = fs.readFileSync(path.join(ICONS_SRC_DIR, `outline/${icon}.svg`), 'utf-8'),
  8. padding = 16,
  9. paddingOuter = 3,
  10. iconSize = 56,
  11. width = 830,
  12. height = iconSize + paddingOuter * 2
  13. let svgContentSymbols = '',
  14. svgContentIcons = '',
  15. x = paddingOuter
  16. strokes.forEach(function (stroke) {
  17. let svgFileContentStroked = createSvgSymbol(svgFileContent, `icon-${stroke}`, stroke)
  18. svgFileContent
  19. .replace('<svg', `<symbol id="icon-${stroke}"`)
  20. .replace(' width="24" height="24"', '')
  21. .replace(' stroke-width="2"', ` stroke-width="${stroke}"`)
  22. .replace('</svg>', '</symbol>')
  23. .replace(/\n\s+/g, ' ')
  24. .replace(/<!--(.*?)-->/gis, '')
  25. svgContentSymbols += `\t${svgFileContentStroked}\n`
  26. svgContentIcons += `\t<use xlink:href="#icon-${stroke}" x="${x}" y="${paddingOuter}" width="${iconSize}" height="${iconSize}" />\n`
  27. x += padding + iconSize
  28. })
  29. const svgContent = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}" style="color: #354052"><rect x="0" y="0" width="${width}" height="${height}" fill="#fff"></rect>\n${svgContentSymbols}\n${svgContentIcons}\n</svg>`
  30. const svgContentDark = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}" style="color: #ffffff"><rect x="0" y="0" width="${width}" height="${height}" fill="transparent"></rect>\n${svgContentSymbols}\n${svgContentIcons}\n</svg>`
  31. fs.writeFileSync('.github/icons-stroke.svg', svgContent)
  32. fs.writeFileSync('.github/icons-stroke-dark.svg', svgContentDark)
  33. await createScreenshot('.github/icons-stroke.svg')
  34. await createScreenshot('.github/icons-stroke-dark.svg')