lib/convert.js
function convertWithContainer (program) {
  return new Promise((resolve, reject) => {
    if (!program.desktopConverter) {
      utils.log('Could not find the Project Centennial Desktop App Converter, which is required to')
      utils.log('run the conversion to appx using a Windows Container.\n')
      utils.log('Consult the documentation at https://aka.ms/electron-windows-store for a tutorial.\n')
      utils.log('You can find the Desktop App Converter at https://www.microsoft.com/en-us/download/details.aspx?id=51691\n')
      utils.log('Exiting now - restart when you downloaded and unpacked the Desktop App Converter!')

      process.exit(0)
    }

    let preAppx = path.join(program.outputDirectory, 'pre-appx')
    let installer = path.join(program.outputDirectory, 'ElectronInstaller.exe')
    let logfile = path.join(program.outputDirectory, 'logs', 'conversion.log')
    let converterArgs = [
      `-LogFile ${logfile}`,
      `-Installer '${installer}'`,
      `-Converter '${path.join(program.desktopConverter, 'DesktopAppConverter.ps1')}'`,
      `-ExpandedBaseImage ${program.expandedBaseImage}`,
      `-Destination '${preAppx}'`,
      `-PackageName "${program.packageName}"`,
      `-Version ${program.packageVersion}`,
      `-Publisher "${program.publisher}"`,
      `-AppExecutable '${program.packageExecutable}'`
    ]
    let args = `& {& '${path.resolve(__dirname, '..', 'ps1', 'convert.ps1')}' ${converterArgs.join(' ')}}`
    let child, tail

    utils.log(chalk.green.bold('Starting Conversion...'))
    utils.debug(`Conversion parameters used: ${JSON.stringify(converterArgs)}`)

    try {
      child = spawn('powershell.exe', ['-NoProfile', '-NoLogo', args])
    } catch (error) {
      reject(error)
    }

    child.stdout.on('data', (data) => utils.debug(data.toString()))
    child.stderr.on('data', (data) => utils.debug(data.toString()))
    child.on('exit', () => {
      // The conversion process exited, let's look for a log file
      // However, give the PS process a 3s headstart, since we'll
      // crash if the logfile does not exist yet
      setTimeout(() => {
        tail = new Tail(logfile, {
          fromBeginning: true
        })

        tail.on('line', (data) => {
          utils.log(data)

          if (data.indexOf('Conversion complete') > -1) {
            utils.log('')
            tail.unwatch()
            resolve()
          } else if (data.indexOf('An error occurred') > -1) {
            tail.unwatch()
            reject(new Error('Detected error in conversion log'))
          }
        })

        tail.on('error', (err) => utils.log(err))
      }, 3000)
    })

    child.stdin.end()
  })
}
function convertWithContainer (program) {
  return new Promise((resolve, reject) => {
    if (!program.desktopConverter) {
      utils.log('Could not find the Project Centennial Desktop App Converter, which is required to')
      utils.log('run the conversion to appx using a Windows Container.\n')
      utils.log('Consult the documentation at https://aka.ms/electron-windows-store for a tutorial.\n')
      utils.log('You can find the Desktop App Converter at https://www.microsoft.com/en-us/download/details.aspx?id=51691\n')
      utils.log('Exiting now - restart when you downloaded and unpacked the Desktop App Converter!')

      process.exit(0)
    }

    let preAppx = path.join(program.outputDirectory, 'pre-appx')
    let installer = path.join(program.outputDirectory, 'ElectronInstaller.exe')
    let logfile = path.join(program.outputDirectory, 'logs', 'conversion.log')
    let converterArgs = [
      `-LogFile ${logfile}`,
      `-Installer '${installer}'`,
      `-Converter '${path.join(program.desktopConverter, 'DesktopAppConverter.ps1')}'`,
      `-ExpandedBaseImage ${program.expandedBaseImage}`,
      `-Destination '${preAppx}'`,
      `-PackageName "${program.packageName}"`,
      `-Version ${program.packageVersion}`,
      `-Publisher "${program.publisher}"`,
      `-AppExecutable '${program.packageExecutable}'`
    ]
    let args = `& {& '${path.resolve(__dirname, '..', 'ps1', 'convert.ps1')}' ${converterArgs.join(' ')}}`
    let child, tail

    utils.log(chalk.green.bold('Starting Conversion...'))
    utils.debug(`Conversion parameters used: ${JSON.stringify(converterArgs)}`)

    try {
      child = spawn('powershell.exe', ['-NoProfile', '-NoLogo', args])
    } catch (error) {
      reject(error)
    }

    child.stdout.on('data', (data) => utils.debug(data.toString()))
    child.stderr.on('data', (data) => utils.debug(data.toString()))
    child.on('exit', () => {
      // The conversion process exited, let's look for a log file
      // However, give the PS process a 3s headstart, since we'll
      // crash if the logfile does not exist yet
      setTimeout(() => {
        tail = new Tail(logfile, {
          fromBeginning: true
        })

        tail.on('line', (data) => {
          utils.log(data)

          if (data.indexOf('Conversion complete') > -1) {
            utils.log('')
            tail.unwatch()
            resolve()
          } else if (data.indexOf('An error occurred') > -1) {
            tail.unwatch()
            reject(new Error('Detected error in conversion log'))
          }
        })

        tail.on('error', (err) => utils.log(err))
      }, 3000)
    })

    child.stdin.end()
  })
}
function convertWithContainer ( program ) { return new Promise ( ( resolve , reject ) => { if ( ! program . desktopConverter ) { utils . log ( 'Could not find the Project Centennial Desktop App Converter, which is required to' ) utils . log ( 'run the conversion to appx using a Windows Container.\n' ) utils . log ( 'Consult the documentation at https://aka.ms/electron-windows-store for a tutorial.\n' ) utils . log ( 'You can find the Desktop App Converter at https://www.microsoft.com/en-us/download/details.aspx?id=51691\n' ) utils . log ( 'Exiting now - restart when you downloaded and unpacked the Desktop App Converter!' ) process . exit ( 0 ) } let preAppx = path . join ( program . outputDirectory , 'pre-appx' ) let installer = path . join ( program . outputDirectory , 'ElectronInstaller.exe' ) let logfile = path . join ( program . outputDirectory , 'logs' , 'conversion.log' ) let converterArgs = [ ` ${ logfile } ` , ` ${ installer } ` , ` ${ path . join ( program . desktopConverter , 'DesktopAppConverter.ps1' ) } ` , ` ${ program . expandedBaseImage } ` , ` ${ preAppx } ` , ` ${ program . packageName } ` , ` ${ program . packageVersion } ` , ` ${ program . publisher } ` , ` ${ program . packageExecutable } ` ] let args = ` ${ path . resolve ( __dirname , '..' , 'ps1' , 'convert.ps1' ) } ${ converterArgs . join ( ' ' ) } ` let child , tail utils . log ( chalk . green . bold ( 'Starting Conversion...' ) ) utils . debug ( ` ${ JSON . stringify ( converterArgs ) } ` ) try { child = spawn ( 'powershell.exe' , [ '-NoProfile' , '-NoLogo' , args ] ) } catch ( error ) { reject ( error ) } child . stdout . on ( 'data' , ( data ) => utils . debug ( data . toString ( ) ) ) child . stderr . on ( 'data' , ( data ) => utils . debug ( data . toString ( ) ) ) child . on ( 'exit' , ( ) => { // The conversion process exited, let's look for a log file // However, give the PS process a 3s headstart, since we'll // crash if the logfile does not exist yet setTimeout ( ( ) => { tail = new Tail ( logfile , { fromBeginning : true } ) tail . on ( 'line' , ( data ) => { utils . log ( data ) if ( data . indexOf ( 'Conversion complete' ) > - 1 ) { utils . log ( '' ) tail . unwatch ( ) resolve ( ) } else if ( data . indexOf ( 'An error occurred' ) > - 1 ) { tail . unwatch ( ) reject ( new Error ( 'Detected error in conversion log' ) ) } } ) tail . on ( 'error' , ( err ) => utils . log ( err ) ) } , 3000 ) } ) child . stdin . end ( ) } ) }
Converts the given Electron app using Project Centennial
Container Virtualization.

@param program - Program object containing the user's instructions
@returns - Promise
Converts the given Electron app using Project Centennial Container Virtualization .