Skip to content

Commit

Permalink
feat: add interactive command support
Browse files Browse the repository at this point in the history
  • Loading branch information
loddit committed Aug 18, 2017
1 parent 31a41a6 commit 9e264fe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ Legilimens help you generate release report with pull requests info

## Command Usage

1. Edit a config file in legilimens`s repo folder to setup GitHub account and repo
1. Install packages
`npm install`

2. Edit a config file in legilimens`s repo folder to setup GitHub account and repo

`.config.json`

Expand All @@ -51,9 +54,7 @@ Legilimens help you generate release report with pull requests info
"repo_branch": // prs' base branch, eg: `master`
}
```

2. Install packages
`npm install`
(Optinal, otherwise you need answer some interactive command questions later)

3. Run Script
`npm start`
Expand Down
38 changes: 31 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
const fs = require('fs');
const legilimens = require('./legilimens.js');
const inquirer = require('inquirer');

const config = JSON.parse(fs.readFileSync('.config.json','utf8'));
if (fs.existsSync(".config.json")) {
const config = JSON.parse(fs.readFileSync('.config.json','utf8'));
const token = config.token;
const repoPath = config.repo_path;
const baseBranch = process.argv[2] || config.repo_branch || 'master';
legilimens(token, repoPath, baseBranch, (output) => {
console.log(output);
})
} else {
const questions = [{
type: "input",
name: "repo",
message: "what is your repo path? (as hubotio/hubot in https://github.com/hubotio/hubot)\n"
}, {
type: "input",
name: "branch",
message: "what is your repo release branch?\n",
default: "master"
}, {
type: "input",
name: "branch",
message: "give me a access token for API, you can get one via https://github.com/settings/tokens\n(optional, not need for public repo)",
default: null
}]
inquirer.prompt(questions).then(function (answers) {
legilimens(answers.token, answers.repo, answers.branch, (output) => {
console.log(output);
})
});
}

const token = config.token;
const repoPath = config.repo_path;
const baseBranch = process.argv[2] || config.repo_branch || 'master';

legilimens(token, repoPath, baseBranch, (output) => {
console.log(output);
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"coffee-script": "^1.8.0",
"inquirer": "^3.2.2",
"request": "^2.60.0"
},
"main": "./legilimens.js"
Expand Down

0 comments on commit 9e264fe

Please sign in to comment.