Skip to content

Commit

Permalink
Merge pull request #93 from kdembler/init-custom-directory
Browse files Browse the repository at this point in the history
Allow creating plans in custom directory
  • Loading branch information
scriptnull authored Oct 29, 2017
2 parents 63ed09e + 70f362d commit 5738cb5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
13 changes: 10 additions & 3 deletions microplan-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ async.waterfall([
function _parseInputFromUser (callback) {
program
.option('-t, --template <location>', 'specify input template location', templateFileLocation.yaml)
.option('-d, --directory <location>', 'specify plan output directory')
.parse(process.argv)

if (program.args.length < 1) {
callback('Please specify a valid filename for plan output.', null)
}

var destFilePath = program.args[0]

if (utils.fileExists(program.template) === false) {
Expand All @@ -51,9 +51,16 @@ function _parseInputFromUser (callback) {

if (suppFileExtns.indexOf(fileExt) === -1) {
callback('Template extension not supported. Please use supported file extensions: ' + suppFileExtns.join(', '), null)
} else {
callback(null, program.template, destFilePath)
}

if (program.directory) {
if (utils.directoryExists(program.directory) === false) {
callback('Please provide a valid directory path', null)
}
destFilePath = path.join(program.directory, destFilePath)
}

callback(null, program.template, destFilePath)
}

function _getOptsFromUser (templateFilePath, destFilePath, callback) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "microplan",
"version": "1.4.2",
"version": "1.5.0",
"description": "Plan your project from command line",
"main": "microplan.js",
"scripts": {
Expand Down
9 changes: 9 additions & 0 deletions utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ function fileExists (filePath) {
}
}

function directoryExists (dirPath) {
try {
return fs.statSync(dirPath).isDirectory()
} catch (err) {
return false
}
}

module.exports =
{
fileExists: fileExists,
directoryExists: directoryExists,
parseSlug: parseSlug
}

0 comments on commit 5738cb5

Please sign in to comment.