Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
feat(sfp-package): add support for unpackaged metadata in unlocked pa…
Browse files Browse the repository at this point in the history
…ckages

Add support for unpackaged metadata. This was removed as sfpowerscripts do parallel development and
working directory didnt copy the unpackaged directory. Support is added to copy unpackaged directory
and copy the folder to appropriate working directory. sfdx-project.json is then aligned for
sucessful preparation of the package. The unpackaged is a package directory and it will be upto the
user to determine the behaviour during validate,prepare or deploy. This along with changes in #842
which will skip the directories

fix #958
  • Loading branch information
azlam-abdulsalam committed Jun 16, 2022
1 parent e8776d7 commit c2569bf
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
53 changes: 50 additions & 3 deletions packages/core/src/package/generators/SfpPackageContentGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,70 @@ export default class SfpPackageContentGenerator {
SfpPackageContentGenerator.copyConfigFilePath(configFilePath, artifactDirectory, rootDirectory, logger);
}

SfpPackageContentGenerator.createPackageManifests(artifactDirectory, rootDirectory, projectConfig, sfdx_package);
SfpPackageContentGenerator.handleUnpackagedMetadata(
sfdx_package,
projectConfig,
rootDirectory,
artifactDirectory
);

SfpPackageContentGenerator.createPackageManifests(
artifactDirectory,
rootDirectory,
projectConfig,
sfdx_package
);

fs.copySync(path.join(rootDirectory, packageDirectory), path.join(artifactDirectory, packageDirectory));

return artifactDirectory;
}

private static createPackageManifests(artifactDirectory: string, projectDirectory: string, projectConfig: any, sfdx_package: string) {
private static handleUnpackagedMetadata(
sfdx_package: string,
projectConfig: any,
rootDirectory: string,
artifactDirectory: string
) {
const packageDescriptor = ProjectConfig.getPackageDescriptorFromConfig(sfdx_package, projectConfig);
if (packageDescriptor.unpackagedMetadata?.path) {
if (fs.pathExistsSync(packageDescriptor.unpackagedMetadata.path)) {
let unpackagedMetadataDir: string = path.join(artifactDirectory, `unpackagedMetadata`);
mkdirpSync(unpackagedMetadataDir);
console.log(
'rootDir',
rootDirectory,
path.join(rootDirectory, packageDescriptor.unpackagedMetadata.path),
process.cwd()
);
fs.copySync(path.join(rootDirectory, packageDescriptor.unpackagedMetadata.path), unpackagedMetadataDir);
} else {
throw new Error(`unpackagedMetadata ${packageDescriptor.unpackagedMetadata.path} does not exist`);
}
}
}

private static createPackageManifests(
artifactDirectory: string,
projectDirectory: string,
projectConfig: any,
sfdx_package: string
) {
// Create pruned package manifest in source directory
let cleanedUpProjectManifest = ProjectConfig.cleanupMPDFromProjectConfig(projectConfig, sfdx_package);

//Handle unpackaged metadata
if (fs.existsSync(path.join(artifactDirectory, 'unpackagedMetadata'))) {
cleanedUpProjectManifest.packageDirectories[0].unpackagedMetadata.path = path.join('unpackagedMetadata');
cleanedUpProjectManifest.packageDirectories.push({ path: path.join('unpackagedMetadata'), default: false });
}

//Setup preDeployment Script Path
if (fs.existsSync(path.join(artifactDirectory, 'scripts', `preDeployment`)))
cleanedUpProjectManifest.packageDirectories[0].preDeploymentScript = path.join('scripts', `preDeployment`);

//Setup postDeployment Script Path
if (fs.existsSync(path.join(artifactDirectory, 'scripts', `postDeployment`)))
if (fs.existsSync(path.join(artifactDirectory, 'scripts', `postDeployment`)))
cleanedUpProjectManifest.packageDirectories[0].postDeploymentScript = path.join(
'scripts',
`postDeployment`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": ["package", "versionNumber"],
"package": ["versionNumber"],
"postInstallUrl": ["package", "versionNumber"],
"unpackagedMetadata": ["package", "versionNumber"],
"releaseNotesUrl": ["package", "versionNumber"],
"versionDescription": ["package", "versionNumber"],
"versionName": ["package", "versionNumber"],
Expand Down Expand Up @@ -61,6 +62,9 @@
"postInstallUrl": {
"$ref": "#/definitions/packageDirectory.postInstallUrl"
},
"unpackagedMetadata": {
"$ref": "#/definitions/packageDirectory.unpackagedMetadata"
} ,
"releaseNotesUrl": {
"$ref": "#/definitions/packageDirectory.releaseNotesUrl"
},
Expand Down Expand Up @@ -256,6 +260,19 @@
"title": "Post Install Url",
"description": "The post install url."
},
"packageDirectory.unpackagedMetadata": {
"type": "object",
"title": "Unpackaged Metadata",
"description": "Metadata not meant to be packaged, but deployed when testing packaged metadata",
"required": ["path"],
"properties": {
"path": {
"type": "string",
"title": "Path",
"description": "The path name of the package directory containing the unpackaged metadata"
}
}
},
"packageDirectory.includeProfileUserLicenses": {
"type": "boolean",
"title": "Include Profile User Licenses",
Expand Down

0 comments on commit c2569bf

Please sign in to comment.