-
Notifications
You must be signed in to change notification settings - Fork 199
Adds a Polymer 3 element template to init.
#115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
1438c47
d3f365a
5d116f7
5e3f069
ade3349
1b00b80
1e1439c
1a6be11
f9de6b3
c556f4b
1fc67fa
d493ae2
bdd7977
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,12 +27,12 @@ const logger = logging.getLogger('init'); | |
| */ | ||
| export function createElementGenerator(templateName: string): | ||
| (typeof Generator) { | ||
| return class ElementGenerator extends Generator { | ||
| class ElementGenerator extends Generator { | ||
| props: any; | ||
|
|
||
| constructor(args: string|string[], options: any) { | ||
| super(args, options); | ||
| this.sourceRoot(path.join(__dirname, 'templates', templateName)); | ||
| this.sourceRoot(path.join(__dirname, '../../../templates/element', templateName)); | ||
| } | ||
|
|
||
| // This is necessary to prevent an exception in Yeoman when creating | ||
|
|
@@ -119,4 +119,63 @@ export function createElementGenerator(templateName: string): | |
| 'Check out your new project README for information about what to do next.\n'); | ||
| } | ||
| }; | ||
|
|
||
| class Polymer3ElementGenerator extends ElementGenerator { | ||
| // This is not a no-op: Yeoman only checks the object's prototype's own | ||
| // properties for methods. | ||
| initializing() { | ||
| return super.initializing(); | ||
| } | ||
|
|
||
| // This is not a no-op: Yeoman only checks the object's prototype's own | ||
| // properties for methods. | ||
| async prompting() { | ||
| return super.prompting(); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you double check that this doesn't work when this isn't here? I looked at the JS that's produced, and we're producing ES6 here. I can't see any reason why this code would do anything at all.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like async-await is being compiled out. I'm betting it has something to do with that.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, yes, the parent class'
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, telling TypeScript to target ES2017 still has this problem.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's the problem: https://github.com/yeoman/generator/blob/v1.0.1/lib/index.js#L382
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added pass-through functions for all of the other methods as well.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh hey, you found it too. I just filed yeoman/generator#1065 |
||
|
|
||
| writing() { | ||
| const name = this.props.name; | ||
|
|
||
| this.fs.copyTpl( | ||
| `${this.templatePath()}/**/?(.)!(_)*`, | ||
| this.destinationPath(), | ||
| this.props); | ||
|
|
||
| this.fs.copyTpl( | ||
| this.templatePath('_element.js'), `${name}.js`, this.props); | ||
|
|
||
| this.fs.copyTpl( | ||
| this.templatePath('test/_element_test.html'), | ||
| `test/${name}_test.html`, | ||
| this.props); | ||
|
|
||
| this.fs.copyTpl( | ||
| this.templatePath('test/index.html'), `test/index.html`, this.props); | ||
|
|
||
| this.fs.copyTpl( | ||
| this.templatePath('.gitignore'), '.gitignore', this.props); | ||
| } | ||
|
|
||
| install() { | ||
| this.log(chalk.bold('\nProject generated!')); | ||
| this.log('Installing dependencies...'); | ||
| this.installDependencies({ | ||
| bower: false, | ||
| npm: true, | ||
| }); | ||
| } | ||
|
|
||
| // This is not a no-op: Yeoman only checks the object's prototype's own | ||
| // properties for methods. | ||
| end() { | ||
| return super.end(); | ||
| } | ||
| } | ||
|
|
||
| switch (templateName) { | ||
| case 'polymer-3.x': | ||
| return Polymer3ElementGenerator; | ||
| default: | ||
| return ElementGenerator; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,9 @@ import {createApplicationGenerator} from '../../init/application/application'; | |
| import {runCommand} from './run-command'; | ||
| import {createElementGenerator} from '../../init/element/element'; | ||
| import {createGithubGenerator} from '../../init/github'; | ||
| import * as child_process from 'child_process'; | ||
| import * as util from 'util'; | ||
| const exec = util.promisify(child_process.exec); | ||
|
|
||
| // A zero priveledge github token of a nonce account, used for quota. | ||
| const githubToken = '8d8622bf09bb1d85cb411b5e475a35e742a7ce35'; | ||
|
|
@@ -34,6 +37,24 @@ suite('integration tests', function() { | |
|
|
||
| suite('init templates', () => { | ||
|
|
||
| skipOnWindows('test the Polymer 3.x element template', async () => { | ||
| const dir = | ||
| await runGenerator(createElementGenerator('polymer-3.x')) | ||
| .withPrompts({name: 'my-element'}) // Mock the prompt answers | ||
| .toPromise(); | ||
| // TODO(#118): Use `polymer install` once it supports installing npm | ||
| // packages. | ||
| await exec('npm install', {cwd: dir}); | ||
|
|
||
| // TODO(#130): Add this back in when `polymer lint` has a Polymer 3 | ||
| // option. | ||
| // await runCommand(binPath, ['lint'], {cwd: dir}); | ||
|
|
||
| // TODO(#113): Remove the `--module-resolution=node` argument once | ||
| // `polymer test` passes them in correctly | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| await runCommand(binPath, ['test', '--module-resolution=node'], {cwd: dir}); | ||
| }); | ||
|
|
||
| skipOnWindows('test the Polymer 1.x application template', async () => { | ||
| const dir = await runGenerator(createApplicationGenerator('polymer-1.x')) | ||
| .withPrompts({name: 'my-app'}) // Mock the prompt answers | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /node_modules/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # \<<%= name %>\> | ||
|
|
||
| <%= description %> | ||
|
|
||
| ## Install the Polymer-CLI | ||
|
|
||
| First, make sure you have the [Polymer CLI](https://www.npmjs.com/package/polymer-cli) and npm (packaged with [Node.js](https://nodejs.org)) installed. Run `npm install` to install your element's dependencies, then run `polymer serve` to serve your element locally. | ||
|
|
||
| ## Viewing Your Element | ||
|
|
||
| ``` | ||
| $ polymer serve | ||
| ``` | ||
|
|
||
| ## Running Tests | ||
|
|
||
| ``` | ||
| $ polymer test | ||
| ``` | ||
|
|
||
| Your application is already set up to be tested via [web-component-tester](https://github.com/Polymer/web-component-tester). Run `polymer test` to run your application's test suite locally. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import {PolymerElement} from '@polymer/polymer/polymer-element.js'; | ||
|
|
||
| /** | ||
| * `<%= name %>` | ||
| * <%= description %> | ||
| * | ||
| * @customElement | ||
| * @polymer | ||
| * @demo demo/index.html | ||
| */ | ||
| class <%= elementClassName %> extends PolymerElement { | ||
| static get template() { | ||
| return ` | ||
| <style> | ||
| :host { | ||
| display: block; | ||
| } | ||
| </style> | ||
| <h2>Hello [[prop1]]!</h2> | ||
| `; | ||
| } | ||
| static get properties() { | ||
| return { | ||
| prop1: { | ||
| type: String, | ||
| value: '<%= name %>', | ||
| }, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| window.customElements.define('<%= name %>', <%= elementClassName %>); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes"> | ||
|
|
||
| <title><%= name %> demo</title> | ||
|
|
||
| <script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script> | ||
|
|
||
| <script type="module" src="../node_modules/@polymer/iron-demo-helpers/demo-pages-shared-styles.js"></script> | ||
| <script type="module" src="../node_modules/@polymer/iron-demo-helpers/demo-snippet.js"></script> | ||
| <script type="module" src="../<%= name %>.js"></script> | ||
|
|
||
| <custom-style> | ||
| <style is="custom-style" include="demo-pages-shared-styles"> | ||
| </style> | ||
| </custom-style> | ||
| </head> | ||
| <body> | ||
| <div class="vertical-section-container centered"> | ||
| <h3>Basic <%= name %> demo</h3> | ||
| <demo-snippet> | ||
| <template> | ||
| <<%= name %>></<%= name %>> | ||
| </template> | ||
| </demo-snippet> | ||
| </div> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta http-equiv="refresh" content="0;url=demo/" /> | ||
| <title><%= name %></title> | ||
| </head> | ||
| <body> | ||
| <!-- | ||
| Visit demo/index.html to see live examples of your element running. | ||
| This page will automatically redirect you there when run in the browser | ||
| with `polymer serve`. | ||
| --> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "name": "<%= name %>", | ||
| <% if (description) { -%> "description": "<%= description %>", | ||
| <% } -%> | ||
| "main": "<%= name %>.js", | ||
| "dependencies": { | ||
| "@polymer/polymer": "^3.0.0-pre.12" | ||
| }, | ||
| "devDependencies": { | ||
| "@polymer/iron-demo-helpers": "^3.0.0-pre.12", | ||
| "@webcomponents/webcomponentsjs": "^1.0.0", | ||
| "wct-browser-legacy": "^0.0.1-pre.11" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "npm": true, | ||
| "moduleResolution": "node" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes"> | ||
|
|
||
| <title><%= name %> test</title> | ||
|
|
||
| <script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script> | ||
| <script src="../node_modules/wct-browser-legacy/browser.js"></script> | ||
|
|
||
| <script type="module" src="../<%= name %>.js"></script> | ||
| </head> | ||
| <body> | ||
|
|
||
| <test-fixture id="BasicTestFixture"> | ||
| <template> | ||
| <<%= name %>></<%= name %>> | ||
| </template> | ||
| </test-fixture> | ||
|
|
||
| <test-fixture id="ChangedPropertyTestFixture"> | ||
| <template> | ||
| <<%= name %> prop1="new-prop1"></<%= name %>> | ||
| </template> | ||
| </test-fixture> | ||
|
|
||
| <script type="module"> | ||
| suite('<%= name %>', () => { | ||
|
|
||
| test('instantiating the element with default properties works', () => { | ||
| const element = fixture('BasicTestFixture'); | ||
| assert.equal(element.prop1, '<%= name %>'); | ||
| const elementShadowRoot = element.shadowRoot; | ||
| const elementHeader = elementShadowRoot.querySelector('h2'); | ||
| assert.equal(elementHeader.innerHTML, 'Hello <%= name %>!'); | ||
| }); | ||
|
|
||
| test('setting a property on the element works', () => { | ||
| // Create a test fixture | ||
| const element = fixture('ChangedPropertyTestFixture'); | ||
| assert.equal(element.prop1, 'new-prop1'); | ||
| const elementShadowRoot = element.shadowRoot; | ||
| const elementHeader = elementShadowRoot.querySelector('h2'); | ||
| assert.equal(elementHeader.innerHTML, 'Hello new-prop1!'); | ||
| }); | ||
|
|
||
| }); | ||
| </script> | ||
|
|
||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> | ||
|
|
||
| <script src="../node_modules/wct-browser-legacy/browser.js"></script> | ||
| </head> | ||
| <body> | ||
| <script> | ||
| // Load and run all tests (.html, .js): | ||
| WCT.loadSuites([ | ||
| '<%= name %>_test.html' | ||
| ]); | ||
| </script> | ||
| </body> | ||
| </html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a mention of yeoman/generator#1065 here with these
not a no-opcomments.