Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: inResource file identification #178

Merged
merged 3 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions __tests__/unit/lib/service/inResourceHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ const testContext = {
'force-app/main/default/aura/component/component.cmp-meta.xml',
new Set(['component']),
],
[
'experiences',
'force-app/main/default/experiences/component/subfolder/file.json',
new Set(['component']),
],
[
'experiences',
'force-app/main/default/experiences/component-meta.xml',
new Set(['component']),
],
],
work: {
config: { output: '', repo: '', generateDelta: true },
Expand Down
32 changes: 17 additions & 15 deletions src/service/inResourceHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,11 @@ const elementSrc = {}
class ResourceHandler extends StandardHandler {
constructor(line, type, work, metadata) {
super(line, type, work, metadata)
this.elementRegex = new RegExp(
`(?<path>.*[/\\\\]${
StandardHandler.metadata[this.type].directoryName
})[/\\\\](?<name>[^/\\\\]*)+`,
'u'
)
}
handleAddition() {
super.handleAddition()
if (!this.config.generateDelta) return
const [, srcPath, elementName] = path
.join(this.config.repo, this.line)
.match(this.elementRegex)
const [, srcPath, elementName] = this._parseLine()
const [targetPath] = `${path.join(this.config.output, this.line)}`.match(
new RegExp(
`.*[/\\\\]${StandardHandler.metadata[this.type].directoryName}`,
Expand All @@ -30,12 +22,12 @@ class ResourceHandler extends StandardHandler {
)

const parsedElementName = path.parse(elementName)

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

elementSrc[srcPath]
.filter(src => src.indexOf(parsedElementName.name) !== -1)
.filter(src => path.parse(src).name === parsedElementName.name)
.forEach(src =>
this._copyFiles(
path.normalize(path.join(srcPath, src)),
Expand All @@ -45,17 +37,27 @@ class ResourceHandler extends StandardHandler {
}

handleDeletion() {
const [, srcPath, elementName] = path
.join(this.config.repo, this.line)
.match(this.elementRegex)

const [, srcPath, elementName] = this._parseLine()
if (fs.existsSync(path.join(srcPath, elementName))) {
this.handleModification(this)
} else {
super.handleDeletion()
}
}

_parseLine() {
return path
.join(this.config.repo, this.line)
.match(
new RegExp(
`(?<path>.*[/\\\\]${
StandardHandler.metadata[this.type].directoryName
})[/\\\\](?<name>[^/\\\\]*)+`,
'u'
)
)
}

_getElementName() {
const parsedPath = this._getParsedPath()
return StandardHandler.cleanUpPackageMember(parsedPath.name)
Expand Down