CLI. Added --no-comments option to init commend
This commit is contained in:
parent
4fc519f9f5
commit
9e26fd84e3
3 changed files with 64 additions and 34 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue