@@ -24,6 +24,7 @@ export default function (options: Schema): any {
2424 addMdbModuleImport ( options ) ,
2525 addAngularAnimationsModule ( options ) ,
2626 addStylesImports ( options ) ,
27+ addChartsToScripts ( options ) ,
2728 addRobotoFontToIndexHtml ( options ) ,
2829 updateAppComponentContent ( ) ,
2930 ] ) ;
@@ -144,6 +145,33 @@ function addStylesImports(options: Schema): any {
144145 } ;
145146}
146147
148+ function addChartsToScripts ( options : Schema ) : any {
149+ return async ( host : Tree , context : SchematicContext ) => {
150+ const logger = context . logger ;
151+
152+ const chartsPath = 'node_modules/chart.js/dist/chart.js' ;
153+
154+ if ( options . charts ) {
155+ const angularJsonFile = host . read ( 'angular.json' ) ;
156+
157+ if ( angularJsonFile ) {
158+ const angularJsonFileObject = JSON . parse ( angularJsonFile . toString ( 'utf-8' ) ) ;
159+ const project = options . project
160+ ? options . project
161+ : Object . keys ( angularJsonFileObject . projects ) [ 0 ] ;
162+ const projectObject = angularJsonFileObject . projects [ project ] ;
163+ const scripts = projectObject . architect . build . options . scripts ;
164+
165+ scripts . push ( chartsPath ) ;
166+
167+ host . overwrite ( 'angular.json' , JSON . stringify ( angularJsonFileObject , null , 2 ) ) ;
168+ } else {
169+ logger . error ( 'Failed to add charts script to angular.json' ) ;
170+ }
171+ }
172+ } ;
173+ }
174+
147175function updateAppComponentContent ( ) : any {
148176 return async ( host : Tree , context : SchematicContext ) => {
149177 const filePath = './src/app/app.component.html' ;
0 commit comments