66
77import { strings , normalize } from '@angular-devkit/core' ;
88import { Schema as MyServiceSchema } from './schema' ;
9+ import { addRouteToScullyConfig } from '../utils/utils' ;
910
1011export default function ( options : MyServiceSchema ) : Rule {
1112 return ( host : Tree , context : SchematicContext ) => {
@@ -26,24 +27,26 @@ publish: false
2627` ) ;
2728 context . logger . info ( `✅ ${ fullDay } -${ name } file created` ) ;
2829 }
29- context . logger . info ( `start json scully` ) ;
30- // add into scully config
30+
31+ let scullyJson ;
3132 try {
32- const content : Buffer | null = host . read ( `/scully.json` ) ;
33- let jsonContent ;
34- if ( content ) { jsonContent = JSON . parse ( content . toString ( ) ) ; }
35- /* tslint:disable:no-string-literal */
36- jsonContent . routes [ `${ name } /:id` ] = {
37- type : 'contentFolder' ,
38- id : {
39- folder : './${name}'
40- }
41- } ;
42- host . overwrite ( `/scully.json` , JSON . stringify ( jsonContent , undefined , 2 ) ) ;
43- context . logger . info ( '✅️ Update scully.json' ) ;
33+ scullyJson = ( host . read ( '/scully.config.js' ) ) . toString ( ) ;
4434 } catch ( e ) {
45- context . logger . error ( 'Cant update scully.json' ) ;
35+ // for test in schematics
36+ scullyJson = `exports.config = {
37+ projectRoot: "./src/app",
38+ routes: {
39+ '/demo/:id': {
40+ type: 'fake',
41+ numberOfPages: 100
42+ },
43+ },
44+ };` ;
4645 }
46+ const slug = options . slug ? options . slug : 'id' ;
47+ const newScullyJson = addRouteToScullyConfig ( scullyJson , { name, slug, type : 'contentFolder' } ) ;
48+ host . overwrite ( `/scully.config.js` , newScullyJson ) ;
49+ context . logger . info ( '✅️ Update scully.config.js' ) ;
4750
4851 options . path = options . path ? options . path : strings . dasherize ( `./src/app/${ name } ` ) ;
4952
0 commit comments