@adobe/spectrum-tokens 13.0.0-beta.8 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +9255 -0
  2. package/README.md +4 -0
  3. package/dist/json/drover.json +954 -250
  4. package/dist/json/variables.json +16755 -7175
  5. package/index.js +60 -0
  6. package/moon.yml +2 -2
  7. package/package.json +13 -8
  8. package/schemas/token-types/alias.json +1 -0
  9. package/schemas/token-types/color-set.json +4 -3
  10. package/schemas/token-types/color.json +1 -0
  11. package/schemas/token-types/dimension.json +1 -0
  12. package/schemas/token-types/font-family.json +1 -0
  13. package/schemas/token-types/font-size.json +1 -0
  14. package/schemas/token-types/font-style.json +1 -0
  15. package/schemas/token-types/font-weight.json +1 -0
  16. package/schemas/token-types/gradient-stop.json +27 -0
  17. package/schemas/token-types/multiplier.json +2 -1
  18. package/schemas/token-types/opacity.json +1 -0
  19. package/schemas/token-types/scale-set.json +7 -0
  20. package/schemas/token-types/system-set.json +83 -0
  21. package/schemas/token-types/text-align.json +27 -0
  22. package/schemas/token-types/text-transform.json +1 -0
  23. package/schemas/token-types/token.json +14 -2
  24. package/src/color-aliases.json +669 -97
  25. package/src/color-component.json +261 -15
  26. package/src/color-palette.json +736 -347
  27. package/src/icons.json +974 -20
  28. package/src/layout-component.json +4332 -896
  29. package/src/layout.json +450 -195
  30. package/src/semantic-color-palette.json +125 -1
  31. package/src/typography.json +299 -90
  32. package/tasks/addIds.js +7 -9
  33. package/tasks/addPrivate.js +22 -0
  34. package/tasks/buildManifest.js +1 -1
  35. package/tasks/buildSpectrumTokens.js +1 -1
  36. package/tasks/deprecateExpress.js +1 -1
  37. package/tasks/diff.js +19 -5
  38. package/tasks/lib/augmentExpressTokens.js +1 -1
  39. package/test/checkComponentProps.js +29 -0
  40. package/test/checkId.test.js +1 -37
  41. package/test/checkManifest.test.js +1 -1
  42. package/test/checkPrivate.js +22 -0
  43. package/test/checkSetsUnique.js +54 -0
  44. package/test/checkUniqueTokenNames.js +32 -0
  45. package/test/componentSchemaValidator.test.js +1 -1
  46. package/test/deprecateExpress.test.js +1 -1
  47. package/test/drover.test.js +1 -1
  48. package/test/schemaValidator.test.js +1 -1
  49. package/test/schemaValidators/alias.test.js +1 -1
  50. package/test/snapshots/deprecateExpress.test.js.md +1 -1
  51. package/test/snapshots/deprecateExpress.test.js.snap +0 -0
  52. package/test/tokenSchemaValidator.test.js +1 -1
package/tasks/addIds.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -10,15 +10,13 @@ OF ANY KIND, either express or implied. See the License for the specific languag
10
10
  governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { glob } from "glob";
14
13
  import crypto from "crypto"; // (not the fake money)
15
14
  import { writeFile, readFile } from "fs/promises";
16
-
17
- const files = await glob("src/**/*.json");
18
- console.log(files);
15
+ import { tokenFileNames, writeJson } from "../index.js";
19
16
 
20
17
  const VALUE = "value";
21
18
  const UUID = "uuid";
19
+ const SETS = "sets";
22
20
  const uuids = [];
23
21
 
24
22
  // dumb function to check if something is an object
