Skip to content

Commit

Permalink
enable TypeScript only when using init --types for now
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinMalfait committed Mar 21, 2022
1 parent 19ebb7b commit 6fc7613
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
14 changes: 13 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ let commands = {
args: {
'--full': { type: Boolean, description: 'Initialize a full `tailwind.config.js` file' },
'--postcss': { type: Boolean, description: 'Initialize a `postcss.config.js` file' },
'--types': {
type: Boolean,
description: 'Add TypeScript types for the `tailwind.config.js` file',
},
'-f': '--full',
'-p': '--postcss',
},
Expand Down Expand Up @@ -209,7 +213,7 @@ if (
help({
usage: [
'tailwindcss [--input input.css] [--output output.css] [--watch] [options...]',
'tailwindcss init [--full] [--postcss] [options...]',
'tailwindcss init [--full] [--postcss] [--types] [options...]',
],
commands: Object.keys(commands)
.filter((command) => command !== 'build')
Expand Down Expand Up @@ -336,6 +340,14 @@ function init() {
'utf8'
)

if (args['--types']) {
let typesHeading = "/** @type {import('tailwindcss/types').Config} */"
stubFile =
stubFile.replace(`module.exports = `, `${typesHeading}\nconst config = `) +
'\n\n' +
'module.exports = config'
}

// Change colors import
stubFile = stubFile.replace('../colors', 'tailwindcss/colors')

Expand Down
5 changes: 1 addition & 4 deletions stubs/defaultConfig.stub.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @type {import('tailwindcss/types').Config} */
const config = {
module.exports = {
content: [],
presets: [],
darkMode: 'media', // or 'class'
Expand Down Expand Up @@ -952,5 +951,3 @@ const config = {
],
plugins: [],
}

module.exports = config
5 changes: 1 addition & 4 deletions stubs/simpleConfig.stub.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/** @type {import('tailwindcss/types').Config} */
const config = {
module.exports = {
content: [],
theme: {
extend: {},
},
plugins: [],
}

module.exports = config

0 comments on commit 6fc7613

Please sign in to comment.