-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c23d90c
commit d3717b9
Showing
9 changed files
with
142 additions
and
128 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,49 @@ | ||
const path = require('node:path') | ||
|
||
// const log = require('./log') | ||
const getFileList = require('./utils/getFileList') | ||
const removeFile = require('./utils/removeFile') | ||
const sortByName = require('./utils/sortByName') | ||
const writeTextFile = require('./utils/writeTextFile') | ||
|
||
const dirs = [ | ||
'composables', | ||
'icons', | ||
'utils' | ||
] | ||
|
||
// Build logic | ||
function getFilenames (sourceDir) { | ||
const fileList = getFileList(sourceDir, '{svg,js}') | ||
|
||
const ids = fileList.map((file) => { | ||
return file.replace(sourceDir, '') | ||
}) | ||
|
||
return sortByName(ids) | ||
} | ||
|
||
function composeIndex (sourceDirFromBuildDir, filenames) { | ||
return filenames.map((filename) => { | ||
return `export { default as ${filename.replace('.js', '').replace('.svg', '')} } from '${sourceDirFromBuildDir}${filename}'` | ||
}).join('\n') + '\n' | ||
} | ||
|
||
// Build process | ||
function build () { | ||
dirs.forEach((dir) => { | ||
const sourceDir = path.resolve(__dirname, `../${dir}/`) + '/' | ||
const buildDir = path.resolve(__dirname, '../') + '/' | ||
|
||
const indexFilePath = `${dir}.js` | ||
const sourceDirFromBuildDir = `./${dir}/` | ||
|
||
const filenames = getFilenames(sourceDir) | ||
|
||
removeFile(buildDir + indexFilePath) | ||
writeTextFile(buildDir + indexFilePath, composeIndex(sourceDirFromBuildDir, filenames)) | ||
}) | ||
} | ||
|
||
// Actually run the build | ||
build() |
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,23 @@ | ||
// https://github.com/svg/svgo?tab=readme-ov-file#api-usage | ||
const { | ||
// loadConfig, | ||
optimize | ||
} = require('svgo') | ||
|
||
const path = require('node:path') | ||
|
||
const getFileList = require('./utils/getFileList') | ||
const readFile = require('./utils/readFile') | ||
const writeTextFile = require('./utils/writeTextFile') | ||
|
||
// const config = await loadConfig() | ||
|
||
const sourceDir = path.resolve(__dirname, '../icons/') + '/' | ||
const filePaths = getFileList(sourceDir, 'svg') | ||
|
||
filePaths.forEach((filePath) => { | ||
const svgString = readFile(filePath) | ||
const optimized = optimize(svgString) | ||
|
||
writeTextFile(filePath, optimized.data) | ||
}) |
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
const fs = require('node:fs') | ||
|
||
// https://nodejs.org/en/learn/manipulating-files/reading-files-with-nodejs | ||
module.exports = function (path) { | ||
try { | ||
const data = fs.readFileSync(path, 'utf8') | ||
return data | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
|
||
return '' | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,40 @@ | ||
// https://github.com/svg/svgo | ||
export default { | ||
multipass: false, // boolean | ||
datauri: 'base64', // 'base64'|'enc'|'unenc' | ||
js2svg: { | ||
indent: 4, // number | ||
pretty: false // boolean | ||
}, | ||
plugins: [ | ||
'preset-default', // built-in plugins enabled by default | ||
'removeTitle', | ||
// 'removeViewBox', | ||
'removeDimensions', | ||
|
||
// { | ||
// name: 'convertTransform', | ||
// params: { | ||
// degPrecision: 0, | ||
// floatPrecision: 0, | ||
// transformPrecision: 0 | ||
// } | ||
// }, | ||
|
||
// https://svgo.dev/docs/plugins/convertColors/ | ||
{ | ||
name: 'convertColors', | ||
params: { | ||
names2hex: true, | ||
rgb2hex: true, | ||
shorthex: true, | ||
shortname: true, | ||
|
||
// Convert this color code in fills/strokes to currentColor (used to generate mono-capable assets) | ||
// NOTE: must be exact, case-sensitive match before any other conversions | ||
// Assets must be authored with this in mind | ||
currentColor: '#FF00FF' | ||
} | ||
} | ||
] | ||
} |