From 6902ba2e8505b5686f7200296b52efe216df671f Mon Sep 17 00:00:00 2001 From: Austin Date: Mon, 12 Mar 2018 19:17:21 -0500 Subject: [PATCH 1/5] fix(schematics): better formatting on index, insert body margin 0 --- schematics/shell/index.ts | 35 +++++++++++++++++++++++++++++------ schematics/utils/ast.ts | 20 ++++++++++++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/schematics/shell/index.ts b/schematics/shell/index.ts index 7c8b1d4c4f85..643e4bfc87df 100644 --- a/schematics/shell/index.ts +++ b/schematics/shell/index.ts @@ -9,7 +9,7 @@ import { import {Schema} from './schema'; import {materialVersion, cdkVersion, angularVersion} from '../utils/lib-versions'; import {getConfig, getAppFromConfig, AppConfig, CliConfig} from '../utils/devkit-utils/config'; -import {addModuleImportToRootModule} from '../utils/ast'; +import {addModuleImportToRootModule, getStylesPath} from '../utils/ast'; import {addHeadLink} from '../utils/html'; import {addPackageToPackageJson} from '../utils/package'; import {createCustomTheme} from './custom-theme'; @@ -27,7 +27,8 @@ export default function(options: Schema): Rule { options && options.skipPackageJson ? noop() : addMaterialToPackageJson(options), addThemeToAppStyles(options), addAnimationRootConfig(), - addFontsToIndex() + addFontsToIndex(), + addBodyMarginToStyles() ]); } @@ -115,10 +116,32 @@ function addAnimationRootConfig() { */ function addFontsToIndex() { return (host: Tree) => { - addHeadLink(host, - ``); - addHeadLink(host, - ``); + addHeadLink(host, ` + `); + addHeadLink(host, ` + `); return host; }; } + +/** + * Add 0 margin to body in styles.ext + */ +function addBodyMarginToStyles() { + return (host: Tree) => { + const stylesPath = getStylesPath(host); + + const buffer = host.read(stylesPath); + if (!buffer) { + throw new SchematicsException(`Could not find file for path: ${stylesPath}`); + } + + const src = buffer.toString(); + const insertion = new InsertChange(stylesPath, src.length, ` +body { margin: 0; } +`); + const recorder = host.beginUpdate(stylesPath); + recorder.insertLeft(insertion.pos, insertion.toAdd); + host.commitUpdate(recorder); + }; +} diff --git a/schematics/utils/ast.ts b/schematics/utils/ast.ts index 7625181eaa9e..15c93a0da179 100644 --- a/schematics/utils/ast.ts +++ b/schematics/utils/ast.ts @@ -60,3 +60,23 @@ export function getIndexHtmlPath(host: Tree) { const app = getAppFromConfig(config, '0'); return normalize(`/${app.root}/${app.index}`); } + +/** + * Get the root stylesheet file. + */ +export function getStylesPath(host: Tree) { + const config = getConfig(host); + const app = getAppFromConfig(config, '0'); + const styles = app.styles.find(style => { + const str = style.toString(); + return str === 'styles.css' || + str === 'styles.less' || + str === 'styles.scss'; + }); + + if (!styles) { + throw new SchematicsException(`Could not find global styles.ext file.`); + } + + return normalize(`/${app.root}/${styles}`); +} From 024c88a30d19c128ed2a4bf3aeddfed8c0c29523 Mon Sep 17 00:00:00 2001 From: Austin Date: Mon, 12 Mar 2018 19:20:16 -0500 Subject: [PATCH 2/5] fix(schematics): fix wrong mode on init --- .../__name@dasherize__.component.html | 2 +- .../__name@dasherize@if-flat__/__name@dasherize__.component.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html b/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html index c0bd9312648a..f71b7e702e9b 100644 --- a/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html +++ b/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html @@ -4,7 +4,7 @@ class="sidenav" fixedInViewport="true" [attr.role]="isHandset ? 'dialog' : 'navigation'" - [mode]="isHandset ? 'over' : 'side'" + [mode]="(isHandset | async)!.matches ? 'over' : 'side'" [opened]="!(isHandset | async)!.matches"> Menu diff --git a/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts b/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts index 1820ccfa8840..7b290c5911c5 100644 --- a/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts +++ b/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts @@ -11,7 +11,7 @@ import { Observable } from 'rxjs/Observable'; class="sidenav" fixedInViewport="true" [attr.role]="isHandset ? 'dialog' : 'navigation'" - [mode]="isHandset ? 'over' : 'side'" + [mode]="(isHandset | async)!.matches ? 'over' : 'side'" [opened]="!(isHandset | async)!.matches"> Menu From ca67c2d726c97aee21def02efe7077e0d4f58456 Mon Sep 17 00:00:00 2001 From: Austin Date: Mon, 12 Mar 2018 21:04:19 -0500 Subject: [PATCH 3/5] fix(schemtic): convert == to === --- .../__name@dasherize@if-flat__/__name@dasherize__-datasource.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schematics/table/files/__path__/__name@dasherize@if-flat__/__name@dasherize__-datasource.ts b/schematics/table/files/__path__/__name@dasherize@if-flat__/__name@dasherize__-datasource.ts index 7254deaa5b3b..e858342254bf 100644 --- a/schematics/table/files/__path__/__name@dasherize@if-flat__/__name@dasherize__-datasource.ts +++ b/schematics/table/files/__path__/__name@dasherize@if-flat__/__name@dasherize__-datasource.ts @@ -91,7 +91,7 @@ export class <%= classify(name) %>DataSource extends DataSource<<%= classify(nam } return data.sort((a, b) => { - const isAsc = this.sort.direction == 'asc'; + const isAsc = this.sort.direction === 'asc'; switch (this.sort.active) { case 'name': return compare(a.name, b.name, isAsc); case 'id': return compare(+a.id, +b.id, isAsc); From 76f09479d96c04339d60dfe2da773640766b230b Mon Sep 17 00:00:00 2001 From: Austin Date: Mon, 12 Mar 2018 21:23:49 -0500 Subject: [PATCH 4/5] fix(schematic): fix check expression --- .../__name@dasherize__-datasource.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/schematics/table/files/__path__/__name@dasherize@if-flat__/__name@dasherize__-datasource.ts b/schematics/table/files/__path__/__name@dasherize@if-flat__/__name@dasherize__-datasource.ts index e858342254bf..1272c9e1b21b 100644 --- a/schematics/table/files/__path__/__name@dasherize@if-flat__/__name@dasherize__-datasource.ts +++ b/schematics/table/files/__path__/__name@dasherize@if-flat__/__name@dasherize__-datasource.ts @@ -61,8 +61,11 @@ export class <%= classify(name) %>DataSource extends DataSource<<%= classify(nam this.sort.sortChange ]; + // Set the paginators length + this.paginator.length = this.data.length; + return merge(...dataMutations).pipe(map(() => { - return this.getPagedData(this.getSortedData(this.data)); + return this.getPagedData(this.getSortedData([...this.data])); })); } From bc459685dd1848464263803775f5b1638b7bef72 Mon Sep 17 00:00:00 2001 From: Austin Date: Wed, 14 Mar 2018 17:52:43 -0500 Subject: [PATCH 5/5] chore: pr feedback --- schematics/shell/index.ts | 49 ++++++++++++++++++++------------------- schematics/utils/ast.ts | 15 ++++-------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/schematics/shell/index.ts b/schematics/shell/index.ts index 643e4bfc87df..1f94e6aa9574 100644 --- a/schematics/shell/index.ts +++ b/schematics/shell/index.ts @@ -70,15 +70,15 @@ function insertCustomTheme(app: AppConfig, host: Tree) { const stylesPath = normalize(`/${app.root}/styles.scss`); const buffer = host.read(stylesPath); - if (!buffer) { - throw new SchematicsException(`Could not find file for path: ${stylesPath}`); + if (buffer) { + const src = buffer.toString(); + const insertion = new InsertChange(stylesPath, 0, createCustomTheme(app)); + const recorder = host.beginUpdate(stylesPath); + recorder.insertLeft(insertion.pos, insertion.toAdd); + host.commitUpdate(recorder); + } else { + console.warn(`Skipped custom theme; could not find file: ${stylesPath}`); } - - const src = buffer.toString(); - const insertion = new InsertChange(stylesPath, 0, createCustomTheme(app)); - const recorder = host.beginUpdate(stylesPath); - recorder.insertLeft(insertion.pos, insertion.toAdd); - host.commitUpdate(recorder); } /** @@ -95,9 +95,10 @@ function insertPrebuiltTheme(app: AppConfig, host: Tree, themeName: string, conf } if (hasOtherTheme) { - throw new SchematicsException(`Another theme is already defined.`); + console.warn(`Skipped theme insertion; another theme is already defined.`); + } else { + host.overwrite('.angular-cli.json', JSON.stringify(config, null, 2)); } - host.overwrite('.angular-cli.json', JSON.stringify(config, null, 2)); } /** @@ -116,10 +117,12 @@ function addAnimationRootConfig() { */ function addFontsToIndex() { return (host: Tree) => { - addHeadLink(host, ` - `); - addHeadLink(host, ` - `); + addHeadLink(host, + // tslint:disable-next-line + `\n`); + addHeadLink(host, + // tslint:disable-next-line + `\n`); return host; }; } @@ -132,16 +135,14 @@ function addBodyMarginToStyles() { const stylesPath = getStylesPath(host); const buffer = host.read(stylesPath); - if (!buffer) { - throw new SchematicsException(`Could not find file for path: ${stylesPath}`); + if (buffer) { + const src = buffer.toString(); + const insertion = new InsertChange(stylesPath, src.length, `\nbody { margin: 0; }\n`); + const recorder = host.beginUpdate(stylesPath); + recorder.insertLeft(insertion.pos, insertion.toAdd); + host.commitUpdate(recorder); + } else { + console.warn(`Skipped body reset; could not find file: ${stylesPath}`); } - - const src = buffer.toString(); - const insertion = new InsertChange(stylesPath, src.length, ` -body { margin: 0; } -`); - const recorder = host.beginUpdate(stylesPath); - recorder.insertLeft(insertion.pos, insertion.toAdd); - host.commitUpdate(recorder); }; } diff --git a/schematics/utils/ast.ts b/schematics/utils/ast.ts index 15c93a0da179..3f9e0ac13ed8 100644 --- a/schematics/utils/ast.ts +++ b/schematics/utils/ast.ts @@ -67,16 +67,11 @@ export function getIndexHtmlPath(host: Tree) { export function getStylesPath(host: Tree) { const config = getConfig(host); const app = getAppFromConfig(config, '0'); - const styles = app.styles.find(style => { - const str = style.toString(); - return str === 'styles.css' || - str === 'styles.less' || - str === 'styles.scss'; - }); + const styles = app.styles.find(s => /styles\.(c|le|sc)ss/.test(s.toString())); - if (!styles) { - throw new SchematicsException(`Could not find global styles.ext file.`); + if (styles) { + return normalize(`/${app.root}/${styles}`); + } else { + console.warn(`Could not find global styles.ext file.`); } - - return normalize(`/${app.root}/${styles}`); }