1
1
'use strict' ;
2
2
3
+ var chalk = require ( 'chalk' ) ;
4
+ var Command = require ( 'ember-cli/lib/models/command' ) ;
5
+ var Promise = require ( 'ember-cli/lib/ext/promise' ) ;
6
+ var Project = require ( 'ember-cli/lib/models/project' ) ;
7
+ var SilentError = require ( 'silent-error' ) ;
8
+ var validProjectName = require ( 'ember-cli/lib/utilities/valid-project-name' ) ;
9
+ var normalizeBlueprint = require ( 'ember-cli/lib/utilities/normalize-blueprint-option' ) ;
10
+
3
11
var NewCommand = require ( 'ember-cli/lib/commands/new' ) ;
12
+ var GitInit = require ( '../tasks/git-init' ) ;
4
13
5
14
module . exports = NewCommand . extend ( {
6
15
availableOptions : [
@@ -11,7 +20,68 @@ module.exports = NewCommand.extend({
11
20
{ name : 'skip-bower' , type : Boolean , default : true , aliases : [ 'sb' ] } ,
12
21
{ name : 'skip-git' , type : Boolean , default : false , aliases : [ 'sg' ] } ,
13
22
{ name : 'directory' , type : String , aliases : [ 'dir' ] }
14
- ]
23
+ ] ,
24
+ run : function ( commandOptions , rawArgs ) {
25
+ var packageName = rawArgs [ 0 ] ,
26
+ message ;
27
+
28
+ commandOptions . name = rawArgs . shift ( ) ;
29
+
30
+ if ( ! packageName ) {
31
+ message = chalk . yellow ( 'The `ember ' + this . name + '` command requires a ' +
32
+ 'name to be specified. For more details, use `ember help`.' ) ;
33
+
34
+ return Promise . reject ( new SilentError ( message ) ) ;
35
+ }
36
+
37
+ if ( commandOptions . dryRun ) {
38
+ commandOptions . skipGit = true ;
39
+ }
40
+
41
+ if ( packageName === '.' ) {
42
+ message = 'Trying to generate an application structure in this directory? Use `ember init` instead.' ;
43
+
44
+ return Promise . reject ( new SilentError ( message ) ) ;
45
+ }
46
+
47
+ if ( ! validProjectName ( packageName ) ) {
48
+ message = 'We currently do not support a name of `' + packageName + '`.' ;
49
+
50
+ return Promise . reject ( new SilentError ( message ) ) ;
51
+ }
52
+
53
+ commandOptions . blueprint = normalizeBlueprint ( commandOptions . blueprint ) ;
54
+
55
+ if ( ! commandOptions . directory ) {
56
+ commandOptions . directory = packageName ;
57
+ }
58
+
59
+ var createAndStepIntoDirectory = new this . tasks . CreateAndStepIntoDirectory ( {
60
+ ui : this . ui ,
61
+ analytics : this . analytics
62
+ } ) ;
63
+ var InitCommand = this . commands . Init ;
64
+
65
+ var gitInit = new GitInit ( {
66
+ ui : this . ui ,
67
+ project : this . project
68
+ } ) ;
69
+
70
+ var initCommand = new InitCommand ( {
71
+ ui : this . ui ,
72
+ analytics : this . analytics ,
73
+ tasks : this . tasks ,
74
+ project : Project . nullProject ( this . ui , this . cli )
75
+ } ) ;
76
+
77
+ return createAndStepIntoDirectory
78
+ . run ( {
79
+ directoryName : commandOptions . directory ,
80
+ dryRun : commandOptions . dryRun
81
+ } )
82
+ . then ( initCommand . run . bind ( initCommand , commandOptions , rawArgs ) )
83
+ . then ( gitInit . run . bind ( gitInit , commandOptions , rawArgs ) ) ;
84
+ }
15
85
} ) ;
16
86
17
87
module . exports . overrideCore = true ;
0 commit comments