-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
66 changed files
with
20,390 additions
and
2,939 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
coverage: | ||
status: | ||
project: | ||
default: | ||
target: 95% | ||
patch: | ||
default: | ||
target: 95% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.md | ||
test | ||
vitest.config.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
extends: '@antfu', | ||
rules: { | ||
'@typescript-eslint/ban-ts-comment': 'off', | ||
'@typescript-eslint/prefer-ts-expect-error': 'off', | ||
'no-console': 'off', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16.x | ||
cache: pnpm | ||
|
||
- name: Setup | ||
run: npm i -g @antfu/ni | ||
|
||
- name: Install | ||
run: nci | ||
|
||
- name: Lint | ||
run: nr lint | ||
|
||
typecheck: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
cache: pnpm | ||
|
||
- name: Setup | ||
run: npm i -g @antfu/ni | ||
|
||
- name: Install | ||
run: nci | ||
|
||
test: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
node: [16.x, 18.x] | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
fail-fast: false | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
|
||
- name: Set node ${{ matrix.node }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
cache: pnpm | ||
|
||
- name: Setup | ||
run: npm i -g @antfu/ni | ||
|
||
- name: Install | ||
run: nci | ||
|
||
# - name: Test | ||
# run: nr test --run --coverage | ||
|
||
- name: Build | ||
run: nr build | ||
|
||
# - name: Upload coverage report to Codecov | ||
# uses: codecov/codecov-action@v3 | ||
# with: | ||
# token: ${{ secrets.CODECOV_TOKEN }} | ||
# files: coverage/lcov.info | ||
# fail_ci_if_error: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Release | ||
|
||
permissions: | ||
contents: write | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
|
||
- name: Set node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16.x | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: ChangeLog | ||
run: npx changelogithub | ||
env: | ||
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | ||
|
||
- name: Setup | ||
run: npm i -g @antfu/ni | ||
|
||
- name: Install | ||
run: nci | ||
|
||
- name: Release | ||
run: nr release | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
//.prettierignore | ||
**/*.min.js | ||
**/*.min.css | ||
|
||
.idea/ | ||
node_modules/ | ||
dist/ | ||
.vscode | ||
.DS_Store | ||
.idea | ||
.vscode | ||
npm-debug.log | ||
yarn-error.log | ||
.stylelintcache | ||
.eslintcache | ||
node_modules | ||
dist | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx --no -- commitlint --edit $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
lint-staged |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
registry = http://registry.npmjs.org | ||
registry = http://registry.npmjs.org | ||
auto-install-peers=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
16.17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
|
||
<p align="center"> | ||
<h1 align="center">taro-history</h1> | ||
</p> | ||
|
||
<div align="center"> | ||
一个用来为console.log添加代码所在文件名,所在行,log参数名以及添加分隔符的 vite 插件 | ||
|
||
[![NPM version][npm-image]][npm-url] ![NPM downloads][download-image] | ||
|
||
![Test][test-badge] | ||
|
||
<!-- ![codecov][codecov-badge] --> | ||
|
||
|
||
[npm-image]: https://img.shields.io/npm/v/taro-history.svg?style=flat-square | ||
[npm-url]: http://npmjs.org/package/taro-history | ||
|
||
|
||
[download-image]: https://img.shields.io/npm/dm/taro-history.svg?style=flat-square | ||
|
||
|
||
|
||
[test-badge]: https://github.com/baozouai/taro-history/actions/workflows/ci.yml/badge.svg | ||
|
||
[codecov-badge]: https://codecov.io/github/baozouai/plugin-taro-history/branch/master/graph/badge.svg | ||
|
||
|
||
</div> | ||
|
||
中文 | [English](./README.md) | ||
|
||
🔥 Features | ||
|
||
- 支持打印文件名 | ||
- 支持打印所在行(加上endLine则支持结束行) | ||
- 支持打印参数名称 | ||
- 支持分隔符来分开每个参数 | ||
- 支持不同的文件 —— 👉 .js、.jsx、.ts、.tsx、.vue、.svelte 和 .astro | ||
|
||
> 更多用法,请看[示例](#-例子) | ||
## 📦 安装 | ||
|
||
```sh | ||
pnpm add taro-history -D | ||
# or | ||
yarn add taro-history -D | ||
# or | ||
npm i taro-history -D | ||
``` | ||
## ⚙️ 参数 | ||
|
||
```ts | ||
interface Options { | ||
/** | ||
* 打印文件名 | ||
* 如果你文件名太长,希望不显示文件path的目录,比如src/pages/xxx/yyy/a.tsx, 那么可以配置enableDir为false,则只打印a.tsx | ||
* | ||
* @default true | ||
*/ | ||
enableFileName?: boolean | { | ||
enableDir?: boolean | ||
} | ||
/** | ||
* 打印的前缀提示,这样方便快速找到log 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 | ||
* @example | ||
* console.log(' 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀', ...) | ||
*/ | ||
preTip?: string | ||
/** 每个参数分隔符,默认空字符串,你也可以使用换行符\n,分号;逗号,甚至猪猪🐖都行~ */ | ||
splitBy?: boolean | ||
/** | ||
* 是否需要endLine,默认false,如果为true,只有在开始和结束不相同才打印endLine | ||
* @example | ||
* console.log('line of 1 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 ~ main.tsx', ..., 'line of 10 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 ~ main.tsx') | ||
* */ | ||
endLine?: boolean | ||
} | ||
``` | ||
|
||
## 🔨 使用 | ||
|
||
```ts | ||
import { defineConfig } from 'vite' | ||
import EnhanceLog from 'taro-history' | ||
|
||
const config = defineConfig({ | ||
plugins: [ | ||
// 如果用vue, 请确保 vuePlugin 在 log plugin 之前 | ||
EnhanceLog({ | ||
splitBy: '\n', | ||
preTip: '🐖🐖🐖🐖🐖🐖🐖🐖🐖🐖', | ||
enableFileName: true, // or enableFileName: { enableDir: false} | ||
}), | ||
], | ||
}) | ||
|
||
export default config | ||
|
||
``` | ||
|
||
## 👇 例子 | ||
|
||
拉项目后通过运行启动playgrounds: | ||
```shell | ||
pnpm play # 对应vue | ||
# 或者 | ||
pnpm play:react # 对应react | ||
``` | ||
|
||
来启动项目 | ||
|
||
具体配置可以看 [vue/vite.config.ts](./playgrounds/vue/vite.config.ts) 或者 [react/vite.config.ts](./playgrounds/react/vite.config.ts) | ||
|
||
比如说,你不喜欢小 🚀,你喜欢猪猪 🐖,那可以配置 preTip 为 🐖🐖🐖🐖🐖🐖🐖🐖🐖🐖: | ||
|
||
![img](./assets/pig_pretip.png) | ||
|
||
比如说,在参数较多的情况下,你希望 log 每个参数都换行,那可以配置 splitBy 为 `\n`: | ||
|
||
![img](./assets/linefeed.png) | ||
|
||
或者分隔符是`;`: | ||
|
||
![img](./assets/semicolon_delimiter.png) | ||
|
||
当然,你也可以随意指定,比如用个狗头🐶来分隔: | ||
|
||
![img](./assets/dog_delimiter.png) | ||
|
||
比如说,你希望知道log所在的文件名,那么可以配置enableFileName为true(当然默认就是true): | ||
|
||
![img](./assets/filename.png) | ||
|
||
如果文件路径太长: | ||
![img](./assets/deep_file.png) | ||
|
||
|
||
你只希望打印文件名,不需要目录前缀,那么可以配置 `enableFileName: { enableDir: false }`: | ||
![img](./assets/only_file_name.png) | ||
|
||
又比如说,有个 log 跨了多行,你希望 log 开始和结束的行数,中间是 log 实体,那可以将 endLine 设置为 true: | ||
|
||
![img](./assets/log_multi_line.png) | ||
|
||
![img](./assets/log_multi_line_res.png) | ||
|
||
> 我们可以看到开始的行数是29,结束的行数是44,跟源码一致 | ||
## 📄 协议 | ||
|
||
taro-history 遵循 [MIT 协议](./LICENSE). |
Oops, something went wrong.