tokenize-css 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,16 +3,19 @@
3
3
  CLI tool to convert Design Tokens (Token Studio) to CSS variables.
4
4
 
5
5
  ## Installation
6
+
6
7
  ```bash
7
8
  npm install -g tokenize-css
8
9
  ```
9
10
 
10
11
  ## Usage
12
+
11
13
  ```bash
12
14
  tokenize <input> <output> [options]
13
15
  ```
14
16
 
15
17
  ### Examples
18
+
16
19
  ```bash
17
20
  # Basic usage
18
21
  tokenize tokens.json dist
@@ -29,12 +32,12 @@ tokenize tokens.json dist --watch
29
32
 
30
33
  ### Options
31
34
 
32
- | Option | Description | Default |
33
- |--------|-------------|---------|
35
+ | Option | Description | Default |
36
+ | --------------------- | ------------------------------------------- | ------------ |
34
37
  | `-s, --source <type>` | Source type (token-studio, figma-variables) | token-studio |
35
- | `-w, --watch` | Watch for changes and rebuild automatically | false |
36
- | `-V, --version` | Output version | |
37
- | `-h, --help` | Display help | |
38
+ | `-w, --watch` | Watch for changes and rebuild automatically | false |
39
+ | `-V, --version` | Output version | |
40
+ | `-h, --help` | Display help | |
38
41
 
39
42
  ## Supported Sources
40
43
 
package/bin/cli.js CHANGED
@@ -1,16 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { program } from "commander";
4
- import StyleDictionary from "style-dictionary";
5
- import chalk from "chalk";
6
- import chokidar from "chokidar";
7
- import { resolve } from "path";
8
- import { createTokenStudioConfig } from "../src/config/token-studio.js";
3
+ import { program } from 'commander';
4
+ import StyleDictionary from 'style-dictionary';
5
+ import chalk from 'chalk';
6
+ import chokidar from 'chokidar';
7
+ import { resolve } from 'path';
8
+ import { createTokenStudioConfig } from '../src/config/token-studio.js';
9
+ import { loadConfig } from '../src/config/loader.js';
9
10
 
10
- async function build(input, output, source = "token-studio") {
11
+ async function build(input, output, source = 'token-studio') {
11
12
  let config;
12
13
 
13
- if (source === "token-studio") {
14
+ if (source === 'token-studio') {
14
15
  config = createTokenStudioConfig(input, output);
15
16
  } else {
16
17
  console.error(chalk.red(`āŒ Source "${source}" not supported yet`));
@@ -27,60 +28,79 @@ async function build(input, output, source = "token-studio") {
27
28
  }
28
29
  }
29
30
 
30
- program
31
- .name("tokenize")
32
- .description("Convert Design Tokens to CSS variables")
33
- .version("0.2.0");
31
+ async function run(inputPath, outputPath, options) {
32
+ console.log(chalk.blue.bold('\nšŸŽØ tokenize-css\n'));
33
+ console.log(chalk.gray(`Source: ${options.source}`));
34
+ console.log(chalk.gray(`Input: ${inputPath}`));
35
+ console.log(chalk.gray(`Output: ${outputPath}`));
36
+
37
+ if (options.watch) {
38
+ console.log(chalk.yellow(`\nšŸ‘€ Watching for changes...\n`));
39
+ } else {
40
+ console.log('');
41
+ }
34
42
 
35
- program
36
- .argument("<input>", "Input tokens file")
37
- .argument("<output>", "Output directory")
38
- .option(
39
- "-s, --source <type>",
40
- "Source type (token-studio, figma-variables)",
41
- "token-studio"
42
- )
43
- .option("-w, --watch", "Watch for changes and rebuild automatically")
44
- .action(async (input, output, options) => {
45
- const inputPath = resolve(process.cwd(), input);
46
- const outputPath = resolve(process.cwd(), output);
43
+ const success = await build(inputPath, outputPath, options.source);
44
+
45
+ if (success) {
46
+ console.log(chalk.green('\nāœ… Build complete!\n'));
47
+ }
47
48
 
48
- console.log(chalk.blue.bold("\nšŸŽØ tokenize-css\n"));
49
- console.log(chalk.gray(`Source: ${options.source}`));
50
- console.log(chalk.gray(`Input: ${inputPath}`));
51
- console.log(chalk.gray(`Output: ${outputPath}`));
49
+ if (options.watch) {
50
+ const watcher = chokidar.watch(inputPath, { persistent: true });
52
51
 
53
- if (options.watch) {
54
- console.log(chalk.yellow(`\nšŸ‘€ Watching for changes...\n`));
55
- } else {
56
- console.log("");
57
- }
52
+ watcher.on('change', async () => {
53
+ console.log(chalk.yellow(`\nšŸ”„ File changed, rebuilding...\n`));
54
+ const success = await build(inputPath, outputPath, options.source);
55
+ if (success) {
56
+ console.log(chalk.green('āœ… Build complete!\n'));
57
+ }
58
+ });
58
59
 
59
- // Initial build
60
- const success = await build(inputPath, outputPath, options.source);
60
+ process.on('SIGINT', () => {
61
+ console.log(chalk.gray('\n\nšŸ‘‹ Stopping watch mode...\n'));
62
+ watcher.close();
63
+ process.exit(0);
64
+ });
65
+ }
66
+ }
61
67
 
62
- if (success) {
63
- console.log(chalk.green("\nāœ… Build complete!\n"));
64
- }
68
+ program
69
+ .name('tokenize')
70
+ .description('Convert Design Tokens to CSS variables')
71
+ .version('0.2.1');
65
72
 
66
- // Watch mode
67
- if (options.watch) {
68
- const watcher = chokidar.watch(inputPath, { persistent: true });
73
+ program
74
+ .argument('[input]', 'Input tokens file')
75
+ .argument('[output]', 'Output directory')
76
+ .option('-c, --config <path>', 'Path to config file')
77
+ .option('-s, --source <type>', 'Source type (token-studio, figma-variables)', 'token-studio')
78
+ .option('-w, --watch', 'Watch for changes and rebuild automatically')
79
+ .action(async (input, output, options) => {
80
+ let inputPath, outputPath, source, watch;
69
81
 
70
- watcher.on("change", async () => {
71
- console.log(chalk.yellow(`\nšŸ”„ File changed, rebuilding...\n`));
72
- const success = await build(inputPath, outputPath, options.source);
73
- if (success) {
74
- console.log(chalk.green("āœ… Build complete!\n"));
75
- }
76
- });
82
+ // Try to load config file
83
+ const config = await loadConfig(options.config);
77
84
 
78
- process.on("SIGINT", () => {
79
- console.log(chalk.gray("\n\nšŸ‘‹ Stopping watch mode...\n"));
80
- watcher.close();
81
- process.exit(0);
82
- });
85
+ if (config) {
86
+ console.log(chalk.gray(`Using config: ${config.configPath || options.config}\n`));
87
+ inputPath = resolve(process.cwd(), input || config.input);
88
+ outputPath = resolve(process.cwd(), output || config.output);
89
+ source = options.source || config.source;
90
+ watch = options.watch || config.watch;
91
+ } else if (input && output) {
92
+ inputPath = resolve(process.cwd(), input);
93
+ outputPath = resolve(process.cwd(), output);
94
+ source = options.source;
95
+ watch = options.watch;
96
+ } else {
97
+ console.error(chalk.red('āŒ Error: No config file found and no input/output provided.'));
98
+ console.log(chalk.gray('\nUsage: tokenize <input> <output>'));
99
+ console.log(chalk.gray(' or: create tokenize.config.js\n'));
100
+ process.exit(1);
83
101
  }
102
+
103
+ await run(inputPath, outputPath, { source, watch });
84
104
  });
85
105
 
86
106
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenize-css",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "CLI tool to convert Design Tokens (Token Studio, Figma Variables) to CSS variables using Style Dictionary",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,13 @@
1
+ export const defaultConfig = {
2
+ source: 'token-studio',
3
+ input: './tokens.json',
4
+ output: './dist',
5
+ watch: false,
6
+ files: {
7
+ colors: 'colors.css',
8
+ spacing: 'spacing.css',
9
+ typography: 'typography.css',
10
+ shadows: 'shadows.css',
11
+ all: 'tokens.css'
12
+ }
13
+ };
@@ -0,0 +1,34 @@
1
+ import { existsSync } from 'fs';
2
+ import { resolve } from 'path';
3
+ import { pathToFileURL } from 'url';
4
+ import { defaultConfig } from './defaults.js';
5
+
6
+ const CONFIG_FILES = [
7
+ 'tokenize.config.js',
8
+ 'tokenize.config.mjs'
9
+ ];
10
+
11
+ export async function loadConfig(customPath) {
12
+ const cwd = process.cwd();
13
+
14
+ // Custom path provided
15
+ if (customPath) {
16
+ const fullPath = resolve(cwd, customPath);
17
+ if (!existsSync(fullPath)) {
18
+ throw new Error(`Config file not found: ${customPath}`);
19
+ }
20
+ const userConfig = await import(pathToFileURL(fullPath));
21
+ return { ...defaultConfig, ...userConfig.default };
22
+ }
23
+
24
+ // Search for config file
25
+ for (const fileName of CONFIG_FILES) {
26
+ const fullPath = resolve(cwd, fileName);
27
+ if (existsSync(fullPath)) {
28
+ const userConfig = await import(pathToFileURL(fullPath));
29
+ return { ...defaultConfig, ...userConfig.default, configPath: fullPath };
30
+ }
31
+ }
32
+
33
+ return null;
34
+ }
package/src/parser.js DELETED
File without changes