Skip to content
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

Merged
merged 7 commits into from
Aug 7, 2020

Conversation

chenesan
Copy link
Contributor

@chenesan chenesan commented Aug 4, 2020

Purpose

接著 #280

  • icon component 改成吃整個 src/icons/svg,自動產 index.js (用 svgr 的 custom index template)。產出來的 index.js 會放在 src/icons/components 裡面。
  • 調整產出的 icon component 格式。(用 svgr 的 custom template,並且調整 svgr 內部的 prettier 設定)
  • 拔掉 configs/fontello.config.json,將引用它的 storybook 改成引用 icon components index.js。會導致 storybook 面 basic usage 的順序有點小差異(改成由 a-z),但應該還好。

至此,加入新 icon 的流程變成:

  1. 把新的 svg 加到 packages/core/src/icons/svg
  2. 在 core package 裡面跑 yarn generate-icon-components。(這會吃下整個 src/icons/svg 資料夾,吐出 components 和 index.js 到 src/icons/components。)

Changes

  • a list of what have been done
  • maybe some code change

Risk

應該沒有。

TODOs

  • Describe what should be done outside of this PR
  • Maybe in other PRs or some manual actions.

*/
function indexTemplate(filePaths) {
const importStatements = filePaths.map((filePath) => {
const exportName = path.basename(filePath, path.extname(filePath));
Copy link
Contributor

@benny0642 benny0642 Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(optional)exportNamefileName 會不會比較直覺一點?
阿阿,但是它官方是寫 exportName,就看乙山大大惹,我只是看 path.basename(filePath, path.extname(filePath)) 截出來的是 fileName而已,不然我還自己開 node 試了一下這個邏輯。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileName 可啊,按我們的規範 component 名稱和檔名本來就應該一樣

Comment on lines 3 to 20
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;
}
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是有啦,可是想說這可以自己寫就處理掉,比較不會莫名引入有問題的 package

@chenesan chenesan merged commit 60b769e into develop Aug 7, 2020
@chenesan chenesan deleted the chore/auto-generate-icon-index branch August 7, 2020 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants