Skip to content

Commit

Permalink
feat: support list tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
lumenghz committed Nov 27, 2022
1 parent a5edee1 commit 58fe650
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 4 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,36 @@ Just task it...
npm install -g @dennislu/ti
```

## Commands

### list

List all task names in your configuration file.

```shell
ti list
```

![ti-list](./screenshots/ti-list.jpg)

### -h, --help

```shell
ti -h
```

![ti-help](./screenshots/ti-help.jpg)

## Configuration

A [json-schema definition](./schema/ti-config-schema-v1.json) is provided, you can use it for tips in your editor.

### Steps

- Create a configuration file at user's config folder
- Windows:
- Linux/MacOS: `$HOME/.config/ti/config.yml`

### Example

```yaml
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"@antfu/eslint-config-ts": "^0.31.0",
"@types/node": "^17.0.40",
"@types/prompts": "^2.0.14",
"@types/yargs": "^17.0.14",
"consola": "^2.15.3",
"eslint": "^8.28.0",
"esno": "^0.16.0",
"execa": "^6.1.0",
Expand All @@ -47,7 +49,8 @@
"typescript": "^4.6.4",
"unbuild": "^1.0.0",
"vitest": "^0.25.3",
"yaml": "^2.1.3"
"yaml": "^2.1.3",
"yargs": "^17.6.2"
},
"eslintConfig": {
"extends": [
Expand Down
43 changes: 43 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added screenshots/ti-help.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/ti-list.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 20 additions & 3 deletions src/bin/ti.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import yargs from 'yargs/yargs'
import { hideBin } from 'yargs/helpers'
import type { TiConfig } from '../config'
import { getConfig } from '../config'
import { runTi } from '../runner'
import { listTi, runTi } from '../runner'

const config: TiConfig = getConfig()
const options = yargs(hideBin(process.argv))
.command('list', 'Show configured task list', { list: { default: true } })
.help('h')
.alias('h', 'help')
.version()
.alias('v', 'version')
.showHelpOnFail(true)
.strictCommands(true)
.strictOptions(true)
.locale('en')
.parseSync()

const config = getConfig()
if (config === null || config === undefined)
process.exit(1)

runTi(config)
if (options.list)
listTi(config)
else
runTi(config)
6 changes: 6 additions & 0 deletions src/runner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type SyncOptions, execaCommandSync } from 'execa'
import prompts, { type Answers } from 'prompts'
import { Fzf } from 'fzf'
import consola from 'consola'
import { parseCommand } from './parse'
import type { TiConfig, TiTask } from './config'

Expand All @@ -13,6 +14,11 @@ function getTask(config: TiConfig, name: string): TiTask {
process.exit(1)
}

export function listTi(config: TiConfig): void {
consola.success('Ti founded tasks:\n\n')
config.tasks.forEach(task => consola.info(`[task] ${task.name}`))
}

export function runTi(config: TiConfig): void {
const choices = config.tasks.map(task => ({ title: task.name, value: task }))
const fzf = new Fzf(choices.map(choice => choice.title))
Expand Down

0 comments on commit 58fe650

Please sign in to comment.