diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..b8a6e5723 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +# http://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + + +[*.md] +max_line_length = 0 +trim_trailing_whitespace = false + +# Indentation override +#[lib/**.js] +#[{package.json,.travis.yml}] +#[**/**.js] diff --git a/.gitignore b/.gitignore index 5fd454991..9b3a09fc9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,14 @@ -typings/ -node_modules/ -*.js -*.js.map \ No newline at end of file +.idea +node_modules +jspm_packages +npm-debug.log +debug.log +src/**/*.js +!src/systemjs.config.extras.js +!src/systemjs.config.js +!src/systemjs-angular-loader.js +*.js.map +e2e/**/*.js +e2e/**/*.js.map +_test-output +_temp diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..808bc2c4e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +dist: trusty +sudo: required +language: node_js +node_js: + - "5" +os: + - linux +env: + global: + - DBUS_SESSION_BUS_ADDRESS=/dev/null + - DISPLAY=:99.0 + - CHROME_BIN=chromium-browser +before_script: + - sh -e /etc/init.d/xvfb start +install: + - npm install +script: + - npm run lint + - npm run test:once + - npm run e2e diff --git a/CHANGELOG.md b/CHANGELOG.md index 8959763b6..4c991b119 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,197 @@ +## Angular Documentation QuickStart Changelog +Upgraders: for a fresh start, consider running these commands +* `git clean -xdf` +* `npm install` + + +# 0.4.1 (2017-03-24) +* Replace systemjs-angular-loader with version that works for IE + + +# 0.4.0 (2017-03-24) +* Update to Angular 4.0.0 + + +# 0.3.0 (2017-03-22) +* Remove moduleId with a systemjs loader. + + +# 0.2.22 (2017-01-05) +* Add `non-essential-files.txt` and instructions to use it to README + + +# 0.2.21 (2016-12-14) +* Update to in-memory-web-api v.0.2.1 + + +# 0.2.20 (2016-12-07) +* Update to Angular 2.3.0 + + +# 0.2.19 (2016-11-30) +* remove upgrade mappings from `systemjs.config.js` PR #301 + + +# 0.2.18 (2016-11-30) +* remove `exclude` clause from `tsconfig.json`; it was just confusing people +* karma.config + karma-test-shim can handle multiple spec source paths (issue #294) +* cosmetic `app.component.spec.ts` changes +* cosmetic `karma.config.js` changes + + +# 0.2.17 (2016-11-16) +* Conform to updated QuickStart advice + * removed docker everywhere (was nice but not necessary) + * removed wallaby + * shrink styles.css + * refine tsconfig.json + * `AppComponent` uses interpolation + + +# 0.2.16 (2016-11-14) +* Update to Angular 2.2.0 + + +# 0.2.15 (2016-10-29) +* Revert to Jasmine 2.4.1 because bug in 2.5.x (see [jasmine issue #1231](https://github.com/jasmine/jasmine/issues/1231)) + + +# 0.2.14 (2016-10-29) +* Remove bootstrap.css install +* Angular v2.1.2 + + +# 0.2.13 (2016-10-20) +* Protractor 4 +* Move from `typings` to `@types`. See `tsconfig.json` changes. +* Angular v2.1.1 + + +# 0.2.12 (2016-10-06) +* Angular v2.1.0 + + +# 0.2.11 (2016-10-06) +* Angular v2.0.2 +* License is MIT +* Current testing configuration +* No code changes + + +# 0.2.10 (2016-09-19) +* All "Angular 2" references become just "Angular" +* No code changes + + +# 0.2.9 (2016-09-14) +* Angular 2.0.0 version +* Update to Typescript 2.0.2 +* Fix e2e test missing dir + + +# 0.2.8 (2016-09-01) +* remove @angular test libraries from system.js (now in shim) +* update test related files +* wallaby doesn't completely work. Researching. + + +# 0.2.7 (2016-08-31) +* Angular 2 RC6 version +* Updated new forms, router, angular2-in-memory-web-api, karma, core-js, rxjs and zone.js packages +* Removed router-deprecated package +* Updated karma.conf.js and systemjs.config.js + + +# 0.2.6 (2016-08-09) +* Angular 2 RC5 version +* Updated new forms, router and angular2-in-memory-web-api + + +# 0.2.5 (2016-06-30) +* Angular 2 RC4 version +* Updated new forms and router + + +# 0.2.4 (2016-06-21) +* Angular 2 RC3 version +* Add new forms and router +* Add support for TS e2e tests + + +# 0.2.3 (2016-06-15) +* Angular 2 RC2 version + + +# 0.2.2 (2016-05-21) +* Update to Typings 1.x + + +# 0.2.1 (2016-05-03) +* Angular 2 RC01 version + + +# 0.2.0 (2016-05-02) +* Angular 2 RC0 version + + +# 0.1.17 (2016-04-29) +* update packages + * Angular 2 beta 17 + * RxJS 5.0.0-beta.6 + * a2-in-memory-web-api 0.1.17 + + +# 0.1.16 (2016-04-26) +* update packages + * Angular 2 beta 16 + * a2-in-memory-web-api 0.1.6 + * protractor 3.3.0 + * typings 0.8.1 + * zone.js 0.6.12 + + * added favicon.ico + + * testing + - updated wallaby.js and karma.conf.js + - updated app.component.spec.ts + + + +# 0.1.15 (2016-04-13) +* Add testing support + * npm scripts + * karma/jasmine + * protractor + +* update packages + * Angular 2 beta 15 + * lite-server 2.2.0 + * systemjs 0.19.26 + * typescript 1.8.10 + * typings 0.7.12 + +* add run packages + * a2-in-memory-web-api + +* add testing dev-dependency packages + * canonical-path: 0.0.2, + * http-server: ^0.9.0, + * jasmine-core: ~2.4.1, + * karma: ^0.13.22, + * karma-chrome-launcher: ^0.2.3, + * karma-cli: ^0.1.2, + * karma-htmlfile-reporter: ^0.2.2, + * karma-jasmine: ^0.3.8, + * protractor: ^3.2.2, + * rimraf: ^2.5.2 + + +# 0.1.14 (2016-04-07) +* update packages + * Angular 2 beta 14 + * lite-server 2.2.0 + * typings 0.7.12 + # 0.1.13 (2016-03-31) * update packages @@ -16,4 +210,4 @@ * Angular 2 beta 11 * zones 0.6.4 * typescript 1.8.9 - * typings 0.7.9 \ No newline at end of file + * typings 0.7.9 diff --git a/README.md b/README.md index 1ac4cc334..aeccb7d76 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,88 @@ -# Angular 2 QuickStart Source +# Angular QuickStart Source +[![Build Status][travis-badge]][travis-badge-url] + +**This repository is now deprecated. The Angular Quickstart project was a nice starting point for creating Angular applications. Now we recommend using the [Angular CLI](https://github.com/angular/angular-cli) to create new Angular projects.** + +**Starting from 1 November 2017, all the Angular documentation, at [angular.io](https://angular.io), is based on the Angular CLI.** + +**Let's [get started](https://angular.io/guide/quickstart)** + +--- This repository holds the TypeScript source code of the [angular.io quickstart](https://angular.io/docs/ts/latest/quickstart.html), the foundation for most of the documentation samples and potentially a good starting point for your application. +It's been extended with testing support so you can start writing tests immediately. + +**This is not the perfect arrangement for your application. It is not designed for production. +It exists primarily to get you started quickly with learning and prototyping in Angular** + +We are unlikely to accept suggestions about how to grow this QuickStart into something it is not. +Please keep that in mind before posting issues and PRs. + +## Updating to a newer version of the Quickstart Repo + +From time to time the QuickStart will be enhanced with support for new features or to reflect +changes to the [official Style Guide](https://angular.io/docs/ts/latest/guide/style-guide.html). + +You can update your existing project to an up-to-date QuickStart by following these instructions: +- Create a new project using the [instructions below](#create-a-new-project-based-on-the-quickstart) +- Copy the code you have in your project's `main.ts` file onto `src/app/main.ts` in the new project +- Copy your old `app` folder into `src/app` +- Delete `src/app/main.ts` if you have one (we now use `src/main.ts` instead) +- Copy your old `index.html`, `styles.css` and `tsconfig.json` into `src/` +- Install all your third party dependencies +- Copy your old `e2e/` folder into `e2e/` +- Copy over any other files you added to your project +- Copy your old `.git` folder into your new project's root + +Now you can continue working on the new project. + +## Prerequisites + +Node.js and npm are essential to Angular development. + + +Get it now if it's not already installed on your machine. + +**Verify that you are running at least node `v4.x.x` and npm `3.x.x`** +by running `node -v` and `npm -v` in a terminal/console window. +Older versions produce errors. + +We recommend [nvm](https://github.com/creationix/nvm) for managing multiple versions of node and npm. + ## Create a new project based on the QuickStart Clone this repo into new project folder (e.g., `my-proj`). -```bash -$ git clone https://github.com/angular/quickstart my-proj -$ cd my-proj +```shell +git clone https://github.com/angular/quickstart my-proj +cd my-proj ``` We have no intention of updating the source on `angular/quickstart`. -Discard everything "git-like" by deleting the `.git` folder. -```bash -$ rm -rf .git +Discard the `.git` folder.. +```shell +rm -rf .git # OS/X (bash) +rd .git /S/Q # windows +``` +### Delete _non-essential_ files (optional) + +You can quickly delete the _non-essential_ files that concern testing and QuickStart repository maintenance +(***including all git-related artifacts*** such as the `.git` folder and `.gitignore`!) +by entering the following commands while in the project folder: + +##### OS/X (bash) +```shell +xargs rm -rf < non-essential-files.osx.txt +rm src/app/*.spec*.ts +rm non-essential-files.osx.txt +``` + +##### Windows +```shell +for /f %i in (non-essential-files.txt) do del %i /F /S /Q +rd .git /s /q +rd e2e /s /q ``` ### Create a new git repo @@ -22,37 +90,106 @@ You could [start writing code](#start-development) now and throw it all away whe If you'd rather preserve your work under source control, consider taking the following steps. Initialize this project as a *local git repo* and make the first commit: -```bash -$ git init -$ git add . -$ git commit -m "Initial commit" +```shell +git init +git add . +git commit -m "Initial commit" ``` +>Recover the deleted `.gitignore` from the QuickStart repository +if you lost it in the _Delete non-essential files_ step. + Create a *remote repository* for this project on the service of your choice. Grab its address (e.g. *`https://github.com//my-proj.git`*) and push the *local repo* to the *remote*. -```bash -$ git remote add origin -$ git push -u origin master +```shell +git remote add origin +git push -u origin master ``` -### Start development +## Install npm packages + +> See npm and nvm version notes above Install the npm packages described in the `package.json` and verify that it works: -```bash -$ npm install -$ npm start +```shell +npm install +npm start ``` + +>Doesn't work in _Bash for Windows_ which does not support servers as of January, 2017. + +The `npm start` command first compiles the application, +then simultaneously re-compiles and runs the `lite-server`. +Both the compiler and the server watch for file changes. + +Shut it down manually with `Ctrl-C`. + You're ready to write your application. -Remember the npm scripts in `package.json`: +### npm scripts + +We've captured many of the most useful commands in npm scripts defined in the `package.json`: * `npm start` - runs the compiler and a server at the same time, both in "watch mode". -* `npm run tsc` - runs the TypeScript compiler once. -* `npm run tsc:w` - runs the TypeScript compiler in watch mode; the process keeps running, awaiting changes to TypeScript files and re-compiling when it sees them. -* `npm run lite` - runs the [lite-server](https://www.npmjs.com/package/lite-server), a light-weight, static file server, written and maintained by +* `npm run build` - runs the TypeScript compiler once. +* `npm run build:w` - runs the TypeScript compiler in watch mode; the process keeps running, awaiting changes to TypeScript files and re-compiling when it sees them. +* `npm run serve` - runs the [lite-server](https://www.npmjs.com/package/lite-server), a light-weight, static file server, written and maintained by [John Papa](https://github.com/johnpapa) and [Christopher Martin](https://github.com/cgmartin) with excellent support for Angular apps that use routing. -* `npm run typings` - runs the typings tool. -* `npm run postinstall` - called by *npm* automatically *after* it successfully completes package installation. This script installs the TypeScript definition files this app requires. + +Here are the test related scripts: +* `npm test` - compiles, runs and watches the karma unit tests +* `npm run e2e` - compiles and run protractor e2e tests, written in Typescript (*e2e-spec.ts) + +## Testing + +The QuickStart documentation doesn't discuss testing. +This repo adds both karma/jasmine unit test and protractor end-to-end testing support. + +These tools are configured for specific conventions described below. + +*It is unwise and rarely possible to run the application, the unit tests, and the e2e tests at the same time. +We recommend that you shut down one before starting another.* + +### Unit Tests +TypeScript unit-tests are usually in the `src/app` folder. Their filenames must end in `.spec.ts`. + +Look for the example `src/app/app.component.spec.ts`. +Add more `.spec.ts` files as you wish; we configured karma to find them. + +Run it with `npm test` + +That command first compiles the application, then simultaneously re-compiles and runs the karma test-runner. +Both the compiler and the karma watch for (different) file changes. + +Shut it down manually with `Ctrl-C`. + +Test-runner output appears in the terminal window. +We can update our app and our tests in real-time, keeping a weather eye on the console for broken tests. +Karma is occasionally confused and it is often necessary to shut down its browser or even shut the command down (`Ctrl-C`) and +restart it. No worries; it's pretty quick. + +### End-to-end (E2E) Tests + +E2E tests are in the `e2e` directory, side by side with the `src` folder. +Their filenames must end in `.e2e-spec.ts`. + +Look for the example `e2e/app.e2e-spec.ts`. +Add more `.e2e-spec.js` files as you wish (although one usually suffices for small projects); +we configured Protractor to find them. + +Thereafter, run them with `npm run e2e`. + +That command first compiles, then simultaneously starts the `lite-server` at `localhost:8080` +and launches Protractor. + +The pass/fail test results appear at the bottom of the terminal window. +A custom reporter (see `protractor.config.js`) generates a `./_test-output/protractor-results.txt` file +which is easier to read; this file is excluded from source control. + +Shut it down manually with `Ctrl-C`. + +[travis-badge]: https://travis-ci.org/angular/quickstart.svg?branch=master +[travis-badge-url]: https://travis-ci.org/angular/quickstart diff --git a/app/app.component.ts b/app/app.component.ts deleted file mode 100644 index c9e1ba9c3..000000000 --- a/app/app.component.ts +++ /dev/null @@ -1,7 +0,0 @@ -import {Component} from 'angular2/core'; - -@Component({ - selector: 'my-app', - template: '

