Skip to content

Commit ed3edf9

Browse files
authored
Merge pull request #2225 from tailwindlabs/add-postcss-init-option
add tailwind -p init option to generate a postcss file
2 parents 634a0e6 + 939346d commit ed3edf9

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

__tests__/cli.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('cli', () => {
1010
const customConfigPath = path.resolve(__dirname, 'fixtures/custom-config.js')
1111
const defaultConfigFixture = utils.readFile(constants.defaultConfigStubFile)
1212
const simpleConfigFixture = utils.readFile(constants.simpleConfigStubFile)
13+
const defaultPostCssConfigFixture = utils.readFile(constants.defaultPostCssConfigStubFile)
1314

1415
beforeEach(() => {
1516
console.log = jest.fn()
@@ -25,6 +26,17 @@ describe('cli', () => {
2526
})
2627
})
2728

29+
it('creates a Tailwind config file and a postcss.config.js file', () => {
30+
return runInTempDirectory(() => {
31+
return cli(['init', '-p']).then(() => {
32+
expect(utils.readFile(constants.defaultConfigFile)).toEqual(simpleConfigFixture)
33+
expect(utils.readFile(constants.defaultPostCssConfigFile)).toEqual(
34+
defaultPostCssConfigFixture
35+
)
36+
})
37+
})
38+
})
39+
2840
it('creates a full Tailwind config file', () => {
2941
return runInTempDirectory(() => {
3042
return cli(['init', '--full']).then(() => {

src/cli/commands/init.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ export const options = [
1313
usage: '--full',
1414
description: 'Generate complete configuration file.',
1515
},
16+
{
17+
usage: '-p',
18+
description: 'Generate a postcss configuration file.',
19+
},
1620
]
1721

1822
export const optionMap = {
1923
full: ['full'],
24+
postcss: ['p'],
2025
}
2126

2227
/**
@@ -43,6 +48,14 @@ export function run(cliParams, cliOptions) {
4348
utils.log()
4449
utils.log(emoji.yes, 'Created Tailwind config file:', colors.file(simplePath))
4550

51+
if (cliOptions.postcss) {
52+
const path = utils.getSimplePath(constants.defaultPostCssConfigFile)
53+
utils.exists(constants.defaultPostCssConfigFile) &&
54+
utils.die(colors.file(path), 'already exists.')
55+
utils.copyFile(constants.defaultPostCssConfigStubFile, constants.defaultPostCssConfigFile)
56+
utils.log(emoji.yes, 'Created PostCSS config file:', colors.file(path))
57+
}
58+
4659
utils.footer()
4760

4861
resolve()

src/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@ import path from 'path'
22

33
export const cli = 'tailwind'
44
export const defaultConfigFile = './tailwind.config.js'
5+
export const defaultPostCssConfigFile = './postcss.config.js'
6+
57
export const defaultConfigStubFile = path.resolve(__dirname, '../stubs/defaultConfig.stub.js')
68
export const simpleConfigStubFile = path.resolve(__dirname, '../stubs/simpleConfig.stub.js')
9+
export const defaultPostCssConfigStubFile = path.resolve(
10+
__dirname,
11+
'../stubs/defaultPostCssConfig.stub.js'
12+
)

stubs/defaultPostCssConfig.stub.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
}
7+

0 commit comments

Comments
 (0)