From f20204900addffa03400ac7385bcfaf4f52b09ad Mon Sep 17 00:00:00 2001 From: dylanirlbeck Date: Thu, 14 May 2020 22:34:40 -0500 Subject: [PATCH] Removing **.js files from static/avatars --- static/avatars/Exports.js | 3 - static/avatars/SvgLoader.js | 62 -------------- static/avatars/array.js | 6 -- static/avatars/files.json | 1 - static/avatars/parse.js | 54 ------------ static/avatars/svg.js | 158 ------------------------------------ 6 files changed, 284 deletions(-) delete mode 100644 static/avatars/Exports.js delete mode 100644 static/avatars/SvgLoader.js delete mode 100644 static/avatars/array.js delete mode 100644 static/avatars/files.json delete mode 100644 static/avatars/parse.js delete mode 100644 static/avatars/svg.js diff --git a/static/avatars/Exports.js b/static/avatars/Exports.js deleted file mode 100644 index dc260b4..0000000 --- a/static/avatars/Exports.js +++ /dev/null @@ -1,3 +0,0 @@ -| "Mediumround" => getMediumround(fill, size)} -| "Smallround" => getSmallround(fill, size)} -| "Wrinkles" => getWrinkles(fill, size)} diff --git a/static/avatars/SvgLoader.js b/static/avatars/SvgLoader.js deleted file mode 100644 index b8b137e..0000000 --- a/static/avatars/SvgLoader.js +++ /dev/null @@ -1,62 +0,0 @@ -let getMediumround = (fill, size) => { - ;j | - ( - - - - - - - ) | - j -} -let getSmallround = (fill, size) => { - ;j | - ( - - - - - - - ) | - j -} -let getWrinkles = (fill, size) => { - ;j | - ( - - - - - - - - ) | - j -} diff --git a/static/avatars/array.js b/static/avatars/array.js deleted file mode 100644 index 3497a1a..0000000 --- a/static/avatars/array.js +++ /dev/null @@ -1,6 +0,0 @@ -"Mediumround", -"Smallround", -"Wrinkles", -"Mediumround", -"Smallround", -"Wrinkles", diff --git a/static/avatars/files.json b/static/avatars/files.json deleted file mode 100644 index 9e26dfe..0000000 --- a/static/avatars/files.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/static/avatars/parse.js b/static/avatars/parse.js deleted file mode 100644 index ee7b848..0000000 --- a/static/avatars/parse.js +++ /dev/null @@ -1,54 +0,0 @@ -const fs = require('fs') -const { promisify } = require('util') - -const readdirAsync = promisify(fs.readdir) -const readFileAsync = promisify(fs.readFile) - -const templ = (name, code) => ` -import * as React from "react"; - -const Svg${name} = () => ( - ${code} -) - -export default Svg${name} -` - -function capitalize(string) { - return string.charAt(0).toUpperCase() + string.slice(1) -} - -const ITEMS = {} - -async function readDir() { - const folders = await readdirAsync('.') - - for (const f of folders) { - if (f.indexOf('DS_Store') === -1) { - try { - const svgs = await readdirAsync(f) - if (Array.isArray(svgs)) { - const svgsToParse = svgs. - for (const svg of svgs) { - const path = `${process.cwd()}/${f}/${svg}` - const res = await readFileAsync(path, 'utf8') - const name = capitalize(svg.split('.')[0].split('-')[0]) - const code = templ(name, res) - - console.log('name', name) - console.log('code', code) - } - } - } catch (e) { - console.log('err', e) - } - } - } - - return ITEMS -} - -readDir() - .then(console.log) - // .then(items => fs.writeFileSync('files.json', JSON.stringify(items, null, 2))) - .catch(console.error) diff --git a/static/avatars/svg.js b/static/avatars/svg.js deleted file mode 100644 index 240bdd8..0000000 --- a/static/avatars/svg.js +++ /dev/null @@ -1,158 +0,0 @@ -const SVGO = require('svgo') -const fs = require('fs') -const { promisify } = require('util') - -const readdirAsync = promisify(fs.readdir) -const readFileAsync = promisify(fs.readFile) -const appendFileAsync = promisify(fs.appendFile) - -const svgo = new SVGO({ - plugins: [ - { - cleanupAttrs: true, - }, - { - removeDoctype: true, - }, - { - removeXMLProcInst: true, - }, - { - removeComments: true, - }, - { - removeMetadata: true, - }, - { - removeTitle: true, - }, - { - removeDesc: true, - }, - { - removeUselessDefs: true, - }, - { - removeEditorsNSData: true, - }, - { - removeEmptyAttrs: true, - }, - { - removeHiddenElems: true, - }, - { - removeEmptyText: true, - }, - { - removeEmptyContainers: true, - }, - { - removeViewBox: false, - }, - { - cleanupEnableBackground: true, - }, - { - convertStyleToAttrs: true, - }, - { - convertColors: true, - }, - { - convertPathData: true, - }, - { - convertTransform: true, - }, - { - removeUnknownsAndDefaults: true, - }, - { - removeNonInheritableGroupAttrs: true, - }, - { - removeUselessStrokeAndFill: true, - }, - { - removeUnusedNS: true, - }, - { - cleanupIDs: true, - }, - { - cleanupNumericValues: true, - }, - { - moveElemsAttrsToGroup: true, - }, - { - moveGroupAttrsToElems: true, - }, - { - collapseGroups: true, - }, - { - removeRasterImages: false, - }, - { - mergePaths: true, - }, - { - convertShapeToPath: true, - }, - { - sortAttrs: true, - }, - { - removeDimensions: true, - }, - { - removeAttrs: { attrs: '(xmlns|link)' }, - }, - { removeXMLNS: true }, - { - removePrefixedAttributes: { - type: 'perItem', - fn: (item) => { - item.eachAttr((attr) => { - if (attr.prefix && attr.local) { - item.removeAttr(attr.name) - } - }) - }, - }, - }, - ], -}) - -const createCode = (name, code) => - `let get${name} = (fill, size) => {j|${code}|j};\n` -const createExport = (name) => `| "${name}" => get${name}(fill, size)}\n` - -function capitalize(string) { - return string.charAt(0).toUpperCase() + string.slice(1) -} - -async function runSvgo(path) { - const folder = process.cwd() - const file = await readFileAsync(path) - const result = await svgo.optimize(file, { path }) - const location = `${folder}/${path}` - const fileName = capitalize(path.split('/')[1].split('.')[0]) - await appendFileAsync( - 'SvgLoader.js', - createCode(fileName, result.data), - 'utf-8' - ) - await appendFileAsync('Exports.js', createExport(fileName), 'utf-8') - await appendFileAsync('array.js', `"${fileName}",\n`, 'utf-8') - fs.writeFileSync(`${folder}/${path}`, result.data, 'utf-8') - return path -} - -const file = process.argv[2] -runSvgo(file).then((file) => { - console.log('done', file) - process.exit(0) -})