import { normalize , workspaces } from '@angular-devkit/core' ; import { SchematicsException } from '@angular-devkit/schematics' ; import { ProjectDefinitionCollection } from "@angular-devkit/core/src/workspace/definitions" ; export function getProjectPath ( workspace , options ) { const project = getProject ( workspace , options ) ; if ( project ?. root . substr ( - 1 ) === '/' ) { project . root = project . root . substr ( 0 , project . root . length - 1 ) ; } if ( options . path === undefined ) { const projectDirName = project ?. extensions . projectType === 'application' ? 'app' : 'lib' ; const sourceRoot = getSourceRoot ( project ?. sourceRoot ) ; return `${ project ?. root ? `/${ project . root }` : '' }/${ sourceRoot }/${ projectDirName }` ; } return options . path ; } export function getProject ( workspace , options , typeFilter = null ) { if ( ! options . project ) { if ( workspace . projects . size === 0 ) { throw new SchematicsException ( 'Your app must have at least 1 project to use Playground.' ) ; } let firstFilteredProjectName = getFirstProjectName ( workspace . projects ) ; if ( typeFilter ) { for ( const [ projectName , project ] of workspace . projects . entries ( ) ) { if ( project . extensions . projectType === typeFilter ) { firstFilteredProjectName = projectName ; break ; } } } options . project = firstFilteredProjectName ; } return workspace . projects . get ( options . project || '' ) ; } export const getSourceRoot = ( sourceRoot ) => sourceRoot === undefined ? 'src' : normalize ( sourceRoot ) ; const getFirstProjectName = ( projects ) : string | undefined => { let firstProject = undefined ; for ( const projectName of projects . keys ( ) ) { firstProject = projectName ; break ; } return firstProject ; } ;