Skip to content

Commit

Permalink
chore: updated example generator
Browse files Browse the repository at this point in the history
  • Loading branch information
pimenovoleg committed Jun 24, 2019
1 parent 7f33804 commit e70432d
Show file tree
Hide file tree
Showing 24 changed files with 156 additions and 39 deletions.
2 changes: 1 addition & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
{
"glob": "**/*",
"input": "./node_modules/@angular/material-examples/docs-content",
"input": "./node_modules/@angular/mosaic-examples/docs-content",
"output": "/docs-content"
},
{
Expand Down
1 change: 1 addition & 0 deletions packages/cdk/version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Version } from '@angular/core';


/** Current version of the Component Development Kit. */
export const VERSION = new Version('0.0.0-PLACEHOLDER');
2 changes: 1 addition & 1 deletion packages/docs/src/_app-theme.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import '../../mosaic/core/theming/theming';


@mixin material-docs-app-theme($theme) {
@mixin mosaic-docs-app-theme($theme) {
$primary: map-get($theme, primary);
$accent: map-get($theme, accent);
$warn: map-get($theme, warn);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Input } from '@angular/core';
import { EXAMPLE_COMPONENTS, LiveExample } from '@angular/material-examples';
import { ComponentPortal } from '@ptsecurity/cdk/portal';
import { EXAMPLE_COMPONENTS, LiveExample } from '@ptsecurity/mosaic-examples';

import { CopierService } from '../copier/copier.service';

Expand Down
28 changes: 13 additions & 15 deletions packages/docs/src/app/shared/stackblitz/stackblitz-writer.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ExampleData } from '@angular/material-examples';
import { ExampleData } from '@ptsecurity/mosaic-examples';
import { VERSION } from '@ptsecurity/mosaic/core';

import { materialVersion } from '../version/version';
import { mosaicVersion } from '../version/version';


const STACKBLITZ_URL = 'https://run.stackblitz.com/api/angular/v1';

const COPYRIGHT =
`Copyright 2019 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license`;
`Copyright 2019 Positive Technologies. MIT-style license.`;

/**
* Path that refers to the docs-content from the "@angular/material-examples" package. The
Expand All @@ -27,16 +25,16 @@ const TEMPLATE_FILES = [
'polyfills.ts',
'.angular-cli.json',
'main.ts',
'material-module.ts'
'mosaic-module.ts'
];

const TAGS: string[] = ['angular', 'material', 'example'];
const angularVersion = '>=7.0.0';
const TAGS: string[] = ['angular', 'mosaic', 'example'];
const angularVersion = '>=8.0.0';

const dependencies = {
'@ptsecurity/cdk': materialVersion,
'@ptsecurity/mosaic': materialVersion,
'@ptsecurity/mosaic-moment-adapter': materialVersion,
'@ptsecurity/cdk': mosaicVersion,
'@ptsecurity/mosaic': mosaicVersion,
'@ptsecurity/mosaic-moment-adapter': mosaicVersion,
'@angular/animations': angularVersion,
'@angular/common': angularVersion,
'@angular/compiler': angularVersion,
Expand Down Expand Up @@ -186,7 +184,7 @@ export class StackblitzWriter {
// For example, <material-docs-example></material-docs-example> will be replaced as
// <button-demo></button-demo>
// tslint:disable:no-parameter-reassignment
fileContent = fileContent.replace(/material-docs-example/g, data.selectorName);
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`.
Expand All @@ -196,12 +194,12 @@ export class StackblitzWriter {

// Replace `declarations: [MaterialDocsExample]`
// will be replaced as `declarations: [ButtonDemo]`
fileContent = fileContent.replace(/declarations: \[MaterialDocsExample\]/g,
fileContent = fileContent.replace(/declarations: \[MosaicDocsExample\]/g,
`declarations: [${data.componentName}]`);

// Replace `entryComponents: [MaterialDocsExample]`
// will be replaced as `entryComponents: [DialogContent]`
fileContent = fileContent.replace(/entryComponents: \[MaterialDocsExample\]/g,
fileContent = fileContent.replace(/entryComponents: \[MosaicDocsExample\]/g,
`entryComponents: [${data.componentName}]`);

// Replace `bootstrap: [MaterialDocsExample]`
Expand All @@ -211,7 +209,7 @@ export class StackblitzWriter {
fileContent = fileContent.replace(/bootstrap: \[MaterialDocsExample\]/g,
`bootstrap: [${componentList}]`);

fileContent = fileContent.replace(/material-docs-example/g, data.indexFilename);
fileContent = fileContent.replace(/mosaic-docs-example/g, data.indexFilename);
}

return fileContent;
Expand Down
1 change: 1 addition & 0 deletions packages/docs/src/app/shared/style-manager/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './style-manager';
47 changes: 47 additions & 0 deletions packages/docs/src/app/shared/style-manager/style-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {Injectable} from '@angular/core';


/**
* Class for managing stylesheets. Stylesheets are loaded into named slots so that they can be
* removed or changed later.
*/
@Injectable()
export class StyleManager {
/**
* Set the stylesheet with the specified key.
*/
setStyle(key: string, href: string) {
getLinkElementForKey(key).setAttribute('href', href);
}

/**
* Remove the stylesheet with the specified key.
*/
removeStyle(key: string) {
const existingLinkElement = getExistingLinkElementByKey(key);
if (existingLinkElement) {
document.head.removeChild(existingLinkElement);
}
}
}

