Skip to content

Commit e3d2e14

Browse files
amcdnlmmalerba
authored andcommitted
Schematic fixes (#10388)
* fix(schematics): better formatting on index, insert body margin 0 * fix(schematics): fix wrong mode on init * fix(schemtic): convert == to === * fix(schematic): fix check expression * chore: pr feedback
1 parent 9f3bf27 commit e3d2e14

File tree

5 files changed

+60
-18
lines changed

5 files changed

+60
-18
lines changed

schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class="sidenav"
55
fixedInViewport="true"
66
[attr.role]="isHandset ? 'dialog' : 'navigation'"
7-
[mode]="isHandset ? 'over' : 'side'"
7+
[mode]="(isHandset | async)!.matches ? 'over' : 'side'"
88
[opened]="!(isHandset | async)!.matches">
99
<mat-toolbar color="primary">Menu</mat-toolbar>
1010
<mat-nav-list>

schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Observable } from 'rxjs/Observable';
1111
class="sidenav"
1212
fixedInViewport="true"
1313
[attr.role]="isHandset ? 'dialog' : 'navigation'"
14-
[mode]="isHandset ? 'over' : 'side'"
14+
[mode]="(isHandset | async)!.matches ? 'over' : 'side'"
1515
[opened]="!(isHandset | async)!.matches">
1616
<mat-toolbar color="primary">Menu</mat-toolbar>
1717
<mat-nav-list>

schematics/shell/index.ts

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import {Schema} from './schema';
1010
import {materialVersion, cdkVersion, angularVersion} from '../utils/lib-versions';
1111
import {getConfig, getAppFromConfig, AppConfig, CliConfig} from '../utils/devkit-utils/config';
12-
import {addModuleImportToRootModule} from '../utils/ast';
12+
import {addModuleImportToRootModule, getStylesPath} from '../utils/ast';
1313
import {addHeadLink} from '../utils/html';
1414
import {addPackageToPackageJson} from '../utils/package';
1515
import {createCustomTheme} from './custom-theme';
@@ -27,7 +27,8 @@ export default function(options: Schema): Rule {
2727
options && options.skipPackageJson ? noop() : addMaterialToPackageJson(options),
2828
addThemeToAppStyles(options),
2929
addAnimationRootConfig(),
30-
addFontsToIndex()
30+
addFontsToIndex(),
31+
addBodyMarginToStyles()
3132
]);
3233
}
3334

@@ -69,15 +70,15 @@ function insertCustomTheme(app: AppConfig, host: Tree) {
6970
const stylesPath = normalize(`/${app.root}/styles.scss`);
7071

7172
const buffer = host.read(stylesPath);
72-
if (!buffer) {
73-
throw new SchematicsException(`Could not find file for path: ${stylesPath}`);
73+
if (buffer) {
74+
const src = buffer.toString();
75+
const insertion = new InsertChange(stylesPath, 0, createCustomTheme(app));
76+
const recorder = host.beginUpdate(stylesPath);
77+
recorder.insertLeft(insertion.pos, insertion.toAdd);
78+
host.commitUpdate(recorder);
79+
} else {
80+
console.warn(`Skipped custom theme; could not find file: ${stylesPath}`);
7481
}
75-
76-
const src = buffer.toString();
77-
const insertion = new InsertChange(stylesPath, 0, createCustomTheme(app));
78-
const recorder = host.beginUpdate(stylesPath);
79-
recorder.insertLeft(insertion.pos, insertion.toAdd);
80-
host.commitUpdate(recorder);
8182
}
8283

8384
/**
@@ -94,9 +95,10 @@ function insertPrebuiltTheme(app: AppConfig, host: Tree, themeName: string, conf
9495
}
9596

9697
if (hasOtherTheme) {
97-
throw new SchematicsException(`Another theme is already defined.`);
98+
console.warn(`Skipped theme insertion; another theme is already defined.`);
99+
} else {
100+
host.overwrite('.angular-cli.json', JSON.stringify(config, null, 2));
98101
}
99-
host.overwrite('.angular-cli.json', JSON.stringify(config, null, 2));
100102
}
101103

102104
/**
@@ -116,9 +118,31 @@ function addAnimationRootConfig() {
116118
function addFontsToIndex() {
117119
return (host: Tree) => {
118120
addHeadLink(host,
119-
`<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`);
121+
// tslint:disable-next-line
122+
`\n<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">`);
120123
addHeadLink(host,
121-
`<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">`);
124+
// tslint:disable-next-line
125+
`\n<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">`);
122126
return host;
123127
};
124128
}
129+
130+
/**
131+
* Add 0 margin to body in styles.ext
132+
*/
133+
function addBodyMarginToStyles() {
134+
return (host: Tree) => {
135+
const stylesPath = getStylesPath(host);
136+
137+
const buffer = host.read(stylesPath);
138+
if (buffer) {
139+
const src = buffer.toString();
140+
const insertion = new InsertChange(stylesPath, src.length, `\nbody { margin: 0; }\n`);
141+
const recorder = host.beginUpdate(stylesPath);
142+
recorder.insertLeft(insertion.pos, insertion.toAdd);
143+
host.commitUpdate(recorder);
144+
} else {
145+
console.warn(`Skipped body reset; could not find file: ${stylesPath}`);
146+
}
147+
};
148+
}

schematics/table/files/__path__/__name@dasherize@if-flat__/__name@dasherize__-datasource.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ export class <%= classify(name) %>DataSource extends DataSource<<%= classify(nam
6161
this.sort.sortChange
6262
];
6363

64+
// Set the paginators length
65+
this.paginator.length = this.data.length;
66+
6467
return merge(...dataMutations).pipe(map(() => {
65-
return this.getPagedData(this.getSortedData(this.data));
68+
return this.getPagedData(this.getSortedData([...this.data]));
6669
}));
6770
}
6871

@@ -91,7 +94,7 @@ export class <%= classify(name) %>DataSource extends DataSource<<%= classify(nam
9194
}
9295

9396
return data.sort((a, b) => {
94-
const isAsc = this.sort.direction == 'asc';
97+
const isAsc = this.sort.direction === 'asc';
9598
switch (this.sort.active) {
9699
case 'name': return compare(a.name, b.name, isAsc);
97100
case 'id': return compare(+a.id, +b.id, isAsc);

schematics/utils/ast.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,18 @@ export function getIndexHtmlPath(host: Tree) {
6060
const app = getAppFromConfig(config, '0');
6161
return normalize(`/${app.root}/${app.index}`);
6262
}
63+
64+
/**
65+
* Get the root stylesheet file.
66+
*/
67+
export function getStylesPath(host: Tree) {
68+
const config = getConfig(host);
69+
const app = getAppFromConfig(config, '0');
70+
const styles = app.styles.find(s => /styles\.(c|le|sc)ss/.test(s.toString()));
71+
72+
if (styles) {
73+
return normalize(`/${app.root}/${styles}`);
74+
} else {
75+
console.warn(`Could not find global styles.ext file.`);
76+
}
77+
}

0 commit comments

Comments
 (0)