Repository: TaroXin/vue-pretty-logger Branch: master Commit: 0ca3491517e0 Files: 23 Total size: 53.5 KB Directory structure: gitextract_mhxvg_ky/ ├── .babelrc ├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── example/ │ ├── example.js │ ├── index.html │ ├── main.js │ ├── source.vue │ └── webpack.config.js ├── index.js ├── lib/ │ ├── constant/ │ │ ├── logger-types.js │ │ └── options.js │ ├── in-js.js │ ├── index.js │ └── utils/ │ ├── logger-note-judge.js │ ├── logger-parser.js │ └── logger-type-judge.js ├── package.json └── test/ ├── loader-type-judge.test.js └── logger-parser.test.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .babelrc ================================================ { "presets": ["env"], "plugins": [ "transform-runtime" ] } ================================================ FILE: .gitignore ================================================ .DS_Store node_modules *.log example/dist ================================================ FILE: .npmignore ================================================ test example yarn.lock ================================================ FILE: .travis.yml ================================================ language: node_js node_js: - "8" ================================================ FILE: CHANGELOG.md ================================================ # 0.9.0 (2018-05-09) ### Bug Fixes * fix bug 'loaderContext is not defined' ([a03dacf](https://github.com/TaroXin/vue-pretty-logger/commit/a03dacf)) * fix bug: Cannot read property 'content' of null. ([6956668](https://github.com/TaroXin/vue-pretty-logger/commit/6956668)), closes [#1](https://github.com/TaroXin/vue-pretty-logger/issues/1) ### Features * add -stop to stop default actions ([230bfc1](https://github.com/TaroXin/vue-pretty-logger/commit/230bfc1)) * add await statement comment compiler ([469294f](https://github.com/TaroXin/vue-pretty-logger/commit/469294f)), closes [#3](https://github.com/TaroXin/vue-pretty-logger/issues/3) * add command that control the currently displayed tag ([46dd72b](https://github.com/TaroXin/vue-pretty-logger/commit/46dd72b)) * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) * add control of the log output type ([509cea6](https://github.com/TaroXin/vue-pretty-logger/commit/509cea6)) * add function callback and lambda callback comment compiler ([d8eaa9e](https://github.com/TaroXin/vue-pretty-logger/commit/d8eaa9e)), closes [#2](https://github.com/TaroXin/vue-pretty-logger/issues/2) * add support for js files ([fe36184](https://github.com/TaroXin/vue-pretty-logger/commit/fe36184)), closes [#8](https://github.com/TaroXin/vue-pretty-logger/issues/8) * add the -count command to display the number of the function calls ([d659577](https://github.com/TaroXin/vue-pretty-logger/commit/d659577)) * add the -from command to output function call parameters ([851512e](https://github.com/TaroXin/vue-pretty-logger/commit/851512e)), closes [#5](https://github.com/TaroXin/vue-pretty-logger/issues/5) * add the -sign command to display the corresponding key value of the output value ([a3378a3](https://github.com/TaroXin/vue-pretty-logger/commit/a3378a3)) * add the -time -profile command ([ef38e85](https://github.com/TaroXin/vue-pretty-logger/commit/ef38e85)) * add the judgment of the NODE_ENV ([c61b081](https://github.com/TaroXin/vue-pretty-logger/commit/c61b081)) * add the option of the log hook ([2914afc](https://github.com/TaroXin/vue-pretty-logger/commit/2914afc)) ### BREAKING CHANGES * add support for js files * add function logger * add await statement comment compiler * add function callback and lambda callback comment compiler * add the option of the log hook * add the judgment of the NODE_ENV * add the -from command to output function call parameters * add -time -profile command * add -count command * add -sign command * add control of the log output type * add -stop command to stop default actions # 0.9.0 (2018-05-09) ### Bug Fixes * fix bug: Cannot read property 'content' of null. ([6956668](https://github.com/TaroXin/vue-pretty-logger/commit/6956668)), closes [#1](https://github.com/TaroXin/vue-pretty-logger/issues/1) ### Features * add -stop to stop default actions ([230bfc1](https://github.com/TaroXin/vue-pretty-logger/commit/230bfc1)) * add await statement comment compiler ([469294f](https://github.com/TaroXin/vue-pretty-logger/commit/469294f)), closes [#3](https://github.com/TaroXin/vue-pretty-logger/issues/3) * add command that control the currently displayed tag ([46dd72b](https://github.com/TaroXin/vue-pretty-logger/commit/46dd72b)) * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) * add control of the log output type ([509cea6](https://github.com/TaroXin/vue-pretty-logger/commit/509cea6)) * add function callback and lambda callback comment compiler ([d8eaa9e](https://github.com/TaroXin/vue-pretty-logger/commit/d8eaa9e)), closes [#2](https://github.com/TaroXin/vue-pretty-logger/issues/2) * add support for js files ([fe36184](https://github.com/TaroXin/vue-pretty-logger/commit/fe36184)), closes [#8](https://github.com/TaroXin/vue-pretty-logger/issues/8) * add the -count command to display the number of the function calls ([d659577](https://github.com/TaroXin/vue-pretty-logger/commit/d659577)) * add the -from command to output function call parameters ([851512e](https://github.com/TaroXin/vue-pretty-logger/commit/851512e)), closes [#5](https://github.com/TaroXin/vue-pretty-logger/issues/5) * add the -sign command to display the corresponding key value of the output value ([a3378a3](https://github.com/TaroXin/vue-pretty-logger/commit/a3378a3)) * add the -time -profile command ([ef38e85](https://github.com/TaroXin/vue-pretty-logger/commit/ef38e85)) * add the judgment of the NODE_ENV ([c61b081](https://github.com/TaroXin/vue-pretty-logger/commit/c61b081)) * add the option of the log hook ([2914afc](https://github.com/TaroXin/vue-pretty-logger/commit/2914afc)) ### BREAKING CHANGES * add support for js files * add function logger * add await statement comment compiler * add function callback and lambda callback comment compiler * add the option of the log hook * add the judgment of the NODE_ENV * add the -from command to output function call parameters * add -time -profile command * add -count command * add -sign command * add control of the log output type * add -stop command to stop default actions ## 0.8.9 (2018-05-09) ### Bug Fixes * fix bug: Cannot read property 'content' of null. ([6956668](https://github.com/TaroXin/vue-pretty-logger/commit/6956668)), closes [#1](https://github.com/TaroXin/vue-pretty-logger/issues/1) ### Features * add -stop to stop default actions ([230bfc1](https://github.com/TaroXin/vue-pretty-logger/commit/230bfc1)) * add await statement comment compiler ([469294f](https://github.com/TaroXin/vue-pretty-logger/commit/469294f)), closes [#3](https://github.com/TaroXin/vue-pretty-logger/issues/3) * add command that control the currently displayed tag ([46dd72b](https://github.com/TaroXin/vue-pretty-logger/commit/46dd72b)) * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) * add control of the log output type ([509cea6](https://github.com/TaroXin/vue-pretty-logger/commit/509cea6)) * add function callback and lambda callback comment compiler ([d8eaa9e](https://github.com/TaroXin/vue-pretty-logger/commit/d8eaa9e)), closes [#2](https://github.com/TaroXin/vue-pretty-logger/issues/2) * add support for js files ([fe36184](https://github.com/TaroXin/vue-pretty-logger/commit/fe36184)), closes [#8](https://github.com/TaroXin/vue-pretty-logger/issues/8) * add the -count command to display the number of the function calls ([d659577](https://github.com/TaroXin/vue-pretty-logger/commit/d659577)) * add the -from command to output function call parameters ([851512e](https://github.com/TaroXin/vue-pretty-logger/commit/851512e)), closes [#5](https://github.com/TaroXin/vue-pretty-logger/issues/5) * add the -sign command to display the corresponding key value of the output value ([a3378a3](https://github.com/TaroXin/vue-pretty-logger/commit/a3378a3)) * add the -time -profile command ([ef38e85](https://github.com/TaroXin/vue-pretty-logger/commit/ef38e85)) * add the judgment of the NODE_ENV ([c61b081](https://github.com/TaroXin/vue-pretty-logger/commit/c61b081)) * add the option of the log hook ([2914afc](https://github.com/TaroXin/vue-pretty-logger/commit/2914afc)) ### BREAKING CHANGES * add support for js files * add function logger * add await statement comment compiler * add function callback and lambda callback comment compiler * add the option of the log hook * add the judgment of the NODE_ENV * add the -from command to output function call parameters * add -time -profile command * add -count command * add -sign command * add control of the log output type * add -stop command to stop default actions ## 0.8.9 (2018-05-09) ### Bug Fixes * fix bug: Cannot read property 'content' of null. ([6956668](https://github.com/TaroXin/vue-pretty-logger/commit/6956668)), closes [#1](https://github.com/TaroXin/vue-pretty-logger/issues/1) ### Features * add -stop to stop default actions ([230bfc1](https://github.com/TaroXin/vue-pretty-logger/commit/230bfc1)) * add await statement comment compiler ([469294f](https://github.com/TaroXin/vue-pretty-logger/commit/469294f)), closes [#3](https://github.com/TaroXin/vue-pretty-logger/issues/3) * add command that control the currently displayed tag ([46dd72b](https://github.com/TaroXin/vue-pretty-logger/commit/46dd72b)) * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) * add control of the log output type ([509cea6](https://github.com/TaroXin/vue-pretty-logger/commit/509cea6)) * add function callback and lambda callback comment compiler ([d8eaa9e](https://github.com/TaroXin/vue-pretty-logger/commit/d8eaa9e)), closes [#2](https://github.com/TaroXin/vue-pretty-logger/issues/2) * add the -count command to display the number of the function calls ([d659577](https://github.com/TaroXin/vue-pretty-logger/commit/d659577)) * add the -from command to output function call parameters ([851512e](https://github.com/TaroXin/vue-pretty-logger/commit/851512e)), closes [#5](https://github.com/TaroXin/vue-pretty-logger/issues/5) * add the -sign command to display the corresponding key value of the output value ([a3378a3](https://github.com/TaroXin/vue-pretty-logger/commit/a3378a3)) * add the -time -profile command ([ef38e85](https://github.com/TaroXin/vue-pretty-logger/commit/ef38e85)) * add the judgment of the NODE_ENV ([c61b081](https://github.com/TaroXin/vue-pretty-logger/commit/c61b081)) * add the option of the log hook ([2914afc](https://github.com/TaroXin/vue-pretty-logger/commit/2914afc)) ### BREAKING CHANGES * add the -from command to output function call parameters * add function logger * add function callback and lambda callback comment compiler * add the option of the log hook * add the judgment of the NODE_ENV * add await statement comment compiler * add -time -profile command * add -count command * add -sign command * add control of the log output type * add -stop command to stop default actions ## 0.8.7 (2018-05-09) ### Bug Fixes * fix bug: Cannot read property 'content' of null. ([6956668](https://github.com/TaroXin/vue-pretty-logger/commit/6956668)), closes [#1](https://github.com/TaroXin/vue-pretty-logger/issues/1) ### Features * add -stop to stop default actions ([230bfc1](https://github.com/TaroXin/vue-pretty-logger/commit/230bfc1)) * add await statement comment compiler ([469294f](https://github.com/TaroXin/vue-pretty-logger/commit/469294f)), closes [#3](https://github.com/TaroXin/vue-pretty-logger/issues/3) * add command that control the currently displayed tag ([46dd72b](https://github.com/TaroXin/vue-pretty-logger/commit/46dd72b)) * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) * add control of the log output type ([509cea6](https://github.com/TaroXin/vue-pretty-logger/commit/509cea6)) * add function callback and lambda callback comment compiler ([d8eaa9e](https://github.com/TaroXin/vue-pretty-logger/commit/d8eaa9e)), closes [#2](https://github.com/TaroXin/vue-pretty-logger/issues/2) * add the -count command to display the number of the function calls ([d659577](https://github.com/TaroXin/vue-pretty-logger/commit/d659577)) * add the -sign command to display the corresponding key value of the output value ([a3378a3](https://github.com/TaroXin/vue-pretty-logger/commit/a3378a3)) * add the -time -profile command ([ef38e85](https://github.com/TaroXin/vue-pretty-logger/commit/ef38e85)) * add the judgment of the NODE_ENV ([c61b081](https://github.com/TaroXin/vue-pretty-logger/commit/c61b081)) * add the option of the log hook ([2914afc](https://github.com/TaroXin/vue-pretty-logger/commit/2914afc)) ### BREAKING CHANGES * add await statement comment compiler * add function callback and lambda callback comment compiler * add the option of the log hook * add the judgment of the NODE_ENV * add -stop command to stop default actions * add -time -profile command * add -count command * add -sign command * add control of the log output type * add function logger ## 0.8.7 (2018-05-08) ### Bug Fixes * fix bug: Cannot read property 'content' of null. ([6956668](https://github.com/TaroXin/vue-pretty-logger/commit/6956668)), closes [#1](https://github.com/TaroXin/vue-pretty-logger/issues/1) ### Features * add -stop to stop default actions ([230bfc1](https://github.com/TaroXin/vue-pretty-logger/commit/230bfc1)) * add await statement comment compiler ([469294f](https://github.com/TaroXin/vue-pretty-logger/commit/469294f)), closes [#3](https://github.com/TaroXin/vue-pretty-logger/issues/3) * add command that control the currently displayed tag ([46dd72b](https://github.com/TaroXin/vue-pretty-logger/commit/46dd72b)) * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) * add control of the log output type ([509cea6](https://github.com/TaroXin/vue-pretty-logger/commit/509cea6)) * add function callback and lambda callback comment compiler ([d8eaa9e](https://github.com/TaroXin/vue-pretty-logger/commit/d8eaa9e)), closes [#2](https://github.com/TaroXin/vue-pretty-logger/issues/2) * add the -count command to display the number of the function calls ([d659577](https://github.com/TaroXin/vue-pretty-logger/commit/d659577)) * add the -sign command to display the corresponding key value of the output value ([a3378a3](https://github.com/TaroXin/vue-pretty-logger/commit/a3378a3)) * add the -time -profile command ([ef38e85](https://github.com/TaroXin/vue-pretty-logger/commit/ef38e85)) * add the judgment of the NODE_ENV ([c61b081](https://github.com/TaroXin/vue-pretty-logger/commit/c61b081)) * add the option of the log hook ([2914afc](https://github.com/TaroXin/vue-pretty-logger/commit/2914afc)) ### BREAKING CHANGES * add await statement comment compiler * add function callback and lambda callback comment compiler * add the option of the log hook * add the judgment of the NODE_ENV * add -stop command to stop default actions * add -time -profile command * add -count command * add -sign command * add control of the log output type * add function logger ## 0.8.3 (2018-05-06) ### Features * add -stop to stop default actions ([230bfc1](https://github.com/TaroXin/vue-pretty-logger/commit/230bfc1)) * add command that control the currently displayed tag ([46dd72b](https://github.com/TaroXin/vue-pretty-logger/commit/46dd72b)) * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) * add control of the log output type ([509cea6](https://github.com/TaroXin/vue-pretty-logger/commit/509cea6)) * add the -count command to display the number of the function calls ([d659577](https://github.com/TaroXin/vue-pretty-logger/commit/d659577)) * add the -sign command to display the corresponding key value of the output value ([a3378a3](https://github.com/TaroXin/vue-pretty-logger/commit/a3378a3)) * add the -time -profile command ([ef38e85](https://github.com/TaroXin/vue-pretty-logger/commit/ef38e85)) * add the judgment of the NODE_ENV ([c61b081](https://github.com/TaroXin/vue-pretty-logger/commit/c61b081)) * add the option of the log hook ([2914afc](https://github.com/TaroXin/vue-pretty-logger/commit/2914afc)) ### BREAKING CHANGES * add the option of the log hook * add the judgment of the NODE_ENV * add -stop command to stop default actions * add -time -profile command * add -count command * add -sign command * add control of the log output type * add function logger # 0.8.0 (2018-05-06) ### Features * add -stop to stop default actions ([230bfc1](https://github.com/TaroXin/vue-pretty-logger/commit/230bfc1)) * add command that control the currently displayed tag ([46dd72b](https://github.com/TaroXin/vue-pretty-logger/commit/46dd72b)) * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) * add control of the log output type ([509cea6](https://github.com/TaroXin/vue-pretty-logger/commit/509cea6)) * add the -count command to display the number of the function calls ([d659577](https://github.com/TaroXin/vue-pretty-logger/commit/d659577)) * add the -sign command to display the corresponding key value of the output value ([a3378a3](https://github.com/TaroXin/vue-pretty-logger/commit/a3378a3)) * add the -time -profile command ([ef38e85](https://github.com/TaroXin/vue-pretty-logger/commit/ef38e85)) ### BREAKING CHANGES * add -stop command to stop default actions * add -time -profile command * add -count command * add -sign command * add control of the log output type * add function logger # 0.7.0 (2018-05-06) ### Features * add command that control the currently displayed tag ([46dd72b](https://github.com/TaroXin/vue-pretty-logger/commit/46dd72b)) * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) * add control of the log output type ([509cea6](https://github.com/TaroXin/vue-pretty-logger/commit/509cea6)) * add the -count command to display the number of the function calls ([d659577](https://github.com/TaroXin/vue-pretty-logger/commit/d659577)) * add the -sign command to display the corresponding key value of the output value ([a3378a3](https://github.com/TaroXin/vue-pretty-logger/commit/a3378a3)) * add the -time -profile command ([ef38e85](https://github.com/TaroXin/vue-pretty-logger/commit/ef38e85)) ### BREAKING CHANGES * add -time -profile command * add -count command * add -sign command * add control of the log output type * add function logger # 0.7.0 (2018-05-06) ### Features * add command that control the currently displayed tag ([46dd72b](https://github.com/TaroXin/vue-pretty-logger/commit/46dd72b)) * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) * add control of the log output type ([509cea6](https://github.com/TaroXin/vue-pretty-logger/commit/509cea6)) * add the -count command to display the number of the function calls ([d659577](https://github.com/TaroXin/vue-pretty-logger/commit/d659577)) * add the -sign command to display the corresponding key value of the output value ([a3378a3](https://github.com/TaroXin/vue-pretty-logger/commit/a3378a3)) * add the -time -profile command ([ef38e85](https://github.com/TaroXin/vue-pretty-logger/commit/ef38e85)) ### BREAKING CHANGES * add -time -profile command * add -count command * add -sign command * add control of the log output type * add function logger ## 0.5.2 (2018-05-06) ### Features * add command that control the currently displayed tag ([46dd72b](https://github.com/TaroXin/vue-pretty-logger/commit/46dd72b)) * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) * add control of the log output type ([509cea6](https://github.com/TaroXin/vue-pretty-logger/commit/509cea6)) * add the -sign command to display the corresponding key value of the output value ([a3378a3](https://github.com/TaroXin/vue-pretty-logger/commit/a3378a3)) ### BREAKING CHANGES * add -sign command * add control of the log output type * add function logger # 0.4.0 (2018-05-05) ### Features * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) * add control of the log output type ([509cea6](https://github.com/TaroXin/vue-pretty-logger/commit/509cea6)) ### BREAKING CHANGES * add control of the log output type * add function logger # 0.3.0 (2018-05-05) ### Features * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) * add control of the log output type ([509cea6](https://github.com/TaroXin/vue-pretty-logger/commit/509cea6)) ### BREAKING CHANGES * add control of the log output type * add function logger # 0.3.0 (2018-05-04) ### Features * add console for function declarations and call ([d6905e1](https://github.com/TaroXin/vue-pretty-logger/commit/d6905e1)) ### BREAKING CHANGES * add function logger ## 0.0.1 (2018-05-04) ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2018 杨鑫 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # vue-pretty-logger [![Scrutinizer Build](https://img.shields.io/npm/v/vue-pretty-logger.svg?style=for-the-badge)](https://www.npmjs.com/package/vue-pretty-logger) [![Scrutinizer Build](https://img.shields.io/scrutinizer/build/g/filp/whoops.svg?style=for-the-badge)](https://travis-ci.org/TaroXin/vue-pretty-logger) [![npm](https://img.shields.io/npm/l/express.svg?style=for-the-badge) ](https://opensource.org/licenses/mit-license.php) [README for Chinese](https://juejin.im/post/5aef271c51882506a36c69a7) ### Table of content * [Introduce](#introduce) * [Install](#install) * [Usage](#usage) * [Example](#example) * [Options](#options) * [Commands](#commands) * [Change Log](#changeLog) ### What is Vue pretty logger loader ? `vue-pretty-logger` is a loader for webpack, you can use it in your .vue file ``` vue ``` ### You don't know what to do? ``` javascript /** * // {#} is hook * So the result is the console prints 123. * Did you feel cool? */ let a = 123 // {#} ``` ### Install ``` javascript npm install vue-pretty-logger -D // or yarn add --dev vue-pretty-logger ``` **in your webpack config file** > **NOTE:** `vue-pretty-logger` must be executed prior to `vue-loader`, Putting it at the bottom of the list of loaders is the best choice ``` javascript ... module: { rules: [ { test: /\.vue$/, use: [ { loader: 'vue-loader' }, { loader: 'vue-pretty-logger', options: { ... } } ] } ] } ... ``` ### Usage **in your vue file** ``` vue ``` ### Example Example can be found in `example/` ### Options * **tag** `Globally specified log display tag` `default: ''` * **hook** `Globally specified log Hook` `default: '#'` * **infoTag** `Globally specified log info tag` `default: 'INFO'` * **infoTagStyle** `Globally specified log info tag style` `default: ''` * **error, debug, warn are the same as info** ### Commands * **-e** `Output as error` * **-d** `Output as debug` * **-w** `Output as warn` * **-i** `Output as info` * **-t** `Specify local log comment tag` * **-sign** `The variable name corresponding to the output value when outputting the value` * **-count** `Number of times the output function was called` `Only valid at function declaration` * **-time** `Output function execution time-consunming` `Only valid at function call` * **-profile** `Create a profile for your function` `Only valid at function call` * **-stop** `Stop default actions` ### Change Log * `V0.9.0` [issues](https://github.com/TaroXin/vue-pretty-logger/issues/8) ``` javascript // add support for js files { test: /\.js$/, use: ['babel-loader', 'vue-pretty-logger/lib/in-js'], exclude: /node_modules/ } ``` * `V0.8.8` [issues](https://github.com/TaroXin/vue-pretty-logger/issues/5) ``` javascript // add the -form command this.testFuncCall(p1, p2) // {#} -sign -from // equals: console.log(`p1: ${p1}, p2: ${p2}`) const result = this.testFuncCall(p1, p2) console.log(`result: ${result}`) ``` * `V0.8.7` [issues](https://github.com/TaroXin/vue-pretty-logger/issues/3) ``` javascript // Add support for await statements, consistent with function call await test() // {#} -e -sign -time // equals: const result = await test(); console.error(`result: ${result}`) ``` * `V0.8.6` [issues](https://github.com/TaroXin/vue-pretty-logger/issues/2) ``` javascript // Support callback function use, output callback function parameters. this.$bus.$on('gotData', (data) => { // {#} -i -sign // equals: console.info(`data: ${data}`) }) this.$bus.$on('gotData', function (data) { // {#} -i -sign // equals: console.info(`data: ${data}`) }) ``` * `V0.8.5` [issues](https://github.com/TaroXin/vue-pretty-logger/issues/1) ``` fix bug: Can not read property 'content' of null ``` ================================================ FILE: example/example.js ================================================ function Example (test) { // {#} -sign -w -t Example let a = 123 testFunc(a) // {#} -sign -i -from -time -profile testFuncCallback((val) => { // {#} -sign -d // do something }) } function testFunc (form) { return 'Return me!' } function testFuncCallback (cb) { cb && cb('Callback return me') } export default Example ================================================ FILE: example/index.html ================================================
================================================ FILE: example/main.js ================================================ import Vue from 'vue' import Foo from './source.vue' import Example from './example.js' Example('I\' a test str') new Vue({ el: '#app', render: h => h(Foo) }) ================================================ FILE: example/source.vue ================================================ ================================================ FILE: example/webpack.config.js ================================================ const path = require('path') const VueLoaderPlugin = require('vue-loader/lib/plugin.js') module.exports = { mode: 'development', entry: path.join(__dirname, './main.js'), output: { path: path.join(__dirname, 'dist'), filename: 'bundle.js', publicPath: '/dist/' }, devServer: { stats: 'minimal', contentBase: __dirname }, module: { rules: [ { test: /\.vue$/, use: [ { loader: 'vue-loader' }, { loader: path.join(__dirname, '../lib/index.js'), options: { tag: 'Pretty_Logger', hook: '#' } } ] }, { test: /\.css$/, use: ['style-loader', 'css-loader'] }, { test: /\.js$/, use: ['babel-loader', path.join(__dirname, '../lib/in-js.js')], exclude: /node_modules/ } ] }, plugins: [ new VueLoaderPlugin() ] } ================================================ FILE: index.js ================================================ const loader = require('./loader') module.exports = loader ================================================ FILE: lib/constant/logger-types.js ================================================ module.exports = { FUNCTION: 'FUNCTION', FUNCTION_CALL: 'FUNCTION_CALL', ASSIGNMENT: 'ASSIGNMENT', FUNCTION_CALLBACK: 'FUNCTION_CALLBACK' } ================================================ FILE: lib/constant/options.js ================================================ module.exports = { tag: '', dev: true, hook: '#', tagStyle: '', infoTag: 'INFO', infoTagStyle: 'color: #3838AD; font-weight: bold;', infoContentStyle: 'color: #333333, font-weight: bold;', warnTag: 'WARN', warnTagStyle: 'color: #DA9D32; font-weight: bold;', warnContentStyle: 'color: #333333, font-weight: bold;', debugTag: 'DEBUG', debugTagStyle: 'color: #22D015; font-weight: bold;', debugContentStyle: 'color: #333333, font-weight: bold;', errorTag: 'ERROR', errorTagStyle: 'color: #CD2931; font-weight: bold;', errorContentStyle: 'color: #333333, font-weight: bold;', } ================================================ FILE: lib/in-js.js ================================================ // Vue-pretty-logger-loader const loaderUtils = require('loader-utils') const compiler = require('vue-template-compiler') const loggerParser = require('./utils/logger-parser') const defaultOptions = require('./constant/options') module.exports = function (source, map) { const loaderContext = this loaderContext.cacheable && loaderContext.cacheable() const { resourcePath } = loaderContext const isJsFile = /\.js$/.test(resourcePath) // default options const options = Object.assign( defaultOptions, loaderUtils.getOptions(this) ) // script has logger note ? let isScriptHasLoggerLine = false // get scripts let scripts = '' if (isJsFile) { scripts = source } else { return source } let scriptArray = scripts.split(/\r?\n/) // parse logger scriptArray = scriptArray.map(scriptLine => { if (loggerParser.isLoggerLine(scriptLine, options)) { // is logger line isScriptHasLoggerLine = true return loggerParser.parseLogger(scriptLine, options) } else { return scriptLine } }) // do replace if (isScriptHasLoggerLine && scriptArray.length > 0) { source = scriptArray.join('\n') } return source } ================================================ FILE: lib/index.js ================================================ // Vue-pretty-logger-loader const loaderUtils = require('loader-utils') const compiler = require('vue-template-compiler') const loggerParser = require('./utils/logger-parser') const defaultOptions = require('./constant/options') module.exports = function (source, map) { this.cacheable && this.cacheable() // default options const options = Object.assign( defaultOptions, loaderUtils.getOptions(this) ) // script has logger note ? let isScriptHasLoggerLine = false // get scripts const { script } = compiler.parseComponent(source, { pad: 'line' }) if (script === null) { return source } const scripts = script.content let scriptArray = scripts.split(/\r?\n/) // parse logger scriptArray = scriptArray.map(scriptLine => { if (loggerParser.isLoggerLine(scriptLine, options)) { // is logger line isScriptHasLoggerLine = true return loggerParser.parseLogger(scriptLine, options) } else { return scriptLine } }) // do replace if (isScriptHasLoggerLine && scriptArray.length > 0) { source = source.replace( /]*?>[\s\S]*?<\/script>/i, '' ) } return source } ================================================ FILE: lib/utils/logger-note-judge.js ================================================ // logger-note-judge const loggerNoteJudge = { tagCommand: '-t', signCommand: '-sign', countCommand: '-count', timeCommand: '-time', profileCommand: '-profile', stopCommand: '-stop', fromCommand: '-from', loggerLevels: [ { name: '-e', value: 'error' }, { name: '-d', value: 'debug' }, { name: '-w', value: 'warn' }, { name: '-i', value: 'info' }, ] } loggerNoteJudge.generateNote = function(logger, options, ...consoleStrArr) { // logger => // {#} -d logger = logger.substring(`// {${options.hook}}`.length, logger.length).trim() let loggerCommands = logger.split(/\s+/) let consoleLine = '' // check -t let localTag = options.tag let tagIndex = loggerCommands.findIndex(comm => comm === loggerNoteJudge.tagCommand) if (tagIndex > -1) { localTag = loggerCommands[tagIndex + 1] } // find logger levels let currentLevel = loggerNoteJudge.loggerLevels.find(level => { for (let i = 0; i < loggerCommands.length; i++) { if (loggerCommands[i] === level.name) { // get return true } } return false }) if (currentLevel) { let levelTag = `${currentLevel.value}Tag` let levelTagStyle = `${currentLevel.value}TagStyle` consoleLine += `console.${currentLevel.value}('%c[${options[levelTag]}][${localTag}]', '${options[levelTagStyle]}', ` for (let i = 0; i < consoleStrArr.length; i++) { consoleLine += `${consoleStrArr[i]}` if (i !== consoleStrArr.length - 1) { consoleLine += ', ' } } consoleLine += `)` } else { consoleLine += `console.log(` for (let i = 0; i < consoleStrArr.length; i++) { consoleLine += `${consoleStrArr[i]}` if (i !== consoleStrArr.length - 1) { consoleLine += ', ' } } consoleLine += `)` } if (loggerCommands.indexOf(loggerNoteJudge.stopCommand) > -1) { consoleLine = '' } return consoleLine } loggerNoteJudge.hasSignCommand = function (logger, options) { logger = logger.substring(`// {${options.hook}}`.length, logger.length).trim() let loggerCommands = logger.split(/\s+/) return loggerCommands.indexOf(loggerNoteJudge.signCommand) > -1 } loggerNoteJudge.withAssignment = function (loggerType, options) { let loggerLine = '' loggerLine += loggerType.input let consoleStrArr = [] let hasSignCommand = loggerNoteJudge.hasSignCommand(loggerType.logger, options) if (hasSignCommand) { consoleStrArr.push(`'${loggerType.var}: '`) } consoleStrArr.push(loggerType.var) let generateNote = loggerNoteJudge.generateNote(loggerType.logger, options, consoleStrArr) loggerLine += '\n' + generateNote return loggerLine } loggerNoteJudge.withFunction = function (loggerType, options) { let loggerLine = '' loggerLine += loggerType.input let consoleStrArr = [] let hasSignCommand = loggerNoteJudge.hasSignCommand(loggerType.logger, options) for (let i = 0; i < loggerType.var.length; i++) { if (hasSignCommand) { consoleStrArr.push(`'${loggerType.var[i]}: '`) } consoleStrArr.push(`${loggerType.var[i]}`) } if (loggerType.var.length > 0) { loggerLine += `\n` + loggerNoteJudge.generateNote(loggerType.logger, options, consoleStrArr) } // check -count let logger = loggerType.logger.substring(`// {${options.hook}}`.length, loggerType.logger.length).trim() let loggerCommands = logger.split(/\s+/) if (loggerCommands.indexOf(loggerNoteJudge.countCommand) > -1) { // has -count loggerLine += `\nconsole.count('${loggerType.functionName}')` } return loggerLine } loggerNoteJudge.withFunctionCall = function (loggerType, options) { let loggerLine = '' // check -time -profile -from let logger = loggerType.logger.substring(`// {${options.hook}}`.length, loggerType.logger.length).trim() let loggerCommands = logger.split(/\s+/) let hasTimeCommand = false let hasProfileCommand = false let hasFromCommand = false if (loggerCommands.indexOf(loggerNoteJudge.timeCommand) > -1) { hasTimeCommand = true } if (loggerCommands.indexOf(loggerNoteJudge.profileCommand) > -1) { hasProfileCommand = true } if (loggerCommands.indexOf(loggerNoteJudge.fromCommand) > -1) { hasFromCommand = true } if (hasProfileCommand) { loggerLine += `console.profile('${loggerType.functionName}')` } if (hasTimeCommand) { loggerLine += `\nconsole.time('${loggerType.functionName}')` } // check -from let consoleStrArr = [] if (hasFromCommand) { let hasSignCommand = loggerNoteJudge.hasSignCommand(loggerType.logger, options) for (let i = 0; i < loggerType.var.length; i++) { if (hasSignCommand) { consoleStrArr.push(`'${loggerType.var[i]}: '`) } consoleStrArr.push(`${loggerType.var[i]}`) } if (loggerType.var.length > 0) { loggerLine += `\n` + loggerNoteJudge.generateNote(loggerType.logger, options, consoleStrArr) } } // check -form end let resultName = 'result_' + Math.floor(Math.random() * 100000000) loggerLine += `\nconst ${resultName} = ${loggerType.input}` if (hasTimeCommand) { loggerLine += `\nconsole.timeEnd('${loggerType.functionName}')` } if (hasProfileCommand) { loggerLine += `\nconsole.profileEnd('${loggerType.functionName}')` } consoleStrArr = [] if (loggerNoteJudge.hasSignCommand(loggerType.logger, options)) { consoleStrArr.push(`'result: '`) } consoleStrArr.push(resultName) loggerLine += `\n` + loggerNoteJudge.generateNote(loggerType.logger, options, consoleStrArr) return loggerLine } loggerNoteJudge.withFunctionCallback = function (loggerType, options) { let loggerLine = '' loggerLine += loggerType.input let consoleStrArr = [] let hasSignCommand = loggerNoteJudge.hasSignCommand(loggerType.logger, options) for (let i = 0; i < loggerType.var.length; i++) { if (hasSignCommand) { consoleStrArr.push(`'${loggerType.var[i]}: '`) } consoleStrArr.push(`${loggerType.var[i]}`) } if (loggerType.var.length > 0) { loggerLine += `\n` + loggerNoteJudge.generateNote(loggerType.logger, options, consoleStrArr) } return loggerLine } module.exports = loggerNoteJudge ================================================ FILE: lib/utils/logger-parser.js ================================================ // logger-parser const typeJudge = require('./logger-type-judge') const noteJudge = require('./logger-note-judge') const loggerTypes = require('../constant/logger-types') const isDevelopment = process.env.NODE_ENV ? (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') : true const loggerParser = { constant: { LOGGER_REG: /\/\/[^\n]*/ } } loggerParser.isLoggerLine = function (line, options) { return line.indexOf(`// {${options.hook}}`) > -1 } loggerParser.getLoggerNote = function (loggerLine, options) { const result = {} try { let contentArr = loggerParser.constant.LOGGER_REG.exec(loggerLine) result.logger = contentArr ? contentArr[0] : '' if (result.logger.indexOf(`// {${options.hook}}`) > -1) { result.input = contentArr.input result.index = contentArr.index return result } else { return loggerLine } } catch (error) { console.error('pretty-logger:', error) return loggerLine } } loggerParser.parseLogger = function (loggerLine, options) { // replace the current line with the options // get logger note const result = loggerParser.getLoggerNote(loggerLine, options) // judge the type of line that has logger const loggerType = typeJudge(result.logger, result.input, result.index) || {type: ''} if (!isDevelopment) { return loggerType.input } switch (loggerType.type) { case loggerTypes.ASSIGNMENT: loggerLine = noteJudge.withAssignment(loggerType, options) break case loggerTypes.FUNCTION: loggerLine = noteJudge.withFunction(loggerType, options) break case loggerTypes.FUNCTION_CALL: loggerLine = noteJudge.withFunctionCall(loggerType, options) break case loggerTypes.FUNCTION_CALLBACK: loggerLine = noteJudge.withFunctionCallback(loggerType, options) default: break } return loggerLine } module.exports = loggerParser ================================================ FILE: lib/utils/logger-type-judge.js ================================================ const loggerTypes = require('../constant/logger-types') const assignmentTag = ['let', 'const', 'var'] module.exports = (logger, input, index) => { // whether it is an assignment line input = input.substring(0, index).trim() const result = { logger: logger, input: input, var: '', type: '', functionName: '' } // Assignment statement let assignmentVar = '' assignmentTag.forEach(tag => { if (input.indexOf(tag) > -1 && input.indexOf('=') > -1) { assignmentVar = input.substring( input.indexOf(tag) + tag.length, input.indexOf('=') ).trim() } }) if (assignmentVar) { result.type = loggerTypes.ASSIGNMENT result.var = assignmentVar return result } // judge like this: a = 123 if (input.indexOf('=') > -1 && input.indexOf('=>') === -1) { let splitArrayWithEqualSign = input.split('=') // result: "a = 1" => ["a","1"] if (splitArrayWithEqualSign.length === 2) { result.type = loggerTypes.ASSIGNMENT result.var = splitArrayWithEqualSign[0].trim() return result } } // Function declaration: function test (p1, p2, p3) { // {#} // avoid: let a = 'test(p1, p2) { //{#}' const isFuncReg = /^(function)?\s*[a-zA-Z0-9_$]+\s*\(.*\)\s*{$/ if (isFuncReg.test(input)) { let startIndex = 0 if (input.indexOf('function') > -1) { startIndex = 'function'.length + 1 } let endIndex = input.indexOf('(') let functionName = input.substring(startIndex, endIndex).trim() let paramsString = input.match(/\(.+\)/) if (paramsString) { paramsString = paramsString[0] paramsString = paramsString.substring(1, paramsString.length - 1) if (paramsString.trim()) { result.type = loggerTypes.FUNCTION result.var = paramsString.split(',') result.functionName = functionName return result } } else { result.type = loggerTypes.FUNCTION result.var = [] result.functionName = functionName return result } } // Function call: this.test() // {#} const isFuncCallReg = /^[\.a-zA-Z0-9_$]+\(.*\);?$/ if (isFuncCallReg.test(input) || input.indexOf('await') === 0) { let startIndex = 0 if (input.indexOf('.') > -1) { startIndex = input.indexOf('.') + 1 } let endIndex = input.indexOf('(') if (input.indexOf('await') === 0) { startIndex = 'await'.length + 1 let awaitFuncEnd = input.indexOf('(') endIndex = awaitFuncEnd === -1 ? -1 : awaitFuncEnd } let functionName if (endIndex === -1) { functionName = 'await statement' } else { functionName = input.substring(startIndex, endIndex).trim() } startIndex = input.lastIndexOf('(') + 1 endIndex = input.lastIndexOf(')') let paramsString = input.substring(startIndex, endIndex).trim() if (paramsString) { result.var = paramsString.split(',') } else { result.var = [] } result.type = loggerTypes.FUNCTION_CALL result.functionName = functionName return result } // Function callback: this.test(() => { // {#} const isFuncCallbackReg = /^[\.a-zA-Z0-9_$]+\(.*(function)?\(.*\)\s*(=>)?\s*{$/ if (isFuncCallbackReg.test(input)) { let startIndex = 0 if (input.indexOf('.') > -1) { startIndex = input.indexOf('.') + 1 } let endIndex = input.indexOf('(') let functionName = input.substring(startIndex, endIndex).trim() startIndex = input.lastIndexOf('(') endIndex = input.lastIndexOf(')') let paramsString = input.substring(startIndex + 1, endIndex).trim() result.type = loggerTypes.FUNCTION_CALLBACK result.functionName = functionName if (paramsString) { result.var = paramsString.split(',') } else { result.var = [] } return result } return null } ================================================ FILE: package.json ================================================ { "name": "vue-pretty-logger", "version": "0.9.0", "author": "YangXin", "description": "Pretty logger for Vue", "keywords": [ "logger", "vue-pretty-logger", "pretty-logger", "pretty", "pretty-logger-loader", "logger-loader" ], "main": "lib/index.js", "scripts": { "test": "jest", "dev": "webpack-dev-server --config example/webpack.config.js --inline --hot", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "pregit": "yarn test && yarn changelog", "git": "git add . && git cz", "postgit": "git push origin master && yarn publish" }, "repository": { "type": "git", "url": "https://github.com/TaroXin/vue-pretty-logger.git" }, "bugs": { "url": "https://github.com/TaroXin/vue-pretty-logger/issues" }, "homepage": "https://github.com/TaroXin/vue-pretty-logger", "license": "MIT", "peerDependencies": { "loader-utils": "^1.1.0", "vue-template-compiler": "^2.5.16" }, "devDependencies": { "babel-core": "^6.26.3", "babel-loader": "^7.1.4", "babel-plugin-transform-runtime": "^6.23.0", "babel-preset-env": "^1.6.1", "css-loader": "^0.28.11", "cz-conventional-changelog": "^2.1.0", "jest": "^22.4.3", "style-loader": "^0.21.0", "vue": "^2.5.16", "vue-loader": "^15.0.7", "vue-template-compiler": "^2.5.16", "webpack": "^4.7.0", "webpack-cli": "^2.1.2", "webpack-dev-server": "^3.1.4" }, "config": { "commitizen": { "path": "./node_modules/cz-conventional-changelog" } } } ================================================ FILE: test/loader-type-judge.test.js ================================================ const loggerTypeJudge = require('../lib/utils/logger-type-judge') test('test loggerTypeJudge assignment', () => { const input = { logger: '// {#}', input: 'let a = 0 // {#}', index: 10 } const output = { logger: '// {#}', input: 'let a = 0', var: 'a', type: 'ASSIGNMENT', functionName: '' } expect(JSON.stringify(loggerTypeJudge(input.logger, input.input, input.index))).toBe(JSON.stringify(output)) }) test('test loggerTypeJudge function', () => { const input = { logger: '// {#}', input: 'test (a, b) { // {#}', index: 14 } const output = { logger: '// {#}', input: 'test (a, b) {', var: ['a', ' b'], type: 'FUNCTION', functionName: 'test' } expect(JSON.stringify(loggerTypeJudge(input.logger, input.input, input.index))).toBe(JSON.stringify(output)) }) test('test loggerTypeJudge function call', () => { const input = { logger: '// {#}', input: 'this.test(p1, p2) // {#}', index: 18 } const output = { logger: '// {#}', input: 'this.test(p1, p2)', var: ['p1', ' p2'], type: 'FUNCTION_CALL', functionName: 'test' } expect(JSON.stringify(loggerTypeJudge(input.logger, input.input, input.index))).toBe(JSON.stringify(output)) }) test('test loggerTypeJudge function call with await', () => { const input = { logger: '// {#}', input: 'await test() // {#}', index: 13 } const output = { logger: '// {#}', input: 'await test()', var: [], type: 'FUNCTION_CALL', functionName: 'test' } expect(JSON.stringify(loggerTypeJudge(input.logger, input.input, input.index))).toBe(JSON.stringify(output)) }) test('test loggerTypeJudge function callback', () => { const input = { logger: '// {#}', input: 'this.test("test", (result) => { // {#}', index: 32 } const output = { logger: '// {#}', input: 'this.test("test", (result) => {', var: ['result'], type: 'FUNCTION_CALLBACK', functionName: 'test' } expect(JSON.stringify(loggerTypeJudge(input.logger, input.input, input.index))).toBe(JSON.stringify(output)) }) ================================================ FILE: test/logger-parser.test.js ================================================ const loggerParser = require('../lib/utils/logger-parser') test('test parse logger with normal', () => { let test = 'let a = 0 // {#}' let testResult = 'let a = 0\nconsole.log(a)' expect(loggerParser.parseLogger(test, {hook: '#'})).toBe(testResult) }) test('test function declaration', () => { let test = 'test () { // {#}' let testResult = 'test () {' expect(loggerParser.parseLogger(test, {hook: '#'})).toBe(testResult) }) test('test function declaration with params', () => { let test = 'test (a, b) { // {#}' let testResult = 'test (a, b) {\nconsole.log(a, b)' expect(loggerParser.parseLogger(test, {hook: '#'})).toBe(testResult) })