Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
34 changes: 34 additions & 0 deletions .github/workflows/build-design-system.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build Design System

on:
push:
paths:
- "packages/design-system/src/tokens/**" # Trigger only when files in the tokens folder change
pull_request:
paths:
- "packages/design-system/src/tokens/**"

jobs:
build-design-system:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the repository
- name: Checkout repository
uses: actions/checkout@v3

# Step 2: Set up Bun
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
Comment on lines +21 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Pin Bun version for stability.

Using "latest" for bun-version could lead to unexpected issues if a new version introduces breaking changes.

   - name: Setup Bun
     uses: oven-sh/setup-bun@v1
     with:
-      bun-version: latest
+      bun-version: 1.0.20  # Pin to a specific version
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.0.20 # Pin to a specific version


# Step 3: Navigate to the design-system package and install dependencies
- name: Install dependencies
working-directory: ./packages/design-system
run: bun install

# Step 4: Run the build script
- name: Run build script
working-directory: ./packages/design-system
run: bun run build
24 changes: 0 additions & 24 deletions .github/workflows/update-leaderboard.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/updateLeaderboard.js

This file was deleted.

5 changes: 4 additions & 1 deletion .hintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": [
"development"
]
],
"hints": {
"typescript-config/consistent-casing": "off"
}
}
2 changes: 1 addition & 1 deletion apps/core/app/auth/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "@repo/ui/globals.css";
import "@repo/ui/globals.scss";
import type { Metadata } from "next";

export const metadata: Metadata = {
Expand Down
2 changes: 1 addition & 1 deletion apps/core/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "@repo/ui/globals.css";
import "@repo/ui/globals.scss";
import { cn } from "@repo/ui/lib/utils";
import type { Metadata } from "next";
import { ThemeProvider } from "next-themes";
Expand Down
Binary file modified bun.lockb
Binary file not shown.
15 changes: 15 additions & 0 deletions packages/design-system/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@repo/design-system",
"version": "1.0.0",
"scripts": {
"build": "bun run src/scripts/build.ts"
},
"exports": {
"./styles": "./src/styles/main.scss",
"./tailwind": "./src/tailwind/config.ts"
},
"devDependencies": {
"@repo/typescript-config": "*",
"style-dictionary": "^4.3.2"
}
}
79 changes: 79 additions & 0 deletions packages/design-system/src/scripts/build-colors-style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as fs from "fs";
import * as path from "path";

// Paths for token files
const tokensDir = path.join(__dirname, "../tokens");
const stylesDir = path.join(__dirname, "../styles/base");
const resolveTokenReference = (value: string): string => {
return value.replace(/{(.+?)}/g, (_, match) => `var(--${match.replace(".", "-")})`);
};
Comment on lines +7 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance token reference resolution with error handling.

