Skip to content

Commit

Permalink
build: pretty twoslash error log (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilharp authored May 17, 2022
1 parent 2fc58aa commit b38b481
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ jobs:
name: codecov

docs:
if: ${{ github.repository == 'koishijs/koishi' && github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
needs:
- prepare
Expand Down Expand Up @@ -201,6 +200,7 @@ jobs:
- name: Build
run: yarn docs build
- name: Deploy
if: ${{ github.repository == 'koishijs/koishi' && github.ref == 'refs/heads/master' }}
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
Expand All @@ -210,7 +210,6 @@ jobs:
force_orphan: true

docs-next:
if: ${{ github.repository == 'koishijs/koishi' && github.ref == 'refs/heads/next' }}
runs-on: ubuntu-latest
needs:
- prepare
Expand Down Expand Up @@ -242,6 +241,7 @@ jobs:
- name: Build
run: yarn docs build
- name: Deploy
if: ${{ github.repository == 'koishijs/koishi' && github.ref == 'refs/heads/next' }}
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY_NEXT }}
Expand Down
28 changes: 22 additions & 6 deletions docs/.vuepress/markdown/twoslash.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,28 @@ function render(code, lang, attrs) {
.replace(/<\/div>(?!<\/pre>)/g, '</span>\n')
.replace(/<\/br>/g, '\n')
} catch (e) {
console.log('Code block:')
console.log(code)
console.log()
console.log('Message:')
console.log(e.message)
console.log()
const ci = 'GITHUB_ACTIONS' in process.env
const blue = (x) => `\u001b[34m${x}\u001b[0m\n`
const startGroup = (x) => ci ? `::group::${x}` : `${blue('----- ' + x)}\n`
const endGroup = () => ci ? '::endgroup::' : `${blue('-----')}\n`

if ('recommendation' in e && 'code' in e) {
// Twoslash error
console.log(startGroup('Twoslash Compiler Error'))
console.log(blue('Code:'))
console.log(e.code)
console.log(blue('Error:'))
console.log(e.recommendation)
} else {
// Other error
console.log(startGroup('Twoslash Error'))
console.log(blue('Code:'))
console.log(code)
console.log(blue('Error:'))
console.log(e.message)
}

console.log(endGroup())
return null
}
}
Expand Down

0 comments on commit b38b481

Please sign in to comment.