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

Commit

Permalink
BREAKING CHANGE: yo polymer:seed now requires an element-name argument.
Browse files Browse the repository at this point in the history
This allows us to construct the element's directory and be a _litte_ bit
more safe about the .bowerrc madness.
  • Loading branch information
Ian MacLeod committed Nov 13, 2014
1 parent 57b1949 commit 47ec8b5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
9 changes: 6 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ yo polymer:el my-element
### Seed
Generates a reusable polymer element based on the [seed-element workflow](http://www.polymer-project.org/docs/start/reusableelements.html). **This should only be used if you're creating a standalone element repo that you intend to share with others via bower.** If you're just building a Polymer app, stick to the [El](#el) generator.

To create a seed-element you'll first need to create a parent directory, then a sub directory to hold your seed-element. All bower dependencies will be installed into the parent directory. Please follow the [seed-element guide](http://www.polymer-project.org/docs/start/reusableelements.html) for more instructions.
The seed-element generator will construct a new element _and_ its directory for
you. Be aware: all bower dependencies will be installed as _siblings_ of the
newly generated element. Make sure that you generate the seed element within a
directory that is intended to contain multiple components!

Example:
```bash
mkdir -p components/x-foo && cd $_
yo polymer:seed
mkdir -p components && cd $_
yo polymer:seed x-foo
```

### Gh
Expand Down
35 changes: 18 additions & 17 deletions seed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ module.exports = yeoman.generators.Base.extend({
constructor: function () {
yeoman.generators.Base.apply(this, arguments);

this.argument('element-name', {
desc: 'Tag name of the element and directory to generate.',
required: true,
});

this.option('skip-install', {
desc: 'Whether bower dependencies should be installed',
defaults: false,
Expand All @@ -17,43 +22,39 @@ module.exports = yeoman.generators.Base.extend({
defaults: false,
});
},
validate: function () {
this.elementName = this['element-name'];
if (this.elementName.indexOf('-') === -1) {
this.emit('error', new Error(
'Element name must contain a dash "-"\n' +
'ex: yo polymer:seed my-element'
));
}

// Construct the element as a subdirectory.
this.destinationRoot(this.elementName);
},
askFor: function () {
var done = this.async();

// Have Yeoman greet the user.
this.log(yosay('Out of the box I include the Polymer seed-element.'));
this.log(yosay('Out of the box I follow the seed-element pattern.'));

var defaultName = path.basename(process.cwd());
var prompts = [
{
name: 'ghUser',
message: 'What is your GitHub username?'
},
{
name: 'elementName',
message: 'What is your element\'s name',
default: defaultName
}
];

this.prompt(prompts, function (props) {
this.ghUser = props.ghUser;
this.elementName = props.elementName;

done();
}.bind(this));
},
seed: function () {
if (this.elementName.indexOf('-') === -1) {
console.error(
'The element name you provided: ' + this.elementName + ' ' +
'is invalid.'
);
console.error('Element name must contain a dash "-"');
console.error('ex: my-element');
return;
}

this.copy('gitignore', '.gitignore');
this.copy('gitattributes', '.gitattributes');
this.copy('bowerrc', '.bowerrc');
Expand Down
33 changes: 18 additions & 15 deletions test/seed-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ var path = require('path');
var helpers = require('yeoman-generator').test;

describe('yo polymer:seed test', function () {
var testDir = path.join(__dirname, 'temp');

before(function (done) {
helpers.testDirectory(path.join(__dirname, 'temp'), function (err) {
helpers.testDirectory(testDir, function (err) {
if (err) {
return done(err);
}
Expand All @@ -15,7 +17,7 @@ describe('yo polymer:seed test', function () {
helpers.createDummyGenerator(),
'mocha:seed'
]
]);
], 'x-foo');
this.polymer.options['skip-install'] = true;

done();
Expand All @@ -29,19 +31,19 @@ describe('yo polymer:seed test', function () {

it('creates expected files', function (done) {
var expected = [
['bower.json', /"name": "x-foo"/, /"main": "x-foo.html"/],
'.bowerrc',
'.editorconfig',
'.gitignore',
'.jshintrc',
'demo.html',
'index.html',
'README.md',
'x-foo.css',
'x-foo.html',
'test/index.html',
'test/tests.html',
'test/x-foo-basic.html',
['x-foo/bower.json', /"name": "x-foo"/, /"main": "x-foo.html"/],
'x-foo/.bowerrc',
'x-foo/.editorconfig',
'x-foo/.gitignore',
'x-foo/.jshintrc',
'x-foo/demo.html',
'x-foo/index.html',
'x-foo/README.md',
'x-foo/x-foo.css',
'x-foo/x-foo.html',
'x-foo/test/index.html',
'x-foo/test/tests.html',
'x-foo/test/x-foo-basic.html',
];

helpers.mockPrompt(this.polymer, {
Expand All @@ -50,6 +52,7 @@ describe('yo polymer:seed test', function () {
});

this.polymer.run({}, function () {
process.chdir(testDir);
helpers.assertFiles(expected);
done();
});
Expand Down

0 comments on commit 47ec8b5

Please sign in to comment.