The resolveTokenReference function should handle invalid token references and provide better error reporting.

 const resolveTokenReference = (value: string): string => {
+  if (typeof value !== 'string') {
+    console.warn(`Invalid token value: ${value}, expected string`);
+    return value;
+  }
   return value.replace(/{(.+?)}/g, (_, match) => `var(--${match.replace(".", "-")})`);
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const resolveTokenReference = (value: string): string => {
return value.replace(/{(.+?)}/g, (_, match) => `var(--${match.replace(".", "-")})`);
};
const resolveTokenReference = (value: string): string => {
if (typeof value !== 'string') {
console.warn(`Invalid token value: ${value}, expected string`);
return value;
}
return value.replace(/{(.+?)}/g, (_, match) => `var(--${match.replace(".", "-")})`);
};


// Generate SCSS content for a given theme
const generateScssContent = (
theme: "dark" | "light",
tokens: Record<string, any>,
): string => {
const lines: string[] = [];

const selector = theme === "dark" ? ":root" : ".light";

// Add the @use directive
lines.push(`@use "_palette.scss" as *;\n`);

// Start the layer and class
lines.push(`@layer base {`);
lines.push(` ${selector} {`);

// Process each token in the "color" group
const colorTokens = tokens.color;
for (const key in colorTokens) {
const value = colorTokens[key].$value;

// Convert token reference (e.g., {zinc.200}) to CSS variable (e.g., var(--zinc.200))
const resolvedValue = resolveTokenReference(value);
lines.push(` --${key}: ${resolvedValue};`);
}

// Close the class and layer
lines.push(` }`);
lines.push(`}`);

return lines.join("\n");
};

// Function to build and write SCSS for a given theme
export const buildColorsScss = (theme: "dark" | "light"): void => {
// Define the input and output file paths
const partFileName = theme === "dark" ? "Default" : "Light";
const inputFilePath = path.join(
tokensDir,
`token_Color_${partFileName}.json`,
);
const outputFilePath = path.join(stylesDir, `_colors-${theme}.scss`);

// Ensure the input file exists
if (!fs.existsSync(inputFilePath)) {
console.error(`Token file not found: ${inputFilePath}`);
return;
}

// Read and parse the JSON file
const rawData = fs.readFileSync(inputFilePath, "utf-8");
const tokens = JSON.parse(rawData);

Comment on lines +61 to +63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for JSON parsing and file operations.

Similar to build-colors-tailwind.ts, add proper error handling for file operations and JSON parsing.

-const rawData = fs.readFileSync(inputFilePath, "utf-8");
-const tokens = JSON.parse(rawData);
+let rawData: string;
+try {
+  rawData = fs.readFileSync(inputFilePath, "utf-8");
+} catch (error) {
+  console.error(`Failed to read token file: ${error.message}`);
+  return;
+}
+
+let tokens;
+try {
+  tokens = JSON.parse(rawData);
+  if (!tokens.color || typeof tokens.color !== 'object') {
+    throw new Error('Invalid token structure: missing or invalid color object');
+  }
+} catch (error) {
+  console.error(`Failed to parse token file: ${error.message}`);
+  return;
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const rawData = fs.readFileSync(inputFilePath, "utf-8");
const tokens = JSON.parse(rawData);
let rawData: string;
try {
rawData = fs.readFileSync(inputFilePath, "utf-8");
} catch (error) {
console.error(`Failed to read token file: ${error.message}`);
return;
}
let tokens;
try {
tokens = JSON.parse(rawData);
if (!tokens.color || typeof tokens.color !== 'object') {
throw new Error('Invalid token structure: missing or invalid color object');
}
} catch (error) {
console.error(`Failed to parse token file: ${error.message}`);
return;
}

// Generate SCSS content
const scssContent = generateScssContent(theme, tokens);

// Ensure the output directory exists
if (!fs.existsSync(stylesDir)) {
fs.mkdirSync(stylesDir, { recursive: true });
}

// Write the SCSS content to the file
fs.writeFileSync(outputFilePath, scssContent, "utf-8");
console.log(`SCSS file created for ${theme} theme at: ${outputFilePath}`);
};

// Reusable calls for light and dark themes
buildColorsScss("light");
buildColorsScss("dark");
61 changes: 61 additions & 0 deletions packages/design-system/src/scripts/build-colors-tailwind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as fs from "fs";
import * as path from "path";

// Paths for token files
const tokensDir = path.join(__dirname, "../tokens");
const outputDir = path.join(__dirname, "../tailwind");

// Utility to resolve token references to match the key directly
const resolveTokenReference = (key: string): string => {
return `hsl(var(--${key}))`;
};

// Generate TypeScript content for colors
const generateColorsTsContent = (tokens: Record<string, any>): string => {
const colorTokens = tokens.color;
const lines: string[] = [];

// Add the TypeScript export header
lines.push(`export const colors = {`);

// Process each token and use the key for the variable name
for (const key in colorTokens) {
lines.push(` "${key}": "${resolveTokenReference(key)}",`);
}

// Close the object
lines.push(`};`);

return lines.join("\n");
};

// Function to build and write colors.ts
export const buildColorsTailwind = (): void => {
const inputFilePath = path.join(tokensDir, `token_Color_Light.json`);
const outputFilePath = path.join(outputDir, `colors.ts`);

// Ensure the input file exists
if (!fs.existsSync(inputFilePath)) {
console.error(`Token file not found: ${inputFilePath}`);
return;
}

// Read and parse the JSON file
const rawData = fs.readFileSync(inputFilePath, "utf-8");
const tokens = JSON.parse(rawData);

Comment on lines +44 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for JSON parsing and type validation.

The function should handle potential JSON parsing errors and validate the token structure.

 const rawData = fs.readFileSync(inputFilePath, "utf-8");
-const tokens = JSON.parse(rawData);
+let tokens;
+try {
+  tokens = JSON.parse(rawData);
+  if (!tokens.color || typeof tokens.color !== 'object') {
+    throw new Error('Invalid token structure: missing or invalid color object');
+  }
+} catch (error) {
+  console.error(`Failed to parse token file: ${error.message}`);
+  return;
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const rawData = fs.readFileSync(inputFilePath, "utf-8");
const tokens = JSON.parse(rawData);
const rawData = fs.readFileSync(inputFilePath, "utf-8");
let tokens;
try {
tokens = JSON.parse(rawData);
if (!tokens.color || typeof tokens.color !== 'object') {
throw new Error('Invalid token structure: missing or invalid color object');
}
} catch (error) {
console.error(`Failed to parse token file: ${error.message}`);
return;
}

// Generate TypeScript content
const tsContent = generateColorsTsContent(tokens);

// Ensure the output directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}

// Write the TypeScript content to the file
fs.writeFileSync(outputFilePath, tsContent, "utf-8");
console.log(`colors.ts file created at: ${outputFilePath}`);
};

// Build colors.ts
buildColorsTailwind();
40 changes: 40 additions & 0 deletions packages/design-system/src/scripts/build-config-tailwind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as fs from "fs";
import * as path from "path";

// Paths for the output file
const outputDir = path.join(__dirname, "../tailwind");
const outputFilePath = path.join(outputDir, "config.ts");
Comment on lines +4 to +6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve path handling and configuration.

The current implementation uses hardcoded paths. Consider:

  1. Making paths configurable through environment variables
  2. Using a configuration file for paths
  3. Adding path validation
import { config } from '../config';

const getOutputPaths = () => {
  const baseDir = process.env.DESIGN_SYSTEM_OUTPUT_DIR || config.outputDir;
  return {
    dir: path.resolve(baseDir, 'tailwind'),
    file: path.resolve(baseDir, 'tailwind/config.ts')
  };
};


// Content for the tailwindConfig.ts file
const generateTailwindConfigContent = (): string => {
return `
import { colors } from "./colors";
import { palette } from "./palette";

export const tailwindConfig = {
theme: {
extend: {
colors: { ...colors, ...palette },
},
},
};
`.trim();
};

// Function to create the tailwindConfig.ts file
export const buildTailwindConfig = (): void => {
// Generate the content
const configContent = generateTailwindConfigContent();

// Ensure the output directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}

// Write the content to the file
fs.writeFileSync(outputFilePath, configContent, "utf-8");
console.log(`tailwindConfig.ts file created at: ${outputFilePath}`);
};
Comment on lines +24 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for file operations.

File operations could fail due to permissions or disk space. Add proper error handling:

 export const buildTailwindConfig = (): void => {
+  const { dir, file } = getOutputPaths();
+
   try {
     const configContent = generateTailwindConfigContent();
 
-    if (!fs.existsSync(outputDir)) {
-      fs.mkdirSync(outputDir, { recursive: true });
+    if (!fs.existsSync(dir)) {
+      fs.mkdirSync(dir, { recursive: true });
     }
 
-    fs.writeFileSync(outputFilePath, configContent, "utf-8");
-    console.log(`tailwindConfig.ts file created at: ${outputFilePath}`);
+    // Check write permissions
+    try {
+      fs.accessSync(dir, fs.constants.W_OK);
+    } catch (error) {
+      throw new Error(`No write permission to directory: ${dir}`);
+    }
+
+    fs.writeFileSync(file, configContent, "utf-8");
+    console.log(`tailwindConfig.ts file created at: ${file}`);
+  } catch (error) {
+    throw new Error(`Failed to build Tailwind config: ${error.message}`);
   }
 };

Committable suggestion skipped: line range outside the PR's diff.


// Run the script
buildTailwindConfig();
Comment on lines +39 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove direct script execution.

The script is imported by build.ts, so it shouldn't execute directly. Remove the direct call to buildTailwindConfig().

-// Run the script
-buildTailwindConfig();

32 changes: 32 additions & 0 deletions packages/design-system/src/scripts/build-main-style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as fs from "fs";
import * as path from "path";

// Paths for the output file
const outputDir = path.join(__dirname, "../styles");
const outputFilePath = path.join(outputDir, "main.scss");

// Content for the main.scss file
const generateMainScssContent = (): string => {
return `
@use "./base/_colors-dark.scss" as *;
@use "./base/_colors-light.scss" as *;
`.trim();
};

// Function to create the main.scss file
export const buildMainScss = (): void => {
// Generate the content
const scssContent = generateMainScssContent();

// Ensure the output directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}

// Write the content to the file
fs.writeFileSync(outputFilePath, scssContent, "utf-8");
console.log(`main.scss file created at: ${outputFilePath}`);
};
Comment on lines +16 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add robust error handling and improved logging.

The current implementation lacks proper error handling and logging capabilities.

 export const buildMainScss = (): void => {
+  try {
     // Generate the content
     const scssContent = generateMainScssContent();
 
     // Ensure the output directory exists
     if (!fs.existsSync(outputDir)) {
+      console.log(`Creating directory: ${outputDir}`);
       fs.mkdirSync(outputDir, { recursive: true });
     }
 
+    // Check if file exists
+    if (fs.existsSync(outputFilePath)) {
+      console.log(`Warning: Overwriting existing file: ${outputFilePath}`);
+    }
+
     // Write the content to the file
     fs.writeFileSync(outputFilePath, scssContent, "utf-8");
     console.log(`main.scss file created at: ${outputFilePath}`);
+  } catch (error) {
+    console.error('Failed to build main.scss:', error);
+    process.exit(1);
+  }
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Function to create the main.scss file
export const buildMainScss = (): void => {
// Generate the content
const scssContent = generateMainScssContent();
// Ensure the output directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Write the content to the file
fs.writeFileSync(outputFilePath, scssContent, "utf-8");
console.log(`main.scss file created at: ${outputFilePath}`);
};
// Function to create the main.scss file
export const buildMainScss = (): void => {
try {
// Generate the content
const scssContent = generateMainScssContent();
// Ensure the output directory exists
if (!fs.existsSync(outputDir)) {
console.log(`Creating directory: ${outputDir}`);
fs.mkdirSync(outputDir, { recursive: true });
}
// Check if file exists
if (fs.existsSync(outputFilePath)) {
console.log(`Warning: Overwriting existing file: ${outputFilePath}`);
}
// Write the content to the file
fs.writeFileSync(outputFilePath, scssContent, "utf-8");
console.log(`main.scss file created at: ${outputFilePath}`);
} catch (error) {
console.error('Failed to build main.scss:', error);
process.exit(1);
}
};


// Run the script
buildMainScss();
54 changes: 54 additions & 0 deletions packages/design-system/src/scripts/build-palette-style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as fs from 'fs';
import * as path from 'path';
import { hexToHsl } from './utills.js';

// Paths for input and output files
const inputFilePath = path.join(__dirname, '../tokens/token_Palette_Primitive.json');
const outputFilePath = path.join(__dirname, '../styles/base/_palette.scss');

// Generate SCSS content with groups separated by an empty line
const generateScssContent = (tokens: Record<string, any>): string => {
const lines: string[] = [];

for (const group in tokens) {
const groupTokens = tokens[group];
for (const key in groupTokens) {
const value = groupTokens[key];
if (value.$type === 'color') {
lines.push(` --${group}-${key}: ${hexToHsl(value.$value)};`);
}
}
lines.push(''); // Add an empty line after each group
}

return `
@layer base {
:root {
${lines.join('\n')}
}
}
`.trim();
};

// Function to build and write SCSS content
export const buildPaletteScss = (): void => {
// Read and parse the JSON file
const rawData = fs.readFileSync(inputFilePath, 'utf-8');
const tokens = JSON.parse(rawData);

// Generate SCSS content
const scssContent = generateScssContent(tokens);

// Ensure the output directory exists
const outputDir = path.dirname(outputFilePath);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}

// Write the SCSS content to the file
fs.writeFileSync(outputFilePath, scssContent, 'utf-8');
console.log(`SCSS file created at: ${outputFilePath}`);
};
Comment on lines +34 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling and input validation.

The script should handle potential errors and validate input data.

 export const buildPaletteScss = (): void => {
-  // Read and parse the JSON file
-  const rawData = fs.readFileSync(inputFilePath, 'utf-8');
-  const tokens = JSON.parse(rawData);
+  try {
+    // Read and parse the JSON file
+    if (!fs.existsSync(inputFilePath)) {
+      throw new Error(`Input file not found: ${inputFilePath}`);
+    }
+    const rawData = fs.readFileSync(inputFilePath, 'utf-8');
+    const tokens = JSON.parse(rawData);
+    
+    // Validate tokens structure
+    if (!tokens || typeof tokens !== 'object') {
+      throw new Error('Invalid token format: expected an object');
+    }
 
-  // Generate SCSS content
-  const scssContent = generateScssContent(tokens);
+    // Generate SCSS content
+    const scssContent = generateScssContent(tokens);
 
-  // Ensure the output directory exists
-  const outputDir = path.dirname(outputFilePath);
-  if (!fs.existsSync(outputDir)) {
-    fs.mkdirSync(outputDir, { recursive: true });
-  }
+    // Ensure the output directory exists
+    const outputDir = path.dirname(outputFilePath);
+    if (!fs.existsSync(outputDir)) {
+      fs.mkdirSync(outputDir, { recursive: true });
+    }
 
-  // Write the SCSS content to the file
-  fs.writeFileSync(outputFilePath, scssContent, 'utf-8');
-  console.log(`SCSS file created at: ${outputFilePath}`);
+    // Write the SCSS content to the file
+    fs.writeFileSync(outputFilePath, scssContent, 'utf-8');
+    console.log(`SCSS file created at: ${outputFilePath}`);
+  } catch (error) {
+    console.error('Error building palette SCSS:', error);
+    process.exit(1);
+  }
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const buildPaletteScss = (): void => {
// Read and parse the JSON file
const rawData = fs.readFileSync(inputFilePath, 'utf-8');
const tokens = JSON.parse(rawData);
// Generate SCSS content
const scssContent = generateScssContent(tokens);
// Ensure the output directory exists
const outputDir = path.dirname(outputFilePath);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Write the SCSS content to the file
fs.writeFileSync(outputFilePath, scssContent, 'utf-8');
console.log(`SCSS file created at: ${outputFilePath}`);
};
export const buildPaletteScss = (): void => {
try {
// Read and parse the JSON file
if (!fs.existsSync(inputFilePath)) {
throw new Error(`Input file not found: ${inputFilePath}`);
}
const rawData = fs.readFileSync(inputFilePath, 'utf-8');
const tokens = JSON.parse(rawData);
// Validate tokens structure
if (!tokens || typeof tokens !== 'object') {
throw new Error('Invalid token format: expected an object');
}
// Generate SCSS content
const scssContent = generateScssContent(tokens);
// Ensure the output directory exists
const outputDir = path.dirname(outputFilePath);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Write the SCSS content to the file
fs.writeFileSync(outputFilePath, scssContent, 'utf-8');
console.log(`SCSS file created at: ${outputFilePath}`);
} catch (error) {
console.error('Error building palette SCSS:', error);
process.exit(1);
}
};


// Run the script
buildPaletteScss();
Loading
Loading