-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: upgrade webpack to v5 and node to 22 and fixed workflow (#89)
- Loading branch information
Showing
301 changed files
with
6,033 additions
and
5,926 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
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
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 @@ | ||
22.11.0 |
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,69 +1,92 @@ | ||
const path = require('path') | ||
const fs = require('fs-plus') | ||
const cheerio = require('cheerio') | ||
const upperCamelCase = require('uppercamelcase') | ||
const svgr = require('@svgr/core').default | ||
const path = require("path"); | ||
const fs = require("fs-plus"); | ||
const upperCamelCase = require("uppercamelcase"); | ||
const svgr = require("@svgr/core").default; | ||
|
||
const iconsComponentPath = path.join(process.cwd(), 'icons') | ||
const iconsIndexPath = path.join(process.cwd(), 'index.js') | ||
const uniconsConfig = require('@iconscout/unicons/json/monochrome.json') | ||
const iconsComponentPath = path.join(process.cwd(), "icons"); | ||
const iconsIndexPath = path.join(process.cwd(), "index.js"); | ||
const uniconsConfig = require("@iconscout/unicons/json/monochrome.json"); | ||
|
||
const COLOR_CLASS = { | ||
'class="uim-primary"': 'opacity="1"', | ||
'class="uim-secondary"': 'opacity="0.7"', | ||
'class="uim-tertiary"': 'opacity="0.5"', | ||
'class="uim-quaternary"': 'opacity="0.25"', | ||
'class="uim-quinary"': 'opacity="0"' | ||
} | ||
'class="uim-quinary"': 'opacity="0"', | ||
}; | ||
|
||
// Clear Directories | ||
fs.removeSync(iconsComponentPath) | ||
fs.mkdirSync(iconsComponentPath) | ||
fs.removeSync(iconsComponentPath); | ||
fs.mkdirSync(iconsComponentPath); | ||
|
||
const indexJs = [] | ||
|
||
const icon = uniconsConfig[0] | ||
const indexJs = []; | ||
|
||
const babelTransform = (component) => { | ||
return new Promise ((resolve, reject) => { | ||
require("@babel/core").transform(component, { | ||
plugins: [ | ||
["@babel/plugin-transform-react-jsx", { | ||
useBuiltIns: true | ||
}] | ||
], | ||
}, function(err, result) { | ||
if (err) { | ||
reject(err) | ||
} else { | ||
resolve(result.code) | ||
return new Promise((resolve, reject) => { | ||
require("@babel/core").transform( | ||
component, | ||
{ | ||
plugins: [ | ||
[ | ||
"@babel/plugin-transform-react-jsx", | ||
{ | ||
useBuiltIns: true, | ||
}, | ||
], | ||
], | ||
}, | ||
function (err, result) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(result.code); | ||
} | ||
} | ||
}); | ||
}) | ||
} | ||
); | ||
}); | ||
}; | ||
|
||
uniconsConfig.forEach(icon => { | ||
const baseName = `uim-${icon.name}` | ||
const location = path.join(iconsComponentPath, `${baseName}.js`) | ||
const name = upperCamelCase(baseName) | ||
let svgFile = fs.readFileSync(path.resolve('node_modules/@iconscout/unicons', icon.svg), 'utf-8') | ||
uniconsConfig.forEach((icon) => { | ||
const baseName = `uim-${icon.name}`; | ||
const location = path.join(iconsComponentPath, `${baseName}.js`); | ||
const name = upperCamelCase(baseName); | ||
let svgFile = fs.readFileSync( | ||
path.resolve("node_modules/@iconscout/unicons", icon.svg), | ||
"utf-8" | ||
); | ||
|
||
Object.keys(COLOR_CLASS).forEach(key => { | ||
svgFile = svgFile.replace(new RegExp(key, 'g'), COLOR_CLASS[key]) | ||
}) | ||
Object.keys(COLOR_CLASS).forEach((key) => { | ||
svgFile = svgFile.replace(new RegExp(key, "g"), COLOR_CLASS[key]); | ||
}); | ||
|
||
svgr(svgFile, { svgo: false, expandProps: 'start', svgProps: { width: "{props.size || '1em'}", height: "{props.size || '1em'}", fill: 'currentColor', className: "{`ui-svg-inline ${props.className || ''}`}" } }, { componentName: name }).then(template => { | ||
babelTransform(template).then(code => { | ||
svgr( | ||
svgFile, | ||
{ | ||
svgo: false, | ||
expandProps: "start", | ||
svgProps: { | ||
width: "{props.size || '1em'}", | ||
height: "{props.size || '1em'}", | ||
fill: "currentColor", | ||
className: "{`ui-svg-inline ${props.className || ''}`}", | ||
}, | ||
}, | ||
{ componentName: name } | ||
).then((template) => { | ||
babelTransform(template).then((code) => { | ||
// Add CSS in reactComponent | ||
reactComponent = code.replace(`import * as React from "react";`, `import * as React from "react";\nimport "../utils/style.css";`) | ||
fs.writeFileSync(location, reactComponent, 'utf-8') | ||
}) | ||
}) | ||
reactComponent = code.replace( | ||
`import * as React from "react";`, | ||
`import * as React from "react";\nimport "../utils/style.css";` | ||
); | ||
fs.writeFileSync(location, reactComponent, "utf-8"); | ||
}); | ||
}); | ||
|
||
// Add it to index.js | ||
indexJs.push(`export { default as ${name} } from './icons/${baseName}'`) | ||
}) | ||
indexJs.push(`export { default as ${name} } from './icons/${baseName}'`); | ||
}); | ||
|
||
fs.writeFileSync(iconsIndexPath, indexJs.join('\n'), 'utf-8') | ||
fs.writeFileSync(iconsIndexPath, indexJs.join("\n"), "utf-8"); | ||
|
||
console.log(`Generated ${uniconsConfig.length} icon components.`) | ||
console.log(`Generated ${uniconsConfig.length} icon components.`); |
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
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
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
Oops, something went wrong.