forked from sindresorhus/meow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* this has had no effect since sindresorhus#68
- Loading branch information
1 parent
21b5c91
commit 6e178a9
Showing
7 changed files
with
108 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env tsimp | ||
import process from 'node:process'; | ||
import type {LiteralUnion} from 'type-fest'; | ||
import meow from '../../../source/index.js'; | ||
|
||
/* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/consistent-type-definitions */ | ||
declare global { | ||
namespace NodeJS { | ||
interface ProcessEnv { | ||
VERSION?: LiteralUnion<'false', string>; | ||
} | ||
} | ||
} | ||
/* eslint-enable @typescript-eslint/no-namespace, @typescript-eslint/consistent-type-definitions */ | ||
|
||
const version = (process.env.VERSION === 'false' ? false : process.env.VERSION) as string; | ||
|
||
const options = { | ||
importMeta: import.meta, | ||
version, | ||
autoVersion: !process.argv.includes('--no-auto-version'), | ||
flags: { | ||
showVersion: {type: 'boolean'}, | ||
}, | ||
} as const; | ||
|
||
if (options.version === undefined) { | ||
// @ts-expect-error: version should be deleted | ||
delete options.version; | ||
} | ||
|
||
const cli = meow(options); | ||
|
||
if (cli.flags.showVersion) { | ||
cli.showVersion(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "foo", | ||
"version": "1.0.0", | ||
"bin": "./fixture.ts", | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import test from 'ava'; | ||
import {spawnFixture, stripIndent} from './_utils.js'; | ||
|
||
const fixture = 'version/fixture.ts'; | ||
|
||
test('spawn cli and show version', async t => { | ||
const {stdout} = await spawnFixture(fixture, ['--version']); | ||
t.is(stdout, '1.0.0'); | ||
}); | ||
|
||
test('spawn cli and disabled autoVersion', async t => { | ||
const {stdout} = await spawnFixture(['--version', '--no-auto-version']); | ||
|
||
t.is(stdout, stripIndent` | ||
version | ||
autoVersion | ||
meow | ||
camelCaseOption | ||
`); | ||
}); | ||
|
||
test('spawn cli and not show version', async t => { | ||
const {stdout} = await spawnFixture(['--version=beta']); | ||
|
||
t.is(stdout, stripIndent` | ||
version | ||
meow | ||
camelCaseOption | ||
`); | ||
}); | ||
|
||
test('custom version', async t => { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const {stdout} = await spawnFixture(fixture, ['--version'], {env: {VERSION: 'beta'}}); | ||
t.is(stdout, 'beta'); | ||
}); | ||
|
||
test('version = false has no effect', async t => { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const {stdout} = await spawnFixture(fixture, ['--version'], {env: {VERSION: 'false'}}); | ||
t.is(stdout, ''); | ||
}); | ||
|
||
test('manual showVersion', async t => { | ||
const {stdout} = await spawnFixture(fixture, ['--show-version']); | ||
t.is(stdout, '1.0.0'); | ||
}); |