tokenize-css 0.2.1 ā 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/bin/cli.js +73 -53
- package/package.json +1 -1
- package/src/config/defaults.js +13 -0
- package/src/config/loader.js +34 -0
- package/src/parser.js +0 -0
package/bin/cli.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { program } from
|
|
4
|
-
import StyleDictionary from
|
|
5
|
-
import chalk from
|
|
6
|
-
import chokidar from
|
|
7
|
-
import { resolve } from
|
|
8
|
-
import { createTokenStudioConfig } from
|
|
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 =
|
|
11
|
+
async function build(input, output, source = 'token-studio') {
|
|
11
12
|
let config;
|
|
12
13
|
|
|
13
|
-
if (source ===
|
|
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
|
-
|
|
31
|
-
.
|
|
32
|
-
.
|
|
33
|
-
.
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
49
|
-
|
|
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
|
-
|
|
54
|
-
console.log(chalk.yellow(`\n
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
60
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
program
|
|
69
|
+
.name('tokenize')
|
|
70
|
+
.description('Convert Design Tokens to CSS variables')
|
|
71
|
+
.version('0.2.1');
|
|
65
72
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
71
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
@@ -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
|