diff --git a/DAVAI-CONFIG-example.json b/DAVAI-CONFIG-example.json index 13eb240..d7f2a24 100644 --- a/DAVAI-CONFIG-example.json +++ b/DAVAI-CONFIG-example.json @@ -1,5 +1,7 @@ { "PROJECT_NAME": "DAVAI-COMMIT", + "SEND_EMAIL": false, + "SEND_COMMIT": false, "EMAIL_CONFIG": { "LOGIN": "YANDEX EMAIL", "PASS": "PASSWORD", diff --git a/README.md b/README.md index e6f6f44..8e329f3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # DAVAI-COMMIT ## VERSIONS - - DEVELOPMENT RELEASE 1.1.0 + - DEVELOPMENT RELEASE 1.2.0 - PRODUCTION RELEASE 1.1.0 ## First installation @@ -37,6 +37,14 @@ ## Example DAVAI-CONFIG.json ```json { - "PROJECT_NAME": "DAVAI-COMMIT" + "PROJECT_NAME": "DAVAI-COMMIT", + "SEND_EMAIL": false, + "SEND_COMMIT": false, + "EMAIL_CONFIG": { + "LOGIN": "YANDEX EMAIL", + "PASS": "PASSWORD", + "SERVICE": "Yandex", + "SENDER_LIST": "email-1,email-2" + } } ``` diff --git a/src/cli.js b/src/cli.js index 680df0e..15272e1 100644 --- a/src/cli.js +++ b/src/cli.js @@ -22,8 +22,10 @@ export async function cli(args) { try { await parseArgumentsIntoOptions(args) await promptForMissingOptions() - await startUpTasks() const { sendCommit, sendEmail } = ShellArgumentsStore + + await startUpTasks() + if (sendCommit) await submitChangesToGithub() if (sendEmail) await sendEmailTasks() diff --git a/src/modules/stores/filesInfoStore.js b/src/modules/stores/filesInfoStore.js index df24ebc..fb5bff9 100644 --- a/src/modules/stores/filesInfoStore.js +++ b/src/modules/stores/filesInfoStore.js @@ -46,6 +46,23 @@ export const FilesInfoStore = observable({ return logError('Setting project name failed:', 'There was a problem with a config file') }, + async checkDefaultParams() { + const { config } = this.getConfigurationFile() || {} + + if (!__isEmpty(config)) { + const { + SEND_EMAIL = null, + SEND_COMMIT = null + } = config + + this.SEND_EMAIL = SEND_EMAIL + this.SEND_COMMIT = SEND_COMMIT + + return this + } + return logError('Setting project name failed:', 'There was a problem with a config file') + }, + async setEmailCreds() { const { config } = this.getConfigurationFile() || {} @@ -74,7 +91,8 @@ export const FilesInfoStore = observable({ }, { checkConfigFile: action, setProjectName: action, - setEmailCreds: action + setEmailCreds: action, + checkDefaultParams: action }) autorun(() => { diff --git a/src/tasks/parseArgumentsIntoOptions.js b/src/tasks/parseArgumentsIntoOptions.js index 2a3cd43..6c559d9 100644 --- a/src/tasks/parseArgumentsIntoOptions.js +++ b/src/tasks/parseArgumentsIntoOptions.js @@ -1,7 +1,7 @@ import arg from 'arg' // Stores -import { ShellArgumentsStore } from '../modules/index' +import { ShellArgumentsStore, FilesInfoStore } from '../modules/index' /** * Parsing arguments that the user sends in the console @@ -11,7 +11,7 @@ import { ShellArgumentsStore } from '../modules/index' * * @return {Boolean} */ -function parseArgumentsIntoOptions(rawArgs) { +async function parseArgumentsIntoOptions(rawArgs) { // TODO: set the option to: // - version // - mode [?] @@ -24,6 +24,13 @@ function parseArgumentsIntoOptions(rawArgs) { * --send-commit boolean * --send-email boolean */ + // First, let's check for default params, such as SEND_EMAIL and SEND COMMIT + + const { + SEND_EMAIL, + SEND_COMMIT + } = await FilesInfoStore.checkDefaultParams() + const args = arg({ '--commit-message': Boolean, '--send-commit': Boolean, @@ -33,9 +40,17 @@ function parseArgumentsIntoOptions(rawArgs) { * If the user did not specify either of the params * he will be asked to do so in the cli-view */ - ShellArgumentsStore.setCommitMessage(args._[0] || false) - ShellArgumentsStore.setSendCommit(args._[1] || false) - ShellArgumentsStore.setSendEmail(args._[2] || false) + ShellArgumentsStore.setCommitMessage(args._[0] || null) + if (SEND_EMAIL === null) { + ShellArgumentsStore.setSendEmail(args._[2] || null) + } else { + ShellArgumentsStore.setSendEmail(SEND_EMAIL) + } + if (SEND_COMMIT === null) { + ShellArgumentsStore.setSendCommit(args._[1] || null) + } else { + ShellArgumentsStore.setSendCommit(SEND_COMMIT) + } ShellArgumentsStore.setDirectory(process.cwd()) return true diff --git a/src/tasks/promptForMissingOptions.js b/src/tasks/promptForMissingOptions.js index ff740f6..0035dee 100644 --- a/src/tasks/promptForMissingOptions.js +++ b/src/tasks/promptForMissingOptions.js @@ -6,9 +6,13 @@ import { ShellArgumentsStore } from '../modules/index' async function promptForMissingOptions() { const questions = [] - const { commitMsg, sendCommit, sendEmail } = ShellArgumentsStore + const { + commitMsg, + sendCommit, + sendEmail + } = ShellArgumentsStore - if (!commitMsg) { + if (commitMsg === null) { // TODO: move AUTOGENERATED to the global config questions.push({ type: 'input', @@ -17,7 +21,7 @@ async function promptForMissingOptions() { default: 'AUTOGENERATED' }) } - if (!sendCommit) { + if (sendCommit === null) { questions.push({ type: 'confirm', name: 'sendCommit', @@ -25,7 +29,7 @@ async function promptForMissingOptions() { default: 'true' }) } - if (!sendEmail) { + if (sendEmail === null) { questions.push({ type: 'confirm', name: 'sendEmail', @@ -37,8 +41,8 @@ async function promptForMissingOptions() { const answers = await inquirer.prompt(questions) ShellArgumentsStore.setCommitMessage(commitMsg || answers.commitMsg) - ShellArgumentsStore.setSendCommit(sendCommit || answers.sendCommit) - ShellArgumentsStore.setSendEmail(sendEmail || answers.sendEmail) + ShellArgumentsStore.setSendCommit(answers.sendCommit || sendCommit) + ShellArgumentsStore.setSendEmail(answers.sendEmail || sendEmail) return true }