From 6fc76138eafb2d7db1a312ff961df0e7840f4efb Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Mon, 21 Mar 2022 16:40:51 +0100 Subject: [PATCH] enable TypeScript only when using `init --types` for now --- src/cli.js | 14 +++++++++++++- stubs/defaultConfig.stub.js | 5 +---- stubs/simpleConfig.stub.js | 5 +---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/cli.js b/src/cli.js index 8aee860a870f..38262fa43ebe 100644 --- a/src/cli.js +++ b/src/cli.js @@ -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', }, @@ -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') @@ -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') diff --git a/stubs/defaultConfig.stub.js b/stubs/defaultConfig.stub.js index 0d8ad5d4b6f5..cff789cb843f 100644 --- a/stubs/defaultConfig.stub.js +++ b/stubs/defaultConfig.stub.js @@ -1,5 +1,4 @@ -/** @type {import('tailwindcss/types').Config} */ -const config = { +module.exports = { content: [], presets: [], darkMode: 'media', // or 'class' @@ -952,5 +951,3 @@ const config = { ], plugins: [], } - -module.exports = config diff --git a/stubs/simpleConfig.stub.js b/stubs/simpleConfig.stub.js index 7d987c73b26e..9843c05570a6 100644 --- a/stubs/simpleConfig.stub.js +++ b/stubs/simpleConfig.stub.js @@ -1,10 +1,7 @@ -/** @type {import('tailwindcss/types').Config} */ -const config = { +module.exports = { content: [], theme: { extend: {}, }, plugins: [], } - -module.exports = config