Skip to content

Commit

Permalink
Remove colors dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
johansatge committed Jan 10, 2022
1 parent e44d680 commit 4c6fee2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"cli"
],
"dependencies": {
"colors": "^1.4.0",
"glob": "^7.2.0",
"jpeg-js": "^0.4.3",
"piexifjs": "^1.0.6",
Expand Down
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ Bug reports and feature requests are welcome! More details in the [contribution
* [piexifjs](https://github.com/hMatoba/piexifjs)
* [jpeg-js](https://github.com/eugeneware/jpeg-js)
* [exif-orientation-examples](https://github.com/recurser/exif-orientation-examples)
* [colors](https://github.com/Marak/colors.js)
* [yargs](https://github.com/bcoe/yargs)
* [FontAwesome](http://fontawesome.io/)
* [Chai](http://chaijs.com/)
Expand Down
10 changes: 5 additions & 5 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node

const yargsParser = require('yargs-parser')
const colors = require('colors')
const fsp = require('fs').promises
const glob = require('glob')
const jo = require('./main.js')
const cliStyle = require('./clistyle.js')
const manifest = require('../package.json')
const promisify = require('util').promisify

Expand All @@ -23,10 +23,10 @@ if (argv.help || argv._.length === 0) {
'',
'Rotate JPEG images based on EXIF orientation',
'',
colors.underline('Usage'),
cliStyle.underline('Usage'),
'jpeg-autorotate <path>',
'',
colors.underline('Options'),
cliStyle.underline('Options'),
'--quality=<1-100> JPEG output quality',
'--jpegjsMaxResolutionInMP=<num> jpeg-js maxResolutionInMP option',
'--jpegjsMaxMemoryUsageInMB=<num> jpeg-js maxMemoryUsageInMB option',
Expand All @@ -52,10 +52,10 @@ if (argv.help || argv._.length === 0) {
await fsp.writeFile(filePath, buffer)
const readableDimensions = `${dimensions.width}x${dimensions.height}`
const message = `Processed (Orientation: ${orientation}) (Quality: ${quality}%) (Dimensions: ${readableDimensions})`
console.log(`${filePath}: ${colors.green(message)}`)
console.log(`${filePath}: ${cliStyle.green(message)}`)
} catch (error) {
const isFatal = error.code !== jo.errors.correct_orientation
console.log(`${filePath}: ${isFatal ? colors.red(error.message) : colors.yellow(error.message)}`)
console.log(`${filePath}: ${isFatal ? cliStyle.red(error.message) : cliStyle.yellow(error.message)}`)
}
}
})()
29 changes: 29 additions & 0 deletions src/clistyle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
// Styles
// bold: (string) => applyCliStyle(string, '\x1b[1m'),
underline: (string) => applyCliStyle(string, '\x1b[4m'),
// inverse: (string) => applyCliStyle(string, '\x1b[7m'),
// Colors (text)
// black: (string) => applyCliStyle(string, '\x1b[30m'),
red: (string) => applyCliStyle(string, '\x1b[31m'),
green: (string) => applyCliStyle(string, '\x1b[32m'),
yellow: (string) => applyCliStyle(string, '\x1b[33m'),
// blue: (string) => applyCliStyle(string, '\x1b[34m'),
// magenta: (string) => applyCliStyle(string, '\x1b[35m'),
// cyan: (string) => applyCliStyle(string, '\x1b[36m'),
// white: (string) => applyCliStyle(string, '\x1b[37m'),
// Colors (background)
// blackBg: (string) => applyCliStyle(string, '\x1b[40m'),
// redBg: (string) => applyCliStyle(string, '\x1b[41m'),
// greenBg: (string) => applyCliStyle(string, '\x1b[42m'),
// yellowBg: (string) => applyCliStyle(string, '\x1b[43m'),
// blueBg: (string) => applyCliStyle(string, '\x1b[44m'),
// magentaBg: (string) => applyCliStyle(string, '\x1b[45m'),
// cyanBg: (string) => applyCliStyle(string, '\x1b[46m'),
// whiteBg: (string) => applyCliStyle(string, '\x1b[47m'),
}

function applyCliStyle(string, styleTag) {
const resetTag = '\x1b[0m'
return `${styleTag}${string}${resetTag}`
}

0 comments on commit 4c6fee2

Please sign in to comment.