css-typed-vars 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.
- package/README.md +23 -0
- package/dist/{chunk-3LGOJDGV.js → chunk-2AQHBHAG.js} +7 -7
- package/dist/{chunk-SUEAXDIO.js → chunk-6HASMGMT.js} +13 -8
- package/dist/cli.cjs +16 -9
- package/dist/cli.js +8 -6
- package/dist/esbuild.cjs +17 -12
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +11 -6
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -3
- package/dist/rollup.cjs +17 -12
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +17 -12
- package/dist/unplugin.d.cts +2 -0
- package/dist/unplugin.d.ts +2 -0
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +17 -12
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +17 -12
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,10 +108,17 @@ npx css-typed-vars --input "src/styles/**/*.css" --output src/cssVars.ts
|
|
|
108
108
|
npx css-typed-vars --input "src/styles/**/*.{css,scss}" --output src/cssVars.ts --watch
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
+
```sh
|
|
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
|
|
114
|
+
```
|
|
115
|
+
|
|
111
116
|
| Flag | Description |
|
|
112
117
|
|------|-------------|
|
|
113
118
|
| `--input` | Glob pattern for CSS/SCSS/Less files |
|
|
114
119
|
| `--output` | Path to the generated TypeScript file |
|
|
120
|
+
| `--exclude` | Glob pattern for files to exclude (single value; use config file for multiple) |
|
|
121
|
+
| `--prefix` | Prefix for generated keys: `--prefix theme` → `themeColorPrimary` |
|
|
115
122
|
| `--watch` | Watch for file changes and regenerate |
|
|
116
123
|
|
|
117
124
|
CLI flags override values from the config file.
|
|
@@ -124,6 +131,18 @@ The CLI looks for a config file in the current working directory (in order):
|
|
|
124
131
|
2. `css-typed-vars.config.mjs`
|
|
125
132
|
3. `css-typed-vars.config.json`
|
|
126
133
|
|
|
134
|
+
All options are supported in the config file:
|
|
135
|
+
|
|
136
|
+
```js
|
|
137
|
+
// css-typed-vars.config.js
|
|
138
|
+
export default {
|
|
139
|
+
input: 'src/styles/**/*.{css,scss}',
|
|
140
|
+
output: 'src/cssVars.ts',
|
|
141
|
+
exclude: ['**/vendor/**', '**/node_modules/**'],
|
|
142
|
+
prefix: 'theme',
|
|
143
|
+
};
|
|
144
|
+
```
|
|
145
|
+
|
|
127
146
|
---
|
|
128
147
|
|
|
129
148
|
## Plugin
|
|
@@ -215,6 +234,8 @@ Turbopack does not yet have a public plugin API for virtual modules. Use the CLI
|
|
|
215
234
|
| Option | Type | Default | Description |
|
|
216
235
|
|--------|------|---------|-------------|
|
|
217
236
|
| `input` | `string \| string[]` | — | Glob pattern for CSS/SCSS/Less files |
|
|
237
|
+
| `exclude` | `string \| string[]` | — | Glob pattern(s) for files to exclude |
|
|
238
|
+
| `prefix` | `string` | — | Prefix for generated keys: `'theme'` → `themeColorPrimary` |
|
|
218
239
|
| `dts` | `string \| false` | inside `node_modules` | Path to write type declarations. `false` to skip |
|
|
219
240
|
|
|
220
241
|
---
|
|
@@ -268,6 +289,8 @@ import { generate } from 'css-typed-vars';
|
|
|
268
289
|
await generate({
|
|
269
290
|
input: 'src/styles/**/*.{css,scss}',
|
|
270
291
|
output: 'src/cssVars.ts',
|
|
292
|
+
exclude: ['**/vendor/**'],
|
|
293
|
+
prefix: 'theme',
|
|
271
294
|
});
|
|
272
295
|
```
|
|
273
296
|
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
generateDeclaration,
|
|
4
4
|
generateJs,
|
|
5
5
|
scanVarNames
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-6HASMGMT.js";
|
|
7
7
|
|
|
8
8
|
// src/unplugin.ts
|
|
9
9
|
import { createUnplugin } from "unplugin";
|
|
@@ -22,10 +22,10 @@ var unplugin_default = createUnplugin((options) => ({
|
|
|
22
22
|
configureServer(server) {
|
|
23
23
|
server.watcher.on("change", async (file) => {
|
|
24
24
|
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
25
|
-
const names = await scanVarNames(options.input);
|
|
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), "utf8");
|
|
28
|
+
await writeFile(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
29
29
|
}
|
|
30
30
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
31
31
|
if (mod) {
|
|
@@ -38,16 +38,16 @@ var unplugin_default = createUnplugin((options) => ({
|
|
|
38
38
|
async buildStart() {
|
|
39
39
|
const dtsPath = getDtsPath(options);
|
|
40
40
|
if (!dtsPath) return;
|
|
41
|
-
const names = await scanVarNames(options.input);
|
|
42
|
-
await writeFile(dtsPath, generateDeclaration(names), "utf8");
|
|
41
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
42
|
+
await writeFile(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
43
43
|
},
|
|
44
44
|
resolveId(id) {
|
|
45
45
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
46
46
|
},
|
|
47
47
|
async load(id) {
|
|
48
48
|
if (id === RESOLVED_ID) {
|
|
49
|
-
const names = await scanVarNames(options.input);
|
|
50
|
-
return generateJs(names);
|
|
49
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
50
|
+
return generateJs(names, options.prefix);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
}));
|
|
@@ -21,11 +21,12 @@ function parseVarNames(css) {
|
|
|
21
21
|
// src/scanner.ts
|
|
22
22
|
import { readFile } from "fs/promises";
|
|
23
23
|
import fg from "fast-glob";
|
|
24
|
-
async function scanVarNames(patterns) {
|
|
24
|
+
async function scanVarNames(patterns, exclude) {
|
|
25
25
|
const normalized = (Array.isArray(patterns) ? patterns : [patterns]).map(
|
|
26
26
|
(p) => p.replace(/\\/g, "/")
|
|
27
27
|
);
|
|
28
|
-
const
|
|
28
|
+
const normalizedExclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]).map((p) => p.replace(/\\/g, "/")) : [];
|
|
29
|
+
const files = await fg(normalized, { absolute: true, ignore: normalizedExclude });
|
|
29
30
|
const all = /* @__PURE__ */ new Set();
|
|
30
31
|
await Promise.all(
|
|
31
32
|
files.map(async (file) => {
|
|
@@ -42,8 +43,12 @@ async function scanVarNames(patterns) {
|
|
|
42
43
|
function toCamelCase(cssVarName) {
|
|
43
44
|
return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
44
45
|
}
|
|
45
|
-
function
|
|
46
|
-
|
|
46
|
+
function applyPrefix(key, prefix) {
|
|
47
|
+
if (!prefix) return key;
|
|
48
|
+
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
49
|
+
}
|
|
50
|
+
function generateCode(varNames, prefix) {
|
|
51
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
|
|
47
52
|
return [
|
|
48
53
|
"// generated \u2014 do not edit",
|
|
49
54
|
"export const cssVars = {",
|
|
@@ -54,8 +59,8 @@ function generateCode(varNames) {
|
|
|
54
59
|
""
|
|
55
60
|
].join("\n");
|
|
56
61
|
}
|
|
57
|
-
function generateJs(varNames) {
|
|
58
|
-
const entries = varNames.map((name) => ` ${toCamelCase(name)}: 'var(${name})',`);
|
|
62
|
+
function generateJs(varNames, prefix) {
|
|
63
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
|
|
59
64
|
return [
|
|
60
65
|
"export const cssVars = {",
|
|
61
66
|
...entries,
|
|
@@ -63,8 +68,8 @@ function generateJs(varNames) {
|
|
|
63
68
|
""
|
|
64
69
|
].join("\n");
|
|
65
70
|
}
|
|
66
|
-
function generateDeclaration(varNames) {
|
|
67
|
-
const entries = varNames.map((name) => ` ${toCamelCase(name)}: 'var(${name})';`);
|
|
71
|
+
function generateDeclaration(varNames, prefix) {
|
|
72
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})';`);
|
|
68
73
|
return [
|
|
69
74
|
"export declare const cssVars: {",
|
|
70
75
|
...entries,
|
package/dist/cli.cjs
CHANGED
|
@@ -47,11 +47,12 @@ function parseVarNames(css) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// src/scanner.ts
|
|
50
|
-
async function scanVarNames(patterns) {
|
|
50
|
+
async function scanVarNames(patterns, exclude) {
|
|
51
51
|
const normalized = (Array.isArray(patterns) ? patterns : [patterns]).map(
|
|
52
52
|
(p) => p.replace(/\\/g, "/")
|
|
53
53
|
);
|
|
54
|
-
const
|
|
54
|
+
const normalizedExclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]).map((p) => p.replace(/\\/g, "/")) : [];
|
|
55
|
+
const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
|
|
55
56
|
const all = /* @__PURE__ */ new Set();
|
|
56
57
|
await Promise.all(
|
|
57
58
|
files.map(async (file) => {
|
|
@@ -68,8 +69,12 @@ async function scanVarNames(patterns) {
|
|
|
68
69
|
function toCamelCase(cssVarName) {
|
|
69
70
|
return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
70
71
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
72
|
+
function applyPrefix(key, prefix) {
|
|
73
|
+
if (!prefix) return key;
|
|
74
|
+
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
75
|
+
}
|
|
76
|
+
function generateCode(varNames, prefix) {
|
|
77
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
|
|
73
78
|
return [
|
|
74
79
|
"// generated \u2014 do not edit",
|
|
75
80
|
"export const cssVars = {",
|
|
@@ -109,9 +114,9 @@ async function loadConfig() {
|
|
|
109
114
|
}
|
|
110
115
|
return {};
|
|
111
116
|
}
|
|
112
|
-
async function run(input, output) {
|
|
113
|
-
const names = await scanVarNames(input);
|
|
114
|
-
const code = generateCode(names);
|
|
117
|
+
async function run(input, output, exclude, prefix) {
|
|
118
|
+
const names = await scanVarNames(input, exclude);
|
|
119
|
+
const code = generateCode(names, prefix);
|
|
115
120
|
await (0, import_promises2.mkdir)((0, import_node_path.dirname)((0, import_node_path.resolve)(output)), { recursive: true });
|
|
116
121
|
await (0, import_promises2.writeFile)(output, code, "utf8");
|
|
117
122
|
console.log(`Generated ${names.length} variables \u2192 ${output}`);
|
|
@@ -120,17 +125,19 @@ async function main() {
|
|
|
120
125
|
const config = await loadConfig();
|
|
121
126
|
const input = getArg("--input") ?? config.input;
|
|
122
127
|
const output = getArg("--output") ?? config.output;
|
|
128
|
+
const exclude = getArg("--exclude") ?? config.exclude;
|
|
129
|
+
const prefix = getArg("--prefix") ?? config.prefix;
|
|
123
130
|
if (!input || !output) {
|
|
124
131
|
console.error("Usage: css-typed-vars --input <glob> --output <file> [--watch]");
|
|
125
132
|
console.error("Or add a css-typed-vars.config.js file with input and output fields.");
|
|
126
133
|
process.exit(1);
|
|
127
134
|
}
|
|
128
|
-
await run(input, output);
|
|
135
|
+
await run(input, output, exclude, prefix);
|
|
129
136
|
if (watchMode) {
|
|
130
137
|
const patterns = Array.isArray(input) ? input : [input];
|
|
131
138
|
(0, import_chokidar.watch)(patterns).on("change", (file) => {
|
|
132
139
|
console.log(`Changed: ${file}`);
|
|
133
|
-
run(input, output).catch(console.error);
|
|
140
|
+
run(input, output, exclude, prefix).catch(console.error);
|
|
134
141
|
});
|
|
135
142
|
console.log("Watching for changes...");
|
|
136
143
|
}
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
generateCode,
|
|
4
4
|
scanVarNames
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-6HASMGMT.js";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
8
8
|
import { readFile, writeFile, mkdir } from "fs/promises";
|
|
@@ -36,9 +36,9 @@ async function loadConfig() {
|
|
|
36
36
|
}
|
|
37
37
|
return {};
|
|
38
38
|
}
|
|
39
|
-
async function run(input, output) {
|
|
40
|
-
const names = await scanVarNames(input);
|
|
41
|
-
const code = generateCode(names);
|
|
39
|
+
async function run(input, output, exclude, prefix) {
|
|
40
|
+
const names = await scanVarNames(input, exclude);
|
|
41
|
+
const code = generateCode(names, prefix);
|
|
42
42
|
await mkdir(dirname(resolve(output)), { recursive: true });
|
|
43
43
|
await writeFile(output, code, "utf8");
|
|
44
44
|
console.log(`Generated ${names.length} variables \u2192 ${output}`);
|
|
@@ -47,17 +47,19 @@ async function main() {
|
|
|
47
47
|
const config = await loadConfig();
|
|
48
48
|
const input = getArg("--input") ?? config.input;
|
|
49
49
|
const output = getArg("--output") ?? config.output;
|
|
50
|
+
const exclude = getArg("--exclude") ?? config.exclude;
|
|
51
|
+
const prefix = getArg("--prefix") ?? config.prefix;
|
|
50
52
|
if (!input || !output) {
|
|
51
53
|
console.error("Usage: css-typed-vars --input <glob> --output <file> [--watch]");
|
|
52
54
|
console.error("Or add a css-typed-vars.config.js file with input and output fields.");
|
|
53
55
|
process.exit(1);
|
|
54
56
|
}
|
|
55
|
-
await run(input, output);
|
|
57
|
+
await run(input, output, exclude, prefix);
|
|
56
58
|
if (watchMode) {
|
|
57
59
|
const patterns = Array.isArray(input) ? input : [input];
|
|
58
60
|
watch(patterns).on("change", (file) => {
|
|
59
61
|
console.log(`Changed: ${file}`);
|
|
60
|
-
run(input, output).catch(console.error);
|
|
62
|
+
run(input, output, exclude, prefix).catch(console.error);
|
|
61
63
|
});
|
|
62
64
|
console.log("Watching for changes...");
|
|
63
65
|
}
|
package/dist/esbuild.cjs
CHANGED
|
@@ -57,11 +57,12 @@ function parseVarNames(css) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// src/scanner.ts
|
|
60
|
-
async function scanVarNames(patterns) {
|
|
60
|
+
async function scanVarNames(patterns, exclude) {
|
|
61
61
|
const normalized = (Array.isArray(patterns) ? patterns : [patterns]).map(
|
|
62
62
|
(p) => p.replace(/\\/g, "/")
|
|
63
63
|
);
|
|
64
|
-
const
|
|
64
|
+
const normalizedExclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]).map((p) => p.replace(/\\/g, "/")) : [];
|
|
65
|
+
const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
|
|
65
66
|
const all = /* @__PURE__ */ new Set();
|
|
66
67
|
await Promise.all(
|
|
67
68
|
files.map(async (file) => {
|
|
@@ -78,8 +79,12 @@ async function scanVarNames(patterns) {
|
|
|
78
79
|
function toCamelCase(cssVarName) {
|
|
79
80
|
return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
80
81
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
82
|
+
function applyPrefix(key, prefix) {
|
|
83
|
+
if (!prefix) return key;
|
|
84
|
+
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
|
+
}
|
|
86
|
+
function generateJs(varNames, prefix) {
|
|
87
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
|
|
83
88
|
return [
|
|
84
89
|
"export const cssVars = {",
|
|
85
90
|
...entries,
|
|
@@ -87,8 +92,8 @@ function generateJs(varNames) {
|
|
|
87
92
|
""
|
|
88
93
|
].join("\n");
|
|
89
94
|
}
|
|
90
|
-
function generateDeclaration(varNames) {
|
|
91
|
-
const entries = varNames.map((name) => ` ${toCamelCase(name)}: 'var(${name})';`);
|
|
95
|
+
function generateDeclaration(varNames, prefix) {
|
|
96
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})';`);
|
|
92
97
|
return [
|
|
93
98
|
"export declare const cssVars: {",
|
|
94
99
|
...entries,
|
|
@@ -112,10 +117,10 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
112
117
|
configureServer(server) {
|
|
113
118
|
server.watcher.on("change", async (file) => {
|
|
114
119
|
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
115
|
-
const names = await scanVarNames(options.input);
|
|
120
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
116
121
|
const dtsPath = getDtsPath(options);
|
|
117
122
|
if (dtsPath) {
|
|
118
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
123
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
119
124
|
}
|
|
120
125
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
121
126
|
if (mod) {
|
|
@@ -128,16 +133,16 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
128
133
|
async buildStart() {
|
|
129
134
|
const dtsPath = getDtsPath(options);
|
|
130
135
|
if (!dtsPath) return;
|
|
131
|
-
const names = await scanVarNames(options.input);
|
|
132
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
136
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
137
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
133
138
|
},
|
|
134
139
|
resolveId(id) {
|
|
135
140
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
136
141
|
},
|
|
137
142
|
async load(id) {
|
|
138
143
|
if (id === RESOLVED_ID) {
|
|
139
|
-
const names = await scanVarNames(options.input);
|
|
140
|
-
return generateJs(names);
|
|
144
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
145
|
+
return generateJs(names, options.prefix);
|
|
141
146
|
}
|
|
142
147
|
}
|
|
143
148
|
}));
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -57,11 +57,12 @@ function parseVarNames(css) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// src/scanner.ts
|
|
60
|
-
async function scanVarNames(patterns) {
|
|
60
|
+
async function scanVarNames(patterns, exclude) {
|
|
61
61
|
const normalized = (Array.isArray(patterns) ? patterns : [patterns]).map(
|
|
62
62
|
(p) => p.replace(/\\/g, "/")
|
|
63
63
|
);
|
|
64
|
-
const
|
|
64
|
+
const normalizedExclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]).map((p) => p.replace(/\\/g, "/")) : [];
|
|
65
|
+
const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
|
|
65
66
|
const all = /* @__PURE__ */ new Set();
|
|
66
67
|
await Promise.all(
|
|
67
68
|
files.map(async (file) => {
|
|
@@ -78,8 +79,12 @@ async function scanVarNames(patterns) {
|
|
|
78
79
|
function toCamelCase(cssVarName) {
|
|
79
80
|
return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
80
81
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
82
|
+
function applyPrefix(key, prefix) {
|
|
83
|
+
if (!prefix) return key;
|
|
84
|
+
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
|
+
}
|
|
86
|
+
function generateCode(varNames, prefix) {
|
|
87
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
|
|
83
88
|
return [
|
|
84
89
|
"// generated \u2014 do not edit",
|
|
85
90
|
"export const cssVars = {",
|
|
@@ -93,8 +98,8 @@ function generateCode(varNames) {
|
|
|
93
98
|
|
|
94
99
|
// src/index.ts
|
|
95
100
|
async function generate(options) {
|
|
96
|
-
const names = await scanVarNames(options.input);
|
|
97
|
-
const code = generateCode(names);
|
|
101
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
102
|
+
const code = generateCode(names, options.prefix);
|
|
98
103
|
await (0, import_promises2.mkdir)((0, import_node_path.dirname)((0, import_node_path.resolve)(options.output)), { recursive: true });
|
|
99
104
|
await (0, import_promises2.writeFile)(options.output, code, "utf8");
|
|
100
105
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
declare function parseVarNames(css: string): string[];
|
|
2
2
|
|
|
3
|
-
declare function generateCode(varNames: string[]): string;
|
|
3
|
+
declare function generateCode(varNames: string[], prefix?: string): string;
|
|
4
4
|
|
|
5
|
-
declare function scanVarNames(patterns: string | string[]): Promise<string[]>;
|
|
5
|
+
declare function scanVarNames(patterns: string | string[], exclude?: string | string[]): Promise<string[]>;
|
|
6
6
|
|
|
7
7
|
interface GenerateOptions {
|
|
8
8
|
input: string | string[];
|
|
9
9
|
output: string;
|
|
10
|
+
exclude?: string | string[];
|
|
11
|
+
prefix?: string;
|
|
10
12
|
}
|
|
11
13
|
declare function generate(options: GenerateOptions): Promise<void>;
|
|
12
14
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
declare function parseVarNames(css: string): string[];
|
|
2
2
|
|
|
3
|
-
declare function generateCode(varNames: string[]): string;
|
|
3
|
+
declare function generateCode(varNames: string[], prefix?: string): string;
|
|
4
4
|
|
|
5
|
-
declare function scanVarNames(patterns: string | string[]): Promise<string[]>;
|
|
5
|
+
declare function scanVarNames(patterns: string | string[], exclude?: string | string[]): Promise<string[]>;
|
|
6
6
|
|
|
7
7
|
interface GenerateOptions {
|
|
8
8
|
input: string | string[];
|
|
9
9
|
output: string;
|
|
10
|
+
exclude?: string | string[];
|
|
11
|
+
prefix?: string;
|
|
10
12
|
}
|
|
11
13
|
declare function generate(options: GenerateOptions): Promise<void>;
|
|
12
14
|
|
package/dist/index.js
CHANGED
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
generateCode,
|
|
3
3
|
parseVarNames,
|
|
4
4
|
scanVarNames
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-6HASMGMT.js";
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
8
8
|
import { writeFile, mkdir } from "fs/promises";
|
|
9
9
|
import { dirname, resolve } from "path";
|
|
10
10
|
async function generate(options) {
|
|
11
|
-
const names = await scanVarNames(options.input);
|
|
12
|
-
const code = generateCode(names);
|
|
11
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
12
|
+
const code = generateCode(names, options.prefix);
|
|
13
13
|
await mkdir(dirname(resolve(options.output)), { recursive: true });
|
|
14
14
|
await writeFile(options.output, code, "utf8");
|
|
15
15
|
}
|
package/dist/rollup.cjs
CHANGED
|
@@ -57,11 +57,12 @@ function parseVarNames(css) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// src/scanner.ts
|
|
60
|
-
async function scanVarNames(patterns) {
|
|
60
|
+
async function scanVarNames(patterns, exclude) {
|
|
61
61
|
const normalized = (Array.isArray(patterns) ? patterns : [patterns]).map(
|
|
62
62
|
(p) => p.replace(/\\/g, "/")
|
|
63
63
|
);
|
|
64
|
-
const
|
|
64
|
+
const normalizedExclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]).map((p) => p.replace(/\\/g, "/")) : [];
|
|
65
|
+
const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
|
|
65
66
|
const all = /* @__PURE__ */ new Set();
|
|
66
67
|
await Promise.all(
|
|
67
68
|
files.map(async (file) => {
|
|
@@ -78,8 +79,12 @@ async function scanVarNames(patterns) {
|
|
|
78
79
|
function toCamelCase(cssVarName) {
|
|
79
80
|
return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
80
81
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
82
|
+
function applyPrefix(key, prefix) {
|
|
83
|
+
if (!prefix) return key;
|
|
84
|
+
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
|
+
}
|
|
86
|
+
function generateJs(varNames, prefix) {
|
|
87
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
|
|
83
88
|
return [
|
|
84
89
|
"export const cssVars = {",
|
|
85
90
|
...entries,
|
|
@@ -87,8 +92,8 @@ function generateJs(varNames) {
|
|
|
87
92
|
""
|
|
88
93
|
].join("\n");
|
|
89
94
|
}
|
|
90
|
-
function generateDeclaration(varNames) {
|
|
91
|
-
const entries = varNames.map((name) => ` ${toCamelCase(name)}: 'var(${name})';`);
|
|
95
|
+
function generateDeclaration(varNames, prefix) {
|
|
96
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})';`);
|
|
92
97
|
return [
|
|
93
98
|
"export declare const cssVars: {",
|
|
94
99
|
...entries,
|
|
@@ -112,10 +117,10 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
112
117
|
configureServer(server) {
|
|
113
118
|
server.watcher.on("change", async (file) => {
|
|
114
119
|
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
115
|
-
const names = await scanVarNames(options.input);
|
|
120
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
116
121
|
const dtsPath = getDtsPath(options);
|
|
117
122
|
if (dtsPath) {
|
|
118
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
123
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
119
124
|
}
|
|
120
125
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
121
126
|
if (mod) {
|
|
@@ -128,16 +133,16 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
128
133
|
async buildStart() {
|
|
129
134
|
const dtsPath = getDtsPath(options);
|
|
130
135
|
if (!dtsPath) return;
|
|
131
|
-
const names = await scanVarNames(options.input);
|
|
132
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
136
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
137
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
133
138
|
},
|
|
134
139
|
resolveId(id) {
|
|
135
140
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
136
141
|
},
|
|
137
142
|
async load(id) {
|
|
138
143
|
if (id === RESOLVED_ID) {
|
|
139
|
-
const names = await scanVarNames(options.input);
|
|
140
|
-
return generateJs(names);
|
|
144
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
145
|
+
return generateJs(names, options.prefix);
|
|
141
146
|
}
|
|
142
147
|
}
|
|
143
148
|
}));
|
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -55,11 +55,12 @@ function parseVarNames(css) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
// src/scanner.ts
|
|
58
|
-
async function scanVarNames(patterns) {
|
|
58
|
+
async function scanVarNames(patterns, exclude) {
|
|
59
59
|
const normalized = (Array.isArray(patterns) ? patterns : [patterns]).map(
|
|
60
60
|
(p) => p.replace(/\\/g, "/")
|
|
61
61
|
);
|
|
62
|
-
const
|
|
62
|
+
const normalizedExclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]).map((p) => p.replace(/\\/g, "/")) : [];
|
|
63
|
+
const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
|
|
63
64
|
const all = /* @__PURE__ */ new Set();
|
|
64
65
|
await Promise.all(
|
|
65
66
|
files.map(async (file) => {
|
|
@@ -76,8 +77,12 @@ async function scanVarNames(patterns) {
|
|
|
76
77
|
function toCamelCase(cssVarName) {
|
|
77
78
|
return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
78
79
|
}
|
|
79
|
-
function
|
|
80
|
-
|
|
80
|
+
function applyPrefix(key, prefix) {
|
|
81
|
+
if (!prefix) return key;
|
|
82
|
+
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
83
|
+
}
|
|
84
|
+
function generateJs(varNames, prefix) {
|
|
85
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
|
|
81
86
|
return [
|
|
82
87
|
"export const cssVars = {",
|
|
83
88
|
...entries,
|
|
@@ -85,8 +90,8 @@ function generateJs(varNames) {
|
|
|
85
90
|
""
|
|
86
91
|
].join("\n");
|
|
87
92
|
}
|
|
88
|
-
function generateDeclaration(varNames) {
|
|
89
|
-
const entries = varNames.map((name) => ` ${toCamelCase(name)}: 'var(${name})';`);
|
|
93
|
+
function generateDeclaration(varNames, prefix) {
|
|
94
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})';`);
|
|
90
95
|
return [
|
|
91
96
|
"export declare const cssVars: {",
|
|
92
97
|
...entries,
|
|
@@ -110,10 +115,10 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
110
115
|
configureServer(server) {
|
|
111
116
|
server.watcher.on("change", async (file) => {
|
|
112
117
|
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
113
|
-
const names = await scanVarNames(options.input);
|
|
118
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
114
119
|
const dtsPath = getDtsPath(options);
|
|
115
120
|
if (dtsPath) {
|
|
116
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
121
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
117
122
|
}
|
|
118
123
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
119
124
|
if (mod) {
|
|
@@ -126,16 +131,16 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
126
131
|
async buildStart() {
|
|
127
132
|
const dtsPath = getDtsPath(options);
|
|
128
133
|
if (!dtsPath) return;
|
|
129
|
-
const names = await scanVarNames(options.input);
|
|
130
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
134
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
135
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
131
136
|
},
|
|
132
137
|
resolveId(id) {
|
|
133
138
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
134
139
|
},
|
|
135
140
|
async load(id) {
|
|
136
141
|
if (id === RESOLVED_ID) {
|
|
137
|
-
const names = await scanVarNames(options.input);
|
|
138
|
-
return generateJs(names);
|
|
142
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
143
|
+
return generateJs(names, options.prefix);
|
|
139
144
|
}
|
|
140
145
|
}
|
|
141
146
|
}));
|
package/dist/unplugin.d.cts
CHANGED
package/dist/unplugin.d.ts
CHANGED
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -57,11 +57,12 @@ function parseVarNames(css) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// src/scanner.ts
|
|
60
|
-
async function scanVarNames(patterns) {
|
|
60
|
+
async function scanVarNames(patterns, exclude) {
|
|
61
61
|
const normalized = (Array.isArray(patterns) ? patterns : [patterns]).map(
|
|
62
62
|
(p) => p.replace(/\\/g, "/")
|
|
63
63
|
);
|
|
64
|
-
const
|
|
64
|
+
const normalizedExclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]).map((p) => p.replace(/\\/g, "/")) : [];
|
|
65
|
+
const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
|
|
65
66
|
const all = /* @__PURE__ */ new Set();
|
|
66
67
|
await Promise.all(
|
|
67
68
|
files.map(async (file) => {
|
|
@@ -78,8 +79,12 @@ async function scanVarNames(patterns) {
|
|
|
78
79
|
function toCamelCase(cssVarName) {
|
|
79
80
|
return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
80
81
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
82
|
+
function applyPrefix(key, prefix) {
|
|
83
|
+
if (!prefix) return key;
|
|
84
|
+
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
|
+
}
|
|
86
|
+
function generateJs(varNames, prefix) {
|
|
87
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
|
|
83
88
|
return [
|
|
84
89
|
"export const cssVars = {",
|
|
85
90
|
...entries,
|
|
@@ -87,8 +92,8 @@ function generateJs(varNames) {
|
|
|
87
92
|
""
|
|
88
93
|
].join("\n");
|
|
89
94
|
}
|
|
90
|
-
function generateDeclaration(varNames) {
|
|
91
|
-
const entries = varNames.map((name) => ` ${toCamelCase(name)}: 'var(${name})';`);
|
|
95
|
+
function generateDeclaration(varNames, prefix) {
|
|
96
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})';`);
|
|
92
97
|
return [
|
|
93
98
|
"export declare const cssVars: {",
|
|
94
99
|
...entries,
|
|
@@ -112,10 +117,10 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
112
117
|
configureServer(server) {
|
|
113
118
|
server.watcher.on("change", async (file) => {
|
|
114
119
|
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
115
|
-
const names = await scanVarNames(options.input);
|
|
120
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
116
121
|
const dtsPath = getDtsPath(options);
|
|
117
122
|
if (dtsPath) {
|
|
118
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
123
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
119
124
|
}
|
|
120
125
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
121
126
|
if (mod) {
|
|
@@ -128,16 +133,16 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
128
133
|
async buildStart() {
|
|
129
134
|
const dtsPath = getDtsPath(options);
|
|
130
135
|
if (!dtsPath) return;
|
|
131
|
-
const names = await scanVarNames(options.input);
|
|
132
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
136
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
137
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
133
138
|
},
|
|
134
139
|
resolveId(id) {
|
|
135
140
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
136
141
|
},
|
|
137
142
|
async load(id) {
|
|
138
143
|
if (id === RESOLVED_ID) {
|
|
139
|
-
const names = await scanVarNames(options.input);
|
|
140
|
-
return generateJs(names);
|
|
144
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
145
|
+
return generateJs(names, options.prefix);
|
|
141
146
|
}
|
|
142
147
|
}
|
|
143
148
|
}));
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -57,11 +57,12 @@ function parseVarNames(css) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// src/scanner.ts
|
|
60
|
-
async function scanVarNames(patterns) {
|
|
60
|
+
async function scanVarNames(patterns, exclude) {
|
|
61
61
|
const normalized = (Array.isArray(patterns) ? patterns : [patterns]).map(
|
|
62
62
|
(p) => p.replace(/\\/g, "/")
|
|
63
63
|
);
|
|
64
|
-
const
|
|
64
|
+
const normalizedExclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]).map((p) => p.replace(/\\/g, "/")) : [];
|
|
65
|
+
const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
|
|
65
66
|
const all = /* @__PURE__ */ new Set();
|
|
66
67
|
await Promise.all(
|
|
67
68
|
files.map(async (file) => {
|
|
@@ -78,8 +79,12 @@ async function scanVarNames(patterns) {
|
|
|
78
79
|
function toCamelCase(cssVarName) {
|
|
79
80
|
return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
80
81
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
82
|
+
function applyPrefix(key, prefix) {
|
|
83
|
+
if (!prefix) return key;
|
|
84
|
+
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
|
+
}
|
|
86
|
+
function generateJs(varNames, prefix) {
|
|
87
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
|
|
83
88
|
return [
|
|
84
89
|
"export const cssVars = {",
|
|
85
90
|
...entries,
|
|
@@ -87,8 +92,8 @@ function generateJs(varNames) {
|
|
|
87
92
|
""
|
|
88
93
|
].join("\n");
|
|
89
94
|
}
|
|
90
|
-
function generateDeclaration(varNames) {
|
|
91
|
-
const entries = varNames.map((name) => ` ${toCamelCase(name)}: 'var(${name})';`);
|
|
95
|
+
function generateDeclaration(varNames, prefix) {
|
|
96
|
+
const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})';`);
|
|
92
97
|
return [
|
|
93
98
|
"export declare const cssVars: {",
|
|
94
99
|
...entries,
|
|
@@ -112,10 +117,10 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
112
117
|
configureServer(server) {
|
|
113
118
|
server.watcher.on("change", async (file) => {
|
|
114
119
|
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
115
|
-
const names = await scanVarNames(options.input);
|
|
120
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
116
121
|
const dtsPath = getDtsPath(options);
|
|
117
122
|
if (dtsPath) {
|
|
118
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
123
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
119
124
|
}
|
|
120
125
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
121
126
|
if (mod) {
|
|
@@ -128,16 +133,16 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
128
133
|
async buildStart() {
|
|
129
134
|
const dtsPath = getDtsPath(options);
|
|
130
135
|
if (!dtsPath) return;
|
|
131
|
-
const names = await scanVarNames(options.input);
|
|
132
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
136
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
137
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
133
138
|
},
|
|
134
139
|
resolveId(id) {
|
|
135
140
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
136
141
|
},
|
|
137
142
|
async load(id) {
|
|
138
143
|
if (id === RESOLVED_ID) {
|
|
139
|
-
const names = await scanVarNames(options.input);
|
|
140
|
-
return generateJs(names);
|
|
144
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
145
|
+
return generateJs(names, options.prefix);
|
|
141
146
|
}
|
|
142
147
|
}
|
|
143
148
|
}));
|
package/dist/webpack.js
CHANGED