Skip to content

Commit

Permalink
feat: automatically discover new style entries
Browse files Browse the repository at this point in the history
  • Loading branch information
nyarthan committed Feb 27, 2024
1 parent e8204ff commit 3fcbcef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
20 changes: 11 additions & 9 deletions packages/css2tailwind/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { z } from 'zod';

import { parseStyles, writeStyles } from './build';
import { NoStylesDirectory } from './error';
import { kinds } from './util';

const { argv } = yargs(hideBin(process.argv))
.usage('tgp <styles-directory> <output-directory>')
Expand Down Expand Up @@ -54,24 +53,27 @@ async function assertDirExists(dir: string) {
async function main() {
await assertDirExists(stylesDirectory);

const dirents = await fsp.readdir(stylesDirectory, { withFileTypes: true });
const entries = dirents.filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);

await Promise.all(
kinds.map(async (kind) => {
const styles = await parseStyles(path.join(stylesDirectory, kind));
await writeStyles(outputDirectory, kind, styles);
entries.map(async (entry) => {
const styles = await parseStyles(path.join(stylesDirectory, entry));
await writeStyles(outputDirectory, entry, styles);
}),
);

if (!args.watch) process.exit(0);

for (const kind of kinds) {
const kindPath = path.join(stylesDirectory, kind);
const watcher = watch(`${kindPath}/*/*.css`, {
for (const entry of entries) {
const entryPath = path.join(stylesDirectory, entry);
const watcher = watch(`${entryPath}/*/*.css`, {
awaitWriteFinish: { stabilityThreshold: 10, pollInterval: 10 },
});
watcher.on('change', () => {
void (async () => {
const styles = await parseStyles(path.join(stylesDirectory, kind));
await writeStyles(outputDirectory, kind, styles);
const styles = await parseStyles(path.join(stylesDirectory, entry));
await writeStyles(outputDirectory, entry, styles);
})();
});
}
Expand Down
6 changes: 0 additions & 6 deletions packages/css2tailwind/src/config.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/css2tailwind/src/util.ts

This file was deleted.

0 comments on commit 3fcbcef

Please sign in to comment.