@@ -16,11 +16,21 @@ limitations under the License.
1616"use strict" ;
1717
1818const BaseCommand = require ( "../lib/baseCommand" ) ;
19+ const prompt = require ( 'prompt' )
20+ const Q = require ( "q" ) ;
1921
2022const ToolsApi = require ( "wchtools-api" ) ;
2123const utils = ToolsApi . getUtils ( ) ;
2224const i18n = utils . getI18N ( __dirname , ".json" , "en" ) ;
2325
26+ var property = {
27+ name : 'yesno' ,
28+ message : 'y/n' ,
29+ validator : / y [ e s ] * | n [ o ] ? / ,
30+ warning : 'Must respond y or n' ,
31+ default : 'n'
32+ } ;
33+
2434class PublishCommand extends BaseCommand {
2535 /**
2636 * Create a PublishCommand object.
@@ -51,6 +61,32 @@ class PublishCommand extends BaseCommand {
5161 } ) ;
5262 }
5363
64+ createPublishingJob ( helper , status , context , apiOptions , jobParameters , self ) {
65+ if ( status ) {
66+ self . displaySiteRevisionStatus ( helper , context , apiOptions ) ;
67+ } else {
68+ BaseCommand . displayToConsole ( i18n . __ ( 'cli_publishing_job_starting' ) ) ;
69+
70+ self . spinner = self . getProgram ( ) . getSpinner ( ) ;
71+ self . spinner . start ( ) ;
72+ helper . createPublishingJob ( context , jobParameters , apiOptions )
73+ . then ( job => {
74+ self . spinner . stop ( ) ;
75+ const startedMsg = i18n . __ ( 'cli_publishing_job_started' ) ;
76+ self . successMessage ( startedMsg ) ;
77+ if ( self . getCommandLineOption ( "verbose" ) ) {
78+ const logger = this . getLogger ( ) ;
79+ logger . info ( i18n . __ ( "cli_publishing_job_details" , { job_details : JSON . stringify ( job , null , " " ) } ) ) ;
80+ }
81+ } )
82+ . catch ( err => {
83+ const curError = i18n . __ ( "cli_publishing_job_error" , { message : err . message } ) ;
84+ self . spinner . stop ( ) ;
85+ self . errorMessage ( curError ) ;
86+ } ) ;
87+ }
88+ }
89+
5490 /**
5591 * Create a new publishing job, or look up the status of the publishing site revision.
5692 */
@@ -59,7 +95,6 @@ class PublishCommand extends BaseCommand {
5995 const toolsApi = new ToolsApi ( ) ;
6096 const context = toolsApi . getContext ( ) ;
6197
62- const logger = this . getLogger ( ) ;
6398 const mode = this . getCommandLineOption ( "rebuild" ) ? "REBUILD" : "UPDATE" ;
6499 const status = this . getCommandLineOption ( "status" ) ;
65100 const apiOptions = this . getApiOptions ( ) ;
@@ -82,26 +117,23 @@ class PublishCommand extends BaseCommand {
82117 return self . handleInitialization ( context ) ;
83118 } )
84119 . then ( function ( /*results*/ ) {
85- if ( status ) {
86- self . displaySiteRevisionStatus ( helper , context , apiOptions ) ;
120+ if ( mode === 'REBUILD' ) {
121+ self . warningMessage ( i18n . __ ( 'cli_publishing_rebuild_warn' ) ) ;
122+ prompt . message = '' ; // remove 'prompt' when asking for value
123+ prompt . start ( ) ;
124+ prompt . get ( property , function ( err , result ) {
125+ // Display a blank line to separate the prompt output from the delete output.
126+ BaseCommand . displayToConsole ( "" ) ;
127+ if ( err ) {
128+ self . errorMessage ( err ) ;
129+ } else if ( result . yesno === 'yes' || result . yesno === 'y' ) {
130+ self . createPublishingJob ( helper , status , context , apiOptions , jobParameters , self ) ;
131+ } else {
132+ self . successMessage ( i18n . __ ( 'cli_publishing_rebuild_canceled' ) ) ;
133+ }
134+ } ) ;
87135 } else {
88- BaseCommand . displayToConsole ( i18n . __ ( 'cli_publishing_job_starting' ) ) ;
89- self . spinner = self . getProgram ( ) . getSpinner ( ) ;
90- self . spinner . start ( ) ;
91- return helper . createPublishingJob ( context , jobParameters , apiOptions )
92- . then ( job => {
93- self . spinner . stop ( ) ;
94- const startedMsg = i18n . __ ( 'cli_publishing_job_started' ) ;
95- self . successMessage ( startedMsg ) ;
96- if ( self . getCommandLineOption ( "verbose" ) ) {
97- logger . info ( i18n . __ ( "cli_publishing_job_details" , { job_details : JSON . stringify ( job , null , " " ) } ) ) ;
98- }
99- } )
100- . catch ( err => {
101- const curError = i18n . __ ( "cli_publishing_job_error" , { message : err . message } ) ;
102- self . spinner . stop ( ) ;
103- self . errorMessage ( curError ) ;
104- } ) ;
136+ self . createPublishingJob ( helper , status , context , apiOptions , jobParameters , self )
105137 }
106138 } )
107139 . catch ( err => {
@@ -110,7 +142,7 @@ class PublishCommand extends BaseCommand {
110142 . finally ( ( ) => {
111143 self . resetCommandLineOptions ( ) ;
112144 } ) ;
113- }
145+ } ;
114146
115147 /**
116148 * Reset the command line options for this command.
0 commit comments