Skip to content

Commit

Permalink
Merge branch 'main' into feat/55
Browse files Browse the repository at this point in the history
  • Loading branch information
dieffrei authored Aug 2, 2024
2 parents 508c503 + 93a01cf commit 8520506
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
54 changes: 36 additions & 18 deletions src/core/metadata/CustomFieldFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { XMLParser } from 'fast-xml-parser';
import MetadataFetcher from './MetadataFetcher';
import {
ComponentSet,
ComponentSetBuilder,
MetadataConverter,
MetadataResolver,
ZipTreeContainer,
RegistryAccess,
} from '@salesforce/source-deploy-retrieve';
import path from 'path';
import { makeRandomId } from '../utils/RandomId';
import { SfProject } from '@salesforce/core';

export default class CustomFieldFetcher extends MetadataFetcher {
constructor(logger: Logger) {
Expand All @@ -22,24 +22,42 @@ export default class CustomFieldFetcher extends MetadataFetcher {
let retriveLocation = await this.fetchPackageFromOrg(org, {
types: { name: 'CustomField', members: fields.length > 1 ? fields : fields[0] },
});
const sfProjectJson = {
packageDirectories: [
{
path: 'source',
default: true,
},
],
name: 'retrieve',
namespace: '',
sourceApiVersion: await org.retrieveMaxApiVersion()
};
fs.mkdirpSync(path.join(retriveLocation.unzippedLocation, 'source'));
fs.writeFileSync(
path.join(retriveLocation.unzippedLocation, 'sfdx-project.json'),
JSON.stringify(sfProjectJson)
);
//Write a force ignore file as its required for component set resolution
fs.writeFileSync(path.resolve(retriveLocation.unzippedLocation, '.forceignore'), '# .forceignore v2');

const zipTree = await ZipTreeContainer.create(fs.readFileSync(retriveLocation.zipLocation));
const zipResolver = new MetadataResolver(undefined, zipTree);
const zipComponents = zipResolver.getComponentsFromPath('.');
let packageName = makeRandomId(6);
await new MetadataConverter().convert(zipComponents, 'source', {
let sfProject = await SfProject.resolve(retriveLocation.unzippedLocation);
let metadataConverter = new MetadataConverter(new RegistryAccess(undefined, sfProject.getPath()));
let componentSet = await ComponentSetBuilder.build({
sourcepath: [path.resolve(retriveLocation.unzippedLocation)],
manifest: undefined,
metadata: undefined,
projectDir: sfProject.getPath(),
});
await metadataConverter.convert(componentSet, 'source', {
type: 'directory',
outputDirectory: path.join(retriveLocation.unzippedLocation, 'source'),
packageName: packageName
outputDirectory: path.join(retriveLocation.unzippedLocation,sfProject.getDefaultPackage().path),
genUniqueDir: false,
});

//Write a force ignore file as its required for component set resolution
fs.writeFileSync(path.resolve(retriveLocation.unzippedLocation, 'source', '.forceignore'), '# .forceignore v2');

let sourceBackedComponents = ComponentSet.fromSource(path.resolve(retriveLocation.unzippedLocation, 'source'));

return {components:sourceBackedComponents,location:path.join(retriveLocation.unzippedLocation, 'source',packageName)}
return {
components: sourceBackedComponents,
location: path.join(retriveLocation.unzippedLocation, 'source'),
};
}


}
2 changes: 1 addition & 1 deletion src/core/package/SfpPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PackageInfo {

export default class SfpPackage extends PackageInfo {
public projectDirectory: string;
public workingDirectory: string;
public workingDirectory: string = '';
public mdapiDir: string;
public destructiveChangesPath: string;
public resolvedPackageDirectory: string;
Expand Down
3 changes: 2 additions & 1 deletion src/core/package/deploymentCustomizers/FHTEnabler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export default class FHTEnabler extends MetdataDeploymentCustomizer {

//Modify the component set
//Parsing is risky due to various encoding, so do an inplace replacement
for (const sourceComponent of fetchedCustomFields.components.getSourceComponents()) {
let sourceComponents = fetchedCustomFields.components.getSourceComponents().toArray();
for (const sourceComponent of sourceComponents) {
let metadataOfComponent = fs.readFileSync(sourceComponent.xml).toString();

metadataOfComponent = metadataOfComponent.replace(
Expand Down

0 comments on commit 8520506

Please sign in to comment.