Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ cli.command('help', 'Display task description', (input, flags) => {
return runner.getHelp(input)
})

cli.command('run', 'Choose which task to run from a list', (input, flags) => {
const runner = require('..')(flags)
return runner.runList(input)
})

cli.command('list', 'Display task list', (input, flags) => {
const runner = require('..')(flags)
return runner.getList()
Expand Down
41 changes: 41 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const logger = require('./logger')
const readMaidFile = require('./readMaidFile')
const MaidError = require('./MaidError')
const runCLICommand = require('./runCLICommand')
const inquirer = require('inquirer')
const spawn = require('cross-spawn')

class Maid {
constructor(opts = {}) {
Expand Down Expand Up @@ -152,6 +154,45 @@ class Maid {
)
}

runList(patterns) {
patterns = [].concat(patterns)
const tasks =
patterns.length > 0
? this.maidfile.tasks.filter(task => {
return mm.some(task.name, patterns)
})
: this.maidfile.tasks

if (tasks.length === 0) {
throw new MaidError(
`No tasks for pattern "${patterns.join(' ')}" was found. Stop.`
)
}

let taskNames = tasks.map(task => `${task.name} \t ${task.description}`)
inquirer
.prompt([
{
type: 'list',
name: 'taskToRun',
message: 'Which task do you want to run',
choices: taskNames
}
])
.then(({ taskToRun }) => {
spawn(
'yarn',
[taskToRun.split('\t')[0].trim(), ...process.argv.slice(2)],
{
stdio: 'inherit',
env: Object.assign({}, process.env, {
PATH: `${path.resolve('node_modules/.bin')} :${process.env.PATH}`
})
}
)
})
}

getList() {
const tasks = this.maidfile.tasks
console.log(tasks.map(task => task.name).join('\n'))
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"eslint-config-xo": "^0.22.2",
"eslint-plugin-prettier": "^2.6.0",
"husky": "^1.0.0-rc.8",
"inquirer": "^6.2.2",
"lint-staged": "^7.1.3",
"prettier": "^1.13.3"
},
Expand Down
Loading