-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Chore] auto generate icon index.js #281
Conversation
*/ | ||
function indexTemplate(filePaths) { | ||
const importStatements = filePaths.map((filePath) => { | ||
const exportName = path.basename(filePath, path.extname(filePath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(optional)exportName
叫 fileName
會不會比較直覺一點?
阿阿,但是它官方是寫 exportName
,就看乙山大大惹,我只是看 path.basename(filePath, path.extname(filePath))
截出來的是 fileName
而已,不然我還自己開 node 試了一下這個邏輯。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fileName
可啊,按我們的規範 component 名稱和檔名本來就應該一樣
function isUpperCase(char) { | ||
return char.toUpperCase() === char; | ||
} | ||
|
||
function upperCamelCaseToKebabCase(inputString) { | ||
let result = ''; | ||
inputString.split('').forEach((char, i) => { | ||
if (isUpperCase(char)) { | ||
if (i !== 0) { | ||
result += '-'; | ||
} | ||
result += char.toLowerCase(); | ||
} else { | ||
result += char; | ||
} | ||
}); | ||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我猜應該有套件在做類似的事情,maybe https://github.com/blakeembrey/change-case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是有啦,可是想說這可以自己寫就處理掉,比較不會莫名引入有問題的 package
Purpose
接著 #280,
src/icons/svg
,自動產 index.js (用 svgr 的 custom index template)。產出來的 index.js 會放在src/icons/components
裡面。configs/fontello.config.json
,將引用它的 storybook 改成引用 icon components index.js。會導致 storybook 面 basic usage 的順序有點小差異(改成由 a-z),但應該還好。至此,加入新 icon 的流程變成:
packages/core/src/icons/svg
。yarn generate-icon-components
。(這會吃下整個src/icons/svg
資料夾,吐出 components 和 index.js 到src/icons/components
。)Changes
Risk
應該沒有。
TODOs