-
Notifications
You must be signed in to change notification settings - Fork 104
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
sm/territory2 #433
Closed
Closed
sm/territory2 #433
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e5feb17
style: typo in comments
mshanemc d6e2c73
fix: support for nested types
mshanemc 11d4ae3
refactor: store parentType when sourceComponent is created
mshanemc 8c768ea
style: explain type naming exceptions
mshanemc 1993bc5
test: ut for nested types
mshanemc edb0d70
test: unit tests with virtualComponent
mshanemc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import { join, basename } from 'path'; | ||
import { join, basename, sep } from 'path'; | ||
import { parse } from 'fast-xml-parser'; | ||
import { ForceIgnore } from './forceIgnore'; | ||
import { NodeFSTreeContainer, TreeContainer, VirtualTreeContainer } from './treeContainers'; | ||
|
@@ -22,6 +22,7 @@ export type ComponentProperties = { | |
xml?: string; | ||
content?: string; | ||
parent?: SourceComponent; | ||
parentType?: MetadataType; | ||
}; | ||
|
||
/** | ||
|
@@ -32,6 +33,7 @@ export class SourceComponent implements MetadataComponent { | |
public readonly type: MetadataType; | ||
public readonly xml?: string; | ||
public readonly parent?: SourceComponent; | ||
public parentType?: MetadataType; | ||
public content?: string; | ||
private _tree: TreeContainer; | ||
private forceIgnore: ForceIgnore; | ||
|
@@ -47,6 +49,7 @@ export class SourceComponent implements MetadataComponent { | |
this.xml = props.xml; | ||
this.parent = props.parent; | ||
this.content = props.content; | ||
this.parentType = props.parentType; | ||
this._tree = tree; | ||
this.forceIgnore = forceIgnore; | ||
} | ||
|
@@ -98,24 +101,9 @@ export class SourceComponent implements MetadataComponent { | |
} | ||
|
||
public getPackageRelativePath(fsPath: string, format: SfdxFileFormat): string { | ||
const { directoryName, suffix, inFolder, folderType } = this.type; | ||
// if there isn't a suffix, assume this is a mixed content component that must | ||
// reside in the directoryName of its type. trimUntil maintains the folder structure | ||
// the file resides in for the new destination. | ||
let relativePath: string; | ||
if (!suffix) { | ||
relativePath = trimUntil(fsPath, directoryName); | ||
} else if (folderType || inFolder) { | ||
const folderName = this.fullName.split('/')[0]; | ||
relativePath = join(directoryName, folderName, basename(fsPath)); | ||
} else { | ||
relativePath = join(directoryName, basename(fsPath)); | ||
} | ||
|
||
if (format === 'source') { | ||
return join(DEFAULT_PACKAGE_ROOT_SFDX, relativePath); | ||
} | ||
return relativePath; | ||
return format === 'source' | ||
? join(DEFAULT_PACKAGE_ROOT_SFDX, this.calculateRelativePath(fsPath)) | ||
: this.calculateRelativePath(fsPath); | ||
} | ||
|
||
/** | ||
|
@@ -129,6 +117,29 @@ export class SourceComponent implements MetadataComponent { | |
this.markedForDelete = asDeletion; | ||
} | ||
|
||
private calculateRelativePath(fsPath: string): string { | ||
const { directoryName, suffix, inFolder, folderType } = this.type; | ||
// if there isn't a suffix, assume this is a mixed content component that must | ||
// reside in the directoryName of its type. trimUntil maintains the folder structure | ||
// the file resides in for the new destination. | ||
if (!suffix) { | ||
return trimUntil(fsPath, directoryName); | ||
} | ||
// legacy version of folderType | ||
if (inFolder) { | ||
return join(directoryName, this.fullName.split('/')[0], basename(fsPath)); | ||
} | ||
if (folderType) { | ||
// types like Territory2Model have child types inside them. We have to preserve those folder structures | ||
if (this.parentType?.folderType && this.parentType?.folderType !== this.type.id) { | ||
const fsPathSplits = fsPath.split(sep); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll echo the same comment from above about using |
||
return fsPathSplits.slice(fsPathSplits.indexOf(this.parentType.directoryName)).join(sep); | ||
} | ||
return join(directoryName, this.fullName.split('/')[0], basename(fsPath)); | ||
} | ||
return join(directoryName, basename(fsPath)); | ||
} | ||
|
||
private parse<T = JsonMap>(contents: string): T { | ||
// include tag attributes and don't parse text node as number | ||
const parsed = parse(contents.toString(), { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import { mockRegistryData } from '../mockRegistry'; | ||
import { join } from 'path'; | ||
import { SourceComponent } from '../../../../src'; | ||
|
||
const parentType = mockRegistryData.types.nestedparent; | ||
const childType = mockRegistryData.types.nestedchild; | ||
|
||
export const PARENT_COMPONENT_NAME = 'parentName'; | ||
export const PARENT_TYPE_DIRECTORY = join('path', 'to', parentType.directoryName); | ||
export const PARENT_CONTENT_PATH = join(PARENT_TYPE_DIRECTORY, PARENT_COMPONENT_NAME); | ||
export const PARENT_XML_NAME = `${PARENT_COMPONENT_NAME}.${parentType.suffix}-meta.xml`; | ||
export const PARENT_XML_PATH = join(PARENT_CONTENT_PATH, PARENT_XML_NAME); | ||
|
||
export const CHILD_COMPONENT_NAME = 'childName'; | ||
// /Territory2Models/someModel/rules | ||
export const CHILD_TYPE_DIRECTORY = join(PARENT_CONTENT_PATH, childType.directoryName); | ||
export const CHILD_XML_NAME = `${CHILD_COMPONENT_NAME}.${childType.suffix}-meta.xml`; | ||
export const CHILD_XML_PATH = join(CHILD_TYPE_DIRECTORY, CHILD_XML_NAME); | ||
|
||
export const NESTED_PARENT_COMPONENT = SourceComponent.createVirtualComponent( | ||
{ | ||
name: PARENT_COMPONENT_NAME, | ||
type: parentType, | ||
xml: PARENT_XML_PATH, | ||
parentType, | ||
}, | ||
[] | ||
); | ||
|
||
export const NESTED_CHILD_COMPONENT = SourceComponent.createVirtualComponent( | ||
{ | ||
name: `${PARENT_COMPONENT_NAME}.${CHILD_COMPONENT_NAME}`, | ||
type: childType, | ||
xml: CHILD_XML_PATH, | ||
parentType, | ||
}, | ||
[] | ||
); | ||
|
||
// export const NESTED_CHILD_COMPONENT = SourceComponent.createVirtualComponent( | ||
// { | ||
// name: 'testRule', | ||
// type: childType, | ||
// xml: XML_PATH, | ||
// content: CONTENT_PATH, | ||
// }, | ||
// [ | ||
// { | ||
// dirPath: TYPE_DIRECTORY, | ||
// children: [COMPONENT_NAME], | ||
// }, | ||
// { | ||
// dirPath: CONTENT_PATH, | ||
// children: [], | ||
// }, | ||
// ] | ||
// ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using path sep can be tricky because if the path is from a server response it will necessarily be a forward slash, even on Windows OS. If this is used for a retrieve on Windows I'd expect it to not work as expected. In order for it to work we first have to normalize the path, then split.