@@ -123,8 +123,7 @@ ComponentManager.prototype.rm = function(args, callback) {
123123} ;
124124
125125ComponentManager . prototype . import = function ( args , callback ) {
126- var self = this ,
127- project ,
126+ var project ,
128127 componentName ,
129128 pkgPath ,
130129 pkgContent ,
@@ -134,54 +133,70 @@ ComponentManager.prototype.import = function(args, callback) {
134133 job ;
135134
136135 if ( ! ( args . name && args . project ) ) {
137- return this . _logger . error ( `Usage: webgme import ${ this . _name } [${ this . _name } ] [project]` ) ;
136+ let err = new Error ( 'missing required "name" or "project"' ) ;
137+ this . _logger . error ( err . message ) ;
138+ return callback ( err ) ;
138139 }
139140 componentName = args . name ;
140141 project = args . project ;
141- cmd = args . dev ?
142- `npm install ${ project } --save-dev` :
143- `npm install ${ project } --save` ;
144142
145143 // Add the project to the package.json
146144 var pkgProject = args . packageName || utils . getPackageName ( project ) ;
147145 this . _logger . info ( `Adding ${ componentName } from ${ pkgProject } ` ) ;
148146
149147 // Add the component to the webgme config component paths
150148 // FIXME: Call this without --save then later save it
151- job = spawn ( cmd , { cwd : projectRoot } ) ;
149+ if ( args . skipInstall ) {
150+ this . _addComponentFromProject ( componentName , pkgProject , callback ) ;
151+ } else {
152+ this . _installProject ( project , args . dev , ( err , result ) => {
153+ this . _addComponentFromProject ( componentName , pkgProject , callback ) ;
154+ } ) ;
155+ }
156+ } ;
157+
158+ ComponentManager . prototype . _addComponentFromProject = function ( name , project , callback ) {
159+ let info = {
160+ name : name ,
161+ pkg : project
162+ } ;
163+
164+ return this . _getJsonForConfig ( info , ( err , configObject ) => {
165+ if ( err ) {
166+ this . _logger . error ( err ) ;
167+ return callback ( err ) ;
168+ }
169+
170+ var config = utils . getConfig ( ) ;
171+ config . dependencies [ this . _group ] [ name ] = configObject ;
172+ utils . saveConfig ( config ) ;
173+
174+ // Update the webgme config file from
175+ // the cli's config
176+ utils . updateWebGMEConfig ( ) ;
177+ configObject . id = name ;
178+ return callback ( null , configObject ) ;
179+ } ) ;
180+ } ;
181+
182+ ComponentManager . prototype . _installProject = function ( projectName , isDev , callback ) {
183+ let projectRoot = utils . getRootPath ( ) ;
184+ let cmd = isDev ?
185+ `npm install ${ projectName } --save-dev` :
186+ `npm install ${ projectName } --save` ;
187+ let job = spawn ( cmd , { cwd : projectRoot } ) ;
152188
153189 this . _logger . info ( cmd ) ;
154190 this . _logger . writeStream ( job . stdout ) ;
155191 this . _logger . errorStream ( job . stderr ) ;
156192
157- job . on ( 'close' , function ( code ) {
158- var err ,
159- info = {
160- name : componentName ,
161- pkg : pkgProject
162- } ;
163- self . _logger . info ( 'npm exited with: ' + code ) ;
193+ job . on ( 'close' , code => {
194+ this . _logger . info ( `npm exited with: ${ code } ` ) ;
164195 if ( code === 0 ) { // Success!
165- self . _getJsonForConfig ( info , function ( err , configObject ) {
166- if ( err ) {
167- self . _logger . error ( err ) ;
168- return callback ( err ) ;
169- }
170-
171- var config = utils . getConfig ( ) ;
172- config . dependencies [ self . _group ] [ componentName ] = configObject ;
173- utils . saveConfig ( config ) ;
174-
175- // Update the webgme config file from
176- // the cli's config
177- utils . updateWebGMEConfig ( ) ;
178- configObject . id = componentName ;
179- return callback ( null , configObject ) ;
180- } ) ;
181-
196+ return callback ( null ) ;
182197 } else {
183- err = ' Could not find project (' + project + ') !' ;
184- self . _logger . error ( err ) ;
198+ let err = ` Could not find project (${ projectName } )!` ;
199+ this . _logger . error ( err ) ;
185200 return callback ( err ) ;
186201 }
187202 } ) ;
0 commit comments