@@ -9,6 +9,10 @@ var merge = require('lodash-node/modern/objects/merge');
99var path = require ( 'path' ) ;
1010var pkg = require ( '../package.json' ) ;
1111var ui = require ( './ui' ) ;
12+ var fs = require ( 'fs' ) ;
13+ var denodeify = RSVP . denodeify ;
14+ var readFile = denodeify ( fs . readFile ) ;
15+ var sequence = require ( './utilities/sequence' ) ;
1216
1317RSVP . on ( 'error' , function ( error ) {
1418 ui . write ( chalk . red ( String ( error ) ) + '\n' ) ;
@@ -53,32 +57,41 @@ function loadInsight() {
5357 } ) ;
5458}
5559
60+ function readDefaults ( ) {
61+ var defaultsPath = path . join ( process . cwd ( ) , '.ember-cli' ) ;
62+ return readFile ( defaultsPath ) . then ( function ( content ) {
63+ return content . toString ( ) . split ( ' ' ) ;
64+ } ) . catch ( function ( ) { } ) ;
65+ }
66+
67+
5668Cli . run = function run ( argv , ui , insight ) {
5769 var commands = require ( '../lib/commands/commands' ) ;
58- var permission ;
5970
6071 ui = ui || require ( './ui' ) ;
6172 insight = insight || loadInsight ( ) ;
6273
6374 var cli = new Cli ( argv , commands , ui , insight ) ;
75+ var permission = insight . askPermission ( ) ;
6476
65- permission = insight . askPermission ( ) ;
66-
67- return permission . then ( function ( ) {
68- return cli . run ( ) ;
69- } ) ;
77+ return sequence ( [
78+ permission ,
79+ readDefaults ,
80+ cli . run . bind ( cli )
81+ ] ) ;
7082} ;
7183
7284function collectArgs ( args , options ) {
7385 return JSON . stringify ( args . concat ( [ options ] ) ) ;
7486}
87+
7588function setupEnvironment ( command , options ) {
7689 if ( typeof command . getEnv === 'function' ) {
7790 process . env . BROCCOLI_ENV = command . getEnv ( options ) || 'development' ;
7891 }
7992}
8093
81- Cli . prototype . runCurrentCommand = function ( ) {
94+ Cli . prototype . runCurrentCommand = function ( defaults ) {
8295 var cmd = this . cmd ;
8396 cmd = commandAliases [ cmd ] ? commandAliases [ cmd ] : cmd ;
8497 var action = this . commands [ cmd ] ;
@@ -94,9 +107,16 @@ Cli.prototype.runCurrentCommand = function() {
94107 action = this . commands . help ;
95108 }
96109
97- var opts = nopt ( action . types , action . shorthands , this . argv ) ;
110+ var parseOpts = nopt . bind ( null , action . types , action . shorthands ) ;
111+ var opts = parseOpts ( this . argv ) ;
112+
113+ if ( defaults !== undefined ) {
114+ defaults = nopt ( action . types , action . shorthands , defaults , 0 ) ;
115+ } else {
116+ defaults = { } ;
117+ }
98118
99- var options = merge ( { } , opts , {
119+ var options = merge ( { } , opts , defaults , {
100120 appRoot : process . cwd ( ) ,
101121 cliRoot : path . resolve ( path . join ( __dirname , '..' ) )
102122 } ) ;
@@ -116,7 +136,7 @@ Cli.prototype.runCurrentCommand = function() {
116136
117137} ;
118138
119- Cli . prototype . run = function ( ) {
139+ Cli . prototype . run = function ( defaults ) {
120140 var opts = this . opts ;
121141 var cli = this ;
122142
@@ -128,10 +148,10 @@ Cli.prototype.run = function() {
128148 }
129149
130150 return new Promise ( function ( resolve ) {
131- resolve ( cli . runCurrentCommand ( ) ) ;
151+ resolve ( cli . runCurrentCommand ( defaults ) ) ;
132152 } ) . catch ( function ( err ) {
133- // Log it if it's just a string. Else if it's a real error, throw.
134- if ( typeof err === 'string' ) { cli . ui . write ( err ) ; }
135- else { throw err ; }
136- } ) ;
153+ // Log it if it's just a string. Else if it's a real error, throw.
154+ if ( typeof err === 'string' ) { cli . ui . write ( err ) ; }
155+ else { throw err ; }
156+ } ) ;
137157} ;
0 commit comments