Skip to content

Commit

Permalink
fix: issue with inResource meta file not copied for corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon committed Aug 4, 2021
1 parent ee56c9f commit 2a13db4
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/metadata/a48.json
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@
"directoryName": "experiences",
"inFolder": false,
"metaFile": true,
"suffix": "",
"suffix": "site",
"xmlName": "ExperienceBundle"
},
{
Expand Down
1 change: 1 addition & 0 deletions src/metadata/v47.json
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@
"directoryName": "experiences",
"inFolder": false,
"metaFile": true,
"suffix": "site",
"xmlName": "ExperienceBundle"
},
{
Expand Down
1 change: 1 addition & 0 deletions src/metadata/v49.json
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@
"directoryName": "experiences",
"inFolder": false,
"metaFile": true,
"suffix": "site",
"xmlName": "ExperienceBundle"
},
{
Expand Down
1 change: 1 addition & 0 deletions src/metadata/v50.json
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@
"directoryName": "experiences",
"inFolder": false,
"metaFile": true,
"suffix": "site",
"xmlName": "ExperienceBundle"
},
{
Expand Down
1 change: 1 addition & 0 deletions src/metadata/v51.json
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@
"directoryName": "experiences",
"inFolder": false,
"metaFile": true,
"suffix": "site",
"xmlName": "ExperienceBundle"
},
{
Expand Down
1 change: 1 addition & 0 deletions src/metadata/v52.json
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@
"directoryName": "experiences",
"inFolder": false,
"metaFile": true,
"suffix": "site",
"xmlName": "ExperienceBundle"
},
{
Expand Down
34 changes: 28 additions & 6 deletions src/service/inResourceHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('path')
const fs = require('fs')
const mc = require('../utils/metadataConstants')

const STATICRESOURCE_TYPE = 'staticresources'
const elementSrc = {}

class ResourceHandler extends StandardHandler {
Expand All @@ -20,14 +21,16 @@ class ResourceHandler extends StandardHandler {
'u'
)
)
this._buildElementMap(srcPath)

const parsedElementName = path.parse(elementName)
if (!Object.prototype.hasOwnProperty.call(elementSrc, srcPath)) {
elementSrc[srcPath] = fs.readdirSync(srcPath)
}

const matchingFiles = this._buildMatchingFiles(elementName)
elementSrc[srcPath]
.filter(src => path.parse(src).name === parsedElementName.name)
.filter(
src =>
(this.type === STATICRESOURCE_TYPE &&
src.startsWith(path.parse(elementName).name)) ||
matchingFiles.includes(src)
)
.forEach(src =>
this._copyFiles(
path.normalize(path.join(srcPath, src)),
Expand Down Expand Up @@ -70,6 +73,25 @@ class ResourceHandler extends StandardHandler {
.replace(this.suffixRegex, '')
)
}

_buildMatchingFiles(elementName) {
const parsedElementName = path.parse(elementName).name
const matchingFiles = [parsedElementName]
if (StandardHandler.metadata[this.type].suffix) {
matchingFiles.push(
`${parsedElementName}.${StandardHandler.metadata[this.type].suffix}${
mc.METAFILE_SUFFIX
}`
)
}
return matchingFiles
}

_buildElementMap(srcPath) {
if (!Object.prototype.hasOwnProperty.call(elementSrc, srcPath)) {
elementSrc[srcPath] = fs.readdirSync(srcPath)
}
}
}

module.exports = ResourceHandler

0 comments on commit 2a13db4

Please sign in to comment.