Skip to content

Commit

Permalink
fix --write truthness
Browse files Browse the repository at this point in the history
  • Loading branch information
mimarz committed Aug 27, 2024
1 parent 361e7a7 commit 9a4f35e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
7 changes: 4 additions & 3 deletions packages/cli/bin/designsystemet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Argument, createCommand, program } from '@commander-js/extra-typings';
import chalk from 'chalk';

import { write } from 'node:fs';
import { convertToHex } from '../src/colors/index.js';
import { createTokensPackage } from '../src/init/createTokensPackage.js';
import migrations from '../src/migrations/index.js';
Expand Down Expand Up @@ -31,7 +32,7 @@ function makeTokenCommands() {
tokenCmd
.command('create')
.description('Create Designsystemet tokens')
.option('-w, --write [string]', `Output directory for created ${chalk.blue('design-tokens')}`, './design-tokens')
.option('-w, --write [string]', `Output directory for created ${chalk.blue('design-tokens')}`)
.option('-a, --accent <number>', `Accent hex color`)
.option('-n, --neutral <number>', `Neutral hex color`)
.option('-b1, --brand1 <number>', `Brand1 hex color`)
Expand All @@ -41,8 +42,8 @@ function makeTokenCommands() {
.action(async (opts) => {
// const out = typeof opts.out === 'string' ? opts.out : './dist/tokens';
console.log(`Creating tokens with options ${chalk.green(JSON.stringify(opts))}`);
const outPath = typeof opts.write === 'string' ? opts.write : './design-tokens';
const family = typeof opts.fontFamily === 'string' ? opts.fontFamily : 'Inter';
const write = typeof opts.write === 'boolean' ? './design-tokens' : opts.write;

const props = {
colors: {
Expand All @@ -55,7 +56,7 @@ function makeTokenCommands() {
typography: {
family,
},
outPath: outPath,
write,
};

await createTokens(props);
Expand Down
26 changes: 12 additions & 14 deletions packages/cli/src/tokens/create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type TypographyModes = 'primary' | 'secondary';
type CreateTokens = {
colors: Colors;
typography: Typography;
outPath: string;
write?: string;
};

type File = {
Expand Down Expand Up @@ -134,7 +134,7 @@ const generateGlobalTokens = (theme: ColorMode) => {
};

export const createTokens = async (opts: CreateTokens) => {
const { colors, outPath, typography } = opts;
const { colors, write, typography } = opts;

const tokens = {
colors: {
Expand All @@ -150,10 +150,8 @@ export const createTokens = async (opts: CreateTokens) => {
},
};

const write = R.isNotNil(outPath);

if (write) {
const targetDir = path.resolve(process.cwd(), outPath);
if (R.isNotNil(write)) {
const targetDir = path.resolve(process.cwd(), String(write));
await fs.mkdir(targetDir, { recursive: true });

// Generate metadata and themes json for Token Studio and build script
Expand All @@ -170,14 +168,14 @@ export const createTokens = async (opts: CreateTokens) => {
});

const files: File[] = [
generateColorModeFile('light', 'theme', tokens.colors.light.theme, outPath),
generateColorModeFile('light', 'global', tokens.colors.light.global, outPath),
generateColorModeFile('dark', 'theme', tokens.colors.dark.theme, outPath),
generateColorModeFile('dark', 'global', tokens.colors.dark.global, outPath),
generateColorModeFile('contrast', 'theme', tokens.colors.contrast.theme, outPath),
generateColorModeFile('contrast', 'global', tokens.colors.contrast.global, outPath),
generateTypographyFile('primary', 'theme', tokens.typography.primary, outPath),
generateTypographyFile('secondary', 'theme', tokens.typography.primary, outPath),
generateColorModeFile('light', 'theme', tokens.colors.light.theme, targetDir),
generateColorModeFile('light', 'global', tokens.colors.light.global, targetDir),
generateColorModeFile('dark', 'theme', tokens.colors.dark.theme, targetDir),
generateColorModeFile('dark', 'global', tokens.colors.dark.global, targetDir),
generateColorModeFile('contrast', 'theme', tokens.colors.contrast.theme, targetDir),
generateColorModeFile('contrast', 'global', tokens.colors.contrast.global, targetDir),
generateTypographyFile('primary', 'theme', tokens.typography.primary, targetDir),
generateTypographyFile('secondary', 'theme', tokens.typography.primary, targetDir),
];

for (const file of files) {
Expand Down

0 comments on commit 9a4f35e

Please sign in to comment.