Skip to content

Commit

Permalink
Require Node.js 14 and upgrade dependencies
Browse files Browse the repository at this point in the history
Fixes #18
Fixes #16
  • Loading branch information
sindresorhus committed Jun 15, 2021
1 parent 660a80f commit bf6110c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
3 changes: 0 additions & 3 deletions .github/funding.yml

This file was deleted.

4 changes: 2 additions & 2 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
- 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
37 changes: 22 additions & 15 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const open = require('open');
const getStdin = require('get-stdin');
const tempy = require('tempy');
const fileType = require('file-type');
import meow from 'meow';
import open from 'open';
import getStdin from 'get-stdin';
import tempy from 'tempy';
import FileType from 'file-type';

// eslint-disable-next-line unicorn/string-content
const cli = meow(`
Usage
$ open-cli <file|url> [--wait] [--background] [-- <app> [args]]
Expand All @@ -15,7 +13,7 @@ const cli = meow(`
Options
--wait Wait for the app to exit
--background Do not bring the app to the foreground (macOS only)
--extension File extension for when stdin file type can't be detected
--extension File extension for when stdin file type cannot be detected
Examples
$ open-cli https://sindresorhus.com
Expand All @@ -25,6 +23,7 @@ const cli = meow(`
$ cat unicorn.png | open-cli
$ echo '<h1>Unicorns!</h1>' | open-cli --extension=html
`, {
importMeta: import.meta,
flags: {
wait: {
type: 'boolean',
Expand All @@ -40,22 +39,30 @@ const cli = meow(`
}
});

cli.flags.app = cli.input.slice(1);

const input = cli.input[0];
const options = cli.flags;

if (!input && process.stdin.isTTY) {
console.error('Specify a filepath or URL');
console.error('Specify a file path or URL');
process.exit(1);
}

const [, appName, appArguments] = cli.input;
if (appName) {
options.app = {
name: appName,
arguments: appArguments
};
}

(async () => {
if (input) {
await open(input, cli.flags);
await open(input, options);
} else {
const stdin = await getStdin.buffer();
const type = fileType.fromBuffer(stdin);
const extension = cli.flags.extension || (type && type.ext) || 'txt';
await open(await tempy.write(stdin, {extension}), cli.flags);
const type = await FileType.fromBuffer(stdin);
const extension = cli.flags.extension ?? type?.ext ?? 'txt';
const filePath = await tempy.write(stdin, {extension});
await open(filePath, options);
}
})();
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
"description": "Open stuff like URLs, files, executables. Cross-platform.",
"license": "MIT",
"repository": "sindresorhus/open-cli",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"bin": {
"open-cli": "cli.js"
},
"engines": {
"node": ">=10"
"node": ">=14.13"
},
"scripts": {
"test": "xo && ava"
Expand Down Expand Up @@ -49,15 +51,15 @@
"file"
],
"dependencies": {
"file-type": "^14.1.4",
"get-stdin": "^7.0.0",
"meow": "^6.1.0",
"open": "^7.0.3",
"tempy": "^0.5.0"
"file-type": "^16.5.0",
"get-stdin": "^9.0.0",
"meow": "^10.0.1",
"open": "^8.2.0",
"tempy": "^1.0.1"
},
"devDependencies": {
"ava": "^1.4.1",
"execa": "^4.0.0",
"xo": "^0.28.0"
"ava": "^3.15.0",
"execa": "^5.1.1",
"xo": "^0.40.2"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $ open-cli --help
Options
--wait Wait for the app to exit
--background Do not bring the app to the foreground (macOS only)
--extension File extension for when stdin file type can't be detected
--extension File extension for when stdin file type cannot be detected
Examples
$ open-cli https://sindresorhus.com
Expand Down

0 comments on commit bf6110c

Please sign in to comment.