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

Commit 11918de

Browse files
authored
feat: add version and version picker (#406)
1 parent aebdacb commit 11918de

File tree

10 files changed

+96
-12
lines changed

10 files changed

+96
-12
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"build-themes": "bash ./tools/build-themes.sh",
1515
"prod-build": "npm run build-themes && ng build --aot --prod",
1616
"postinstall": "webdriver-manager update && bash ./tools/fetch-assets.sh",
17-
"publish-prod": "npm run build-themes && ng build --aot --prod && firebase use material-angular-io && firebase deploy",
18-
"publish-dev": "npm run build-themes && ng build --aot --prod && firebase use material2-docs-dev && firebase deploy"
17+
"publish-prod": "bash ./tools/deploy.sh stable prod",
18+
"publish-dev": "bash ./tools/deploy.sh"
1919
},
2020
"private": true,
2121
"dependencies": {

src/app/shared/footer/footer.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import {Component, NgModule} from '@angular/core';
2-
import {VERSION} from '@angular/material';
2+
import {materialVersion} from '../version/version'
33

44
@Component({
55
selector: 'app-footer',
66
templateUrl: './footer.html',
77
styleUrls: ['./footer.scss']
88
})
99
export class Footer {
10-
get version() {
11-
const version = VERSION.full.match(/\d+\.\d+\.\d+/);
12-
if (version) {
13-
return version[0];
14-
}
15-
return '';
16-
}
10+
version = materialVersion;
1711
}
1812

1913

src/app/shared/navbar/navbar.html

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
[routerLink]="key">{{sections[key]}}</a>
1212
<a mat-button class="docs-navbar-hide-small docs-button" routerLink="guides">Guides</a>
1313
<div class="flex-spacer"></div>
14+
<!-- TODO(tinayuangao): Uncomment this when we are ready for v6
15+
<version-picker></version-picker>
16+
-->
1417
<theme-picker></theme-picker>
1518
<a mat-button class="docs-button docs-navbar-hide-small" href="https://github.com/angular/material2"
1619
aria-label="GitHub Repository">

src/app/shared/navbar/navbar.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {CommonModule} from '@angular/common';
33
import {MatButtonModule, MatMenuModule} from '@angular/material';
44
import {RouterModule} from '@angular/router';
55
import {ThemePickerModule} from '../theme-picker/theme-picker';
6+
import {VersionPickerModule} from '../version-picker';
67
import {SECTIONS} from '../documentation-items/documentation-items';
78

89
const SECTIONS_KEYS = Object.keys(SECTIONS);
@@ -23,7 +24,7 @@ export class NavBar {
2324
}
2425

2526
@NgModule({
26-
imports: [MatButtonModule, MatMenuModule, RouterModule, ThemePickerModule, CommonModule],
27+
imports: [MatButtonModule, MatMenuModule, RouterModule, ThemePickerModule, VersionPickerModule, CommonModule],
2728
exports: [NavBar],
2829
declarations: [NavBar],
2930
})

src/app/shared/stackblitz/stackblitz-writer.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {Http} from '@angular/http';
33
import {ExampleData} from '@angular/material-examples';
44
import {VERSION} from '@angular/material';
55

6+
import {materialVersion} from '../version/version';
7+
68
const STACKBLITZ_URL = 'https://run.stackblitz.com/api/angular/v1';
79

810
const COPYRIGHT =
@@ -21,7 +23,6 @@ const TEMPLATE_FILES = [
2123

2224
const TAGS: string[] = ['angular', 'material', 'example'];
2325
const angularVersion = '^5.0.0';
24-
const materialVersion = '5.2.4';
2526

2627
const dependencies = {
2728
'@angular/cdk': materialVersion,
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './version-picker';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<button mat-button [matMenuTriggerFor]="versionPicker">
2+
{{materialVersion}}
3+
</button>
4+
<mat-menu #versionPicker="matMenu">
5+
<button mat-menu-item *ngFor="let version of docVersions"
6+
(click)="onVersionChanged(version)">
7+
{{version.title}}
8+
</button>
9+
</mat-menu>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {Component, NgModule} from '@angular/core';
2+
import {CommonModule} from '@angular/common';
3+
import {MatButtonModule, MatMenuModule} from '@angular/material';
4+
import {docVersions, materialVersion, VersionInfo} from '../version/version'
5+
6+
@Component({
7+
selector: 'version-picker',
8+
templateUrl: './version-picker.html'
9+
})
10+
export class VersionPicker {
11+
12+
_versionRegex = /\d+.\d+.\d+/;
13+
docVersions = docVersions;
14+
15+
materialVersion = materialVersion;
16+
17+
displayVersion = materialVersion.match(this._versionRegex)[0];
18+
19+
onVersionChanged(version: VersionInfo) {
20+
if (version.title.match(this._versionRegex)[0] !== this.displayVersion) {
21+
window.location.assign(version.url);
22+
}
23+
}
24+
}
25+
26+
@NgModule({
27+
imports: [MatButtonModule, MatMenuModule, CommonModule],
28+
exports: [VersionPicker],
29+
declarations: [VersionPicker]
30+
})
31+
export class VersionPickerModule {}

src/app/shared/version/version.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {VERSION} from '@angular/material';
2+
3+
/** This material version will be used in footer and stackblitz. */
4+
export const materialVersion = VERSION.full;
5+
6+
/** Version information with title and redirect url */
7+
export interface VersionInfo {
8+
url: string;
9+
title: string;
10+
}
11+
12+
/** Doc site versions. We update the urls and titles manually */
13+
// TODO(tinayuangao): Update the title with actual versions
14+
export const docVersions: VersionInfo[] = [
15+
{
16+
url: 'https://material.angular.io/',
17+
title: '5.2.4'
18+
},
19+
{
20+
url: `http://v5.material.angular.io`,
21+
title: '6.0.0-beta.4'
22+
}
23+
];

tools/deploy.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -eu -o pipefail
4+
5+
declare -A PROJECT_ID
6+
7+
#Firebase project Ids
8+
PROJECT_ID["stable", "dev"]="material2-docs-dev"
9+
PROJECT_ID["stable", "prod"]="material-angular-io"
10+
PROJECT_ID["v5", "dev"]="material2-docs-5"
11+
PROJECT_ID["v5", "prod"]="v5-material-angular-io"
12+
13+
version=${1:-stable}
14+
mode=${2:-dev}
15+
projectId=${PROJECT_ID[$version, $mode]}
16+
17+
npm run build-themes
18+
ng build --aot --prod
19+
firebase use $projectId
20+
firebase deploy
21+

0 commit comments

Comments
 (0)