Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
54nd10 committed Jan 7, 2024
1 parent 5e3d8f3 commit 63bcd81
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 60 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ jobs:
name: Storybook
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: npm i
# - uses: actions/checkout@v2
# - name: Install modules
# run: npm i
- name: Check for missing stories
id: check
run: echo "::set-output name=summary::$(npx tsx apps/www/scripts/storybook-checker.ts)"
- uses: buildingcash/json-to-markdown-table-action@v1
id: table
with:
json: ${{ steps.check.outputs.summary }}
# - uses: buildingcash/json-to-markdown-table-action@v1
# id: table
# with:
# json: ${{ steps.check.outputs.summary }}
- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
${{steps.table.outputs.table}}
${{steps.check.outputs.summary}}
117 changes: 65 additions & 52 deletions scripts/storybook-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,74 @@ import tablemark from 'tablemark'

const basePath = '../apps/www/src/components/ui'
;(async () => {
const uiComponents = fg.sync(join(__dirname, `${basePath}/**/*/index.tsx`))
const componentsCategories = fg
.sync(join(__dirname, `${basePath}/*`), {onlyDirectories: true})
.reduce((acc, path) => {
const key = path.split('/').pop()?.toString() || ''
return {
...acc,
[key]: {
path,
total: 0,
hasStory: 0
}
}
}, {})
// const uiComponents = fg.sync(join(__dirname, `${basePath}/**/*/index.tsx`))
// const componentsCategories = fg
// .sync(join(__dirname, `${basePath}/*`), {onlyDirectories: true})
// .reduce((acc, path) => {
// const key = path.split('/').pop()?.toString() || ''
// return {
// ...acc,
// [key]: {
// path,
// total: 0,
// hasStory: 0
// }
// }
// }, {})

function incrementCategory(path: string, hasStory: boolean) {
const index = Object.keys(componentsCategories)
.map((key) => path.includes(componentsCategories[key].path))
.indexOf(true)
componentsCategories[Object.keys(componentsCategories)[index]].total++
hasStory && componentsCategories[Object.keys(componentsCategories)[index]].hasStory++
}
// function incrementCategory(path: string, hasStory: boolean) {
// const index = Object.keys(componentsCategories)
// .map((key) => path.includes(componentsCategories[key].path))
// .indexOf(true)
// componentsCategories[Object.keys(componentsCategories)[index]].total++
// hasStory && componentsCategories[Object.keys(componentsCategories)[index]].hasStory++
// }

function getRelativePath(path: string) {
return path.replace(join(__dirname, basePath), '.')
}
// function getRelativePath(path: string) {
// return path.replace(join(__dirname, basePath), '.')
// }

const componentsStories = await Promise.all(
uiComponents.map(async (path) => {
const splitedPath = path.split('/')
splitedPath.pop()
const parent = splitedPath.join('/')
const name = parent.split('/').pop()
const hasStory = fs.existsSync(`${parent}/${name}.stories.tsx`)
incrementCategory(path, hasStory)
return {
name,
hasStory,
path: getRelativePath(parent)
}
})
)
// const componentsStories = await Promise.all(
// uiComponents.map(async (path) => {
// const splitedPath = path.split('/')
// splitedPath.pop()
// const parent = splitedPath.join('/')
// const name = parent.split('/').pop()
// const hasStory = fs.existsSync(`${parent}/${name}.stories.tsx`)
// incrementCategory(path, hasStory)
// return {
// name,
// hasStory,
// path: getRelativePath(parent)
// }
// })
// )

const categoriesSummaryTable = Object.keys(componentsCategories).map((key) => {
const {total, hasStory} = componentsCategories[key]
return {
Category: key,
'Total components': total,
'Has story': `${hasStory} - ${Math.round((hasStory / total) * 100)}%`
}
})
console.log(tablemark(categoriesSummaryTable))
// const categoriesSummaryTable = Object.keys(componentsCategories).map((key) => {
// const {total, hasStory} = componentsCategories[key]
// return {
// Category: key,
// 'Total components': total,
// 'Has story': `${hasStory} - ${Math.round((hasStory / total) * 100)}%`
// }
// })
// console.log(tablemark(categoriesSummaryTable))

const missingStories = componentsStories.filter(({hasStory}) => !hasStory)
if (missingStories.length > 0) {
console.log(tablemark(missingStories))
}
// const missingStories = componentsStories.filter(({hasStory}) => !hasStory)
// if (missingStories.length > 0) {
// console.log(tablemark(missingStories))
// }

console.log(`
| Category | Total components | Has story |
| :-------- | :--------------- | :-------- |
| atoms | 8 | 8 - 100% |
| molecules | 12 | 12 - 100% |
| organisms | 26 | 26 - 100% |
| svgs | 1 | 0 - 0% |
| Name | Has story | Path |
| :---- | :-------- | :----------- |
| icons | false | ./svgs/icons |
`)
})()

0 comments on commit 63bcd81

Please sign in to comment.