tokenize-css 0.1.0 → 0.2.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.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/bin/cli.js +58 -21
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -22,6 +22,9 @@ tokenize tokens.json "/path/to/output"
22
22
 
23
23
  # Specify source type
24
24
  tokenize tokens.json dist --source token-studio
25
+
26
+ # Watch mode - rebuild on file changes
27
+ tokenize tokens.json dist --watch
25
28
  ```
26
29
 
27
30
  ### Options
@@ -29,6 +32,7 @@ tokenize tokens.json dist --source token-studio
29
32
  | Option | Description | Default |
30
33
  |--------|-------------|---------|
31
34
  | `-s, --source <type>` | Source type (token-studio, figma-variables) | token-studio |
35
+ | `-w, --watch` | Watch for changes and rebuild automatically | false |
32
36
  | `-V, --version` | Output version | |
33
37
  | `-h, --help` | Display help | |
34
38
 
package/bin/cli.js CHANGED
@@ -1,20 +1,16 @@
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 { resolve } from 'path';
7
- import { createTokenStudioConfig } from '../src/config/token-studio.js';
8
-
9
- async function build(input, output, source = 'token-studio') {
10
- console.log(chalk.blue.bold('\nšŸŽØ tokenize-css\n'));
11
- console.log(chalk.gray(`Source: ${source}`));
12
- console.log(chalk.gray(`Input: ${input}`));
13
- console.log(chalk.gray(`Output: ${output}\n`));
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";
14
9
 
10
+ async function build(input, output, source = "token-studio") {
15
11
  let config;
16
12
 
17
- if (source === 'token-studio') {
13
+ if (source === "token-studio") {
18
14
  config = createTokenStudioConfig(input, output);
19
15
  } else {
20
16
  console.error(chalk.red(`āŒ Source "${source}" not supported yet`));
@@ -24,26 +20,67 @@ async function build(input, output, source = 'token-studio') {
24
20
  try {
25
21
  const sd = new StyleDictionary(config);
26
22
  await sd.buildAllPlatforms();
27
- console.log(chalk.green('āœ… Done!\n'));
23
+ return true;
28
24
  } catch (error) {
29
25
  console.error(chalk.red(`āŒ Error: ${error.message}`));
30
- process.exit(1);
26
+ return false;
31
27
  }
32
28
  }
33
29
 
34
30
  program
35
- .name('tokenize')
36
- .description('Convert Design Tokens to CSS variables')
37
- .version('0.1.0');
31
+ .name("tokenize")
32
+ .description("Convert Design Tokens to CSS variables")
33
+ .version("0.2.0");
38
34
 
39
35
  program
40
- .argument('<input>', 'Input tokens file')
41
- .argument('<output>', 'Output directory')
42
- .option('-s, --source <type>', 'Source type (token-studio, figma-variables)', 'token-studio')
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")
43
44
  .action(async (input, output, options) => {
44
45
  const inputPath = resolve(process.cwd(), input);
45
46
  const outputPath = resolve(process.cwd(), output);
46
- await build(inputPath, outputPath, options.source);
47
+
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}`));
52
+
53
+ if (options.watch) {
54
+ console.log(chalk.yellow(`\nšŸ‘€ Watching for changes...\n`));
55
+ } else {
56
+ console.log("");
57
+ }
58
+
59
+ // Initial build
60
+ const success = await build(inputPath, outputPath, options.source);
61
+
62
+ if (success) {
63
+ console.log(chalk.green("\nāœ… Build complete!\n"));
64
+ }
65
+
66
+ // Watch mode
67
+ if (options.watch) {
68
+ const watcher = chokidar.watch(inputPath, { persistent: true });
69
+
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
+ });
77
+
78
+ process.on("SIGINT", () => {
79
+ console.log(chalk.gray("\n\nšŸ‘‹ Stopping watch mode...\n"));
80
+ watcher.close();
81
+ process.exit(0);
82
+ });
83
+ }
47
84
  });
48
85
 
49
86
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenize-css",
3
- "version": "0.1.0",
3
+ "version": "0.2.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": {
@@ -44,6 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "chalk": "^5.3.0",
47
+ "chokidar": "^3.6.0",
47
48
  "commander": "^12.1.0",
48
49
  "style-dictionary": "^4.3.0"
49
50
  }