From c128c720c2c92760e753d1941f453fcb0fd59c6f Mon Sep 17 00:00:00 2001 From: Technote Date: Wed, 7 Oct 2020 19:11:47 +0900 Subject: [PATCH 1/3] chore: update packages --- package.json | 5 +++-- yarn.lock | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 7f7fb58..3f22f4b 100644 --- a/package.json +++ b/package.json @@ -26,12 +26,13 @@ "dist" ], "dependencies": { - "@actions/core": "^1.2.6" + "@actions/core": "^1.2.6", + "sprintf-js": "^1.1.2" }, "devDependencies": { "@commitlint/cli": "^11.0.0", "@commitlint/config-conventional": "^11.0.0", - "@technote-space/github-action-test-helper": "^0.6.0", + "@technote-space/github-action-test-helper": "^0.6.1", "@types/jest": "^26.0.14", "@types/node": "^14.11.5", "@typescript-eslint/eslint-plugin": "^4.4.0", diff --git a/yarn.lock b/yarn.lock index 14be30b..b6acadc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -766,10 +766,10 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@technote-space/github-action-test-helper@^0.6.0": - version "0.6.0" - resolved "https://registry.yarnpkg.com/@technote-space/github-action-test-helper/-/github-action-test-helper-0.6.0.tgz#ff058a3f1467d4ea63b17c01583c6a22906392c8" - integrity sha512-n4YdEmhHvondmffqArdMsNB3iQE0f/GGOoHdT3phaar9vuNl87tYynioiN7W/YLEv/+VDHbtiCnsjNILgN+bKw== +"@technote-space/github-action-test-helper@^0.6.1": + version "0.6.1" + resolved "https://registry.yarnpkg.com/@technote-space/github-action-test-helper/-/github-action-test-helper-0.6.1.tgz#a0fc8a4278145ffaf0561fc87315e81365aa9354" + integrity sha512-EzirRTpYWVKnGOA0fZe73oGt6Fwr+DT0tovx9QlHP4Mxx9xfEOrS0OENeOlz7vyP4NyP9j9OdBvkFtsPvRoIPQ== dependencies: "@actions/core" "^1.2.6" "@actions/github" "^4.0.0" @@ -4485,6 +4485,11 @@ split2@^2.0.0: dependencies: through2 "^2.0.2" +sprintf-js@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.1.2.tgz#da1765262bf8c0f571749f2ad6c26300207ae673" + integrity sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug== + sprintf-js@~1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" From 46fb07f7a710dfaf47ac95821ada3b53fb738f00 Mon Sep 17 00:00:00 2001 From: Technote Date: Wed, 7 Oct 2020 19:12:32 +0900 Subject: [PATCH 2/3] fix: consider attribute setting is not set (#7) --- __tests__/logger.test.ts | 9 +++++---- src/logger.ts | 11 ++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/__tests__/logger.test.ts b/__tests__/logger.test.ts index 13700e8..c6eed95 100644 --- a/__tests__/logger.test.ts +++ b/__tests__/logger.test.ts @@ -124,10 +124,11 @@ describe('Logger', () => { backColor: 'red', attribute: 'bold', })).toBe('\x1b[34;41;1mHello World!!!\x1b[0m'); - expect(logger.getColorString('Hello World!!!')).toBe('\x1b[37;40;0mHello World!!!\x1b[0m'); - expect(logger.getColorString('Hello World!!!', {color: 'green'})).toBe('\x1b[32;40;0mHello World!!!\x1b[0m'); - expect(logger.c('Hello World!!!')).toBe('\x1b[37;40;0mHello World!!!\x1b[0m'); - expect(logger.c('Hello World!!!', {color: 'green'})).toBe('\x1b[32;40;0mHello World!!!\x1b[0m'); + expect(logger.getColorString('Hello World!!!')).toBe('\x1b[37;40mHello World!!!\x1b[0m'); + expect(logger.getColorString('Hello World!!!', {color: 'green'})).toBe('\x1b[32;40mHello World!!!\x1b[0m'); + expect(logger.getColorString('Hello World!!!', {color: 'green', attribute: 'italic'})).toBe('\x1b[32;40;3mHello World!!!\x1b[0m'); + expect(logger.c('Hello World!!!')).toBe('\x1b[37;40mHello World!!!\x1b[0m'); + expect(logger.c('Hello World!!!', {color: 'green'})).toBe('\x1b[32;40mHello World!!!\x1b[0m'); expect(logger.c('Hello World!!!', { color: 'yellow', attribute: 'underline', diff --git a/src/logger.ts b/src/logger.ts index c810aa1..59606ac 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -166,7 +166,16 @@ export default class Logger { * @param {Setting|undefined} setting setting * @return {string} color string */ - public getColorString = (string: string, setting?: Setting): string => sprintf('\x1b[3%d;4%d;%dm%s\x1b[0m', COLOR_MAP[setting?.color ?? 'white'], COLOR_MAP[setting?.backColor ?? 'black'], ATTRIBUTE_MAP[setting?.attribute ?? 'none'], string); + public getColorString = (string: string, setting?: Setting): string => { + const color = setting?.color ?? 'white'; + const backColor = setting?.backColor ?? 'black'; + const attribute = setting?.attribute ?? 'none'; + if (attribute !== 'none') { + return sprintf('\x1b[3%d;4%d;%dm%s\x1b[0m', COLOR_MAP[color], COLOR_MAP[backColor], ATTRIBUTE_MAP[attribute], string); + } + + return sprintf('\x1b[3%d;4%dm%s\x1b[0m', COLOR_MAP[color], COLOR_MAP[backColor], string); + }; /** * @param {string} string string From 0d7ee189324b0f21feda437d3317152acc8f37cc Mon Sep 17 00:00:00 2001 From: Technote Date: Wed, 7 Oct 2020 19:15:33 +0900 Subject: [PATCH 3/3] feat: update package version --- package.json | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 3f22f4b..65fc1f2 100644 --- a/package.json +++ b/package.json @@ -1,30 +1,38 @@ { "name": "@technote-space/github-action-log-helper", - "version": "0.1.2", + "version": "0.1.3", "description": "Logging helpers for GitHub Actions.", - "author": { - "name": "Technote", - "email": "technote.space@gmail.com", - "url": "https://technote.space" - }, - "license": "MIT", "keywords": [ "github", "github actions" ], "homepage": "https://github.com/technote-space/github-action-log-helper", + "bugs": { + "url": "https://github.com/technote-space/github-action-log-helper/issues" + }, "repository": { "type": "git", "url": "https://github.com/technote-space/github-action-log-helper.git" }, - "bugs": { - "url": "https://github.com/technote-space/github-action-log-helper/issues" + "license": "MIT", + "author": { + "name": "Technote", + "email": "technote.space@gmail.com", + "url": "https://technote.space" }, "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ "dist" ], + "scripts": { + "build": "tsc", + "cover": "jest --coverage", + "lint": "eslint 'src/**/*.ts' '__tests__/**/*.ts' --cache", + "lint:fix": "eslint --fix 'src/**/*.ts' '__tests__/**/*.ts'", + "test": "yarn lint && yarn cover", + "update": "npx npm-check-updates -u && yarn install && yarn upgrade && yarn audit" + }, "dependencies": { "@actions/core": "^1.2.6", "sprintf-js": "^1.1.2" @@ -47,13 +55,5 @@ }, "publishConfig": { "access": "public" - }, - "scripts": { - "build": "tsc", - "test": "yarn lint && yarn cover", - "lint": "eslint 'src/**/*.ts' '__tests__/**/*.ts' --cache", - "lint:fix": "eslint --fix 'src/**/*.ts' '__tests__/**/*.ts'", - "cover": "jest --coverage", - "update": "npx npm-check-updates -u && yarn install && yarn upgrade && yarn audit" } }