-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(foundations/icons): add mozaic svelte icon components (#824)
- Loading branch information
1 parent
9463230
commit 39aaa12
Showing
904 changed files
with
9,092 additions
and
952 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,57 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const reactIconsIndex = require('./reactIcon') | ||
const vueIconsIndex = require('./vueIcon') | ||
const config = require('../config') | ||
const fs = require("fs") | ||
const path = require("path") | ||
const reactIconsIndex = require("./reactIcon") | ||
const svelteIconsIndex = require("./svelteIcon") | ||
const vueIconsIndex = require("./vueIcon") | ||
const config = require("../config") | ||
const { createComponentName } = require("../utils/tools") | ||
|
||
const transpilers = { | ||
react: { | ||
transpiler: reactIconsIndex, | ||
file: 'index.js', | ||
file: "index.js", | ||
}, | ||
vue: { | ||
transpiler: vueIconsIndex, | ||
file: 'index.vue', | ||
file: "index.vue", | ||
}, | ||
svelte: { | ||
transpiler: svelteIconsIndex, | ||
file: "index.svelte", | ||
}, | ||
} | ||
|
||
const generateIconComponent = (framework, icons) => | ||
new Promise((res, rej) => { | ||
const data = transpilers[framework].transpiler(icons) | ||
if (framework === "svelte") { | ||
icons.map((icon) => { | ||
const dataSvelte = transpilers[framework].transpiler(icon) | ||
const parsedName = createComponentName(icon.fileName) | ||
|
||
const writePath = path.join( | ||
process.cwd(), | ||
config.outputPaths[framework], | ||
`${parsedName}.svelte` | ||
) | ||
|
||
const writePath = path.join( | ||
process.cwd(), | ||
config.outputPaths[framework], | ||
transpilers[framework].file | ||
) | ||
fs.writeFile(writePath, dataSvelte, "utf8", (err) => { | ||
if (err) rej(err) | ||
res(true) | ||
}) | ||
}) | ||
} else { | ||
const data = transpilers[framework].transpiler(icons) | ||
const writePath = path.join( | ||
process.cwd(), | ||
config.outputPaths[framework], | ||
transpilers[framework].file | ||
) | ||
|
||
fs.writeFile(writePath, data, 'utf8', err => { | ||
if (err) rej(err) | ||
res(true) | ||
}) | ||
fs.writeFile(writePath, data, "utf8", (err) => { | ||
if (err) rej(err) | ||
res(true) | ||
}) | ||
} | ||
}) | ||
|
||
module.exports = generateIconComponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { convertPxToRem } = require("../utils/tools") | ||
|
||
const iconContent = (fileName, data) => { | ||
const size = fileName.replace(".svg", "").split("_").pop() | ||
|
||
const parsedData = data.replace( | ||
"<svg", | ||
`<svg width={size} height={size} id={id} style={style} class={className} fill={fill}` | ||
) | ||
|
||
return `<script> | ||
export let id = undefined; | ||
export let style = undefined; | ||
export let className = undefined; | ||
export let fill = undefined; | ||
export let size = "${convertPxToRem(size)}"; | ||
</script> | ||
${parsedData}` | ||
} | ||
|
||
const svelteIconsIndex = (icon) => `${iconContent(icon.fileName, icon.data)}` | ||
|
||
module.exports = svelteIconsIndex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
const path = require('path') | ||
const destPath = strPath => path.relative(process.cwd(), strPath) | ||
const path = require("path") | ||
const destPath = (strPath) => path.relative(process.cwd(), strPath) | ||
|
||
module.exports = { | ||
sourcePaths: { | ||
svg: destPath('src/icons/SVG'), | ||
svgColor: destPath('src/icons/COLORS/SVG'), | ||
svgColorToGatsby: destPath('src/icons/COLORS/SVG'), | ||
pdf: destPath('src/icons/PDF'), | ||
pdfColor: destPath('src/icons/COLORS/PDF'), | ||
svg: destPath("src/icons/SVG"), | ||
svgColor: destPath("src/icons/COLORS/SVG"), | ||
svgColorToGatsby: destPath("src/icons/COLORS/SVG"), | ||
pdf: destPath("src/icons/PDF"), | ||
pdfColor: destPath("src/icons/COLORS/PDF"), | ||
}, | ||
outputPaths: { | ||
data: destPath('src/data'), | ||
svg: destPath('packages/icons/svg'), | ||
svgColor: destPath('packages/icons/svg-color'), | ||
svgColorToGatsby: destPath('static/colorsvg'), | ||
pdf: destPath('packages/icons/pdf'), | ||
pdfColor: destPath('packages/icons/pdf-color'), | ||
react: destPath('packages/icons/react'), | ||
vue: destPath('packages/icons/vue'), | ||
data: destPath("src/data"), | ||
svg: destPath("packages/icons/svg"), | ||
svgColor: destPath("packages/icons/svg-color"), | ||
svgColorToGatsby: destPath("static/colorsvg"), | ||
pdf: destPath("packages/icons/pdf"), | ||
pdfColor: destPath("packages/icons/pdf-color"), | ||
react: destPath("packages/icons/react"), | ||
vue: destPath("packages/icons/vue"), | ||
svelte: destPath("packages/icons/svelte"), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.