9
9
import { Schema } from './schema' ;
10
10
import { materialVersion , cdkVersion , angularVersion } from '../utils/lib-versions' ;
11
11
import { getConfig , getAppFromConfig , AppConfig , CliConfig } from '../utils/devkit-utils/config' ;
12
- import { addModuleImportToRootModule } from '../utils/ast' ;
12
+ import { addModuleImportToRootModule , getStylesPath } from '../utils/ast' ;
13
13
import { addHeadLink } from '../utils/html' ;
14
14
import { addPackageToPackageJson } from '../utils/package' ;
15
15
import { createCustomTheme } from './custom-theme' ;
@@ -27,7 +27,8 @@ export default function(options: Schema): Rule {
27
27
options && options . skipPackageJson ? noop ( ) : addMaterialToPackageJson ( options ) ,
28
28
addThemeToAppStyles ( options ) ,
29
29
addAnimationRootConfig ( ) ,
30
- addFontsToIndex ( )
30
+ addFontsToIndex ( ) ,
31
+ addBodyMarginToStyles ( )
31
32
] ) ;
32
33
}
33
34
@@ -69,15 +70,15 @@ function insertCustomTheme(app: AppConfig, host: Tree) {
69
70
const stylesPath = normalize ( `/${ app . root } /styles.scss` ) ;
70
71
71
72
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 } ` ) ;
74
81
}
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 ) ;
81
82
}
82
83
83
84
/**
@@ -94,9 +95,10 @@ function insertPrebuiltTheme(app: AppConfig, host: Tree, themeName: string, conf
94
95
}
95
96
96
97
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 ) ) ;
98
101
}
99
- host . overwrite ( '.angular-cli.json' , JSON . stringify ( config , null , 2 ) ) ;
100
102
}
101
103
102
104
/**
@@ -116,9 +118,31 @@ function addAnimationRootConfig() {
116
118
function addFontsToIndex ( ) {
117
119
return ( host : Tree ) => {
118
120
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">` ) ;
120
123
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">` ) ;
122
126
return host ;
123
127
} ;
124
128
}
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
+ }
0 commit comments