Skip to content

Commit

Permalink
feat: added support for uuid properties
Browse files Browse the repository at this point in the history
  • Loading branch information
GarthDB committed May 31, 2023
1 parent 580213e commit 7820c7e
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 70 deletions.
9 changes: 6 additions & 3 deletions lib/json-sets-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ const getValue = (token, dictionary) => {
for (const setName in token.value.sets) {
sets[setName] = getValue(token.value.sets[setName], dictionary);
}
return { ref, sets };
const uuidObj = (Object.hasOwn(token, "uuid")) ? {uuid: token.uuid}: {};
return { ref, sets, ...uuidObj };
} else {
return { ref, value: token.value };
const uuidObj = (Object.hasOwn(token, "uuid")) ? {uuid: token.uuid}: {};
return { ref, value: token.value, ...uuidObj };
}
} else {
return { value: token.value }
const uuidObj = (Object.hasOwn(token, "uuid")) ? {uuid: token.uuid}: {};
return { value: token.value, ...uuidObj }
}
};

Expand Down
154 changes: 108 additions & 46 deletions tests/expected/uuid.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,115 @@
{
"component": {
"size": {
"sets": {
"mobile": {
"value": "15px",
"uuid": "b874cb14-d4d4-4531-b8a9-750f1e507770",
"filePath": "tests/fixtures/uuid.json",
"isSource": true,
"original": {
"value": "15px"
},
"name": "component-size-sets-mobile",
"attributes": {
"sets": ["mobile"]
},
"path": ["component", "size", "sets", "mobile"]
},
"desktop": {
"value": "12px",
"uuid": "9b3da02b-ed03-4d73-b5c8-d00ae6da2a29",
"filePath": "tests/fixtures/uuid.json",
"isSource": true,
"original": {
"value": "12px"
},
"name": "component-size-sets-desktop",
"attributes": {
"sets": ["desktop"]
},
"path": ["component", "size", "sets", "desktop"]
"accent-content-color-hover": {
"ref": "{accent-color-1000}",
"uuid": "b874cb14-d4d4-4531-b8a9-750f1e507770",
"sets": {
"spectrum": {
"ref": "{blue-1000}",
"uuid": "9b3da02b-ed03-4d73-b5c8-d00ae6da2a29",
"sets": {
"light": {
"uuid": "14dfcb4f-d9ba-459c-9d13-b55960ea55d6",
"value": "rgb(0, 84, 182)"
},
"dark": {
"uuid": "9a9705e5-aeb8-4c9c-b9a0-45f194dd4979",
"value": "rgb(143, 202, 252)"
},
"darkest": {
"uuid": "6aedd27e-2f73-44ad-b4e3-bcba0134c315",
"value": "rgb(124, 189, 250)"
}
}
},
"express": {
"ref": "{indigo-1000}",
"uuid": "90c7ad1e-ebb1-42e6-8742-bb69480d7920",
"sets": {
"light": {
"uuid": "3fadcb6c-c4f6-43b0-a97e-a4162c526509",
"value": "rgb(64, 70, 202)"
},
"dark": {
"uuid": "39d4ee72-c02e-4fa4-bd93-d2078ec49c46",
"value": "rgb(188, 190, 255)"
},
"darkest": {
"uuid": "dd6576ad-6304-4062-8328-34a04a1e2c0b",
"value": "rgb(174, 177, 255)"
}
}
}
},
"black-font-weight": {
"sets": {
"spectrum": {
"attributes": {
"sets": ["spectrum"]
},
"filePath": "tests/fixtures/uuid.json",
"isSource": true,
"original": {
"value": "black"
},
"name": "component-black-font-weight-sets-spectrum",
"path": ["component", "black-font-weight", "sets", "spectrum"],
"value": "black",
"uuid": "90c7ad1e-ebb1-42e6-8742-bb69480d7920"
}
},
"accent-color-1000": {
"sets": {
"spectrum": {
"ref": "{blue-1000}",
"uuid": "9b3da02b-ed03-4d73-b5c8-d00ae6da2a29",
"sets": {
"light": {
"uuid": "14dfcb4f-d9ba-459c-9d13-b55960ea55d6",
"value": "rgb(0, 84, 182)"
},
"dark": {
"uuid": "9a9705e5-aeb8-4c9c-b9a0-45f194dd4979",
"value": "rgb(143, 202, 252)"
},
"darkest": {
"uuid": "6aedd27e-2f73-44ad-b4e3-bcba0134c315",
"value": "rgb(124, 189, 250)"
}
}
},
"express": {
"ref": "{indigo-1000}",
"uuid": "90c7ad1e-ebb1-42e6-8742-bb69480d7920",
"sets": {
"light": {
"uuid": "3fadcb6c-c4f6-43b0-a97e-a4162c526509",
"value": "rgb(64, 70, 202)"
},
"dark": {
"uuid": "39d4ee72-c02e-4fa4-bd93-d2078ec49c46",
"value": "rgb(188, 190, 255)"
},
"darkest": {
"uuid": "dd6576ad-6304-4062-8328-34a04a1e2c0b",
"value": "rgb(174, 177, 255)"
}
}
}
}
},
"blue-1000": {
"sets": {
"light": {
"uuid": "14dfcb4f-d9ba-459c-9d13-b55960ea55d6",
"value": "rgb(0, 84, 182)"
},
"dark": {
"uuid": "9a9705e5-aeb8-4c9c-b9a0-45f194dd4979",
"value": "rgb(143, 202, 252)"
},
"darkest": {
"uuid": "6aedd27e-2f73-44ad-b4e3-bcba0134c315",
"value": "rgb(124, 189, 250)"
}
}
},
"indigo-1000": {
"sets": {
"light": {
"uuid": "3fadcb6c-c4f6-43b0-a97e-a4162c526509",
"value": "rgb(64, 70, 202)"
},
"dark": {
"uuid": "39d4ee72-c02e-4fa4-bd93-d2078ec49c46",
"value": "rgb(188, 190, 255)"
},
"darkest": {
"uuid": "dd6576ad-6304-4062-8328-34a04a1e2c0b",
"value": "rgb(174, 177, 255)"
}
}
}
Expand Down
62 changes: 44 additions & 18 deletions tests/fixtures/uuid.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
{
"component": {
"size": {
"sets": {
"mobile": {
"value": "15px",
"uuid": "b874cb14-d4d4-4531-b8a9-750f1e507770"
},
"desktop": {
"value": "12px",
"uuid": "9b3da02b-ed03-4d73-b5c8-d00ae6da2a29"
}
"accent-content-color-hover": {
"value": "{accent-color-1000}",
"uuid": "b874cb14-d4d4-4531-b8a9-750f1e507770"
},
"accent-color-1000": {
"sets": {
"spectrum": {
"value": "{blue-1000}",
"uuid": "9b3da02b-ed03-4d73-b5c8-d00ae6da2a29"
},
"express": {
"value": "{indigo-1000}",
"uuid": "90c7ad1e-ebb1-42e6-8742-bb69480d7920"
}
},
"black-font-weight": {
"sets": {
"spectrum": {
"value": "black",
"uuid": "90c7ad1e-ebb1-42e6-8742-bb69480d7920"
}
}
},
"blue-1000": {
"sets": {
"light": {
"value": "rgb(0, 84, 182)",
"uuid": "14dfcb4f-d9ba-459c-9d13-b55960ea55d6"
},
"dark": {
"value": "rgb(143, 202, 252)",
"uuid": "9a9705e5-aeb8-4c9c-b9a0-45f194dd4979"
},
"darkest": {
"value": "rgb(124, 189, 250)",
"uuid": "6aedd27e-2f73-44ad-b4e3-bcba0134c315"
}
}
},
"indigo-1000": {
"sets": {
"light": {
"value": "rgb(64, 70, 202)",
"uuid": "3fadcb6c-c4f6-43b0-a97e-a4162c526509"
},
"dark": {
"value": "rgb(188, 190, 255)",
"uuid": "39d4ee72-c02e-4fa4-bd93-d2078ec49c46"
},
"darkest": {
"value": "rgb(174, 177, 255)",
"uuid": "dd6576ad-6304-4062-8328-34a04a1e2c0b"
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions tests/json-formatter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ test("should handle multi nested values", () => {
expect(expected).toMatchObject(result);
});

test("should keep included `uuid`", () => {
test("should keep included uuid", () => {
const filename = "uuid.json";
const sd = StyleDictionary.extend(generateConfig(filename));
const output = sd.exportPlatform('JSON');
sd.buildAllPlatforms();
const expected = helpers.fileToJSON(`./tests/expected/${filename}`);
expect(output).toMatchObject(expected);
const result = helpers.fileToJSON(path.join(helpers.outputDir, filename));
expect(expected).toMatchObject(result);
});

0 comments on commit 7820c7e

Please sign in to comment.