license import { tags } from '@angular-devkit/core' ; import { SchematicsException } from '@angular-devkit/schematics' ; export function validateName ( name ) { if ( name && /^\d/ . test ( name ) ) { throw new SchematicsException ( tags . oneLine `name (${ name })
        can not start with a digit.` ) ; } } export const htmlSelectorRe = /^[a-zA-Z][.0-9a-zA-Z]*(:?-[a-zA-Z][.0-9a-zA-Z]*)*$/ ; export function validateHtmlSelector ( selector ) { if ( selector && ! htmlSelectorRe . test ( selector ) ) { throw new SchematicsException ( tags . oneLine `Selector (${ selector })
        is invalid.` ) ; } } export function validateProjectName ( projectName ) { const errorIndex = getRegExpFailPosition ( projectName ) ; const unsupportedProjectNames = [ 'test' , 'ember' , 'ember-cli' , 'vendor' , 'app' ] ; const packageNameRegex = /^(?:@[a-zA-Z0-9_-]+\/)?[a-zA-Z0-9_-]+$/ ; if ( errorIndex !== null ) { const firstMessage = tags . oneLine `
    Project name "${ projectName }" is not valid. New project names must
    start with a letter, and must contain only alphanumeric characters or dashes.
    When adding a dash the segment after the dash must also start with a letter.
    ` ; const msg = tags . stripIndent `
    ${ firstMessage }
    ${ projectName }
    ${ Array ( errorIndex + 1 ) . join ( ' ' ) + '^' }
    ` ; throw new SchematicsException ( msg ) ; } else if ( unsupportedProjectNames . indexOf ( projectName ) !== - 1 ) { throw new SchematicsException ( `Project name ${ JSON . stringify ( projectName ) } is not a supported name.` ) ; } else if ( ! packageNameRegex . test ( projectName ) ) { throw new SchematicsException ( `Project name ${ JSON . stringify ( projectName ) } is invalid.` ) ; } } function getRegExpFailPosition ( str ) { const isScope = /^@.*\/.*/ . test ( str ) ; if ( isScope ) { str = str . replace ( /^@/ , '' ) ; str = str . replace ( /\//g , '-' ) ; } const parts = str . indexOf ( '-' ) >= 0 ? str . split ( '-' ) : [ str ] ; const matched = [ ] ; const projectNameRegexp = /^[a-zA-Z][.0-9a-zA-Z]*(-[.0-9a-zA-Z]*)*$/ ; parts . forEach ( part => { if ( part . match ( projectNameRegexp ) ) { matched . push ( part ) ; } } ) ; const compare = matched . join ( '-' ) ; return ( str !== compare ) ? compare . length : null ; }