From e45a82065a1fef4203420a6d57cd335ad7ada25d Mon Sep 17 00:00:00 2001 From: Shirley Li Date: Fri, 21 Jun 2024 15:29:11 -0700 Subject: [PATCH 1/8] feat: moved functionality in cli into diff generator library for cross platform use --- .../snapshots/deprecateExpress.test.js.md | 2 +- .../snapshots/deprecateExpress.test.js.snap | Bin 578 -> 583 bytes tools/diff-generator/src/lib/cli.js | 72 ++++-------- .../src/lib/updated-token-detection.js | 70 ++++++++++++ tools/diff-generator/test/fileImport.test.js | 13 +-- .../test/snapshots/fileImport.test.js.md | 6 +- .../test/snapshots/fileImport.test.js.snap | Bin 1109 -> 1110 bytes tools/diff-generator/test/tokenDiff.test.js | 90 ++++++++++++--- .../diff-generator/test/updatedToken.test.js | 104 ++++++++++++++---- 9 files changed, 262 insertions(+), 95 deletions(-) diff --git a/packages/tokens/test/snapshots/deprecateExpress.test.js.md b/packages/tokens/test/snapshots/deprecateExpress.test.js.md index f490beb0..98733ef0 100644 --- a/packages/tokens/test/snapshots/deprecateExpress.test.js.md +++ b/packages/tokens/test/snapshots/deprecateExpress.test.js.md @@ -1,4 +1,4 @@ -# Snapshot report for `test/deprecateExpress.test.js` +# Snapshot report for `packages/tokens/test/deprecateExpress.test.js` The actual snapshot is saved in `deprecateExpress.test.js.snap`. diff --git a/packages/tokens/test/snapshots/deprecateExpress.test.js.snap b/packages/tokens/test/snapshots/deprecateExpress.test.js.snap index 1ec3e84fcfb28adf9f1c0362a3120ac037943701..7eca889712a5ab7aef059d4fbe49946e1b973ea3 100644 GIT binary patch literal 583 zcmV-N0=WG_RzV_xgZa&O&gIMdye&=^}j_-M+ZYP#O zU+unN9qE{dm#=V^bKq9VeN;$_B}0UsFrryVB-R0J0=Nlag=%f8UF+QCKoiYgTdfvo8DxPPL>Yi%BtTA^ z+JVed&R26kj0S4;%-ULkJS!ohE9Kb8dJEvaX=43t;*#|lz!wucQprMv(XWz`tyrs) zc8ca&o%eQ9{P7k6+XUofxCk?h{fK}k1iU8Tgk|8%3l?`;yfQI&L7gA0#dZFyYA%W60yrsv z^TM!j%p~Hv0B#82o{1h>(Bnf<>M>;1*D@=FHzlE#$W9bqf00000000BklD}`$KorOCe0CBFZIZ%BwF#DGBXH!!gQ3u0yC#mx_Mt`Tc3J^6Cq&&&7uzBlT2 zVioqy?n|(djbV888e|$mVS!&C;>s9qdTJ0$E~MmgB1S6Z30NV872K*BYE>Un6PZ+G z*k#S`NRE-6;0GghGJa@-vNe2fV%^3%No#FdyV1E1p`~=TY_(d1E)wbyx)o z4cfFFDxHE}(LzQ8vvOf|HAkKo5Y|;{Y~;Pe%@3}L_qPdRUl94~Vkb(o(A?;E!N@mY zO+hO&LschZ4`E}G<95la#vjv%Nc})jco&$G7l_ZebsdQzU|D!05@nYzEfJ@us+Y`rwU$zHaLkz+I zSKYa|cHXfH9*TGXvp73K=Q%yak9p=EiC>EI6(X-)tWgo?N3S~0Uu6xmJk1C>i*<=P z7J)knyNSpxtOqW7tRlxfR>)C;>06cM!rOvSOH?O{q0siNs%^ZhHzy<0e`D+a QhizoTKU>0puTlm80PVsFfB*mh diff --git a/tools/diff-generator/src/lib/cli.js b/tools/diff-generator/src/lib/cli.js index c8055d7e..e4ef198c 100755 --- a/tools/diff-generator/src/lib/cli.js +++ b/tools/diff-generator/src/lib/cli.js @@ -42,7 +42,7 @@ program "latest", ) .option( - "-ntv, --new-token-version ", + "-ntv, --new-token-version ", "indicates which npm package version/github tag to pull new tokens from", "latest", ) @@ -54,9 +54,9 @@ program "-ntb, --new-token-branch ", "indicates which branch to fetch updated token data from", ) - .option("-t, --test ", "indicates switch to testing mode") + .option("-t, --test ", "indicates switch to testing mode") .option( - "-tn, --token-names ", + "-tn, --token-names ", "indicates specific tokens to compare", ) .action(async (options) => { @@ -146,13 +146,9 @@ const printStyleColored = (token, color, log) => { * @param {object} token - the current token * @param {object} log - the console.log object being used */ -const printStyleUpdated = (original, result, renamed, token, log) => { - const originalToken = - original[token] === undefined - ? original[renamed[token]["old-name"]] // if the token was renamed and updated, need to look in renamed to get token's old name - : original[token]; +const printStyleUpdated = (result, token, log) => { log(indent(yellow(`"${token}"`), 2)); - printNestedChanges(result[token], "", originalToken, originalToken, log); + printNestedChanges(result[token], log); }; /** @@ -421,7 +417,7 @@ function printSection( if (textColor != white) { func(token, textColor, log); } else if (original !== undefined && renamed !== undefined) { - func(original, result, renamed, token, log); + func(result, token, log); } else { func(result, token, log); } @@ -436,36 +432,23 @@ function printSection( * @param {object} originalToken - the original token * @param {object} log - the console.log object used */ -function printNestedChanges( - token, - properties, - originalToken, - curOriginalLevel, - log, -) { - if ( - typeof token !== "object" || - typeof token === "string" || - token === null - ) { - log(indent(yellow(properties.substring(1)), 3)); - if (curOriginalLevel === token) { - if ( - curOriginalLevel.includes( - "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/", - ) - ) { +function printNestedChanges(token, log) { + if (token["path"] !== undefined) { + log(indent(yellow(token["path"]), 3)); + + if (token["original-value"] === undefined) { + if (token["path"].includes("$schema")) { log(indent(yellow(`"${token}"`), 4)); } else { log(indent(yellow(`${token}`), 4)); } - } else if (properties.substring(1) === "$schema") { - const newValue = token.split("/"); + } else if (token["path"].includes("$schema")) { + const newValue = token["new-value"].split("/"); const str = - indent(white(`"${curOriginalLevel}" -> \n`), 4) + + indent(white(`"${token["original-value"]}" -> \n`), 4) + indent( white( - `"${token.substring(0, token.length - newValue[newValue.length - 1].length)}`, + `"${token["new-value"].substring(0, token["new-value"].length - newValue[newValue.length - 1].length)}`, ) + yellow( `${newValue[newValue.length - 1].split(".")[0]}` + @@ -475,24 +458,17 @@ function printNestedChanges( ); log(str); } else { - log(indent(white(`${curOriginalLevel} -> `) + yellow(`${token}`), 4)); + log( + indent( + white(`${token["original-value"]} -> `) + + yellow(`${token["new-value"]}`), + 4, + ), + ); } return; } Object.keys(token).forEach((property) => { - const nextProperties = properties + "." + property; - const keys = nextProperties.substring(1).split("."); - curOriginalLevel = originalToken; - keys.forEach((key) => { - curOriginalLevel = - curOriginalLevel[key] === undefined ? token : curOriginalLevel[key]; - }); - printNestedChanges( - token[property], - nextProperties, - originalToken, - curOriginalLevel, - log, - ); + printNestedChanges(token[property], log); }); } diff --git a/tools/diff-generator/src/lib/updated-token-detection.js b/tools/diff-generator/src/lib/updated-token-detection.js index 28dcdeb9..b3e20c25 100644 --- a/tools/diff-generator/src/lib/updated-token-detection.js +++ b/tools/diff-generator/src/lib/updated-token-detection.js @@ -57,5 +57,75 @@ export default function detectUpdatedTokens( updatedTokens.deleted[token] = tokenDiff; } }); + Object.keys(updatedTokens.updated).forEach((token) => { + if (renamed[token] !== undefined) { + includeOldProperties( + updatedTokens.updated[token], + updatedTokens.updated[token], + token + "", + original, + original[renamed[token]["old-name"]], + renamed, + ); + } else { + includeOldProperties( + updatedTokens.updated[token], + updatedTokens.updated[token], + token + "", + original, + original[token], + renamed, + ); + } + }); return updatedTokens; } + +function includeOldProperties( + token, + curTokenLevel, + properties, + originalToken, + curOriginalLevel, + renamed, +) { + Object.keys(curTokenLevel).forEach((property) => { + if (typeof curTokenLevel[property] === "string") { + const newValue = curTokenLevel[property]; + const path = !properties.includes(".") + ? property + : `${properties.substring(properties.indexOf(".") + 1)}.${property}`; + curTokenLevel[property] = JSON.parse(`{ + "${"new-value"}": "${newValue}", + "path": "${path}", + "original-value": "${curOriginalLevel[property]}" + }`); + return; + } + const nextProperties = properties + "." + property; + const keys = nextProperties.split("."); + curOriginalLevel = originalToken; + curTokenLevel = token; + keys.forEach((key) => { + if (curOriginalLevel[key] === undefined) { + if (curOriginalLevel[renamed[key]["old-name"]] !== undefined) { + curOriginalLevel = curOriginalLevel[renamed[key]["old-name"]]; + } else { + curOriginalLevel = originalToken; + } + } else { + curOriginalLevel = curOriginalLevel[key]; + } + curTokenLevel = + curTokenLevel[key] === undefined ? token : curTokenLevel[key]; + }); + includeOldProperties( + token, + curTokenLevel, + nextProperties, + originalToken, + curOriginalLevel, + renamed, + ); + }); +} diff --git a/tools/diff-generator/test/fileImport.test.js b/tools/diff-generator/test/fileImport.test.js index 36ef636d..5ad2ecb6 100644 --- a/tools/diff-generator/test/fileImport.test.js +++ b/tools/diff-generator/test/fileImport.test.js @@ -14,7 +14,6 @@ import test from "ava"; import nixt from "nixt"; import fs from "fs"; import { access, readFile } from "fs/promises"; -import fileImport from "../src/lib/file-import.js"; const path = fs.realpathSync("./") + "/test/"; const schemaPath = "test-schemas/"; @@ -45,7 +44,7 @@ test("checking file import for two branches (both main)", async (t) => { }); }); -test("checking cli output for two branches (shirlsli/diff-generator-cli-tests and shirlsli/file-import-tests) for added color-component tokens", async (t) => { +test("checking cli output for two branches (shirlsli/diff-generator-cli and shirlsli/file-import-tests) for added color-component tokens", async (t) => { t.plan(1); return new Promise((resolve, reject) => { try { @@ -63,7 +62,7 @@ test("checking cli output for two branches (shirlsli/diff-generator-cli-tests an } }) .run( - "pnpm tdiff report -otb shirlsli/diff-generator-cli-tests -ntb shirlsli/file-import-tests -tn src/color-component.json", + "pnpm tdiff report -otb shirlsli/diff-generator-cli -ntb shirlsli/file-import-tests -tn src/color-component.json", ) .end(resolve); } catch (error) { @@ -72,7 +71,7 @@ test("checking cli output for two branches (shirlsli/diff-generator-cli-tests an }); }); -test("checking cli output for two branches (shirlsli/diff-generator-cli-tests and shirlsli/file-import-tests) for deleted layout tokens", async (t) => { +test("checking cli output for two branches (shirlsli/diff-generator-cli and shirlsli/file-import-tests) for deleted layout tokens", async (t) => { t.plan(1); return new Promise((resolve, reject) => { try { @@ -90,7 +89,7 @@ test("checking cli output for two branches (shirlsli/diff-generator-cli-tests an } }) .run( - "pnpm tdiff report -otb shirlsli/diff-generator-cli-tests -ntb shirlsli/file-import-tests -tn src/layout.json", + "pnpm tdiff report -otb shirlsli/diff-generator-cli -ntb shirlsli/file-import-tests -tn src/layout.json", ) .end(resolve); } catch (error) { @@ -99,7 +98,7 @@ test("checking cli output for two branches (shirlsli/diff-generator-cli-tests an }); }); -test("checking cli output for two branches (shirlsli/diff-generator-cli-tests and shirlsli/file-import-tests) for renamed, deprecated, added, deleted, and updated tokens", async (t) => { +test("checking cli output for two branches (shirlsli/diff-generator-cli and shirlsli/file-import-tests) for renamed, deprecated, added, deleted, and updated tokens", async (t) => { t.plan(1); return new Promise((resolve, reject) => { try { @@ -117,7 +116,7 @@ test("checking cli output for two branches (shirlsli/diff-generator-cli-tests an } }) .run( - "pnpm tdiff report -otb shirlsli/diff-generator-cli-tests -ntb shirlsli/file-import-tests", + "pnpm tdiff report -otb shirlsli/diff-generator-cli -ntb shirlsli/file-import-tests", ) .end(resolve); } catch (error) { diff --git a/tools/diff-generator/test/snapshots/fileImport.test.js.md b/tools/diff-generator/test/snapshots/fileImport.test.js.md index bbd78ce2..db9600f8 100644 --- a/tools/diff-generator/test/snapshots/fileImport.test.js.md +++ b/tools/diff-generator/test/snapshots/fileImport.test.js.md @@ -17,7 +17,7 @@ Generated by [AVA](https://avajs.dev). latest | latest␊ -------------------------------------------------------------------------------------------` -## checking cli output for two branches (shirlsli/diff-generator-cli-tests and shirlsli/file-import-tests) for added color-component tokens +## checking cli output for two branches (shirlsli/diff-generator-cli and shirlsli/file-import-tests) for added color-component tokens > Snapshot 1 @@ -41,7 +41,7 @@ Generated by [AVA](https://avajs.dev). ␊ "i-like-frozen-yogurt"` -## checking cli output for two branches (shirlsli/diff-generator-cli-tests and shirlsli/file-import-tests) for deleted layout tokens +## checking cli output for two branches (shirlsli/diff-generator-cli and shirlsli/file-import-tests) for deleted layout tokens > Snapshot 1 @@ -61,7 +61,7 @@ Generated by [AVA](https://avajs.dev). ␊ "text-to-visual-100"` -## checking cli output for two branches (shirlsli/diff-generator-cli-tests and shirlsli/file-import-tests) for renamed, deprecated, added, deleted, and updated tokens +## checking cli output for two branches (shirlsli/diff-generator-cli and shirlsli/file-import-tests) for renamed, deprecated, added, deleted, and updated tokens > Snapshot 1 diff --git a/tools/diff-generator/test/snapshots/fileImport.test.js.snap b/tools/diff-generator/test/snapshots/fileImport.test.js.snap index 14927199c7dcc44d864a44528f77bf62690134d7..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5D75%eP~Sz7Pe`OlgE`OTSqktW)TssG`34k~Cq8;Fd>RGA5+N;9auur5Gq9fX;M z#E}shd*~)MWRR0GJIWg>d}f1x`a((y^xgJ@54S$vs;=#iwm$jbc>B@4hbIqCzB-0S zN^4*he=>HEFepPpl#T*}bug=fA#-*HWPqKs4pa)IXIUrUSTlL{kZ@`p!(Ea#;l3|e z1Xt!5?39haI~ewccY5*dDB9iqrhWupW@IKTp&Re)?naT%l+#|TzEo+76E^H9ScgI@ z4D5r4C$M~{vH=?#nqU-Zs&3#3G&d2xxoc6De`m|G2(7@Dp(r<1<@%M8k*`?WPOV8& zvIJpuHPYsVHEaSj_HL;5%e89%`TkUUbknLGMbY2C{qh&ws|(N_?L-j(bQEeeWt7&F z@2ov4$dH+!D4m)9Gw zfAjYTt>Mi?>m}T8o$n4?xO_oEnF$W!IBq!!d=@ZRJXO9VT}76Z{P8v^acn4Oxd)O9 z$AUt2UpJ?{1wnhYP+7<-cqK=-K3n7H(_8O|qYWSp4sRq$KmQ63o9aM!za=TrCF7kq z?f`yq-n3MXzRX*)97`Nsc%vZil{J{Ue^LdUIA()^X~7~Tn$fdn5m=(LGfYTKC(f2e zqOIT!b2Qc<=S4SUI6$KR*jk$LKR$-{2QmnJQ&3^Zyuo-3{o5& z#t9~el;UW7bQJT!ksJwL#cr`Xufgt;nakF_aZ~bH;n@2ti$9Lzs+qS3{BpL{K6!ol z-cZFB>kCcQsyzSiDcXiRwWP0tLsv)DCjT~`CAFL0=8W|SoRLS-e2e@8y{;w83lIPR DFNYB| diff --git a/tools/diff-generator/test/tokenDiff.test.js b/tools/diff-generator/test/tokenDiff.test.js index 07dd31e8..262a9c99 100644 --- a/tools/diff-generator/test/tokenDiff.test.js +++ b/tools/diff-generator/test/tokenDiff.test.js @@ -264,28 +264,57 @@ const expectedSeveralRADDepU = { deleted: {}, updated: { "thumbnail-border-color": { - $schema: - "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/not-a-thumbnail.json", + $schema: { + "new-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/not-a-thumbnail.json", + "original-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json", + path: "$schema", + }, }, "opacity-checkerboard-square-dark": { sets: { light: { - value: "{gray-500}", + value: { + "new-value": "{gray-500}", + "original-value": "{gray-200}", + path: "sets.light.value", + }, }, darkest: { - value: "{gray-900}", + value: { + "new-value": "{gray-900}", + "original-value": "{gray-800}", + path: "sets.darkest.value", + }, }, }, }, "color-slider-border-opacity": { - component: "not-a-color-slider", + component: { + "new-value": "not-a-color-slider", + "original-value": "color-slider", + path: "component", + }, }, "color-loupe-inner-border": { - uuid: "if a uuid ever change lol", + uuid: { + "new-value": "if a uuid ever change lol", + "original-value": "d2c4cb48-8a90-461d-95bc-d882ba01472b", + path: "uuid", + }, }, "drop-zone-background-color": { - component: "woohoo!", - value: "{fushcia pink}", + component: { + "new-value": "woohoo!", + "original-value": "drop-zone", + path: "component", + }, + value: { + "new-value": "{fushcia pink}", + "original-value": "{accent-visual-color}", + path: "value", + }, }, }, }, @@ -343,28 +372,57 @@ const expectedSeveralRADDepURev = { deleted: {}, updated: { "thumbnail-border-color": { - $schema: - "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/not-a-thumbnail.json", + $schema: { + "new-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/not-a-thumbnail.json", + "original-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json", + path: "$schema", + }, }, "opacity-checkerboard-square-dark": { sets: { light: { - value: "{gray-500}", + value: { + "new-value": "{gray-500}", + "original-value": "{gray-200}", + path: "sets.light.value", + }, }, darkest: { - value: "{gray-900}", + value: { + "new-value": "{gray-900}", + "original-value": "{gray-800}", + path: "sets.darkest.value", + }, }, }, }, "color-slider-border-opacity": { - component: "not-a-color-slider", + component: { + "new-value": "not-a-color-slider", + "original-value": "color-slider", + path: "component", + }, }, "color-loupe-inner-border": { - uuid: "if a uuid ever change lol", + uuid: { + "new-value": "if a uuid ever change lol", + "original-value": "d2c4cb48-8a90-461d-95bc-d882ba01472b", + path: "uuid", + }, }, "drop-zone-background-color": { - component: "woohoo!", - value: "{fushcia pink}", + component: { + "new-value": "woohoo!", + "original-value": "drop-zone", + path: "component", + }, + value: { + "new-value": "{fushcia pink}", + "original-value": "{accent-visual-color}", + path: "value", + }, }, }, }, diff --git a/tools/diff-generator/test/updatedToken.test.js b/tools/diff-generator/test/updatedToken.test.js index 0a886970..9b29ec25 100644 --- a/tools/diff-generator/test/updatedToken.test.js +++ b/tools/diff-generator/test/updatedToken.test.js @@ -31,7 +31,13 @@ const expected = { added: {}, deleted: {}, updated: { - "swatch-border-color": { value: "{blue-200}" }, + "swatch-border-color": { + value: { + "new-value": "{blue-200}", + path: "value", + "original-value": "{gray-900}", + }, + }, }, }; @@ -40,9 +46,18 @@ const expectedUpdatedSeveralProperties = { deleted: {}, updated: { "swatch-border-color": { - $schema: - "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/color.json", - value: "{blue-200}", + $schema: { + "new-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/color.json", + path: "$schema", + "original-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json", + }, + value: { + "new-value": "{blue-200}", + path: "value", + "original-value": "{gray-900}", + }, }, }, }; @@ -54,16 +69,34 @@ const expectedUpdatedSet = { "overlay-opacity": { sets: { darkest: { - value: "0.8", + value: { + "new-value": "0.8", + "original-value": "0.6", + path: "sets.darkest.value", + }, }, light: { - $schema: - "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/color.json", + $schema: { + "new-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/color.json", + "original-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/opacity.json", + path: "sets.light.$schema", + }, }, wireframe: { - $schema: - "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/wireframe.json", - value: "0", + $schema: { + "new-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/wireframe.json", + "original-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/opacity.json", + path: "sets.wireframe.$schema", + }, + value: { + "new-value": "0", + "original-value": "0.4", + path: "sets.wireframe.value", + }, }, }, }, @@ -75,22 +108,40 @@ const expectedSeveralUpdatedSet = { deleted: {}, updated: { "help-text-top-to-workflow-icon-medium": { - $schema: - "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/token-set.json", + $schema: { + "new-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/token-set.json", + path: "$schema", + "original-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/scale-set.json", + }, sets: { desktop: { - $schema: - "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/changing-two-schemas.json", + $schema: { + "new-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/changing-two-schemas.json", + "original-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/dimension.json", + path: "sets.desktop.$schema", + }, }, mobile: { - value: "9px", + value: { + "new-value": "9px", + "original-value": "4px", + path: "sets.mobile.value", + }, }, }, }, "status-light-top-to-dot-large": { sets: { desktop: { - value: "20px", + value: { + "new-value": "20px", + "original-value": "15px", + path: "sets.desktop.value", + }, }, }, }, @@ -104,16 +155,29 @@ const expectedUpdatedSetWithRename = { "help-text-top-to-workflow-icon-medium": { sets: { desktop: { - value: "7px", + value: { + "new-value": "7px", + "original-value": "3px", + path: "sets.desktop.value", + }, }, }, }, "i-like-fish-tacos": { - $schema: - "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/scaly-fish.json", + $schema: { + "new-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/scaly-fish.json", + "original-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/scale-set.json", + path: "$schema", + }, sets: { mobile: { - value: "15px", + value: { + "new-value": "15px", + "original-value": "12px", + path: "sets.mobile.value", + }, }, }, }, From ed1474592396f4dedbe8b12759e4be85a6a93f91 Mon Sep 17 00:00:00 2001 From: Shirley Li Date: Fri, 21 Jun 2024 16:00:29 -0700 Subject: [PATCH 2/8] docs: edited comments --- tools/diff-generator/src/lib/cli.js | 4 ---- tools/diff-generator/src/lib/updated-token-detection.js | 9 +++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/diff-generator/src/lib/cli.js b/tools/diff-generator/src/lib/cli.js index e4ef198c..07c05b01 100755 --- a/tools/diff-generator/src/lib/cli.js +++ b/tools/diff-generator/src/lib/cli.js @@ -140,9 +140,7 @@ const printStyleColored = (token, color, log) => { /** * Styling for updated tokens - * @param {object} original - the original token(s) * @param {object} result - the JSON object with the report results - * @param {object} renamed - tokens that were renamed * @param {object} token - the current token * @param {object} log - the console.log object being used */ @@ -428,8 +426,6 @@ function printSection( /** * Traverse through the updated token's keys and prints a simple changelog * @param {object} token - the updated token - * @param {object} properties - a string containing the keys traversed through until intended value, separated by periods (i.e. sets.light.value) - * @param {object} originalToken - the original token * @param {object} log - the console.log object used */ function printNestedChanges(token, log) { diff --git a/tools/diff-generator/src/lib/updated-token-detection.js b/tools/diff-generator/src/lib/updated-token-detection.js index b3e20c25..46b82a87 100644 --- a/tools/diff-generator/src/lib/updated-token-detection.js +++ b/tools/diff-generator/src/lib/updated-token-detection.js @@ -81,6 +81,15 @@ export default function detectUpdatedTokens( return updatedTokens; } +/** + * Traverses original and result token to insert the original value, path to the value, and new value + * @param {object} token - the current token from updatedTokens + * @param {object} curTokenLevel - the current key + * @param {string} properties - a string containing the path to get to the value + * @param {object} originalToken - the original token + * @param {object} curOriginalLevel - the current key for original token + * @param {object} renamed - the renamed tokens + */ function includeOldProperties( token, curTokenLevel, From 69a337ec9e37ceff7e86b7a9f6ff32a1fbda3b5b Mon Sep 17 00:00:00 2001 From: Shirley Li Date: Tue, 25 Jun 2024 15:31:14 -0700 Subject: [PATCH 3/8] fix: fixed bug with added and deleted properties detection after refactor --- tools/diff-generator/src/lib/cli.js | 4 +- .../src/lib/updated-token-detection.js | 81 ++++++++++++------ tools/diff-generator/test/cli.test.js | 54 ++++++++++++ .../test/snapshots/cli.test.js.md | 46 ++++++++++ .../test/snapshots/cli.test.js.snap | Bin 1172 -> 1250 bytes .../expected-deleted-property-token.txt | 18 ++++ .../expected-non-schema-property.txt | 18 ++++ .../added-non-schema-property-token.json | 31 +++++++ tools/diff-generator/test/tokenDiff.test.js | 34 ++++++-- .../diff-generator/test/updatedToken.test.js | 34 ++++++-- 10 files changed, 277 insertions(+), 43 deletions(-) create mode 100644 tools/diff-generator/test/test-cli-outputs/expected-deleted-property-token.txt create mode 100644 tools/diff-generator/test/test-cli-outputs/expected-non-schema-property.txt create mode 100644 tools/diff-generator/test/test-schemas/added-non-schema-property-token.json diff --git a/tools/diff-generator/src/lib/cli.js b/tools/diff-generator/src/lib/cli.js index 07c05b01..340b79a5 100755 --- a/tools/diff-generator/src/lib/cli.js +++ b/tools/diff-generator/src/lib/cli.js @@ -434,9 +434,9 @@ function printNestedChanges(token, log) { if (token["original-value"] === undefined) { if (token["path"].includes("$schema")) { - log(indent(yellow(`"${token}"`), 4)); + log(indent(yellow(`"${token["new-value"]}"`), 4)); } else { - log(indent(yellow(`${token}`), 4)); + log(indent(yellow(`${token["new-value"]}`), 4)); } } else if (token["path"].includes("$schema")) { const newValue = token["new-value"].split("/"); diff --git a/tools/diff-generator/src/lib/updated-token-detection.js b/tools/diff-generator/src/lib/updated-token-detection.js index 46b82a87..4e344e45 100644 --- a/tools/diff-generator/src/lib/updated-token-detection.js +++ b/tools/diff-generator/src/lib/updated-token-detection.js @@ -45,6 +45,7 @@ export default function detectUpdatedTokens( deprecatedTokens.deprecated[token] === undefined ) { updatedTokens.added[token] = changes.added[token]; + formatJSON(updatedTokens.added[token], token, original, renamed, false); } }); Object.keys(changes.deleted).forEach((token) => { @@ -55,32 +56,47 @@ export default function detectUpdatedTokens( original[token], ).updated; updatedTokens.deleted[token] = tokenDiff; + formatJSON(updatedTokens.deleted[token], token, original, renamed, false); } }); Object.keys(updatedTokens.updated).forEach((token) => { - if (renamed[token] !== undefined) { - includeOldProperties( - updatedTokens.updated[token], - updatedTokens.updated[token], - token + "", - original, - original[renamed[token]["old-name"]], - renamed, - ); - } else { - includeOldProperties( - updatedTokens.updated[token], - updatedTokens.updated[token], - token + "", - original, - original[token], - renamed, - ); - } + formatJSON(updatedTokens.updated[token], token, original, renamed, true); }); return updatedTokens; } +/** + * Appends original token properties to updatedTokens JSON + * @param {object} tokens - the updated tokens (added, deleted, or updated) + * @param {string} properties - the path containing all the keys required to traverse through to get to value + * @param {object} original - the original token + * @param {object} renamed - a JSON object containing the renamed tokens + * @param {boolean} update - a boolean indicating whether token property is added, deleted, or updated + */ +function formatJSON(tokens, properties, original, renamed, update) { + if (renamed[properties] !== undefined) { + includeOldProperties( + tokens, + tokens, + properties, + original, + original[renamed[properties]["old-name"]], + renamed, + update, + ); + } else { + includeOldProperties( + tokens, + tokens, + properties, + original, + original[properties], + renamed, + update, + ); + } +} + /** * Traverses original and result token to insert the original value, path to the value, and new value * @param {object} token - the current token from updatedTokens @@ -97,18 +113,31 @@ function includeOldProperties( originalToken, curOriginalLevel, renamed, + update, ) { Object.keys(curTokenLevel).forEach((property) => { + if ( + property === "path" || + property === "new-value" || + property === "original-value" + ) { + return; + } if (typeof curTokenLevel[property] === "string") { const newValue = curTokenLevel[property]; const path = !properties.includes(".") ? property : `${properties.substring(properties.indexOf(".") + 1)}.${property}`; - curTokenLevel[property] = JSON.parse(`{ - "${"new-value"}": "${newValue}", + curTokenLevel[property] = update + ? JSON.parse(`{ + "new-value": "${newValue}", "path": "${path}", "original-value": "${curOriginalLevel[property]}" - }`); + }`) + : JSON.parse(`{ + "new-value": "${newValue}", + "path": "${path}" + }`); return; } const nextProperties = properties + "." + property; @@ -117,10 +146,11 @@ function includeOldProperties( curTokenLevel = token; keys.forEach((key) => { if (curOriginalLevel[key] === undefined) { - if (curOriginalLevel[renamed[key]["old-name"]] !== undefined) { + if ( + renamed[key] !== undefined && + curOriginalLevel[renamed[key]["old-name"]] !== undefined + ) { curOriginalLevel = curOriginalLevel[renamed[key]["old-name"]]; - } else { - curOriginalLevel = originalToken; } } else { curOriginalLevel = curOriginalLevel[key]; @@ -135,6 +165,7 @@ function includeOldProperties( originalToken, curOriginalLevel, renamed, + update, ); }); } diff --git a/tools/diff-generator/test/cli.test.js b/tools/diff-generator/test/cli.test.js index 505c037d..9f61671d 100644 --- a/tools/diff-generator/test/cli.test.js +++ b/tools/diff-generator/test/cli.test.js @@ -171,3 +171,57 @@ test("check cli output for renamed, added, deleted, and deprecated tokens", asyn } }); }); + +test("check cli output for added non-schema property", async (t) => { + t.plan(1); + return new Promise((resolve, reject) => { + try { + nixt() + .expect(async () => { + try { + const expectedFileName = `${path}${outputPath}expected-non-schema-property.txt`; + await access(expectedFileName); + const expected = await readFile(expectedFileName, { + encoding: "utf8", + }); + t.snapshot(expected.trim()); + } catch (error) { + reject(error); + } + }) + .run( + `pnpm tdiff report -t ${path}${schemaPath}basic-set-token.json ${path}${schemaPath}added-non-schema-property-token.json`, + ) + .end(resolve); + } catch (error) { + reject(error); + } + }); +}); + +test("check cli output for deleted non-schema property", async (t) => { + t.plan(1); + return new Promise((resolve, reject) => { + try { + nixt() + .expect(async () => { + try { + const expectedFileName = `${path}${outputPath}expected-deleted-property-token.txt`; + await access(expectedFileName); + const expected = await readFile(expectedFileName, { + encoding: "utf8", + }); + t.snapshot(expected.trim()); + } catch (error) { + reject(error); + } + }) + .run( + `pnpm tdiff report -t ${path}${schemaPath}added-non-schema-property-token.json ${path}${schemaPath}basic-set-token.json`, + ) + .end(resolve); + } catch (error) { + reject(error); + } + }); +}); diff --git a/tools/diff-generator/test/snapshots/cli.test.js.md b/tools/diff-generator/test/snapshots/cli.test.js.md index 78044d94..92d5ea27 100644 --- a/tools/diff-generator/test/snapshots/cli.test.js.md +++ b/tools/diff-generator/test/snapshots/cli.test.js.md @@ -240,3 +240,49 @@ Generated by [AVA](https://avajs.dev). "table-selected-row-background-opacity-non-emphasized"␊ ␊ "table-selected-row-background-opacity-non-emphasized-hover"` + +## check cli output for added non-schema property + +> Snapshot 1 + + `WARNING: Will either be inaccurate or will throw an error if used for releases before @adobe/spectrum-tokens@12.26.0!␊ + ␊ + ␊ + **Tokens Changed (1)**␊ + ␊ + latest | latest␊ + -------------------------------------------------------------------------------------------␊ + ␊ + ␊ + 🆕 Updated (1)␊ + ␊ + 🆕 Added Properties (1)␊ + ␊ + "overlay-opacity"␊ + ␊ + sets.some-new-property.value␊ + ␊ + 0.8` + +## check cli output for deleted non-schema property + +> Snapshot 1 + + `WARNING: Will either be inaccurate or will throw an error if used for releases before @adobe/spectrum-tokens@12.26.0!␊ + ␊ + ␊ + **Tokens Changed (1)**␊ + ␊ + latest | latest␊ + -------------------------------------------------------------------------------------------␊ + ␊ + ␊ + 🆕 Updated (1)␊ + ␊ + 🆕 Deleted Properties (1)␊ + ␊ + "overlay-opacity"␊ + ␊ + sets.some-new-property.value␊ + ␊ + 0.8` diff --git a/tools/diff-generator/test/snapshots/cli.test.js.snap b/tools/diff-generator/test/snapshots/cli.test.js.snap index da6ba5cdbedb88e07b658bb73bd333e9a81f6336..5e8cbf91102523a1cbac3ac1ac6bae8ba469c47a 100644 GIT binary patch literal 1250 zcmV<81ReW9RzVTf zPnT0&udS-y*;yhYh=K$KlN>}u;$Pq&p#O}2fk%(h-P5z(JF{zu3E9QWsi&&m_wRi@ zPh!Jz>c9Dwf)0lEK&B+8AdLntLS6(&*n!tsZU~f4678+XeagXq`CKUx#3vgU&!5>i zQ~u7rbLQQ1?`=H1egEEv_dd7*54ABsI;7+vCeT($SvV00*ukv445{N82n*yKJJ1Of zo>V2%ks;y9Lre)ff?GmyOaq^j46ev9@RY2-H5&KFSNp>YQM9%7adiZDQeh{g;Ns}& z=GIme`BXdOjUJTxWGm zPRK=AGI~K4(VyS{w$QNmz~aH19$Xx4uCZP@&e5kr@ob@MW#`l1;kHt3;}-77_5QwC z=$dLwc~<%!=e%&x(?8%Y8LIrUy&z2ti=gcUg$$Z4#z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zn1Z^NPMuibcsMM5sNVO6!;|1rBKgzd2QB!GWBA7OU0U8YP;!>DB^$b;+vrk!9g+6x z2}N~|x2sQEOHpXmRiMUlBIC&c9*7%5oa~Pj-q?#Js)K`ZEQX`W^>JJ()(MCT4s=Kk zWL5LQuvzJ^67PsDwJE%@kj3n|G4Jk-7rrq)wplftJ`3&^#d zHBA;bHrb*{G*OnM9mwn4TC8{6OW$`o?$?*zoQ``g8*aPGjapT%?hWl4H#)9yk_@@U z8n;kUA_^1MlD+O{*!#u-+XTb&%`@Ez~ilg;yi-LIWX zy0?d@W+X_-X zes$Lx4TsHv){xK~@j-;bV|DXG#R1DJH`3$a1RCL{)N819_ob+{q*cSQ)vR Date: Wed, 26 Jun 2024 08:54:28 -0700 Subject: [PATCH 4/8] test: added another test to check for added and deleted properties --- .../added-deleted-set-token-property.json | 28 +++++++ .../diff-generator/test/updatedToken.test.js | 75 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 tools/diff-generator/test/test-schemas/added-deleted-set-token-property.json diff --git a/tools/diff-generator/test/test-schemas/added-deleted-set-token-property.json b/tools/diff-generator/test/test-schemas/added-deleted-set-token-property.json new file mode 100644 index 00000000..9c6e01ba --- /dev/null +++ b/tools/diff-generator/test/test-schemas/added-deleted-set-token-property.json @@ -0,0 +1,28 @@ +{ + "celery-background-color-default": { + "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/color-set.json", + "sets": { + "light": { + "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json", + "value": "{celery-600}", + "uuid": "d4fd682d-4bef-4a92-bf14-90ce02b534e6" + }, + "dark": { + "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json", + "value": "{celery-800}", + "uuid": "87f5b73a-19b1-40f7-991b-0d4b6bfc4a99" + }, + "wireframe": { + "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json", + "value": "{celery-1100}", + "uuid": "3e44abd8-ea12-4c0a-9007-4a6edaa3b962" + }, + "fun-times": { + "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json", + "value": "{fun}", + "uuid": "2345" + } + }, + "uuid": "2c159320-bf17-48b6-9d09-b2d037f937d1" + } +} diff --git a/tools/diff-generator/test/updatedToken.test.js b/tools/diff-generator/test/updatedToken.test.js index 081c7412..bf3fb987 100644 --- a/tools/diff-generator/test/updatedToken.test.js +++ b/tools/diff-generator/test/updatedToken.test.js @@ -26,6 +26,7 @@ import severalUpdatedSetTokens from "./test-schemas/several-updated-set-tokens.j import severalRenamedUpdatedSetTokens from "./test-schemas/several-renamed-updated-set-tokens.json" with { type: "json" }; import basicSetTokenProperty from "./test-schemas/basic-set-token-property.json" with { type: "json" }; import addedPropertySetToken from "./test-schemas/added-property-set-token.json" with { type: "json" }; +import addedDeletedPropertySetToken from "./test-schemas/added-deleted-set-token-property.json" with { type: "json" }; const expected = { added: {}, @@ -236,6 +237,52 @@ const expectedDeletedProperty = { updated: {}, }; +const expectedAddedDeletedProperty = { + added: { + "celery-background-color-default": { + sets: { + "fun-times": { + $schema: { + "new-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json", + path: "sets.fun-times.$schema", + }, + uuid: { + "new-value": "2345", + path: "sets.fun-times.uuid", + }, + value: { + "new-value": "{fun}", + path: "sets.fun-times.value", + }, + }, + }, + }, + }, + deleted: { + "celery-background-color-default": { + sets: { + darkest: { + $schema: { + "new-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json", + path: "sets.darkest.$schema", + }, + uuid: { + "new-value": "a9ab7a59-9cab-47fb-876d-6f0af93dc5df", + path: "sets.darkest.uuid", + }, + value: { + "new-value": "{celery-800}", + path: "sets.darkest.value", + }, + }, + }, + }, + }, + updated: {}, +}; + test("basic test to check if updated token is detected", (t) => { const diff = detailedDiff(original, updatedToken); const renamed = detectRenamedTokens(original, updatedToken); @@ -362,3 +409,31 @@ test("testing deleting a property to a token with sets", (t) => { expectedDeletedProperty, ); }); + +test("testing adding and deleting a property to a token with sets", (t) => { + const diff = detailedDiff( + basicSetTokenProperty, + addedDeletedPropertySetToken, + ); + const renamed = detectRenamedTokens( + basicSetTokenProperty, + addedDeletedPropertySetToken, + ); + const deprecated = detectDeprecatedTokens(renamed, diff); + const added = detectNewTokens( + renamed, + deprecated, + diff.added, + basicSetTokenProperty, + ); + t.deepEqual( + detectUpdatedTokens( + renamed, + basicSetTokenProperty, + diff, + added, + deprecated, + ), + expectedAddedDeletedProperty, + ); +}); From f5d245ea92352d45fb914295f6bb53a2423eecfd Mon Sep 17 00:00:00 2001 From: Shirley Li Date: Thu, 27 Jun 2024 11:28:41 -0700 Subject: [PATCH 5/8] test: checking cli output for when comparing between github tag and branch --- tools/diff-generator/src/lib/cli.js | 31 ++--- tools/diff-generator/test/fileImport.test.js | 27 ++++ .../test/snapshots/fileImport.test.js.md | 125 ++++++++++++++++++ .../test/snapshots/fileImport.test.js.snap | Bin 1110 -> 1182 bytes .../expected-release-branch-compare.txt | 120 +++++++++++++++++ .../diff-generator/test/updatedToken.test.js | 76 +++++++++++ 6 files changed, 361 insertions(+), 18 deletions(-) create mode 100644 tools/diff-generator/test/test-cli-outputs/expected-release-branch-compare.txt diff --git a/tools/diff-generator/src/lib/cli.js b/tools/diff-generator/src/lib/cli.js index 340b79a5..04145d3d 100755 --- a/tools/diff-generator/src/lib/cli.js +++ b/tools/diff-generator/src/lib/cli.js @@ -39,12 +39,10 @@ program .option( "-otv, --old-token-version ", "indicates which npm package version/github tag to pull old tokens from", - "latest", ) .option( "-ntv, --new-token-version ", "indicates which npm package version/github tag to pull new tokens from", - "latest", ) .option( "-otb, --old-token-branch ", @@ -227,23 +225,20 @@ function printReport(original, result, log, options) { Object.keys(result.updated.deleted).length + Object.keys(result.updated.updated).length; log(white("\n**Tokens Changed (" + totalTokens + ")**")); - if ( - options.oldTokenBranch !== undefined && - options.newTokenBranch !== undefined - ) { - log( - white(`\n${options.oldTokenBranch} | `) + - yellow(`${options.newTokenBranch}`), - ); + let originalSchema = ""; + let updatedSchema = ""; + if (options.oldTokenBranch !== undefined) { + originalSchema = white(`\n${options.oldTokenBranch} | `); + } else if (options.oldTokenVersion !== undefined) { + originalSchema = white(`\n${options.oldTokenVersion} | `); } - if ( - options.oldTokenVersion !== undefined && - options.newTokenVersion !== undefined - ) { - log( - white(`\n${options.oldTokenVersion} | `) + - yellow(`${options.newTokenVersion}`), - ); + if (options.newTokenBranch !== undefined) { + updatedSchema = yellow(`${options.newTokenBranch}`); + } else if (options.newTokenVersion !== undefined) { + updatedSchema = yellow(`${options.newTokenVersion}`); + } + if (originalSchema !== "" && updatedSchema !== "") { + log(`${originalSchema}${updatedSchema}`); } log( white( diff --git a/tools/diff-generator/test/fileImport.test.js b/tools/diff-generator/test/fileImport.test.js index 5ad2ecb6..020cd56f 100644 --- a/tools/diff-generator/test/fileImport.test.js +++ b/tools/diff-generator/test/fileImport.test.js @@ -124,3 +124,30 @@ test("checking cli output for two branches (shirlsli/diff-generator-cli and shir } }); }); + +test("checking cli output between a release and a branch (@adobe/spectrum-tokens@12.26.0 and shirlsli/file-import-tests) for renamed, deprecated, added, deleted, and updated tokens", async (t) => { + t.plan(1); + return new Promise((resolve, reject) => { + try { + nixt() + .expect(async () => { + try { + const expectedFileName = `${path}${outputPath}expected-release-branch-compare.txt`; + await access(expectedFileName); + const expected = await readFile(expectedFileName, { + encoding: "utf8", + }); + t.snapshot(expected.trim()); + } catch (error) { + reject(error); + } + }) + .run( + "pnpm tdiff report -otv @adobe/spectrum-tokens@12.26.0 -ntb shirlsli/file-import-tests", + ) + .end(resolve); + } catch (error) { + reject(error); + } + }); +}); diff --git a/tools/diff-generator/test/snapshots/fileImport.test.js.md b/tools/diff-generator/test/snapshots/fileImport.test.js.md index db9600f8..cdfd736f 100644 --- a/tools/diff-generator/test/snapshots/fileImport.test.js.md +++ b/tools/diff-generator/test/snapshots/fileImport.test.js.md @@ -187,3 +187,128 @@ Generated by [AVA](https://avajs.dev). sets.light.value␊ ␊ informative-color-1000 -> some-value-was-changed` + +## checking cli output between a release and a branch (@adobe/spectrum-tokens@12.26.0 and shirlsli/file-import-tests) for renamed, deprecated, added, deleted, and updated tokens + +> Snapshot 1 + + `WARNING: Will either be inaccurate or will throw an error if used for releases before @adobe/spectrum-tokens@12.26.0!␊ + ␊ + ␊ + **Tokens Changed (17)**␊ + ␊ + @adobe/spectrum-tokens@12.26.0 | shirlsli/file-import-tests␊ + -------------------------------------------------------------------------------------------␊ + ␊ + ␊ + 📝 Renamed (3)␊ + ␊ + "blue-600" -> "i-like-dim-sum"␊ + ␊ + "red-400" -> "i-like-passion-fruit-green-tea"␊ + ␊ + "table-selected-row-background-opacity-non-emphasized" -> "i-like-sushi"␊ + ␊ + ␊ + ␊ + 🕒 Newly Deprecated (3)␊ + ␊ + "black-font-weight": "here is an another totally informative comment"␊ + ␊ + "font-size-800": "this is totally not not deprecated"␊ + ␊ + "informative-color-100": "here is a totally informative comment"␊ + ␊ + ␊ + ␊ + 🔼 Added (4)␊ + ␊ + "i-like-dosas"␊ + ␊ + "i-like-panang-curry"␊ + ␊ + "i-like-fried-chicken"␊ + ␊ + "i-like-frozen-yogurt"␊ + ␊ + ␊ + ␊ + 🔽 Deleted (2)␊ + ␊ + "spacing-1000"␊ + ␊ + "text-to-visual-100"␊ + ␊ + ␊ + ␊ + 🆕 Updated (5)␊ + ␊ + 🆕 Added Properties (1)␊ + ␊ + "accent-background-color-down"␊ + ␊ + sets.definite-a-real-property.$schema␊ + ␊ + "adobe link"␊ + ␊ + sets.definite-a-real-property.value␊ + ␊ + woohoo!␊ + ␊ + sets.definite-a-real-property.uuid␊ + ␊ + 7890␊ + ␊ + ␊ + ␊ + 🆕 Deleted Properties (2)␊ + ␊ + "neutral-subdued-background-color-hover"␊ + ␊ + sets.darkest.$schema␊ + ␊ + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json"␊ + ␊ + sets.darkest.value␊ + ␊ + gray-300␊ + ␊ + sets.darkest.uuid␊ + ␊ + 2d72c9fc-22d0-4e4d-9b00-fae4b30a47b5␊ + ␊ + "accent-background-color-hover"␊ + ␊ + sets.darkest.$schema␊ + ␊ + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json"␊ + ␊ + sets.darkest.value␊ + ␊ + accent-color-500␊ + ␊ + sets.darkest.uuid␊ + ␊ + 9e140a94-c11f-470b-b7af-49880e58d4ce␊ + ␊ + ␊ + ␊ + 🆕 Updated Properties (2)␊ + ␊ + "neutral-background-color-selected-down"␊ + ␊ + sets.express.value␊ + ␊ + gray-900 -> updated␊ + ␊ + "informative-background-color-hover"␊ + ␊ + $schema␊ + ␊ + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/color-set.json" -> ␊ + ␊ + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/i-like-koalas.json"␊ + ␊ + sets.light.value␊ + ␊ + informative-color-1000 -> some-value-was-changed` diff --git a/tools/diff-generator/test/snapshots/fileImport.test.js.snap b/tools/diff-generator/test/snapshots/fileImport.test.js.snap index 7a27e7bf9fc1e79f9fbf2cdd530fe13219ae5bbb..8f56869f025b9403e4a10dfd1c4f97e7a3ee2a5d 100644 GIT binary patch literal 1182 zcmV;P1Y!F@RzVr8gjfxCVMzq4EHI0{Tuo0@^>vPMo9&nkJH0vb5gWIs45yXTCWv zlUNx(aXG?lq|#qQX}VuMNeQXOv^!^ zS~CUIK-L-yGJ(R8s0y&82pu_yDKVDdJ_-|4-{r);Ei&fKgtWUq81{zudg0w5*xvrS zdIVpjsK+Fr8*XiH2Z2kaRZhvikV(SEq{*T;mT@JSC+8hJgZVop4Xmc29t;A7~P33m#Mgbfc{x0Dz8UN=}Fg-+2RmLNr*1Sp)D;u2H+vSg~+%`w&RcADxnJZzZn4jWs!9J$nE zHVDJ8afqiA&%9yB(iN!6k-0x!T#r92Y0OCMfS}wGM_=Ao4QZ$K&Q1kX2%VHHfpn$*s7+-PZ#*hB1E~{ZGxYM9 zfSW8M?VFk_jIt7T5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hql0As zT6}JhL+uipy7&K$Q)3>CVj7Q73 "i-like-dim-sum" + + "red-400" -> "i-like-passion-fruit-green-tea" + + "table-selected-row-background-opacity-non-emphasized" -> "i-like-sushi" + + + +🕒 Newly Deprecated (3) + + "black-font-weight": "here is an another totally informative comment" + + "font-size-800": "this is totally not not deprecated" + + "informative-color-100": "here is a totally informative comment" + + + +🔼 Added (4) + + "i-like-dosas" + + "i-like-panang-curry" + + "i-like-fried-chicken" + + "i-like-frozen-yogurt" + + + +🔽 Deleted (2) + + "spacing-1000" + + "text-to-visual-100" + + + +🆕 Updated (5) + + 🆕 Added Properties (1) + + "accent-background-color-down" + + sets.definite-a-real-property.$schema + + "adobe link" + + sets.definite-a-real-property.value + + woohoo! + + sets.definite-a-real-property.uuid + + 7890 + + + + 🆕 Deleted Properties (2) + + "neutral-subdued-background-color-hover" + + sets.darkest.$schema + + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json" + + sets.darkest.value + + gray-300 + + sets.darkest.uuid + + 2d72c9fc-22d0-4e4d-9b00-fae4b30a47b5 + + "accent-background-color-hover" + + sets.darkest.$schema + + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json" + + sets.darkest.value + + accent-color-500 + + sets.darkest.uuid + + 9e140a94-c11f-470b-b7af-49880e58d4ce + + + + 🆕 Updated Properties (2) + + "neutral-background-color-selected-down" + + sets.express.value + + gray-900 -> updated + + "informative-background-color-hover" + + $schema + + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/color-set.json" -> + + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/i-like-koalas.json" + + sets.light.value + + informative-color-1000 -> some-value-was-changed \ No newline at end of file diff --git a/tools/diff-generator/test/updatedToken.test.js b/tools/diff-generator/test/updatedToken.test.js index bf3fb987..867311f3 100644 --- a/tools/diff-generator/test/updatedToken.test.js +++ b/tools/diff-generator/test/updatedToken.test.js @@ -27,6 +27,7 @@ import severalRenamedUpdatedSetTokens from "./test-schemas/several-renamed-updat import basicSetTokenProperty from "./test-schemas/basic-set-token-property.json" with { type: "json" }; import addedPropertySetToken from "./test-schemas/added-property-set-token.json" with { type: "json" }; import addedDeletedPropertySetToken from "./test-schemas/added-deleted-set-token-property.json" with { type: "json" }; +import renamedAddedDeletedPropertySetToken from "./test-schemas/renamed-added-deleted-property-set-token.json" with { type: "json" }; const expected = { added: {}, @@ -283,6 +284,52 @@ const expectedAddedDeletedProperty = { updated: {}, }; +const expectedRenamedAddedDeletedProperty = { + added: { + "celery-background-color-default": { + sets: { + "added-property": { + $schema: { + "new-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/some-property-type.json", + path: "sets.added-property.$schema", + }, + uuid: { + "new-value": "1234", + path: "sets.added-property.uuid", + }, + value: { + "new-value": "{celery-1100}", + path: "sets.added-property.value", + }, + }, + }, + }, + }, + deleted: { + "celery-background-color-default": { + sets: { + darkest: { + $schema: { + "new-value": + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json", + path: "sets.darkest.$schema", + }, + uuid: { + "new-value": "a9ab7a59-9cab-47fb-876d-6f0af93dc5df", + path: "sets.darkest.uuid", + }, + value: { + "new-value": "{celery-800}", + path: "sets.darkest.value", + }, + }, + }, + }, + }, + updated: {}, +}; + test("basic test to check if updated token is detected", (t) => { const diff = detailedDiff(original, updatedToken); const renamed = detectRenamedTokens(original, updatedToken); @@ -437,3 +484,32 @@ test("testing adding and deleting a property to a token with sets", (t) => { expectedAddedDeletedProperty, ); }); + +// will a token's properties be renamed? if so, do we want to display that? ask tomorrow +test.skip("testing adding and deleting renamed properties to a token with sets", (t) => { + const diff = detailedDiff( + basicSetTokenProperty, + renamedAddedDeletedPropertySetToken, + ); + const renamed = detectRenamedTokens( + basicSetTokenProperty, + renamedAddedDeletedPropertySetToken, + ); + const deprecated = detectDeprecatedTokens(renamed, diff); + const added = detectNewTokens( + renamed, + deprecated, + diff.added, + basicSetTokenProperty, + ); + t.deepEqual( + detectUpdatedTokens( + renamed, + basicSetTokenProperty, + diff, + added, + deprecated, + ), + expectedRenamedAddedDeletedProperty, + ); +}); From 95dcc7841ba74e22c17de1c394db629bab259af6 Mon Sep 17 00:00:00 2001 From: Shirley Li Date: Thu, 27 Jun 2024 11:57:17 -0700 Subject: [PATCH 6/8] test: added tests to check token comparisons between branch and release and vice versa --- tools/diff-generator/src/lib/cli.js | 4 +- tools/diff-generator/test/fileImport.test.js | 27 ++++ .../test/snapshots/fileImport.test.js.md | 124 ++++++++++++++++++ .../test/snapshots/fileImport.test.js.snap | Bin 1182 -> 1343 bytes .../expected-branch-release-compare.txt | 119 +++++++++++++++++ .../diff-generator/test/updatedToken.test.js | 56 ++++---- 6 files changed, 300 insertions(+), 30 deletions(-) create mode 100644 tools/diff-generator/test/test-cli-outputs/expected-branch-release-compare.txt diff --git a/tools/diff-generator/src/lib/cli.js b/tools/diff-generator/src/lib/cli.js index 04145d3d..d8401586 100755 --- a/tools/diff-generator/src/lib/cli.js +++ b/tools/diff-generator/src/lib/cli.js @@ -163,7 +163,7 @@ async function cliCheck(originalFile, result, options) { ); if (Object.keys(result.reverted).length > 0 && !options.y) { printSection( - "\nalarm_clock", + "alarm_clock", 'Newly "Un-deprecated"', Object.keys(result.reverted).length, result.reverted, @@ -189,7 +189,7 @@ async function cliCheck(originalFile, result, options) { .then((response) => { if (response.confirmation) { console.clear(); - return printReport(originalFile, result, log); + return printReport(originalFile, result, log, options); } else { log( yellow( diff --git a/tools/diff-generator/test/fileImport.test.js b/tools/diff-generator/test/fileImport.test.js index 020cd56f..50dc1302 100644 --- a/tools/diff-generator/test/fileImport.test.js +++ b/tools/diff-generator/test/fileImport.test.js @@ -151,3 +151,30 @@ test("checking cli output between a release and a branch (@adobe/spectrum-tokens } }); }); + +test("checking cli output between a branch and a release (shirlsli/file-import-tests and @adobe/spectrum-tokens@12.26.0) for renamed, deprecated, added, deleted, and updated tokens", async (t) => { + t.plan(1); + return new Promise((resolve, reject) => { + try { + nixt() + .expect(async () => { + try { + const expectedFileName = `${path}${outputPath}expected-branch-release-compare.txt`; + await access(expectedFileName); + const expected = await readFile(expectedFileName, { + encoding: "utf8", + }); + t.snapshot(expected.trim()); + } catch (error) { + reject(error); + } + }) + .run( + "pnpm tdiff report -y -otb shirlsli/file-import-tests -ntv @adobe/spectrum-tokens@12.26.0", + ) + .end(resolve); + } catch (error) { + reject(error); + } + }); +}); diff --git a/tools/diff-generator/test/snapshots/fileImport.test.js.md b/tools/diff-generator/test/snapshots/fileImport.test.js.md index cdfd736f..b9e8c502 100644 --- a/tools/diff-generator/test/snapshots/fileImport.test.js.md +++ b/tools/diff-generator/test/snapshots/fileImport.test.js.md @@ -312,3 +312,127 @@ Generated by [AVA](https://avajs.dev). sets.light.value␊ ␊ informative-color-1000 -> some-value-was-changed` + +## checking cli output between a branch and a release (shirlsli/file-import-tests and @adobe/spectrum-tokens@12.26.0) for renamed, deprecated, added, deleted, and updated tokens + +> Snapshot 1 + + `WARNING: Will either be inaccurate or will throw an error if used for releases before @adobe/spectrum-tokens@12.26.0!␊ + ␊ + **Tokens Changed (17)**␊ + ␊ + shirlsli/file-import-tests | @adobe/spectrum-tokens@12.26.0␊ + -------------------------------------------------------------------------------------------␊ + ␊ + ␊ + 📝 Renamed (3)␊ + ␊ + "i-like-dim-sum" -> "blue-600"␊ + ␊ + "i-like-passion-fruit-green-tea" -> "red-400"␊ + ␊ + "i-like-sushi" -> "table-selected-row-background-opacity-non-emphasized"␊ + ␊ + ␊ + ␊ + ⏰ Newly "Un-deprecated" (3)␊ + ␊ + "black-font-weight"␊ + ␊ + "font-size-800"␊ + ␊ + "informative-color-100"␊ + ␊ + ␊ + ␊ + 🔼 Added (2)␊ + ␊ + "spacing-1000"␊ + ␊ + "text-to-visual-100"␊ + ␊ + ␊ + ␊ + 🔽 Deleted (4)␊ + ␊ + "i-like-dosas"␊ + ␊ + "i-like-panang-curry"␊ + ␊ + "i-like-fried-chicken"␊ + ␊ + "i-like-frozen-yogurt"␊ + ␊ + ␊ + ␊ + 🆕 Updated (5)␊ + ␊ + 🆕 Added Properties (2)␊ + ␊ + "neutral-subdued-background-color-hover"␊ + ␊ + sets.darkest.$schema␊ + ␊ + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json"␊ + ␊ + sets.darkest.value␊ + ␊ + gray-300␊ + ␊ + sets.darkest.uuid␊ + ␊ + 2d72c9fc-22d0-4e4d-9b00-fae4b30a47b5␊ + ␊ + "accent-background-color-hover"␊ + ␊ + sets.darkest.$schema␊ + ␊ + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json"␊ + ␊ + sets.darkest.value␊ + ␊ + accent-color-500␊ + ␊ + sets.darkest.uuid␊ + ␊ + 9e140a94-c11f-470b-b7af-49880e58d4ce␊ + ␊ + ␊ + ␊ + 🆕 Deleted Properties (1)␊ + ␊ + "accent-background-color-down"␊ + ␊ + sets.definite-a-real-property.$schema␊ + ␊ + "adobe link"␊ + ␊ + sets.definite-a-real-property.value␊ + ␊ + woohoo!␊ + ␊ + sets.definite-a-real-property.uuid␊ + ␊ + 7890␊ + ␊ + ␊ + ␊ + 🆕 Updated Properties (2)␊ + ␊ + "neutral-background-color-selected-down"␊ + ␊ + sets.express.value␊ + ␊ + updated -> gray-900␊ + ␊ + "informative-background-color-hover"␊ + ␊ + $schema␊ + ␊ + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/i-like-koalas.json" -> ␊ + ␊ + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/color-set.json"␊ + ␊ + sets.light.value␊ + ␊ + some-value-was-changed -> informative-color-1000` diff --git a/tools/diff-generator/test/snapshots/fileImport.test.js.snap b/tools/diff-generator/test/snapshots/fileImport.test.js.snap index 8f56869f025b9403e4a10dfd1c4f97e7a3ee2a5d..120e2ab8162c8344f1903e6f2c45af0aee2923a3 100644 GIT binary patch literal 1343 zcmV-F1;F}2RzV{IB(vypxF2Rh*-9(GuSY$Vi>ghC<_aiWbQp*F;gH3Di z3KAP>XMcFfIXL)s{lSN8AFpM{`bTS@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XTCWv zlUNx(aXG?lq|#qQX}VuMNeQXOv^!^ zS~CUIK-L-yGJ(R8s0y&82pu_yDKVDdJ_-|4-{r);Ei&fKgtWUq81{zudg0w5*xvrS zdIVpjsK+Fr8*XiH2Z2kaRZhvikV(SEq{*T;mT@JSC+8hJgZVop4Xmc29t;A7~P33m#Mgbfc{x0Dz8UN=}Fg-+2RmLNr*1Sp)D;u2H+vSg~+%`w&RcADxnJZzZn4jWs!9J$nE zHVDJ8afqiA&%9yB(iN!6k-0x!T#r92Y0OCMfS}wGM_=Ao4QZ$K&Q1kX2%VHHfpn$*s7+-PZ#*hB1E~{ZGxYM9 zfSW8M?VFk_jIt7T5QZg+Po*nS+Ns+3>UZkvwkw}vvii&&)CluBuK4^rI5dL)*i`EI zKR<_WnqA!8tLIk_>y>< zSAUtG<>dOPB)Z;r&aBX-`SJ?##ujI6Hw-VDa-OWA*dOvy!r5>rLKaaZ*eDJ|mLNs( zZivx-ymzI2ZV^Mx66(75{tZ(j8bl$EBE|=Ughl&d%;J4aSTs5~2x;#?M4T3F*Y3_M zYLPQf z@~B$H-^#P3V$+$7ST%!9(J@|Ukv81DS{3eM@>3!W*oK}ecVQFupnG}rx#qO@(Nfym wxOr*s3brnddh2AjPIl{Lw|vO0lih90E$d{rPIl{LcTLIeAJVm{V$&G_05h#T0RR91 diff --git a/tools/diff-generator/test/test-cli-outputs/expected-branch-release-compare.txt b/tools/diff-generator/test/test-cli-outputs/expected-branch-release-compare.txt new file mode 100644 index 00000000..32a9f58d --- /dev/null +++ b/tools/diff-generator/test/test-cli-outputs/expected-branch-release-compare.txt @@ -0,0 +1,119 @@ +WARNING: Will either be inaccurate or will throw an error if used for releases before @adobe/spectrum-tokens@12.26.0! + +**Tokens Changed (17)** + +shirlsli/file-import-tests | @adobe/spectrum-tokens@12.26.0 +------------------------------------------------------------------------------------------- + + +📝 Renamed (3) + + "i-like-dim-sum" -> "blue-600" + + "i-like-passion-fruit-green-tea" -> "red-400" + + "i-like-sushi" -> "table-selected-row-background-opacity-non-emphasized" + + + +⏰ Newly "Un-deprecated" (3) + + "black-font-weight" + + "font-size-800" + + "informative-color-100" + + + +🔼 Added (2) + + "spacing-1000" + + "text-to-visual-100" + + + +🔽 Deleted (4) + + "i-like-dosas" + + "i-like-panang-curry" + + "i-like-fried-chicken" + + "i-like-frozen-yogurt" + + + +🆕 Updated (5) + + 🆕 Added Properties (2) + + "neutral-subdued-background-color-hover" + + sets.darkest.$schema + + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json" + + sets.darkest.value + + gray-300 + + sets.darkest.uuid + + 2d72c9fc-22d0-4e4d-9b00-fae4b30a47b5 + + "accent-background-color-hover" + + sets.darkest.$schema + + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json" + + sets.darkest.value + + accent-color-500 + + sets.darkest.uuid + + 9e140a94-c11f-470b-b7af-49880e58d4ce + + + + 🆕 Deleted Properties (1) + + "accent-background-color-down" + + sets.definite-a-real-property.$schema + + "adobe link" + + sets.definite-a-real-property.value + + woohoo! + + sets.definite-a-real-property.uuid + + 7890 + + + + 🆕 Updated Properties (2) + + "neutral-background-color-selected-down" + + sets.express.value + + updated -> gray-900 + + "informative-background-color-hover" + + $schema + + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/i-like-koalas.json" -> + + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/color-set.json" + + sets.light.value + + some-value-was-changed -> informative-color-1000 \ No newline at end of file diff --git a/tools/diff-generator/test/updatedToken.test.js b/tools/diff-generator/test/updatedToken.test.js index 867311f3..f3fd389c 100644 --- a/tools/diff-generator/test/updatedToken.test.js +++ b/tools/diff-generator/test/updatedToken.test.js @@ -27,7 +27,7 @@ import severalRenamedUpdatedSetTokens from "./test-schemas/several-renamed-updat import basicSetTokenProperty from "./test-schemas/basic-set-token-property.json" with { type: "json" }; import addedPropertySetToken from "./test-schemas/added-property-set-token.json" with { type: "json" }; import addedDeletedPropertySetToken from "./test-schemas/added-deleted-set-token-property.json" with { type: "json" }; -import renamedAddedDeletedPropertySetToken from "./test-schemas/renamed-added-deleted-property-set-token.json" with { type: "json" }; +// import renamedAddedDeletedPropertySetToken from "./test-schemas/renamed-added-deleted-property-set-token.json" with { type: "json" }; const expected = { added: {}, @@ -486,30 +486,30 @@ test("testing adding and deleting a property to a token with sets", (t) => { }); // will a token's properties be renamed? if so, do we want to display that? ask tomorrow -test.skip("testing adding and deleting renamed properties to a token with sets", (t) => { - const diff = detailedDiff( - basicSetTokenProperty, - renamedAddedDeletedPropertySetToken, - ); - const renamed = detectRenamedTokens( - basicSetTokenProperty, - renamedAddedDeletedPropertySetToken, - ); - const deprecated = detectDeprecatedTokens(renamed, diff); - const added = detectNewTokens( - renamed, - deprecated, - diff.added, - basicSetTokenProperty, - ); - t.deepEqual( - detectUpdatedTokens( - renamed, - basicSetTokenProperty, - diff, - added, - deprecated, - ), - expectedRenamedAddedDeletedProperty, - ); -}); +// test.skip("testing adding and deleting renamed properties to a token with sets", (t) => { +// const diff = detailedDiff( +// basicSetTokenProperty, +// renamedAddedDeletedPropertySetToken, +// ); +// const renamed = detectRenamedTokens( +// basicSetTokenProperty, +// renamedAddedDeletedPropertySetToken, +// ); +// const deprecated = detectDeprecatedTokens(renamed, diff); +// const added = detectNewTokens( +// renamed, +// deprecated, +// diff.added, +// basicSetTokenProperty, +// ); +// t.deepEqual( +// detectUpdatedTokens( +// renamed, +// basicSetTokenProperty, +// diff, +// added, +// deprecated, +// ), +// expectedRenamedAddedDeletedProperty, +// ); +// }); From 16cbd7a4ddc40688d9297bf079e55f50db9e9df5 Mon Sep 17 00:00:00 2001 From: Shirley Li Date: Fri, 28 Jun 2024 17:02:23 -0700 Subject: [PATCH 7/8] feat: detects renamed keys in tokens --- tools/diff-generator/src/lib/index.js | 4 +- .../src/lib/updated-token-detection.js | 67 ++++++++++++++++-- ...amed-added-deleted-property-set-token.json | 28 ++++++++ tools/diff-generator/test/tokenDiff.test.js | 9 +++ .../diff-generator/test/updatedToken.test.js | 69 +++++++++++-------- 5 files changed, 143 insertions(+), 34 deletions(-) create mode 100644 tools/diff-generator/test/test-schemas/renamed-added-deleted-property-set-token.json diff --git a/tools/diff-generator/src/lib/index.js b/tools/diff-generator/src/lib/index.js index a5fee800..2b57f585 100644 --- a/tools/diff-generator/src/lib/index.js +++ b/tools/diff-generator/src/lib/index.js @@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ import { detailedDiff } from "deep-object-diff"; -import checkIfRenamed from "./renamed-token-detection.js"; +import detectRenamedTokens from "./renamed-token-detection.js"; import detectNewTokens from "./added-token-detection.js"; import detectDeletedTokens from "./deleted-token-detection.js"; import detectDeprecatedTokens from "./deprecated-token-detection.js"; @@ -24,7 +24,7 @@ import detectUpdatedTokens from "./updated-token-detection.js"; */ export default function tokenDiff(original, updated) { const changes = detailedDiff(original, updated); - const renamedTokens = checkIfRenamed(original, changes.added); + const renamedTokens = detectRenamedTokens(original, changes.added); const deprecatedTokens = detectDeprecatedTokens(renamedTokens, changes); const newTokens = detectNewTokens( renamedTokens, diff --git a/tools/diff-generator/src/lib/updated-token-detection.js b/tools/diff-generator/src/lib/updated-token-detection.js index 4e344e45..0442f994 100644 --- a/tools/diff-generator/src/lib/updated-token-detection.js +++ b/tools/diff-generator/src/lib/updated-token-detection.js @@ -26,6 +26,7 @@ export default function detectUpdatedTokens( deprecatedTokens, ) { const updatedTokens = { + renamed: {}, added: {}, deleted: {}, updated: { ...changes.updated }, @@ -45,7 +46,14 @@ export default function detectUpdatedTokens( deprecatedTokens.deprecated[token] === undefined ) { updatedTokens.added[token] = changes.added[token]; - formatJSON(updatedTokens.added[token], token, original, renamed, false); + formatJSON( + updatedTokens, + updatedTokens.added[token], + token, + original, + renamed, + false, + ); } }); Object.keys(changes.deleted).forEach((token) => { @@ -56,11 +64,25 @@ export default function detectUpdatedTokens( original[token], ).updated; updatedTokens.deleted[token] = tokenDiff; - formatJSON(updatedTokens.deleted[token], token, original, renamed, false); + formatJSON( + updatedTokens, + updatedTokens.deleted[token], + token, + original, + renamed, + false, + ); } }); Object.keys(updatedTokens.updated).forEach((token) => { - formatJSON(updatedTokens.updated[token], token, original, renamed, true); + formatJSON( + updatedTokens, + updatedTokens.updated[token], + token, + original, + renamed, + true, + ); }); return updatedTokens; } @@ -73,9 +95,17 @@ export default function detectUpdatedTokens( * @param {object} renamed - a JSON object containing the renamed tokens * @param {boolean} update - a boolean indicating whether token property is added, deleted, or updated */ -function formatJSON(tokens, properties, original, renamed, update) { +function formatJSON( + updatedTokens, + tokens, + properties, + original, + renamed, + update, +) { if (renamed[properties] !== undefined) { includeOldProperties( + updatedTokens, tokens, tokens, properties, @@ -86,6 +116,7 @@ function formatJSON(tokens, properties, original, renamed, update) { ); } else { includeOldProperties( + updatedTokens, tokens, tokens, properties, @@ -107,6 +138,7 @@ function formatJSON(tokens, properties, original, renamed, update) { * @param {object} renamed - the renamed tokens */ function includeOldProperties( + updatedTokens, token, curTokenLevel, properties, @@ -158,7 +190,34 @@ function includeOldProperties( curTokenLevel = curTokenLevel[key] === undefined ? token : curTokenLevel[key]; }); + if (!update) { + Object.keys(curOriginalLevel).forEach((originalProp) => { + Object.keys(curTokenLevel).forEach((curProp) => { + if ( + curTokenLevel[curProp] !== undefined && + typeof curOriginalLevel[originalProp] !== "string" && + typeof curTokenLevel[curProp] !== "string" && + curOriginalLevel[originalProp].uuid !== undefined && + curTokenLevel[curProp].uuid !== undefined && + curOriginalLevel[originalProp].uuid === + curTokenLevel[curProp].uuid && + originalProp !== curProp + ) { + updatedTokens.renamed[curProp] = { + "old-name": originalProp, + }; + delete curTokenLevel[curProp]; + } + Object.keys(updatedTokens["renamed"]).forEach((prop) => { + if (updatedTokens["renamed"][prop]["old-name"] === curProp) { + delete curTokenLevel[curProp]; + } + }); + }); + }); + } includeOldProperties( + updatedTokens, token, curTokenLevel, nextProperties, diff --git a/tools/diff-generator/test/test-schemas/renamed-added-deleted-property-set-token.json b/tools/diff-generator/test/test-schemas/renamed-added-deleted-property-set-token.json new file mode 100644 index 00000000..2567ba9a --- /dev/null +++ b/tools/diff-generator/test/test-schemas/renamed-added-deleted-property-set-token.json @@ -0,0 +1,28 @@ +{ + "celery-background-color-default": { + "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/color-set.json", + "sets": { + "light": { + "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json", + "value": "{celery-600}", + "uuid": "d4fd682d-4bef-4a92-bf14-90ce02b534e6" + }, + "dark": { + "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json", + "value": "{celery-800}", + "uuid": "87f5b73a-19b1-40f7-991b-0d4b6bfc4a99" + }, + "i-like-waffle-fries": { + "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json", + "value": "{celery-1100}", + "uuid": "3e44abd8-ea12-4c0a-9007-4a6edaa3b962" + }, + "added-property": { + "$schema": "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/some-property-type.json", + "value": "{celery-1100}", + "uuid": "1234" + } + }, + "uuid": "2c159320-bf17-48b6-9d09-b2d037f937d1" + } +} diff --git a/tools/diff-generator/test/tokenDiff.test.js b/tools/diff-generator/test/tokenDiff.test.js index 7c54cf74..2b540984 100644 --- a/tools/diff-generator/test/tokenDiff.test.js +++ b/tools/diff-generator/test/tokenDiff.test.js @@ -38,6 +38,7 @@ const expectedRenamed = { updated: { added: {}, deleted: {}, + renamed: {}, updated: {}, }, }; @@ -70,6 +71,7 @@ const expectedManyAddedRenamed = { updated: { added: {}, deleted: {}, + renamed: {}, updated: {}, }, }; @@ -122,6 +124,7 @@ const expectedRenamedAddedDeleted = { updated: { added: {}, deleted: {}, + renamed: {}, updated: {}, }, }; @@ -162,6 +165,7 @@ const expectedSeveralRenamedAddedDeleted = { updated: { added: {}, deleted: {}, + renamed: {}, updated: {}, }, }; @@ -213,6 +217,7 @@ const expectedSeveralRADDep = { updated: { added: {}, deleted: {}, + renamed: {}, updated: {}, }, }; @@ -262,6 +267,7 @@ const expectedSeveralRADDepU = { updated: { added: {}, deleted: {}, + renamed: {}, updated: { "thumbnail-border-color": { $schema: { @@ -370,6 +376,7 @@ const expectedSeveralRADDepURev = { updated: { added: {}, deleted: {}, + renamed: {}, updated: { "thumbnail-border-color": { $schema: { @@ -457,6 +464,7 @@ const expectedAddedProperty = { }, }, deleted: {}, + renamed: {}, updated: {}, }, }; @@ -490,6 +498,7 @@ const expectedDeletedProperty = { }, }, }, + renamed: {}, updated: {}, }, }; diff --git a/tools/diff-generator/test/updatedToken.test.js b/tools/diff-generator/test/updatedToken.test.js index 0d04b147..8b1887e7 100644 --- a/tools/diff-generator/test/updatedToken.test.js +++ b/tools/diff-generator/test/updatedToken.test.js @@ -27,11 +27,12 @@ import severalRenamedUpdatedSetTokens from "./test-schemas/several-renamed-updat import basicSetTokenProperty from "./test-schemas/basic-set-token-property.json" with { type: "json" }; import addedPropertySetToken from "./test-schemas/added-property-set-token.json" with { type: "json" }; import addedDeletedPropertySetToken from "./test-schemas/added-deleted-set-token-property.json" with { type: "json" }; -// import renamedAddedDeletedPropertySetToken from "./test-schemas/renamed-added-deleted-property-set-token.json" with { type: "json" }; +import renamedAddedDeletedPropertySetToken from "./test-schemas/renamed-added-deleted-property-set-token.json" with { type: "json" }; const expected = { added: {}, deleted: {}, + renamed: {}, updated: { "swatch-border-color": { value: { @@ -53,6 +54,7 @@ const expected = { const expectedUpdatedSeveralProperties = { added: {}, deleted: {}, + renamed: {}, updated: { "swatch-border-color": { $schema: { @@ -86,6 +88,7 @@ const expectedUpdatedSeveralProperties = { const expectedUpdatedSet = { added: {}, deleted: {}, + renamed: {}, updated: { "overlay-opacity": { sets: { @@ -151,6 +154,7 @@ const expectedUpdatedSet = { const expectedSeveralUpdatedSet = { added: {}, deleted: {}, + renamed: {}, updated: { "help-text-top-to-workflow-icon-medium": { $schema: { @@ -220,6 +224,7 @@ const expectedSeveralUpdatedSet = { const expectedUpdatedSetWithRename = { added: {}, deleted: {}, + renamed: {}, updated: { "help-text-top-to-workflow-icon-medium": { sets: { @@ -306,6 +311,7 @@ const expectedAddedProperty = { }, }, deleted: {}, + renamed: {}, updated: {}, }; @@ -332,6 +338,7 @@ const expectedDeletedProperty = { }, }, }, + renamed: {}, updated: {}, }; @@ -378,6 +385,7 @@ const expectedAddedDeletedProperty = { }, }, }, + renamed: {}, updated: {}, }; @@ -424,6 +432,11 @@ const expectedRenamedAddedDeletedProperty = { }, }, }, + renamed: { + "i-like-waffle-fries": { + "old-name": "wireframe", + }, + }, updated: {}, }; @@ -583,30 +596,30 @@ test("testing adding and deleting a property to a token with sets", (t) => { }); // will a token's properties be renamed? if so, do we want to display that? ask tomorrow -// test.skip("testing adding and deleting renamed properties to a token with sets", (t) => { -// const diff = detailedDiff( -// basicSetTokenProperty, -// renamedAddedDeletedPropertySetToken, -// ); -// const renamed = detectRenamedTokens( -// basicSetTokenProperty, -// renamedAddedDeletedPropertySetToken, -// ); -// const deprecated = detectDeprecatedTokens(renamed, diff); -// const added = detectNewTokens( -// renamed, -// deprecated, -// diff.added, -// basicSetTokenProperty, -// ); -// t.deepEqual( -// detectUpdatedTokens( -// renamed, -// basicSetTokenProperty, -// diff, -// added, -// deprecated, -// ), -// expectedRenamedAddedDeletedProperty, -// ); -// }); +test("testing adding and deleting renamed properties to a token with sets", (t) => { + const diff = detailedDiff( + basicSetTokenProperty, + renamedAddedDeletedPropertySetToken, + ); + const renamed = detectRenamedTokens( + basicSetTokenProperty, + renamedAddedDeletedPropertySetToken, + ); + const deprecated = detectDeprecatedTokens(renamed, diff); + const added = detectNewTokens( + renamed, + deprecated, + diff.added, + basicSetTokenProperty, + ); + t.deepEqual( + detectUpdatedTokens( + renamed, + basicSetTokenProperty, + diff, + added, + deprecated, + ), + expectedRenamedAddedDeletedProperty, + ); +}); From ad8ee39d081d9efa1c6f1918ef63b1662e404ca2 Mon Sep 17 00:00:00 2001 From: Shirley Li Date: Mon, 8 Jul 2024 08:28:35 -0700 Subject: [PATCH 8/8] feat: prints out renamed properties in cli --- tools/diff-generator/src/lib/cli.js | 61 +++++++++--------- tools/diff-generator/test/cli.test.js | 27 ++++++++ .../test/snapshots/cli.test.js.md | 53 +++++++++++++++ .../test/snapshots/cli.test.js.snap | Bin 1250 -> 1387 bytes .../expected-renamed-property-token.txt | 48 ++++++++++++++ 5 files changed, 160 insertions(+), 29 deletions(-) create mode 100644 tools/diff-generator/test/test-cli-outputs/expected-renamed-property-token.txt diff --git a/tools/diff-generator/src/lib/cli.js b/tools/diff-generator/src/lib/cli.js index d8401586..4b7d9a1a 100755 --- a/tools/diff-generator/src/lib/cli.js +++ b/tools/diff-generator/src/lib/cli.js @@ -103,10 +103,10 @@ function indent(text, amount) { * @param {object} token - the current token * @param {object} log - the console.log object being used */ -const printStyleRenamed = (result, token, log) => { +const printStyleRenamed = (result, token, log, i) => { const str = white(`"${result[token]["old-name"]}" -> `) + yellow(`"${token}"`); - log(indent(str, 1)); + log(indent(str, i)); }; /** @@ -115,13 +115,13 @@ const printStyleRenamed = (result, token, log) => { * @param {object} token - the current token * @param {object} log - the console.log object being used */ -const printStyleDeprecated = (result, token, log) => { +const printStyleDeprecated = (result, token, log, i) => { log( indent( yellow(`"${token}"`) + white(": ") + yellow(`"${result[token]["deprecated_comment"]}"`), - 1, + i, ), ); }; @@ -142,8 +142,8 @@ const printStyleColored = (token, color, log) => { * @param {object} token - the current token * @param {object} log - the console.log object being used */ -const printStyleUpdated = (result, token, log) => { - log(indent(yellow(`"${token}"`), 2)); +const printStyleUpdated = (result, token, log, i) => { + log(indent(yellow(`"${token}"`), i)); printNestedChanges(result[token], log); }; @@ -223,7 +223,8 @@ function printReport(original, result, log, options) { Object.keys(result.deleted).length + Object.keys(result.updated.added).length + Object.keys(result.updated.deleted).length + - Object.keys(result.updated.updated).length; + Object.keys(result.updated.updated).length + + Object.keys(result.updated.renamed).length; log(white("\n**Tokens Changed (" + totalTokens + ")**")); let originalSchema = ""; let updatedSchema = ""; @@ -253,6 +254,7 @@ function printReport(original, result, log, options) { result.renamed, log, printStyleRenamed, + 1, ); } if (Object.keys(result.deprecated).length > 0) { @@ -263,6 +265,7 @@ function printReport(original, result, log, options) { result.deprecated, log, printStyleDeprecated, + 1, ); } if (Object.keys(result.reverted).length > 0) { @@ -301,9 +304,21 @@ function printReport(original, result, log, options) { const totalUpdatedTokens = Object.keys(result.updated.added).length + Object.keys(result.updated.deleted).length + - Object.keys(result.updated.updated).length; + Object.keys(result.updated.updated).length + + Object.keys(result.updated.renamed).length; if (totalUpdatedTokens > 0) { printTitle("new", "Updated", totalUpdatedTokens, log); + if (Object.keys(result.updated.renamed).length > 0) { + printSection( + "new", + "Renamed Properties", + Object.keys(result.updated.renamed).length, + result.updated.renamed, + log, + printStyleRenamed, + 2, + ); + } if (Object.keys(result.updated.added).length > 0) { printSection( "new", @@ -312,9 +327,7 @@ function printReport(original, result, log, options) { result.updated.added, log, printStyleUpdated, - white, - result.renamed, - original, + 2, ); } if (Object.keys(result.updated.deleted).length > 0) { @@ -325,9 +338,7 @@ function printReport(original, result, log, options) { result.updated.deleted, log, printStyleUpdated, - white, - result.renamed, - original, + 2, ); } if (Object.keys(result.updated.updated).length > 0) { @@ -338,9 +349,7 @@ function printReport(original, result, log, options) { result.updated.updated, log, printStyleUpdated, - white, - result.renamed, - original, + 2, ); } } @@ -382,8 +391,6 @@ function printTitle(emojiName, title, numTokens, log, amount) { * @param {object} log - the console.log object being used * @param {object} func - the styling function that will be used * @param {object} color - the intended text color - * @param {object} renamed - the renamed tokens - * @param {object} original - the original token (json object) */ function printSection( emojiName, @@ -392,27 +399,23 @@ function printSection( result, log, func, - color, - renamed, - original, + colorOrIndent, ) { - const textColor = color || white; if ( title === "Added Properties" || title === "Deleted Properties" || - title === "Updated Properties" + title === "Updated Properties" || + title === "Renamed Properties" ) { printTitle(emojiName, title, numTokens, log, 1); } else { printTitle(emojiName, title, numTokens, log, 0); } Object.keys(result).forEach((token) => { - if (textColor != white) { - func(token, textColor, log); - } else if (original !== undefined && renamed !== undefined) { - func(result, token, log); + if (typeof colorOrIndent !== "number") { + func(token, colorOrIndent, log); } else { - func(result, token, log); + func(result, token, log, colorOrIndent); } }); log("\n"); diff --git a/tools/diff-generator/test/cli.test.js b/tools/diff-generator/test/cli.test.js index 9f61671d..0113443a 100644 --- a/tools/diff-generator/test/cli.test.js +++ b/tools/diff-generator/test/cli.test.js @@ -225,3 +225,30 @@ test("check cli output for deleted non-schema property", async (t) => { } }); }); + +test("check cli output for renamed property", async (t) => { + t.plan(1); + return new Promise((resolve, reject) => { + try { + nixt() + .expect(async () => { + try { + const expectedFileName = `${path}${outputPath}expected-renamed-property-token.txt`; + await access(expectedFileName); + const expected = await readFile(expectedFileName, { + encoding: "utf8", + }); + t.snapshot(expected.trim()); + } catch (error) { + reject(error); + } + }) + .run( + `pnpm tdiff report -t ${path}${schemaPath}basic-set-token-property.json ${path}${schemaPath}renamed-added-deleted-property-set-token.json`, + ) + .end(resolve); + } catch (error) { + reject(error); + } + }); +}); diff --git a/tools/diff-generator/test/snapshots/cli.test.js.md b/tools/diff-generator/test/snapshots/cli.test.js.md index 92d5ea27..6f4ae446 100644 --- a/tools/diff-generator/test/snapshots/cli.test.js.md +++ b/tools/diff-generator/test/snapshots/cli.test.js.md @@ -286,3 +286,56 @@ Generated by [AVA](https://avajs.dev). sets.some-new-property.value␊ ␊ 0.8` + +## check cli output for renamed property + +> Snapshot 1 + + `WARNING: Will either be inaccurate or will throw an error if used for releases before @adobe/spectrum-tokens@12.26.0!␊ + ␊ + ␊ + **Tokens Changed (3)**␊ + -------------------------------------------------------------------------------------------␊ + ␊ + ␊ + 🆕 Updated (3)␊ + ␊ + 🆕 Renamed Properties (1)␊ + ␊ + "wireframe" -> "i-like-waffle-fries"␊ + ␊ + ␊ + ␊ + 🆕 Added Properties (1)␊ + ␊ + "celery-background-color-default"␊ + ␊ + sets.added-property.$schema␊ + ␊ + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/some-property-type.json"␊ + ␊ + sets.added-property.value␊ + ␊ + celery-1100␊ + ␊ + sets.added-property.uuid␊ + ␊ + 1234␊ + ␊ + ␊ + ␊ + 🆕 Deleted Properties (1)␊ + ␊ + "celery-background-color-default"␊ + ␊ + sets.darkest.$schema␊ + ␊ + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json"␊ + ␊ + sets.darkest.value␊ + ␊ + celery-800␊ + ␊ + sets.darkest.uuid␊ + ␊ + a9ab7a59-9cab-47fb-876d-6f0af93dc5df` diff --git a/tools/diff-generator/test/snapshots/cli.test.js.snap b/tools/diff-generator/test/snapshots/cli.test.js.snap index 5e8cbf91102523a1cbac3ac1ac6bae8ba469c47a..87b530c6b18a8ee0f6ba80cd96d147c0772887cc 100644 GIT binary patch literal 1387 zcmV-x1(fF00000000B+Sj~$ZMHEl6$imz_daDcy*(Gnjc6N6r2T4dkyaWk`;PG|U z>+N!?tJEORnW6fq&gP&$o?i;Q=lKNSK!ezbXI zE_hGjUAL zO&pWL1&(Bt3OEmD;GWjH4dl|e7{0U-C%Xb4j8jcydZ=6b_T zkAWg^q=*$cN0;>f48u+ zcKCrc30W`6E#Bv1qcjdQN>#^4`JOTMw&M}SSUJgE?S0~|b-N}Z?M!Mpb@Ht5a1)=* z{BFU)b@RXAX9>A3Dv7T1u`@bH_lst)jR%BhFzEF%8}jGfUhgDv#*y4=@==9+d`#Y$zH`m13UU)CMw9k+ z)>Z0^ec_Sn=?Otaj#sNsRZ5ylQ5PTve8_|02u3*W!EmoHV7wb}5Tnr`z+Qj2KL|3x zGGv&OGdd*8cwY0FGHM||PrM_esS5ceAg-`;L7d5&8WS0FxpJey>Bu>04~NpFs0uk5 zZJ4@bV>~!37*>I~>u3xEgMQ^Cq zxc+gC7 zi)RMzJLeMa)g`K22_jMnc)IVwn*_Xpsj-t#nJGwaG{hui8rRk$MX}Mq4L3UV5T{`% zwaZ51+VW8H&u6WEuUB5EED7Zm=h3GQ^2rZ`@sN$&K=-{xP-qXRT|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!E;7vX?E<0G3@U&VI8gwYcmkMSYW^F1on%!fql7Y_Em-U MAF$_qSU48|0L)HtUjP6A diff --git a/tools/diff-generator/test/test-cli-outputs/expected-renamed-property-token.txt b/tools/diff-generator/test/test-cli-outputs/expected-renamed-property-token.txt new file mode 100644 index 00000000..16654176 --- /dev/null +++ b/tools/diff-generator/test/test-cli-outputs/expected-renamed-property-token.txt @@ -0,0 +1,48 @@ +WARNING: Will either be inaccurate or will throw an error if used for releases before @adobe/spectrum-tokens@12.26.0! + + +**Tokens Changed (3)** +------------------------------------------------------------------------------------------- + + +🆕 Updated (3) + + 🆕 Renamed Properties (1) + + "wireframe" -> "i-like-waffle-fries" + + + + 🆕 Added Properties (1) + + "celery-background-color-default" + + sets.added-property.$schema + + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/some-property-type.json" + + sets.added-property.value + + celery-1100 + + sets.added-property.uuid + + 1234 + + + + 🆕 Deleted Properties (1) + + "celery-background-color-default" + + sets.darkest.$schema + + "https://opensource.adobe.com/spectrum-tokens/schemas/token-types/alias.json" + + sets.darkest.value + + celery-800 + + sets.darkest.uuid + + a9ab7a59-9cab-47fb-876d-6f0af93dc5df \ No newline at end of file