import { Rule , Tree } from '@angular-devkit/schematics' ; import { WorkspaceProject , WorkspaceSchema } from '@schematics/angular/utility/workspace-models' ; import { logError } from '../shared/log-helper' ; export function addTsconfigPaths ( ) { return ( tree ) => { try { const tsconfig = JSON . parse ( tree . read ( 'tsconfig.json' ) . toString ( ) . replace ( /\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm , '' ) ) ; const angularJSON = JSON . parse ( tree . read ( 'angular.json' ) . toString ( ) ) ; const libraryProjectNames = getLibraryProjectNames ( angularJSON ) ; if ( ! tsconfig . compilerOptions . paths ) { tsconfig . compilerOptions . paths = { } ; } libraryProjectNames . forEach ( ( libraryProjectName ) => { tsconfig . compilerOptions . paths [ `${ libraryProjectName }/*` ] = [ `projects/${ libraryProjectName }/*` , `projects/${ libraryProjectName }` ] ; } ) ; tree . overwrite ( 'tsconfig.json' , JSON . stringify ( tsconfig , null , 2 ) ) ; } catch ( e ) { logError ( `Something went wrong while ng-samurai tried to update your tsconfig.json, ${ e . toString ( ) }` ) ; } } ; } function getLibraryProjectNames ( angularJSON ) { return Object . values ( angularJSON . projects ) . filter ( ( project ) => project . projectType === 'library' ) . map ( ( project ) => project . root . split ( '/' ) [ 1 ] ) ; }