@@ -409,9 +409,15 @@ $projectList.on('click', '.js_project_item', function () {
409409
410410 // 根据是否开启了服务设置 Gulp 按钮的状态
411411 if ( $this . data ( 'watch' ) ) {
412- setWatching ( ) ;
412+ setGulpBtnWatching ( ) ;
413413 } else {
414- setNormal ( ) ;
414+ setGulpBtnNormal ( ) ;
415+ }
416+ // 根据是否正在安装依赖包设置 Install 按钮的状态
417+ if ( $this . data ( 'install' ) ) {
418+ setInstallBtnInstalling ( ) ;
419+ } else {
420+ setInstallBtnNormal ( ) ;
415421 }
416422 }
417423
@@ -434,22 +440,34 @@ $projectList.on('click', '.js_openFolder', function () {
434440 }
435441} ) ;
436442
437- function setNormal ( ) {
443+ function setGulpBtnNormal ( ) {
438444 $gulpButton . removeClass ( 'frame_toolbar_btn_Watching' ) ;
439445 $gulpButton . text ( '开启 Gulp 服务' ) ;
440446
441447 $curProject . removeClass ( 'project_stage_item_Watching' ) ;
442448 $curProject . data ( 'watch' , false ) ;
443449}
444450
445- function setWatching ( ) {
451+ function setGulpBtnWatching ( ) {
446452 $gulpButton . addClass ( 'frame_toolbar_btn_Watching' ) ;
447453 $gulpButton . text ( 'Gulp 正在服务' ) ;
448454
449455 $curProject . addClass ( 'project_stage_item_Watching' ) ;
450456 $curProject . data ( 'watch' , true ) ;
451457}
452458
459+ function setInstallBtnNormal ( ) {
460+ $installButton . removeClass ( 'frame_toolbar_btn_Disabled' ) ;
461+
462+ $curProject . data ( 'install' , false ) ;
463+ }
464+
465+ function setInstallBtnInstalling ( ) {
466+ $installButton . addClass ( 'frame_toolbar_btn_Disabled' ) ;
467+
468+ $curProject . data ( 'install' , true ) ;
469+ }
470+
453471// 结束子进程
454472function killChildProcess ( projectDir ) {
455473 let storage = Common . getLocalStorage ( ) ;
@@ -548,6 +566,7 @@ function runDevTask(projectPath, task) {
548566 child = childProcess . spawn ( 'gulp' , [ task ] , { env : { 'PATH' :'/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin' } , cwd : qmuiPath , silent : true } ) ;
549567 }
550568 }
569+ console . log ( child . pid ) ;
551570
552571 child . stdout . setEncoding ( 'utf-8' ) ;
553572 child . stdout . on ( 'data' , function ( data ) {
@@ -566,8 +585,9 @@ function runDevTask(projectPath, task) {
566585 logReply ( `child process exited with code ${ code } ` , projectPath ) ;
567586 }
568587
588+ let tipText ;
569589 if ( task === 'main' ) {
570- let tipText ;
590+ // Gulp 服务进程结束处理
571591 if ( closeGulpManually ) {
572592 closeGulpManually = false ;
573593 tipText = '已关闭 Gulp 服务' ;
@@ -596,11 +616,39 @@ function runDevTask(projectPath, task) {
596616 Common . postNotification ( 'Gulp 意外停止工作' , '项目 ' + projectName + ' (' + projectDir + ') 的 Gulp 服务停止工作,请重新启动' ) ;
597617 }
598618 } else if ( task === 'install' ) {
599- $gulpButton . removeClass ( 'qw_hide' ) ;
600- $mergeButton . removeClass ( 'qw_hide' ) ;
601- $cleanButton . removeClass ( 'qw_hide' ) ;
602- $installButton . addClass ( 'qw_hide' ) ;
603- logReply ( logTextWithDate ( '依赖包安装完毕,可以开始使用 QMUI Web 的功能' ) , projectPath ) ;
619+ // 安装依赖包进程结束处理
620+ // 按照进程 pid 确定项目,然后手动更新 storage 和 UI 表现
621+ let $project = $ ( '.js_project_item[data-pid="' + this . pid + '"]' ) ;
622+ $project . data ( 'install' , false ) ;
623+
624+ let storage = Common . getLocalStorage ( ) ;
625+ storage [ 'projects' ] [ projectDir ] [ 'pid' ] = 0 ;
626+ Common . setLocalStorage ( storage ) ;
627+
628+ if ( projectDir === $curProject . data ( 'project' ) ) {
629+ $installButton . removeClass ( 'frame_toolbar_btn_Disabled' ) ;
630+ }
631+
632+ if ( code && code !== 0 ) {
633+ // 出错处理
634+ tipText = '安装依赖包进程意外停止,请检查 NPM 和 Github 等环境后重新启动' ;
635+ logReply ( logTextWithDate ( tipText ) , projectPath ) ;
636+ // 改变状态栏图标
637+ mainProcess . emit ( 'closeGulp' ) ;
638+ // 发出通知
639+ let projectName = $project . data ( 'name' ) ;
640+ Common . postNotification ( '安装依赖包进程意外停止' , '项目 ' + projectName + ' (' + projectDir + ') 安装依赖包进程意外停止,请检查 NPM 和 Github 等环境后重新启动' ) ;
641+ } else {
642+ // 成功处理
643+ if ( projectDir === $curProject . data ( 'project' ) ) {
644+ $gulpButton . removeClass ( 'qw_hide' ) ;
645+ $mergeButton . removeClass ( 'qw_hide' ) ;
646+ $cleanButton . removeClass ( 'qw_hide' ) ;
647+ $installButton . addClass ( 'qw_hide' ) ;
648+ }
649+ tipText = '依赖包安装完毕,可以开始使用 QMUI Web 的功能' ;
650+ logReply ( logTextWithDate ( tipText ) , projectPath ) ;
651+ }
604652 }
605653 } ) ;
606654
@@ -615,12 +663,15 @@ function runDevTask(projectPath, task) {
615663
616664 $curProject . attr ( 'data-pid' , child . pid ) ;
617665
618- setWatching ( ) ;
666+ setGulpBtnWatching ( ) ;
667+
668+ } else if ( task === 'install' ) {
669+ setInstallBtnInstalling ( ) ;
619670 }
620671 }
621672}
622673
623- var runTaskInCurrentTask = function ( task ) {
674+ var runTaskOnCurrentProject = function ( task ) {
624675 let projectDir = $curProject . data ( 'project' ) ;
625676 let storage = Common . getLocalStorage ( ) ;
626677 if ( storage && storage [ 'projects' ] && storage [ 'projects' ] [ projectDir ] ) {
@@ -629,7 +680,9 @@ var runTaskInCurrentTask = function(task) {
629680} ;
630681
631682$installButton . on ( 'click' , function ( ) {
632- runTaskInCurrentTask ( 'install' ) ;
683+ if ( ! $curProject . data ( 'install' ) ) {
684+ runTaskOnCurrentProject ( 'install' ) ;
685+ }
633686} ) ;
634687
635688$gulpButton . on ( 'click' , function ( ) {
@@ -639,20 +692,20 @@ $gulpButton.on('click', function() {
639692 if ( $curProject . data ( 'watch' ) ) {
640693 closeGulpManually = true ;
641694 killChildProcess ( projectDir ) ;
642- setNormal ( ) ;
695+ setGulpBtnNormal ( ) ;
643696 } else {
644- runTaskInCurrentTask ( 'main' ) ;
697+ runTaskOnCurrentProject ( 'main' ) ;
645698 }
646699} ) ;
647700
648701$mergeButton . on ( 'click' , function ( ) {
649702
650- runTaskInCurrentTask ( 'merge' ) ;
703+ runTaskOnCurrentProject ( 'merge' ) ;
651704} ) ;
652705
653706$cleanButton . on ( 'click' , function ( ) {
654707
655- runTaskInCurrentTask ( 'clean' ) ;
708+ runTaskOnCurrentProject ( 'clean' ) ;
656709} ) ;
657710
658711// 设置界面
0 commit comments