-
Notifications
You must be signed in to change notification settings - Fork 125
feat: support decomposed components across multiple directories #224
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
c4bac32
refactor: consolidate componentset w/ workingset
889530d
refactor: consolidated sets
cddedbe
feat: initial multi merge
6e27f98
Merge branch 'develop' into bp/convertMergeMultiple
597545c
Merge branch 'develop' into bp/convertMergeMultiple
3cba5cc
test: update tests for new return result
8f9db33
Merge branch 'develop' into bp/convertMergeMultiple
dbfa020
fix: update mdapi
4ad33e7
test: fix tests
a116981
test: multi-merge test
2c1d33e
style: clean up
019ca6b
feat: merge segmented decomposed components
829357f
Merge branch 'develop' into bp/segmentedDecomposedComponents
70423c8
test: fix tests
7686e65
test: add tests for resolveChildrenWithParent
9f974b6
fix: needs clean up but merge works
7a96606
fix: dont duplicate to default
9233b8a
fix: functionally there, needs some clean up still
2ec0277
refactor: new state pattern - fix tests
1ba492f
fix: some fixes
9db7c6c
test: beginning to rework tests
37b999e
test: some tests
386ab82
test: one test
e028324
test: more tests, parent merge bug fix
517a6e2
feat: remove unnecessary resolve option
ae98fb5
refactor: remove unused code
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,131 @@ | ||
/* | ||
* 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 { WriteInfo, WriterFormat } from './types'; | ||
import { SourceComponent } from '../metadata-registry'; | ||
import { join } from 'path'; | ||
import { JsToXml } from './streams'; | ||
import { MetadataComponent } from '../common'; | ||
import { JsonArray, JsonMap } from '@salesforce/ts-types'; | ||
import { ComponentSet } from '../collections'; | ||
|
||
abstract class ConvertTransactionFinalizer<T> { | ||
protected abstract _state: T; | ||
|
||
public setState(props: (state: T) => void): void { | ||
props(this._state); | ||
} | ||
|
||
get state(): T { | ||
return this._state; | ||
} | ||
|
||
public abstract finalize(): Promise<WriterFormat[]>; | ||
} | ||
|
||
export interface RecompositionState { | ||
[componentKey: string]: { | ||
/** | ||
* Parent component that children are rolled up into | ||
*/ | ||
component?: SourceComponent; | ||
/** | ||
* Children to be rolled up into the parent file | ||
*/ | ||
children?: ComponentSet; | ||
}; | ||
} | ||
|
||
/** | ||
* Merges child components that share the same parent in the conversion pipeline | ||
* into a single file. | ||
*/ | ||
class RecompositionFinalizer extends ConvertTransactionFinalizer<RecompositionState> { | ||
protected _state: RecompositionState = {}; | ||
|
||
public async finalize(): Promise<WriterFormat[]> { | ||
const writerData: WriterFormat[] = []; | ||
|
||
for (const { component: parent, children } of Object.values(this.state)) { | ||
const baseObject: JsonMap = await parent.parseXml(); | ||
const recomposedXmlObj = await this.recompose(children, baseObject); | ||
writerData.push({ | ||
component: parent, | ||
writeInfos: [ | ||
{ | ||
source: new JsToXml(recomposedXmlObj), | ||
output: join(parent.type.directoryName, `${parent.fullName}.${parent.type.suffix}`), | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
return writerData; | ||
} | ||
|
||
private async recompose(children: ComponentSet, baseXmlObj: any): Promise<JsonMap> { | ||
for (const child of children) { | ||
const { directoryName: groupNode } = child.type; | ||
const { name: parentName } = child.parent.type; | ||
const xmlObj = await (child as SourceComponent).parseXml(); | ||
const childContents = xmlObj[child.type.name]; | ||
|
||
if (!baseXmlObj[parentName][groupNode]) { | ||
baseXmlObj[parentName][groupNode] = []; | ||
} | ||
(baseXmlObj[parentName][groupNode] as JsonArray).push(childContents); | ||
} | ||
return baseXmlObj; | ||
} | ||
} | ||
|
||
export interface DecompositionState { | ||
[componentKey: string]: { | ||
foundMerge?: boolean; | ||
writeInfo?: WriteInfo; | ||
origin?: MetadataComponent; | ||
}; | ||
} | ||
|
||
/** | ||
* Creates write infos for any children that haven't been written yet. Children may | ||
* delay being written in order to find potential existing children to merge | ||
* with in the conversion pipeline. | ||
*/ | ||
class DecompositionFinalizer extends ConvertTransactionFinalizer<DecompositionState> { | ||
protected _state: DecompositionState = {}; | ||
|
||
public async finalize(): Promise<WriterFormat[]> { | ||
const writerData: WriterFormat[] = []; | ||
|
||
for (const toDecompose of Object.values(this._state)) { | ||
if (!toDecompose.foundMerge) { | ||
writerData.push({ | ||
component: toDecompose.origin.parent ?? toDecompose.origin, | ||
writeInfos: [toDecompose.writeInfo], | ||
}); | ||
} | ||
} | ||
|
||
return writerData; | ||
} | ||
} | ||
|
||
/** | ||
* A state manager over the course of a single metadata conversion call. | ||
*/ | ||
export class ConvertContext { | ||
public readonly decomposition = new DecompositionFinalizer(); | ||
public readonly recomposition = new RecompositionFinalizer(); | ||
|
||
public async *executeFinalizers(): AsyncIterable<WriterFormat[]> { | ||
for (const member of Object.values(this)) { | ||
if (member instanceof ConvertTransactionFinalizer) { | ||
yield member.finalize(); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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.
This is a refactor of the ConvertTransaction concept, but performs the same job