From b38b48195568f3a9f85b5ca3f642fdc2ca02eab6 Mon Sep 17 00:00:00 2001 From: Il Harper Date: Tue, 17 May 2022 22:25:11 +0800 Subject: [PATCH] build: pretty twoslash error log (#686) --- .github/workflows/build.yml | 4 ++-- docs/.vuepress/markdown/twoslash.js | 28 ++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2867dfdcf1..74c42468fd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -149,7 +149,6 @@ jobs: name: codecov docs: - if: ${{ github.repository == 'koishijs/koishi' && github.ref == 'refs/heads/master' }} runs-on: ubuntu-latest needs: - prepare @@ -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 }} @@ -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 @@ -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 }} diff --git a/docs/.vuepress/markdown/twoslash.js b/docs/.vuepress/markdown/twoslash.js index f31248afd4..e08942c6c9 100644 --- a/docs/.vuepress/markdown/twoslash.js +++ b/docs/.vuepress/markdown/twoslash.js @@ -49,12 +49,28 @@ function render(code, lang, attrs) { .replace(/<\/div>(?!<\/pre>)/g, '\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 } }