| 
									
										
										
										
											2017-07-15 16:38:10 +01:00
										 |  |  | # Overview
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | Many of the documentation pages contain snippets of code examples. Extract these snippets from | 
					
						
							| 
									
										
										
										
											2017-09-21 11:16:27 +01:00
										 |  |  | real working example applications, which are stored in subfolders of the `/aio/content/examples` | 
					
						
							|  |  |  | folder. Each example can be built and run independently. Each example also provides e2e specs, which | 
					
						
							|  |  |  | are run as part of our Travis build tasks, to verify that the examples continue to work as expected, | 
					
						
							|  |  |  | as changes are made to the core Angular libraries. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | In order to build, run and test these examples independently you need to install dependencies into | 
					
						
							| 
									
										
										
										
											2017-09-21 11:16:27 +01:00
										 |  |  | their sub-folder. Also there are a number of common boilerplate files that are needed to configure | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | each example's project. Maintain these common boilerplate files centrally to reduce the amount | 
					
						
							| 
									
										
										
										
											2017-09-21 11:16:27 +01:00
										 |  |  | of effort if one of them needs to change. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | ## Boilerplate overview
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 11:16:27 +01:00
										 |  |  | As mentioned, many of the documentation pages contain snippets extracted from real example applications. | 
					
						
							|  |  |  | To achieve that, all those applications needs to contain a basic boilerplate. E.g. a `node_modules` | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | folder, `package.json` with scripts, etc. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 11:16:27 +01:00
										 |  |  | No one wants to maintain the boilerplate on each example, so the goal of this tool is to provide a | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | set of boilerplates that works in all the examples. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | ### Boilerplate files
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | Inside `/aio/tools/examples/shared/boilerplate` you will find a set of folders representing each | 
					
						
							|  |  |  | boilerplate. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | Currently you will find the next boilerplates: | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | * CLI - For CLI based examples. This is the default one, to be used in the majority of the examples. | 
					
						
							|  |  |  | * systemjs - Currently in deprecation, only used in a a few examples. | 
					
						
							|  |  |  | * i18n - Based on the CLI one, features a few scripts for i18n. | 
					
						
							|  |  |  | * universal - Based on the cli with a extra server for universal. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | There is also a `common` folder that contains files used in all different examples. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | ### The example-config.json
 | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | Each example is identified by an **example-config.json** configuration file in its root folder. | 
					
						
							|  |  |  | This configuration file indicates what type of boilerplate this example needs. E.g. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```json | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | { projectType: 'universal' } | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | If the file is empty then the default type of cli is assumed. | 
					
						
							|  |  |  | When the boilerplate tooling runs, it will copy into the example folder all of the appropriate boilerplate files. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | ### A node_modules to share
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 11:16:27 +01:00
										 |  |  | With all the boilerplate files in place, the only missing piece are the installed packages. For | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | that you have a `/aio/tools/examples/shared/package.json` which contains **all** the packages | 
					
						
							|  |  |  | needed to run all the examples through all different boilerplates. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 11:16:27 +01:00
										 |  |  | After installing these dependencies, a `node_modules` will be created at | 
					
						
							|  |  |  | `/aio/tools/examples/shared/node_modules`. This folder will be **symlinked** into each example. | 
					
						
							|  |  |  | So it is not a copy like the other boilerplate files. This solution works in all OSes. Windows | 
					
						
							|  |  |  | may require admin rights. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | ### End to end tests
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | End to end changes between boilerplates. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | For CLI applications, create a `app.e2e-spec.ts` inside the `e2e` folder. The tooling will run | 
					
						
							|  |  |  | `ng e2e` for each CLI based examples. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-30 14:38:30 +01:00
										 |  |  | For SystemJS, each example contains an `e2e-spec.ts` file. You can find all the related configuration files | 
					
						
							|  |  |  | in the `/aio/tools/examples/shared` folder. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-21 16:48:14 -05:00
										 |  |  | ### example-boilerplate.js
 | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 11:16:27 +01:00
										 |  |  | This script installs all the dependencies that are shared among all the examples, creates the | 
					
						
							|  |  |  | `node_modules` symlinks and copy all the boilerplate files where needed. It won't do anything | 
					
						
							| 
									
										
										
										
											2017-11-03 18:08:28 +01:00
										 |  |  | about stackblitz nor e2e tests. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 11:16:27 +01:00
										 |  |  | It also contains a function to remove all the boilerplate. It uses a `git clean -xdf` to do | 
					
						
							|  |  |  | the job. It will remove all files that don't exist in the git repository, **including any | 
					
						
							|  |  |  | new file that you are working on that hasn't been stage yet.** So be sure to save your work | 
					
						
							|  |  |  | before removing the boilerplate. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | ### run-example-e2e.js
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This script will find all the `e2e-spec.ts` files and run them. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 11:16:27 +01:00
										 |  |  | To not run all tests, you can use the `--filter=name` flag to run the example's e2e that contains | 
					
						
							|  |  |  | that name. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-21 16:48:14 -05:00
										 |  |  | It also has an optional `--setup` flag to run the `example-boilerplate.js` script and install | 
					
						
							| 
									
										
										
										
											2017-09-21 11:16:27 +01:00
										 |  |  | the latest `webdriver`. | 
					
						
							| 
									
										
										
										
											2017-07-18 16:17:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | It will create a `/aio/protractor-results-txt` file when it finishes running tests. |