From 203cb20029668825526570a586be2cfdbedaba57 Mon Sep 17 00:00:00 2001 From: Oleg Pimenov Date: Thu, 13 Jun 2019 22:47:45 +0300 Subject: [PATCH] chore: updated example generator --- angular.json | 4 +- .../main-layout/main-layout.module.ts | 1 - packages/docs/src/app/docs.module.ts | 2 - .../shared/doc-viewer/doc-viewer-module.ts | 30 --- .../src/app/shared/doc-viewer/doc-viewer.ts | 135 ----------- .../src/app/shared/doc-viewer/header-link.ts | 50 ---- .../example-viewer/_example-viewer-theme.scss | 35 --- .../shared/example-viewer/example-viewer.html | 31 --- .../shared/example-viewer/example-viewer.scss | 43 ---- .../shared/example-viewer/example-viewer.ts | 90 ------- .../docs/src/app/shared/stackblitz/index.ts | 1 - .../shared/stackblitz/stackblitz-button.html | 8 - .../shared/stackblitz/stackblitz-button.ts | 61 ----- .../shared/stackblitz/stackblitz-writer.ts | 227 ------------------ .../docs/src/app/shared/version/version.ts | 3 +- packages/docs/src/main.ts | 7 +- packages/docs/src/test.ts | 23 -- packages/docs/src/tsconfig.json | 5 +- packages/docs/src/tsconfig.spec.json | 18 -- .../docs/src/unregister-service-workers.ts | 17 -- .../mosaic-dev/theme-picker/theme-picker.ts | 2 +- packages/mosaic/core/public-api.ts | 2 +- packages/mosaic/public-api.ts | 2 + packages/mosaic/{core => }/version.ts | 0 tools/gulp/packages.ts | 6 +- tsconfig.json | 12 +- 26 files changed, 21 insertions(+), 794 deletions(-) delete mode 100644 packages/docs/src/app/shared/doc-viewer/doc-viewer-module.ts delete mode 100644 packages/docs/src/app/shared/doc-viewer/doc-viewer.ts delete mode 100644 packages/docs/src/app/shared/doc-viewer/header-link.ts delete mode 100644 packages/docs/src/app/shared/example-viewer/_example-viewer-theme.scss delete mode 100644 packages/docs/src/app/shared/example-viewer/example-viewer.html delete mode 100644 packages/docs/src/app/shared/example-viewer/example-viewer.scss delete mode 100644 packages/docs/src/app/shared/example-viewer/example-viewer.ts delete mode 100644 packages/docs/src/app/shared/stackblitz/index.ts delete mode 100644 packages/docs/src/app/shared/stackblitz/stackblitz-button.html delete mode 100644 packages/docs/src/app/shared/stackblitz/stackblitz-button.ts delete mode 100644 packages/docs/src/app/shared/stackblitz/stackblitz-writer.ts delete mode 100644 packages/docs/src/test.ts delete mode 100644 packages/docs/src/tsconfig.spec.json delete mode 100644 packages/docs/src/unregister-service-workers.ts rename packages/mosaic/{core => }/version.ts (100%) diff --git a/angular.json b/angular.json index caa4d20f0..f2cd8460e 100644 --- a/angular.json +++ b/angular.json @@ -23,12 +23,12 @@ }, { "glob": "**/*", - "input": "./node_modules/@angular/mosaic-examples/docs-content", + "input": "./node_modules/@ptsecurity/mosaic-examples/docs-content", "output": "/docs-content" }, { "glob": "favicon.ico", - "input": "src", + "input": "packages/docs/src", "output": "/" } ], diff --git a/packages/docs/src/app/components/main-layout/main-layout.module.ts b/packages/docs/src/app/components/main-layout/main-layout.module.ts index 42aa1cb4c..1ac0e12ac 100644 --- a/packages/docs/src/app/components/main-layout/main-layout.module.ts +++ b/packages/docs/src/app/components/main-layout/main-layout.module.ts @@ -1,7 +1,6 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { RouterModule } from '@angular/router'; - import { McButtonModule } from '@ptsecurity/mosaic/button'; import { McDropdownModule } from '@ptsecurity/mosaic/dropdown'; import { McIconModule } from '@ptsecurity/mosaic/icon'; diff --git a/packages/docs/src/app/docs.module.ts b/packages/docs/src/app/docs.module.ts index 04465088c..079a4316a 100644 --- a/packages/docs/src/app/docs.module.ts +++ b/packages/docs/src/app/docs.module.ts @@ -8,9 +8,7 @@ import { RouterModule } from '@angular/router'; import { MainLayoutComponent } from './components/main-layout/main-layout.component'; import { MainLayoutModule } from './components/main-layout/main-layout.module'; - import { CompComponent, CompModule, HomepageComponent, HomepageModule } from './containers'; - import { DocsComponent } from './docs.component'; diff --git a/packages/docs/src/app/shared/doc-viewer/doc-viewer-module.ts b/packages/docs/src/app/shared/doc-viewer/doc-viewer-module.ts deleted file mode 100644 index c44adb584..000000000 --- a/packages/docs/src/app/shared/doc-viewer/doc-viewer-module.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { CommonModule } from '@angular/common'; -import { NgModule } from '@angular/core'; -import { PortalModule } from '@ptsecurity/cdk/portal'; -import { McButtonModule } from '@ptsecurity/mosaic/button'; -import { McTabsModule } from '@ptsecurity/mosaic/tabs'; - -import { CopierService } from '../copier/copier.service'; -import { ExampleViewer } from '../example-viewer/example-viewer'; -import { StackblitzButtonModule } from '../stackblitz/stackblitz-button'; - -import { DocViewer } from './doc-viewer'; -import { HeaderLink } from './header-link'; - - -// ExampleViewer is included in the DocViewerModule because they have a circular dependency. -@NgModule({ - imports: [ - McButtonModule, - McTabsModule, - CommonModule, - PortalModule, - StackblitzButtonModule - ], - providers: [CopierService], - declarations: [DocViewer, ExampleViewer, HeaderLink], - entryComponents: [ExampleViewer, HeaderLink], - exports: [DocViewer, ExampleViewer, HeaderLink] -}) -export class DocViewerModule { -} diff --git a/packages/docs/src/app/shared/doc-viewer/doc-viewer.ts b/packages/docs/src/app/shared/doc-viewer/doc-viewer.ts deleted file mode 100644 index 860d945d7..000000000 --- a/packages/docs/src/app/shared/doc-viewer/doc-viewer.ts +++ /dev/null @@ -1,135 +0,0 @@ -import { HttpClient, HttpErrorResponse } from '@angular/common/http'; -import { - ApplicationRef, - Component, - ComponentFactoryResolver, - ElementRef, - EventEmitter, - Injector, - Input, - NgZone, - OnDestroy, - Output, - SecurityContext, - ViewContainerRef -} from '@angular/core'; -import { DomSanitizer } from '@angular/platform-browser'; -import { ComponentPortal, DomPortalHost } from '@ptsecurity/cdk/portal'; -import { Subscription } from 'rxjs'; -import { take } from 'rxjs/operators'; - -import { ExampleViewer } from '../example-viewer/example-viewer'; - -import { HeaderLink } from './header-link'; - - -@Component({ - selector: 'doc-viewer', - template: 'Loading document...' -}) -export class DocViewer implements OnDestroy { - - /** The URL of the document to display. */ - @Input() - set documentUrl(url: string) { - this.fetchDocument(url); - } - - @Output() contentRendered = new EventEmitter(); - - /** The document text. It should not be HTML encoded. */ - textContent = ''; - private _portalHosts: DomPortalHost[] = []; - private _documentFetchSubscription: Subscription; - - constructor(private _appRef: ApplicationRef, - private _componentFactoryResolver: ComponentFactoryResolver, - private _elementRef: ElementRef, - private _http: HttpClient, - private _injector: Injector, - private _viewContainerRef: ViewContainerRef, - private _ngZone: NgZone, - private _domSanitizer: DomSanitizer) { - } - - ngOnDestroy() { - this.clearLiveExamples(); - - if (this._documentFetchSubscription) { - this._documentFetchSubscription.unsubscribe(); - } - } - - /** Fetch a document by URL. */ - private fetchDocument(url: string) { - // Cancel previous pending request - if (this._documentFetchSubscription) { - this._documentFetchSubscription.unsubscribe(); - } - - this._documentFetchSubscription = this._http.get(url, {responseType: 'text'}).subscribe( - (document) => this.updateDocument(document), - (error) => this.showError(url, error) - ); - } - - /** - * Updates the displayed document. - * @param rawDocument The raw document content to show. - */ - private updateDocument(rawDocument: string) { - // Replace all relative fragment URLs with absolute fragment URLs. e.g. "#my-section" becomes - // "/components/button/api#my-section". This is necessary because otherwise these fragment - // links would redirect to "/#my-section". - // tslint:disable-next-line:no-parameter-reassignment - rawDocument = rawDocument.replace(/href="#([^"]*)"/g, (_m: string, fragmentUrl: string) => { - const absoluteUrl = `${location.pathname}#${fragmentUrl}`; - - return `href="${this._domSanitizer.sanitize(SecurityContext.URL, absoluteUrl)}"`; - }); - - // tslint:disable-next-line:no-inner-html - this._elementRef.nativeElement.innerHTML = rawDocument; - this.textContent = this._elementRef.nativeElement.textContent; - - this.loadComponents('material-docs-example', ExampleViewer); - this.loadComponents('header-link', HeaderLink); - - // Resolving and creating components dynamically in Angular happens synchronously, but since - // we want to emit the output if the components are actually rendered completely, we wait - // until the Angular zone becomes stable. - this._ngZone.onStable - .pipe(take(1)) - .subscribe(() => this.contentRendered.next()); - } - - /** Show an error that occurred when fetching a document. */ - private showError(url: string, error: HttpErrorResponse) { - // tslint:disable-next-line:no-console - console.log(error); - this._elementRef.nativeElement.innerText = - `Failed to load document: ${url}. Error: ${error.statusText}`; - } - - /** Instantiate a ExampleViewer for each example. */ - private loadComponents(componentName: string, componentClass: any) { - const exampleElements = - this._elementRef.nativeElement.querySelectorAll(`[${componentName}]`); - - Array.prototype.slice.call(exampleElements).forEach((element: Element) => { - const example = element.getAttribute(componentName); - const portalHost = new DomPortalHost( - element, this._componentFactoryResolver, this._appRef, this._injector); - const examplePortal = new ComponentPortal(componentClass, this._viewContainerRef); - const exampleViewer = portalHost.attach(examplePortal); - (exampleViewer.instance as ExampleViewer).example = example; - - this._portalHosts.push(portalHost); - }); - } - - private clearLiveExamples() { - this._portalHosts.forEach((h) => h.dispose()); - this._portalHosts = []; - } -} diff --git a/packages/docs/src/app/shared/doc-viewer/header-link.ts b/packages/docs/src/app/shared/doc-viewer/header-link.ts deleted file mode 100644 index 4a6f062a9..000000000 --- a/packages/docs/src/app/shared/doc-viewer/header-link.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { Component, Input } from '@angular/core'; -import { Router } from '@angular/router'; - - -/** - * Header link is a component that handles normalizing - * the anchor jump tags with the current route url. - * - * For example: - * - * Foo - * - * would result in the wrong url, this component - * combines the current route with that jump link: - * - * Foo - */ -@Component({ - selector: 'header-link', - template: ` - - header_link - - ` -}) -export class HeaderLink { - - /** - * Id of the anchor element. Note that is uses "example" because we instantiate the - * header link components through the ComponentPortal. - */ - @Input() example: string; - - /** Base URL that is used to build an absolute fragment URL. */ - private _baseUrl: string; - - constructor(router: Router) { - this._baseUrl = router.url.split('#')[0]; - } - - _getFragmentUrl(): string { - return `${this._baseUrl}#${this.example}`; - } - -} diff --git a/packages/docs/src/app/shared/example-viewer/_example-viewer-theme.scss b/packages/docs/src/app/shared/example-viewer/_example-viewer-theme.scss deleted file mode 100644 index 6e9690d35..000000000 --- a/packages/docs/src/app/shared/example-viewer/_example-viewer-theme.scss +++ /dev/null @@ -1,35 +0,0 @@ -@mixin example-viewer-theme($theme) { - $primary: map-get($theme, primary); - $accent: map-get($theme, accent); - $warn: map-get($theme, warn); - $background: map-get($theme, background); - $foreground: map-get($theme, foreground); - - example-viewer { - .docs-example-viewer-wrapper { - border: 1px solid rgba(mc-color($foreground, secondary-text), 0.03); - box-shadow: 0 2px 2px rgba(0, 0, 0, 0.24), 0 0 2px rgba(0, 0, 0, 0.12); - margin: 4px; - } - - .docs-example-viewer-title { - color: mc-color($foreground, secondary-text); - background: rgba(mc-color($foreground, secondary-text), 0.03); - } - - .docs-example-source-copy { - color: mc-color($foreground, hint-text); - right: 8px; - - [dir='rtl'] & { - right: auto; - left: 8px; - } - } - - .docs-example-source { - border-bottom: 1px solid mc-color($foreground, divider); - overflow: auto; - } - } -} diff --git a/packages/docs/src/app/shared/example-viewer/example-viewer.html b/packages/docs/src/app/shared/example-viewer/example-viewer.html deleted file mode 100644 index 09b0ee8f4..000000000 --- a/packages/docs/src/app/shared/example-viewer/example-viewer.html +++ /dev/null @@ -1,31 +0,0 @@ -
-
-
{{exampleData?.title}}
- - - - -
- -
- - -
- -
-
-
-
-
- -
- -
-
diff --git a/packages/docs/src/app/shared/example-viewer/example-viewer.scss b/packages/docs/src/app/shared/example-viewer/example-viewer.scss deleted file mode 100644 index 179760379..000000000 --- a/packages/docs/src/app/shared/example-viewer/example-viewer.scss +++ /dev/null @@ -1,43 +0,0 @@ -:host { - display: block; - padding: 20px 0; -} - -.docs-example-viewer-wrapper { - h3 { - margin-top: 10px; - } -} - -.docs-example-viewer-title { - align-content: center; - align-items: center; - display: flex; - justify-content: center; - padding: 8px 20px; -} - -.docs-example-viewer-title-spacer { - flex: 1 1 auto; -} - -.docs-example-source-copy { - position: absolute; - top: 8px; - display: none; -} - -.docs-example-source-wrapper:hover { - .docs-example-source-copy { - display: inline-block; - } -} - -.docs-example-source { - padding: 0 30px 10px 30px; - min-height: 150px; -} - -.docs-example-viewer-body { - padding: 30px; -} diff --git a/packages/docs/src/app/shared/example-viewer/example-viewer.ts b/packages/docs/src/app/shared/example-viewer/example-viewer.ts deleted file mode 100644 index 60920a49e..000000000 --- a/packages/docs/src/app/shared/example-viewer/example-viewer.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { Component, Input } from '@angular/core'; -import { ComponentPortal } from '@ptsecurity/cdk/portal'; -import { EXAMPLE_COMPONENTS, LiveExample } from '@ptsecurity/mosaic-examples'; - -import { CopierService } from '../copier/copier.service'; - - -/** Regular expression that matches a file name and its extension */ -const fileExtensionRegex = /(.*)\.(\w+)/; - -@Component({ - selector: 'example-viewer', - templateUrl: './example-viewer.html', - styleUrls: ['./example-viewer.scss'] -}) -export class ExampleViewer { - /** Component portal for the currently displayed example. */ - selectedPortal: ComponentPortal; - - /** Map of example files that should be displayed in the view-source tab. */ - exampleTabs: { [tabName: string]: string }; - - /** Data for the currently selected example. */ - exampleData: LiveExample; - - /** Whether the source for the example is being displayed. */ - showSource = false; - - /** String key of the currently displayed example. */ - @Input() - get example() { - return this._example; - } - - set example(exampleName: string) { - if (exampleName && EXAMPLE_COMPONENTS[exampleName]) { - this._example = exampleName; - this.exampleData = EXAMPLE_COMPONENTS[exampleName]; - this.selectedPortal = new ComponentPortal(this.exampleData.component); - this.generateExampleTabs(); - } else { - // tslint:disable-next-line:no-console - console.error(`Could not find example: ${exampleName}`); - } - } - - private _example: string; - - constructor(private copier: CopierService) { - } - - toggleSourceView(): void { - this.showSource = !this.showSource; - } - - copySource(text: string) { - if (this.copier.copyText(text)) { - // tslint:disable-next-line:no-console - console.log('Code copied'); - } else { - // tslint:disable-next-line:no-console - console.log('Copy failed. Please try again!'); - } - } - - getExampleTabNames() { - return Object.keys(this.exampleTabs); - } - - private resolveHighlightedExampleFile(fileName: string) { - return `/docs-content/examples-highlighted/${fileName}`; - } - - private generateExampleTabs() { - this.exampleTabs = { - HTML: this.resolveHighlightedExampleFile(`${this.example}-example-html.html`), - TS: this.resolveHighlightedExampleFile(`${this.example}-example-ts.html`), - CSS: this.resolveHighlightedExampleFile(`${this.example}-example-css.html`) - }; - - const additionalFiles = this.exampleData.additionalFiles || []; - - additionalFiles.forEach((fileName) => { - // Since the additional files refer to the original file name, we need to transform - // the file name to match the highlighted HTML file that displays the source. - const fileSourceName = fileName.replace(fileExtensionRegex, '$1-$2.html'); - this.exampleTabs[fileName] = this.resolveHighlightedExampleFile(fileSourceName); - }); - } -} diff --git a/packages/docs/src/app/shared/stackblitz/index.ts b/packages/docs/src/app/shared/stackblitz/index.ts deleted file mode 100644 index d1e0c8e03..000000000 --- a/packages/docs/src/app/shared/stackblitz/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './stackblitz-button'; diff --git a/packages/docs/src/app/shared/stackblitz/stackblitz-button.html b/packages/docs/src/app/shared/stackblitz/stackblitz-button.html deleted file mode 100644 index 219d23506..000000000 --- a/packages/docs/src/app/shared/stackblitz/stackblitz-button.html +++ /dev/null @@ -1,8 +0,0 @@ - -
- -
diff --git a/packages/docs/src/app/shared/stackblitz/stackblitz-button.ts b/packages/docs/src/app/shared/stackblitz/stackblitz-button.ts deleted file mode 100644 index 68eaca189..000000000 --- a/packages/docs/src/app/shared/stackblitz/stackblitz-button.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { Component, Input, NgModule } from '@angular/core'; -import { ExampleData } from '@ptsecurity/mosaic-examples'; -import { McButtonModule } from '@ptsecurity/mosaic/button'; - -import { StackblitzWriter } from './stackblitz-writer'; - - -@Component({ - selector: 'stackblitz-button', - templateUrl: './stackblitz-button.html', - providers: [StackblitzWriter], - host: { - '(mouseover)': 'isDisabled = !stackblitzForm' - } -}) -export class StackblitzButton { - /** - * The button becomes disabled if the user hovers over the button before the stackblitz form - * is created. After the form is created, the button becomes enabled again. - * The form creation usually happens extremely quickly, but we handle the case of the - * stackblitz not yet being ready for people will poor network connections or slow devices. - */ - isDisabled = false; - stackblitzForm: HTMLFormElement; - - @Input() - set example(example: string) { - const exampleData = new ExampleData(example); - - if (example) { - this.stackblitzWriter.constructStackblitzForm(exampleData).then((stackblitzForm) => { - this.stackblitzForm = stackblitzForm; - this.isDisabled = false; - }); - } else { - this.isDisabled = true; - } - } - - constructor(private stackblitzWriter: StackblitzWriter) { - } - - openStackblitz(): void { - // When the form is submitted, it must be in the document body. The standard of forms is not - // to submit if it is detached from the document. See the following chromium commit for - // more details: - // https://chromium.googlesource.com/chromium/src/+/962c2a22ddc474255c776aefc7abeba00edc7470%5E! - document.body.appendChild(this.stackblitzForm); - this.stackblitzForm.submit(); - document.body.removeChild(this.stackblitzForm); - } -} - -@NgModule({ - imports: [McButtonModule], - exports: [StackblitzButton], - declarations: [StackblitzButton], - providers: [StackblitzWriter] -}) -export class StackblitzButtonModule { -} diff --git a/packages/docs/src/app/shared/stackblitz/stackblitz-writer.ts b/packages/docs/src/app/shared/stackblitz/stackblitz-writer.ts deleted file mode 100644 index f64832d92..000000000 --- a/packages/docs/src/app/shared/stackblitz/stackblitz-writer.ts +++ /dev/null @@ -1,227 +0,0 @@ -import { HttpClient } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import { ExampleData } from '@ptsecurity/mosaic-examples'; -import { VERSION } from '@ptsecurity/mosaic/core'; - -import { mosaicVersion } from '../version/version'; - - -const STACKBLITZ_URL = 'https://run.stackblitz.com/api/angular/v1'; - -const COPYRIGHT = - `Copyright 2019 Positive Technologies. MIT-style license.`; - -/** - * Path that refers to the docs-content from the "@angular/material-examples" package. The - * structure is defined in the Material repository, but we include the docs-content as assets in - * in the CLI configuration. - */ -const DOCS_CONTENT_PATH = '/docs-content/examples-source/'; - -const TEMPLATE_PATH = '/assets/stackblitz/'; -const TEMPLATE_FILES = [ - 'index.html', - 'styles.css', - 'polyfills.ts', - '.angular-cli.json', - 'main.ts', - 'mosaic-module.ts' -]; - -const TAGS: string[] = ['angular', 'mosaic', 'example']; -const angularVersion = '>=8.0.0'; - -const dependencies = { - '@ptsecurity/cdk': mosaicVersion, - '@ptsecurity/mosaic': mosaicVersion, - '@ptsecurity/mosaic-moment-adapter': mosaicVersion, - '@angular/animations': angularVersion, - '@angular/common': angularVersion, - '@angular/compiler': angularVersion, - '@angular/core': angularVersion, - '@angular/forms': angularVersion, - '@angular/platform-browser': angularVersion, - '@angular/platform-browser-dynamic': angularVersion, - '@angular/router': angularVersion, - 'angular-in-memory-web-api': '~0.5.0', - 'core-js': '^2.4.1', - rxjs: '>=6.0.0-beta.0 <7.0.0', - 'web-animations-js': '^2.3.1', - 'zone.js': '^0.8.14', - moment: '^2.18.1' -}; - -/** - * Stackblitz writer, write example files to stackblitz - * - * StackBlitz API - * URL: https://run.stackblitz.com/api/aio/v1/ - * data: { - * // File name, directory and content of files - * files[file-name1]: file-content1, - * files[directory-name/file-name2]: file-content2, - * // Can add multiple tags - * tags[0]: tag-0, - * // Description of stackblitz - * description: description, - * // Private or not - * private: true - * // Dependencies - * dependencies: dependencies - * } - */ -@Injectable() -export class StackblitzWriter { - constructor(private _http: HttpClient) { - } - - /** - * Returns an HTMLFormElement that will open a new stackblitz template with the example data when - * called with submit(). - */ - constructStackblitzForm(data: ExampleData): Promise { - const indexFile = `app%2F${data.indexFilename}.ts`; - const form = this._createFormElement(indexFile); - - TAGS.forEach((tag, i) => this._appendFormInput(form, `tags[${i}]`, tag)); - this._appendFormInput(form, 'private', 'true'); - this._appendFormInput(form, 'description', data.description); - this._appendFormInput(form, 'dependencies', JSON.stringify(dependencies)); - - return new Promise((resolve) => { - const templateContents = TEMPLATE_FILES - .map((file) => this._readFile(form, data, file, TEMPLATE_PATH)); - - const exampleContents = data.exampleFiles - .map((file) => this._readFile(form, data, file, DOCS_CONTENT_PATH)); - - // TODO(josephperrott): Prevent including assets to be manually checked. - if (data.selectorName === 'icon-svg-example') { - this._readFile(form, data, 'assets/img/examples/thumbup-icon.svg', '', false); - } - - Promise.all(templateContents.concat(exampleContents)).then(() => { - resolve(form); - }); - }); - } - - /** Constructs a new form element that will navigate to the stackblitz url. */ - _createFormElement(indexFile: string): HTMLFormElement { - const form = document.createElement('form'); - form.action = `${STACKBLITZ_URL}?file=${indexFile}`; - form.method = 'post'; - form.target = '_blank'; - - return form; - } - - /** Appends the name and value as an input to the form. */ - _appendFormInput(form: HTMLFormElement, name: string, value: string): void { - const input = document.createElement('input'); - input.type = 'hidden'; - input.name = name; - input.value = value; - form.appendChild(input); - } - - /** - * Reads the file and adds its text to the form - * @param form the html form you are appending to - * @param data example metadata about the example - * @param filename file name of the example - * @param path path to the src - * @param prependApp whether to prepend the 'app' prefix to the path - */ - _readFile(form: HTMLFormElement, - data: ExampleData, - filename: string, - path: string, - prependApp = true): void { - this._http.get(path + filename, {responseType: 'text'}).subscribe( - (response) => this.addFileToForm(form, data, response, filename, path, prependApp), - // tslint:disable-next-line:no-console - (error) => console.log(error) - ); - } - - /** - * Adds the file text to the form. - * @param form the html form you are appending to - * @param data example metadata about the example - * @param content file contents - * @param filename file name of the example - * @param path path to the src - * @param prependApp whether to prepend the 'app' prefix to the path - */ - addFileToForm(form: HTMLFormElement, - data: ExampleData, - content: string, - filename: string, - path: string, - prependApp = true) { - if (path === TEMPLATE_PATH) { - // tslint:disable-next-line:no-parameter-reassignment - content = this.replaceExamplePlaceholderNames(data, filename, content); - } else if (prependApp) { - // tslint:disable-next-line:no-parameter-reassignment - filename = `app/${filename}`; - } - this._appendFormInput(form, `files[${filename}]`, this.appendCopyright(filename, content)); - } - - /** - * The stackblitz template assets contain placeholder names for the examples: - * "" and "MaterialDocsExample". - * This will replace those placeholders with the names from the example metadata, - * e.g. "" and "BasicButtonExample" - */ - replaceExamplePlaceholderNames(data: ExampleData, - fileName: string, - fileContent: string): string { - if (fileName === 'index.html') { - // Replace the component selector in `index,html`. - // For example, will be replaced as - // - // tslint:disable:no-parameter-reassignment - fileContent = fileContent.replace(/mosaic-docs-example/g, data.selectorName); - fileContent = fileContent.replace(/{{version}}/g, VERSION.full); - } else if (fileName === 'main.ts') { - // Replace the component name in `main.ts`. - // Replace `import {MaterialDocsExample} from 'material-docs-example'` - // will be replaced as `import {ButtonDemo} from './button-demo'` - fileContent = fileContent.replace(/{MaterialDocsExample}/g, `{${data.componentName}}`); - - // Replace `declarations: [MaterialDocsExample]` - // will be replaced as `declarations: [ButtonDemo]` - fileContent = fileContent.replace(/declarations: \[MosaicDocsExample\]/g, - `declarations: [${data.componentName}]`); - - // Replace `entryComponents: [MaterialDocsExample]` - // will be replaced as `entryComponents: [DialogContent]` - fileContent = fileContent.replace(/entryComponents: \[MosaicDocsExample\]/g, - `entryComponents: [${data.componentName}]`); - - // Replace `bootstrap: [MaterialDocsExample]` - // will be replaced as `bootstrap: [ButtonDemo]` - // This assumes the first component listed in the main component - const componentList = (data.componentName || '').split(',')[0]; - fileContent = fileContent.replace(/bootstrap: \[MaterialDocsExample\]/g, - `bootstrap: [${componentList}]`); - - fileContent = fileContent.replace(/mosaic-docs-example/g, data.indexFilename); - } - - return fileContent; - } - - appendCopyright(filename: string, content: string) { - if (filename.indexOf('.ts') > -1 || filename.indexOf('.scss') > -1) { - content = `${content}\n\n/** ${COPYRIGHT} */`; - } else if (filename.indexOf('.html') > -1) { - content = `${content}\n\n`; - } - - return content; - } -} diff --git a/packages/docs/src/app/shared/version/version.ts b/packages/docs/src/app/shared/version/version.ts index 958f43d39..6dec885c6 100644 --- a/packages/docs/src/app/shared/version/version.ts +++ b/packages/docs/src/app/shared/version/version.ts @@ -1,10 +1,11 @@ -import { VERSION } from '@ptsecurity/mosaic/core'; +import { VERSION } from '@ptsecurity/mosaic/version'; /** This material version will be used in footer and stackblitz. */ export const mosaicVersion = VERSION.full; /** Version information with title and redirect url */ +// tslint:disable-next-line:naming-convention export interface VersionInfo { url: string; title: string; diff --git a/packages/docs/src/main.ts b/packages/docs/src/main.ts index 751b0e2ea..6c9976286 100644 --- a/packages/docs/src/main.ts +++ b/packages/docs/src/main.ts @@ -5,14 +5,9 @@ import { AppModule } from './app/'; import { environment } from './environments/environment'; // tslint:disable-next-line:no-import-side-effect import './polyfills.ts'; -import { unregisterServiceWorkers } from './unregister-service-workers'; -// Unregister all installed service workers and force reload the page if there was -// an old service worker from a previous version of the docs. -unregisterServiceWorkers() - .then((hadServiceWorker) => hadServiceWorker && location.reload(true)); - +// tslint:disable-next-line:blank-lines if (environment.production) { enableProdMode(); } diff --git a/packages/docs/src/test.ts b/packages/docs/src/test.ts deleted file mode 100644 index 737534163..000000000 --- a/packages/docs/src/test.ts +++ /dev/null @@ -1,23 +0,0 @@ -// This file is required by karma.conf.js and loads recursively all the .spec and framework files - -import { getTestBed } from '@angular/core/testing'; -import { - BrowserDynamicTestingModule, - platformBrowserDynamicTesting -} from '@angular/platform-browser-dynamic/testing'; -// tslint:disable-next-line:no-import-side-effect -import 'zone.js/dist/zone-testing'; - - -// tslint:disable-next-line:no-reserved-keywords -declare const require: any; - -// First, initialize the Angular testing environment. -getTestBed().initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting() -); -// Then we find all the tests. -const context = require.context('./', true, /\.spec\.ts$/); -// And load the modules. -context.keys().map(context); diff --git a/packages/docs/src/tsconfig.json b/packages/docs/src/tsconfig.json index f6914cba2..71c409f9b 100644 --- a/packages/docs/src/tsconfig.json +++ b/packages/docs/src/tsconfig.json @@ -22,13 +22,14 @@ "../../../dist/packages/mosaic/*" ], "@ptsecurity/mosaic-moment-adapter/*": [ - "../../../dist/packages/mosaic-moment-adapter/*" + "../../../dit/packages/mosaic-moment-adapter/*" ], + "@ptsecurity/mosaic-examples/*": [ "../../../dist/packages/mosaic-examples/*" ], "@ptsecurity/mosaic-examples": [ - "../../../dist/packages/mosaic-examples/public-api.ts" + "../../../dist/packages/mosaic-examples/public-api" ] } }, diff --git a/packages/docs/src/tsconfig.spec.json b/packages/docs/src/tsconfig.spec.json deleted file mode 100644 index 0234b37e0..000000000 --- a/packages/docs/src/tsconfig.spec.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../out-tsc/spec", - "module": "commonjs", - "types": [ - "jasmine" - ] - }, - "files": [ - "test.ts", - "polyfills.ts" - ], - "include": [ - "**/*.spec.ts", - "**/*.d.ts" - ] -} diff --git a/packages/docs/src/unregister-service-workers.ts b/packages/docs/src/unregister-service-workers.ts deleted file mode 100644 index c41f591b1..000000000 --- a/packages/docs/src/unregister-service-workers.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Unregisters all currently registered service workers and returns a boolean that indicates - * whether there were service workers registered or not. - */ -export async function unregisterServiceWorkers(): Promise { - if (!navigator.serviceWorker) { - return false; - } - - const registrations = await navigator.serviceWorker.getRegistrations(); - - // Walk through every currently registered Service Worker and unregister it. There can be - // service workers from previous versions of the Angular Material docs. - registrations.forEach((registration) => registration.unregister()); - - return registrations.length > 0; -} diff --git a/packages/mosaic-dev/theme-picker/theme-picker.ts b/packages/mosaic-dev/theme-picker/theme-picker.ts index 2777b7b64..a4b01bdde 100644 --- a/packages/mosaic-dev/theme-picker/theme-picker.ts +++ b/packages/mosaic-dev/theme-picker/theme-picker.ts @@ -28,7 +28,7 @@ export class ThemePicker { } ]; - constructor( private _themeStorage: ThemeStorage ) { + constructor(private _themeStorage: ThemeStorage) { const currentTheme = this._themeStorage.getStoredTheme(); if (currentTheme) { diff --git a/packages/mosaic/core/public-api.ts b/packages/mosaic/core/public-api.ts index b837a9159..06337b0d3 100644 --- a/packages/mosaic/core/public-api.ts +++ b/packages/mosaic/core/public-api.ts @@ -1,4 +1,4 @@ -export * from './version'; + export * from './utils/index'; export * from './common-behaviors/index'; export * from './line/line'; diff --git a/packages/mosaic/public-api.ts b/packages/mosaic/public-api.ts index 0d7180a8a..b5e344d5f 100644 --- a/packages/mosaic/public-api.ts +++ b/packages/mosaic/public-api.ts @@ -1,3 +1,5 @@ +export * from './version'; + export * from '@ptsecurity/mosaic/core'; export * from '@ptsecurity/mosaic/autocomplete'; diff --git a/packages/mosaic/core/version.ts b/packages/mosaic/version.ts similarity index 100% rename from packages/mosaic/core/version.ts rename to packages/mosaic/version.ts diff --git a/tools/gulp/packages.ts b/tools/gulp/packages.ts index 9e9b872d6..40460fc15 100644 --- a/tools/gulp/packages.ts +++ b/tools/gulp/packages.ts @@ -6,7 +6,11 @@ import { buildConfig, BuildPackage } from '../packages'; export const cdkPackage = new BuildPackage('cdk'); export const momentAdapterPackage = new BuildPackage('mosaic-moment-adapter', [cdkPackage]); export const mosaicPackage = new BuildPackage('mosaic', [cdkPackage, momentAdapterPackage]); -export const examplesPackage = new BuildPackage('mosaic-examples', [mosaicPackage]); +export const examplesPackage = new BuildPackage('mosaic-examples', [ + cdkPackage, + momentAdapterPackage, + mosaicPackage +]); mosaicPackage.exportsSecondaryEntryPointsAtRoot = true; mosaicPackage.sourceDir = join(buildConfig.packagesDir, 'mosaic'); diff --git a/tsconfig.json b/tsconfig.json index d0069ab6d..aefc88cc8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,6 @@ "moduleResolution": "node", "noUnusedLocals": true, "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, "strictNullChecks": true, "strictFunctionTypes": true, "skipLibCheck": true, @@ -16,19 +15,16 @@ "es2015", "dom" ], - "baseUrl": ".", + "baseUrl": "./packages", "paths": { "@ptsecurity/cdk/*": [ - "./packages/cdk/*" + "./cdk/*" ], "@ptsecurity/mosaic/*": [ - "./packages/mosaic/*" + "./mosaic/*" ], "@ptsecurity/mosaic-moment-adapter/*": [ - "./packages/mosaic-moment-adapter/*" - ], - "@ptsecurity/mosaic-examples": [ - "./packages/mosaic-examples/*" + "./mosaic-moment-adapter/*" ] }, "typeRoots": [