Skip to content

Commit 6db6316

Browse files
committed
feat: support typescript configs
1 parent 0c214c3 commit 6db6316

File tree

4 files changed

+42
-19
lines changed

4 files changed

+42
-19
lines changed

README.md

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,45 @@ yarn add @twind/cli
2020
## Usage
2121

2222
```bash
23-
node -r esm -r esbuild-register bin/twind.js -c src/__fixtures__/twind.config.js -o build/tailwind.css -w -b
23+
# Find all htm,html,js,jsx,tsx,svelte,vue,mdx files and print generated CSS
24+
twind
25+
26+
# Write CSS to a file
27+
twind -o public/styles.css
28+
29+
# Use custom globs
30+
twind 'src/**/*.jsx' 'public/**/*.html'
31+
32+
# Watch mode
33+
twind -w
34+
35+
# Generate beautified css file
36+
twind -b
37+
38+
# Use different twind config (esm or cjs)
39+
twind -c src/twind.config.js
40+
41+
# Use different tailwind config (esm or cjs)
42+
twind -c tailwind.prod.js
2443
```
2544

2645
```
2746
Usage
2847
$ twind [...globs=**/*.{htm,html,js,jsx,tsx,svelte,vue,mdx}] [options]
2948
3049
Options
31-
-o, --output Set output css file path
32-
-c, --config Set config file path
33-
-i, --ignore Any file patterns to ignore
34-
--ignore-file gitignore like file (default .gitignore)
35-
-b, --beautify Generate beautified css file (default false)
36-
-C, --cwd The current directory to resolve from (default .)
37-
-w, --watch Watch for changes (default false)
38-
--color Print colorized output (default [object Object])
39-
-v, --version Displays current version
40-
-h, --help Displays this message
50+
-o, --output Set output css file path (default print to console)
51+
-c, --config Set config file path (default twind.config.[cm]js or tailwind.config.[cm]js
52+
-i, --ignore Any file patterns to ignore
53+
-I, --ignore-file gitignore like file (default .gitignore)
54+
-b, --beautify Generate beautified css file (default false)
55+
-C, --cwd The current directory to resolve from (default .)
56+
-w, --watch Watch for changes (default false)
57+
--color Print colorized output - to disable use --no-color (default true)
58+
-v, --version Displays current version
59+
-h, --help Displays this message
4160
```
4261

4362
## License
4463

45-
[MIT](https://github.com/tw-in-js/content/blob/main/LICENSE)
64+
[MIT](https://github.com/tw-in-js/cli/blob/main/LICENSE)

src/__fixtures__/test.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
<title>Twind</title>
77
</head>
88
<body>
9-
<h1 class="text-3xl sm:text-6xl">Hello World"</h1>
9+
<h1 class="text-3xl sm:text-4xl hover:underline sm:hover:focus:first:bg-red-500">Hello World"</h1>
1010
</body>
1111
</html>

src/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import supportsColor from 'supports-color'
66
export const cli = (argv = process.argv) =>
77
sade('twind [...globs=**/*.{htm,html,js,jsx,tsx,svelte,vue,mdx}]', /* single commmand */ true)
88
.version(version)
9-
.option('-o, --output', 'Set output css file path (default print to console)')
9+
.option('-o, --output', 'Set output css file path (default print to console)')
1010
.option(
1111
'-c, --config',
12-
'Set config file path (default twind.config.[cm]js or tailwind.config.[cm]js',
12+
'Set config file path (default twind.config.{[cm]js,ts} or tailwind.config.{[cm]js,ts})',
1313
)
1414
.option('-i, --ignore', 'Any file patterns to ignore')
1515
.option('-I, --ignore-file', 'gitignore like file', '.gitignore')
1616
.option('-b, --beautify', 'Generate beautified css file', false)
1717
.option('-C, --cwd', 'The current directory to resolve from', '.')
1818
.option('-w, --watch', 'Watch for changes', false)
19-
.option('--color', 'Print colorized output - to disable use --no-color', supportsColor.stderr)
19+
.option('--color', 'Print colorized output - to disable use --no-color', !!supportsColor.stderr)
2020
.action(async (globs, { _, ['ignore-file']: ignoreFile, ...options }) => {
2121
try {
2222
await run([globs, ..._], { ...options, ignoreFile })

src/run.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ const run$ = async (globs: string[], options: RunOptions, esbuild: Service): Pro
112112

113113
const configFile =
114114
(options.config && path.resolve(options.cwd, options.config)) ||
115-
(await findUp(['twind.config.js', 'twind.config.mjs', 'twind.config.cjs'], {
115+
(await findUp(['twind.config.js', 'twind.config.mjs', 'twind.config.cjs', 'twind.config.ts'], {
116116
cwd: options.cwd,
117117
})) ||
118-
(await findUp(['tailwind.config.js', 'tailwind.config.mjs', 'tailwind.config.cjs'], {
118+
(await findUp(['tailwind.config.js', 'tailwind.config.mjs', 'tailwind.config.cjs', 'tailwind.config.ts'], {
119119
cwd: options.cwd,
120120
}))
121121

@@ -184,7 +184,7 @@ const run$ = async (globs: string[], options: RunOptions, esbuild: Service): Pro
184184
}
185185

186186
console.error(
187-
kleur.dim(`Watching the following patterns: ${kleur.bold(JSON.stringify(globs).slice(1, -1))}`),
187+
kleur.dim(`Using the following patterns: ${kleur.bold(JSON.stringify(globs).slice(1, -1))}`),
188188
)
189189

190190
for await (const changes of watch(configFile ? [configFile, ...globs] : globs, options)) {
@@ -316,6 +316,10 @@ const run$ = async (globs: string[], options: RunOptions, esbuild: Service): Pro
316316
console.error('\n' + kleur.dim('Waiting for file changes...'))
317317
}
318318
}
319+
320+
if (runCount < 0) {
321+
console.error(kleur.yellow(`No matching files found...`))
322+
}
319323
}
320324

321325
function equals(a: Set<unknown>, b: Set<unknown>) {

0 commit comments

Comments
 (0)