Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

refactor: convert app to latest Angular CLI format #641

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 17 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,34 @@
# compiled output
/dist
/tmp
/out-tsc
/src/assets/*.css
# Only exists if Bazel was run
/bazel-out

# dependencies
/node_modules
/bower_components

# profiling files
chrome-profiler-events*.json
speed-measure-plugin*.json

# IDEs and editors
/.idea
/.vscode
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# misc
/.sass-cache
Expand All @@ -27,10 +42,6 @@ yarn-error.log
testem.log
/typings

# e2e
/e2e/*.js
/e2e/*.map

#System Files
.DS_Store
Thumbs.db
42 changes: 19 additions & 23 deletions angular.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
Copy link
Member

@jelbourn jelbourn Oct 2, 2019

Choose a reason for hiding this comment

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

Are the changes for Angular CLI structure throughout this PR captured by a schematic? To what extent will these changes be required of other Angular CLI users? (Particularly ones who started a project in the early days like us)

cc @vikerman @IgorMinar @StephenFluin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of the changes are not breaking or required changes. They mostly fall into the category of best practices. Over time, as these slight deviations from best practices build up, you can run into issues and/or unexpected breaking changes in future migrations.

Most projects that I've seen will try to align themselves with the best practices (i.e. output from a ng new) from the latest version of the Angular CLI every couple of major releases. Currently, this repo seems to be aligned with the recommendations from Angular CLI v5.

Copy link
Member

Choose a reason for hiding this comment

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

I guess what I really want to know here is how much of this change was for ivy and how much was was just event horizon for Angular CLI?

Copy link
Contributor Author

@Splaktar Splaktar Oct 2, 2019

Choose a reason for hiding this comment

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

I just went through and added comments for any Ivy-specific issues (only 2-3).

"version": 1,
"newProjectRoot": "projects",
"projects": {
"material-angular-io": {
"root": "",
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
Expand All @@ -14,7 +20,7 @@
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.json",
"tsConfig": "tsconfig.app.json",
"assets": [
{
"glob": "**/*",
Expand Down Expand Up @@ -104,8 +110,8 @@
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"karmaConfig": "./karma.conf.js",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"tsConfig": "tsconfig.spec.json",
"scripts": [],
"styles": [
{
Expand Down Expand Up @@ -153,38 +159,28 @@
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.json"
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"material-angular-io-e2e": {
"root": "",
"projectType": "application",
"cli": {},
"schematics": {},
"architect": {
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "./protractor.conf.js",
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "material-angular-io:serve"
},
"configurations": {
"production": {
"devServerTarget": "material-angular-io:serve:production"
}
}
}
}
}
},
"schematics": {
"@schematics/angular:component": {
"prefix": "app",
"styleext": "css"
},
"@schematics/angular:directive": {
"prefix": "app"
}
}
}
13 changes: 0 additions & 13 deletions e2e/app.e2e-spec.ts

This file was deleted.

5 changes: 0 additions & 5 deletions e2e/app.po.ts

This file was deleted.

24 changes: 11 additions & 13 deletions protractor.conf.js → e2e/protractor.conf.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
// @ts-check
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/docs/referenceConf.js
// https://github.com/angular/protractor/blob/master/lib/config.ts

/*global jasmine */
const SpecReporter = require('jasmine-spec-reporter');
const {SpecReporter} = require('jasmine-spec-reporter');

/**
* @type { import("protractor").Config }
*/
let config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
'./src/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
useAllAngular2AppRoots: true,
beforeLaunch: function() {
onPrepare() {
require('ts-node').register({
project: 'e2e'
project: require('path').join(__dirname, './tsconfig.json')
});
},
onPrepare: function() {
jasmine.getEnv().addReporter(new SpecReporter());
jasmine.getEnv().addReporter(new SpecReporter({spec: {displayStacktrace: true}}));
}
};


if (process.env['TRAVIS']) {

config.sauceUser = process.env['SAUCE_USERNAME'];
config.sauceKey = process.env['SAUCE_ACCESS_KEY'].split('').reverse().join('');

Expand All @@ -42,7 +41,6 @@ if (process.env['TRAVIS']) {
'build': process.env['TRAVIS_JOB_NUMBER'],
'name': 'Material Docs E2E'
};

}

exports.config = config;
23 changes: 23 additions & 0 deletions e2e/src/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {MaterialDocsAppPage} from './app.po';
import {browser, logging} from 'protractor';

describe('Material Docs App', () => {
let page: MaterialDocsAppPage;

beforeEach(() => {
page = new MaterialDocsAppPage();
});

it('should display welcome message', async() => {
await page.navigateTo();
expect(await page.getTitleText()).toEqual('Angular Material');
});

afterEach(async () => {
// Assert that there are no errors emitted from the browser
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
expect(logs).not.toContain(jasmine.objectContaining({
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure whether this will actually fail the test. A long time ago I tried doing something similar to detect leaking elements in unit tests and I couldn't get it to fail properly, although Jasmine could've changed the behavior since then. It might be better to either throw an error here or pull it out into a function that is called at the end of each test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is taken directly from what the Angular CLI's e2e schematic generates for a new project.

If there is a little more concrete guidance here, I could open up an issue against Angular CLI.

level: logging.Level.SEVERE,
} as logging.Entry));
});
});
12 changes: 12 additions & 0 deletions e2e/src/app.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {browser, by, element} from 'protractor';

