@adobe/spectrum-tokens 0.0.0-tabs-20230503165321

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,20 @@
1
+ /*
2
+ Copyright 2023 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 glob from "glob-promise";
14
+ import { writeFile } from "fs/promises";
15
+
16
+ const manifestFileName = "manifest.json";
17
+ const files = await glob("src/**/*.json");
18
+
19
+ await writeFile(manifestFileName, JSON.stringify(files, null, 2));
20
+ console.log(`Wrote ${manifestFileName} with ${files.length} files.`);
@@ -0,0 +1,58 @@
1
+ /*
2
+ Copyright 2023 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 StyleDictionary from "style-dictionary";
14
+ import {
15
+ JsonSetsFormatter,
16
+ NameKebabTransfom,
17
+ DroverJsonFormatter,
18
+ AttributeSetsTransform,
19
+ } from "style-dictionary-sets";
20
+
21
+ StyleDictionary.registerTransform(AttributeSetsTransform);
22
+ StyleDictionary.registerTransform(NameKebabTransfom);
23
+ StyleDictionary.registerFormat(JsonSetsFormatter);
24
+ StyleDictionary.registerFormat(DroverJsonFormatter);
25
+
26
+ StyleDictionary.extend({
27
+ source: ["src/**/*.json"],
28
+ platforms: {
29
+ JSON: {
30
+ buildPath: "dist/json/",
31
+ transforms: [NameKebabTransfom.name],
32
+ files: [
33
+ {
34
+ destination: "variables.json",
35
+ format: JsonSetsFormatter.name,
36
+ options: {
37
+ showFileHeader: false,
38
+ outputReferences: true,
39
+ },
40
+ },
41
+ ],
42
+ },
43
+ Drover: {
44
+ buildPath: "dist/json/",
45
+ transforms: [AttributeSetsTransform.name, NameKebabTransfom.name],
46
+ files: [
47
+ {
48
+ destination: "drover.json",
49
+ format: "drover/json/sets",
50
+ options: {
51
+ showFileHeader: false,
52
+ outputReferences: true,
53
+ },
54
+ },
55
+ ],
56
+ },
57
+ },
58
+ }).buildAllPlatforms();
@@ -0,0 +1,23 @@
1
+ /*
2
+ Copyright 2023 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 glob from "glob-promise";
14
+ import { readFile, writeFile } from "fs/promises";
15
+ import augmentExpressTokens from "./lib/augmentExpressTokens.js";
16
+
17
+ const files = await glob("src/**/*.json");
18
+ files.forEach(async (fileName) => {
19
+ const fileTokens = JSON.parse(await readFile(fileName, "utf8"));
20
+ const result = augmentExpressTokens(fileTokens);
21
+ await writeFile(fileName, JSON.stringify(result, null, 2));
22
+ console.log(`Updated ${fileName}.`);
23
+ });
package/tasks/diff.js ADDED
@@ -0,0 +1,130 @@
1
+ /*
2
+ Copyright 2023 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 { access, readFile, writeFile } from "fs/promises";
14
+ import { join, dirname } from "path";
15
+ import { fileURLToPath } from "url";
16
+ import { detailedDiff, diff } from "deep-object-diff";
17
+ import { exec } from "node:child_process";
18
+ import { promisify } from "util";
19
+ import tar from "tar";
20
+ import tmp from "tmp-promise";
21
+
22
+ const execP = promisify(exec);
23
+
24
+ const tag = "latest";
25
+ const tokenPath = "dist/json/variables.json";
26
+ const localRootDir = join(dirname(fileURLToPath(import.meta.url)), "..");
27
+ const localTokenPath = join(localRootDir, tokenPath);
28
+
29
+ run()
30
+ .then(() => {
31
+ process.exit();
32
+ })
33
+ .catch((err) => {
34
+ console.error(err);
35
+ process.exit(1);
36
+ });
37
+
38
+ async function run() {
39
+ const [newTokens, oldTokens] = await Promise.all([
40
+ getNewTokens(),
41
+ getOldTokens(),
42
+ ]);
43
+
44
+ const diffResult = detailedDiff(oldTokens, newTokens);
45
+
46
+ calculatePossibleRenames(diffResult, oldTokens, newTokens);
47
+
48
+ logResultCategory(diffResult, "added");
49
+ logResultCategory(diffResult, "deleted");
50
+ logResultCategory(diffResult, "updated", "Token values updated");
51
+ logResultCategory(diffResult, "possiblyRenamed", "Tokens possibly renamed");
52
+ }
53
+
54
+ async function getNewTokens() {
55
+ try {
56
+ await access(localTokenPath);
57
+ return JSON.parse(await readFile(localTokenPath, { encoding: "utf8" }));
58
+ } catch {
59
+ console.error("cannot access");
60
+ }
61
+ }
62
+
63
+ async function getOldTokens() {
64
+ const tmpDir = await tmp.dir();
65
+ const { stdout, stderr } = await execP(
66
+ `npm pack @adobe/spectrum-tokens@${tag} --pack-destination ${tmpDir.path}`,
67
+ );
68
+ await tar.x({
69
+ cwd: tmpDir.path,
70
+ file: join(tmpDir.path, stdout.trim()),
71
+ });
72
+ const oldTokenPath = join(tmpDir.path, "package", tokenPath);
73
+ await access(oldTokenPath);
74
+ return JSON.parse(await readFile(oldTokenPath, { encoding: "utf8" }));
75
+ }
76
+
77
+ function calculatePossibleRenames(diffResult, oldTokens, newTokens) {
78
+ diffResult.possiblyRenamed = {};
79
+ Object.keys(diffResult.deleted).forEach((deletedTokenName) => {
80
+ const oldTokenValue = oldTokens[deletedTokenName];
81
+ const allValueMatches = [];
82
+ Object.keys(diffResult.added).forEach((addedTokenName, i) => {
83
+ const newTokenValue = newTokens[addedTokenName];
84
+ if (Object.keys(diff(oldTokenValue, newTokenValue)).length === 0) {
85
+ allValueMatches.push(addedTokenName);
86
+ }
87
+ });
88
+ if (allValueMatches.length > 0) {
89
+ diffResult.possiblyRenamed[deletedTokenName] = allValueMatches;
90
+ }
91
+ });
92
+ }
93
+
94
+ function logResultCategory(diffResult, categoryKey, msg) {
95
+ const results = diffResult[categoryKey];
96
+ const resultCount = Object.keys(results).length;
97
+ if (!msg) {
98
+ msg = `Tokens ${categoryKey}`;
99
+ }
100
+ if (resultCount > 0) {
101
+ console.log(`\n*${msg} (${resultCount}):*`);
102
+ switch (categoryKey) {
103
+ case "possiblyRenamed":
104
+ Object.keys(results)
105
+ .sort()
106
+ .forEach((oldTokenName, i) => {
107
+ if (
108
+ Array.isArray(results[oldTokenName]) &&
109
+ results[oldTokenName].length > 1
110
+ ) {
111
+ console.log(
112
+ ` - Old name: \`${oldTokenName}\`, new name options:`,
113
+ );
114
+ results[oldTokenName].forEach((newTokenName) =>
115
+ console.log(` - \`${newTokenName}\``),
116
+ );
117
+ } else {
118
+ console.log(
119
+ ` - \`${oldTokenName}\` -> \`${results[oldTokenName][0]}\``,
120
+ );
121
+ }
122
+ });
123
+ break;
124
+ default:
125
+ Object.keys(results)
126
+ .sort()
127
+ .forEach((tokenName, i) => console.log(` - \`${tokenName}\``));
128
+ }
129
+ }
130
+ }
@@ -0,0 +1,52 @@
1
+ /*
2
+ Copyright 2023 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
+ const deprecationObj = {
14
+ deprecated: true,
15
+ deprecated_comment:
16
+ "Express will merge with Spectrum with the release of Spectrum 2.",
17
+ };
18
+
19
+ const findExpressValue = (tokenObj) => {
20
+ if (typeof tokenObj === "object" && tokenObj !== null) {
21
+ if (tokenObj.hasOwnProperty("value")) {
22
+ return {
23
+ ...tokenObj,
24
+ ...deprecationObj,
25
+ };
26
+ } else {
27
+ const result = {};
28
+ Object.keys(tokenObj).forEach((tokenName) => {
29
+ result[tokenName] = findExpressValue(tokenObj[tokenName]);
30
+ });
31
+ return result;
32
+ }
33
+ }
34
+ };
35
+
36
+ const augmentExpressTokens = (tokenObj) => {
37
+ if (typeof tokenObj === "object" && tokenObj !== null) {
38
+ const result = {};
39
+ Object.keys(tokenObj).forEach((tokenName) => {
40
+ if (tokenName === "express") {
41
+ result[tokenName] = findExpressValue(tokenObj[tokenName]);
42
+ } else {
43
+ result[tokenName] = augmentExpressTokens(tokenObj[tokenName]);
44
+ }
45
+ });
46
+ return result;
47
+ } else {
48
+ return tokenObj;
49
+ }
50
+ };
51
+
52
+ export default augmentExpressTokens;
@@ -0,0 +1,50 @@
1
+ /*
2
+ Copyright 2023 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 augmentExpressTokens from "../tasks/lib/augmentExpressTokens.js";
15
+
16
+ const fixture = {
17
+ foo: {
18
+ express: {
19
+ value: "bar",
20
+ },
21
+ },
22
+ "corner-radius-100": {
23
+ sets: {
24
+ spectrum: {
25
+ sets: {
26
+ desktop: {
27
+ value: "4px",
28
+ },
29
+ mobile: {
30
+ value: "5px",
31
+ },
32
+ },
33
+ },
34
+ express: {
35
+ sets: {
36
+ desktop: {
37
+ value: "6px",
38
+ },
39
+ mobile: {
40
+ value: "8px",
41
+ },
42
+ },
43
+ },
44
+ },
45
+ },
46
+ };
47
+
48
+ test("Deprecate Express should add deprecation metadata to Express tokens", (t) => {
49
+ t.snapshot(augmentExpressTokens(fixture));
50
+ });
@@ -0,0 +1,58 @@
1
+ /*
2
+ Copyright 2023 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
+
16
+ const getValue = (obj, setName) => {
17
+ if (obj.hasOwnProperty("value")) {
18
+ return obj.value;
19
+ } else if (obj.hasOwnProperty("sets")) {
20
+ if (obj.sets.hasOwnProperty(setName)) {
21
+ return getValue(obj.sets[setName], setName);
22
+ } else if (obj.sets.hasOwnProperty("spectrum")) {
23
+ return getValue(obj.sets.spectrum, setName);
24
+ }
25
+ }
26
+ };
27
+
28
+ const vars = { light: {}, dark: {}, darkest: {} };
29
+ let variables;
30
+ let drover;
31
+
32
+ test.before(async (t) => {
33
+ variables = JSON.parse(
34
+ await readFile("dist/json/variables.json", { encoding: "utf8" }),
35
+ );
36
+ drover = JSON.parse(
37
+ await readFile("dist/json/drover.json", { encoding: "utf8" }),
38
+ );
39
+ Object.keys(drover.colorThemes.light).forEach((tokenName) => {
40
+ vars.light[tokenName] = getValue(variables[tokenName], "light");
41
+ });
42
+ Object.keys(drover.colorThemes.dark).forEach((tokenName) => {
43
+ vars.dark[tokenName] = getValue(variables[tokenName], "dark");
44
+ });
45
+ Object.keys(drover.colorThemes.darkest).forEach((tokenName) => {
46
+ vars.darkest[tokenName] = getValue(variables[tokenName], "darkest");
47
+ });
48
+ });
49
+
50
+ test("Drover should match light variable values", (t) => {
51
+ t.deepEqual(drover.colorThemes.light, vars.light);
52
+ });
53
+ test("Drover should match dark variable values", (t) => {
54
+ t.deepEqual(drover.colorThemes.dark, vars.dark);
55
+ });
56
+ test("Drover should match darkest variable values", (t) => {
57
+ t.deepEqual(drover.colorThemes.darkest, vars.darkest);
58
+ });
@@ -0,0 +1,47 @@
1
+ # Snapshot report for `test/deprecateExpress.test.js`
2
+
3
+ The actual snapshot is saved in `deprecateExpress.test.js.snap`.
4
+
5
+ Generated by [AVA](https://avajs.dev).
6
+
7
+ ## Deprecate Express should add deprecation metadata to Express tokens
8
+
9
+ > Snapshot 1
10
+
11
+ {
12
+ 'corner-radius-100': {
13
+ sets: {
14
+ express: {
15
+ sets: {
16
+ desktop: {
17
+ deprecated: true,
18
+ deprecated_comment: 'Express will merge with Spectrum with the release of Spectrum 2.',
19
+ value: '6px',
20
+ },
21
+ mobile: {
22
+ deprecated: true,
23
+ deprecated_comment: 'Express will merge with Spectrum with the release of Spectrum 2.',
24
+ value: '8px',
25
+ },
26
+ },
27
+ },
28
+ spectrum: {
29
+ sets: {
30
+ desktop: {
31
+ value: '4px',
32
+ },
33
+ mobile: {
34
+ value: '5px',
35
+ },
36
+ },
37
+ },
38
+ },
39
+ },
40
+ foo: {
41
+ express: {
42
+ deprecated: true,
43
+ deprecated_comment: 'Express will merge with Spectrum with the release of Spectrum 2.',
44
+ value: 'bar',
45
+ },
46
+ },
47
+ }