Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(docs-infra): show a dist-tag when installing the CLI on non-sta…
…ble versions (#41991) It is important to use the correct major version of the Angular CLI when following the examples in the tutorials. This commit provides a custom element that renders an appropriate dist-tag in the setup step of the tutorial when the docs are not in "stable" mode. Fixes #39821 PR Close #41991
- Loading branch information
1 parent
d43e351
commit a4e03d3
Showing
6 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
aio/src/app/custom-elements/dist-tag/dist-tag.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { VERSION } from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { environment } from 'environments/environment'; | ||
import { DistTagComponent } from './dist-tag.component'; | ||
|
||
describe('DistTagComponent', () => { | ||
let actualMode: string; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ declarations: [DistTagComponent] }); | ||
actualMode = environment.mode; | ||
}); | ||
|
||
afterEach(() => { | ||
(environment.mode as any) = actualMode; | ||
}); | ||
|
||
describe('rendering', () => { | ||
it('should display nothing (for stable versions)', () => { | ||
environment.mode = 'stable'; | ||
const fixture = TestBed.createComponent(DistTagComponent); | ||
fixture.detectChanges(); | ||
expect(fixture.nativeElement.innerHTML).toEqual(''); | ||
}); | ||
|
||
it('should display the current major version (for archive versions)', () => { | ||
environment.mode = 'archive'; | ||
const fixture = TestBed.createComponent(DistTagComponent); | ||
fixture.detectChanges(); | ||
expect(fixture.nativeElement.innerHTML).toEqual('@' + VERSION.major); | ||
}); | ||
|
||
it('should display "@next" (for rc versions)', () => { | ||
environment.mode = 'rc'; | ||
const fixture = TestBed.createComponent(DistTagComponent); | ||
fixture.detectChanges(); | ||
expect(fixture.nativeElement.innerHTML).toEqual('@next'); | ||
}); | ||
|
||
it('should display "@next" (for next versions)', () => { | ||
environment.mode = 'next'; | ||
const fixture = TestBed.createComponent(DistTagComponent); | ||
fixture.detectChanges(); | ||
expect(fixture.nativeElement.innerHTML).toEqual('@next'); | ||
}); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
aio/src/app/custom-elements/dist-tag/dist-tag.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Component, VERSION } from '@angular/core'; | ||
import { environment } from 'environments/environment'; | ||
|
||
/** | ||
* Display the dist-tag of Angular for installing from npm at the point these docs are generated. | ||
*/ | ||
@Component({ | ||
selector: 'aio-angular-dist-tag', | ||
template: '{{tag}}', | ||
}) | ||
export class DistTagComponent { | ||
tag: string; | ||
|
||
constructor() { | ||
switch (environment.mode) { | ||
case 'stable': | ||
this.tag = ''; | ||
break; | ||
case 'next': | ||
case 'rc': | ||
this.tag = '@next'; | ||
break; | ||
default: | ||
this.tag = `@${VERSION.major}`; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NgModule, Type } from '@angular/core'; | ||
import { WithCustomElementComponent } from '../element-registry'; | ||
|
||
import { DistTagComponent } from './dist-tag.component'; | ||
|
||
@NgModule({ | ||
declarations: [ DistTagComponent ], | ||
entryComponents: [ DistTagComponent ], | ||
}) | ||
export class DistTagModule implements WithCustomElementComponent { | ||
customElementComponent: Type<any> = DistTagComponent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters