tokenize-css 0.1.0 ā 0.2.1
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 +11 -4
- package/bin/cli.js +58 -21
- package/package.json +2 -1
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
|
|
@@ -22,15 +25,19 @@ tokenize tokens.json "/path/to/output"
|
|
|
22
25
|
|
|
23
26
|
# Specify source type
|
|
24
27
|
tokenize tokens.json dist --source token-studio
|
|
28
|
+
|
|
29
|
+
# Watch mode - rebuild on file changes
|
|
30
|
+
tokenize tokens.json dist --watch
|
|
25
31
|
```
|
|
26
32
|
|
|
27
33
|
### Options
|
|
28
34
|
|
|
29
|
-
| Option
|
|
30
|
-
|
|
35
|
+
| Option | Description | Default |
|
|
36
|
+
| --------------------- | ------------------------------------------- | ------------ |
|
|
31
37
|
| `-s, --source <type>` | Source type (token-studio, figma-variables) | token-studio |
|
|
32
|
-
| `-
|
|
33
|
-
| `-
|
|
38
|
+
| `-w, --watch` | Watch for changes and rebuild automatically | false |
|
|
39
|
+
| `-V, --version` | Output version | |
|
|
40
|
+
| `-h, --help` | Display help | |
|
|
34
41
|
|
|
35
42
|
## Supported Sources
|
|
36
43
|
|
package/bin/cli.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { program } from
|
|
4
|
-
import StyleDictionary from
|
|
5
|
-
import chalk from
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
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 ===
|
|
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
|
-
|
|
23
|
+
return true;
|
|
28
24
|
} catch (error) {
|
|
29
25
|
console.error(chalk.red(`ā Error: ${error.message}`));
|
|
30
|
-
|
|
26
|
+
return false;
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
|
|
34
30
|
program
|
|
35
|
-
.name(
|
|
36
|
-
.description(
|
|
37
|
-
.version(
|
|
31
|
+
.name("tokenize")
|
|
32
|
+
.description("Convert Design Tokens to CSS variables")
|
|
33
|
+
.version("0.2.0");
|
|
38
34
|
|
|
39
35
|
program
|
|
40
|
-
.argument(
|
|
41
|
-
.argument(
|
|
42
|
-
.option(
|
|
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
|
-
|
|
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
|
|
3
|
+
"version": "0.2.1",
|
|
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
|
}
|