@adobe/spectrum-tokens 12.9.0 → 12.10.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.
@@ -0,0 +1,79 @@
1
+ import glob from "glob-promise";
2
+ import crypto from "crypto"; // (not the fake money)
3
+ import { writeFile, readFile } from "fs/promises";
4
+
5
+ const files = await glob("src/**/*.json");
6
+ console.log(files);
7
+
8
+ const VALUE = "value";
9
+ const UUID = "uuid";
10
+ const uuids = [];
11
+
12
+ // dumb function to check if something is an object
13
+ function isObject(a) {
14
+ return (
15
+ !!a &&
16
+ a.constructor &&
17
+ (a.constructor === Object || a.constructor.name === "Object")
18
+ );
19
+ }
20
+
21
+ // find existing uuids
22
+ function findUUIDs(json) {
23
+ if (json[UUID]) {
24
+ uuids.push(json[UUID]);
25
+ }
26
+
27
+ Object.keys(json).forEach((key) => {
28
+ if (isObject(json[key])) {
29
+ findUUIDs(json[key]);
30
+ }
31
+ });
32
+ }
33
+
34
+ // check for and add uuids
35
+ function addUUIDs(json) {
36
+ // if it is in want of uuid, give it one
37
+ if (json[VALUE] && !json[UUID]) {
38
+ while (!json[UUID] || uuids.includes(json[UUID])) {
39
+ json[UUID] = crypto.randomUUID(); // https://stackoverflow.com/questions/105034/how-do-i-create-a-guid-uuid#2117523
40
+ }
41
+
42
+ uuids.push(json[UUID]);
43
+ }
44
+
45
+ // handle the json's children
46
+ Object.keys(json).forEach((key) => {
47
+ if (isObject(json[key])) {
48
+ addUUIDs(json[key]);
49
+ }
50
+ });
51
+ }
52
+
53
+ // run through the files and find uuids
54
+ for (const fileName of files) {
55
+ const fileData = await readFile(fileName, "utf8");
56
+ const fileJSON = JSON.parse(fileData);
57
+
58
+ findUUIDs(fileJSON);
59
+ }
60
+
61
+ // run through the files and add uuids
62
+ for (const fileName of files) {
63
+ const fileData = await readFile(fileName, "utf8");
64
+ const fileJSON = JSON.parse(fileData);
65
+
66
+ const existing = uuids.length;
67
+
68
+ addUUIDs(fileJSON);
69
+
70
+ await writeFile(fileName, JSON.stringify(fileJSON, null, 2));
71
+
72
+ if (uuids.length !== existing) {
73
+ console.log(` added: ${fileName} ${uuids.length - existing} uuids`);
74
+ } else {
75
+ console.log(`checked: ${fileName}`);
76
+ }
77
+ }
78
+
79
+ console.log(`total: ${uuids.length} uuids`);