From 21dc9f2e4a176b73e053fd0ddd2f9f0b8bfc229b Mon Sep 17 00:00:00 2001 From: Kazakov Artem Date: Sat, 12 Oct 2019 19:58:26 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9D=8D=20Added=20send=20email=20and=20se?= =?UTF-8?q?nd=20commit=20to=20the=20config=20file=20=E2=9D=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ☐-------------------------------☐ ✸ Developer: Kazakov Artem ✸ Date: Oct 12th [ 19:58:00 ] ☐-------------------------------☐ --- DAVAI-CONFIG-example.json | 2 ++ src/cli.js | 4 +++- src/modules/stores/filesInfoStore.js | 20 +++++++++++++++++++- src/tasks/parseArgumentsIntoOptions.js | 25 ++++++++++++++++++++----- src/tasks/promptForMissingOptions.js | 16 ++++++++++------ 5 files changed, 54 insertions(+), 13 deletions(-) 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/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 } From ce4c4eb6cf9f7c1f1469e2b179d8d7d026e00d5d Mon Sep 17 00:00:00 2001 From: Kazakov Artem Date: Sat, 12 Oct 2019 20:10:51 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9D=8D=20Started=201.2.0=20=E2=9D=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ☐-------------------------------☐ ✸ Developer: Kazakov Artem ✸ Date: Oct 12th [ 20:10:00 ] ☐-------------------------------☐ --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e6f6f44..da725df 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 From 8f1a97e87a4e13e04eb4c621bb85cb9d170b6c5c Mon Sep 17 00:00:00 2001 From: Kazakov Artem Date: Sat, 12 Oct 2019 20:18:49 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9D=8D=20Updated=20Readme=20=E2=9D=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ☐-------------------------------☐ ✸ Developer: Kazakov Artem ✸ Date: Oct 12th [ 20:18:00 ] ☐-------------------------------☐ --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da725df..8e329f3 100644 --- a/README.md +++ b/README.md @@ -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" + } } ```