Skip to content

Commit 5d902f9

Browse files
committed
feat(tokens): export json, remove duplicate file generation
1 parent 6c19fcf commit 5d902f9

11 files changed

+42
-10797
lines changed

.changeset/mean-adults-scream.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@spectrum-css/tokens": minor
3+
---
4+
5+
Add JSON to token package exports.
6+
7+
Remove CSS files from commit history (but continue to build and ship them in the releases).
8+
9+
Stop physically copying the `dist/css/index.css` to `dist/index.css` and instead, map `dist/index.css` in the package exports to the same `dist/css/index.css` file.

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dist
22
!dist/metadata.json
3-
!tokens/dist/**
3+
!tokens/dist/json/*
44

55
# Not committing the map assets, these are dev-only
66
*.map

tokens/dist/css/dark-vars.css

-842
This file was deleted.

tokens/dist/css/global-vars.css

-669
This file was deleted.

tokens/dist/css/index.css

-3,579
This file was deleted.

tokens/dist/css/large-vars.css

-638
This file was deleted.

tokens/dist/css/light-vars.css

-842
This file was deleted.

tokens/dist/css/medium-vars.css

-638
This file was deleted.

tokens/dist/index.css

-3,579
This file was deleted.

tokens/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
"exports": {
1717
".": "./dist/css/index.css",
1818
"./*.md": "./*.md",
19-
"./dist/css/*.css": "./dist/css/*.css",
19+
"./dist/css/*": "./dist/css/*",
2020
"./dist/index.css": "./dist/css/index.css",
21+
"./dist/json/*": "./dist/json/*",
2122
"./package.json": "./package.json"
2223
},
2324
"main": "dist/index.css",

tokens/tasks/token-rollup.js

+30-8
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,23 @@ const path = require("path");
2020
const fg = require("fast-glob");
2121

2222
const { processCSS } = require("../../tasks/component-builder.js");
23-
const { copy, fetchContent } = require("../../tasks/utilities.js");
23+
const { fetchContent } = require("../../tasks/utilities.js");
2424

2525
require("colors");
2626

27+
/**
28+
* Create a tagline for the CSS file based on the package.json data
29+
* @param {Object} [packageJson={}]
30+
* @param {string} packageJson.name
31+
* @param {string} packageJson.version
32+
* @returns
33+
*/
34+
function generateTagline({ name, version } = {}) {
35+
if (!name) return "";
36+
if (!version) return `/* ${name} */\n\n`;
37+
return `/* ${name}@v${version} */\n\n`;
38+
}
39+
2740
/**
2841
* The builder for the main entry point
2942
* @param {object} config
@@ -44,7 +57,14 @@ async function index(inputGlob, outputPath, { cwd = process.cwd(), clean = false
4457
const contents = inputs.map(input => `@import "${input}";`).join("\n");
4558
if (!contents) return;
4659

47-
return processCSS(contents, undefined, outputPath, { cwd, clean, configPath: cwd, map: false, resolveImports: true, customTagline: `/* Token version: v${packageJson.version} */\n\n` });
60+
return processCSS(contents, undefined, outputPath, {
61+
cwd,
62+
clean,
63+
configPath: cwd,
64+
map: false,
65+
resolveImports: true,
66+
customTagline: generateTagline(packageJson),
67+
});
4868
}
4969

5070
/**
@@ -53,7 +73,7 @@ async function index(inputGlob, outputPath, { cwd = process.cwd(), clean = false
5373
* @param {string} [config.cwd=process.cwd()] - Current working directory for the component
5474
* @returns {Promise<string[]>}
5575
*/
56-
async function appendCustomOverrides({ cwd = process.cwd() } = {}) {
76+
async function appendCustomOverrides({ cwd = process.cwd(), packageJson = {} } = {}) {
5777
const promises = [];
5878

5979
// Add custom/*-vars.css to the end of the dist/css/*-vars.css files and run through postcss before writing back to the dist/css/*-vars.css file
@@ -75,6 +95,7 @@ async function appendCustomOverrides({ cwd = process.cwd() } = {}) {
7595
processCSS(combinedContent[0].content, path.join(cwd, "dist", "css", file), path.join(cwd, "dist", "css", file), {
7696
cwd,
7797
configPath: cwd,
98+
customTagline: generateTagline(packageJson),
7899
})
79100
);
80101
}
@@ -103,16 +124,17 @@ async function main({
103124

104125
const compiledOutputPath = path.join(cwd, "dist");
105126

127+
// Read in the package version from the package.json file
128+
const packageJson = await fsp.readFile(path.join(cwd, "package.json"), "utf-8").then(JSON.parse);
129+
106130
// Wait for all the custom files to be processed
107-
return appendCustomOverrides({ cwd }).then(async (r) =>
131+
return appendCustomOverrides({ packageJson, cwd }).then(async (r) =>
108132
Promise.all([
109133
index(
110134
["dist/css/*-vars.css"],
111135
path.join(compiledOutputPath, "css", "index.css"),
112-
{ cwd, clean }
113-
).then((reports) =>
114-
copy(path.join(compiledOutputPath, "css", "index.css"), path.join(cwd, "dist", "index.css"), { cwd, isDeprecated: false })
115-
.then((reps) => [reports, reps]))
136+
{ cwd, clean, packageJson }
137+
)
116138
]).then((reports) => {
117139
const logs = [reports, r].flat(Infinity).filter(Boolean);
118140

0 commit comments

Comments
 (0)