Skip to content
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

feature/1619 allow using "name:" for buildTemplate and build #1623

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

50 changes: 50 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Retriever from './Retriever.js';
import cache from './util/cache.js';
import ReplaceContentBlockReference from './util/replaceContentBlockReference.js';
import pLimit from 'p-limit';
import path from 'node:path';

import { confirm } from '@inquirer/prompts';

Expand Down Expand Up @@ -1151,6 +1152,7 @@ class Mcdev {
Util.startLogger();
Util.logger.info('mcdev:: Build Template from retrieved files');
const properties = await config.getProperties();
const buObject = await Cli.getCredentialObject(properties, businessUnit);
if (!Util.checkMarket(market, properties)) {
return;
}
Expand All @@ -1172,6 +1174,54 @@ class Mcdev {
if (!Util.OPTIONS.dependencies) {
await this._reRetrieve(businessUnit, false, selectedTypes);
}
// convert names to keys
const retrieveDir = File.normalizePath([
properties.directories.retrieve,
buObject.credential,
buObject.businessUnit,
]);
for (const type of Object.keys(selectedTypes)) {
const keyArr = selectedTypes[type];
if (keyArr.some((key) => key.startsWith('name:'))) {
// at least one key was provided as a name -> load all files from disk to try and find that key
const builTemplateCache = Object.values(
await MetadataTypeInfo[type].getJsonFromFS(retrieveDir + path.sep + type)
);
selectedTypes[type] = keyArr
.map((key) => {
if (key.startsWith('name:')) {
// key was defined by name. try and find matching item on disk
const name = key.slice(5);
const foundKeysByName = builTemplateCache
.filter(
(item) =>
name == item[MetadataTypeInfo[type].definition.nameField]
)
.map((item) => item[MetadataTypeInfo[type].definition.keyField]);
if (foundKeysByName.length === 1) {
key = foundKeysByName[0];
Util.logger.debug(
`- found ${type} key '${key}' for name '${name}'`
);
return key;
} else if (foundKeysByName.length > 1) {
Util.logger.error(
`Found multiple keys (${foundKeysByName.join(', ')}) for given name ${key}`
);
return;
} else {
Util.logger.error(
`Could not find any keys for given name: ${name}`
);
return;
}
} else {
return key;
}
})
.filter(Boolean);
}
}

// if dependencies are enabled, we need to search for them and add them to our
await this.addDependencies(businessUnit, selectedTypes);
Expand Down
Loading