Add helper script to convert the SVG icon files into a Vue components

This commit is contained in:
Wolfgang Huß 2024-03-20 12:28:22 +01:00
parent d65d574e1d
commit ff0ad9054a

View File

@ -0,0 +1,24 @@
// usage:
// put source files in folder 'svgs'
// folder 'svgComponents' have to exist
// call script with command 'node convertSvgToVue.js'
// delete source files or whole folder
// run 'lint --fix' afterwards
import { readdirSync, readFileSync, writeFileSync } from 'fs'
import { join, parse } from 'path'
const inputDir = '../svgs'
const outputDir = '../svgComponents'
readdirSync(inputDir).forEach((file) => {
const filePath = join(inputDir, file)
const fileName = parse(file).name
// eslint-disable-next-line security/detect-non-literal-fs-filename
const content = readFileSync(filePath, 'utf8')
const vueComponent = `<!-- eslint-disable vue/multi-word-component-names -->\n<!-- eslint-disable @intlify/vue-i18n/no-raw-text -->\n<template>\n${content}\n</template>\n\n<script lang="ts">\nimport { defineComponent } from 'vue';\n\nexport default defineComponent({});\n</script>\n`
const outputFilePath = join(outputDir, `${fileName}.vue`)
// eslint-disable-next-line security/detect-non-literal-fs-filename
writeFileSync(outputFilePath, vueComponent)
})