Skip to content

Commit

Permalink
Require Node.js 18
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jul 26, 2024
1 parent 73067e7 commit 046bf94
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 34 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 22
- 20
- 18
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
37 changes: 20 additions & 17 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env node
import process from 'node:process';
import meow from 'meow';
import getStdin from 'get-stdin';
import terminalImage from 'terminal-image';
import fileType from 'file-type';
import {fileTypeFromFile, fileTypeFromBuffer} from 'file-type';

const cli = meow(`
Usage
Expand All @@ -12,7 +13,9 @@ const cli = meow(`
Examples
$ image unicorn.jpg
$ cat unicorn.jpg | image
`);
`, {
importMeta: import.meta,
});

const [input] = cli.input;

Expand All @@ -21,21 +24,21 @@ if (!input && process.stdin.isTTY) {
process.exit(1);
}

(async () => {
if (input) {
// TODO: Make it `if ((await fileType.fromFile(input))?.ext === 'gif') {` when targeting Node.js 14.
if ((await fileType.fromFile(input)).ext === 'gif') {
terminalImage.gifFile(input);
} else {
console.log(await terminalImage.file(input));
}
if (input) {
const {ext} = await fileTypeFromFile(input);

if (ext === 'gif') {
terminalImage.gifFile(input);
} else {
const stdin = await getStdin.buffer();
console.log(await terminalImage.file(input));
}
} else {
const stdin = await getStdin.buffer();
const {ext} = await fileTypeFromBuffer(stdin);

if ((await fileType.fromBuffer(stdin)).ext === 'gif') {
terminalImage.gifBuffer(stdin);
} else {
console.log(await terminalImage.buffer(stdin));
}
if (ext === 'gif') {
terminalImage.gifBuffer(stdin);
} else {
console.log(await terminalImage.buffer(stdin));
}
})();
}
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"image": "./cli.js"
},
"engines": {
"node": ">=12"
"node": ">=18"
},
"scripts": {
"test": "xo && FORCE_COLOR=1 ava"
Expand All @@ -38,15 +38,15 @@
"animation"
],
"dependencies": {
"file-type": "^16.3.0",
"file-type": "^19.3.0",
"get-stdin": "^9.0.0",
"meow": "^9.0.0",
"terminal-image": "^2.0.0"
"meow": "^13.2.0",
"terminal-image": "^3.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
"execa": "^5.0.0",
"has-ansi": "^5.0.0",
"xo": "^0.39.1"
"ava": "^6.1.3",
"execa": "^9.3.0",
"has-ansi": "^6.0.0",
"xo": "^0.59.2"
}
}
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Works in any terminal that supports colors. Supports animated GIFs.

## Install

```
$ npm install --global terminal-image-cli
```sh
npm install --global terminal-image-cli
```

## Usage
Expand All @@ -30,5 +30,5 @@ $ image --help

## Related

- [terminal-image](https://github.com/sindresorhus/terminal-image) - API for this module
- [terminal-image](https://github.com/sindresorhus/terminal-image) - API for this package
- [terminal-link-cli](https://github.com/sindresorhus/terminal-link-cli) - Create clickable links in the terminal
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import execa from 'execa';
import {execa} from 'execa';
import hasAnsi from 'has-ansi';

test('main', async t => {
Expand Down

0 comments on commit 046bf94

Please sign in to comment.