mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
Merge pull request #2225 from tailwindlabs/add-postcss-init-option
add tailwind -p init option to generate a postcss file
This commit is contained in:
commit
ed3edf9129
@ -10,6 +10,7 @@ describe('cli', () => {
|
||||
const customConfigPath = path.resolve(__dirname, 'fixtures/custom-config.js')
|
||||
const defaultConfigFixture = utils.readFile(constants.defaultConfigStubFile)
|
||||
const simpleConfigFixture = utils.readFile(constants.simpleConfigStubFile)
|
||||
const defaultPostCssConfigFixture = utils.readFile(constants.defaultPostCssConfigStubFile)
|
||||
|
||||
beforeEach(() => {
|
||||
console.log = jest.fn()
|
||||
@ -25,6 +26,17 @@ describe('cli', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('creates a Tailwind config file and a postcss.config.js file', () => {
|
||||
return runInTempDirectory(() => {
|
||||
return cli(['init', '-p']).then(() => {
|
||||
expect(utils.readFile(constants.defaultConfigFile)).toEqual(simpleConfigFixture)
|
||||
expect(utils.readFile(constants.defaultPostCssConfigFile)).toEqual(
|
||||
defaultPostCssConfigFixture
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('creates a full Tailwind config file', () => {
|
||||
return runInTempDirectory(() => {
|
||||
return cli(['init', '--full']).then(() => {
|
||||
|
||||
@ -13,10 +13,15 @@ export const options = [
|
||||
usage: '--full',
|
||||
description: 'Generate complete configuration file.',
|
||||
},
|
||||
{
|
||||
usage: '-p',
|
||||
description: 'Generate a postcss configuration file.',
|
||||
},
|
||||
]
|
||||
|
||||
export const optionMap = {
|
||||
full: ['full'],
|
||||
postcss: ['p'],
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,6 +48,14 @@ export function run(cliParams, cliOptions) {
|
||||
utils.log()
|
||||
utils.log(emoji.yes, 'Created Tailwind config file:', colors.file(simplePath))
|
||||
|
||||
if (cliOptions.postcss) {
|
||||
const path = utils.getSimplePath(constants.defaultPostCssConfigFile)
|
||||
utils.exists(constants.defaultPostCssConfigFile) &&
|
||||
utils.die(colors.file(path), 'already exists.')
|
||||
utils.copyFile(constants.defaultPostCssConfigStubFile, constants.defaultPostCssConfigFile)
|
||||
utils.log(emoji.yes, 'Created PostCSS config file:', colors.file(path))
|
||||
}
|
||||
|
||||
utils.footer()
|
||||
|
||||
resolve()
|
||||
|
||||
@ -2,5 +2,11 @@ import path from 'path'
|
||||
|
||||
export const cli = 'tailwind'
|
||||
export const defaultConfigFile = './tailwind.config.js'
|
||||
export const defaultPostCssConfigFile = './postcss.config.js'
|
||||
|
||||
export const defaultConfigStubFile = path.resolve(__dirname, '../stubs/defaultConfig.stub.js')
|
||||
export const simpleConfigStubFile = path.resolve(__dirname, '../stubs/simpleConfig.stub.js')
|
||||
export const defaultPostCssConfigStubFile = path.resolve(
|
||||
__dirname,
|
||||
'../stubs/defaultPostCssConfig.stub.js'
|
||||
)
|
||||
|
||||
7
stubs/defaultPostCssConfig.stub.js
Normal file
7
stubs/defaultPostCssConfig.stub.js
Normal file
@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user