lib/prompt-if-main-theme.js
function promptIfMainTheme(env) {
  return new Promise((resolve, reject) => {
    const c = config.shopify[env]

    if (!c.api_key) {
      console.log(chalk.yellow(`The "${env}" environment in config/shopify.yml does not specify an "api_key". Skipping check for if is main theme.`))
      resolve()
      return
    }

    // c.theme_id is live or equal to mainThemeId
    if (c.theme_id === 'live' || (mainThemeId && mainThemeId === c.theme_id)) {
      const question = 'You are about to deploy to the main theme. Continue ?'

      prompt(question, false).then((isYes) => {
        if (isYes) {
          resolve()
          return
        }

        reject('Aborting. You aborted the deploy.')
      })

      return
    }

    // we already have a mainThemeId and it's not c.theme_id
    if (mainThemeId && mainThemeId !== c.theme_id) {
      resolve()
      return
    }

    fetchMainThemeId(env)
      .then((id) => {
        mainThemeId = id
        promptIfMainTheme(env).then(resolve).catch(reject)
      })
      .catch(reject)
  })
}
function promptIfMainTheme(env) {
  return new Promise((resolve, reject) => {
    const c = config.shopify[env]

    if (!c.api_key) {
      console.log(chalk.yellow(`The "${env}" environment in config/shopify.yml does not specify an "api_key". Skipping check for if is main theme.`))
      resolve()
      return
    }

    // c.theme_id is live or equal to mainThemeId
    if (c.theme_id === 'live' || (mainThemeId && mainThemeId === c.theme_id)) {
      const question = 'You are about to deploy to the main theme. Continue ?'

      prompt(question, false).then((isYes) => {
        if (isYes) {
          resolve()
          return
        }

        reject('Aborting. You aborted the deploy.')
      })

      return
    }

    // we already have a mainThemeId and it's not c.theme_id
    if (mainThemeId && mainThemeId !== c.theme_id) {
      resolve()
      return
    }

    fetchMainThemeId(env)
      .then((id) => {
        mainThemeId = id
        promptIfMainTheme(env).then(resolve).catch(reject)
      })
      .catch(reject)
  })
}
function promptIfMainTheme ( env ) { return new Promise ( ( resolve , reject ) => { const c = config . shopify [ env ] if ( ! c . api_key ) { console . log ( chalk . yellow ( ` ${ env } ` ) ) resolve ( ) return } // c.theme_id is live or equal to mainThemeId if ( c . theme_id === 'live' || ( mainThemeId && mainThemeId === c . theme_id ) ) { const question = 'You are about to deploy to the main theme. Continue ?' prompt ( question , false ) . then ( ( isYes ) => { if ( isYes ) { resolve ( ) return } reject ( 'Aborting. You aborted the deploy.' ) } ) return } // we already have a mainThemeId and it's not c.theme_id if ( mainThemeId && mainThemeId !== c . theme_id ) { resolve ( ) return } fetchMainThemeId ( env ) . then ( ( id ) => { mainThemeId = id promptIfMainTheme ( env ) . then ( resolve ) . catch ( reject ) } ) . catch ( reject ) } ) }
Prompt the user to confirm if they are about to deploy to the main theme

@param   env   String  The environment to check against
@return        Promise Reason for abort or empty resolve
Prompt the user to confirm if they are about to deploy to the main theme