Skip to content

Commit

Permalink
changed cli tokens command
Browse files Browse the repository at this point in the history
  • Loading branch information
mimarz committed Aug 22, 2024
1 parent f608b29 commit 96484ea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
41 changes: 23 additions & 18 deletions packages/cli/bin/designsystemet.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
#!/usr/bin/env node
import { Argument, program } from '@commander-js/extra-typings';
import { Argument, createCommand, program } from '@commander-js/extra-typings';
import chalk from 'chalk';

import { createTokensPackage } from '../src/init/createTokensPackage.js';
import migrations from '../src/migrations/index.js';
import { run } from '../src/tokens/build/index.js';

program.name('Designsystemet').description('CLI for working with Designsystemet');
program.name('Designsystemet').description('CLI for working with Designsystemet').showHelpAfterError();

program
.command('tokens')
.showHelpAfterError()
.description('run Designsystemet token builder')
.option('-t, --tokens [string]', `Path to ${chalk.blue('design-tokens')}`, './design-tokens')
.option('-o, --out [string]', `Output directory for built ${chalk.blue('design-tokens')}`, './dist/tokens')
.option('-p, --preview', 'Generate preview token.ts files', false)
.action((opts) => {
const tokens = typeof opts.tokens === 'string' ? opts.tokens : './design-tokens';
const out = typeof opts.out === 'string' ? opts.out : './dist/tokens';
const preview = opts.preview;
console.log(`Bulding tokens in ${chalk.green(tokens)}`);
return run({ tokens, out, preview });
});
function makeTokenCommands() {
const tokenCmd = createCommand('tokens');

tokenCmd
.command('build')
.description('run Designsystemet token builder')
.option('-t, --tokens [string]', `Path to ${chalk.blue('design-tokens')}`, './design-tokens')
.option('-o, --out [string]', `Output directory for built ${chalk.blue('design-tokens')}`, './dist/tokens')
.option('-p, --preview', 'Generate preview token.ts files', false)
.action((opts) => {
const tokens = typeof opts.tokens === 'string' ? opts.tokens : './design-tokens';
const out = typeof opts.out === 'string' ? opts.out : './dist/tokens';
const preview = opts.preview;
console.log(`Bulding tokens in ${chalk.green(tokens)}`);
return run({ tokens, out, preview });
});

return tokenCmd;
}

program.addCommand(makeTokenCommands());

program
.command('migrate')
.showHelpAfterError()
.description('run a Designsystemet migration')
.addArgument(new Argument('[migration]', 'Available migrations').choices(Object.keys(migrations)))
.option('-l --list', 'List available migrations')
Expand Down Expand Up @@ -55,7 +61,6 @@ program

program
.command('init')
.showHelpAfterError()
.description('create an initial token structure for Designsystemet')
.addArgument(new Argument('<targetDir>', 'Target directory for the generated code'))
.action(async (targetDir) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
},
"scripts": {
"designsystemet": "tsx ./bin/designsystemet.ts",
"build:tokens": "yarn clean:theme && yarn designsystemet tokens -p -t ../../design-tokens -o ../../packages/theme/brand",
"build:tokens:debug": "yarn clean:theme && tsx --inspect-brk ./bin/designsystemet.ts tokens -p -t ../../design-tokens -o ../../packages/theme/brand",
"build:tokens": "yarn clean:theme && yarn designsystemet tokens build -p -t ../../design-tokens -o ../../packages/theme/brand",
"build:tokens:debug": "yarn clean:theme && tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../design-tokens -o ../../packages/theme/brand",
"build": "tsup && yarn build:types",
"build:swc": "yarn clean && swc src bin --copy-files -d dist && yarn build:types",
"build:types": "tsc --emitDeclarationOnly --declaration",
Expand Down

0 comments on commit 96484ea

Please sign in to comment.