Skip to content

Commit

Permalink
[TASK] check is specified folder exist in current dir
Browse files Browse the repository at this point in the history
  • Loading branch information
dmh committed Jun 1, 2017
1 parent c5e1d35 commit 669e5a6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const parse = require('./lib/parse')
// const dep = require('./lib/dep')
const argv = require('minimist')(process.argv.slice(2))
const cmd = require('./lib/cmd')
// const subtheme = require('./lib/subtheme')
const text = require('./lib/text')

var cache = {}
Expand All @@ -32,7 +31,8 @@ function generateSubtheme () {
.then(check.folder)

.then(prompt.siteName)
.then(() => prompt.isOk(cache, text.subtheme.isAutoDirName(cache), prompt.dirName))
.then(check.isFolderExist)
.then(() => cache.isFolderExist ? prompt.dirName(cache) : prompt.isOk(cache, text.subtheme.isAutoDirName(cache), prompt.dirName))
.then(cmd.mkdir)
.then(() => git.clone(cache, variables.subtheme.repo))

Expand Down
13 changes: 12 additions & 1 deletion lib/check/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

// var fs = require('fs')
var fs = require('fs')
const shell = require('shelljs')
const chalk = require('chalk')
const variables = require('../variables')
Expand Down Expand Up @@ -33,3 +33,14 @@ check.folder = function folder (cache) {
return cache
}
}

check.isFolderExist = function isFolderExist (cache) {
let isFolderExist = {}
if (fs.existsSync(variables.subtheme.dirName(cache))) {
isFolderExist.isFolderExist = true
} else {
isFolderExist.isFolderExist = false
}
helpers.addTo(cache, isFolderExist)
return cache
}
3 changes: 3 additions & 0 deletions lib/prompt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ prompt.siteName = function siteName (cache) {
function recursivePrompt () {
inquirer.prompt(siteName)
.then(function (answers) {
if (fs.existsSync(variables.subtheme.dirName(answers))) {
console.log(` ${chalk.yellow(text.subtheme.warning.nameAlreadyExists(answers))}`)
}
if (answers.isOk === false) {
recursivePrompt()
} else if (answers.isOk === true) {
Expand Down
5 changes: 4 additions & 1 deletion lib/text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ text.subtheme = {
capitalLetter: `Do not use a capital first letter`,
oneWord: `Should be one word or use camelCase`,
camelCase: `Use camelCase`,
dirName: `Folder exists. Please choose another folder name.`
dirName: `Folder exists. Please choose another folder name`
},
warning: {
nameAlreadyExists: (cache) => `Warning: Folder subtheme_t3kit_${cache.siteName} already exist in current directory.`
}
}

Expand Down

0 comments on commit 669e5a6

Please sign in to comment.