tailwindcss-patch 8.2.3 → 8.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/README.md +20 -0
- package/dist/{chunk-CFH3UEW6.js → chunk-7ZWFVW77.js} +476 -166
- package/dist/{chunk-KH3TRSVT.mjs → chunk-SN7IO2IS.mjs} +443 -133
- package/dist/cli.js +3 -233
- package/dist/cli.mjs +3 -233
- package/dist/index.d.mts +98 -1
- package/dist/index.d.ts +98 -1
- package/dist/index.js +8 -2
- package/dist/index.mjs +9 -3
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,238 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _chunkCFH3UEW6js = require('./chunk-CFH3UEW6.js');
|
|
8
|
-
|
|
9
|
-
// src/cli.ts
|
|
10
|
-
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
11
|
-
var _config = require('@tailwindcss-mangle/config');
|
|
12
|
-
|
|
13
|
-
// ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
|
|
14
|
-
function isPlainObject(value) {
|
|
15
|
-
if (value === null || typeof value !== "object") {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
const prototype = Object.getPrototypeOf(value);
|
|
19
|
-
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
if (Symbol.iterator in value) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
if (Symbol.toStringTag in value) {
|
|
26
|
-
return Object.prototype.toString.call(value) === "[object Module]";
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
31
|
-
if (!isPlainObject(defaults)) {
|
|
32
|
-
return _defu(baseObject, {}, namespace, merger);
|
|
33
|
-
}
|
|
34
|
-
const object = Object.assign({}, defaults);
|
|
35
|
-
for (const key in baseObject) {
|
|
36
|
-
if (key === "__proto__" || key === "constructor") {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
const value = baseObject[key];
|
|
40
|
-
if (value === null || value === void 0) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (merger && merger(object, key, value, namespace)) {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
47
|
-
object[key] = [...value, ...object[key]];
|
|
48
|
-
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
49
|
-
object[key] = _defu(
|
|
50
|
-
value,
|
|
51
|
-
object[key],
|
|
52
|
-
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
53
|
-
merger
|
|
54
|
-
);
|
|
55
|
-
} else {
|
|
56
|
-
object[key] = value;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return object;
|
|
60
|
-
}
|
|
61
|
-
function createDefu(merger) {
|
|
62
|
-
return (...arguments_) => (
|
|
63
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
64
|
-
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
var defu = createDefu();
|
|
68
|
-
var defuFn = createDefu((object, key, currentValue) => {
|
|
69
|
-
if (object[key] !== void 0 && typeof currentValue === "function") {
|
|
70
|
-
object[key] = currentValue(object[key]);
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
75
|
-
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
76
|
-
object[key] = currentValue(object[key]);
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// ../shared/src/utils.ts
|
|
82
|
-
var defuOverrideArray = createDefu((obj, key, value) => {
|
|
83
|
-
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
84
|
-
obj[key] = value;
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
var preserveClassNames = [
|
|
89
|
-
// https://tailwindcss.com/docs/transition-timing-function start
|
|
90
|
-
// https://github.com/sonofmagic/tailwindcss-mangle/issues/21
|
|
91
|
-
"ease-out",
|
|
92
|
-
"ease-linear",
|
|
93
|
-
"ease-in",
|
|
94
|
-
"ease-in-out"
|
|
95
|
-
// https://tailwindcss.com/docs/transition-timing-function end
|
|
96
|
-
];
|
|
97
|
-
var preserveClassNamesMap = preserveClassNames.reduce((acc, cur) => {
|
|
98
|
-
acc[cur] = true;
|
|
99
|
-
return acc;
|
|
100
|
-
}, {});
|
|
101
|
-
var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
|
|
3
|
+
var _chunk7ZWFVW77js = require('./chunk-7ZWFVW77.js');
|
|
102
4
|
|
|
103
5
|
// src/cli.ts
|
|
104
|
-
var
|
|
105
|
-
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
|
|
106
|
-
var _pathe = require('pathe'); var _pathe2 = _interopRequireDefault(_pathe);
|
|
107
|
-
var cli = _cac2.default.call(void 0, "tw-patch");
|
|
108
|
-
async function loadPatchOptions(cwd, overrides) {
|
|
109
|
-
const { config } = await _config.getConfig.call(void 0, cwd);
|
|
110
|
-
const legacyConfig = config;
|
|
111
|
-
const base = _optionalChain([config, 'optionalAccess', _ => _.registry]) ? _chunkCFH3UEW6js.fromUnifiedConfig.call(void 0, config.registry) : _optionalChain([legacyConfig, 'optionalAccess', _2 => _2.patch]) ? _chunkCFH3UEW6js.fromLegacyOptions.call(void 0, { patch: legacyConfig.patch }) : {};
|
|
112
|
-
const merged = defu(_nullishCoalesce(overrides, () => ( {})), base);
|
|
113
|
-
return merged;
|
|
114
|
-
}
|
|
115
|
-
cli.command("install", "Apply Tailwind CSS runtime patches").option("--cwd <dir>", "Working directory", { default: _process2.default.cwd() }).action(async (args) => {
|
|
116
|
-
const options = await loadPatchOptions(args.cwd);
|
|
117
|
-
const patcher = new (0, _chunkCFH3UEW6js.TailwindcssPatcher)(options);
|
|
118
|
-
await patcher.patch();
|
|
119
|
-
_chunkCFH3UEW6js.logger_default.success("Tailwind CSS runtime patched successfully.");
|
|
120
|
-
});
|
|
121
|
-
cli.command("extract", "Collect generated class names into a cache file").option("--cwd <dir>", "Working directory", { default: _process2.default.cwd() }).option("--output <file>", "Override output file path").option("--format <format>", "Output format (json|lines)").option("--css <file>", "Tailwind CSS entry CSS when using v4").option("--no-write", "Skip writing to disk").action(async (args) => {
|
|
122
|
-
const overrides = {};
|
|
123
|
-
if (args.output || args.format) {
|
|
124
|
-
overrides.output = {
|
|
125
|
-
file: args.output,
|
|
126
|
-
format: args.format
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
if (args.css) {
|
|
130
|
-
overrides.tailwind = {
|
|
131
|
-
v4: {
|
|
132
|
-
cssEntries: [args.css]
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
const options = await loadPatchOptions(args.cwd, overrides);
|
|
137
|
-
const patcher = new (0, _chunkCFH3UEW6js.TailwindcssPatcher)(options);
|
|
138
|
-
const result = await patcher.extract({ write: args.write });
|
|
139
|
-
if (result.filename) {
|
|
140
|
-
_chunkCFH3UEW6js.logger_default.success(`Collected ${result.classList.length} classes \u2192 ${result.filename}`);
|
|
141
|
-
} else {
|
|
142
|
-
_chunkCFH3UEW6js.logger_default.success(`Collected ${result.classList.length} classes.`);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
var TOKEN_FORMATS = ["json", "lines", "grouped-json"];
|
|
146
|
-
cli.command("tokens", "Extract Tailwind tokens with file/position metadata").option("--cwd <dir>", "Working directory", { default: _process2.default.cwd() }).option("--output <file>", "Override output file path", { default: ".tw-patch/tw-token-report.json" }).option("--format <format>", "Output format (json|lines|grouped-json)", { default: "json" }).option("--group-key <key>", "Grouping key for grouped-json output (relative|absolute)", { default: "relative" }).option("--no-write", "Skip writing to disk").action(async (args) => {
|
|
147
|
-
const options = await loadPatchOptions(args.cwd);
|
|
148
|
-
const patcher = new (0, _chunkCFH3UEW6js.TailwindcssPatcher)(options);
|
|
149
|
-
const report = await patcher.collectContentTokens();
|
|
150
|
-
const shouldWrite = _nullishCoalesce(args.write, () => ( true));
|
|
151
|
-
let format = _nullishCoalesce(args.format, () => ( "json"));
|
|
152
|
-
if (!TOKEN_FORMATS.includes(format)) {
|
|
153
|
-
format = "json";
|
|
154
|
-
}
|
|
155
|
-
const targetFile = _nullishCoalesce(args.output, () => ( ".tw-patch/tw-token-report.json"));
|
|
156
|
-
const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
|
|
157
|
-
const buildGrouped = () => _chunkCFH3UEW6js.groupTokensByFile.call(void 0, report, {
|
|
158
|
-
key: groupKey,
|
|
159
|
-
stripAbsolutePaths: groupKey !== "absolute"
|
|
160
|
-
});
|
|
161
|
-
const grouped = format === "grouped-json" ? buildGrouped() : null;
|
|
162
|
-
const resolveGrouped = () => _nullishCoalesce(grouped, () => ( buildGrouped()));
|
|
163
|
-
if (shouldWrite) {
|
|
164
|
-
const target = _pathe2.default.resolve(targetFile);
|
|
165
|
-
await _fsextra2.default.ensureDir(_pathe2.default.dirname(target));
|
|
166
|
-
if (format === "json") {
|
|
167
|
-
await _fsextra2.default.writeJSON(target, report, { spaces: 2 });
|
|
168
|
-
} else if (format === "grouped-json") {
|
|
169
|
-
await _fsextra2.default.writeJSON(target, resolveGrouped(), { spaces: 2 });
|
|
170
|
-
} else {
|
|
171
|
-
const lines = report.entries.map(formatTokenLine);
|
|
172
|
-
await _fsextra2.default.writeFile(target, `${lines.join("\n")}
|
|
173
|
-
`, "utf8");
|
|
174
|
-
}
|
|
175
|
-
_chunkCFH3UEW6js.logger_default.success(
|
|
176
|
-
`Collected ${report.entries.length} tokens (${format}) \u2192 ${target.replace(_process2.default.cwd(), ".")}`
|
|
177
|
-
);
|
|
178
|
-
} else {
|
|
179
|
-
_chunkCFH3UEW6js.logger_default.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
|
|
180
|
-
if (format === "lines") {
|
|
181
|
-
const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
|
|
182
|
-
if (preview) {
|
|
183
|
-
_chunkCFH3UEW6js.logger_default.log("");
|
|
184
|
-
_chunkCFH3UEW6js.logger_default.info(preview);
|
|
185
|
-
if (report.entries.length > 5) {
|
|
186
|
-
_chunkCFH3UEW6js.logger_default.info(`\u2026and ${report.entries.length - 5} more.`);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
} else if (format === "grouped-json") {
|
|
190
|
-
const map = resolveGrouped();
|
|
191
|
-
const { preview, moreFiles } = formatGroupedPreview(map);
|
|
192
|
-
if (preview) {
|
|
193
|
-
_chunkCFH3UEW6js.logger_default.log("");
|
|
194
|
-
_chunkCFH3UEW6js.logger_default.info(preview);
|
|
195
|
-
if (moreFiles > 0) {
|
|
196
|
-
_chunkCFH3UEW6js.logger_default.info(`\u2026and ${moreFiles} more files.`);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
} else {
|
|
200
|
-
const previewEntries = report.entries.slice(0, 3);
|
|
201
|
-
if (previewEntries.length) {
|
|
202
|
-
_chunkCFH3UEW6js.logger_default.log("");
|
|
203
|
-
_chunkCFH3UEW6js.logger_default.info(JSON.stringify(previewEntries, null, 2));
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (report.skippedFiles.length) {
|
|
208
|
-
_chunkCFH3UEW6js.logger_default.warn("Skipped files:");
|
|
209
|
-
for (const skipped of report.skippedFiles) {
|
|
210
|
-
_chunkCFH3UEW6js.logger_default.warn(` \u2022 ${skipped.file} (${skipped.reason})`);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
cli.command("init", "Generate a tailwindcss-patch config file").option("--cwd <dir>", "Working directory", { default: _process2.default.cwd() }).action(async (args) => {
|
|
215
|
-
await _config.initConfig.call(void 0, args.cwd);
|
|
216
|
-
_chunkCFH3UEW6js.logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
|
|
217
|
-
});
|
|
6
|
+
var cli = _chunk7ZWFVW77js.createTailwindcssPatchCli.call(void 0, );
|
|
218
7
|
cli.help();
|
|
219
8
|
cli.parse();
|
|
220
|
-
function formatTokenLine(entry) {
|
|
221
|
-
return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
|
|
222
|
-
}
|
|
223
|
-
function formatGroupedPreview(map, limit = 3) {
|
|
224
|
-
const files = Object.keys(map);
|
|
225
|
-
if (!files.length) {
|
|
226
|
-
return { preview: "", moreFiles: 0 };
|
|
227
|
-
}
|
|
228
|
-
const lines = files.slice(0, limit).map((file) => {
|
|
229
|
-
const tokens = map[file];
|
|
230
|
-
const sample = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
|
|
231
|
-
const suffix = tokens.length > 3 ? ", \u2026" : "";
|
|
232
|
-
return `${file}: ${tokens.length} tokens (${sample}${suffix})`;
|
|
233
|
-
});
|
|
234
|
-
return {
|
|
235
|
-
preview: lines.join("\n"),
|
|
236
|
-
moreFiles: Math.max(0, files.length - limit)
|
|
237
|
-
};
|
|
238
|
-
}
|
package/dist/cli.mjs
CHANGED
|
@@ -1,238 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
fromUnifiedConfig,
|
|
5
|
-
groupTokensByFile,
|
|
6
|
-
logger_default
|
|
7
|
-
} from "./chunk-KH3TRSVT.mjs";
|
|
2
|
+
createTailwindcssPatchCli
|
|
3
|
+
} from "./chunk-SN7IO2IS.mjs";
|
|
8
4
|
|
|
9
5
|
// src/cli.ts
|
|
10
|
-
|
|
11
|
-
import { CONFIG_NAME, getConfig, initConfig } from "@tailwindcss-mangle/config";
|
|
12
|
-
|
|
13
|
-
// ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
|
|
14
|
-
function isPlainObject(value) {
|
|
15
|
-
if (value === null || typeof value !== "object") {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
const prototype = Object.getPrototypeOf(value);
|
|
19
|
-
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
if (Symbol.iterator in value) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
if (Symbol.toStringTag in value) {
|
|
26
|
-
return Object.prototype.toString.call(value) === "[object Module]";
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
31
|
-
if (!isPlainObject(defaults)) {
|
|
32
|
-
return _defu(baseObject, {}, namespace, merger);
|
|
33
|
-
}
|
|
34
|
-
const object = Object.assign({}, defaults);
|
|
35
|
-
for (const key in baseObject) {
|
|
36
|
-
if (key === "__proto__" || key === "constructor") {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
const value = baseObject[key];
|
|
40
|
-
if (value === null || value === void 0) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (merger && merger(object, key, value, namespace)) {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
47
|
-
object[key] = [...value, ...object[key]];
|
|
48
|
-
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
49
|
-
object[key] = _defu(
|
|
50
|
-
value,
|
|
51
|
-
object[key],
|
|
52
|
-
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
53
|
-
merger
|
|
54
|
-
);
|
|
55
|
-
} else {
|
|
56
|
-
object[key] = value;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return object;
|
|
60
|
-
}
|
|
61
|
-
function createDefu(merger) {
|
|
62
|
-
return (...arguments_) => (
|
|
63
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
64
|
-
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
var defu = createDefu();
|
|
68
|
-
var defuFn = createDefu((object, key, currentValue) => {
|
|
69
|
-
if (object[key] !== void 0 && typeof currentValue === "function") {
|
|
70
|
-
object[key] = currentValue(object[key]);
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
75
|
-
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
76
|
-
object[key] = currentValue(object[key]);
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// ../shared/src/utils.ts
|
|
82
|
-
var defuOverrideArray = createDefu((obj, key, value) => {
|
|
83
|
-
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
84
|
-
obj[key] = value;
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
var preserveClassNames = [
|
|
89
|
-
// https://tailwindcss.com/docs/transition-timing-function start
|
|
90
|
-
// https://github.com/sonofmagic/tailwindcss-mangle/issues/21
|
|
91
|
-
"ease-out",
|
|
92
|
-
"ease-linear",
|
|
93
|
-
"ease-in",
|
|
94
|
-
"ease-in-out"
|
|
95
|
-
// https://tailwindcss.com/docs/transition-timing-function end
|
|
96
|
-
];
|
|
97
|
-
var preserveClassNamesMap = preserveClassNames.reduce((acc, cur) => {
|
|
98
|
-
acc[cur] = true;
|
|
99
|
-
return acc;
|
|
100
|
-
}, {});
|
|
101
|
-
var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
|
|
102
|
-
|
|
103
|
-
// src/cli.ts
|
|
104
|
-
import cac from "cac";
|
|
105
|
-
import fs from "fs-extra";
|
|
106
|
-
import path from "pathe";
|
|
107
|
-
var cli = cac("tw-patch");
|
|
108
|
-
async function loadPatchOptions(cwd, overrides) {
|
|
109
|
-
const { config } = await getConfig(cwd);
|
|
110
|
-
const legacyConfig = config;
|
|
111
|
-
const base = config?.registry ? fromUnifiedConfig(config.registry) : legacyConfig?.patch ? fromLegacyOptions({ patch: legacyConfig.patch }) : {};
|
|
112
|
-
const merged = defu(overrides ?? {}, base);
|
|
113
|
-
return merged;
|
|
114
|
-
}
|
|
115
|
-
cli.command("install", "Apply Tailwind CSS runtime patches").option("--cwd <dir>", "Working directory", { default: process.cwd() }).action(async (args) => {
|
|
116
|
-
const options = await loadPatchOptions(args.cwd);
|
|
117
|
-
const patcher = new TailwindcssPatcher(options);
|
|
118
|
-
await patcher.patch();
|
|
119
|
-
logger_default.success("Tailwind CSS runtime patched successfully.");
|
|
120
|
-
});
|
|
121
|
-
cli.command("extract", "Collect generated class names into a cache file").option("--cwd <dir>", "Working directory", { default: process.cwd() }).option("--output <file>", "Override output file path").option("--format <format>", "Output format (json|lines)").option("--css <file>", "Tailwind CSS entry CSS when using v4").option("--no-write", "Skip writing to disk").action(async (args) => {
|
|
122
|
-
const overrides = {};
|
|
123
|
-
if (args.output || args.format) {
|
|
124
|
-
overrides.output = {
|
|
125
|
-
file: args.output,
|
|
126
|
-
format: args.format
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
if (args.css) {
|
|
130
|
-
overrides.tailwind = {
|
|
131
|
-
v4: {
|
|
132
|
-
cssEntries: [args.css]
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
const options = await loadPatchOptions(args.cwd, overrides);
|
|
137
|
-
const patcher = new TailwindcssPatcher(options);
|
|
138
|
-
const result = await patcher.extract({ write: args.write });
|
|
139
|
-
if (result.filename) {
|
|
140
|
-
logger_default.success(`Collected ${result.classList.length} classes \u2192 ${result.filename}`);
|
|
141
|
-
} else {
|
|
142
|
-
logger_default.success(`Collected ${result.classList.length} classes.`);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
var TOKEN_FORMATS = ["json", "lines", "grouped-json"];
|
|
146
|
-
cli.command("tokens", "Extract Tailwind tokens with file/position metadata").option("--cwd <dir>", "Working directory", { default: process.cwd() }).option("--output <file>", "Override output file path", { default: ".tw-patch/tw-token-report.json" }).option("--format <format>", "Output format (json|lines|grouped-json)", { default: "json" }).option("--group-key <key>", "Grouping key for grouped-json output (relative|absolute)", { default: "relative" }).option("--no-write", "Skip writing to disk").action(async (args) => {
|
|
147
|
-
const options = await loadPatchOptions(args.cwd);
|
|
148
|
-
const patcher = new TailwindcssPatcher(options);
|
|
149
|
-
const report = await patcher.collectContentTokens();
|
|
150
|
-
const shouldWrite = args.write ?? true;
|
|
151
|
-
let format = args.format ?? "json";
|
|
152
|
-
if (!TOKEN_FORMATS.includes(format)) {
|
|
153
|
-
format = "json";
|
|
154
|
-
}
|
|
155
|
-
const targetFile = args.output ?? ".tw-patch/tw-token-report.json";
|
|
156
|
-
const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
|
|
157
|
-
const buildGrouped = () => groupTokensByFile(report, {
|
|
158
|
-
key: groupKey,
|
|
159
|
-
stripAbsolutePaths: groupKey !== "absolute"
|
|
160
|
-
});
|
|
161
|
-
const grouped = format === "grouped-json" ? buildGrouped() : null;
|
|
162
|
-
const resolveGrouped = () => grouped ?? buildGrouped();
|
|
163
|
-
if (shouldWrite) {
|
|
164
|
-
const target = path.resolve(targetFile);
|
|
165
|
-
await fs.ensureDir(path.dirname(target));
|
|
166
|
-
if (format === "json") {
|
|
167
|
-
await fs.writeJSON(target, report, { spaces: 2 });
|
|
168
|
-
} else if (format === "grouped-json") {
|
|
169
|
-
await fs.writeJSON(target, resolveGrouped(), { spaces: 2 });
|
|
170
|
-
} else {
|
|
171
|
-
const lines = report.entries.map(formatTokenLine);
|
|
172
|
-
await fs.writeFile(target, `${lines.join("\n")}
|
|
173
|
-
`, "utf8");
|
|
174
|
-
}
|
|
175
|
-
logger_default.success(
|
|
176
|
-
`Collected ${report.entries.length} tokens (${format}) \u2192 ${target.replace(process.cwd(), ".")}`
|
|
177
|
-
);
|
|
178
|
-
} else {
|
|
179
|
-
logger_default.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
|
|
180
|
-
if (format === "lines") {
|
|
181
|
-
const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
|
|
182
|
-
if (preview) {
|
|
183
|
-
logger_default.log("");
|
|
184
|
-
logger_default.info(preview);
|
|
185
|
-
if (report.entries.length > 5) {
|
|
186
|
-
logger_default.info(`\u2026and ${report.entries.length - 5} more.`);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
} else if (format === "grouped-json") {
|
|
190
|
-
const map = resolveGrouped();
|
|
191
|
-
const { preview, moreFiles } = formatGroupedPreview(map);
|
|
192
|
-
if (preview) {
|
|
193
|
-
logger_default.log("");
|
|
194
|
-
logger_default.info(preview);
|
|
195
|
-
if (moreFiles > 0) {
|
|
196
|
-
logger_default.info(`\u2026and ${moreFiles} more files.`);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
} else {
|
|
200
|
-
const previewEntries = report.entries.slice(0, 3);
|
|
201
|
-
if (previewEntries.length) {
|
|
202
|
-
logger_default.log("");
|
|
203
|
-
logger_default.info(JSON.stringify(previewEntries, null, 2));
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (report.skippedFiles.length) {
|
|
208
|
-
logger_default.warn("Skipped files:");
|
|
209
|
-
for (const skipped of report.skippedFiles) {
|
|
210
|
-
logger_default.warn(` \u2022 ${skipped.file} (${skipped.reason})`);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
cli.command("init", "Generate a tailwindcss-patch config file").option("--cwd <dir>", "Working directory", { default: process.cwd() }).action(async (args) => {
|
|
215
|
-
await initConfig(args.cwd);
|
|
216
|
-
logger_default.success(`\u2728 ${CONFIG_NAME}.config.ts initialized!`);
|
|
217
|
-
});
|
|
6
|
+
var cli = createTailwindcssPatchCli();
|
|
218
7
|
cli.help();
|
|
219
8
|
cli.parse();
|
|
220
|
-
function formatTokenLine(entry) {
|
|
221
|
-
return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
|
|
222
|
-
}
|
|
223
|
-
function formatGroupedPreview(map, limit = 3) {
|
|
224
|
-
const files = Object.keys(map);
|
|
225
|
-
if (!files.length) {
|
|
226
|
-
return { preview: "", moreFiles: 0 };
|
|
227
|
-
}
|
|
228
|
-
const lines = files.slice(0, limit).map((file) => {
|
|
229
|
-
const tokens = map[file];
|
|
230
|
-
const sample = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
|
|
231
|
-
const suffix = tokens.length > 3 ? ", \u2026" : "";
|
|
232
|
-
return `${file}: ${tokens.length} tokens (${sample}${suffix})`;
|
|
233
|
-
});
|
|
234
|
-
return {
|
|
235
|
-
preview: lines.join("\n"),
|
|
236
|
-
moreFiles: Math.max(0, files.length - limit)
|
|
237
|
-
};
|
|
238
|
-
}
|