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

Commit

Permalink
Warn the user if they are attempting to generate a seed element in
Browse files Browse the repository at this point in the history
what appears to be an unsafe workspace.
  • Loading branch information
Ian MacLeod committed Nov 13, 2014
1 parent 47ec8b5 commit b7d68ef
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions seed/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
var _ = require('lodash');
var yeoman = require('yeoman-generator');
var path = require('path');
var yosay = require('yosay');
Expand Down Expand Up @@ -30,9 +31,39 @@ module.exports = yeoman.generators.Base.extend({
'ex: yo polymer:seed my-element'
));
}
},
checkForDanger: function () {
var done = this.async();

// Construct the element as a subdirectory.
this.destinationRoot(this.elementName);
// Because the element installs its dependencies as siblings, we want to
// make it clear to the user that it is potentially dangerous to generate
// their element from workspace containing other directories.
var entries = this.expand('*');
var bowerEntries = _.map(this.expand('*/bower.json'), path.dirname);
var nonComponents = _.difference(entries, bowerEntries);

// Whew, everything looks like a bower component!
if (nonComponents.length === 0) return done();

console.warn(
'You are generating your element in a workspace that appears to contain data\n' +
'other than web components. This is potentially dangerous, as your element\'s\n' +
'dependencies will be installed in the current directory. Bower will\n' +
'overwrite any conflicting directories.\n'
);
var prompts = [{
name: 'livesDangerously',
message: 'Are you ok with that?',
default: 'no',
}];

this.prompt(prompts, function (props) {
if (props.livesDangerously[0] === 'n') {
// Async done never gets called; process ends.
} else {
done();
}
}.bind(this));
},
askFor: function () {
var done = this.async();
Expand All @@ -55,6 +86,9 @@ module.exports = yeoman.generators.Base.extend({
}.bind(this));
},
seed: function () {
// Construct the element as a subdirectory.
this.destinationRoot(this.elementName);

this.copy('gitignore', '.gitignore');
this.copy('gitattributes', '.gitattributes');
this.copy('bowerrc', '.bowerrc');
Expand Down

0 comments on commit b7d68ef

Please sign in to comment.