export class MaterialDocsAppPage {
navigateTo() {
return browser.get(browser.baseUrl) as Promise<any>;
}

getTitleText() {
return element(by.css('app-homepage header .docs-header-headline .mat-h1'))
.getText() as Promise<string>;
}
}
15 changes: 6 additions & 9 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
{
"compileOnSave": false,
"extends": "../tsconfig.json",
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"outDir": "../out-tsc/e2e",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "../dist/out-tsc-e2e",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types"
"types": [
"jasmine",
"jasminewd2",
"node"
]
}
}
81 changes: 43 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,65 @@
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "yarn build-themes && ng serve",
"start-jit": "yarn build-themes && ng serve --aot=false",
"lint": "tslint -p src/tsconfig.json",
"start:prod": "yarn build-themes && ng serve --prod",
"lint": "tslint -p tsconfig.json",
"test": "yarn build-themes && ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor",
"e2e": "yarn build-themes && ng e2e",
"build": "yarn build-themes && ng build",
"build:highmem": "yarn build-themes && node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build",
Copy link
Member

Choose a reason for hiding this comment

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

Is this something commonly required, or is there something special about our app? I'm surprised that it's necessary given the relatively simple nature of our docs app

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's tracked here: angular/angular-cli#13734. Based on this issue, it has become quite common and only minor progress has been made towards "solving it". In some cases, the CLI team has stated that increasing the available memory is expected.

I only ran into the issue when doing an AOT non-production build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if this would occur with Ivy as well since the Ivy build doesn't get that far into the build process, yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's also needed with Ivy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like this is being addressed in PR angular/angular-cli#15777.

"build:sm": "ng build --prod --source-map",
"build-themes": "bash ./tools/build-themes.sh",
"prod-build": "yarn build-themes && ng build --aot --prod",
"prod-build": "yarn build-themes && ng build --prod",
"postinstall": "webdriver-manager update --gecko false && yarn build-themes",
"publish-prod": "bash ./tools/deploy.sh stable prod",
"publish-dev": "bash ./tools/deploy.sh",
"publish-beta": "bash ./tools/deploy.sh stable beta"
},
"private": true,
"dependencies": {
"@angular/animations": "^8.0.0",
"@angular/cdk": "8.2.1",
"@angular/cdk-experimental": "8.2.1",
"@angular/common": "^8.0.0",
"@angular/compiler": "^8.0.0",
"@angular/core": "^8.0.0",
"@angular/forms": "^8.0.0",
"@angular/material": "8.2.1",
"@angular/material-examples": "angular/material2-docs-content#8.2.x",
"@angular/material-experimental": "8.2.1",
"@angular/material-moment-adapter": "8.2.1",
"@angular/platform-browser": "^8.0.0",
"@angular/platform-browser-dynamic": "^8.0.0",
"@angular/router": "^8.0.0",
"core-js": "^2.6.1",
"@angular/animations": "^8.2.9",
"@angular/cdk": "^8.2.2",
"@angular/cdk-experimental": "^8.2.2",
"@angular/common": "^8.2.9",
"@angular/compiler": "^8.2.9",
"@angular/core": "^8.2.9",
"@angular/forms": "^8.2.9",
"@angular/material": "^8.2.2",
"@angular/material-examples": "angular/material2-docs-content",
"@angular/material-experimental": "^8.2.2",
"@angular/material-moment-adapter": "^8.2.2",
"@angular/platform-browser": "^8.2.9",
"@angular/platform-browser-dynamic": "^8.2.9",
"@angular/router": "^8.2.9",
"core-js": "^2.6.9",
"hammerjs": "^2.0.8",
"material-components-web": "^1.1.1",
"moment": "^2.23.0",
"rxjs": "^6.5.1",
"zone.js": "^0.9.0"
"material-components-web": "^4.0.0-alpha.0",
"moment": "^2.24.0",
"rxjs": "^6.5.3",
"zone.js": "^0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.800.0",
"@angular/cli": "^8.0.0",
"@angular/compiler-cli": "^8.0.0",
"@types/jasmine": "^3.3.5",
"@types/node": "^10.12.18",
"firebase-tools": "^6.2.2",
"jasmine-core": "~2.99.1",
"@angular-devkit/build-angular": "^0.803.6",
"@angular/cli": "^8.3.6",
"@angular/compiler-cli": "^8.2.9",
"@types/jasmine": "^3.4.1",
"@types/node": "^12.7.8",
"firebase-tools": "^7.4.0",
"jasmine-core": "^3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^3.1.4",
"karma-chrome-launcher": "^2.2.0",
"karma": "^4.3.0",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.1.0",
"karma-jasmine": "^1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-jasmine": "^2.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"node-sass": "^4.11.0",
"protractor": "~5.3.0",
"ts-node": "^6.0.3",
"tslint": "^5.10.0",
"typescript": "3.4"
"protractor": "^5.4.2",
"ts-node": "^8.4.1",
"tslint": "^5.20.0",
"typescript": "3.5.3"
}
}
}
6 changes: 5 additions & 1 deletion src/app/app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ import {GaService} from './shared/ga/ga';
FormsModule,
HttpClientModule,
MatNativeDateModule,
RouterModule.forRoot(MATERIAL_DOCS_ROUTES),
RouterModule.forRoot(MATERIAL_DOCS_ROUTES, {
scrollPositionRestoration: 'enabled',
anchorScrolling: 'enabled',
relativeLinkResolution: 'corrected'
}),
ComponentCategoryListModule,
ComponentHeaderModule,
ComponentListModule,
Expand Down
Loading