5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import { normalize , relative , strings , tags } from '@angular-devkit/core' ;
8
+ import { normalize , relative , strings } from '@angular-devkit/core' ;
9
9
import { experimental } from '@angular-devkit/core' ;
10
10
import {
11
11
MergeStrategy ,
@@ -26,6 +26,7 @@ import {
26
26
import { Schema as E2eOptions } from '../e2e/schema' ;
27
27
import { getWorkspace , getWorkspacePath } from '../utility/config' ;
28
28
import { latestVersions } from '../utility/latest-versions' ;
29
+ import { validateProjectName } from '../utility/validation' ;
29
30
import { Schema as ApplicationOptions } from './schema' ;
30
31
31
32
type WorkspaceSchema = experimental . workspace . WorkspaceSchema ;
@@ -226,43 +227,6 @@ function addAppToWorkspaceFile(options: ApplicationOptions, workspace: Workspace
226
227
host . overwrite ( getWorkspacePath ( host ) , JSON . stringify ( workspace , null , 2 ) ) ;
227
228
} ;
228
229
}
229
- const projectNameRegexp = / ^ [ a - z A - Z ] [ . 0 - 9 a - z A - Z ] * ( - [ . 0 - 9 a - z A - Z ] * ) * $ / ;
230
- const unsupportedProjectNames = [ 'test' , 'ember' , 'ember-cli' , 'vendor' , 'app' ] ;
231
-
232
- function getRegExpFailPosition ( str : string ) : number | null {
233
- const parts = str . indexOf ( '-' ) >= 0 ? str . split ( '-' ) : [ str ] ;
234
- const matched : string [ ] = [ ] ;
235
-
236
- parts . forEach ( part => {
237
- if ( part . match ( projectNameRegexp ) ) {
238
- matched . push ( part ) ;
239
- }
240
- } ) ;
241
-
242
- const compare = matched . join ( '-' ) ;
243
-
244
- return ( str !== compare ) ? compare . length : null ;
245
- }
246
-
247
- function validateProjectName ( projectName : string ) {
248
- const errorIndex = getRegExpFailPosition ( projectName ) ;
249
- if ( errorIndex !== null ) {
250
- const firstMessage = tags . oneLine `
251
- Project name "${ projectName } " is not valid. New project names must
252
- start with a letter, and must contain only alphanumeric characters or dashes.
253
- When adding a dash the segment after the dash must also start with a letter.
254
- ` ;
255
- const msg = tags . stripIndent `
256
- ${ firstMessage }
257
- ${ projectName }
258
- ${ Array ( errorIndex + 1 ) . join ( ' ' ) + '^' }
259
- ` ;
260
- throw new SchematicsException ( msg ) ;
261
- } else if ( unsupportedProjectNames . indexOf ( projectName ) !== - 1 ) {
262
- throw new SchematicsException ( `Project name "${ projectName } " is not a supported name.` ) ;
263
- }
264
-
265
- }
266
230
267
231
export default function ( options : ApplicationOptions ) : Rule {
268
232
return ( host : Tree , context : SchematicContext ) => {
0 commit comments