forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored the CLI build process to use configuration object instead …
…of many arguments.
- Loading branch information
Showing
4 changed files
with
77 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import path from 'path' | ||
|
||
import autoprefixer from 'autoprefixer' | ||
|
||
import tailwind from '../src' | ||
import compile from '../src/cli/compile' | ||
|
||
describe('cli compile', () => { | ||
const inputFile = path.resolve(__dirname, 'fixtures/tailwind-input.css') | ||
const outputFile = 'output.css' | ||
const plugins = [tailwind(), autoprefixer] | ||
|
||
it('compiles CSS file', () => { | ||
return compile({ inputFile, outputFile, plugins }).then(result => { | ||
expect(result.css).toContain('.example') | ||
expect(result.css).toContain('-ms-input-placeholder') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import path from 'path' | ||
|
||
import * as utils from '../src/cli/utils' | ||
|
||
describe('cli utils', () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import postcss from 'postcss' | ||
|
||
import * as utils from './utils' | ||
|
||
/** | ||
* Compiler options | ||
* | ||
* @typedef {Object} CompileOptions | ||
* @property {string} inputFile | ||
* @property {string} outputFile | ||
* @property {array} plugins | ||
*/ | ||
|
||
const defaultOptions = { | ||
inputFile: null, | ||
outputFile: null, | ||
plugins: [], | ||
} | ||
|
||
/** | ||
* Compiles CSS file. | ||
* | ||
* @param {CompileOptions} options | ||
* @return {Promise} | ||
*/ | ||
export default function compile(options = {}) { | ||
const config = { ...defaultOptions, ...options } | ||
const css = utils.readFile(config.inputFile) | ||
|
||
return new Promise((resolve, reject) => { | ||
postcss(config.plugins) | ||
.process(css, { | ||
from: config.inputFile, | ||
to: config.outputFile, | ||
}) | ||
.then(resolve) | ||
.catch(reject) | ||
}) | ||
} |