diff --git a/__tests__/cli.test.js b/__tests__/cli.test.js index e8b937230..d1c7149b4 100644 --- a/__tests__/cli.test.js +++ b/__tests__/cli.test.js @@ -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') diff --git a/src/cli/commands/build.js b/src/cli/commands/build.js index 6d79b48f7..cec547b7a 100644 --- a/src/cli/commands/build.js +++ b/src/cli/commands/build.js @@ -80,7 +80,7 @@ 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 +112,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) && diff --git a/src/cli/compile.js b/src/cli/compile.js index 956d5e789..7cadbc0d0 100644 --- a/src/cli/compile.js +++ b/src/cli/compile.js @@ -25,7 +25,12 @@ 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)