css-typed-vars 0.5.0 → 0.7.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/dist/cli.js CHANGED
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  checkGenerated,
4
+ findUnusedVars,
4
5
  generate
5
- } from "./chunk-H3T6RMQQ.js";
6
+ } from "./chunk-PLO2JWR7.js";
6
7
  import {
7
8
  VALID_NAMINGS
8
- } from "./chunk-JDZAH2YQ.js";
9
+ } from "./chunk-6YWE4A6S.js";
9
10
 
10
11
  // src/cli.ts
11
12
  import { readFile } from "fs/promises";
@@ -29,6 +30,10 @@ var getArgs = (flag) => {
29
30
  };
30
31
  var watchMode = args.includes("--watch");
31
32
  var checkMode = args.includes("--check");
33
+ var groupFlag = args.includes("--group");
34
+ var pruneFlag = args.includes("--prune");
35
+ var pruneCheckMode = args.includes("--prune-check");
36
+ var helpersFlag = args.includes("--helpers");
32
37
  async function loadConfig() {
33
38
  const candidates = [
34
39
  "css-typed-vars.config.js",
@@ -53,9 +58,9 @@ async function loadConfig() {
53
58
  }
54
59
  return {};
55
60
  }
56
- async function run(input, output, exclude, prefix, naming, selectors) {
57
- await generate({ input, output, exclude, prefix, naming, selectors });
58
- console.log(`Generated \u2192 ${output}`);
61
+ async function run(options) {
62
+ await generate(options);
63
+ console.log(`Generated \u2192 ${options.output}`);
59
64
  }
60
65
  async function main() {
61
66
  if (args.includes("--version") || args.includes("-v")) {
@@ -78,8 +83,23 @@ async function main() {
78
83
  const naming = namingRaw;
79
84
  const selectorArgs = getArgs("--selector");
80
85
  const selectors = selectorArgs.length > 0 ? selectorArgs : config.selectors;
86
+ const themeArgs = getArgs("--theme");
87
+ for (const arg of themeArgs) {
88
+ if (!/^[^=]+=.+$/.test(arg)) {
89
+ console.error(`css-typed-vars: invalid --theme value "${arg}". Expected <name>=<selector or @media prelude>, e.g. dark=[data-theme="dark"].`);
90
+ process.exit(1);
91
+ }
92
+ }
93
+ const themes = themeArgs.length > 0 ? Object.fromEntries(themeArgs.map((arg) => [arg.slice(0, arg.indexOf("=")), arg.slice(arg.indexOf("=") + 1)])) : config.themes;
94
+ const group = groupFlag || config.group;
95
+ const prune = pruneFlag || config.prune;
96
+ const usageArgs = getArgs("--usage");
97
+ const usage = usageArgs.length > 0 ? usageArgs : config.usage;
98
+ const usageExcludeArgs = getArgs("--usage-exclude");
99
+ const usageExclude = usageExcludeArgs.length > 0 ? usageExcludeArgs : config.usageExclude;
100
+ const helpers = helpersFlag || config.helpers;
81
101
  if (!input || !output) {
82
- console.error("Usage: css-typed-vars --input <glob> --output <file> [--watch] [--check]");
102
+ console.error("Usage: css-typed-vars --input <glob> --output <file> [--watch] [--check] [--group] [--helpers] [--theme <name>=<selector>] [--prune --usage <glob>] [--prune-check --usage <glob>]");
83
103
  console.error("Or add a css-typed-vars.config.js file with input and output fields.");
84
104
  process.exit(1);
85
105
  }
@@ -87,8 +107,30 @@ async function main() {
87
107
  console.error("css-typed-vars: --check cannot be combined with --watch.");
88
108
  process.exit(1);
89
109
  }
110
+ if (pruneCheckMode && (watchMode || checkMode)) {
111
+ console.error("css-typed-vars: --prune-check cannot be combined with --watch or --check.");
112
+ process.exit(1);
113
+ }
114
+ if (group && prefix) {
115
+ console.error("css-typed-vars: --group cannot be combined with --prefix.");
116
+ process.exit(1);
117
+ }
118
+ if ((prune || pruneCheckMode) && !usage) {
119
+ console.error("css-typed-vars: --prune/--prune-check requires --usage <glob> (source files to scan for cssVars usage).");
120
+ process.exit(1);
121
+ }
122
+ if (pruneCheckMode) {
123
+ const unused = await findUnusedVars({ input, exclude, selectors, themes, prefix, naming, group, usage, usageExclude });
124
+ if (unused.length > 0) {
125
+ console.error(`css-typed-vars: ${unused.length} unused variable(s): ${unused.join(", ")}`);
126
+ process.exit(1);
127
+ }
128
+ console.log("css-typed-vars: no unused variables.");
129
+ return;
130
+ }
131
+ const runOptions = { input, output, exclude, prefix, naming, selectors, themes, group, prune, usage, usageExclude, helpers };
90
132
  if (checkMode) {
91
- const upToDate = await checkGenerated({ input, output, exclude, prefix, naming, selectors });
133
+ const upToDate = await checkGenerated(runOptions);
92
134
  if (!upToDate) {
93
135
  console.error(`css-typed-vars: "${output}" is out of date. Run without --check to regenerate.`);
94
136
  process.exit(1);
@@ -96,12 +138,12 @@ async function main() {
96
138
  console.log(`css-typed-vars: "${output}" is up to date.`);
97
139
  return;
98
140
  }
99
- await run(input, output, exclude, prefix, naming, selectors);
141
+ await run(runOptions);
100
142
  if (watchMode) {
101
143
  const patterns = Array.isArray(input) ? input : [input];
102
144
  const makeHandler = (label) => (file) => {
103
145
  console.log(`${label}: ${file}`);
104
- run(input, output, exclude, prefix, naming, selectors).catch(console.error);
146
+ run(runOptions).catch(console.error);
105
147
  };
106
148
  const ignored = exclude ? Array.isArray(exclude) ? exclude : [exclude] : void 0;
107
149
  watch(patterns, ignored ? { ignored } : void 0).on("change", makeHandler("Changed")).on("add", makeHandler("Added")).on("unlink", makeHandler("Removed"));