From 9e264fec9ada6aa61d0927c319254caf78ca875b Mon Sep 17 00:00:00 2001 From: loddit Date: Fri, 18 Aug 2017 11:40:26 +0800 Subject: [PATCH] feat: add interactive command support --- README.md | 9 +++++---- index.js | 38 +++++++++++++++++++++++++++++++------- package.json | 1 + 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a84ac71..4e45f02 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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` diff --git a/index.js b/index.js index 01c9f7c..74e6d8a 100644 --- a/index.js +++ b/index.js @@ -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); -}) diff --git a/package.json b/package.json index 00cd619..03829ee 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "coffee-script": "^1.8.0", + "inquirer": "^3.2.2", "request": "^2.60.0" }, "main": "./legilimens.js"