Skip to content

Commit

Permalink
Merge pull request #1496 from Esri/webtool-id-check
Browse files Browse the repository at this point in the history
fix id checking
  • Loading branch information
jmhauck authored Sep 9, 2024
2 parents 38a5614 + c66a98f commit 2cde893
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions packages/creator/src/createItemTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,30 +550,33 @@ export function _templatizeResources(
let dataString = JSON.stringify(fileJson);
if (fileJson && idTest.test(dataString)) {
const ids: string[] = dataString.match(idTest) as string[];
const verifiedIds: string[] = [];
const promises = [];
const idLookup = [];
ids.forEach((id) => {
idLookup.push(id);
if (verifiedIds.indexOf(id) === -1) {
verifiedIds.push(id);
if (idLookup.indexOf(id) === -1) {
idLookup.push(id);
promises.push(isItem(id, srcAuthentication));
idLookup.push(id);
promises.push(isGroup(id, srcAuthentication));
}
});

// eslint-disable-next-line @typescript-eslint/no-floating-promises
Promise.all(promises).then((results) => {
const verifiedIds = [];
results.forEach((isValid, i) => {
if (isValid) {
const id: string = idLookup[i];
// templatize the itemId--but only once per unique id
const regEx = new RegExp(id, "gm");
dataString = dataString.replace(regEx, "{{" + id + ".itemId}}");

// update the dependencies
if (itemTemplate.dependencies.indexOf(id) === -1) {
itemTemplate.dependencies.push(id);
if (id && verifiedIds.indexOf(id) < 0) {
// templatize the itemId--but only once per unique id
const regEx = new RegExp(id, "gm");
dataString = dataString.replace(regEx, "{{" + id + ".itemId}}");

// update the dependencies
if (itemTemplate.dependencies.indexOf(id) === -1) {
itemTemplate.dependencies.push(id);
}
verifiedIds.push(id);
}
}
});
Expand Down

0 comments on commit 2cde893

Please sign in to comment.