Skip to content

Commit

Permalink
refactor(docs): read versions from config (#1612)
Browse files Browse the repository at this point in the history
  • Loading branch information
yggg authored Jun 14, 2019
1 parent 03a8085 commit 9dc1818
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 24 deletions.
25 changes: 24 additions & 1 deletion DEV_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ To start a new release (publish the framework packages on NPM) you need:
* `npm run update-packages-smoke-lock` to update `packages-smoke/package-lock.json`
* `npm run version:bump`
* update version in `package-lock.json` and `packages-smoke/package-lock.json`
* update `docs/versions.json`:
- When releasing minor/patch update (both LTS and current):
- Replace latest current or LTS version in `version.json` with currently released
- When releasing major update:
- Replace LTS version with latest mentioned in version.json
- Add currently released version
- `path` of the current version should be set to `/nebular`, others to `/nebular/<version-name>`
* update `versions` array in `docs/assets/ghspa.js`. It should include all versions from `docs/versions.json` except currently released (latest).
5.
* `npm run version:changelog`
* fix/expand changelog manually
Expand All @@ -372,7 +380,22 @@ To start a new release (publish the framework packages on NPM) you need:
11. create and push git tag
12. create release on github
13. publish docs
14. add relese notes to [Nebular Releases](https://github.com/akveo/nebular/issues/1204)
1. Build docs for currently released version
2. Copy `docs/dist` outside of `nebular/docs` directory
3. Loop over other versions mentioned in `docs/versions.json`:
1. Run `git checkout <version tag>`
2. Run `npm ci`
3. Run `npm run docs:prepare`
4. Run `npm run build -- docs --prod --base-href '/nebular/<version>/'` (for example `--base-href '/nebular/3.6.1/'`)
5. Run `npm run docs:dirs`.
6. Rename `docs/dist` to `docs/<version>`.
7. Copy renamed folder to the directory from step `13.2`.
4. Checkout current version
5. Run `npm install`
6. Remove `docs/dist`
7. Move resulting directory from step `13.2` to 'docs/dist'.
8. Run `npm run ngh -- --dir ./docs/dist`
14. add release notes to [Nebular Releases](https://github.com/akveo/nebular/issues/1204)
#ngx-admin development on the latest Nebular sources
Expand Down
3 changes: 2 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@
"docs/404.html",
"docs/favicon.ico",
"docs/favicon.png",
"docs/google46533d2e7a851062.html"
"docs/google46533d2e7a851062.html",
{ "glob": "versions.json", "input": "docs/", "output": "/" }
],
"styles": [
"node_modules/pace-js/templates/pace-theme-flash.tmpl.css",
Expand Down
40 changes: 29 additions & 11 deletions docs/app/@theme/components/header/header.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { ChangeDetectionStrategy, Component, HostBinding, Inject, Input, OnInit } from '@angular/core';
import { NB_WINDOW, NbMenuItem, NbSidebarService } from '@nebular/theme';
import { NgdVersionService } from '../../services';
import { Observable } from 'rxjs';
import { map, startWith } from 'rxjs/operators';

import { NgdVersionService, VersionInfo } from '../../services';

@Component({
selector: 'ngd-header',
Expand All @@ -12,15 +15,20 @@ import { NgdVersionService } from '../../services';
</button>
<div class="logo">
<a routerLink="/">Nebular</a>
<span class="version">v{{ currentVersion }}</span>
<span class="version" *ngIf="currentVersionName$ | async">
v{{ currentVersionName$ | async }}
</span>
</div>
</div>
<div class="section middle">
<nb-menu [items]="mainMenu"></nb-menu>
<ngd-search *ngIf="showSearch"></ngd-search>
<nb-select class="version-select" [selected]="currentVersion" (selectedChange)="redirectToVersion($event)">
<nb-option *ngFor="let version of versions" [value]="version">
{{ version }}
<nb-select class="version-select"
*ngIf="(showVersionSelect$ | async)"
[selected]="currentVersion$ | async"
(selectedChange)="redirectToVersion($event)">
<nb-option *ngFor="let version of supportedVersions$ | async" [value]="version">
{{ version.name }}
</nb-option>
</nb-select>
</div>
Expand All @@ -40,8 +48,10 @@ export class NgdHeaderComponent implements OnInit {
@HostBinding('class.docs-page') @Input() isDocs = false;

private window: Window;
versions: string[];
currentVersion: string;
supportedVersions$: Observable<VersionInfo[]>;
currentVersion$: Observable<VersionInfo>;
currentVersionName$: Observable<string>;
showVersionSelect$: Observable<boolean>;

mainMenu: NbMenuItem[] = [
{
Expand Down Expand Up @@ -74,11 +84,19 @@ export class NgdHeaderComponent implements OnInit {
private sidebarService: NbSidebarService,
) {
this.window = window;
this.currentVersion = versionService.getNebularVersion();
this.versions = versionService.getNebularVersions();
}

ngOnInit() {
this.currentVersion$ = this.versionService.getCurrentVersion();
this.currentVersionName$ = this.currentVersion$.pipe(map((version: VersionInfo) => version.name));
this.supportedVersions$ = this.versionService.getSupportedVersions();

this.showVersionSelect$ = this.supportedVersions$
.pipe(
map((versions: VersionInfo[]) => versions.length > 0),
startWith(false),
);

if (!this.isDocs) {
this.mainMenu.push({
title: 'Professional Services',
Expand All @@ -91,7 +109,7 @@ export class NgdHeaderComponent implements OnInit {
this.sidebarService.toggle(false, this.sidebarTag);
}

redirectToVersion(version: string): void {
this.window.location.href = this.versionService.getVersionPath(version);
redirectToVersion(version: VersionInfo): void {
this.window.location.href = version.path;
}
}
35 changes: 24 additions & 11 deletions docs/app/@theme/services/version.service.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map, shareReplay } from 'rxjs/operators';

import { environment } from '../../../environments/environment';

const PACKAGE_JSON_VERSION = require('../../../../package.json').version;

export interface VersionInfo {
version: string;
name: string;
path: string;
}

@Injectable()
export class NgdVersionService {

versionsExceptCurrent = [ '3.6.0' ];
supportedVersions$: Observable<VersionInfo[]>;

getNebularVersion() {
return require('../../../../package.json').version;
constructor(private http: HttpClient) {
this.supportedVersions$ = this.http.get<VersionInfo[]>(environment.versionsUrl)
.pipe(shareReplay(1));
}

getNebularVersions(): string[] {
return this.versionsExceptCurrent.concat(this.getNebularVersion());
getCurrentVersion(): Observable<VersionInfo> {
return this.supportedVersions$
.pipe(
map((versions: VersionInfo[]) => versions.find(info => info.version === PACKAGE_JSON_VERSION)),
);
}

getVersionPath(version: string): string {
if (version === this.getNebularVersion()) {
return '/nebular';
}

return `/nebular/${version}`;
getSupportedVersions(): Observable<VersionInfo[]> {
return this.supportedVersions$;
}
}
1 change: 1 addition & 0 deletions docs/app/documentation/page/page.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@

.fixed-panel {
position: fixed;
top: 7.5rem;
width: inherit;
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@

export const environment = {
production: true,
versionsUrl: '/nebular/versions.json',
};
1 change: 1 addition & 0 deletions docs/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@

export const environment = {
production: false,
versionsUrl: 'versions.json',
};
12 changes: 12 additions & 0 deletions docs/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"version": "4.0.0",
"name": "4.0.0",
"path": "/nebular"
},
{
"version": "3.6.0",
"name": "3.6.0",
"path": "/nebular/3.6.0"
}
]

0 comments on commit 9dc1818

Please sign in to comment.