|
1 | 1 | import * as chalk from 'chalk'; |
2 | 2 | import InitCommand from './init'; |
3 | | -import {oneLine, stripIndent} from 'common-tags'; |
| 3 | +import { validateProjectName } from '../utilities/validate-project-name'; |
4 | 4 |
|
5 | 5 | const Command = require('../ember-cli/lib/models/command'); |
6 | 6 | const Project = require('../ember-cli/lib/models/project'); |
7 | 7 | const SilentError = require('silent-error'); |
8 | | -const validProjectName = require('../ember-cli/lib/utilities/valid-project-name'); |
9 | | - |
10 | | -const packageNameRegexp = /^[a-zA-Z][.0-9a-zA-Z]*(-[a-zA-Z][.0-9a-zA-Z]*)*$/; |
11 | | - |
12 | | -function getRegExpFailPosition(str: string) { |
13 | | - const parts = str.split('-'); |
14 | | - const matched: string[] = []; |
15 | | - |
16 | | - parts.forEach(part => { |
17 | | - if (part.match(packageNameRegexp)) { |
18 | | - matched.push(part); |
19 | | - } |
20 | | - }); |
21 | | - |
22 | | - const compare = matched.join('-'); |
23 | | - return (str !== compare) ? compare.length : null; |
24 | | -} |
25 | 8 |
|
26 | 9 | const NewCommand = Command.extend({ |
27 | 10 | name: 'new', |
@@ -53,36 +36,14 @@ const NewCommand = Command.extend({ |
53 | 36 | `The "ng ${this.name}" command requires a name argument to be specified. ` + |
54 | 37 | `For more details, use "ng help".`)); |
55 | 38 | } |
56 | | - if (!packageName.match(packageNameRegexp)) { |
57 | | - const firstMessage = oneLine` |
58 | | - Project name "${packageName}" is not valid. New project names must |
59 | | - start with a letter, and must contain only alphanumeric characters or dashes. |
60 | | - When adding a dash the segment after the dash must start with a letter too. |
61 | | - `; |
62 | | - const msg = stripIndent` |
63 | | - ${firstMessage} |
64 | | - ${packageName} |
65 | | - ${Array(getRegExpFailPosition(packageName) + 1).join(' ') + '^'} |
66 | | - `; |
67 | | - return Promise.reject(new SilentError(msg)); |
68 | | - } |
| 39 | + |
| 40 | + validateProjectName(packageName); |
69 | 41 |
|
70 | 42 | commandOptions.name = packageName; |
71 | 43 | if (commandOptions.dryRun) { |
72 | 44 | commandOptions.skipGit = true; |
73 | 45 | } |
74 | 46 |
|
75 | | - if (packageName === '.') { |
76 | | - return Promise.reject(new SilentError( |
77 | | - `Trying to generate an application structure in this directory? Use "ng init" ` + |
78 | | - `instead.`)); |
79 | | - } |
80 | | - |
81 | | - if (!validProjectName(packageName)) { |
82 | | - return Promise.reject( |
83 | | - new SilentError(`We currently do not support a name of "${packageName}".`)); |
84 | | - } |
85 | | - |
86 | 47 | if (!commandOptions.directory) { |
87 | 48 | commandOptions.directory = packageName; |
88 | 49 | } |
|
0 commit comments