Skip to content

Commit

Permalink
feat: add the -from command to output function call parameters
Browse files Browse the repository at this point in the history
BREAKING CHANGE: add the -from command to output function call parameters

re #5
  • Loading branch information
TaroXin committed May 9, 2018
1 parent ed84243 commit 851512e
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 19 deletions.
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
<a name="0.8.7"></a>
## 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



<a name="0.8.7"></a>
## 0.8.7 (2018-05-08)

Expand Down
13 changes: 9 additions & 4 deletions example/source.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,15 @@
// })
// this.testAsync()
this.testFunc("p1", "p2")
// this.testFunc("p1", "p2")
this.testForm("hello", "world") // {#} -from -sign
},
methods: {
testForm (p1, p2) { // {#} -sign
},
testFunc1 (testStr) { // {#} -e
// console.log(testStr)
},
Expand Down Expand Up @@ -118,9 +123,9 @@
}
},
testAsync () {
async function test () {
await test2() // {#} -time -profile
async testAsync (p) { // {#} -sign
async function test () {
await test2()
}
function test2 () {
Expand Down
29 changes: 27 additions & 2 deletions lib/utils/logger-note-judge.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const loggerNoteJudge = {
timeCommand: '-time',
profileCommand: '-profile',
stopCommand: '-stop',
fromCommand: '-from',
loggerLevels: [
{
name: '-e',
Expand Down Expand Up @@ -134,11 +135,13 @@ loggerNoteJudge.withFunction = function (loggerType, options) {
loggerNoteJudge.withFunctionCall = function (loggerType, options) {
let loggerLine = ''

// check -time -profile
// 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
}
Expand All @@ -147,6 +150,10 @@ loggerNoteJudge.withFunctionCall = function (loggerType, options) {
hasProfileCommand = true
}

if (loggerCommands.indexOf(loggerNoteJudge.fromCommand) > -1) {
hasFromCommand = true
}

if (hasProfileCommand) {
loggerLine += `console.profile('${loggerType.functionName}')`
}
Expand All @@ -155,6 +162,24 @@ loggerNoteJudge.withFunctionCall = function (loggerType, options) {
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}`

Expand All @@ -167,7 +192,7 @@ loggerNoteJudge.withFunctionCall = function (loggerType, options) {
}


let consoleStrArr = []
consoleStrArr = []
if (loggerNoteJudge.hasSignCommand(loggerType.logger, options)) {
consoleStrArr.push(`'result: '`)
}
Expand Down
9 changes: 9 additions & 0 deletions lib/utils/logger-type-judge.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ module.exports = (logger, input, index) => {
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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"pregit": "yarn test && yarn changelog",
"git": "git add . && git cz",
"postgit": "git push origin master"
"postgit": "git push origin master && yarn publish"
},
"repository": {
"type": "git",
Expand Down
24 changes: 12 additions & 12 deletions test/loader-type-judge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ test('test loggerTypeJudge assignment', () => {
index: 10
}

const ouput = {
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(ouput))
expect(JSON.stringify(loggerTypeJudge(input.logger, input.input, input.index))).toBe(JSON.stringify(output))
})

test('test loggerTypeJudge function', () => {
Expand All @@ -25,15 +25,15 @@ test('test loggerTypeJudge function', () => {
index: 14
}

const ouput = {
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(ouput))
expect(JSON.stringify(loggerTypeJudge(input.logger, input.input, input.index))).toBe(JSON.stringify(output))
})

test('test loggerTypeJudge function call', () => {
Expand All @@ -43,15 +43,15 @@ test('test loggerTypeJudge function call', () => {
index: 18
}

const ouput = {
const output = {
logger: '// {#}',
input: 'this.test(p1, p2)',
var: '',
var: ['p1', ' p2'],
type: 'FUNCTION_CALL',
functionName: 'test'
}

expect(JSON.stringify(loggerTypeJudge(input.logger, input.input, input.index))).toBe(JSON.stringify(ouput))
expect(JSON.stringify(loggerTypeJudge(input.logger, input.input, input.index))).toBe(JSON.stringify(output))
})

test('test loggerTypeJudge function call with await', () => {
Expand All @@ -61,15 +61,15 @@ test('test loggerTypeJudge function call with await', () => {
index: 13
}

const ouput = {
const output = {
logger: '// {#}',
input: 'await test()',
var: '',
var: [],
type: 'FUNCTION_CALL',
functionName: 'test'
}

expect(JSON.stringify(loggerTypeJudge(input.logger, input.input, input.index))).toBe(JSON.stringify(ouput))
expect(JSON.stringify(loggerTypeJudge(input.logger, input.input, input.index))).toBe(JSON.stringify(output))
})

test('test loggerTypeJudge function callback', () => {
Expand All @@ -79,13 +79,13 @@ test('test loggerTypeJudge function callback', () => {
index: 32
}

const ouput = {
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(ouput))
expect(JSON.stringify(loggerTypeJudge(input.logger, input.input, input.index))).toBe(JSON.stringify(output))
})

0 comments on commit 851512e

Please sign in to comment.