Merge pull request #1861 from OwenMelbz/master
Allows users to use "tailwind build" without requiring an input file
This commit is contained in:
commit
92ffe40309
3 changed files with 25 additions and 5 deletions
|
|
@ -43,12 +43,20 @@ describe('cli', () => {
|
|||
})
|
||||
|
||||
describe('build', () => {
|
||||
it('compiles CSS file', () => {
|
||||
it('compiles CSS file using an input css file', () => {
|
||||
return cli(['build', inputCssPath]).then(() => {
|
||||
expect(process.stdout.write.mock.calls[0][0]).toContain('.example')
|
||||
})
|
||||
})
|
||||
|
||||
it('compiles CSS file without an input css file', () => {
|
||||
return cli(['build']).then(() => {
|
||||
expect(process.stdout.write.mock.calls[0][0]).toContain('normalize.css') // base
|
||||
expect(process.stdout.write.mock.calls[0][0]).toContain('.container') // components
|
||||
expect(process.stdout.write.mock.calls[0][0]).toContain('.mx-auto') // utilities
|
||||
})
|
||||
})
|
||||
|
||||
it('compiles CSS file using custom configuration', () => {
|
||||
return cli(['build', inputCssPath, '--config', customConfigPath]).then(() => {
|
||||
expect(process.stdout.write.mock.calls[0][0]).toContain('400px')
|
||||
|
|
|
|||
|
|
@ -80,7 +80,11 @@ function buildToFile(compileOptions, startTime) {
|
|||
|
||||
utils.header()
|
||||
utils.log()
|
||||
utils.log(emoji.go, 'Building...', colors.file(inputFileSimplePath))
|
||||
utils.log(
|
||||
emoji.go,
|
||||
'Building...',
|
||||
colors.file(inputFileSimplePath || 'defaults: @base, @components and @utilities.')
|
||||
)
|
||||
|
||||
return compile(compileOptions).then(result => {
|
||||
utils.writeFile(compileOptions.outputFile, result.css)
|
||||
|
|
@ -112,8 +116,9 @@ export function run(cliParams, cliOptions) {
|
|||
const inputFileSimplePath = utils.getSimplePath(inputFile)
|
||||
const configFileSimplePath = utils.getSimplePath(configFile)
|
||||
|
||||
!inputFile && stopWithHelp('CSS file is required.')
|
||||
!utils.exists(inputFile) && stop(colors.file(inputFileSimplePath), 'does not exist.')
|
||||
if (inputFile) {
|
||||
!utils.exists(inputFile) && stop(colors.file(inputFileSimplePath), 'does not exist.')
|
||||
}
|
||||
|
||||
configFile &&
|
||||
!utils.exists(configFile) &&
|
||||
|
|
|
|||
|
|
@ -25,7 +25,14 @@ const defaultOptions = {
|
|||
*/
|
||||
export default function compile(options = {}) {
|
||||
const config = { ...defaultOptions, ...options }
|
||||
const css = utils.readFile(config.inputFile)
|
||||
|
||||
const css = config.inputFile
|
||||
? utils.readFile(config.inputFile)
|
||||
: `
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
`
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
postcss(config.plugins)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue