Skip to content

Commit

Permalink
Merge pull request #776 from maizzle/refactor-tailwind-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
cossssmin authored Oct 1, 2022
2 parents 3aaeddb + 4a9d6ec commit ba80622
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/generators/output/to-disk.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = async (env, spinner, config) => {

const css = (typeof get(config, 'build.tailwind.compiled') === 'string')
? config.build.tailwind.compiled
: await Tailwind.compile('', '', {}, config, spinner)
: await Tailwind.compile('', '', {}, config)

// Parse each template config object
await asyncForEach(templatesConfig, async templateConfig => {
Expand Down
9 changes: 2 additions & 7 deletions src/generators/postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const postcssNested = require('tailwindcss/nesting')
const mergeLonghand = require('postcss-merge-longhand')

module.exports = {
process: async (css = '', maizzleConfig = {}, spinner = null) => {
process: async (css = '', maizzleConfig = {}) => {
const userFilePath = get(maizzleConfig, 'build.tailwind.css', path.join(process.cwd(), 'src/css/tailwind.css'))

return postcss([
Expand All @@ -18,12 +18,7 @@ module.exports = {
.process(css, {from: undefined})
.then(result => result.css)
.catch(error => {
console.error(error)
if (spinner) {
spinner.stop()
}

throw new Error(`PostCSS processing failed`)
throw new SyntaxError(error)
})
}
}
9 changes: 2 additions & 7 deletions src/generators/tailwindcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const mergeLonghand = require('postcss-merge-longhand')
const {get, isObject, isEmpty, merge} = require('lodash')

module.exports = {
compile: async (css = '', html = '', tailwindConfig = {}, maizzleConfig = {}, spinner = null) => {
compile: async (css = '', html = '', tailwindConfig = {}, maizzleConfig = {}) => {
tailwindConfig = (isObject(tailwindConfig) && !isEmpty(tailwindConfig)) ? tailwindConfig : get(maizzleConfig, 'build.tailwind.config', 'tailwind.config.js')

// Compute the Tailwind config to use
Expand Down Expand Up @@ -105,12 +105,7 @@ module.exports = {
.process(css, {from: undefined})
.then(result => result.css)
.catch(error => {
console.error(error)
if (spinner) {
spinner.stop()
}

throw new Error(`Tailwind CSS compilation failed`)
throw new SyntaxError(error)
})
}
}
2 changes: 1 addition & 1 deletion test/test-postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ const PostCSS = require('../src/generators/postcss')
test('throws on processing error', async t => {
await t.throwsAsync(async () => {
await PostCSS.process(null, {})
}, {instanceOf: Error, message: 'PostCSS processing failed'})
}, {instanceOf: SyntaxError})
})
6 changes: 2 additions & 4 deletions test/test-tailwindcss.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const test = require('ava')
const ora = require('ora')
const Tailwind = require('../src/generators/tailwindcss')

test('throws on compile error', async t => {
await t.throwsAsync(async () => {
const spinner = ora('Compiling Tailwind CSS...').start()
await Tailwind.compile('.test {@apply inexistent;}', '<div class="test">Test</a>', {}, {}, spinner)
}, {instanceOf: Error, message: 'Tailwind CSS compilation failed'})
await Tailwind.compile('.test {@apply inexistent;}', '<div class="test">Test</a>', {}, {})
}, {instanceOf: SyntaxError})
})

test('uses defaults if no config specified', async t => {
Expand Down

0 comments on commit ba80622

Please sign in to comment.