Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Commit

Permalink
build(app): use new prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored and passy committed Jun 20, 2013
1 parent e0c03d5 commit 8874722
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 73 deletions.
38 changes: 13 additions & 25 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,11 @@ Generator.prototype.askForBootstrap = function askForBootstrap() {
var cb = this.async();

this.prompt({
type: 'confirm',
name: 'bootstrap',
message: 'Would you like to include Twitter Bootstrap?',
default: true,
warning: 'Yes: All Twitter Bootstrap files will be placed into the styles directory.'
}, function (err, props) {
if (err) {
return this.emit('error', err);
}

default: true
}, function (props) {
this.bootstrap = props.bootstrap;

cb();
Expand All @@ -100,15 +96,11 @@ Generator.prototype.askForCompass = function askForCompass() {
var cb = this.async();

this.prompt({
type: 'confirm',
name: 'compassBootstrap',
message: 'If so, would you like to use Twitter Bootstrap for Compass (as opposed to vanilla CSS)?',
default: true,
warning: 'Yes: All Twitter Bootstrap files will be placed into the styles directory.'
}, function (err, props) {
if (err) {
return this.emit('error', err);
}

default: true
}, function (props) {
this.compassBootstrap = props.compassBootstrap;

cb();
Expand All @@ -119,27 +111,23 @@ Generator.prototype.askForModules = function askForModules() {
var cb = this.async();

var prompts = [{
type: 'confirm',
name: 'resourceModule',
message: 'Would you like to include angular-resource.js?',
default: true,
warning: 'Yes: angular-resource added to bower.json'
default: true
}, {
type: 'confirm',
name: 'cookiesModule',
message: 'Would you like to include angular-cookies.js?',
default: true,
warning: 'Yes: angular-cookies added to bower.json'
default: true
}, {
type: 'confirm',
name: 'sanitizeModule',
message: 'Would you like to include angular-sanitize.js?',
default: true,
warning: 'Yes: angular-sanitize added to bower.json'
default: true
}];

this.prompt(prompts, function (err, props) {
if (err) {
return this.emit('error', err);
}

this.prompt(prompts, function (props) {
this.resourceModule = props.resourceModule;
this.cookiesModule = props.cookiesModule;
this.sanitizeModule = props.sanitizeModule;
Expand Down
89 changes: 41 additions & 48 deletions decorator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,64 @@ var ScriptBase = require('../script-base.js');
var fs = require('fs');

var Generator = module.exports = function Generator(args, options) {
ScriptBase.apply(this, arguments);
this.fileName = this.name;
ScriptBase.apply(this, arguments);
this.fileName = this.name;
};

util.inherits(Generator, ScriptBase);

Generator.prototype.askForOverwrite = function askForOverwrite() {
var cb = this.async();
var cb = this.async();

// TODO: Any yeoman.util function to handle this?
var fileExists = fs.existsSync(this.env.cwd + '/app/scripts/' + buildRelativePath(this.fileName) + ".js");
if (fileExists) {
var prompts = [{
name : 'overwriteDecorator',
message: 'Would you like to overwrite existing decorator?',
default: 'Y/n',
warning: 'Yes: Decorator will be replaced.'
}];
// TODO: Any yeoman.util function to handle this?
var fileExists = fs.existsSync(this.env.cwd + '/app/scripts/' + buildRelativePath(this.fileName) + ".js");
if (fileExists) {
var prompts = [{
type: 'confirm',
name: 'overwriteDecorator',
message: 'Would you like to overwrite existing decorator?',
default: false
}];

this.prompt(prompts, function (err, props) {
if (err) {
return this.emit('error', err);
}
this.prompt(prompts, function (props) {
this.overwriteDecorator = props.overwriteDecorator;

this.overwriteDecorator = (/y/i).test(props.overwriteDecorator);

cb();
}.bind(this));
}
else{
cb();
return;
}
cb();
}.bind(this));
}
else{
cb();
return;
}
};

Generator.prototype.askForNewName = function askForNewName() {
var cb = this.async();
var cb = this.async();

if (this.overwriteDecorator === undefined || this.overwriteDecorator === true) {
cb();
return;
}
else {
var prompts = [];
prompts.push({
name : 'decortatorName',
message: 'Alternative name for the decorator:'
});
if (this.overwriteDecorator === undefined || this.overwriteDecorator === true) {
cb();
return;
}
else {
var prompts = [];
prompts.push({
name: 'decoratorName',
message: 'Alternative name for the decorator'
});

this.prompt(prompts, function (err, props) {
if (err) {
return this.emit('error', err);
}
this.fileName = props.decortatorName;
this.prompt(prompts, function (props) {
this.fileName = props.decoratorName;

cb();
}.bind(this));
}
cb();
}.bind(this));
}
};

Generator.prototype.createDecoratorFiles = function createDecoratorFiles() {
this.appTemplate('decorator', 'scripts/' + buildRelativePath(this.fileName));
this.addScriptToIndex(buildRelativePath(this.fileName));
this.appTemplate('decorator', 'scripts/' + buildRelativePath(this.fileName));
this.addScriptToIndex(buildRelativePath(this.fileName));
};

function buildRelativePath(fileName){
return 'decorators/' + fileName + "Decorator";
}
return 'decorators/' + fileName + "Decorator";
}

0 comments on commit 8874722

Please sign in to comment.