@@ -46,7 +44,7 @@ function findUUIDs(json) {
46
44
  // check for and add uuids
47
45
  function addUUIDs(json) {
48
46
  // if it is in want of uuid, give it one
49
- if (json[VALUE] && !json[UUID]) {
47
+ if (!json[UUID] && (json[VALUE] || json[SETS])) {
50
48
  while (!json[UUID] || uuids.includes(json[UUID])) {
51
49
  json[UUID] = crypto.randomUUID(); // https://stackoverflow.com/questions/105034/how-do-i-create-a-guid-uuid#2117523
52
50
  }
@@ -63,7 +61,7 @@ function addUUIDs(json) {
63
61
  }
64
62
 
65
63
  // run through the files and find uuids
66
- for (const fileName of files) {
64
+ for (const fileName of tokenFileNames) {
67
65
  const fileData = await readFile(fileName, "utf8");
68
66
  const fileJSON = JSON.parse(fileData);
69
67
 
@@ -71,7 +69,7 @@ for (const fileName of files) {
71
69
  }
72
70
 
73
71
  // run through the files and add uuids
74
- for (const fileName of files) {
72
+ for (const fileName of tokenFileNames) {
75
73
  const fileData = await readFile(fileName, "utf8");
76
74
  const fileJSON = JSON.parse(fileData);
77
75
 
@@ -79,7 +77,7 @@ for (const fileName of files) {
79
77
 
80
78
  addUUIDs(fileJSON);
81
79
 
82
- await writeFile(fileName, JSON.stringify(fileJSON, null, 2));
80
+ await writeJson(fileName, fileJSON);
83
81
 
84
82
  if (uuids.length !== existing) {
85
83
  console.log(` added: ${fileName} ${uuids.length - existing} uuids`);
@@ -0,0 +1,22 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import { getFileTokens, writeJson, __dirname } from "../index.js";
13
+ import { resolve } from "path";
14
+
15
+ const tokenData = await getFileTokens("color-palette.json");
16
+ const result = {};
17
+
18
+ for (const [key, value] of Object.entries(tokenData)) {
19
+ result[key] = { ...value, ...{ private: true } };
20
+ }
21
+
22
+ writeJson(`${resolve(__dirname, "./src")}/color-palette.json`, result);
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
package/tasks/diff.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -16,7 +16,7 @@ import { fileURLToPath } from "url";
16
16
  import { detailedDiff, diff } from "deep-object-diff";
17
17
  import { exec } from "node:child_process";
18
18
  import { promisify } from "util";
19
- import tar from "tar";
19
+ import { x } from "tar";
20
20
  import tmp from "tmp-promise";
21
21
 
22
22
  const execP = promisify(exec);
@@ -54,7 +54,11 @@ async function run() {
54
54
  async function getNewTokens() {
55
55
  try {
56
56
  await access(localTokenPath);
57
- return JSON.parse(await readFile(localTokenPath, { encoding: "utf8" }));
57
+ return JSON.parse(
58
+ convertNumberStringsToNumbers(
59
+ await readFile(localTokenPath, { encoding: "utf8" }),
60
+ ),
61
+ );
58
62
  } catch {
59
63
  console.error("cannot access");
60
64
  }
@@ -65,14 +69,18 @@ async function getOldTokens() {
65
69
  const { stdout, stderr } = await execP(
66
70
  `npm pack @adobe/spectrum-tokens@${tag} --pack-destination ${tmpDir.path}`,
67
71
  );
68
- await tar.x({
72
+ await x({
69
73
  cwd: tmpDir.path,
70
74
  file: join(tmpDir.path, stdout.trim()),
71
75
  });
72
76
  const oldTokenPath = join(tmpDir.path, "package", tokenPath);
73
77
  await access(oldTokenPath);
74
78
  console.log(`Comparing against ${stdout.trim()}`);
75
- return JSON.parse(await readFile(oldTokenPath, { encoding: "utf8" }));
79
+ return JSON.parse(
80
+ convertNumberStringsToNumbers(
81
+ await readFile(oldTokenPath, { encoding: "utf8" }),
82
+ ),
83
+ );
76
84
  }
77
85
 
78
86
  function calculatePossibleRenames(diffResult, oldTokens, newTokens) {
@@ -92,6 +100,12 @@ function calculatePossibleRenames(diffResult, oldTokens, newTokens) {
92
100
  });
93
101
  }
94
102
 
103
+ function convertNumberStringsToNumbers(dataString) {
104
+ return dataString.replace(/"([\d]*\.?[\d]*)"/g, (match, p1) => {
105
+ return p1;
106
+ });
107
+ }
108
+
95
109
  function logResultCategory(diffResult, categoryKey, msg) {
96
110
  const results = diffResult[categoryKey];
97
111
  const resultCount = Object.keys(results).length;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -0,0 +1,29 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import test from "ava";
14
+ import { getFileTokens } from "../index.js";
15
+
16
+ test("ensure all component tokens are have component data", async (t) => {
17
+ const tokenData = {
18
+ ...(await getFileTokens("color-component.json")),
19
+ ...(await getFileTokens("layout-component.json")),
20
+ ...(await getFileTokens("icons.json")),
21
+ };
22
+ const result = Object.keys(tokenData).filter((tokenName) => {
23
+ return (
24
+ !Object.hasOwn(tokenData[tokenName], "component") ||
25
+ tokenName.indexOf(tokenData[tokenName].component) != 0
26
+ );
27
+ });
28
+ t.deepEqual(result, []);
29
+ });
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -20,42 +20,6 @@ const files = await Promise.all(
20
20
  ),
21
21
  );
22
22
 
23
- // const uuids = [];
24
- // const missingUUIDs = [];
25
- // const VALUE = "value";
26
- // const UUID = "uuid";
27
-
28
- // function isObject(a) {
29
- // return (
30
- // !!a &&
31
- // a.constructor &&
32
- // (a.constructor === Object || a.constructor.name === "Object")
33
- // );
34
- // }
35
-
36
- // // check for uuids
37
- // function checkUUID(json, name) {
38
- // if (json[VALUE] && !json[UUID]) {
39
- // if (!json[UUID]) {
40
- // if (name) {
41
- // missingUUIDs.push(name);
42
- // } else {
43
- // missingUUIDs.push(json[VALUE]);
44
- // }
45
- // }
46
- // else if (uuids.includes(json[UUID])) {
47
-
48
- // }
49
- // uuids.push(json[UUID]);
50
- // }
51
-
52
- // // handle the json's children
53
- // Object.keys(json).forEach((key) => {
54
- // if (isObject(json[key])) {
55
- // checkUUID(json[key], key);
56
- // }
57
- // });
58
- // }
59
23
  const findDuplicateUUIDs = (json) => {
60
24
  const uuids = [];
61
25
  const duplicateUUIDs = [];
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -0,0 +1,22 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import test from "ava";
14
+ import { getFileTokens } from "../index.js";
15
+
16
+ test("ensure all color-palette.json tokens are private", async (t) => {
17
+ const tokenData = await getFileTokens("color-palette.json");
18
+ const result = Object.keys(tokenData).filter(
19
+ (tokenName) => !Object.hasOwn(tokenData[tokenName], "private"),
20
+ );
21
+ t.deepEqual(result, []);
22
+ });
@@ -0,0 +1,54 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import test from "ava";
14
+ import { getAllTokens, isDeprecated } from "../index.js";
15
+
16
+ test("Single set properties shouldn't be deprecated", async (t) => {
17
+ const tokens = await getAllTokens();
18
+ for (const [tokenName, token] of Object.entries(tokens)) {
19
+ if (
20
+ Object.hasOwn(token, "sets") &&
21
+ !isDeprecated(token) &&
22
+ JSON.stringify(token.sets).indexOf("deprecated") > -1
23
+ ) {
24
+ t.truthy(
25
+ Object.values(token.sets).every((setValue) =>
26
+ Object.hasOwn(setValue, "deprecated"),
27
+ ),
28
+ );
29
+ }
30
+ }
31
+ t.pass();
32
+ });
33
+
34
+ test("Sets should have unique values", async (t) => {
35
+ const tokens = await getAllTokens();
36
+ const result = Object.keys(tokens).filter((tokenName) => {
37
+ const token = tokens[tokenName];
38
+ if (Object.hasOwn(token, "sets") && !isDeprecated(token)) {
39
+ const setValues = Object.keys(token.sets).reduce(
40
+ (accumulator, currentValue) =>
41
+ currentValue != "wireframe"
42
+ ? [...accumulator, token.sets[currentValue].value]
43
+ : accumulator,
44
+ [],
45
+ );
46
+ if (setValues.length != new Set(setValues).size) {
47
+ return true;
48
+ }
49
+ } else {
50
+ return false;
51
+ }
52
+ });
53
+ t.deepEqual(result, [], `${result.length} Duplicate sets found`);
54
+ });
@@ -0,0 +1,32 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import test from "ava";
14
+ import { readFile } from "fs/promises";
15
+ import { tokenFileNames } from "../index.js";
16
+ import findDuplicatedPropertyKeys from "find-duplicated-property-keys";
17
+
18
+ test("check for duplicate token names across all token files", async (t) => {
19
+ const result = await Promise.all(
20
+ tokenFileNames.map(async (tokenFileName) => {
21
+ const tokenDataString = await readFile(tokenFileName, "utf8");
22
+ return tokenDataString.substring(
23
+ tokenDataString.indexOf("{") + 1,
24
+ tokenDataString.lastIndexOf("}"),
25
+ );
26
+ }),
27
+ ).then((tokenDataArray) => {
28
+ return findDuplicatedPropertyKeys(`{${tokenDataArray.join(",")}}`);
29
+ });
30
+ // t.pass();
31
+ t.deepEqual(result, []);
32
+ });
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -1,4 +1,4 @@
1
- # Snapshot report for `test/deprecateExpress.test.js`
1
+ # Snapshot report for `packages/tokens/test/deprecateExpress.test.js`
2
2
 
3
3
  The actual snapshot is saved in `deprecateExpress.test.js.snap`.
4
4
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2023 Adobe. All rights reserved.
2
+ Copyright 2024 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0