An open source design system that's fully customizable and agent ready
TypeScript
chore(cli): remove orphaned theme.mjs scaffolder command (#2465)
Joeyde9d64af1e52
diff --git a/packages/cli/src/commands/theme.mjs b/packages/cli/src/commands/theme.mjsdeleted file mode 100644index c15a17b4e0..0000000000--- a/packages/cli/src/commands/theme.mjs+++ /dev/null@@ -1,355 +0,0 @@-// Copyright (c) Meta Platforms, Inc. and affiliates.--/**- * @file theme command — Scaffold and apply XDS themes- *- * Interactive wizard that generates a complete theme file with:- * - Preset selection (default, neutral, or custom brand)- * - Brand color configuration for custom themes- * - Component style override scaffolding- * - Setup instructions for XDSTheme provider- */--import * as fs from 'node:fs';-import * as path from 'node:path';-import * as p from '@clack/prompts';-import {findCoreDir} from '../utils/paths.mjs';-import {getRunPrefix} from '../utils/package-manager.mjs';--function isCancel(value) {- if (p.isCancel(value)) {- p.cancel('Theme setup cancelled.');- process.exit(0);- }- return value;-}---// =============================================================================-// Theme file generation-// =============================================================================--/**- * Generate the theme file content- */-function generateThemeFile({name, exportName, accent, includeComponentOverrides}) {- const componentsComment = includeComponentOverrides- ? `- // Uncomment to apply component overrides:- // components: {- // button: {- // base: { borderRadius: '9999px' },- // },- // card: {- // base: { borderWidth: '2px', borderStyle: 'solid' },- // },- // },`- : '';-- return `/**- * ${name} Theme- *- * Generated by \`${getRunPrefix()} xds theme\`.- * Uses defineTheme with the color config — all color tokens are- * derived from the accent color via the HCT perceptual color model.- *- * Customize the config below, then import in your app.- */--import {defineTheme} from '@xds/core/theme';--export const ${exportName} = defineTheme({- name: '${name.toLowerCase().replace(/\s+/g, '-')}',-- // Accent color — all color tokens derive from this via HCT.- // Change the hex to update the entire palette.- color: {accent: '${accent}'},-- // Uncomment to customize:- // radius: {base: 4, multiplier: 1},- // typography: {body: {family: 'Inter', fallbacks: 'sans-serif'}},- // tokens: { '--color-on-accent': ['#FFFFFF', '#FFFFFF'] },-${componentsComment}-});-`;-}--/**- * Validate hex color input- */-function isValidHex(value) {- return /^#?[0-9A-Fa-f]{6}$/.test(value);-}--function normalizeHex(value) {- const clean = value.replace('#', '');- return '#' + clean.toUpperCase();-}--// =============================================================================-// Preset color palettes-// =============================================================================--const PRESETS = {- default: {- description: 'XDS branded — blue accent, system fonts',- accent: '#0064E0',- },- neutral: {- description: 'Grayscale — shadcn-inspired, minimal color',- accent: '#18181B',- },-};--// =============================================================================-// Command registration-// =============================================================================--// Keep these exports for backwards compat with init.mjs-export function discoverThemes(coreDir) {- // Check packages/theme/ (monorepo) and packages/core/src/theme/ (legacy)- const searchDirs = [- path.join(coreDir, '..', 'theme', 'src'),- path.join(coreDir, 'src', 'theme'),- ];-- const themes = [];- for (const searchDir of searchDirs) {- if (!fs.existsSync(searchDir)) continue;-- // Scan subdirectories for *Theme.stylex.ts- const entries = fs.readdirSync(searchDir, {withFileTypes: true});- for (const entry of entries) {- if (entry.isDirectory()) {- const dirPath = path.join(searchDir, entry.name);- const files = fs.readdirSync(dirPath);- for (const f of files) {- if (f.endsWith('Theme.stylex.ts')) {- const exportName = f.replace('.stylex.ts', '');- const name = exportName.replace('Theme', '');- themes.push({name, exportName});- }- }- } else if (entry.name.endsWith('Theme.stylex.ts')) {- const exportName = entry.name.replace('.stylex.ts', '');- const name = exportName.replace('Theme', '');- themes.push({name, exportName});- }- }- }-- // Deduplicate by name- const seen = new Set();- return themes- .filter(t => {- if (seen.has(t.name)) return false;- seen.add(t.name);- return true;- })- .sort((a, b) => a.name.localeCompare(b.name));-}--export function writeThemeConfig(targetDir, themeExportName) {- const configPath = path.join(targetDir, 'xds.config.mjs');- const content = `/**- * XDS Configuration- * Generated by \`xds theme\`- */-export default {- theme: '${themeExportName}',-};-`;- fs.writeFileSync(configPath, content);- return configPath;-}--export function registerTheme(program) {- program- .command('theme [preset]')- .description('Scaffold a custom XDS theme')- .option('--list', 'List existing themes in this project')- .option('--output <path>', 'Output file path', './src/theme/customTheme.stylex.ts')- .action(async (preset, options) => {- // Non-interactive: --list- if (options.list) {- const coreDir = findCoreDir(process.cwd());- if (!coreDir) {- console.error('Error: Could not find @xds/core package.');- process.exit(1);- }-- const themes = discoverThemes(coreDir);- if (themes.length === 0) {- console.log(`\nNo themes found. Run \`${getRunPrefix()} xds theme\` to create one.\n`);- } else {- console.log('\nExisting themes:\n');- for (const theme of themes) {- console.log(` ${theme.name} — import { ${theme.exportName} } from '@xds/theme/${theme.name}'`);- }- console.log('');- }- return;- }-- // Non-interactive: preset name provided directly- if (preset && PRESETS[preset]) {- const exportName = `${preset}Theme`;- const content = generateThemeFile({- name: preset.charAt(0).toUpperCase() + preset.slice(1),- exportName,- accent: PRESETS[preset].accent,- includeComponentOverrides: false,- });-- const outputPath = path.resolve(process.cwd(), options.output);- fs.mkdirSync(path.dirname(outputPath), {recursive: true});- fs.writeFileSync(outputPath, content);-- console.log(`\n✓ Generated ${path.relative(process.cwd(), outputPath)}\n`);- printSetupInstructions(outputPath, exportName);- return;- }-- // =====================================================================- // Interactive mode- // =====================================================================- p.intro('XDS Theme Scaffold');-- // Step 1: Choose starting point- const startingPoint = isCancel(- await p.select({- message: 'How would you like to start?',- options: [- {value: 'brand', label: 'Custom brand', hint: 'Pick your accent color, we derive the rest'},- {value: 'default', label: 'Copy Default theme', hint: 'Blue accent, full light/dark support'},- {value: 'neutral', label: 'Copy Neutral theme', hint: 'Grayscale, shadcn-inspired'},- {value: 'minimal', label: 'Minimal scaffold', hint: 'Just the structure, you fill in colors'},- ],- }),- );-- let accent;- let themeName;-- if (startingPoint === 'brand') {- // Step 2a: Brand color- const accentInput = isCancel(- await p.text({- message: 'Accent color (hex)',- placeholder: '#7B61FF',- initialValue: '#7B61FF',- validate: (value) => {- if (!isValidHex(value)) return 'Enter a valid hex color (e.g., #7B61FF)';- },- }),- );- accent = normalizeHex(accentInput);-- // Step 2b: Theme name- themeName = isCancel(- await p.text({- message: 'Theme name',- placeholder: 'myBrand',- initialValue: 'myBrand',- validate: (v) => {- if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(v)) return 'Use camelCase, letters and numbers only';- },- }),- );-- } else if (startingPoint === 'default' || startingPoint === 'neutral') {- accent = PRESETS[startingPoint].accent;- themeName = isCancel(- await p.text({- message: 'Theme name',- placeholder: `my${startingPoint.charAt(0).toUpperCase() + startingPoint.slice(1)}`,- initialValue: `my${startingPoint.charAt(0).toUpperCase() + startingPoint.slice(1)}`,- validate: (v) => {- if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(v)) return 'Use camelCase, letters and numbers only';- },- }),- );- } else {- // Minimal — use default accent as placeholder- accent = '#0064E0';- themeName = isCancel(- await p.text({- message: 'Theme name',- placeholder: 'myTheme',- initialValue: 'myTheme',- validate: (v) => {- if (!/^[a-zA-Z][a-zA-Z0-9]*$/.test(v)) return 'Use camelCase, letters and numbers only';- },- }),- );- }-- // Step 3: Component overrides- const includeComponentOverrides = isCancel(- await p.confirm({- message: 'Include component style override scaffolding?',- initialValue: true,- }),- );-- // Step 4: Output path- const exportName = `${themeName}Theme`;- const defaultOutput = `./src/theme/${themeName}Theme.stylex.ts`;- const outputPath = isCancel(- await p.text({- message: 'Output path',- placeholder: defaultOutput,- initialValue: defaultOutput,- }),- );-- // Generate and write- const content = generateThemeFile({- name: themeName.charAt(0).toUpperCase() + themeName.slice(1),- exportName,- accent,- includeComponentOverrides,- });-- const resolvedPath = path.resolve(process.cwd(), outputPath);- fs.mkdirSync(path.dirname(resolvedPath), {recursive: true});- fs.writeFileSync(resolvedPath, content);-- p.log.success(`Generated ${path.relative(process.cwd(), resolvedPath)}`);-- // Step 5: Setup instructions- p.note(- `import {XDSTheme} from '@xds/core';\n` +- `import {${exportName}} from './${path.relative(path.resolve(process.cwd(), 'src'), resolvedPath).replace('.ts', '')}';\n` +- `\n` +- `<XDSTheme theme={${exportName}}>\n` +- ` <App />\n` +- `</XDSTheme>`,- 'Add to your root layout',- );-- p.note(- 'Edit the color.accent hex to change the entire palette.\n' +- 'Add radius, typography, or tokens config to customize further.\n' +- 'Omitted config uses the defineVars defaults automatically.\n' +- `\nRun \`${getRunPrefix()} xds docs tokens\` to see all available tokens.`,- 'Next steps',- );-- p.outro('Theme ready!');- });-}--/**- * Print setup instructions (non-interactive mode)- */-function printSetupInstructions(outputPath, exportName) {- const relPath = path.relative(process.cwd(), outputPath).replace('.stylex.ts', '');- console.log('Add to your root layout:\n');- console.log(` import {XDSTheme} from '@xds/core';`);- console.log(` import {${exportName}} from './${relPath}';`);- console.log('');- console.log(` <XDSTheme theme={${exportName}}>`);- console.log(' <App />');- console.log(' </XDSTheme>\n');-}diff --git a/packages/cli/src/commands/theme.test.mjs b/packages/cli/src/commands/theme.test.mjsdeleted file mode 100644index 83474f4a8e..0000000000--- a/packages/cli/src/commands/theme.test.mjs+++ /dev/null@@ -1,84 +0,0 @@-// Copyright (c) Meta Platforms, Inc. and affiliates.--import {describe, it, expect, beforeEach, afterEach} from 'vitest';-import * as fs from 'node:fs';-import * as path from 'node:path';-import * as os from 'node:os';-import {discoverThemes, writeThemeConfig} from './theme.mjs';--let tmpDir;--beforeEach(() => {- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xds-theme-test-'));-});--afterEach(() => {- fs.rmSync(tmpDir, {recursive: true, force: true});-});--describe('discoverThemes', () => {- it('discovers *Theme.stylex.ts files in packages/theme/src/', () => {- // Simulate monorepo structure: coreDir = packages/core- // themes at packages/theme/src/default/defaultTheme.stylex.ts- const coreDir = path.join(tmpDir, 'packages', 'core');- const themeDir = path.join(tmpDir, 'packages', 'theme', 'src');- const defaultDir = path.join(themeDir, 'default');- const neutralDir = path.join(themeDir, 'neutral');-- fs.mkdirSync(coreDir, {recursive: true});- fs.mkdirSync(defaultDir, {recursive: true});- fs.mkdirSync(neutralDir, {recursive: true});- fs.writeFileSync(path.join(defaultDir, 'defaultTheme.stylex.ts'), '');- fs.writeFileSync(path.join(neutralDir, 'neutralTheme.stylex.ts'), '');-- const result = discoverThemes(coreDir);- expect(result).toEqual([- {name: 'default', exportName: 'defaultTheme'},- {name: 'neutral', exportName: 'neutralTheme'},- ]);- });-- it('discovers *Theme.stylex.ts files in legacy location (core/src/theme/)', () => {- const coreDir = tmpDir;- const themeDir = path.join(coreDir, 'src', 'theme');- fs.mkdirSync(themeDir, {recursive: true});- fs.writeFileSync(path.join(themeDir, 'defaultTheme.stylex.ts'), '');- fs.writeFileSync(path.join(themeDir, 'tokens.stylex.ts'), ''); // not a theme-- const result = discoverThemes(coreDir);- expect(result).toEqual([- {name: 'default', exportName: 'defaultTheme'},- ]);- });-- it('deduplicates themes found in both locations', () => {- const coreDir = path.join(tmpDir, 'packages', 'core');- const legacyDir = path.join(coreDir, 'src', 'theme');- const newDir = path.join(tmpDir, 'packages', 'theme', 'src', 'default');-- fs.mkdirSync(legacyDir, {recursive: true});- fs.mkdirSync(newDir, {recursive: true});- fs.writeFileSync(path.join(legacyDir, 'defaultTheme.stylex.ts'), '');- fs.writeFileSync(path.join(newDir, 'defaultTheme.stylex.ts'), '');-- const result = discoverThemes(coreDir);- expect(result).toHaveLength(1);- expect(result[0].name).toBe('default');- });-- it('returns empty array when no theme dirs exist', () => {- expect(discoverThemes(tmpDir)).toEqual([]);- });-});--describe('writeThemeConfig', () => {- it('writes xds.config.mjs with correct content', () => {- const configPath = writeThemeConfig(tmpDir, 'neutralTheme');-- expect(configPath).toBe(path.join(tmpDir, 'xds.config.mjs'));-- const content = fs.readFileSync(configPath, 'utf-8');- expect(content).toContain("theme: 'neutralTheme'");- expect(content).toContain('XDS Configuration');- });-});