Skip to content

Commit 95b59a5

Browse files
committed
enable TypeScript only when using init --types for now
1 parent 19ebb7b commit 95b59a5

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/cli.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ let commands = {
151151
args: {
152152
'--full': { type: Boolean, description: 'Initialize a full `tailwind.config.js` file' },
153153
'--postcss': { type: Boolean, description: 'Initialize a `postcss.config.js` file' },
154+
'--types': {
155+
type: Boolean,
156+
description: 'Add TypeScript types for the `tailwind.config.js` file',
157+
},
154158
'-f': '--full',
155159
'-p': '--postcss',
156160
},
@@ -209,7 +213,7 @@ if (
209213
help({
210214
usage: [
211215
'tailwindcss [--input input.css] [--output output.css] [--watch] [options...]',
212-
'tailwindcss init [--full] [--postcss] [options...]',
216+
'tailwindcss init [--full] [--postcss] [--types] [options...]',
213217
],
214218
commands: Object.keys(commands)
215219
.filter((command) => command !== 'build')
@@ -336,6 +340,13 @@ function init() {
336340
'utf8'
337341
)
338342

343+
if (args['--types']) {
344+
let typesHeading = "/** @type {import('tailwindcss/types').Config} */"
345+
stubFile =
346+
stubFile.replace(`module.exports = `, `${typesHeading}\nconst config = `) +
347+
'\nmodule.exports = config'
348+
}
349+
339350
// Change colors import
340351
stubFile = stubFile.replace('../colors', 'tailwindcss/colors')
341352

stubs/defaultConfig.stub.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/** @type {import('tailwindcss/types').Config} */
2-
const config = {
1+
module.exports = {
32
content: [],
43
presets: [],
54
darkMode: 'media', // or 'class'
@@ -952,5 +951,3 @@ const config = {
952951
],
953952
plugins: [],
954953
}
955-
956-
module.exports = config

stubs/simpleConfig.stub.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
/** @type {import('tailwindcss/types').Config} */
2-
const config = {
1+
module.exports = {
32
content: [],
43
theme: {
54
extend: {},
65
},
76
plugins: [],
87
}
9-
10-
module.exports = config

0 commit comments

Comments
 (0)