22
33import each from 'async-each'
44import waterfall from 'async-waterfall'
5+ import ora from 'ora'
56import shell from 'shelljs'
67import yargs from 'yargs'
78import gitops from './gitops'
89import { cloneSubCommands , fetchSubCommands , pullSubCommands } from './helpers'
910import { checkOutBranch , currentBranchName , detectPackageManager , getRepoName , log , packagePaths } from './libs/utils'
1011import npmInstall from './npm'
1112import shellConfig from './shellconfig'
12-
1313// User defined constants
1414const errorLog = [ ]
1515const warningLog = [ ]
@@ -39,6 +39,7 @@ shell.config = shellConfig
3939 */
4040function executeGitOperation ( done ) {
4141 const command = argv . _ [ 0 ]
42+ console . log ( )
4243 switch ( command ) {
4344 case 'pull' :
4445 return gitops . pull ( argv , done )
@@ -59,23 +60,21 @@ function executeNPMInstall (done) {
5960 const activeBranchName = currentBranchName ( )
6061 const branchToCheckout = argv . b && typeof argv . b === 'string' && activeBranchName !== argv . b ? argv . b : false
6162 const branchName = branchToCheckout ? checkOutBranch ( branchToCheckout ) : activeBranchName
62-
63- log . info ( 'listing all package.json files in this project...' )
64-
63+ const listSpinner = ora ( 'Listing all package.json files in this project' ) . start ( )
64+ const npmInstallSpinner = ora ( )
6565 packagePaths ( branchName , ( error , packagePaths ) => {
6666 if ( error ) {
67+ listSpinner . fail ( 'Listing package.json is not successful.' )
6768 return done ( error )
6869 }
6970
7071 // is there any package.json?
7172 if ( ! packagePaths . length ) {
72- return done (
73- NO_PACKAGE_FOUND ,
74- 'No package.json not found in your project. ' + 'Skipping dependency installation.'
75- )
73+ listSpinner . info ( 'No package.json is found in your project. Skipping dependency installation.' )
74+ return done ( NO_PACKAGE_FOUND )
7675 }
77-
78- log . info ( `installing dependencies for branch ${ branchName } `)
76+ listSpinner . succeed ( `Found ${ packagePaths . length } package.json files.` )
77+ npmInstallSpinner . start ( `Installing dependencies for branch ${ branchName } `)
7978 each (
8079 packagePaths ,
8180 ( path , cb ) => {
@@ -97,6 +96,7 @@ function executeNPMInstall (done) {
9796 }
9897
9998 if ( argv . d ) {
99+ console . log ( '' )
100100 log . info ( 'Log for ' + path + 'package.json' )
101101 log . info ( output )
102102 }
@@ -117,13 +117,18 @@ function executeNPMInstall (done) {
117117 }
118118
119119 if ( warningLog . length ) {
120+ npmInstallSpinner . warn ( 'Warnings given by npm during installing dependencies' )
120121 return done ( null , HAS_WARNING )
121122 }
122123
123124 if ( errorLog . length ) {
125+ npmInstallSpinner . fail (
126+ 'Error given by package manager during installing dependencies. Please check npm-debug.log under given directory'
127+ )
124128 return done ( null , HAS_ERROR )
125129 }
126130
131+ npmInstallSpinner . succeed ( 'Dependencies are installed successfully.' )
127132 return done ( null , NO_ERROR )
128133 }
129134 )
@@ -139,7 +144,6 @@ function installNPMPackages (gitOpOutput, done) {
139144 const cmd = argv . _ [ 0 ]
140145 let cloneDir = ''
141146
142- log . success ( 'git ' + cmd + ' ends successfully!!' )
143147 if ( argv . d ) {
144148 log . info ( gitOpOutput )
145149 }
@@ -162,18 +166,14 @@ waterfall([executeGitOperation, installNPMPackages], (err, cmdOutput) => {
162166 }
163167
164168 if ( cmdOutput === HAS_WARNING ) {
165- log . info ( 'warnings given by npm during installing dependencies' )
166169 warningLog . forEach ( function iterateWarnings ( warning ) {
167170 log . warn ( warning . packagePath + '\r\n' + warning . messages . join ( '\r\n' ) )
168171 console . log ( '' )
169172 } )
170173 }
171174
172175 if ( cmdOutput === HAS_ERROR ) {
173- log . info ( `npm modules installation has finished with error(s).
174- Please check npm-debug.log file in reported package.json directory` )
175176 return log . error ( errorLog . join ( '\r\n' ) )
176177 }
177-
178- return log . success ( 'all dependencies installed successfully!!!' )
178+ console . log ( )
179179} )
0 commit comments