Skip to content

Commit a0fd958

Browse files
petebacondarwinzarend
authored andcommitted
build(docs-infra): show a dist-tag when installing the CLI on non-stable versions (angular#42042)
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 angular#39821 PR Close angular#42042
1 parent 3144819 commit a0fd958

File tree

6 files changed

+97
-8
lines changed

6 files changed

+97
-8
lines changed

aio/content/guide/setup-local.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ To install the CLI using `npm`, open a terminal/console window and enter the fol
5959

6060

6161
<code-example language="sh" class="code-shell">
62-
npm install -g @angular/cli
63-
62+
npm install -g @angular/cli<aio-angular-dist-tag class="pln"></aio-angular-dist-tag>
6463
</code-example>
6564

6665

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { VERSION } from '@angular/core';
2+
import { TestBed } from '@angular/core/testing';
3+
import { environment } from 'environments/environment';
4+
import { DistTagComponent } from './dist-tag.component';
5+
6+
describe('DistTagComponent', () => {
7+
let actualMode: string;
8+
9+
beforeEach(() => {
10+
TestBed.configureTestingModule({ declarations: [DistTagComponent] });
11+
actualMode = environment.mode;
12+
});
13+
14+
afterEach(() => {
15+
(environment.mode as any) = actualMode;
16+
});
17+
18+
describe('rendering', () => {
19+
it('should display nothing (for stable versions)', () => {
20+
environment.mode = 'stable';
21+
const fixture = TestBed.createComponent(DistTagComponent);
22+
fixture.detectChanges();
23+
expect(fixture.nativeElement.innerHTML).toEqual('');
24+
});
25+
26+
it('should display the current major version (for archive versions)', () => {
27+
environment.mode = 'archive';
28+
const fixture = TestBed.createComponent(DistTagComponent);
29+
fixture.detectChanges();
30+
expect(fixture.nativeElement.innerHTML).toEqual('@' + VERSION.major);
31+
});
32+
33+
it('should display "@next" (for rc versions)', () => {
34+
environment.mode = 'rc';
35+
const fixture = TestBed.createComponent(DistTagComponent);
36+
fixture.detectChanges();
37+
expect(fixture.nativeElement.innerHTML).toEqual('@next');
38+
});
39+
40+
it('should display "@next" (for next versions)', () => {
41+
environment.mode = 'next';
42+
const fixture = TestBed.createComponent(DistTagComponent);
43+
fixture.detectChanges();
44+
expect(fixture.nativeElement.innerHTML).toEqual('@next');
45+
});
46+
});
47+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Component, VERSION } from '@angular/core';
2+
import { environment } from 'environments/environment';
3+
4+
/**
5+
* Display the dist-tag of Angular for installing from npm at the point these docs are generated.
6+
*/
7+
@Component({
8+
selector: 'aio-angular-dist-tag',
9+
template: '{{tag}}',
10+
})
11+
export class DistTagComponent {
12+
tag: string;
13+
14+
constructor() {
15+
switch (environment.mode) {
16+
case 'stable':
17+
this.tag = '';
18+
break;
19+
case 'next':
20+
case 'rc':
21+
this.tag = '@next';
22+
break;
23+
default:
24+
this.tag = `@${VERSION.major}`;
25+
}
26+
}
27+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { NgModule, Type } from '@angular/core';
2+
import { WithCustomElementComponent } from '../element-registry';
3+
4+
import { DistTagComponent } from './dist-tag.component';
5+
6+
@NgModule({
7+
declarations: [ DistTagComponent ],
8+
entryComponents: [ DistTagComponent ],
9+
})
10+
export class DistTagModule implements WithCustomElementComponent {
11+
customElementComponent: Type<any> = DistTagComponent;
12+
}

aio/src/app/custom-elements/element-registry.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const ELEMENT_MODULE_LOAD_CALLBACKS_AS_ROUTES = [
2121
selector: 'aio-file-not-found-search',
2222
loadChildren: () => import('./search/file-not-found-search.module').then(m => m.FileNotFoundSearchModule)
2323
},
24+
{
25+
selector: 'aio-angular-dist-tag',
26+
loadChildren: () => import('./dist-tag/dist-tag.module').then(m => m.DistTagModule)
27+
},
2428
{
2529
selector: 'aio-resource-list',
2630
loadChildren: () => import('./resource/resource-list.module').then(m => m.ResourceListModule)

goldens/size-tracking/aio-payloads.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22
"aio": {
33
"master": {
44
"uncompressed": {
5-
"runtime-es2015": 2987,
6-
"main-es2015": 454032,
5+
"runtime-es2015": 3041,
6+
"main-es2015": 453890,
77
"polyfills-es2015": 52685
88
}
99
}
1010
},
1111
"aio-local": {
1212
"master": {
1313
"uncompressed": {
14-
"runtime-es2015": 2987,
15-
"main-es2015": 454665,
14+
"runtime-es2015": 3041,
15+
"main-es2015": 454762,
1616
"polyfills-es2015": 52628
1717
}
1818
}
1919
},
2020
"aio-local-viewengine": {
2121
"master": {
2222
"uncompressed": {
23-
"runtime-es2015": 3097,
24-
"main-es2015": 430383,
23+
"runtime-es2015": 3161,
24+
"main-es2015": 430354,
2525
"polyfills-es2015": 52628
2626
}
2727
}

0 commit comments

Comments
 (0)