Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
add option to create new directory
Browse files Browse the repository at this point in the history
  • Loading branch information
petecoop committed May 5, 2015
1 parent 0b0e5d8 commit 4b8906f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
41 changes: 41 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,42 @@ module.exports = generators.Base.extend({
this.slugify = slugify;
},
prompting: {
dir: function () {

if (this.options.createDirectory !== undefined) {
return true;
}

var done = this.async();
var prompt = [{
type: 'confirm',
name: 'createDirectory',
message: 'Would you like to create a new directory for your project?'
}];

this.prompt(prompt, function (response) {
this.options.createDirectory = response.createDirectory;
done();
}.bind(this));
},
dirname: function () {

if (!this.options.createDirectory || this.options.dirname) {
return true;
}

var done = this.async();
var prompt = [{
type: 'input',
name: 'dirname',
message: 'Enter directory name'
}];

this.prompt(prompt, function (response) {
this.options.dirname = response.dirname;
done();
}.bind(this));
},
type: function () {
// Short circuit if an option was explicitly specified
if (this.options.mvc || this.options.basic) {
Expand Down Expand Up @@ -145,6 +181,11 @@ module.exports = generators.Base.extend({
writing: {
buildEnv: function () {

// create directory
if(this.options.createDirectory){
this.destinationRoot(this.options.dirname);
}

var name = this.options.mvc ? 'mvc' : 'basic';
var suffix = this.options.coffee ? '-coffee' : '';
this.filetype = 'js';
Expand Down
8 changes: 7 additions & 1 deletion test/test-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var toCoffeeFileArray = function (fileArray) {
return newArray;
};

var runGenerationTest = function (extraFiles, type, engine, preprocessor, coffee, database, buildTool, callback) {
var runGenerationTest = function (extraFiles, type, engine, preprocessor, coffee, database, buildTool, callback, dir, dirname) {
var expectedFiles;

// Never install dependencies
Expand All @@ -71,6 +71,8 @@ var runGenerationTest = function (extraFiles, type, engine, preprocessor, coffee
this.app.options.cssPreprocessor = preprocessor;
this.app.options.coffee = coffee;
this.app.options.buildTool = buildTool;
this.app.options.createDirectory = dir || false;
this.app.options.dirname = dirname;

// Set up initial file list Basic or MVC
expectedFiles = extraFiles.concat(appFiles[type]);
Expand Down Expand Up @@ -241,6 +243,10 @@ describe('Express generator', function () {
it('works with coffee and less', function (done) {
runGenerationTest.call(this, expected, 'basic', 'ejs', 'less', false, 'none', 'grunt', done);
});

it('creates a new directory', function (done) {
runGenerationTest.call(this, expected, 'basic', 'ejs', 'less', false, 'none', 'grunt', done, true, 'express-project');
});
});

describe('Basic generator with Swig', function () {
Expand Down

0 comments on commit 4b8906f

Please sign in to comment.