Skip to content

Instantly share code, notes, and snippets.

@joshdavenport
Created May 17, 2023 18:38
Show Gist options
  • Save joshdavenport/aabab07a658113cf646317f380fd4af6 to your computer and use it in GitHub Desktop.
Save joshdavenport/aabab07a658113cf646317f380fd4af6 to your computer and use it in GitHub Desktop.
// Name: Tailwind Check
// Author: Josh Davenport-Smith
// Twitter: @joshdprts
import "@johnlindquist/kit";
const b = await npm("beautify");
const input = await arg({
name: "Enter Tailwind classes",
hint: "Enter Tailwind classes to check, only supports stock theme values. Values are applied to a .output-check class.",
});
const checkFile = `/tmp/tw-${Date.now()}.css`;
writeFile(
checkFile,
`
@tailwind base;
@tailwind components;
@tailwind utilities;
/*OUTPUTCHECKSTART*/
.output-check {
@apply ${input};
}
/*OUTPUTCHECKEND*/
`
);
const { stdout } = await exec(`npx tailwindcss -i ${checkFile}`);
rm(checkFile);
const outputMatch = stdout
.replace(/\n/g, "")
.match(/\/\*OUTPUTCHECKSTART\*\/([^\/]+)\/\*OUTPUTCHECKEND\*\//);
const output = outputMatch[1].trim();
await div(`
<pre class="px-2 py-2">${b(output, { format: "css" })}</code>
`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment