Skip to content

Commit

Permalink
Add logic, to rename extracted ui5 directrory to 'resources', if down…
Browse files Browse the repository at this point in the history
…loaded content is wrapped in a directory.
  • Loading branch information
fuchsvomwalde committed Oct 3, 2017
1 parent 49139a0 commit f3f4fa0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,28 @@ function ui5Download(sDownloadURL, sDownloadPath, sUI5Version, oOptions = {}) {
// 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}`)
}
Expand Down

0 comments on commit f3f4fa0

Please sign in to comment.