index.js
function ui5Download(sDownloadURL, sDownloadPath, sUI5Version, oOptions = {}) {
  // check params
  if (!sDownloadURL) {
    return Promise.reject('No download URL provided')
  }
  if (!sDownloadPath) {
    return Promise.reject('No download path provided')
  }
  if (!sUI5Version) {
    return Promise.reject('No UI5 version provided')
  }

  const oSteps = {
    download: {
      number: 1,
      details: { name: 'download' }
    },
    unzip: {
      number: 2,
      details: { name: 'unzip' }
    }
  }
  const iTotalSteps = Object.keys(oSteps).length
  const sTargetPath = `${sDownloadPath}/${sUI5Version}`
  const sSuccessMessage = `UI5 download (${sUI5Version}) already exist at ${sDownloadPath}/${sUI5Version}`
  const fnProgressCallback =
    typeof oOptions.onProgress === 'function' ? oOptions.onProgress : () => {}

  // check if ui5 library was already downloaded and ectracted
  return fs.existsSync(sTargetPath)
    ? // download is already available
      Promise.resolve(sSuccessMessage)
    : // download and unzip sources
      new Promise((resolve, reject) => {
        progress(
          request.get(
            sDownloadURL,
            { encoding: null },
            (oError, oResponse, oData) => {
              if (oError) {
                // reject promise
                return reject(oError)
              }

              // update progress information (start step 2)
              const oStep = oSteps['unzip']
              fnProgressCallback(oStep.number, iTotalSteps, oStep.details)

              // Do something after request finishes
              const oBuffer = new Buffer(oData, 'binary')
              const zip = new Zip(oBuffer)
              const overwrite = true

              // extracts everything
              zip.extractAllTo(sTargetPath, overwrite)

              // if sap-ui-core.js is not located in extracted root,
              // we will rename the download directory to 'resources'
              if (!fs.existsSync(`${sTargetPath}/sap-ui-core.js`)) {
                // read all extracted files in current directory
                const aFiles = fs.readdirSync(sTargetPath)
                aFiles.forEach(sFileName => {
                  if (
                    fs.statSync(`${sTargetPath}/${sFileName}`).isDirectory()
                  ) {
                    // rename download folder in root
                    try {
                      fs.renameSync(
                        `${sTargetPath}/${sFileName}`,
                        `${sTargetPath}/resources`
                      )
                    } catch (e) {
                      // skip renaming
                    }
                  }
                })
              }

              // resolve promise
              return resolve(`UI5 download successful: ${sTargetPath}`)
            }
          )
        ).on('progress', oProgressDetails => {
          // update progress information
          const oStep = oSteps['download']
          fnProgressCallback(
            oStep.number,
            iTotalSteps,
            Object.assign({}, oStep.details, {
              progress: oProgressDetails.percent * 100
            })
          )
        })
      })
}
function ui5Download(sDownloadURL, sDownloadPath, sUI5Version, oOptions = {}) {
  // check params
  if (!sDownloadURL) {
    return Promise.reject('No download URL provided')
  }
  if (!sDownloadPath) {
    return Promise.reject('No download path provided')
  }
  if (!sUI5Version) {
    return Promise.reject('No UI5 version provided')
  }

  const oSteps = {
    download: {
      number: 1,
      details: { name: 'download' }
    },
    unzip: {
      number: 2,
      details: { name: 'unzip' }
    }
  }
  const iTotalSteps = Object.keys(oSteps).length
  const sTargetPath = `${sDownloadPath}/${sUI5Version}`
  const sSuccessMessage = `UI5 download (${sUI5Version}) already exist at ${sDownloadPath}/${sUI5Version}`
  const fnProgressCallback =
    typeof oOptions.onProgress === 'function' ? oOptions.onProgress : () => {}

  // check if ui5 library was already downloaded and ectracted
  return fs.existsSync(sTargetPath)
    ? // download is already available
      Promise.resolve(sSuccessMessage)
    : // download and unzip sources
      new Promise((resolve, reject) => {
        progress(
          request.get(
            sDownloadURL,
            { encoding: null },
            (oError, oResponse, oData) => {
              if (oError) {
                // reject promise
                return reject(oError)
              }

              // update progress information (start step 2)
              const oStep = oSteps['unzip']
              fnProgressCallback(oStep.number, iTotalSteps, oStep.details)

              // Do something after request finishes
              const oBuffer = new Buffer(oData, 'binary')
              const zip = new Zip(oBuffer)
              const overwrite = true

              // extracts everything
              zip.extractAllTo(sTargetPath, overwrite)

              // if sap-ui-core.js is not located in extracted root,
              // we will rename the download directory to 'resources'
              if (!fs.existsSync(`${sTargetPath}/sap-ui-core.js`)) {
                // read all extracted files in current directory
                const aFiles = fs.readdirSync(sTargetPath)
                aFiles.forEach(sFileName => {
                  if (
                    fs.statSync(`${sTargetPath}/${sFileName}`).isDirectory()
                  ) {
                    // rename download folder in root
                    try {
                      fs.renameSync(
                        `${sTargetPath}/${sFileName}`,
                        `${sTargetPath}/resources`
                      )
                    } catch (e) {
                      // skip renaming
                    }
                  }
                })
              }

              // resolve promise
              return resolve(`UI5 download successful: ${sTargetPath}`)
            }
          )
        ).on('progress', oProgressDetails => {
          // update progress information
          const oStep = oSteps['download']
          fnProgressCallback(
            oStep.number,
            iTotalSteps,
            Object.assign({}, oStep.details, {
              progress: oProgressDetails.percent * 100
            })
          )
        })
      })
}
function ui5Download ( sDownloadURL , sDownloadPath , sUI5Version , oOptions = { } ) { // check params if ( ! sDownloadURL ) { return Promise . reject ( 'No download URL provided' ) } if ( ! sDownloadPath ) { return Promise . reject ( 'No download path provided' ) } if ( ! sUI5Version ) { return Promise . reject ( 'No UI5 version provided' ) } const oSteps = { download : { number : 1 , details : { name : 'download' } } , unzip : { number : 2 , details : { name : 'unzip' } } } const iTotalSteps = Object . keys ( oSteps ) . length const sTargetPath = ` ${ sDownloadPath } ${ sUI5Version } ` const sSuccessMessage = ` ${ sUI5Version } ${ sDownloadPath } ${ sUI5Version } ` const fnProgressCallback = typeof oOptions . onProgress === 'function' ? oOptions . onProgress : ( ) => { } // check if ui5 library was already downloaded and ectracted return fs . existsSync ( sTargetPath ) ? // download is already available Promise . resolve ( sSuccessMessage ) : // download and unzip sources new Promise ( ( resolve , reject ) => { progress ( request . get ( sDownloadURL , { encoding : null } , ( oError , oResponse , oData ) => { if ( oError ) { // reject promise return reject ( oError ) } // update progress information (start step 2) const oStep = oSteps [ 'unzip' ] fnProgressCallback ( oStep . number , iTotalSteps , oStep . details ) // Do something after request finishes const oBuffer = new Buffer ( oData , 'binary' ) const zip = new Zip ( oBuffer ) const overwrite = true // extracts everything zip . extractAllTo ( sTargetPath , overwrite ) // if sap-ui-core.js is not located in extracted root, // we will rename the download directory to 'resources' if ( ! fs . existsSync ( ` ${ sTargetPath } ` ) ) { // read all extracted files in current directory const aFiles = fs . readdirSync ( sTargetPath ) aFiles . forEach ( sFileName => { if ( fs . statSync ( ` ${ sTargetPath } ${ sFileName } ` ) . isDirectory ( ) ) { // rename download folder in root try { fs . renameSync ( ` ${ sTargetPath } ${ sFileName } ` , ` ${ sTargetPath } ` ) } catch ( e ) { // skip renaming } } } ) } // resolve promise return resolve ( ` ${ sTargetPath } ` ) } ) ) . on ( 'progress' , oProgressDetails => { // update progress information const oStep = oSteps [ 'download' ] fnProgressCallback ( oStep . number , iTotalSteps , Object . assign ( { } , oStep . details , { progress : oProgressDetails . percent * 100 } ) ) } ) } ) }
Download OpenUI5 repository from external URL and unzip.

@param {string} [sDownloadURL] Download URL of required archive.
@param {string} [sDownloadPath] Destination path for the download archive and extracted files.
@param {string} [sUI5Version] Version number of UI5 to create at <code>sDownloadPath</code> a subdirectory named <code>/{{sUI5Version}}</code>.
@param {Object} [oOptions] Download options.
@param {function(number,number,{ name: string, progress: number|null}):void} [oOptions.onProgress] Callback function to track download progress taking as params: current step number, total step number and if available, step details (object with name and progress in percent).
@returns {Promise.string} Promise which resolves to a success or error message.
Download OpenUI5 repository from external URL and unzip .