Skip to content

Commit d8c602f

Browse files
Merge pull request #1639 from timdeschryver/example/standalone
docs: add standalone example
2 parents 25a9290 + 9905727 commit d8c602f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+855
-0
lines changed

angular.json

+113
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,119 @@
11021102
}
11031103
}
11041104
},
1105+
"sample-code-flow-standalone": {
1106+
"projectType": "application",
1107+
"schematics": {},
1108+
"root": "projects/sample-code-flow-standalone",
1109+
"sourceRoot": "projects/sample-code-flow-standalone/src",
1110+
"prefix": "app",
1111+
"architect": {
1112+
"build": {
1113+
"builder": "@angular-devkit/build-angular:browser",
1114+
"options": {
1115+
"outputPath": "dist/sample-code-flow-standalone",
1116+
"index": "projects/sample-code-flow-standalone/src/index.html",
1117+
"main": "projects/sample-code-flow-standalone/src/main.ts",
1118+
"polyfills": ["zone.js"],
1119+
"tsConfig": "projects/sample-code-flow-standalone/tsconfig.app.json",
1120+
"aot": true,
1121+
"assets": [
1122+
"projects/sample-code-flow-standalone/src/favicon.ico",
1123+
"projects/sample-code-flow-standalone/src/silent-renew.html",
1124+
"projects/sample-code-flow-standalone/src/assets"
1125+
],
1126+
"styles": ["projects/sample-code-flow-standalone/src/styles.css"],
1127+
"scripts": []
1128+
},
1129+
"configurations": {
1130+
"production": {
1131+
"fileReplacements": [],
1132+
"optimization": true,
1133+
"outputHashing": "all",
1134+
"sourceMap": false,
1135+
"namedChunks": false,
1136+
"extractLicenses": true,
1137+
"vendorChunk": false,
1138+
"buildOptimizer": true,
1139+
"budgets": [
1140+
{
1141+
"type": "initial",
1142+
"maximumWarning": "2mb",
1143+
"maximumError": "5mb"
1144+
},
1145+
{
1146+
"type": "anyComponentStyle",
1147+
"maximumWarning": "6kb",
1148+
"maximumError": "10kb"
1149+
}
1150+
]
1151+
},
1152+
"development": {
1153+
"buildOptimizer": false,
1154+
"optimization": false,
1155+
"vendorChunk": true,
1156+
"extractLicenses": false,
1157+
"sourceMap": true,
1158+
"namedChunks": true
1159+
}
1160+
}
1161+
},
1162+
"serve": {
1163+
"builder": "@angular-devkit/build-angular:dev-server",
1164+
"options": {
1165+
"browserTarget": "sample-code-flow-standalone:build",
1166+
"sslKey": "certs/dev_localhost.key",
1167+
"sslCert": "certs/dev_localhost.pem",
1168+
"port": 4204
1169+
},
1170+
"configurations": {
1171+
"production": {
1172+
"browserTarget": "sample-code-flow-standalone:build:production"
1173+
},
1174+
"development": {
1175+
"browserTarget": "sample-code-flow-standalone:build:development"
1176+
}
1177+
},
1178+
"defaultConfiguration": "development"
1179+
},
1180+
"extract-i18n": {
1181+
"builder": "@angular-devkit/build-angular:extract-i18n",
1182+
"options": {
1183+
"browserTarget": "sample-code-flow-standalone:build"
1184+
}
1185+
},
1186+
"test": {
1187+
"builder": "@angular-devkit/build-angular:karma",
1188+
"options": {
1189+
"main": "projects/sample-code-flow-standalone/src/test.ts",
1190+
"polyfills": ["zone.js", "zone.js/testing"],
1191+
"tsConfig": "projects/sample-code-flow-standalone/tsconfig.spec.json",
1192+
"karmaConfig": "projects/sample-code-flow-standalone/karma.conf.js",
1193+
"assets": ["projects/sample-code-flow-standalone/src/favicon.ico", "projects/sample-code-flow-standalone/src/assets"],
1194+
"styles": ["projects/sample-code-flow-standalone/src/styles.css"],
1195+
"scripts": []
1196+
}
1197+
},
1198+
"lint": {
1199+
"builder": "@angular-eslint/builder:lint",
1200+
"options": {
1201+
"lintFilePatterns": ["projects/sample-code-flow-standalone/**/*.ts", "projects/sample-code-flow-standalone/**/*.html"]
1202+
}
1203+
},
1204+
"e2e": {
1205+
"builder": "@angular-devkit/build-angular:protractor",
1206+
"options": {
1207+
"protractorConfig": "projects/sample-code-flow-standalone/e2e/protractor.conf.js",
1208+
"devServerTarget": "sample-code-flow-standalone:serve"
1209+
},
1210+
"configurations": {
1211+
"production": {
1212+
"devServerTarget": "sample-code-flow-standalone:serve:production"
1213+
}
1214+
}
1215+
}
1216+
}
1217+
},
11051218
"sample-code-flow-multi-Azure-B2C": {
11061219
"projectType": "application",
11071220
"schematics": {},

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"start-sample-code-flow-multi-AAD": "ng serve sample-code-flow-multi-AAD --ssl -o",
4444
"start-sample-code-flow-multi-Azure-B2C": "ng serve sample-code-flow-multi-Azure-B2C --ssl -o",
4545
"start-sample-code-flow-multi-iframe": "ng serve sample-code-flow-multi-iframe --ssl -o",
46+
"start-sample-code-flow-standalone": "ng serve sample-code-flow-standalone --ssl -o",
4647
"start-sample-implicit-flow-google": "ng serve sample-implicit-flow-google --ssl -o",
4748
"start-sample-implicit-flow-silent-renew": "ng serve sample-implicit-flow-silent-renew --ssl -o",
4849
"start-sample-code-flow-lazy-loaded": "ng serve sample-code-flow-lazy-loaded --ssl --port=4204 -o",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"extends": "../../.eslintrc.json",
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts"],
7+
"parserOptions": {
8+
"project": [
9+
"projects/sample-code-flow-standalone/tsconfig.app.json",
10+
"projects/sample-code-flow-standalone/tsconfig.spec.json",
11+
"projects/sample-code-flow-standalone/e2e/tsconfig.json"
12+
],
13+
"createDefaultProgram": true
14+
},
15+
"rules": {
16+
"@angular-eslint/component-selector": [
17+
"error",
18+
{
19+
"type": "element",
20+
"prefix": "app",
21+
"style": "kebab-case"
22+
}
23+
],
24+
"@angular-eslint/directive-selector": [
25+
"error",
26+
{
27+
"type": "attribute",
28+
"prefix": "app",
29+
"style": "camelCase"
30+
}
31+
]
32+
}
33+
},
34+
{
35+
"files": ["*.html"],
36+
"rules": {}
37+
}
38+
]
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @ts-check
2+
// Protractor configuration file, see link for more information
3+
// https://github.com/angular/protractor/blob/master/lib/config.ts
4+
5+
const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter');
6+
7+
/**
8+
* @type { import("protractor").Config }
9+
*/
10+
exports.config = {
11+
allScriptsTimeout: 11000,
12+
specs: ['./src/**/*.e2e-spec.ts'],
13+
capabilities: {
14+
browserName: 'chrome',
15+
},
16+
directConnect: true,
17+
SELENIUM_PROMISE_MANAGER: false,
18+
baseUrl: 'http://localhost:4200/',
19+
framework: 'jasmine',
20+
jasmineNodeOpts: {
21+
showColors: true,
22+
defaultTimeoutInterval: 30000,
23+
print: function () {},
24+
},
25+
onPrepare() {
26+
require('ts-node').register({
27+
project: require('path').join(__dirname, './tsconfig.json'),
28+
});
29+
jasmine.getEnv().addReporter(
30+
new SpecReporter({
31+
spec: {
32+
displayStacktrace: StacktraceOption.PRETTY,
33+
},
34+
})
35+
);
36+
},
37+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { AppPage } from './app.po';
2+
import { browser, logging } from 'protractor';
3+
4+
describe('workspace-project App', () => {
5+
let page: AppPage;
6+
7+
beforeEach(() => {
8+
page = new AppPage();
9+
});
10+
11+
it('should display welcome message', async () => {
12+
await page.navigateTo();
13+
expect(await page.getTitleText()).toEqual('sample-code-flow-standalone app is running!');
14+
});
15+
16+
afterEach(async () => {
17+
// Assert that there are no errors emitted from the browser
18+
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
19+
expect(logs).not.toContain(
20+
jasmine.objectContaining({
21+
level: logging.Level.SEVERE,
22+
} as logging.Entry)
23+
);
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { browser, by, element } from 'protractor';
2+
3+
export class AppPage {
4+
async navigateTo(): Promise<unknown> {
5+
return browser.get(browser.baseUrl);
6+
}
7+
8+
async getTitleText(): Promise<string> {
9+
return element(by.css('app-root .content span')).getText();
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
2+
{
3+
"extends": "../../../tsconfig.json",
4+
"compilerOptions": {
5+
"outDir": "../../../out-tsc/e2e",
6+
"module": "commonjs",
7+
"target": "es2018",
8+
"types": ["jasmine", "node"]
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
module.exports = function (config) {
5+
config.set({
6+
basePath: '',
7+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8+
plugins: [
9+
require('karma-jasmine'),
10+
require('karma-chrome-launcher'),
11+
require('karma-jasmine-html-reporter'),
12+
require('karma-coverage'),
13+
require('@angular-devkit/build-angular/plugins/karma'),
14+
],
15+
client: {
16+
jasmine: {
17+
// you can add configuration options for Jasmine here
18+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19+
// for example, you can disable the random execution with `random: false`
20+
// or set a specific seed with `seed: 4321`
21+
},
22+
clearContext: false, // leave Jasmine Spec Runner output visible in browser
23+
},
24+
jasmineHtmlReporter: {
25+
suppressAll: true, // removes the duplicated traces
26+
},
27+
coverageReporter: {
28+
dir: require('path').join(__dirname, '../../coverage/sample-code-flow-standalone'),
29+
subdir: '.',
30+
reporters: [{ type: 'html' }, { type: 'text-summary' }],
31+
},
32+
reporters: ['progress', 'kjhtml'],
33+
port: 9876,
34+
colors: true,
35+
logLevel: config.LOG_INFO,
36+
autoWatch: true,
37+
browsers: ['Chrome'],
38+
singleRun: false,
39+
restartOnFileChange: true,
40+
});
41+
};

projects/sample-code-flow-standalone/src/app/app.component.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<app-navigation></app-navigation>
2+
3+
<div class="container-fluid">
4+
<div class="row">
5+
<div class="col-sm-12 body-content">
6+
<router-outlet></router-outlet>
7+
</div>
8+
</div>
9+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { TestBed, waitForAsync } from '@angular/core/testing';
2+
import { AppComponent } from './app.component';
3+
4+
describe('AppComponent', () => {
5+
beforeEach(
6+
waitForAsync(() => {
7+
TestBed.configureTestingModule({
8+
declarations: [AppComponent],
9+
}).compileComponents();
10+
})
11+
);
12+
13+
it('should create the app', () => {
14+
const fixture = TestBed.createComponent(AppComponent);
15+
const app = fixture.debugElement.componentInstance;
16+
expect(app).toBeTruthy();
17+
});
18+
19+
it(`should have as title 'sample-code-flow-standalone'`, () => {
20+
const fixture = TestBed.createComponent(AppComponent);
21+
const app = fixture.debugElement.componentInstance;
22+
expect(app.title).toEqual('sample-code-flow-standalone');
23+
});
24+
25+
it('should render title in a h1 tag', () => {
26+
const fixture = TestBed.createComponent(AppComponent);
27+
fixture.detectChanges();
28+
const compiled = fixture.debugElement.nativeElement;
29+
expect(compiled.querySelector('h1').textContent).toContain('Welcome to sample-code-flow-standalone!');
30+
});
31+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { OidcSecurityService } from 'angular-auth-oidc-client';
3+
import {RouterOutlet} from "@angular/router";
4+
import {NavigationComponent} from "./navigation/navigation.component";
5+
6+
@Component({
7+
selector: 'app-root',
8+
templateUrl: './app.component.html',
9+
styleUrls: ['./app.component.css'],
10+
standalone: true,
11+
imports: [
12+
RouterOutlet,
13+
NavigationComponent
14+
]
15+
})
16+
export class AppComponent implements OnInit {
17+
constructor(private oidcSecurityService: OidcSecurityService) {}
18+
19+
ngOnInit() {
20+
this.oidcSecurityService.checkAuth().subscribe(({ isAuthenticated, userData, accessToken }) => {
21+
console.log('app authenticated', isAuthenticated);
22+
console.log(`Current access token is '${accessToken}'`);
23+
});
24+
}
25+
26+
login() {
27+
console.log('start login');
28+
this.oidcSecurityService.authorize();
29+
}
30+
31+
refreshSession() {
32+
console.log('start refreshSession');
33+
this.oidcSecurityService.authorize();
34+
}
35+
36+
logout() {
37+
console.log('start logoff');
38+
this.oidcSecurityService.logoff().subscribe((result) => console.log(result));
39+
}
40+
}

0 commit comments

Comments
 (0)