Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 3 roky
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. const fs = require('fs-extra')
  2. const process = require('process')
  3. const changeCase = require('change-case')
  4. const EXIT = 1
  5. const README = './README.md'
  6. const README_HEADER = '# Material Icons\n\n> materialdesignicons.com\n\n| | Name\n:-: | :----------:\n'
  7. const iconsFrom = './svg'
  8. const iconsTo = './icons'
  9. const createFileString = (name, paths) =>
  10. `import React from 'react'
  11. const DEFAULT_SIZE = 24
  12. export default ({
  13. fill = 'currentColor',
  14. width = DEFAULT_SIZE,
  15. height = DEFAULT_SIZE,
  16. style = {},
  17. ...props
  18. }) => (
  19. <svg
  20. viewBox={ \`0 0 \${ DEFAULT_SIZE } \${ DEFAULT_SIZE }\` }
  21. style={{ fill, width, height, ...style }}
  22. { ...props }
  23. >
  24. ${ paths }
  25. </svg>
  26. )
  27. `
  28. const createIndexString = (file) => `export { default as ${ file.replace('.js', '') } } from './${ file }'`
  29. const createMarkdownString = (file) => {
  30. const name = file.replace('.js', '')
  31. const oldFileName = changeCase.paramCase(name).replace('-icon', '')
  32. return `<img src="https://unpkg.com/@icons/material/svg/${ oldFileName }.svg" width="24" height="24"> | \`${ name }\``
  33. }
  34. fs.removeSync(README)
  35. fs.writeFileSync(README, '')
  36. fs.removeSync(iconsFrom)
  37. fs.ensureDirSync(iconsFrom)
  38. fs.copySync('./node_modules/mdi-svg/svg', iconsFrom)
  39. fs.removeSync(iconsTo)
  40. fs.ensureDirSync(iconsTo)
  41. fs.writeFileSync(`${ iconsTo }/index.js`, '')
  42. fs.readdir(iconsFrom)
  43. .then((files) => {
  44. const fileContents = files.map((filename) => fs.readFile(`${ iconsFrom }/${ filename }`, 'utf-8'))
  45. return Promise.all(fileContents)
  46. .then((contents) => ({
  47. names: files,
  48. contents,
  49. }))
  50. })
  51. .then((files) => Promise.all(
  52. files.names.map((filename, i) => {
  53. const content = files.contents[i]
  54. // eslint-disable-next-line no-unused-vars
  55. const [match, paths] = content.match(/<svg .+?>(.+?)<\/svg>/)
  56. const name = `${ changeCase.pascalCase(filename.replace('.svg', '')) }Icon`
  57. return fs.writeFile(`${ iconsTo }/${ name }.js`, createFileString(name, paths))
  58. })
  59. ))
  60. .then(() =>
  61. fs.readdir(iconsTo)
  62. .then((files) => {
  63. const file = files.map((fileName) => createMarkdownString(fileName))
  64. return fs.writeFile(README, `${ README_HEADER }${ file.join('\n') }\n`)
  65. })
  66. )
  67. .then(() =>
  68. fs.readdir(iconsTo)
  69. .then((files) => {
  70. const file = files.map((fileName) => createIndexString(fileName))
  71. return fs.writeFile(`${ iconsTo }/index.js`, `${ file.join('\n') }\n`)
  72. })
  73. )
  74. .catch((err) => {
  75. console.log(err)
  76. process.exit(EXIT)
  77. })