diff --git a/__tests__/cli.test.js b/__tests__/cli.test.js index 5dcbcf69a..5d434c37d 100644 --- a/__tests__/cli.test.js +++ b/__tests__/cli.test.js @@ -28,6 +28,13 @@ describe('cli', () => { expect(utils.writeFile.mock.calls[0][1]).toContain('defaultConfig') }) }) + + it('creates a Tailwind config file without comments', () => { + cli(['init', '--no-comments']).then(() => { + expect(utils.writeFile.mock.calls[0][1]).not.toContain('/**') + expect(utils.writeFile.mock.calls[0][1]).toContain('//') + }) + }) }) describe('build', () => { diff --git a/defaultConfig.stub.js b/defaultConfig.stub.js index d7d0a612d..8ae0d6872 100644 --- a/defaultConfig.stub.js +++ b/defaultConfig.stub.js @@ -1,4 +1,4 @@ -/* +/** Tailwind - The Utility-First CSS Framework @@ -27,7 +27,7 @@ View the full documentation at https://tailwindcss.com. // let defaultConfig = require('tailwindcss/defaultConfig')() -/* +/** |------------------------------------------------------------------------------- | Colors https://tailwindcss.com/docs/colors |------------------------------------------------------------------------------- @@ -131,7 +131,7 @@ let colors = { module.exports = { - /* + /** |----------------------------------------------------------------------------- | Colors https://tailwindcss.com/docs/colors |----------------------------------------------------------------------------- @@ -147,7 +147,7 @@ module.exports = { colors: colors, - /* + /** |----------------------------------------------------------------------------- | Screens https://tailwindcss.com/docs/responsive-design |----------------------------------------------------------------------------- @@ -174,7 +174,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Fonts https://tailwindcss.com/docs/fonts |----------------------------------------------------------------------------- @@ -230,7 +230,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Text sizes https://tailwindcss.com/docs/text-sizing |----------------------------------------------------------------------------- @@ -262,7 +262,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Font weights https://tailwindcss.com/docs/font-weight |----------------------------------------------------------------------------- @@ -289,7 +289,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Leading (line height) https://tailwindcss.com/docs/line-height |----------------------------------------------------------------------------- @@ -309,7 +309,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Tracking (letter spacing) https://tailwindcss.com/docs/letter-spacing |----------------------------------------------------------------------------- @@ -328,7 +328,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Text colors https://tailwindcss.com/docs/text-color |----------------------------------------------------------------------------- @@ -344,7 +344,7 @@ module.exports = { textColors: colors, - /* + /** |----------------------------------------------------------------------------- | Background colors https://tailwindcss.com/docs/background-color |----------------------------------------------------------------------------- @@ -360,7 +360,7 @@ module.exports = { backgroundColors: colors, - /* + /** |----------------------------------------------------------------------------- | Background sizes https://tailwindcss.com/docs/background-size |----------------------------------------------------------------------------- @@ -380,7 +380,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Border widths https://tailwindcss.com/docs/border-width |----------------------------------------------------------------------------- @@ -402,7 +402,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Border colors https://tailwindcss.com/docs/border-color |----------------------------------------------------------------------------- @@ -422,7 +422,7 @@ module.exports = { borderColors: global.Object.assign({ default: colors['grey-light'] }, colors), - /* + /** |----------------------------------------------------------------------------- | Border radius https://tailwindcss.com/docs/border-radius |----------------------------------------------------------------------------- @@ -447,7 +447,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Width https://tailwindcss.com/docs/width |----------------------------------------------------------------------------- @@ -500,7 +500,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Height https://tailwindcss.com/docs/height |----------------------------------------------------------------------------- @@ -537,7 +537,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Minimum width https://tailwindcss.com/docs/min-width |----------------------------------------------------------------------------- @@ -557,7 +557,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Minimum height https://tailwindcss.com/docs/min-height |----------------------------------------------------------------------------- @@ -578,7 +578,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Maximum width https://tailwindcss.com/docs/max-width |----------------------------------------------------------------------------- @@ -607,7 +607,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Maximum height https://tailwindcss.com/docs/max-height |----------------------------------------------------------------------------- @@ -627,7 +627,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Padding https://tailwindcss.com/docs/padding |----------------------------------------------------------------------------- @@ -661,7 +661,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Margin https://tailwindcss.com/docs/margin |----------------------------------------------------------------------------- @@ -696,7 +696,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Negative margin https://tailwindcss.com/docs/negative-margin |----------------------------------------------------------------------------- @@ -730,7 +730,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Shadows https://tailwindcss.com/docs/shadows |----------------------------------------------------------------------------- @@ -756,7 +756,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Z-index https://tailwindcss.com/docs/z-index |----------------------------------------------------------------------------- @@ -780,7 +780,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Opacity https://tailwindcss.com/docs/opacity |----------------------------------------------------------------------------- @@ -802,7 +802,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | SVG fill https://tailwindcss.com/docs/svg |----------------------------------------------------------------------------- @@ -821,7 +821,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | SVG stroke https://tailwindcss.com/docs/svg |----------------------------------------------------------------------------- @@ -840,7 +840,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Modules https://tailwindcss.com/docs/configuration#modules |----------------------------------------------------------------------------- @@ -912,7 +912,7 @@ module.exports = { }, - /* + /** |----------------------------------------------------------------------------- | Plugins https://tailwindcss.com/docs/plugins |----------------------------------------------------------------------------- @@ -934,7 +934,7 @@ module.exports = { ], - /* + /** |----------------------------------------------------------------------------- | Advanced Options https://tailwindcss.com/docs/configuration#options |----------------------------------------------------------------------------- diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js index 1d127240c..0dd92491c 100644 --- a/src/cli/commands/init.js +++ b/src/cli/commands/init.js @@ -1,4 +1,5 @@ import chalk from 'chalk' +import { transform } from 'babel-core' import * as constants from '../constants' import * as emoji from '../emoji' @@ -8,25 +9,47 @@ export const usage = 'init [file]' export const description = 'Creates Tailwind config file. Default: ' + chalk.bold.magenta(constants.defaultConfigFile) +export const options = [ + { + usage: '--no-comments', + description: 'Omit comments from the config file.', + }, +] + +export const optionMap = { + noComments: ['no-comments'], +} + +const transformSettings = { + ast: false, + babelrc: false, + compact: false, + shouldPrintComment: comment => !comment.startsWith('*'), +} + /** * Runs the command. * * @param {string[]} cliParams + * @param {object} cliOptions * @return {Promise} */ -export function run(cliParams) { +export function run(cliParams, cliOptions) { return new Promise(resolve => { utils.header() + const noComments = cliOptions.noComments const file = cliParams[0] || constants.defaultConfigFile utils.exists(file) && utils.die(chalk.bold.magenta(file), 'already exists.') - const stub = utils + let stub = utils .readFile(constants.configStubFile) .replace('// let defaultConfig', 'let defaultConfig') .replace("require('./plugins/container')", "require('tailwindcss/plugins/container')") + noComments && (stub = transform(stub, transformSettings).code.trim()) + utils.writeFile(file, stub) utils.log()