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
2 changes: 2 additions & 0 deletions DAVAI-CONFIG-example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"PROJECT_NAME": "DAVAI-COMMIT",
"SEND_EMAIL": false,
"SEND_COMMIT": false,
"EMAIL_CONFIG": {
"LOGIN": "YANDEX EMAIL",
"PASS": "PASSWORD",
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# DAVAI-COMMIT

## VERSIONS
- DEVELOPMENT RELEASE 1.1.0
- DEVELOPMENT RELEASE 1.2.0
- PRODUCTION RELEASE 1.1.0

## First installation
Expand Down Expand Up @@ -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"
}
}
```
4 changes: 3 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
20 changes: 19 additions & 1 deletion src/modules/stores/filesInfoStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() || {}

Expand Down Expand Up @@ -74,7 +91,8 @@ export const FilesInfoStore = observable({
}, {
checkConfigFile: action,
setProjectName: action,
setEmailCreds: action
setEmailCreds: action,
checkDefaultParams: action
})

autorun(() => {
Expand Down
25 changes: 20 additions & 5 deletions src/tasks/parseArgumentsIntoOptions.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 [?]
Expand All @@ -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,
Expand All @@ -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
Expand Down
16 changes: 10 additions & 6 deletions src/tasks/promptForMissingOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -17,15 +21,15 @@ async function promptForMissingOptions() {
default: 'AUTOGENERATED'
})
}
if (!sendCommit) {
if (sendCommit === null) {
questions.push({
type: 'confirm',
name: 'sendCommit',
message: 'Do you want to send commit?',
default: 'true'
})
}
if (!sendEmail) {
if (sendEmail === null) {
questions.push({
type: 'confirm',
name: 'sendEmail',
Expand All @@ -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
}
Expand Down