css-typed-vars 0.2.0 → 0.3.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 +9 -3
- package/dist/{chunk-6HASMGMT.js → chunk-4VL6W5GO.js} +28 -9
- package/dist/{chunk-2AQHBHAG.js → chunk-B57NHMQD.js} +4 -4
- package/dist/chunk-S2QNFCPF.js +29 -0
- package/dist/cli.cjs +87 -20
- package/dist/cli.js +20 -16
- package/dist/esbuild.cjs +26 -10
- package/dist/esbuild.d.cts +1 -0
- package/dist/esbuild.d.ts +1 -0
- package/dist/esbuild.js +2 -2
- package/dist/generator-Ba8XeISD.d.cts +6 -0
- package/dist/generator-Ba8XeISD.d.ts +6 -0
- package/dist/index.cjs +59 -8
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +8 -11
- package/dist/rollup.cjs +26 -10
- package/dist/rollup.d.cts +1 -0
- package/dist/rollup.d.ts +1 -0
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +26 -10
- package/dist/unplugin.d.cts +2 -0
- package/dist/unplugin.d.ts +2 -0
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +26 -10
- package/dist/vite.d.cts +1 -0
- package/dist/vite.d.ts +1 -0
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +26 -10
- package/dist/webpack.d.cts +1 -0
- package/dist/webpack.d.ts +1 -0
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -110,16 +110,19 @@ npx css-typed-vars --input "src/styles/**/*.{css,scss}" --output src/cssVars.ts
|
|
|
110
110
|
|
|
111
111
|
```sh
|
|
112
112
|
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --exclude "**/vendor/**"
|
|
113
|
-
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --prefix theme
|
|
113
|
+
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --prefix theme --naming snake
|
|
114
|
+
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.js # generates .js + .d.ts
|
|
114
115
|
```
|
|
115
116
|
|
|
116
117
|
| Flag | Description |
|
|
117
118
|
|------|-------------|
|
|
118
119
|
| `--input` | Glob pattern for CSS/SCSS/Less files |
|
|
119
|
-
| `--output` |
|
|
120
|
+
| `--output` | Output file. `.ts` → TypeScript, `.js` → JavaScript + `.d.ts` alongside |
|
|
120
121
|
| `--exclude` | Glob pattern for files to exclude (single value; use config file for multiple) |
|
|
121
122
|
| `--prefix` | Prefix for generated keys: `--prefix theme` → `themeColorPrimary` |
|
|
123
|
+
| `--naming` | Key naming: `camelCase` (default), `snake`, `kebab` |
|
|
122
124
|
| `--watch` | Watch for file changes and regenerate |
|
|
125
|
+
| `--version`, `-v` | Print the version number and exit |
|
|
123
126
|
|
|
124
127
|
CLI flags override values from the config file.
|
|
125
128
|
|
|
@@ -140,6 +143,7 @@ export default {
|
|
|
140
143
|
output: 'src/cssVars.ts',
|
|
141
144
|
exclude: ['**/vendor/**', '**/node_modules/**'],
|
|
142
145
|
prefix: 'theme',
|
|
146
|
+
naming: 'snake', // 'camelCase' | 'snake' | 'kebab'
|
|
143
147
|
};
|
|
144
148
|
```
|
|
145
149
|
|
|
@@ -236,6 +240,7 @@ Turbopack does not yet have a public plugin API for virtual modules. Use the CLI
|
|
|
236
240
|
| `input` | `string \| string[]` | — | Glob pattern for CSS/SCSS/Less files |
|
|
237
241
|
| `exclude` | `string \| string[]` | — | Glob pattern(s) for files to exclude |
|
|
238
242
|
| `prefix` | `string` | — | Prefix for generated keys: `'theme'` → `themeColorPrimary` |
|
|
243
|
+
| `naming` | `'camelCase' \| 'snake' \| 'kebab'` | `'camelCase'` | Key naming convention |
|
|
239
244
|
| `dts` | `string \| false` | inside `node_modules` | Path to write type declarations. `false` to skip |
|
|
240
245
|
|
|
241
246
|
---
|
|
@@ -288,9 +293,10 @@ import { generate } from 'css-typed-vars';
|
|
|
288
293
|
|
|
289
294
|
await generate({
|
|
290
295
|
input: 'src/styles/**/*.{css,scss}',
|
|
291
|
-
output: 'src/cssVars.ts',
|
|
296
|
+
output: 'src/cssVars.ts', // or 'src/cssVars.js' → generates .js + .d.ts
|
|
292
297
|
exclude: ['**/vendor/**'],
|
|
293
298
|
prefix: 'theme',
|
|
299
|
+
naming: 'snake', // 'camelCase' | 'snake' | 'kebab'
|
|
294
300
|
});
|
|
295
301
|
```
|
|
296
302
|
|
|
@@ -40,15 +40,27 @@ async function scanVarNames(patterns, exclude) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// src/generator.ts
|
|
43
|
-
function
|
|
44
|
-
|
|
43
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
44
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
45
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
46
|
+
if (naming === "kebab") return stripped;
|
|
47
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
45
48
|
}
|
|
46
|
-
function applyPrefix(key, prefix) {
|
|
49
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
47
50
|
if (!prefix) return key;
|
|
51
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
52
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
48
53
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
49
54
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
55
|
+
function formatKey(key, naming = "camelCase") {
|
|
56
|
+
if (naming === "kebab") return `'${key}'`;
|
|
57
|
+
return key;
|
|
58
|
+
}
|
|
59
|
+
function generateCode(varNames, prefix, naming) {
|
|
60
|
+
const entries = varNames.map((name) => {
|
|
61
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
62
|
+
return ` ${key}: 'var(${name})',`;
|
|
63
|
+
});
|
|
52
64
|
return [
|
|
53
65
|
"// generated \u2014 do not edit",
|
|
54
66
|
"export const cssVars = {",
|
|
@@ -59,17 +71,24 @@ function generateCode(varNames, prefix) {
|
|
|
59
71
|
""
|
|
60
72
|
].join("\n");
|
|
61
73
|
}
|
|
62
|
-
function generateJs(varNames, prefix) {
|
|
63
|
-
const entries = varNames.map((name) =>
|
|
74
|
+
function generateJs(varNames, prefix, naming) {
|
|
75
|
+
const entries = varNames.map((name) => {
|
|
76
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
77
|
+
return ` ${key}: 'var(${name})',`;
|
|
78
|
+
});
|
|
64
79
|
return [
|
|
80
|
+
"// generated \u2014 do not edit",
|
|
65
81
|
"export const cssVars = {",
|
|
66
82
|
...entries,
|
|
67
83
|
"};",
|
|
68
84
|
""
|
|
69
85
|
].join("\n");
|
|
70
86
|
}
|
|
71
|
-
function generateDeclaration(varNames, prefix) {
|
|
72
|
-
const entries = varNames.map((name) =>
|
|
87
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
88
|
+
const entries = varNames.map((name) => {
|
|
89
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
90
|
+
return ` ${key}: 'var(${name})';`;
|
|
91
|
+
});
|
|
73
92
|
return [
|
|
74
93
|
"export declare const cssVars: {",
|
|
75
94
|
...entries,
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
generateDeclaration,
|
|
4
4
|
generateJs,
|
|
5
5
|
scanVarNames
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-4VL6W5GO.js";
|
|
7
7
|
|
|
8
8
|
// src/unplugin.ts
|
|
9
9
|
import { createUnplugin } from "unplugin";
|
|
@@ -25,7 +25,7 @@ var unplugin_default = createUnplugin((options) => ({
|
|
|
25
25
|
const names = await scanVarNames(options.input, options.exclude);
|
|
26
26
|
const dtsPath = getDtsPath(options);
|
|
27
27
|
if (dtsPath) {
|
|
28
|
-
await writeFile(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
28
|
+
await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
29
29
|
}
|
|
30
30
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
31
31
|
if (mod) {
|
|
@@ -39,7 +39,7 @@ var unplugin_default = createUnplugin((options) => ({
|
|
|
39
39
|
const dtsPath = getDtsPath(options);
|
|
40
40
|
if (!dtsPath) return;
|
|
41
41
|
const names = await scanVarNames(options.input, options.exclude);
|
|
42
|
-
await writeFile(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
42
|
+
await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
43
43
|
},
|
|
44
44
|
resolveId(id) {
|
|
45
45
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
@@ -47,7 +47,7 @@ var unplugin_default = createUnplugin((options) => ({
|
|
|
47
47
|
async load(id) {
|
|
48
48
|
if (id === RESOLVED_ID) {
|
|
49
49
|
const names = await scanVarNames(options.input, options.exclude);
|
|
50
|
-
return generateJs(names, options.prefix);
|
|
50
|
+
return generateJs(names, options.prefix, options.naming);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
}));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateCode,
|
|
3
|
+
generateDeclaration,
|
|
4
|
+
generateJs,
|
|
5
|
+
scanVarNames
|
|
6
|
+
} from "./chunk-4VL6W5GO.js";
|
|
7
|
+
|
|
8
|
+
// src/index.ts
|
|
9
|
+
import { writeFile, mkdir } from "fs/promises";
|
|
10
|
+
import { dirname, resolve } from "path";
|
|
11
|
+
async function generate(options) {
|
|
12
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
13
|
+
if (names.length === 0) {
|
|
14
|
+
console.warn("css-typed-vars: no CSS custom properties found.");
|
|
15
|
+
}
|
|
16
|
+
const outPath = resolve(options.output);
|
|
17
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
18
|
+
if (options.output.endsWith(".js")) {
|
|
19
|
+
await writeFile(outPath, generateJs(names, options.prefix, options.naming), "utf8");
|
|
20
|
+
const dtsPath = outPath.replace(/\.js$/, ".d.ts");
|
|
21
|
+
await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
22
|
+
} else {
|
|
23
|
+
await writeFile(outPath, generateCode(names, options.prefix, options.naming), "utf8");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
generate
|
|
29
|
+
};
|
package/dist/cli.cjs
CHANGED
|
@@ -23,12 +23,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
mod
|
|
24
24
|
));
|
|
25
25
|
|
|
26
|
+
// node_modules/tsup/assets/cjs_shims.js
|
|
27
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
28
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
29
|
+
|
|
26
30
|
// src/cli.ts
|
|
27
|
-
var
|
|
28
|
-
var
|
|
31
|
+
var import_promises3 = require("fs/promises");
|
|
32
|
+
var import_node_path2 = require("path");
|
|
29
33
|
var import_node_url = require("url");
|
|
30
34
|
var import_chokidar = require("chokidar");
|
|
31
35
|
|
|
36
|
+
// src/index.ts
|
|
37
|
+
var import_promises2 = require("fs/promises");
|
|
38
|
+
var import_node_path = require("path");
|
|
39
|
+
|
|
32
40
|
// src/scanner.ts
|
|
33
41
|
var import_promises = require("fs/promises");
|
|
34
42
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
@@ -66,15 +74,27 @@ async function scanVarNames(patterns, exclude) {
|
|
|
66
74
|
}
|
|
67
75
|
|
|
68
76
|
// src/generator.ts
|
|
69
|
-
function
|
|
70
|
-
|
|
77
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
78
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
79
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
80
|
+
if (naming === "kebab") return stripped;
|
|
81
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
71
82
|
}
|
|
72
|
-
function applyPrefix(key, prefix) {
|
|
83
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
73
84
|
if (!prefix) return key;
|
|
85
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
86
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
74
87
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
75
88
|
}
|
|
76
|
-
function
|
|
77
|
-
|
|
89
|
+
function formatKey(key, naming = "camelCase") {
|
|
90
|
+
if (naming === "kebab") return `'${key}'`;
|
|
91
|
+
return key;
|
|
92
|
+
}
|
|
93
|
+
function generateCode(varNames, prefix, naming) {
|
|
94
|
+
const entries = varNames.map((name) => {
|
|
95
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
96
|
+
return ` ${key}: 'var(${name})',`;
|
|
97
|
+
});
|
|
78
98
|
return [
|
|
79
99
|
"// generated \u2014 do not edit",
|
|
80
100
|
"export const cssVars = {",
|
|
@@ -85,6 +105,49 @@ function generateCode(varNames, prefix) {
|
|
|
85
105
|
""
|
|
86
106
|
].join("\n");
|
|
87
107
|
}
|
|
108
|
+
function generateJs(varNames, prefix, naming) {
|
|
109
|
+
const entries = varNames.map((name) => {
|
|
110
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
111
|
+
return ` ${key}: 'var(${name})',`;
|
|
112
|
+
});
|
|
113
|
+
return [
|
|
114
|
+
"// generated \u2014 do not edit",
|
|
115
|
+
"export const cssVars = {",
|
|
116
|
+
...entries,
|
|
117
|
+
"};",
|
|
118
|
+
""
|
|
119
|
+
].join("\n");
|
|
120
|
+
}
|
|
121
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
122
|
+
const entries = varNames.map((name) => {
|
|
123
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
124
|
+
return ` ${key}: 'var(${name})';`;
|
|
125
|
+
});
|
|
126
|
+
return [
|
|
127
|
+
"export declare const cssVars: {",
|
|
128
|
+
...entries,
|
|
129
|
+
"};",
|
|
130
|
+
"export type CssVarName = keyof typeof cssVars;",
|
|
131
|
+
""
|
|
132
|
+
].join("\n");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/index.ts
|
|
136
|
+
async function generate(options) {
|
|
137
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
138
|
+
if (names.length === 0) {
|
|
139
|
+
console.warn("css-typed-vars: no CSS custom properties found.");
|
|
140
|
+
}
|
|
141
|
+
const outPath = (0, import_node_path.resolve)(options.output);
|
|
142
|
+
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
143
|
+
if (options.output.endsWith(".js")) {
|
|
144
|
+
await (0, import_promises2.writeFile)(outPath, generateJs(names, options.prefix, options.naming), "utf8");
|
|
145
|
+
const dtsPath = outPath.replace(/\.js$/, ".d.ts");
|
|
146
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
147
|
+
} else {
|
|
148
|
+
await (0, import_promises2.writeFile)(outPath, generateCode(names, options.prefix, options.naming), "utf8");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
88
151
|
|
|
89
152
|
// src/cli.ts
|
|
90
153
|
var args = process.argv.slice(2);
|
|
@@ -100,10 +163,10 @@ async function loadConfig() {
|
|
|
100
163
|
"css-typed-vars.config.json"
|
|
101
164
|
];
|
|
102
165
|
for (const file of candidates) {
|
|
103
|
-
const path = (0,
|
|
166
|
+
const path = (0, import_node_path2.resolve)(process.cwd(), file);
|
|
104
167
|
try {
|
|
105
168
|
if (file.endsWith(".json")) {
|
|
106
|
-
const content = await (0,
|
|
169
|
+
const content = await (0, import_promises3.readFile)(path, "utf8");
|
|
107
170
|
return JSON.parse(content);
|
|
108
171
|
} else {
|
|
109
172
|
const mod = await import((0, import_node_url.pathToFileURL)(path).href);
|
|
@@ -114,31 +177,35 @@ async function loadConfig() {
|
|
|
114
177
|
}
|
|
115
178
|
return {};
|
|
116
179
|
}
|
|
117
|
-
async function run(input, output, exclude, prefix) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
await (0, import_promises2.mkdir)((0, import_node_path.dirname)((0, import_node_path.resolve)(output)), { recursive: true });
|
|
121
|
-
await (0, import_promises2.writeFile)(output, code, "utf8");
|
|
122
|
-
console.log(`Generated ${names.length} variables \u2192 ${output}`);
|
|
180
|
+
async function run(input, output, exclude, prefix, naming) {
|
|
181
|
+
await generate({ input, output, exclude, prefix, naming });
|
|
182
|
+
console.log(`Generated \u2192 ${output}`);
|
|
123
183
|
}
|
|
124
184
|
async function main() {
|
|
185
|
+
if (args.includes("--version") || args.includes("-v")) {
|
|
186
|
+
const pkg = JSON.parse(await (0, import_promises3.readFile)(new URL("../package.json", importMetaUrl), "utf8"));
|
|
187
|
+
console.log(pkg.version);
|
|
188
|
+
process.exit(0);
|
|
189
|
+
}
|
|
125
190
|
const config = await loadConfig();
|
|
126
191
|
const input = getArg("--input") ?? config.input;
|
|
127
192
|
const output = getArg("--output") ?? config.output;
|
|
128
193
|
const exclude = getArg("--exclude") ?? config.exclude;
|
|
129
194
|
const prefix = getArg("--prefix") ?? config.prefix;
|
|
195
|
+
const naming = getArg("--naming") ?? config.naming;
|
|
130
196
|
if (!input || !output) {
|
|
131
197
|
console.error("Usage: css-typed-vars --input <glob> --output <file> [--watch]");
|
|
132
198
|
console.error("Or add a css-typed-vars.config.js file with input and output fields.");
|
|
133
199
|
process.exit(1);
|
|
134
200
|
}
|
|
135
|
-
await run(input, output, exclude, prefix);
|
|
201
|
+
await run(input, output, exclude, prefix, naming);
|
|
136
202
|
if (watchMode) {
|
|
137
203
|
const patterns = Array.isArray(input) ? input : [input];
|
|
138
|
-
|
|
139
|
-
console.log(
|
|
140
|
-
run(input, output, exclude, prefix).catch(console.error);
|
|
141
|
-
}
|
|
204
|
+
const makeHandler = (label) => (file) => {
|
|
205
|
+
console.log(`${label}: ${file}`);
|
|
206
|
+
run(input, output, exclude, prefix, naming).catch(console.error);
|
|
207
|
+
};
|
|
208
|
+
(0, import_chokidar.watch)(patterns).on("change", makeHandler("Changed")).on("add", makeHandler("Added")).on("unlink", makeHandler("Removed"));
|
|
142
209
|
console.log("Watching for changes...");
|
|
143
210
|
}
|
|
144
211
|
}
|
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
generate
|
|
4
|
+
} from "./chunk-S2QNFCPF.js";
|
|
5
|
+
import "./chunk-4VL6W5GO.js";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
8
|
-
import { readFile
|
|
9
|
-
import { resolve
|
|
8
|
+
import { readFile } from "fs/promises";
|
|
9
|
+
import { resolve } from "path";
|
|
10
10
|
import { pathToFileURL } from "url";
|
|
11
11
|
import { watch } from "chokidar";
|
|
12
12
|
var args = process.argv.slice(2);
|
|
@@ -36,31 +36,35 @@ async function loadConfig() {
|
|
|
36
36
|
}
|
|
37
37
|
return {};
|
|
38
38
|
}
|
|
39
|
-
async function run(input, output, exclude, prefix) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
await mkdir(dirname(resolve(output)), { recursive: true });
|
|
43
|
-
await writeFile(output, code, "utf8");
|
|
44
|
-
console.log(`Generated ${names.length} variables \u2192 ${output}`);
|
|
39
|
+
async function run(input, output, exclude, prefix, naming) {
|
|
40
|
+
await generate({ input, output, exclude, prefix, naming });
|
|
41
|
+
console.log(`Generated \u2192 ${output}`);
|
|
45
42
|
}
|
|
46
43
|
async function main() {
|
|
44
|
+
if (args.includes("--version") || args.includes("-v")) {
|
|
45
|
+
const pkg = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"));
|
|
46
|
+
console.log(pkg.version);
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
47
49
|
const config = await loadConfig();
|
|
48
50
|
const input = getArg("--input") ?? config.input;
|
|
49
51
|
const output = getArg("--output") ?? config.output;
|
|
50
52
|
const exclude = getArg("--exclude") ?? config.exclude;
|
|
51
53
|
const prefix = getArg("--prefix") ?? config.prefix;
|
|
54
|
+
const naming = getArg("--naming") ?? config.naming;
|
|
52
55
|
if (!input || !output) {
|
|
53
56
|
console.error("Usage: css-typed-vars --input <glob> --output <file> [--watch]");
|
|
54
57
|
console.error("Or add a css-typed-vars.config.js file with input and output fields.");
|
|
55
58
|
process.exit(1);
|
|
56
59
|
}
|
|
57
|
-
await run(input, output, exclude, prefix);
|
|
60
|
+
await run(input, output, exclude, prefix, naming);
|
|
58
61
|
if (watchMode) {
|
|
59
62
|
const patterns = Array.isArray(input) ? input : [input];
|
|
60
|
-
|
|
61
|
-
console.log(
|
|
62
|
-
run(input, output, exclude, prefix).catch(console.error);
|
|
63
|
-
}
|
|
63
|
+
const makeHandler = (label) => (file) => {
|
|
64
|
+
console.log(`${label}: ${file}`);
|
|
65
|
+
run(input, output, exclude, prefix, naming).catch(console.error);
|
|
66
|
+
};
|
|
67
|
+
watch(patterns).on("change", makeHandler("Changed")).on("add", makeHandler("Added")).on("unlink", makeHandler("Removed"));
|
|
64
68
|
console.log("Watching for changes...");
|
|
65
69
|
}
|
|
66
70
|
}
|
package/dist/esbuild.cjs
CHANGED
|
@@ -76,24 +76,40 @@ async function scanVarNames(patterns, exclude) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/generator.ts
|
|
79
|
-
function
|
|
80
|
-
|
|
79
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
80
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
81
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
82
|
+
if (naming === "kebab") return stripped;
|
|
83
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
81
84
|
}
|
|
82
|
-
function applyPrefix(key, prefix) {
|
|
85
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
83
86
|
if (!prefix) return key;
|
|
87
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
88
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
84
89
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
90
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
91
|
+
function formatKey(key, naming = "camelCase") {
|
|
92
|
+
if (naming === "kebab") return `'${key}'`;
|
|
93
|
+
return key;
|
|
94
|
+
}
|
|
95
|
+
function generateJs(varNames, prefix, naming) {
|
|
96
|
+
const entries = varNames.map((name) => {
|
|
97
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
98
|
+
return ` ${key}: 'var(${name})',`;
|
|
99
|
+
});
|
|
88
100
|
return [
|
|
101
|
+
"// generated \u2014 do not edit",
|
|
89
102
|
"export const cssVars = {",
|
|
90
103
|
...entries,
|
|
91
104
|
"};",
|
|
92
105
|
""
|
|
93
106
|
].join("\n");
|
|
94
107
|
}
|
|
95
|
-
function generateDeclaration(varNames, prefix) {
|
|
96
|
-
const entries = varNames.map((name) =>
|
|
108
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
109
|
+
const entries = varNames.map((name) => {
|
|
110
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
111
|
+
return ` ${key}: 'var(${name})';`;
|
|
112
|
+
});
|
|
97
113
|
return [
|
|
98
114
|
"export declare const cssVars: {",
|
|
99
115
|
...entries,
|
|
@@ -120,7 +136,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
120
136
|
const names = await scanVarNames(options.input, options.exclude);
|
|
121
137
|
const dtsPath = getDtsPath(options);
|
|
122
138
|
if (dtsPath) {
|
|
123
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
139
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
124
140
|
}
|
|
125
141
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
126
142
|
if (mod) {
|
|
@@ -134,7 +150,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
134
150
|
const dtsPath = getDtsPath(options);
|
|
135
151
|
if (!dtsPath) return;
|
|
136
152
|
const names = await scanVarNames(options.input, options.exclude);
|
|
137
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
153
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
138
154
|
},
|
|
139
155
|
resolveId(id) {
|
|
140
156
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
@@ -142,7 +158,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
142
158
|
async load(id) {
|
|
143
159
|
if (id === RESOLVED_ID) {
|
|
144
160
|
const names = await scanVarNames(options.input, options.exclude);
|
|
145
|
-
return generateJs(names, options.prefix);
|
|
161
|
+
return generateJs(names, options.prefix, options.naming);
|
|
146
162
|
}
|
|
147
163
|
}
|
|
148
164
|
}));
|
package/dist/esbuild.d.cts
CHANGED
package/dist/esbuild.d.ts
CHANGED
package/dist/esbuild.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type NamingConvention = 'camelCase' | 'snake' | 'kebab';
|
|
2
|
+
declare function generateCode(varNames: string[], prefix?: string, naming?: NamingConvention): string;
|
|
3
|
+
declare function generateJs(varNames: string[], prefix?: string, naming?: NamingConvention): string;
|
|
4
|
+
declare function generateDeclaration(varNames: string[], prefix?: string, naming?: NamingConvention): string;
|
|
5
|
+
|
|
6
|
+
export { type NamingConvention as N, generateDeclaration as a, generateJs as b, generateCode as g };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type NamingConvention = 'camelCase' | 'snake' | 'kebab';
|
|
2
|
+
declare function generateCode(varNames: string[], prefix?: string, naming?: NamingConvention): string;
|
|
3
|
+
declare function generateJs(varNames: string[], prefix?: string, naming?: NamingConvention): string;
|
|
4
|
+
declare function generateDeclaration(varNames: string[], prefix?: string, naming?: NamingConvention): string;
|
|
5
|
+
|
|
6
|
+
export { type NamingConvention as N, generateDeclaration as a, generateJs as b, generateCode as g };
|
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,8 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
generate: () => generate,
|
|
34
34
|
generateCode: () => generateCode,
|
|
35
|
+
generateDeclaration: () => generateDeclaration,
|
|
36
|
+
generateJs: () => generateJs,
|
|
35
37
|
parseVarNames: () => parseVarNames,
|
|
36
38
|
scanVarNames: () => scanVarNames
|
|
37
39
|
});
|
|
@@ -76,15 +78,27 @@ async function scanVarNames(patterns, exclude) {
|
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
// src/generator.ts
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
82
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
83
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
84
|
+
if (naming === "kebab") return stripped;
|
|
85
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
81
86
|
}
|
|
82
|
-
function applyPrefix(key, prefix) {
|
|
87
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
83
88
|
if (!prefix) return key;
|
|
89
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
90
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
84
91
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
92
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
93
|
+
function formatKey(key, naming = "camelCase") {
|
|
94
|
+
if (naming === "kebab") return `'${key}'`;
|
|
95
|
+
return key;
|
|
96
|
+
}
|
|
97
|
+
function generateCode(varNames, prefix, naming) {
|
|
98
|
+
const entries = varNames.map((name) => {
|
|
99
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
100
|
+
return ` ${key}: 'var(${name})',`;
|
|
101
|
+
});
|
|
88
102
|
return [
|
|
89
103
|
"// generated \u2014 do not edit",
|
|
90
104
|
"export const cssVars = {",
|
|
@@ -95,18 +109,55 @@ function generateCode(varNames, prefix) {
|
|
|
95
109
|
""
|
|
96
110
|
].join("\n");
|
|
97
111
|
}
|
|
112
|
+
function generateJs(varNames, prefix, naming) {
|
|
113
|
+
const entries = varNames.map((name) => {
|
|
114
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
115
|
+
return ` ${key}: 'var(${name})',`;
|
|
116
|
+
});
|
|
117
|
+
return [
|
|
118
|
+
"// generated \u2014 do not edit",
|
|
119
|
+
"export const cssVars = {",
|
|
120
|
+
...entries,
|
|
121
|
+
"};",
|
|
122
|
+
""
|
|
123
|
+
].join("\n");
|
|
124
|
+
}
|
|
125
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
126
|
+
const entries = varNames.map((name) => {
|
|
127
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
128
|
+
return ` ${key}: 'var(${name})';`;
|
|
129
|
+
});
|
|
130
|
+
return [
|
|
131
|
+
"export declare const cssVars: {",
|
|
132
|
+
...entries,
|
|
133
|
+
"};",
|
|
134
|
+
"export type CssVarName = keyof typeof cssVars;",
|
|
135
|
+
""
|
|
136
|
+
].join("\n");
|
|
137
|
+
}
|
|
98
138
|
|
|
99
139
|
// src/index.ts
|
|
100
140
|
async function generate(options) {
|
|
101
141
|
const names = await scanVarNames(options.input, options.exclude);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
142
|
+
if (names.length === 0) {
|
|
143
|
+
console.warn("css-typed-vars: no CSS custom properties found.");
|
|
144
|
+
}
|
|
145
|
+
const outPath = (0, import_node_path.resolve)(options.output);
|
|
146
|
+
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
147
|
+
if (options.output.endsWith(".js")) {
|
|
148
|
+
await (0, import_promises2.writeFile)(outPath, generateJs(names, options.prefix, options.naming), "utf8");
|
|
149
|
+
const dtsPath = outPath.replace(/\.js$/, ".d.ts");
|
|
150
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
151
|
+
} else {
|
|
152
|
+
await (0, import_promises2.writeFile)(outPath, generateCode(names, options.prefix, options.naming), "utf8");
|
|
153
|
+
}
|
|
105
154
|
}
|
|
106
155
|
// Annotate the CommonJS export names for ESM import in node:
|
|
107
156
|
0 && (module.exports = {
|
|
108
157
|
generate,
|
|
109
158
|
generateCode,
|
|
159
|
+
generateDeclaration,
|
|
160
|
+
generateJs,
|
|
110
161
|
parseVarNames,
|
|
111
162
|
scanVarNames
|
|
112
163
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { N as NamingConvention } from './generator-Ba8XeISD.cjs';
|
|
2
|
+
export { g as generateCode, a as generateDeclaration, b as generateJs } from './generator-Ba8XeISD.cjs';
|
|
2
3
|
|
|
3
|
-
declare function
|
|
4
|
+
declare function parseVarNames(css: string): string[];
|
|
4
5
|
|
|
5
6
|
declare function scanVarNames(patterns: string | string[], exclude?: string | string[]): Promise<string[]>;
|
|
6
7
|
|
|
@@ -9,7 +10,8 @@ interface GenerateOptions {
|
|
|
9
10
|
output: string;
|
|
10
11
|
exclude?: string | string[];
|
|
11
12
|
prefix?: string;
|
|
13
|
+
naming?: NamingConvention;
|
|
12
14
|
}
|
|
13
15
|
declare function generate(options: GenerateOptions): Promise<void>;
|
|
14
16
|
|
|
15
|
-
export { type GenerateOptions,
|
|
17
|
+
export { type GenerateOptions, NamingConvention, generate, parseVarNames, scanVarNames };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { N as NamingConvention } from './generator-Ba8XeISD.js';
|
|
2
|
+
export { g as generateCode, a as generateDeclaration, b as generateJs } from './generator-Ba8XeISD.js';
|
|
2
3
|
|
|
3
|
-
declare function
|
|
4
|
+
declare function parseVarNames(css: string): string[];
|
|
4
5
|
|
|
5
6
|
declare function scanVarNames(patterns: string | string[], exclude?: string | string[]): Promise<string[]>;
|
|
6
7
|
|
|
@@ -9,7 +10,8 @@ interface GenerateOptions {
|
|
|
9
10
|
output: string;
|
|
10
11
|
exclude?: string | string[];
|
|
11
12
|
prefix?: string;
|
|
13
|
+
naming?: NamingConvention;
|
|
12
14
|
}
|
|
13
15
|
declare function generate(options: GenerateOptions): Promise<void>;
|
|
14
16
|
|
|
15
|
-
export { type GenerateOptions,
|
|
17
|
+
export { type GenerateOptions, NamingConvention, generate, parseVarNames, scanVarNames };
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generate
|
|
3
|
+
} from "./chunk-S2QNFCPF.js";
|
|
1
4
|
import {
|
|
2
5
|
generateCode,
|
|
6
|
+
generateDeclaration,
|
|
7
|
+
generateJs,
|
|
3
8
|
parseVarNames,
|
|
4
9
|
scanVarNames
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
|
|
7
|
-
// src/index.ts
|
|
8
|
-
import { writeFile, mkdir } from "fs/promises";
|
|
9
|
-
import { dirname, resolve } from "path";
|
|
10
|
-
async function generate(options) {
|
|
11
|
-
const names = await scanVarNames(options.input, options.exclude);
|
|
12
|
-
const code = generateCode(names, options.prefix);
|
|
13
|
-
await mkdir(dirname(resolve(options.output)), { recursive: true });
|
|
14
|
-
await writeFile(options.output, code, "utf8");
|
|
15
|
-
}
|
|
10
|
+
} from "./chunk-4VL6W5GO.js";
|
|
16
11
|
export {
|
|
17
12
|
generate,
|
|
18
13
|
generateCode,
|
|
14
|
+
generateDeclaration,
|
|
15
|
+
generateJs,
|
|
19
16
|
parseVarNames,
|
|
20
17
|
scanVarNames
|
|
21
18
|
};
|
package/dist/rollup.cjs
CHANGED
|
@@ -76,24 +76,40 @@ async function scanVarNames(patterns, exclude) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/generator.ts
|
|
79
|
-
function
|
|
80
|
-
|
|
79
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
80
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
81
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
82
|
+
if (naming === "kebab") return stripped;
|
|
83
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
81
84
|
}
|
|
82
|
-
function applyPrefix(key, prefix) {
|
|
85
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
83
86
|
if (!prefix) return key;
|
|
87
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
88
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
84
89
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
90
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
91
|
+
function formatKey(key, naming = "camelCase") {
|
|
92
|
+
if (naming === "kebab") return `'${key}'`;
|
|
93
|
+
return key;
|
|
94
|
+
}
|
|
95
|
+
function generateJs(varNames, prefix, naming) {
|
|
96
|
+
const entries = varNames.map((name) => {
|
|
97
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
98
|
+
return ` ${key}: 'var(${name})',`;
|
|
99
|
+
});
|
|
88
100
|
return [
|
|
101
|
+
"// generated \u2014 do not edit",
|
|
89
102
|
"export const cssVars = {",
|
|
90
103
|
...entries,
|
|
91
104
|
"};",
|
|
92
105
|
""
|
|
93
106
|
].join("\n");
|
|
94
107
|
}
|
|
95
|
-
function generateDeclaration(varNames, prefix) {
|
|
96
|
-
const entries = varNames.map((name) =>
|
|
108
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
109
|
+
const entries = varNames.map((name) => {
|
|
110
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
111
|
+
return ` ${key}: 'var(${name})';`;
|
|
112
|
+
});
|
|
97
113
|
return [
|
|
98
114
|
"export declare const cssVars: {",
|
|
99
115
|
...entries,
|
|
@@ -120,7 +136,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
120
136
|
const names = await scanVarNames(options.input, options.exclude);
|
|
121
137
|
const dtsPath = getDtsPath(options);
|
|
122
138
|
if (dtsPath) {
|
|
123
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
139
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
124
140
|
}
|
|
125
141
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
126
142
|
if (mod) {
|
|
@@ -134,7 +150,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
134
150
|
const dtsPath = getDtsPath(options);
|
|
135
151
|
if (!dtsPath) return;
|
|
136
152
|
const names = await scanVarNames(options.input, options.exclude);
|
|
137
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
153
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
138
154
|
},
|
|
139
155
|
resolveId(id) {
|
|
140
156
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
@@ -142,7 +158,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
142
158
|
async load(id) {
|
|
143
159
|
if (id === RESOLVED_ID) {
|
|
144
160
|
const names = await scanVarNames(options.input, options.exclude);
|
|
145
|
-
return generateJs(names, options.prefix);
|
|
161
|
+
return generateJs(names, options.prefix, options.naming);
|
|
146
162
|
}
|
|
147
163
|
}
|
|
148
164
|
}));
|
package/dist/rollup.d.cts
CHANGED
package/dist/rollup.d.ts
CHANGED
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -74,24 +74,40 @@ async function scanVarNames(patterns, exclude) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// src/generator.ts
|
|
77
|
-
function
|
|
78
|
-
|
|
77
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
78
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
79
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
80
|
+
if (naming === "kebab") return stripped;
|
|
81
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
79
82
|
}
|
|
80
|
-
function applyPrefix(key, prefix) {
|
|
83
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
81
84
|
if (!prefix) return key;
|
|
85
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
86
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
82
87
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
83
88
|
}
|
|
84
|
-
function
|
|
85
|
-
|
|
89
|
+
function formatKey(key, naming = "camelCase") {
|
|
90
|
+
if (naming === "kebab") return `'${key}'`;
|
|
91
|
+
return key;
|
|
92
|
+
}
|
|
93
|
+
function generateJs(varNames, prefix, naming) {
|
|
94
|
+
const entries = varNames.map((name) => {
|
|
95
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
96
|
+
return ` ${key}: 'var(${name})',`;
|
|
97
|
+
});
|
|
86
98
|
return [
|
|
99
|
+
"// generated \u2014 do not edit",
|
|
87
100
|
"export const cssVars = {",
|
|
88
101
|
...entries,
|
|
89
102
|
"};",
|
|
90
103
|
""
|
|
91
104
|
].join("\n");
|
|
92
105
|
}
|
|
93
|
-
function generateDeclaration(varNames, prefix) {
|
|
94
|
-
const entries = varNames.map((name) =>
|
|
106
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
107
|
+
const entries = varNames.map((name) => {
|
|
108
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
109
|
+
return ` ${key}: 'var(${name})';`;
|
|
110
|
+
});
|
|
95
111
|
return [
|
|
96
112
|
"export declare const cssVars: {",
|
|
97
113
|
...entries,
|
|
@@ -118,7 +134,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
118
134
|
const names = await scanVarNames(options.input, options.exclude);
|
|
119
135
|
const dtsPath = getDtsPath(options);
|
|
120
136
|
if (dtsPath) {
|
|
121
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
137
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
122
138
|
}
|
|
123
139
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
124
140
|
if (mod) {
|
|
@@ -132,7 +148,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
132
148
|
const dtsPath = getDtsPath(options);
|
|
133
149
|
if (!dtsPath) return;
|
|
134
150
|
const names = await scanVarNames(options.input, options.exclude);
|
|
135
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
151
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
136
152
|
},
|
|
137
153
|
resolveId(id) {
|
|
138
154
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
@@ -140,7 +156,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
140
156
|
async load(id) {
|
|
141
157
|
if (id === RESOLVED_ID) {
|
|
142
158
|
const names = await scanVarNames(options.input, options.exclude);
|
|
143
|
-
return generateJs(names, options.prefix);
|
|
159
|
+
return generateJs(names, options.prefix, options.naming);
|
|
144
160
|
}
|
|
145
161
|
}
|
|
146
162
|
}));
|
package/dist/unplugin.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as unplugin from 'unplugin';
|
|
2
|
+
import { N as NamingConvention } from './generator-Ba8XeISD.cjs';
|
|
2
3
|
|
|
3
4
|
interface Options {
|
|
4
5
|
input: string | string[];
|
|
@@ -11,6 +12,7 @@ interface Options {
|
|
|
11
12
|
dts?: string | false;
|
|
12
13
|
exclude?: string | string[];
|
|
13
14
|
prefix?: string;
|
|
15
|
+
naming?: NamingConvention;
|
|
14
16
|
}
|
|
15
17
|
declare const _default: unplugin.UnpluginInstance<Options, boolean>;
|
|
16
18
|
|
package/dist/unplugin.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as unplugin from 'unplugin';
|
|
2
|
+
import { N as NamingConvention } from './generator-Ba8XeISD.js';
|
|
2
3
|
|
|
3
4
|
interface Options {
|
|
4
5
|
input: string | string[];
|
|
@@ -11,6 +12,7 @@ interface Options {
|
|
|
11
12
|
dts?: string | false;
|
|
12
13
|
exclude?: string | string[];
|
|
13
14
|
prefix?: string;
|
|
15
|
+
naming?: NamingConvention;
|
|
14
16
|
}
|
|
15
17
|
declare const _default: unplugin.UnpluginInstance<Options, boolean>;
|
|
16
18
|
|
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -76,24 +76,40 @@ async function scanVarNames(patterns, exclude) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/generator.ts
|
|
79
|
-
function
|
|
80
|
-
|
|
79
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
80
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
81
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
82
|
+
if (naming === "kebab") return stripped;
|
|
83
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
81
84
|
}
|
|
82
|
-
function applyPrefix(key, prefix) {
|
|
85
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
83
86
|
if (!prefix) return key;
|
|
87
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
88
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
84
89
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
90
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
91
|
+
function formatKey(key, naming = "camelCase") {
|
|
92
|
+
if (naming === "kebab") return `'${key}'`;
|
|
93
|
+
return key;
|
|
94
|
+
}
|
|
95
|
+
function generateJs(varNames, prefix, naming) {
|
|
96
|
+
const entries = varNames.map((name) => {
|
|
97
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
98
|
+
return ` ${key}: 'var(${name})',`;
|
|
99
|
+
});
|
|
88
100
|
return [
|
|
101
|
+
"// generated \u2014 do not edit",
|
|
89
102
|
"export const cssVars = {",
|
|
90
103
|
...entries,
|
|
91
104
|
"};",
|
|
92
105
|
""
|
|
93
106
|
].join("\n");
|
|
94
107
|
}
|
|
95
|
-
function generateDeclaration(varNames, prefix) {
|
|
96
|
-
const entries = varNames.map((name) =>
|
|
108
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
109
|
+
const entries = varNames.map((name) => {
|
|
110
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
111
|
+
return ` ${key}: 'var(${name})';`;
|
|
112
|
+
});
|
|
97
113
|
return [
|
|
98
114
|
"export declare const cssVars: {",
|
|
99
115
|
...entries,
|
|
@@ -120,7 +136,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
120
136
|
const names = await scanVarNames(options.input, options.exclude);
|
|
121
137
|
const dtsPath = getDtsPath(options);
|
|
122
138
|
if (dtsPath) {
|
|
123
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
139
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
124
140
|
}
|
|
125
141
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
126
142
|
if (mod) {
|
|
@@ -134,7 +150,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
134
150
|
const dtsPath = getDtsPath(options);
|
|
135
151
|
if (!dtsPath) return;
|
|
136
152
|
const names = await scanVarNames(options.input, options.exclude);
|
|
137
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
153
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
138
154
|
},
|
|
139
155
|
resolveId(id) {
|
|
140
156
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
@@ -142,7 +158,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
142
158
|
async load(id) {
|
|
143
159
|
if (id === RESOLVED_ID) {
|
|
144
160
|
const names = await scanVarNames(options.input, options.exclude);
|
|
145
|
-
return generateJs(names, options.prefix);
|
|
161
|
+
return generateJs(names, options.prefix, options.naming);
|
|
146
162
|
}
|
|
147
163
|
}
|
|
148
164
|
}));
|
package/dist/vite.d.cts
CHANGED
package/dist/vite.d.ts
CHANGED
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -76,24 +76,40 @@ async function scanVarNames(patterns, exclude) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/generator.ts
|
|
79
|
-
function
|
|
80
|
-
|
|
79
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
80
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
81
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
82
|
+
if (naming === "kebab") return stripped;
|
|
83
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
81
84
|
}
|
|
82
|
-
function applyPrefix(key, prefix) {
|
|
85
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
83
86
|
if (!prefix) return key;
|
|
87
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
88
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
84
89
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
90
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
91
|
+
function formatKey(key, naming = "camelCase") {
|
|
92
|
+
if (naming === "kebab") return `'${key}'`;
|
|
93
|
+
return key;
|
|
94
|
+
}
|
|
95
|
+
function generateJs(varNames, prefix, naming) {
|
|
96
|
+
const entries = varNames.map((name) => {
|
|
97
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
98
|
+
return ` ${key}: 'var(${name})',`;
|
|
99
|
+
});
|
|
88
100
|
return [
|
|
101
|
+
"// generated \u2014 do not edit",
|
|
89
102
|
"export const cssVars = {",
|
|
90
103
|
...entries,
|
|
91
104
|
"};",
|
|
92
105
|
""
|
|
93
106
|
].join("\n");
|
|
94
107
|
}
|
|
95
|
-
function generateDeclaration(varNames, prefix) {
|
|
96
|
-
const entries = varNames.map((name) =>
|
|
108
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
109
|
+
const entries = varNames.map((name) => {
|
|
110
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
111
|
+
return ` ${key}: 'var(${name})';`;
|
|
112
|
+
});
|
|
97
113
|
return [
|
|
98
114
|
"export declare const cssVars: {",
|
|
99
115
|
...entries,
|
|
@@ -120,7 +136,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
120
136
|
const names = await scanVarNames(options.input, options.exclude);
|
|
121
137
|
const dtsPath = getDtsPath(options);
|
|
122
138
|
if (dtsPath) {
|
|
123
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
139
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
124
140
|
}
|
|
125
141
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
126
142
|
if (mod) {
|
|
@@ -134,7 +150,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
134
150
|
const dtsPath = getDtsPath(options);
|
|
135
151
|
if (!dtsPath) return;
|
|
136
152
|
const names = await scanVarNames(options.input, options.exclude);
|
|
137
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
153
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
138
154
|
},
|
|
139
155
|
resolveId(id) {
|
|
140
156
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
@@ -142,7 +158,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
142
158
|
async load(id) {
|
|
143
159
|
if (id === RESOLVED_ID) {
|
|
144
160
|
const names = await scanVarNames(options.input, options.exclude);
|
|
145
|
-
return generateJs(names, options.prefix);
|
|
161
|
+
return generateJs(names, options.prefix, options.naming);
|
|
146
162
|
}
|
|
147
163
|
}
|
|
148
164
|
}));
|
package/dist/webpack.d.cts
CHANGED
package/dist/webpack.d.ts
CHANGED
package/dist/webpack.js
CHANGED