diff --git a/packages/cli/gulpfile.js b/packages/cli/gulpfile.js index e8d79916f..28a2e82e3 100644 --- a/packages/cli/gulpfile.js +++ b/packages/cli/gulpfile.js @@ -81,6 +81,9 @@ gulp.task('depcheck', ['build'], () => { 'babel-plugin-external-helpers', 'polymer-bundler', ], + ignoreDirs: [ + 'templates', + ], }) .then((result) => { let invalidFiles = Object.keys(result.invalidFiles) || []; diff --git a/packages/cli/src/init/application/application.ts b/packages/cli/src/init/application/application.ts index 7927d72fb..d2b898c42 100644 --- a/packages/cli/src/init/application/application.ts +++ b/packages/cli/src/init/application/application.ts @@ -28,7 +28,7 @@ export function createApplicationGenerator(templateName: string): constructor(args: string|string[], options: any) { super(args, options); - this.sourceRoot(path.join(__dirname, 'templates', templateName)); + this.sourceRoot(path.join(__dirname, '../../../templates/application', templateName)); } // This is necessary to prevent an exception in Yeoman when creating @@ -116,4 +116,4 @@ export function createApplicationGenerator(templateName: string): 'Check out your new project README for information about what to do next.\n'); } }; -} \ No newline at end of file +} diff --git a/packages/cli/src/init/element/element.ts b/packages/cli/src/init/element/element.ts index a137a2c69..86b5207d1 100644 --- a/packages/cli/src/init/element/element.ts +++ b/packages/cli/src/init/element/element.ts @@ -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,66 @@ export function createElementGenerator(templateName: string): 'Check out your new project README for information about what to do next.\n'); } }; + + class Polymer3ElementGenerator extends ElementGenerator { + // TODO(yeoman/generator#1065): This is function not a no-op: Yeoman only + // 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 + // 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 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, + }); + } + + // TODO(yeoman/generator#1065): This is function not a no-op: Yeoman only + // 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 Polymer3ElementGenerator; + default: + return ElementGenerator; + } } diff --git a/packages/cli/src/init/init.ts b/packages/cli/src/init/init.ts index ab1274fe6..f50399f58 100644 --- a/packages/cli/src/init/init.ts +++ b/packages/cli/src/init/init.ts @@ -39,6 +39,11 @@ interface GeneratorInfo { } const localGenerators: {[name: string]: GeneratorInfo} = { + 'polymer-3-element': { + id: 'polymer-init-polymer-3-element:app', + description: 'A simple Polymer 3.0 element template', + generator: createElementGenerator('polymer-3.x'), + }, 'polymer-2-element': { id: 'polymer-init-polymer-2-element:app', description: 'A simple Polymer 2.0 element template', diff --git a/packages/cli/src/test/integration/integration_test.ts b/packages/cli/src/test/integration/integration_test.ts index 2ac9d7e84..4498861f1 100644 --- a/packages/cli/src/test/integration/integration_test.ts +++ b/packages/cli/src/test/integration/integration_test.ts @@ -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 + 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 diff --git a/packages/cli/src/init/application/templates/polymer-1.x/.gitignore b/packages/cli/templates/application/polymer-1.x/.gitignore similarity index 100% rename from packages/cli/src/init/application/templates/polymer-1.x/.gitignore rename to packages/cli/templates/application/polymer-1.x/.gitignore diff --git a/packages/cli/src/init/application/templates/polymer-1.x/README.md b/packages/cli/templates/application/polymer-1.x/README.md similarity index 100% rename from packages/cli/src/init/application/templates/polymer-1.x/README.md rename to packages/cli/templates/application/polymer-1.x/README.md diff --git a/packages/cli/src/init/application/templates/polymer-1.x/bower.json b/packages/cli/templates/application/polymer-1.x/bower.json similarity index 100% rename from packages/cli/src/init/application/templates/polymer-1.x/bower.json rename to packages/cli/templates/application/polymer-1.x/bower.json diff --git a/packages/cli/src/init/application/templates/polymer-1.x/index.html b/packages/cli/templates/application/polymer-1.x/index.html similarity index 100% rename from packages/cli/src/init/application/templates/polymer-1.x/index.html rename to packages/cli/templates/application/polymer-1.x/index.html diff --git a/packages/cli/src/init/application/templates/polymer-1.x/manifest.json b/packages/cli/templates/application/polymer-1.x/manifest.json similarity index 100% rename from packages/cli/src/init/application/templates/polymer-1.x/manifest.json rename to packages/cli/templates/application/polymer-1.x/manifest.json diff --git a/packages/cli/src/init/application/templates/polymer-1.x/polymer.json b/packages/cli/templates/application/polymer-1.x/polymer.json similarity index 100% rename from packages/cli/src/init/application/templates/polymer-1.x/polymer.json rename to packages/cli/templates/application/polymer-1.x/polymer.json diff --git a/packages/cli/src/init/application/templates/polymer-1.x/src/_element/_element.html b/packages/cli/templates/application/polymer-1.x/src/_element/_element.html similarity index 100% rename from packages/cli/src/init/application/templates/polymer-1.x/src/_element/_element.html rename to packages/cli/templates/application/polymer-1.x/src/_element/_element.html diff --git a/packages/cli/src/init/application/templates/polymer-1.x/test/_element/_element_test.html b/packages/cli/templates/application/polymer-1.x/test/_element/_element_test.html similarity index 100% rename from packages/cli/src/init/application/templates/polymer-1.x/test/_element/_element_test.html rename to packages/cli/templates/application/polymer-1.x/test/_element/_element_test.html diff --git a/packages/cli/src/init/application/templates/polymer-2.x/.gitignore b/packages/cli/templates/application/polymer-2.x/.gitignore similarity index 100% rename from packages/cli/src/init/application/templates/polymer-2.x/.gitignore rename to packages/cli/templates/application/polymer-2.x/.gitignore diff --git a/packages/cli/src/init/application/templates/polymer-2.x/README.md b/packages/cli/templates/application/polymer-2.x/README.md similarity index 100% rename from packages/cli/src/init/application/templates/polymer-2.x/README.md rename to packages/cli/templates/application/polymer-2.x/README.md diff --git a/packages/cli/src/init/application/templates/polymer-2.x/bower.json b/packages/cli/templates/application/polymer-2.x/bower.json similarity index 100% rename from packages/cli/src/init/application/templates/polymer-2.x/bower.json rename to packages/cli/templates/application/polymer-2.x/bower.json diff --git a/packages/cli/src/init/application/templates/polymer-2.x/index.html b/packages/cli/templates/application/polymer-2.x/index.html similarity index 100% rename from packages/cli/src/init/application/templates/polymer-2.x/index.html rename to packages/cli/templates/application/polymer-2.x/index.html diff --git a/packages/cli/src/init/application/templates/polymer-2.x/manifest.json b/packages/cli/templates/application/polymer-2.x/manifest.json similarity index 100% rename from packages/cli/src/init/application/templates/polymer-2.x/manifest.json rename to packages/cli/templates/application/polymer-2.x/manifest.json diff --git a/packages/cli/src/init/application/templates/polymer-2.x/polymer.json b/packages/cli/templates/application/polymer-2.x/polymer.json similarity index 100% rename from packages/cli/src/init/application/templates/polymer-2.x/polymer.json rename to packages/cli/templates/application/polymer-2.x/polymer.json diff --git a/packages/cli/src/init/application/templates/polymer-2.x/src/_element/_element.html b/packages/cli/templates/application/polymer-2.x/src/_element/_element.html similarity index 100% rename from packages/cli/src/init/application/templates/polymer-2.x/src/_element/_element.html rename to packages/cli/templates/application/polymer-2.x/src/_element/_element.html diff --git a/packages/cli/src/init/application/templates/polymer-2.x/test/_element/_element_test.html b/packages/cli/templates/application/polymer-2.x/test/_element/_element_test.html similarity index 100% rename from packages/cli/src/init/application/templates/polymer-2.x/test/_element/_element_test.html rename to packages/cli/templates/application/polymer-2.x/test/_element/_element_test.html diff --git a/packages/cli/src/init/element/templates/polymer-1.x/.gitignore b/packages/cli/templates/element/polymer-1.x/.gitignore similarity index 100% rename from packages/cli/src/init/element/templates/polymer-1.x/.gitignore rename to packages/cli/templates/element/polymer-1.x/.gitignore diff --git a/packages/cli/src/init/element/templates/polymer-1.x/README.md b/packages/cli/templates/element/polymer-1.x/README.md similarity index 100% rename from packages/cli/src/init/element/templates/polymer-1.x/README.md rename to packages/cli/templates/element/polymer-1.x/README.md diff --git a/packages/cli/src/init/element/templates/polymer-1.x/_element.html b/packages/cli/templates/element/polymer-1.x/_element.html similarity index 100% rename from packages/cli/src/init/element/templates/polymer-1.x/_element.html rename to packages/cli/templates/element/polymer-1.x/_element.html diff --git a/packages/cli/src/init/element/templates/polymer-1.x/bower.json b/packages/cli/templates/element/polymer-1.x/bower.json similarity index 100% rename from packages/cli/src/init/element/templates/polymer-1.x/bower.json rename to packages/cli/templates/element/polymer-1.x/bower.json diff --git a/packages/cli/src/init/element/templates/polymer-1.x/demo/index.html b/packages/cli/templates/element/polymer-1.x/demo/index.html similarity index 100% rename from packages/cli/src/init/element/templates/polymer-1.x/demo/index.html rename to packages/cli/templates/element/polymer-1.x/demo/index.html diff --git a/packages/cli/src/init/element/templates/polymer-1.x/index.html b/packages/cli/templates/element/polymer-1.x/index.html similarity index 100% rename from packages/cli/src/init/element/templates/polymer-1.x/index.html rename to packages/cli/templates/element/polymer-1.x/index.html diff --git a/packages/cli/src/init/element/templates/polymer-1.x/polymer.json b/packages/cli/templates/element/polymer-1.x/polymer.json similarity index 100% rename from packages/cli/src/init/element/templates/polymer-1.x/polymer.json rename to packages/cli/templates/element/polymer-1.x/polymer.json diff --git a/packages/cli/src/init/element/templates/polymer-1.x/test/_element_test.html b/packages/cli/templates/element/polymer-1.x/test/_element_test.html similarity index 100% rename from packages/cli/src/init/element/templates/polymer-1.x/test/_element_test.html rename to packages/cli/templates/element/polymer-1.x/test/_element_test.html diff --git a/packages/cli/src/init/element/templates/polymer-1.x/test/index.html b/packages/cli/templates/element/polymer-1.x/test/index.html similarity index 100% rename from packages/cli/src/init/element/templates/polymer-1.x/test/index.html rename to packages/cli/templates/element/polymer-1.x/test/index.html diff --git a/packages/cli/src/init/element/templates/polymer-2.x/.gitignore b/packages/cli/templates/element/polymer-2.x/.gitignore similarity index 100% rename from packages/cli/src/init/element/templates/polymer-2.x/.gitignore rename to packages/cli/templates/element/polymer-2.x/.gitignore diff --git a/packages/cli/src/init/element/templates/polymer-2.x/README.md b/packages/cli/templates/element/polymer-2.x/README.md similarity index 100% rename from packages/cli/src/init/element/templates/polymer-2.x/README.md rename to packages/cli/templates/element/polymer-2.x/README.md diff --git a/packages/cli/src/init/element/templates/polymer-2.x/_element.html b/packages/cli/templates/element/polymer-2.x/_element.html similarity index 100% rename from packages/cli/src/init/element/templates/polymer-2.x/_element.html rename to packages/cli/templates/element/polymer-2.x/_element.html diff --git a/packages/cli/src/init/element/templates/polymer-2.x/bower.json b/packages/cli/templates/element/polymer-2.x/bower.json similarity index 100% rename from packages/cli/src/init/element/templates/polymer-2.x/bower.json rename to packages/cli/templates/element/polymer-2.x/bower.json diff --git a/packages/cli/src/init/element/templates/polymer-2.x/demo/index.html b/packages/cli/templates/element/polymer-2.x/demo/index.html similarity index 100% rename from packages/cli/src/init/element/templates/polymer-2.x/demo/index.html rename to packages/cli/templates/element/polymer-2.x/demo/index.html diff --git a/packages/cli/src/init/element/templates/polymer-2.x/index.html b/packages/cli/templates/element/polymer-2.x/index.html similarity index 100% rename from packages/cli/src/init/element/templates/polymer-2.x/index.html rename to packages/cli/templates/element/polymer-2.x/index.html diff --git a/packages/cli/src/init/element/templates/polymer-2.x/polymer.json b/packages/cli/templates/element/polymer-2.x/polymer.json similarity index 100% rename from packages/cli/src/init/element/templates/polymer-2.x/polymer.json rename to packages/cli/templates/element/polymer-2.x/polymer.json diff --git a/packages/cli/src/init/element/templates/polymer-2.x/test/_element_test.html b/packages/cli/templates/element/polymer-2.x/test/_element_test.html similarity index 100% rename from packages/cli/src/init/element/templates/polymer-2.x/test/_element_test.html rename to packages/cli/templates/element/polymer-2.x/test/_element_test.html diff --git a/packages/cli/src/init/element/templates/polymer-2.x/test/index.html b/packages/cli/templates/element/polymer-2.x/test/index.html similarity index 100% rename from packages/cli/src/init/element/templates/polymer-2.x/test/index.html rename to packages/cli/templates/element/polymer-2.x/test/index.html diff --git a/packages/cli/templates/element/polymer-3.x/.gitignore b/packages/cli/templates/element/polymer-3.x/.gitignore new file mode 100644 index 000000000..2ccbe4656 --- /dev/null +++ b/packages/cli/templates/element/polymer-3.x/.gitignore @@ -0,0 +1 @@ +/node_modules/ diff --git a/packages/cli/templates/element/polymer-3.x/README.md b/packages/cli/templates/element/polymer-3.x/README.md new file mode 100644 index 000000000..6de431292 --- /dev/null +++ b/packages/cli/templates/element/polymer-3.x/README.md @@ -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. diff --git a/packages/cli/templates/element/polymer-3.x/_element.js b/packages/cli/templates/element/polymer-3.x/_element.js new file mode 100644 index 000000000..64dae6bd1 --- /dev/null +++ b/packages/cli/templates/element/polymer-3.x/_element.js @@ -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 ` + +