Skip to content

Commit

Permalink
#1461: add new option --purge and --no-purge to createDeltaPkg, build…
Browse files Browse the repository at this point in the history
…, buildDefinition, buildDefinitionBulk
  • Loading branch information
JoernBerkefeld committed Jan 28, 2025
1 parent 6af98d8 commit 101ac13
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
3 changes: 1 addition & 2 deletions @types/lib/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion @types/lib/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ yargs(hideBin(process.argv))
group: 'Options for build:',
describe:
'allows reducing validation rules from error to warn to handle edge cases',
})
.option('purge', {
group: 'Options for build:',
describe: 'deletes the relevant deploy folder before building the definition',
}),
(argv) => {
Mcdev.setOptions(argv);
Expand Down Expand Up @@ -578,6 +582,10 @@ yargs(hideBin(process.argv))
describe:
'allows reducing validation rules from error to warn to handle edge cases',
})
.option('purge', {
group: 'Options for buildDefinition:',
describe: 'deletes the relevant deploy folder before building the definition',
})
.check((argv) => {
if (!argv.MARKET && !argv.market) {
throw new Error(
Expand Down Expand Up @@ -635,6 +643,10 @@ yargs(hideBin(process.argv))
group: 'Options for buildDefinitionBulk:',
describe:
'allows reducing validation rules from error to warn to handle edge cases',
})
.option('purge', {
group: 'Options for buildDefinitionBulk:',
describe: 'deletes the relevant deploy folder before building the definition',
}),
(argv) => {
Mcdev.setOptions(argv);
Expand Down Expand Up @@ -688,6 +700,10 @@ yargs(hideBin(process.argv))
type: 'number',
group: 'Options for createDeltaPkg:',
describe: 'Number of commits to look back for changes (supersedes config)',
})
.option('purge', {
group: 'Options for createDeltaPkg:',
describe: 'deletes the relevant deploy folder before building the definition',
}),
(argv) => {
Mcdev.setOptions(argv);
Expand Down
41 changes: 20 additions & 21 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class Mcdev {
'noUpdate',
'autoMidSuffix',
'publish',
'purge',
'referenceFrom',
'referenceTo',
'refresh',
Expand Down Expand Up @@ -1110,26 +1111,19 @@ class Mcdev {
Util.logger.info('mcdev:: Build Template & Build Definition');
await this.buildTemplate(businessUnitTemplate, typeKeyCombo, null, marketTemplate);

let isPurgeDeployFolder;
if (!Util.skipInteraction && !bulk) {
if (typeof Util.OPTIONS.purge !== 'boolean') {
const properties = await config.getProperties();
// deploy folder is in targets for definition creation
// recommend to purge their content first
isPurgeDeployFolder = await confirm({
message: `Do you want to empty the folder /${properties.directories.deploy}${businessUnitDefinition} (ensures no files from previous deployments remain)?`,
Util.OPTIONS.purge = await confirm({
message: `Do you want to empty relevant BU sub-folders in /${properties.directories.deploy} (ensures no files from previous deployments remain)?`,
default: true,
});
}

return bulk
? this.buildDefinitionBulk(marketDefinition[0], typeKeyCombo, null)
: this.buildDefinition(
businessUnitDefinition,
typeKeyCombo,
null,
marketDefinition,
isPurgeDeployFolder
);
: this.buildDefinition(businessUnitDefinition, typeKeyCombo, null, marketDefinition);
}

/**
Expand Down Expand Up @@ -1267,16 +1261,9 @@ class Mcdev {
* @param {string | TypeKeyCombo} selectedTypes limit retrieval to given metadata type
* @param {string[] | undefined} nameArr name of the metadata
* @param {string[]} marketArr market localizations
* @param {boolean} [isPurgeDeployFolder] whether to purge the deploy folder
* @returns {Promise.<MultiMetadataTypeList>} -
*/
static async buildDefinition(
businessUnit,
selectedTypes,
nameArr,
marketArr,
isPurgeDeployFolder
) {
static async buildDefinition(businessUnit, selectedTypes, nameArr, marketArr) {
this.#welcomeMessage();

Util.startLogger();
Expand All @@ -1303,7 +1290,7 @@ class Mcdev {
buObject.credential,
buObject.businessUnit,
]);
if (isPurgeDeployFolder) {
if (Util.OPTIONS.purge) {
// Clear output folder structure for selected sub-type
// only run this if the standard deploy folder is a target of buildDefinition (which technically could be changed)
await File.remove(deployDir);
Expand Down Expand Up @@ -1352,7 +1339,19 @@ class Mcdev {
if (!typeKeyList) {
return;
}

if (Util.OPTIONS.purge) {
for (const businessUnit in properties.marketList[listName]) {
if (businessUnit === 'description') {
// skip, it's just a metadata on this list and not a BU
continue;
}
const deployDir =
properties.directories.deploy.replaceAll('\\', '/') + '/' + businessUnit;
// Clear output folder structure for selected sub-type
// only run this if the standard deploy folder is a target of buildDefinition (which technically could be changed)
await File.remove(deployDir);
}
}
/** @type {MultiMetadataTypeList} */
const returnObj = {};
for (const type of Object.keys(typeKeyList)) {
Expand Down

0 comments on commit 101ac13

Please sign in to comment.