My First Angular 2 App

' -}) -export class AppComponent { } diff --git a/app/main.ts b/app/main.ts deleted file mode 100644 index 52623222b..000000000 --- a/app/main.ts +++ /dev/null @@ -1,4 +0,0 @@ -import {bootstrap} from 'angular2/platform/browser'; -import {AppComponent} from './app.component'; - -bootstrap(AppComponent); diff --git a/bs-config.e2e.json b/bs-config.e2e.json new file mode 100644 index 000000000..24570dbcc --- /dev/null +++ b/bs-config.e2e.json @@ -0,0 +1,14 @@ +{ + "open": false, + "logLevel": "silent", + "port": 8080, + "server": { + "baseDir": "src", + "routes": { + "/node_modules": "node_modules" + }, + "middleware": { + "0": null + } + } +} diff --git a/bs-config.json b/bs-config.json new file mode 100644 index 000000000..4e5859526 --- /dev/null +++ b/bs-config.json @@ -0,0 +1,8 @@ +{ + "server": { + "baseDir": "src", + "routes": { + "/node_modules": "node_modules" + } + } +} diff --git a/e2e/app.e2e-spec.ts b/e2e/app.e2e-spec.ts new file mode 100644 index 000000000..67f5d8d6a --- /dev/null +++ b/e2e/app.e2e-spec.ts @@ -0,0 +1,15 @@ +import { browser, element, by } from 'protractor'; + +describe('QuickStart E2E Tests', function () { + + let expectedMsg = 'Hello Angular'; + + beforeEach(function () { + browser.get(''); + }); + + it('should display: ' + expectedMsg, function () { + expect(element(by.css('h1')).getText()).toEqual(expectedMsg); + }); + +}); diff --git a/tsconfig.json b/e2e/tsconfig.json similarity index 50% rename from tsconfig.json rename to e2e/tsconfig.json index 9be71e4c6..2c7260d1b 100644 --- a/tsconfig.json +++ b/e2e/tsconfig.json @@ -1,17 +1,13 @@ { "compilerOptions": { "target": "es5", - "module": "system", + "module": "commonjs", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, - "removeComments": false, - "noImplicitAny": false - }, - "exclude": [ - "node_modules", - "typings/main", - "typings/main.d.ts" - ] + "lib": [ "es2015", "dom" ], + "noImplicitAny": true, + "suppressImplicitAnyIndexErrors": true + } } diff --git a/index.html b/index.html deleted file mode 100644 index 97b38a337..000000000 --- a/index.html +++ /dev/null @@ -1,33 +0,0 @@ - - - Angular 2 QuickStart - - - - - - - - - - - - - - - - - Loading... - - diff --git a/karma-test-shim.js b/karma-test-shim.js new file mode 100644 index 000000000..fe5aa7761 --- /dev/null +++ b/karma-test-shim.js @@ -0,0 +1,96 @@ +// /*global jasmine, __karma__, window*/ +Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing. + +// Uncomment to get full stacktrace output. Sometimes helpful, usually not. +// Error.stackTraceLimit = Infinity; // + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; + +// builtPaths: root paths for output ("built") files +// get from karma.config.js, then prefix with '/base/' (default is 'src/') +var builtPaths = (__karma__.config.builtPaths || ['src/']) + .map(function(p) { return '/base/'+p;}); + +__karma__.loaded = function () { }; + +function isJsFile(path) { + return path.slice(-3) == '.js'; +} + +function isSpecFile(path) { + return /\.spec\.(.*\.)?js$/.test(path); +} + +// Is a "built" file if is JavaScript file in one of the "built" folders +function isBuiltFile(path) { + return isJsFile(path) && + builtPaths.reduce(function(keep, bp) { + return keep || (path.substr(0, bp.length) === bp); + }, false); +} + +var allSpecFiles = Object.keys(window.__karma__.files) + .filter(isSpecFile) + .filter(isBuiltFile); + +System.config({ + // Base URL for System.js calls. 'base/' is where Karma serves files from. + baseURL: 'base/src', + // Extend usual application package list with test folder + packages: { 'testing': { main: 'index.js', defaultExtension: 'js' } }, + + // Assume npm: is set in `paths` in systemjs.config + // Map the angular testing umd bundles + map: { + '@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js', + '@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js', + '@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js', + '@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js', + '@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js', + '@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js', + '@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js', + '@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js', + }, +}); + +System.import('systemjs.config.js') + .then(importSystemJsExtras) + .then(initTestBed) + .then(initTesting); + +/** Optional SystemJS configuration extras. Keep going w/o it */ +function importSystemJsExtras(){ + return System.import('systemjs.config.extras.js') + .catch(function(reason) { + console.log( + 'Warning: System.import could not load the optional "systemjs.config.extras.js". Did you omit it by accident? Continuing without it.' + ); + console.log(reason); + }); +} + +function initTestBed(){ + return Promise.all([ + System.import('@angular/core/testing'), + System.import('@angular/platform-browser-dynamic/testing') + ]) + + .then(function (providers) { + var coreTesting = providers[0]; + var browserTesting = providers[1]; + + coreTesting.TestBed.initTestEnvironment( + browserTesting.BrowserDynamicTestingModule, + browserTesting.platformBrowserDynamicTesting()); + }) +} + +// Import all spec files and start karma +function initTesting () { + return Promise.all( + allSpecFiles.map(function (moduleName) { + return System.import(moduleName); + }) + ) + .then(__karma__.start, __karma__.error); +} diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 000000000..5a51e814f --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,97 @@ +module.exports = function(config) { + + var appBase = 'src/'; // transpiled app JS and map files + var appSrcBase = appBase; // app source TS files + + // Testing helpers (optional) are conventionally in a folder called `testing` + var testingBase = 'testing/'; // transpiled test JS and map files + var testingSrcBase = 'testing/'; // test source TS files + + config.set({ + basePath: '', + frameworks: ['jasmine'], + + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter') + ], + + client: { + builtPaths: [appBase, testingBase], // add more spec base paths as needed + clearContext: false // leave Jasmine Spec Runner output visible in browser + }, + + customLaunchers: { + // From the CLI. Not used here but interesting + // chrome setup for travis CI using chromium + Chrome_travis_ci: { + base: 'Chrome', + flags: ['--no-sandbox'] + } + }, + + files: [ + // System.js for module loading + 'node_modules/systemjs/dist/system.src.js', + + // Polyfills + 'node_modules/core-js/client/shim.js', + + // zone.js + 'node_modules/zone.js/dist/zone.js', + 'node_modules/zone.js/dist/long-stack-trace-zone.js', + 'node_modules/zone.js/dist/proxy.js', + 'node_modules/zone.js/dist/sync-test.js', + 'node_modules/zone.js/dist/jasmine-patch.js', + 'node_modules/zone.js/dist/async-test.js', + 'node_modules/zone.js/dist/fake-async-test.js', + + // RxJs + { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false }, + { pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false }, + + // Paths loaded via module imports: + // Angular itself + { pattern: 'node_modules/@angular/**/*.js', included: false, watched: false }, + { pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false }, + + { pattern: appBase + '/systemjs.config.js', included: false, watched: false }, + { pattern: appBase + '/systemjs.config.extras.js', included: false, watched: false }, + 'karma-test-shim.js', // optionally extend SystemJS mapping e.g., with barrels + + // transpiled application & spec code paths loaded via module imports + { pattern: appBase + '**/*.js', included: false, watched: true }, + { pattern: testingBase + '**/*.js', included: false, watched: true }, + + + // Asset (HTML & CSS) paths loaded via Angular's component compiler + // (these paths need to be rewritten, see proxies section) + { pattern: appBase + '**/*.html', included: false, watched: true }, + { pattern: appBase + '**/*.css', included: false, watched: true }, + + // Paths for debugging with source maps in dev tools + { pattern: appBase + '**/*.ts', included: false, watched: false }, + { pattern: appBase + '**/*.js.map', included: false, watched: false }, + { pattern: testingSrcBase + '**/*.ts', included: false, watched: false }, + { pattern: testingBase + '**/*.js.map', included: false, watched: false} + ], + + // Proxied base paths for loading assets + proxies: { + // required for modules fetched by SystemJS + '/base/src/node_modules/': '/base/node_modules/' + }, + + exclude: [], + preprocessors: {}, + reporters: ['progress', 'kjhtml'], + + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Chrome'], + singleRun: false + }) +} diff --git a/non-essential-files.osx.txt b/non-essential-files.osx.txt new file mode 100644 index 000000000..653a8db9b --- /dev/null +++ b/non-essential-files.osx.txt @@ -0,0 +1 @@ +.git .gitignore .travis.yml bs-config.e2e.json CHANGELOG.md e2e favicon.ico karma.conf.js karma-test-shim.js LICENSE non-essential-files.txt protractor.config.js README.md \ No newline at end of file diff --git a/non-essential-files.txt b/non-essential-files.txt new file mode 100644 index 000000000..644808a66 --- /dev/null +++ b/non-essential-files.txt @@ -0,0 +1,15 @@ +.git +.gitignore +.travis.yml +*.spec*.ts +bs-config.e2e.json +CHANGELOG.md +e2e +favicon.ico +karma.conf.js +karma-test-shim.js +LICENSE +non-essential-files.txt +non-essential-files.osx.txt +protractor.config.js +README.md diff --git a/package.json b/package.json index 4beca47b3..25513978a 100644 --- a/package.json +++ b/package.json @@ -1,27 +1,63 @@ { - "name": "angular2-quickstart", + "name": "angular-quickstart", "version": "1.0.0", + "description": "QuickStart package.json from the documentation, supplemented with testing support", "scripts": { - "start": "concurrently \"npm run tsc:w\" \"npm run lite\" ", - "tsc": "tsc", - "tsc:w": "tsc -w", - "lite": "lite-server", - "typings": "typings", - "postinstall": "typings install" + "build": "tsc -p src/", + "build:watch": "tsc -p src/ -w", + "build:e2e": "tsc -p e2e/", + "serve": "lite-server -c=bs-config.json", + "serve:e2e": "lite-server -c=bs-config.e2e.json", + "prestart": "npm run build", + "start": "concurrently \"npm run build:watch\" \"npm run serve\"", + "pree2e": "npm run build:e2e", + "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first", + "preprotractor": "webdriver-manager update", + "protractor": "protractor protractor.config.js", + "pretest": "npm run build", + "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"", + "pretest:once": "npm run build", + "test:once": "karma start karma.conf.js --single-run", + "lint": "tslint ./src/**/*.ts -t verbose" }, - "license": "ISC", + "keywords": [], + "author": "", + "license": "MIT", "dependencies": { - "angular2": "2.0.0-beta.13", - "systemjs": "0.19.25", - "es6-shim": "^0.35.0", - "reflect-metadata": "0.1.2", - "rxjs": "5.0.0-beta.2", - "zone.js": "0.6.6" + "@angular/common": "~4.3.4", + "@angular/compiler": "~4.3.4", + "@angular/core": "~4.3.4", + "@angular/forms": "~4.3.4", + "@angular/http": "~4.3.4", + "@angular/platform-browser": "~4.3.4", + "@angular/platform-browser-dynamic": "~4.3.4", + "@angular/router": "~4.3.4", + + "angular-in-memory-web-api": "~0.3.0", + "systemjs": "0.19.40", + "core-js": "^2.4.1", + "rxjs": "5.0.1", + "zone.js": "^0.8.4" }, "devDependencies": { - "concurrently": "^2.0.0", - "lite-server": "^2.1.0", - "typescript": "^1.8.9", - "typings":"^0.7.11" - } -} \ No newline at end of file + "concurrently": "^3.2.0", + "lite-server": "^2.2.2", + "typescript": "~2.1.0", + + "canonical-path": "0.0.2", + "tslint": "^3.15.1", + "lodash": "^4.16.4", + "jasmine-core": "~2.4.1", + "karma": "^1.3.0", + "karma-chrome-launcher": "^2.0.0", + "karma-cli": "^1.0.1", + "karma-jasmine": "^1.0.2", + "karma-jasmine-html-reporter": "^0.2.2", + "protractor": "~4.0.14", + "rimraf": "^2.5.4", + + "@types/node": "^6.0.46", + "@types/jasmine": "2.5.36" + }, + "repository": {} +} diff --git a/protractor.config.js b/protractor.config.js new file mode 100644 index 000000000..8d4e0416a --- /dev/null +++ b/protractor.config.js @@ -0,0 +1,183 @@ +// FIRST TIME ONLY- run: +// ./node_modules/.bin/webdriver-manager update +// +// Try: `npm run webdriver:update` +// +// AND THEN EVERYTIME ... +// 1. Compile with `tsc` +// 2. Make sure the test server (e.g., lite-server: localhost:8080) is running. +// 3. ./node_modules/.bin/protractor protractor.config.js +// +// To do all steps, try: `npm run e2e` + +var fs = require('fs'); +var path = require('canonical-path'); +var _ = require('lodash'); + + +exports.config = { + directConnect: true, + + // Capabilities to be passed to the webdriver instance. + capabilities: { + 'browserName': 'chrome' + }, + + // Framework to use. Jasmine is recommended. + framework: 'jasmine', + + // Spec patterns are relative to this config file + specs: ['**/*e2e-spec.js' ], + + + // For angular tests + useAllAngular2AppRoots: true, + + // Base URL for application server + baseUrl: 'http://localhost:8080/', + + // doesn't seem to work. + // resultJsonOutputFile: "foo.json", + + onPrepare: function() { + //// SpecReporter + //var SpecReporter = require('jasmine-spec-reporter'); + //jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: 'none'})); + //// jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: 'all'})); + + // debugging + // console.log('browser.params:' + JSON.stringify(browser.params)); + jasmine.getEnv().addReporter(new Reporter( browser.params )) ; + + // Allow changing bootstrap mode to NG1 for upgrade tests + global.setProtractorToNg1Mode = function() { + browser.useAllAngular2AppRoots = false; + browser.rootEl = 'body'; + }; + }, + + jasmineNodeOpts: { + // defaultTimeoutInterval: 60000, + defaultTimeoutInterval: 10000, + showTiming: true, + print: function() {} + } +}; + +// Custom reporter +function Reporter(options) { + var _defaultOutputFile = path.resolve(process.cwd(), './_test-output', 'protractor-results.txt'); + options.outputFile = options.outputFile || _defaultOutputFile; + + initOutputFile(options.outputFile); + options.appDir = options.appDir || './'; + var _root = { appDir: options.appDir, suites: [] }; + log('AppDir: ' + options.appDir, +1); + var _currentSuite; + + this.suiteStarted = function(suite) { + _currentSuite = { description: suite.description, status: null, specs: [] }; + _root.suites.push(_currentSuite); + log('Suite: ' + suite.description, +1); + }; + + this.suiteDone = function(suite) { + var statuses = _currentSuite.specs.map(function(spec) { + return spec.status; + }); + statuses = _.uniq(statuses); + var status = statuses.indexOf('failed') >= 0 ? 'failed' : statuses.join(', '); + _currentSuite.status = status; + log('Suite ' + _currentSuite.status + ': ' + suite.description, -1); + }; + + this.specStarted = function(spec) { + + }; + + this.specDone = function(spec) { + var currentSpec = { + description: spec.description, + status: spec.status + }; + if (spec.failedExpectations.length > 0) { + currentSpec.failedExpectations = spec.failedExpectations; + } + + _currentSuite.specs.push(currentSpec); + log(spec.status + ' - ' + spec.description); + }; + + this.jasmineDone = function() { + outputFile = options.outputFile; + //// Alternate approach - just stringify the _root - not as pretty + //// but might be more useful for automation. + // var output = JSON.stringify(_root, null, 2); + var output = formatOutput(_root); + fs.appendFileSync(outputFile, output); + }; + + function ensureDirectoryExistence(filePath) { + var dirname = path.dirname(filePath); + if (directoryExists(dirname)) { + return true; + } + ensureDirectoryExistence(dirname); + fs.mkdirSync(dirname); + } + + function directoryExists(path) { + try { + return fs.statSync(path).isDirectory(); + } + catch (err) { + return false; + } + } + + function initOutputFile(outputFile) { + ensureDirectoryExistence(outputFile); + var header = "Protractor results for: " + (new Date()).toLocaleString() + "\n\n"; + fs.writeFileSync(outputFile, header); + } + + // for output file output + function formatOutput(output) { + var indent = ' '; + var pad = ' '; + var results = []; + results.push('AppDir:' + output.appDir); + output.suites.forEach(function(suite) { + results.push(pad + 'Suite: ' + suite.description + ' -- ' + suite.status); + pad+=indent; + suite.specs.forEach(function(spec) { + results.push(pad + spec.status + ' - ' + spec.description); + if (spec.failedExpectations) { + pad+=indent; + spec.failedExpectations.forEach(function (fe) { + results.push(pad + 'message: ' + fe.message); + }); + pad=pad.substr(2); + } + }); + pad = pad.substr(2); + results.push(''); + }); + results.push(''); + return results.join('\n'); + } + + // for console output + var _pad; + function log(str, indent) { + _pad = _pad || ''; + if (indent == -1) { + _pad = _pad.substr(2); + } + console.log(_pad + str); + if (indent == 1) { + _pad = _pad + ' '; + } + } + +} diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts new file mode 100644 index 000000000..776902446 --- /dev/null +++ b/src/app/app.component.spec.ts @@ -0,0 +1,33 @@ +import { AppComponent } from './app.component'; + +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DebugElement } from '@angular/core'; + +describe('AppComponent', function () { + let de: DebugElement; + let comp: AppComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ AppComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(AppComponent); + comp = fixture.componentInstance; + de = fixture.debugElement.query(By.css('h1')); + }); + + it('should create component', () => expect(comp).toBeDefined() ); + + it('should have expected

text', () => { + fixture.detectChanges(); + const h1 = de.nativeElement; + expect(h1.innerText).toMatch(/angular/i, + '

should say something about "Angular"'); + }); +}); diff --git a/src/app/app.component.ts b/src/app/app.component.ts new file mode 100644 index 000000000..7fb173cd0 --- /dev/null +++ b/src/app/app.component.ts @@ -0,0 +1,7 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'my-app', + template: `

Hello {{name}}

`, +}) +export class AppComponent { name = 'Angular'; } diff --git a/src/app/app.module.ts b/src/app/app.module.ts new file mode 100644 index 000000000..357b003a5 --- /dev/null +++ b/src/app/app.module.ts @@ -0,0 +1,11 @@ +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +import { AppComponent } from './app.component'; + +@NgModule({ + imports: [ BrowserModule ], + declarations: [ AppComponent ], + bootstrap: [ AppComponent ] +}) +export class AppModule { } diff --git a/src/favicon.ico b/src/favicon.ico new file mode 100644 index 000000000..8081c7cea Binary files /dev/null and b/src/favicon.ico differ diff --git a/src/index.html b/src/index.html new file mode 100644 index 000000000..832743558 --- /dev/null +++ b/src/index.html @@ -0,0 +1,25 @@ + + + + Angular QuickStart + + + + + + + + + + + + + + + + + Loading AppComponent content here ... + + diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 000000000..311c44b76 --- /dev/null +++ b/src/main.ts @@ -0,0 +1,5 @@ +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; + +import { AppModule } from './app/app.module'; + +platformBrowserDynamic().bootstrapModule(AppModule); diff --git a/src/styles.css b/src/styles.css new file mode 100644 index 000000000..58e1a7d9a --- /dev/null +++ b/src/styles.css @@ -0,0 +1,5 @@ +h1 { + color: #369; + font-family: Arial, Helvetica, sans-serif; + font-size: 250%; +} diff --git a/src/systemjs-angular-loader.js b/src/systemjs-angular-loader.js new file mode 100644 index 000000000..8b1005444 --- /dev/null +++ b/src/systemjs-angular-loader.js @@ -0,0 +1,49 @@ +var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]\s*)/gm; +var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g; +var stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g; + +module.exports.translate = function(load){ + if (load.source.indexOf('moduleId') != -1) return load; + + var url = document.createElement('a'); + url.href = load.address; + + var basePathParts = url.pathname.split('/'); + + basePathParts.pop(); + var basePath = basePathParts.join('/'); + + var baseHref = document.createElement('a'); + baseHref.href = this.baseURL; + baseHref = baseHref.pathname; + + if (!baseHref.startsWith('/base/')) { // it is not karma + basePath = basePath.replace(baseHref, ''); + } + + load.source = load.source + .replace(templateUrlRegex, function(match, quote, url){ + var resolvedUrl = url; + + if (url.startsWith('.')) { + resolvedUrl = basePath + url.substr(1); + } + + return 'templateUrl: "' + resolvedUrl + '"'; + }) + .replace(stylesRegex, function(match, relativeUrls) { + var urls = []; + + while ((match = stringRegex.exec(relativeUrls)) !== null) { + if (match[2].startsWith('.')) { + urls.push('"' + basePath + match[2].substr(1) + '"'); + } else { + urls.push('"' + match[2] + '"'); + } + } + + return "styleUrls: [" + urls.join(', ') + "]"; + }); + + return load; +}; diff --git a/src/systemjs.config.extras.js b/src/systemjs.config.extras.js new file mode 100644 index 000000000..027dfe58c --- /dev/null +++ b/src/systemjs.config.extras.js @@ -0,0 +1,11 @@ +/** + * Add barrels and stuff + * Adjust as necessary for your application needs. + */ +// (function (global) { +// System.config({ +// packages: { +// // add packages here +// } +// }); +// })(this); diff --git a/src/systemjs.config.js b/src/systemjs.config.js new file mode 100644 index 000000000..129704a37 --- /dev/null +++ b/src/systemjs.config.js @@ -0,0 +1,45 @@ +/** + * System configuration for Angular samples + * Adjust as necessary for your application needs. + */ +(function (global) { + System.config({ + paths: { + // paths serve as alias + 'npm:': 'node_modules/' + }, + // map tells the System loader where to look for things + map: { + // our app is within the app folder + 'app': 'app', + + // angular bundles + '@angular/core': 'npm:@angular/core/bundles/core.umd.js', + '@angular/common': 'npm:@angular/common/bundles/common.umd.js', + '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', + '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', + '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', + '@angular/http': 'npm:@angular/http/bundles/http.umd.js', + '@angular/router': 'npm:@angular/router/bundles/router.umd.js', + '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', + + // other libraries + 'rxjs': 'npm:rxjs', + 'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js' + }, + // packages tells the System loader how to load when no filename and/or no extension + packages: { + app: { + defaultExtension: 'js', + meta: { + './*.js': { + loader: 'systemjs-angular-loader.js' + } + } + }, + rxjs: { + defaultExtension: 'js' + } + } + }); +})(this); diff --git a/src/tsconfig.json b/src/tsconfig.json new file mode 100644 index 000000000..2c7260d1b --- /dev/null +++ b/src/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "moduleResolution": "node", + "sourceMap": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "lib": [ "es2015", "dom" ], + "noImplicitAny": true, + "suppressImplicitAnyIndexErrors": true + } +} diff --git a/styles.css b/styles.css deleted file mode 100644 index 054b417f6..000000000 --- a/styles.css +++ /dev/null @@ -1,142 +0,0 @@ -/* Master Styles */ -h1 { - color: #369; - font-family: Arial, Helvetica, sans-serif; - font-size: 250%; -} -h2, h3 { - color: #444; - font-family: Arial, Helvetica, sans-serif; - font-weight: lighter; -} -body { - margin: 2em; -} -body, input[text], button { - color: #888; - font-family: Cambria, Georgia; -} -a { - cursor: pointer; - cursor: hand; -} -button { - font-family: Arial; - background-color: #eee; - border: none; - padding: 5px 10px; - border-radius: 4px; - cursor: pointer; - cursor: hand; -} -button:hover { - background-color: #cfd8dc; -} -button:disabled { - background-color: #eee; - color: #aaa; - cursor: auto; -} - -/* Navigation link styles */ -nav a { - padding: 5px 10px; - text-decoration: none; - margin-top: 10px; - display: inline-block; - background-color: #eee; - border-radius: 4px; -} -nav a:visited, a:link { - color: #607D8B; -} -nav a:hover { - color: #039be5; - background-color: #CFD8DC; -} -nav a.router-link-active { - color: #039be5; -} - -/* items class */ -.items { - margin: 0 0 2em 0; - list-style-type: none; - padding: 0; - width: 24em; -} -.items li { - cursor: pointer; - position: relative; - left: 0; - background-color: #EEE; - margin: .5em; - padding: .3em 0; - height: 1.6em; - border-radius: 4px; -} -.items li:hover { - color: #607D8B; - background-color: #DDD; - left: .1em; -} -.items li.selected:hover { - background-color: #BBD8DC; - color: white; -} -.items .text { - position: relative; - top: -3px; -} -.items { - margin: 0 0 2em 0; - list-style-type: none; - padding: 0; - width: 24em; -} -.items li { - cursor: pointer; - position: relative; - left: 0; - background-color: #EEE; - margin: .5em; - padding: .3em 0; - height: 1.6em; - border-radius: 4px; -} -.items li:hover { - color: #607D8B; - background-color: #DDD; - left: .1em; -} -.items li.selected { - background-color: #CFD8DC; - color: white; -} - -.items li.selected:hover { - background-color: #BBD8DC; -} -.items .text { - position: relative; - top: -3px; -} -.items .badge { - display: inline-block; - font-size: small; - color: white; - padding: 0.8em 0.7em 0 0.7em; - background-color: #607D8B; - line-height: 1em; - position: relative; - left: -1px; - top: -4px; - height: 1.8em; - margin-right: .8em; - border-radius: 4px 0 0 4px; -} - -/* everywhere else */ -* { - font-family: Arial, Helvetica, sans-serif; -} diff --git a/tslint.json b/tslint.json new file mode 100644 index 000000000..276453f4f --- /dev/null +++ b/tslint.json @@ -0,0 +1,93 @@ +{ + "rules": { + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "label-position": true, + "label-undefined": true, + "max-line-length": [ + true, + 140 + ], + "member-access": false, + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-arg": true, + "no-bitwise": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-debugger": true, + "no-duplicate-key": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": true, + "no-shadowed-variable": true, + "no-string-literal": false, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-unreachable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single" + ], + "radix": true, + "semicolon": [ + "always" + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "variable-name": false, + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-operator", + "check-separator", + "check-type" + ] + } +} diff --git a/typings.json b/typings.json deleted file mode 100644 index c06bb4d72..000000000 --- a/typings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "ambientDependencies": { - "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd", - "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd" - } -}