function getLinkElementForKey(key: string) {
return getExistingLinkElementByKey(key) || createLinkElementWithKey(key);
}

function getExistingLinkElementByKey(key: string) {
return document.head.querySelector(`link[rel="stylesheet"].${getClassNameForKey(key)}`);
}

function createLinkElementWithKey(key: string) {
const linkEl = document.createElement('link');
linkEl.setAttribute('rel', 'stylesheet');
linkEl.classList.add(getClassNameForKey(key));
document.head.appendChild(linkEl);

return linkEl;
}

function getClassNameForKey(key: string) {
return `style-manager-${key}`;
}
1 change: 1 addition & 0 deletions packages/docs/src/app/shared/version-picker/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './version-picker';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<button >
{{mosaicVersion}}
</button>

38 changes: 38 additions & 0 deletions packages/docs/src/app/shared/version-picker/version-picker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { CommonModule } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { Component, NgModule } from '@angular/core';
import { McButtonModule } from '@ptsecurity/mosaic/button';

import { mosaicVersion, VersionInfo } from '../version/version';


const versionUrl = '';

@Component({
selector: 'version-picker',
templateUrl: './version-picker.html'
})
export class VersionPicker {
/** The currently running versin of Material. */
mosaicVersion = mosaicVersion;
/** The possible versions of the doc site. */
docVersions = this.http.get(versionUrl);

constructor(private http: HttpClient) {
}

/** Updates the window location if the selected version is a different version. */
onVersionChanged(version: VersionInfo) {
if (!version.url.startsWith(window.location.href)) {
window.location.assign(version.url);
}
}
}

@NgModule({
imports: [McButtonModule, CommonModule],
exports: [VersionPicker],
declarations: [VersionPicker]
})
export class VersionPickerModule {
}
11 changes: 11 additions & 0 deletions packages/docs/src/app/shared/version/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { VERSION } from '@ptsecurity/mosaic/core';


/** This material version will be used in footer and stackblitz. */
export const mosaicVersion = VERSION.full;

/** Version information with title and redirect url */
export interface VersionInfo {
url: string;
title: string;
}
7 changes: 5 additions & 2 deletions packages/docs/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
"../../../dist/packages/mosaic/*"
],
"@ptsecurity/mosaic-moment-adapter/*": [
"../../../dist/mosaic-moment-adapter/*"
"../../../dist/packages/mosaic-moment-adapter/*"
],
"@ptsecurity/mosaic-examples/*": [
"../../../dist/packages/mosaic-examples/*"
],
"@ptsecurity/mosaic-examples": [
"../../mosaic-examples/*"
"../../../dist/packages/mosaic-examples/public-api.ts"
]
}
},
Expand Down
5 changes: 2 additions & 3 deletions packages/mosaic-examples/mosaic-module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { NgModule} from '@angular/core';

import { NgModule } from '@angular/core';
import {
McButtonModule
} from '@ptsecurity/mosaic';


