@dmisdm/pandatail 0.2.0 → 0.4.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 +90 -83
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +610 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +320 -233
- package/dist/preset.d.ts +36 -13
- package/dist/project.d.ts +74 -0
- package/dist/scanCss.d.ts +30 -0
- package/dist/vite.d.ts +19 -0
- package/dist/vite.js +579 -0
- package/package.json +33 -14
- package/LICENSE +0 -21
- package/dist/extractSync.d.ts +0 -19
package/dist/cli.js
ADDED
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { existsSync as existsSync3, watch } from "node:fs";
|
|
5
|
+
import { relative as relative2, resolve as resolve5, sep } from "node:path";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
|
|
8
|
+
// src/project.ts
|
|
9
|
+
import { bundleConfig, createConfigSnapshot, mergeConfigs } from "@pandacss/config";
|
|
10
|
+
import { createCompilerFromSnapshot } from "@pandacss/compiler";
|
|
11
|
+
import { applyConfigDefaults, formatDiagnostic } from "@pandacss/compiler-shared";
|
|
12
|
+
import presetBase from "@pandacss/preset-base";
|
|
13
|
+
import { createRequire } from "node:module";
|
|
14
|
+
import { existsSync as existsSync2, statSync } from "node:fs";
|
|
15
|
+
import { relative, resolve as resolve4 } from "node:path";
|
|
16
|
+
|
|
17
|
+
// src/preset.ts
|
|
18
|
+
import { definePreset } from "@pandacss/dev";
|
|
19
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
20
|
+
import { dirname as dirname3, resolve as resolve3 } from "node:path";
|
|
21
|
+
|
|
22
|
+
// src/extract.ts
|
|
23
|
+
import { __unstable__loadDesignSystem } from "@tailwindcss/node";
|
|
24
|
+
import { readFile } from "node:fs/promises";
|
|
25
|
+
import { dirname, resolve } from "node:path";
|
|
26
|
+
|
|
27
|
+
// src/namespaces.ts
|
|
28
|
+
var TAILWIND_NAMESPACES = [
|
|
29
|
+
{ prefix: "font-weight", category: "fontWeights" },
|
|
30
|
+
{ prefix: "inset-shadow", category: "shadows" },
|
|
31
|
+
{ prefix: "drop-shadow", category: "dropShadows" },
|
|
32
|
+
{ prefix: "text-shadow", category: "shadows" },
|
|
33
|
+
{ prefix: "color", category: "colors" },
|
|
34
|
+
{ prefix: "spacing", category: "spacing" },
|
|
35
|
+
{ prefix: "font", category: "fonts" },
|
|
36
|
+
{ prefix: "text", category: "fontSizes" },
|
|
37
|
+
{ prefix: "tracking", category: "letterSpacings" },
|
|
38
|
+
{ prefix: "leading", category: "lineHeights" },
|
|
39
|
+
{ prefix: "breakpoint", category: "breakpoints" },
|
|
40
|
+
{ prefix: "container", category: "sizes" },
|
|
41
|
+
{ prefix: "radius", category: "radii" },
|
|
42
|
+
{ prefix: "shadow", category: "shadows" },
|
|
43
|
+
{ prefix: "blur", category: "blurs" },
|
|
44
|
+
{ prefix: "aspect", category: "aspectRatios" },
|
|
45
|
+
{ prefix: "ease", category: "easings" },
|
|
46
|
+
{ prefix: "animate", category: "animations" },
|
|
47
|
+
{ prefix: "perspective", category: "sizes" }
|
|
48
|
+
];
|
|
49
|
+
function deriveTokenPath(rest) {
|
|
50
|
+
const lastDash = rest.lastIndexOf("-");
|
|
51
|
+
if (lastDash > 0) {
|
|
52
|
+
const after = rest.slice(lastDash + 1);
|
|
53
|
+
if (/^\d+$/.test(after)) {
|
|
54
|
+
return [rest.slice(0, lastDash), after];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return [rest];
|
|
58
|
+
}
|
|
59
|
+
function matchNamespace(themeKey) {
|
|
60
|
+
if (!themeKey.startsWith("--"))
|
|
61
|
+
return null;
|
|
62
|
+
const stripped = themeKey.slice(2);
|
|
63
|
+
if (stripped.includes("--"))
|
|
64
|
+
return null;
|
|
65
|
+
for (const mapping of TAILWIND_NAMESPACES) {
|
|
66
|
+
if (stripped === mapping.prefix) {
|
|
67
|
+
return { mapping, rest: "DEFAULT" };
|
|
68
|
+
}
|
|
69
|
+
const withDash = `${mapping.prefix}-`;
|
|
70
|
+
if (stripped.startsWith(withDash)) {
|
|
71
|
+
return { mapping, rest: stripped.slice(withDash.length) };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/derivedScales.ts
|
|
78
|
+
var TAILWIND_NUMERIC_STEPS = [
|
|
79
|
+
0,
|
|
80
|
+
0.5,
|
|
81
|
+
1,
|
|
82
|
+
1.5,
|
|
83
|
+
2,
|
|
84
|
+
2.5,
|
|
85
|
+
3,
|
|
86
|
+
3.5,
|
|
87
|
+
4,
|
|
88
|
+
5,
|
|
89
|
+
6,
|
|
90
|
+
7,
|
|
91
|
+
8,
|
|
92
|
+
9,
|
|
93
|
+
10,
|
|
94
|
+
11,
|
|
95
|
+
12,
|
|
96
|
+
14,
|
|
97
|
+
16,
|
|
98
|
+
20,
|
|
99
|
+
24,
|
|
100
|
+
28,
|
|
101
|
+
32,
|
|
102
|
+
36,
|
|
103
|
+
40,
|
|
104
|
+
44,
|
|
105
|
+
48,
|
|
106
|
+
52,
|
|
107
|
+
56,
|
|
108
|
+
60,
|
|
109
|
+
64,
|
|
110
|
+
72,
|
|
111
|
+
80,
|
|
112
|
+
96
|
|
113
|
+
];
|
|
114
|
+
var NAMED_SIZES = {
|
|
115
|
+
full: "100%",
|
|
116
|
+
screen: "100vw",
|
|
117
|
+
"screen-h": "100vh",
|
|
118
|
+
min: "min-content",
|
|
119
|
+
max: "max-content",
|
|
120
|
+
fit: "fit-content",
|
|
121
|
+
auto: "auto"
|
|
122
|
+
};
|
|
123
|
+
var NAMED_RADII = {
|
|
124
|
+
none: "0",
|
|
125
|
+
full: "9999px"
|
|
126
|
+
};
|
|
127
|
+
function synthesiseDerivedTokens(hasSpacingBase) {
|
|
128
|
+
const out = [];
|
|
129
|
+
if (hasSpacingBase) {
|
|
130
|
+
pushNumericScale(out);
|
|
131
|
+
}
|
|
132
|
+
pushNamed(out);
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
function pushNumericScale(out) {
|
|
136
|
+
for (const step of TAILWIND_NUMERIC_STEPS) {
|
|
137
|
+
const name = String(step);
|
|
138
|
+
const value = `calc(var(--spacing) * ${name})`;
|
|
139
|
+
const cssVar = `--spacing-${name.replace(".", "_")}`;
|
|
140
|
+
out.push({ cssVar, value, category: "spacing", path: [name] });
|
|
141
|
+
out.push({ cssVar, value, category: "sizes", path: [name] });
|
|
142
|
+
out.push({ cssVar, value, category: "lineHeights", path: [name] });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function pushNamed(out) {
|
|
146
|
+
for (const [name, value] of Object.entries(NAMED_SIZES)) {
|
|
147
|
+
out.push({
|
|
148
|
+
cssVar: `--sizes-${name.replace(".", "_")}`,
|
|
149
|
+
value,
|
|
150
|
+
category: "sizes",
|
|
151
|
+
path: [name]
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
for (const [name, value] of Object.entries(NAMED_RADII)) {
|
|
155
|
+
out.push({
|
|
156
|
+
cssVar: `--radii-${name}`,
|
|
157
|
+
value,
|
|
158
|
+
category: "radii",
|
|
159
|
+
path: [name]
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/extract.ts
|
|
165
|
+
async function extractTokens(opts) {
|
|
166
|
+
const base = resolve(opts.base ?? process.cwd());
|
|
167
|
+
const ds = await __unstable__loadDesignSystem(opts.css, { base });
|
|
168
|
+
const themeEntries = new Map;
|
|
169
|
+
for (const [key, entry] of ds.theme.entries())
|
|
170
|
+
themeEntries.set(key, entry.value);
|
|
171
|
+
const out = [];
|
|
172
|
+
for (const [key, rawValue] of themeEntries) {
|
|
173
|
+
const matched = matchNamespace(key);
|
|
174
|
+
if (!matched)
|
|
175
|
+
continue;
|
|
176
|
+
if (matched.rest === "DEFAULT")
|
|
177
|
+
continue;
|
|
178
|
+
out.push({
|
|
179
|
+
cssVar: key,
|
|
180
|
+
value: matched.mapping.category === "breakpoints" ? rawValue : `var(${key})`,
|
|
181
|
+
category: matched.mapping.category,
|
|
182
|
+
path: deriveTokenPath(matched.rest)
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
out.push(...synthesiseDerivedTokens(themeEntries.has("--spacing")));
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
async function extractTokensFromFile(path) {
|
|
189
|
+
const css = await readFile(path, "utf8");
|
|
190
|
+
return extractTokens({ css, base: dirname(resolve(path)) });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/scanCss.ts
|
|
194
|
+
import postcss from "postcss";
|
|
195
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
196
|
+
import { dirname as dirname2, resolve as resolve2 } from "node:path";
|
|
197
|
+
function scanCss(opts) {
|
|
198
|
+
const out = {
|
|
199
|
+
sources: [],
|
|
200
|
+
excludes: [],
|
|
201
|
+
conditions: {},
|
|
202
|
+
warnings: [],
|
|
203
|
+
files: opts.file ? [opts.file] : []
|
|
204
|
+
};
|
|
205
|
+
walk(opts.css, opts.base, out, new Set(opts.file ? [opts.file] : []));
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
function walk(css, base, out, seen) {
|
|
209
|
+
let root;
|
|
210
|
+
try {
|
|
211
|
+
root = postcss.parse(css);
|
|
212
|
+
} catch (e) {
|
|
213
|
+
out.warnings.push(`could not parse CSS in ${base}: ${e.message}`);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
root.walkAtRules((rule) => {
|
|
217
|
+
switch (rule.name) {
|
|
218
|
+
case "import": {
|
|
219
|
+
const id = quoted(rule.params) ?? urlTarget(rule.params);
|
|
220
|
+
if (!id || !id.startsWith("."))
|
|
221
|
+
return;
|
|
222
|
+
const path = resolve2(base, id);
|
|
223
|
+
if (seen.has(path) || !existsSync(path))
|
|
224
|
+
return;
|
|
225
|
+
seen.add(path);
|
|
226
|
+
out.files.push(path);
|
|
227
|
+
walk(readFileSync(path, "utf8"), dirname2(path), out, seen);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
case "source":
|
|
231
|
+
return handleSource(rule, base, out);
|
|
232
|
+
case "custom-variant":
|
|
233
|
+
return handleCustomVariant(rule, out);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function handleSource(rule, base, out) {
|
|
238
|
+
const params = rule.params.trim();
|
|
239
|
+
if (params.startsWith("inline(") || params.startsWith("not inline(")) {
|
|
240
|
+
out.warnings.push(`@source ${params}: inline sources have no Panda equivalent`);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const isNot = /^not\s/.test(params);
|
|
244
|
+
const target = quoted(isNot ? params.replace(/^not\s+/, "") : params);
|
|
245
|
+
if (!target)
|
|
246
|
+
return;
|
|
247
|
+
(isNot ? out.excludes : out.sources).push(resolve2(base, target));
|
|
248
|
+
}
|
|
249
|
+
function handleCustomVariant(rule, out) {
|
|
250
|
+
const params = rule.params.trim();
|
|
251
|
+
const name = /^([\w-]+)/.exec(params)?.[1];
|
|
252
|
+
if (!name)
|
|
253
|
+
return;
|
|
254
|
+
if (!rule.nodes) {
|
|
255
|
+
const m = /^[\w-]+\s*\(([\s\S]+)\)$/.exec(params);
|
|
256
|
+
if (m)
|
|
257
|
+
out.conditions[name] = m[1].trim();
|
|
258
|
+
else
|
|
259
|
+
out.warnings.push(`@custom-variant ${name}: unrecognised form`);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const body = rule.nodes.filter((n) => n.type !== "comment");
|
|
263
|
+
const only = body.length === 1 ? body[0] : undefined;
|
|
264
|
+
if (only?.type === "atrule" && only.name !== "slot" && isSlotOnly(only)) {
|
|
265
|
+
out.conditions[name] = `@${only.name} ${only.params}`.trim();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (only?.type === "rule" && isSlotOnly(only)) {
|
|
269
|
+
out.conditions[name] = only.selector;
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
out.warnings.push(`@custom-variant ${name}: block form is too complex to map to a Panda condition`);
|
|
273
|
+
}
|
|
274
|
+
function isSlotOnly(node) {
|
|
275
|
+
const kids = (node.nodes ?? []).filter((n) => n.type !== "comment");
|
|
276
|
+
return kids.length === 1 && kids[0].type === "atrule" && kids[0].name === "slot";
|
|
277
|
+
}
|
|
278
|
+
function quoted(params) {
|
|
279
|
+
return /^\s*["']([^"']+)["']/.exec(params)?.[1] ?? null;
|
|
280
|
+
}
|
|
281
|
+
function urlTarget(params) {
|
|
282
|
+
return /^\s*url\(\s*["']?([^"')]+)["']?\s*\)/.exec(params)?.[1] ?? null;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// src/preset.ts
|
|
286
|
+
async function loadTailwind(opts) {
|
|
287
|
+
let css;
|
|
288
|
+
let base;
|
|
289
|
+
let file;
|
|
290
|
+
if (opts.css != null) {
|
|
291
|
+
css = opts.css;
|
|
292
|
+
base = opts.base ?? process.cwd();
|
|
293
|
+
} else if (opts.cssPath != null) {
|
|
294
|
+
file = resolve3(opts.cssPath);
|
|
295
|
+
css = await readFile2(file, "utf8");
|
|
296
|
+
base = dirname3(file);
|
|
297
|
+
} else {
|
|
298
|
+
throw new Error("pandatail: provide either `css` or `cssPath`");
|
|
299
|
+
}
|
|
300
|
+
const tokens = await extractTokens({ css, base });
|
|
301
|
+
const scan = scanCss({ css, base, file });
|
|
302
|
+
return { preset: buildPreset(tokens, scan), scan, tokens };
|
|
303
|
+
}
|
|
304
|
+
async function tailwindPreset(opts) {
|
|
305
|
+
return (await loadTailwind(opts)).preset;
|
|
306
|
+
}
|
|
307
|
+
function buildPreset(tokens, scan) {
|
|
308
|
+
const breakpoints = {};
|
|
309
|
+
const tokenTokens = [];
|
|
310
|
+
for (const t of tokens) {
|
|
311
|
+
if (t.category === "breakpoints") {
|
|
312
|
+
breakpoints[t.path.join("-")] = t.value;
|
|
313
|
+
} else {
|
|
314
|
+
tokenTokens.push(t);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const tokensByCategory = groupByCategory(tokenTokens);
|
|
318
|
+
const theme = {};
|
|
319
|
+
for (const [category, list] of Object.entries(tokensByCategory)) {
|
|
320
|
+
theme[category] = buildTree(list, category);
|
|
321
|
+
}
|
|
322
|
+
const preset = definePreset({
|
|
323
|
+
name: "tailwind",
|
|
324
|
+
theme: {
|
|
325
|
+
tokens: theme,
|
|
326
|
+
breakpoints
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
if (scan && Object.keys(scan.conditions).length > 0) {
|
|
330
|
+
preset.conditions = { extend: scan.conditions };
|
|
331
|
+
}
|
|
332
|
+
return preset;
|
|
333
|
+
}
|
|
334
|
+
function groupByCategory(tokens) {
|
|
335
|
+
const out = {};
|
|
336
|
+
for (const t of tokens) {
|
|
337
|
+
(out[t.category] ??= []).push(t);
|
|
338
|
+
}
|
|
339
|
+
return out;
|
|
340
|
+
}
|
|
341
|
+
function buildTree(tokens, category) {
|
|
342
|
+
const root = {};
|
|
343
|
+
for (const t of tokens) {
|
|
344
|
+
let cursor = root;
|
|
345
|
+
for (let i = 0;i < t.path.length - 1; i++) {
|
|
346
|
+
const seg = t.path[i];
|
|
347
|
+
const next = cursor[seg];
|
|
348
|
+
if (next && "value" in next) {
|
|
349
|
+
throw new Error(`pandatail: token path collision in '${category}' at ` + `'${t.path.slice(0, i + 1).join(".")}': ` + `'${t.path.join(".")}' nests under a token that is already a leaf.`);
|
|
350
|
+
}
|
|
351
|
+
if (!next) {
|
|
352
|
+
const fresh = {};
|
|
353
|
+
cursor[seg] = fresh;
|
|
354
|
+
cursor = fresh;
|
|
355
|
+
} else {
|
|
356
|
+
cursor = next;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const leaf = t.path[t.path.length - 1];
|
|
360
|
+
const existing = cursor[leaf];
|
|
361
|
+
if (existing && !("value" in existing)) {
|
|
362
|
+
throw new Error(`pandatail: token path collision in '${category}' at ` + `'${t.path.join(".")}': a leaf token clashes with an existing group.`);
|
|
363
|
+
}
|
|
364
|
+
cursor[leaf] = { value: t.value };
|
|
365
|
+
}
|
|
366
|
+
return root;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// src/project.ts
|
|
370
|
+
var DEFAULT_EXT = "{js,jsx,ts,tsx,mdx}";
|
|
371
|
+
async function createPandatailProject(opts) {
|
|
372
|
+
const cwd = resolve4(opts.cwd ?? process.cwd());
|
|
373
|
+
const cssPath = resolve4(cwd, opts.css);
|
|
374
|
+
if (!existsSync2(cssPath))
|
|
375
|
+
throw new Error(`pandatail: CSS entry not found: ${cssPath}`);
|
|
376
|
+
const tw = await loadTailwind({ cssPath });
|
|
377
|
+
const dependencies = [...tw.scan.files];
|
|
378
|
+
let user = {};
|
|
379
|
+
if (typeof opts.config === "string") {
|
|
380
|
+
const file = resolve4(cwd, opts.config);
|
|
381
|
+
const bundled = await bundleConfig(file, cwd);
|
|
382
|
+
user = bundled.config;
|
|
383
|
+
dependencies.push(file, ...bundled.dependencies);
|
|
384
|
+
} else if (opts.config) {
|
|
385
|
+
user = opts.config;
|
|
386
|
+
}
|
|
387
|
+
const { presets: userPresetList, ...userRest } = user;
|
|
388
|
+
const userPresets = await resolvePresets(userPresetList, cwd);
|
|
389
|
+
const include = opts.include ?? unique([
|
|
390
|
+
...userRest.include ?? [`./src/**/*.${DEFAULT_EXT}`],
|
|
391
|
+
...tw.scan.sources.map((p) => sourceToGlob(p, cwd))
|
|
392
|
+
]);
|
|
393
|
+
const exclude = opts.exclude ?? unique([
|
|
394
|
+
...userRest.exclude ?? [],
|
|
395
|
+
...tw.scan.excludes.map((p) => sourceToGlob(p, cwd))
|
|
396
|
+
]);
|
|
397
|
+
const defaults = {
|
|
398
|
+
cwd,
|
|
399
|
+
preflight: false,
|
|
400
|
+
jsxFramework: "react",
|
|
401
|
+
jsxStyleProps: "all",
|
|
402
|
+
outdir: "styled-system"
|
|
403
|
+
};
|
|
404
|
+
const finalOverrides = { include, exclude, cwd };
|
|
405
|
+
for (const key of [
|
|
406
|
+
"outdir",
|
|
407
|
+
"jsxFramework",
|
|
408
|
+
"jsxStyleProps",
|
|
409
|
+
"preflight",
|
|
410
|
+
"importMap",
|
|
411
|
+
"prefix",
|
|
412
|
+
"hash",
|
|
413
|
+
"minify"
|
|
414
|
+
]) {
|
|
415
|
+
if (opts[key] !== undefined)
|
|
416
|
+
finalOverrides[key] = opts[key];
|
|
417
|
+
}
|
|
418
|
+
const merged = mergeConfigs([
|
|
419
|
+
defaults,
|
|
420
|
+
presetBase,
|
|
421
|
+
...userPresets,
|
|
422
|
+
tw.preset,
|
|
423
|
+
userRest,
|
|
424
|
+
finalOverrides
|
|
425
|
+
]);
|
|
426
|
+
const config = applyConfigDefaults(merged, cwd);
|
|
427
|
+
const compiler = createCompilerFromSnapshot(createConfigSnapshot(config));
|
|
428
|
+
return {
|
|
429
|
+
compiler,
|
|
430
|
+
config,
|
|
431
|
+
cwd,
|
|
432
|
+
outdir: resolve4(cwd, config.outdir ?? "styled-system"),
|
|
433
|
+
dependencies: unique(dependencies),
|
|
434
|
+
warnings: tw.scan.warnings
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
function buildProject(project, opts = {}) {
|
|
438
|
+
const { compiler, cwd, outdir } = project;
|
|
439
|
+
const files = compiler.scan();
|
|
440
|
+
compiler.parseFiles(files);
|
|
441
|
+
let artifacts = 0;
|
|
442
|
+
if (opts.codegen !== false) {
|
|
443
|
+
artifacts = compiler.writeArtifacts({ outdir, cwd }).length;
|
|
444
|
+
}
|
|
445
|
+
let cssPath;
|
|
446
|
+
if (opts.outfile !== false) {
|
|
447
|
+
const outfile = opts.outfile ?? relative(cwd, resolve4(outdir, "styles.css"));
|
|
448
|
+
cssPath = compiler.writeCss({ outfile, cwd }).path;
|
|
449
|
+
}
|
|
450
|
+
return { files, artifacts, cssPath, diagnostics: compiler.diagnostics() };
|
|
451
|
+
}
|
|
452
|
+
function sourceToGlob(path, cwd) {
|
|
453
|
+
const rel = relative(cwd, path).split("\\").join("/");
|
|
454
|
+
const p = rel.startsWith(".") ? rel : `./${rel}`;
|
|
455
|
+
const hasGlob = /[*?{}\[\]]/.test(p);
|
|
456
|
+
if (!hasGlob && existsSync2(path) && statSync(path).isDirectory()) {
|
|
457
|
+
return `${p}/**/*.${DEFAULT_EXT}`;
|
|
458
|
+
}
|
|
459
|
+
return p;
|
|
460
|
+
}
|
|
461
|
+
async function resolvePresets(list, cwd) {
|
|
462
|
+
const out = [];
|
|
463
|
+
for (const entry of list ?? []) {
|
|
464
|
+
const preset = await loadPreset(entry, cwd);
|
|
465
|
+
const { presets, ...rest } = preset;
|
|
466
|
+
out.push(...await resolvePresets(presets, cwd), rest);
|
|
467
|
+
}
|
|
468
|
+
return out;
|
|
469
|
+
}
|
|
470
|
+
async function loadPreset(entry, cwd) {
|
|
471
|
+
const value = await entry;
|
|
472
|
+
if (typeof value !== "string")
|
|
473
|
+
return value;
|
|
474
|
+
const req = createRequire(resolve4(cwd, "__pandatail_anchor__"));
|
|
475
|
+
let mod;
|
|
476
|
+
try {
|
|
477
|
+
mod = await import(req.resolve(value));
|
|
478
|
+
} catch {
|
|
479
|
+
mod = await import(value);
|
|
480
|
+
}
|
|
481
|
+
return mod.default ?? mod.preset ?? mod;
|
|
482
|
+
}
|
|
483
|
+
function unique(xs) {
|
|
484
|
+
return [...new Set(xs)];
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/cli.ts
|
|
488
|
+
var HELP = `pandatail: run Panda from a Tailwind v4 stylesheet, no panda.config.ts needed
|
|
489
|
+
|
|
490
|
+
Usage
|
|
491
|
+
pandatail <command> --css <entry.css> [options]
|
|
492
|
+
|
|
493
|
+
Commands
|
|
494
|
+
build generate styled-system/ and the stylesheet (default)
|
|
495
|
+
codegen generate styled-system/ only
|
|
496
|
+
cssgen write the stylesheet only
|
|
497
|
+
watch build, then rebuild on change
|
|
498
|
+
|
|
499
|
+
Options
|
|
500
|
+
-c, --css <file> Tailwind entry stylesheet (required)
|
|
501
|
+
-o, --out <file> stylesheet to write (default: <outdir>/styles.css)
|
|
502
|
+
--config <file> optional panda.config.ts merged on top of the CSS
|
|
503
|
+
--outdir <dir> generated code directory (default: styled-system)
|
|
504
|
+
-i, --include <glob> source glob to scan; repeatable
|
|
505
|
+
--cwd <dir> project root (default: current directory)
|
|
506
|
+
-h, --help
|
|
507
|
+
`;
|
|
508
|
+
async function main() {
|
|
509
|
+
const { values, positionals } = parseArgs({
|
|
510
|
+
allowPositionals: true,
|
|
511
|
+
options: {
|
|
512
|
+
css: { type: "string", short: "c" },
|
|
513
|
+
out: { type: "string", short: "o" },
|
|
514
|
+
config: { type: "string" },
|
|
515
|
+
outdir: { type: "string" },
|
|
516
|
+
include: { type: "string", short: "i", multiple: true },
|
|
517
|
+
cwd: { type: "string" },
|
|
518
|
+
help: { type: "boolean", short: "h" }
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
const command = positionals[0] ?? "build";
|
|
522
|
+
if (values.help || !["build", "codegen", "cssgen", "watch"].includes(command)) {
|
|
523
|
+
console.log(HELP);
|
|
524
|
+
process.exit(values.help ? 0 : 1);
|
|
525
|
+
}
|
|
526
|
+
if (!values.css) {
|
|
527
|
+
console.error(`pandatail: --css <entry.css> is required
|
|
528
|
+
`);
|
|
529
|
+
console.error(HELP);
|
|
530
|
+
process.exit(1);
|
|
531
|
+
}
|
|
532
|
+
const options = {
|
|
533
|
+
css: values.css,
|
|
534
|
+
cwd: values.cwd,
|
|
535
|
+
config: values.config,
|
|
536
|
+
outdir: values.outdir,
|
|
537
|
+
include: values.include
|
|
538
|
+
};
|
|
539
|
+
const buildOpts = {
|
|
540
|
+
codegen: command !== "cssgen",
|
|
541
|
+
outfile: command === "codegen" ? false : values.out
|
|
542
|
+
};
|
|
543
|
+
let project = await load(options);
|
|
544
|
+
report(project, run(project, buildOpts));
|
|
545
|
+
if (command !== "watch")
|
|
546
|
+
return;
|
|
547
|
+
console.log("pandatail: watching for changes…");
|
|
548
|
+
const ignored = (path) => path.split(sep).some((s) => s === "node_modules" || s === ".git") || path.startsWith(project.outdir);
|
|
549
|
+
let timer;
|
|
550
|
+
const pending = new Set;
|
|
551
|
+
const flush = async () => {
|
|
552
|
+
const changed = [...pending];
|
|
553
|
+
pending.clear();
|
|
554
|
+
try {
|
|
555
|
+
if (changed.some((p) => project.dependencies.includes(p))) {
|
|
556
|
+
project = await load(options);
|
|
557
|
+
report(project, run(project, buildOpts));
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
for (const file of changed) {
|
|
561
|
+
if (existsSync3(file))
|
|
562
|
+
project.compiler.refreshFile(file);
|
|
563
|
+
else
|
|
564
|
+
project.compiler.removeFile(file);
|
|
565
|
+
}
|
|
566
|
+
report(project, run(project, { ...buildOpts, codegen: false }), true);
|
|
567
|
+
} catch (e) {
|
|
568
|
+
console.error(`pandatail: ${e.message}`);
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
watch(project.cwd, { recursive: true }, (_event, name) => {
|
|
572
|
+
if (!name)
|
|
573
|
+
return;
|
|
574
|
+
const abs = resolve5(project.cwd, name.toString());
|
|
575
|
+
if (ignored(abs))
|
|
576
|
+
return;
|
|
577
|
+
const isDep = project.dependencies.includes(abs);
|
|
578
|
+
if (!isDep && !project.compiler.isSourceFile(abs))
|
|
579
|
+
return;
|
|
580
|
+
pending.add(abs);
|
|
581
|
+
clearTimeout(timer);
|
|
582
|
+
timer = setTimeout(flush, 60);
|
|
583
|
+
});
|
|
584
|
+
await new Promise(() => {});
|
|
585
|
+
}
|
|
586
|
+
async function load(options) {
|
|
587
|
+
const project = await createPandatailProject(options);
|
|
588
|
+
for (const w of project.warnings)
|
|
589
|
+
console.warn(`pandatail: warning: ${w}`);
|
|
590
|
+
return project;
|
|
591
|
+
}
|
|
592
|
+
function run(project, opts) {
|
|
593
|
+
return buildProject(project, opts);
|
|
594
|
+
}
|
|
595
|
+
function report(project, r, quiet = false) {
|
|
596
|
+
for (const d of r.diagnostics)
|
|
597
|
+
console.warn(formatDiagnostic(d));
|
|
598
|
+
const rel = (p) => relative2(project.cwd, p) || p;
|
|
599
|
+
const parts = [`${r.files.length} source file(s)`];
|
|
600
|
+
if (r.artifacts)
|
|
601
|
+
parts.push(`${r.artifacts} generated file(s) → ${rel(project.outdir)}/`);
|
|
602
|
+
if (r.cssPath)
|
|
603
|
+
parts.push(`css → ${rel(r.cssPath)}`);
|
|
604
|
+
if (!quiet || r.cssPath)
|
|
605
|
+
console.log(`pandatail: ${parts.join(", ")}`);
|
|
606
|
+
}
|
|
607
|
+
main().catch((e) => {
|
|
608
|
+
console.error(`pandatail: ${e.message}`);
|
|
609
|
+
process.exit(1);
|
|
610
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createPandatailProject, buildProject, formatDiagnostic, type PandatailOptions, type PandatailProject, type BuildOptions, type BuildResult, } from "./project";
|
|
2
|
+
export { tailwindPreset, loadTailwind, type TailwindPresetOptions, type LoadedTailwind, } from "./preset";
|
|
2
3
|
export { extractTokens, extractTokensFromFile, type ExtractedToken, type ExtractOptions, } from "./extract";
|
|
3
|
-
export {
|
|
4
|
+
export { scanCss, type CssScan, type ScanCssOptions } from "./scanCss";
|
|
4
5
|
export { matchNamespace, TAILWIND_NAMESPACES, type NamespaceMapping, type PandaTokenCategory, } from "./namespaces";
|