Skip to content
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

Adds a Polymer 3 application template to init. #134

Merged
merged 25 commits into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1438c47
Copy `polymer-2.x` template to `polymer-3.x`.
bicknellr Apr 11, 2018
d3f365a
Update `init` and associated polymer-3.x template.
bicknellr Apr 11, 2018
5d116f7
Update `README.md`.
bicknellr Apr 11, 2018
5e3f069
Format, excluding broken changes due to templating.
bicknellr Apr 11, 2018
ade3349
Merge remote-tracking branch 'origin/master' into init-3.x-element
bicknellr Apr 12, 2018
1b00b80
Merge remote-tracking branch 'origin/master' into init-3.x-element
bicknellr Apr 12, 2018
1e1439c
Move templates to a folder in the package root so that they aren't ch…
bicknellr Apr 12, 2018
a171316
copy templates/application/polymer-2.x -> templates/application/polym…
bicknellr Apr 12, 2018
8cc1278
Update Polymer 3 application template.
bicknellr Apr 12, 2018
96cc7a1
Merge remote-tracking branch 'origin/master' into init-3.x-application
bicknellr Apr 13, 2018
0770fd9
Add pass-through functions for Yeoman bug.
bicknellr Apr 13, 2018
baebd79
Add an integration test for the Polymer 3 application template.
bicknellr Apr 13, 2018
505288d
Remove unused `static get is()` from the default app element.
bicknellr Apr 13, 2018
b9fa899
Remove `main` field from `package.json`.
bicknellr Apr 13, 2018
58e9741
Merge remote-tracking branch 'origin/master' into init-3.x-application
bicknellr Apr 13, 2018
e5e1613
Merge remote-tracking branch 'origin/master' into init-3.x-application
bicknellr Apr 16, 2018
e1e0e42
Merge remote-tracking branch 'origin/master' into init-3.x-application
bicknellr Apr 16, 2018
4355555
Merge remote-tracking branch 'origin/master' into init-3.x-application
bicknellr Apr 16, 2018
5fd0241
Add `polymer lint` to Polymer 3 application template `polymer.json` a…
bicknellr Apr 16, 2018
4bee9c0
Fix Polymer 3 application template `.gitignore`.
bicknellr Apr 16, 2018
56b2b05
Merge remote-tracking branch 'origin/master' into init-3.x-application
bicknellr Apr 16, 2018
1ce3570
Merge remote-tracking branch 'origin/master' into init-3.x-application
bicknellr Apr 17, 2018
09dba2e
Merge remote-tracking branch 'origin/master' into init-3.x-application
bicknellr Apr 17, 2018
62068bc
Use CLI for installation instead of `npm` directly.
bicknellr Apr 17, 2018
1316549
Fix comment typos.
bicknellr Apr 17, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion packages/cli/src/init/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Generator = require('yeoman-generator');
*/
export function createApplicationGenerator(templateName: string):
(typeof Generator) {
return class ApplicationGenerator extends Generator {
class ApplicationGenerator extends Generator {
props: any;

constructor(args: string|string[], options: any) {
Expand Down Expand Up @@ -116,4 +116,65 @@ export function createApplicationGenerator(templateName: string):
'Check out your new project README for information about what to do next.\n');
}
};

class Polymer3ApplicationGenerator extends ApplicationGenerator {
// TODO(yeoman/generator#1065): This is function not a no-op: Yeoman only
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, typo:

is function not -> is not

// checks the object's prototype's own properties for generator task
// methods. http://yeoman.io/authoring/running-context.html
initializing() {
return super.initializing();
}

// TODO(yeoman/generator#1065): This is function not a no-op: Yeoman only
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

// checks the object's prototype's own properties for generator task
// methods. http://yeoman.io/authoring/running-context.html
async prompting() {
return super.prompting();
}

writing() {
const elementName = this.props.elementName;

this.fs.copyTpl(
`${this.templatePath()}/**/?(.)!(_)*`,
this.destinationPath(),
this.props);

this.fs.copyTpl(
this.templatePath('src/_element/_element.js'),
`src/${elementName}/${elementName}.js`,
this.props);

this.fs.copyTpl(
this.templatePath('test/_element/_element_test.html'),
`test/${elementName}/${elementName}_test.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,
});
}

// TODO(yeoman/generator#1065): This is function not a no-op: Yeoman only
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

// checks the object's prototype's own properties for generator task
// methods. http://yeoman.io/authoring/running-context.html
end() {
return super.end();
}
}

switch (templateName) {
case 'polymer-3.x':
return Polymer3ApplicationGenerator;
default:
return ApplicationGenerator;
}
}
5 changes: 5 additions & 0 deletions packages/cli/src/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ const localGenerators: {[name: string]: GeneratorInfo} = {
description: 'A simple Polymer 3.0 element template',
generator: createElementGenerator('polymer-3.x'),
},
'polymer-3-application': {
id: 'polymer-init-polymer-3-application:app',
description: 'A simple Polymer 3.0 application',
generator: createApplicationGenerator('polymer-3.x'),
},
'polymer-2-element': {
id: 'polymer-init-polymer-2-element:app',
description: 'A simple Polymer 2.0 element template',
Expand Down
18 changes: 18 additions & 0 deletions packages/cli/src/test/integration/integration_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ suite('integration tests', function() {
await runCommand(binPath, ['test', '--module-resolution=node'], {cwd: dir});
});

skipOnWindows('test the Polymer 3.x application template', async () => {
const dir =
await runGenerator(createApplicationGenerator('polymer-3.x'))
.withPrompts({name: 'my-app'}) // Mock the prompt answers
.toPromise();
// TODO(#118): Use `polymer install` once it supports installing npm
// packages.
await exec('npm install', {cwd: dir});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@bicknellr bicknellr Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, #136 safely rewrites the exec used here. :) (edit: ..and was merged.)


await runCommand(binPath, ['lint'], {cwd: dir});

// TODO(#113): Remove the `--module-resolution=node` argument once
// `polymer test` passes them in correctly
await runCommand(binPath, ['test', '--module-resolution=node'], {cwd: dir});

await runCommand(binPath, ['build'], {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
Expand Down
1 change: 1 addition & 0 deletions packages/cli/templates/application/polymer-3.x/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
33 changes: 33 additions & 0 deletions packages/cli/templates/application/polymer-3.x/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# \<<%= name %>\>

<%= description %>

## Install the Polymer-CLI

First, make sure you have the [Polymer CLI](https://www.npmjs.com/package/polymer-cli) installed. Then run `polymer serve` to serve your application locally.

## Viewing Your Application

```
$ polymer serve
```

## Building Your Application

```
$ polymer build
```

This will create builds of your application in the `build/` directory, optimized to be served in production. You can then serve the built versions by giving `polymer serve` a folder to serve from:

```
$ polymer serve build/default
```

## 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.
22 changes: 22 additions & 0 deletions packages/cli/templates/application/polymer-3.x/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!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 %></title>
<meta name="description" content="<%
if (description) { -%><%= description %><% } else { -%><%= name %> description<% }
-%>">

<!-- See https://goo.gl/OOhYW5 -->
<link rel="manifest" href="/manifest.json">

<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>

<script type="module" src="/src/<%= elementName %>/<%= elementName %>.js"></script>
</head>
<body>
<<%= elementName %>></<%= elementName %>>
</body>
</html>
8 changes: 8 additions & 0 deletions packages/cli/templates/application/polymer-3.x/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "<%= name %>",
"short_name": "<%= name %>",
<% if (description) { -%> "description": "<%= description %>",
<% } -%>
"start_url": "/",
"display": "standalone"
}
12 changes: 12 additions & 0 deletions packages/cli/templates/application/polymer-3.x/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "<%= name %>",
<% if (description) { -%> "description": "<%= description %>",
<% } -%>
"dependencies": {
"@polymer/polymer": "^3.0.0-pre.12"
},
"devDependencies": {
"@webcomponents/webcomponentsjs": "^1.0.0",
"wct-browser-legacy": "^0.0.1-pre.11"
}
}
9 changes: 9 additions & 0 deletions packages/cli/templates/application/polymer-3.x/polymer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"npm": true,
"moduleResolution": "node",
"lint": {
"rules": [
"polymer-3"
]
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add lint rules: #142.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {PolymerElement} from '@polymer/polymer/polymer-element.js';

/**
* @customElement
* @polymer
*/
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: '<%= elementName %>'
}
};
}
}

window.customElements.define('<%= elementName %>', <%= elementClassName %>);
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!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><%= elementName %> 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="../../src/<%= elementName %>/<%= elementName %>.js"></script>
</head>
<body>

<test-fixture id="BasicTestFixture">
<template>
<<%= elementName %>></<%= elementName %>>
</template>
</test-fixture>

<test-fixture id="ChangedPropertyTestFixture">
<template>
<<%= elementName %> prop1="new-prop1"></<%= elementName %>>
</template>
</test-fixture>

<script>
suite('<%= elementName %>', function() {

test('instantiating the element with default properties works', function() {
var element = fixture('BasicTestFixture');
assert.equal(element.prop1, '<%= elementName %>');
var elementShadowRoot = element.shadowRoot;
var elementHeader = elementShadowRoot.querySelector('h2');
assert.equal(elementHeader.innerHTML, 'Hello <%= elementName %>!');
});

test('setting a property on the element works', function() {
// Create a test fixture
var element = fixture('ChangedPropertyTestFixture');
assert.equal(element.prop1, 'new-prop1');
var elementShadowRoot = element.shadowRoot;
var elementHeader = elementShadowRoot.querySelector('h2');
assert.equal(elementHeader.innerHTML, 'Hello new-prop1!');
});

});
</script>


</body>
</html>