@NgModule({
imports: [
imports: [
McButtonModule
],
exports: [
Expand Down
2 changes: 0 additions & 2 deletions packages/mosaic-examples/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ export * from './example-data';
// The example-module file will be auto-generated. As soon as the
// examples are being compiled, the module file will be generated.
export * from './example-module';

export * from './button-basic/button-basic-example';
12 changes: 8 additions & 4 deletions packages/mosaic-examples/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"stripInternal": false,
"experimentalDecorators": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitAny": true,
"noImplicitThis": true,
"importHelpers": true,
"module": "es2015",
"moduleResolution": "node",
Expand All @@ -17,10 +21,7 @@
"sourceMap": true,
"inlineSources": true,
"target": "es2015",
"lib": [
"es2015",
"dom"
],
"lib": ["es2015", "dom"],
"skipLibCheck": true,
"types": [],
"baseUrl": ".",
Expand All @@ -33,6 +34,9 @@
],
"@ptsecurity/cdk/*": [
"../../dist/packages/cdk/*"
],
"@ptsecurity/mosaic-moment-adapter": [
"../../dist/packages/mosaic-moment-adapter"
]
}
},
Expand Down
7 changes: 6 additions & 1 deletion packages/mosaic-examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
// Needed for Moment.js since it doesn't have a default export.
"allowSyntheticDefaultImports": true,
"rootDir": "..",
"baseUrl": ".",
"paths": {
Expand All @@ -12,7 +14,10 @@
"../mosaic/*"
],
"@ptsecurity/mosaic": [
"../mosaic/public-api.ts"
"../mosaic/public-api"
],
"@ptsecurity/mosaic-moment-adapter": [
"../mosaic-moment-adapter/public-api"
]
}
},
Expand Down
1 change: 1 addition & 0 deletions packages/mosaic-examples/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare const module: {id: string};
1 change: 1 addition & 0 deletions packages/mosaic/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Core library code for other `@ptsecurity/mosaic` components.
1 change: 1 addition & 0 deletions packages/mosaic/core/public-api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './version';
export * from './utils/index';
export * from './common-behaviors/index';
export * from './line/line';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Version } from '@angular/core';


/** Current version. */
export const VERSION = new Version('0.0.0-PLACEHOLDER');
2 changes: 0 additions & 2 deletions packages/mosaic/public-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export * from './version';

export * from '@ptsecurity/mosaic/core';

export * from '@ptsecurity/mosaic/autocomplete';
Expand Down
5 changes: 3 additions & 2 deletions tools/dgeni/_index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* tslint:disable */
import * as path from 'path';
import {sync as globSync} from 'glob';

Expand All @@ -10,7 +11,7 @@ import {FilterDuplicateExports} from './processors/filter-duplicate-exports';
import {MergeInheritedProperties} from './processors/merge-inherited-properties';
import {DocsPrivateFilter} from './processors/docs-private-filter';
import {Categorizer} from './processors/categorizer';
import {ComponentGrouper} from './processors/component-grouper';
//import {ComponentGrouper} from './processors/component-grouper';


const jsdocPackage = require('dgeni-packages/jsdoc');
Expand Down Expand Up @@ -69,7 +70,7 @@ apiDocsPackage.processor(new DocsPrivateFilter());
apiDocsPackage.processor(new Categorizer());

// Processor to group components into top-level groups such as "Tabs", "Sidenav", etc.
apiDocsPackage.processor(new ComponentGrouper());
//apiDocsPackage.processor(new ComponentGrouper());

// Configure the log level of the API docs dgeni package.
apiDocsPackage.config((log: any) => log.level = 'info');
Expand Down
2 changes: 1 addition & 1 deletion tools/example-module/example-module.template
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const EXAMPLE_LIST = ${exampleList};
declarations: EXAMPLE_LIST,
entryComponents: EXAMPLE_LIST,
imports: [
ExampleMaterialModule,
ExampleMosaicModule,
FormsModule,
ReactiveFormsModule,
CommonModule
Expand Down
12 changes: 8 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"skipLibCheck": true,
Expand All @@ -15,16 +16,19 @@
"es2015",
"dom"
],
"baseUrl": "./packages",
"baseUrl": ".",
"paths": {
"@ptsecurity/cdk/*": [
"./cdk/*"
"./packages/cdk/*"
],
"@ptsecurity/mosaic/*": [
"./mosaic/*"
"./packages/mosaic/*"
],
"@ptsecurity/mosaic-moment-adapter/*": [
"./mosaic-moment-adapter/*"
"./packages/mosaic-moment-adapter/*"
],
"@ptsecurity/mosaic-examples": [
"./packages/mosaic-examples/*"
]
},
"typeRoots": [
Expand Down

0 comments on commit e70432d

Please sign in to comment.