Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Update script to build scss files along css files #19

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
/types
.DS_Store
/*.css
/*.scss
index.js
index.mjs
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@radix-ui/colors",
"version": "0.1.8",
"version": "0.1.9",
"contributors": [
"Colm Tuite <[email protected]>",
"Vlad Moroz <[email protected]>"
Expand All @@ -9,8 +9,8 @@
"module": "index.mjs",
"types": "types/index.d.ts",
"scripts": {
"build": "yarn clean && yarn && rollup -c && yarn build-css-modules",
"build-css-modules": "node ./scripts/build-css-modules.js",
"build": "yarn clean && yarn && rollup -c && yarn build-stylesheets",
"build-stylesheets": "node ./scripts/build-stylesheets.js",
"postpublish": "yarn clean",
"clean": "git clean -fdX"
},
Expand Down
17 changes: 0 additions & 17 deletions scripts/build-css-modules.js

This file was deleted.

29 changes: 29 additions & 0 deletions scripts/build-stylesheets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const fs = require("fs");
const path = require("path");
const allColorScales = require("../index");

const outputDir = require("../tsconfig.json").compilerOptions.outDir;

Object.entries(allColorScales).forEach(([colorScaleName, scale]) => {
const selector = /DarkA?$/.test(colorScaleName) ? ".dark-theme" : ":root";

// Building css modules
const scaleAsCssProperties = Object.entries(scale)
.map(([name, value]) => ` --${name}: ${value};`)
.join("\n");
const scaleAsCssFile = `${selector} {\n${scaleAsCssProperties}\n}`;
fs.writeFileSync(
path.join(outputDir, colorScaleName + ".css"),
scaleAsCssFile
);

// Building scss modules
const scaleAsScssProperties = Object.entries(scale)
.map(([name, value]) => ` $${name}: ${value};`)
.join("\n");
const scaleAsScssFile = `${selector} {\n${scaleAsScssProperties}\n}`;
fs.writeFileSync(
path.join(outputDir, colorScaleName + ".scss"),
scaleAsScssFile
);
});