Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve new JIT-compatible CLI #4558

Merged
merged 22 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/cli
/lib
/docs
/peers
/tests/fixtures/cli-utils.js
/stubs/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/coverage
/cli
/lib
/peers
/example
.vscode
tailwind.config.js
Expand Down
2 changes: 1 addition & 1 deletion integrations/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function $(command, options = {}) {

let args = command.split(' ')
command = args.shift()
command = path.resolve(cwd, 'node_modules', '.bin', command)
command = command === 'node' ? command : path.resolve(cwd, 'node_modules', '.bin', command)

let stdoutMessages = []
let stderrMessages = []
Expand Down
4 changes: 4 additions & 0 deletions integrations/tailwindcss-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
node_modules/
!tailwind.config.js
!index.html
12 changes: 12 additions & 0 deletions integrations/tailwindcss-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions integrations/tailwindcss-cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "tailwindcss-cli",
"private": true,
"version": "0.0.0",
"scripts": {
"build": "NODE_ENV=production node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css",
"test": "jest"
},
"jest": {
"displayName": "Tailwind CSS CLI",
"setupFilesAfterEnv": [
"<rootDir>/../../jest/customMatchers.js"
]
}
}
5 changes: 5 additions & 0 deletions integrations/tailwindcss-cli/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let path = require('path')

module.exports = {
plugins: [require(path.resolve('..', '..'))],
}
3 changes: 3 additions & 0 deletions integrations/tailwindcss-cli/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
11 changes: 11 additions & 0 deletions integrations/tailwindcss-cli/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>

</body>
</html>
15 changes: 15 additions & 0 deletions integrations/tailwindcss-cli/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
purge: ['./src/index.html'],
mode: 'jit',
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
corePlugins: {
preflight: false,
},
plugins: [],
}
232 changes: 232 additions & 0 deletions integrations/tailwindcss-cli/tests/integration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
let $ = require('../../execute')
let { css, html, javascript } = require('../../syntax')

let {
readOutputFile,
appendToInputFile,
writeInputFile,
waitForOutputFileCreation,
waitForOutputFileChange,
} = require('../../io')({ output: 'dist', input: 'src' })

describe('static build', () => {
it('should be possible to generate tailwind output', async () => {
await writeInputFile('index.html', html`<div class="font-bold"></div>`)

await $('node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css', {
env: { NODE_ENV: 'production' },
})

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
`
)
})
})

describe('watcher', () => {
test('classes are generated when the html file changes', async () => {
await writeInputFile('index.html', html`<div class="font-bold"></div>`)

let runningProcess = $('node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css -w')

await waitForOutputFileCreation('main.css')

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
`
)

await waitForOutputFileChange('main.css', async () => {
await appendToInputFile('index.html', html`<div class="font-normal"></div>`)
})

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
.font-normal {
font-weight: 400;
}
`
)

await waitForOutputFileChange('main.css', async () => {
await appendToInputFile('index.html', html`<div class="bg-red-500"></div>`)
})

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.bg-red-500 {
--tw-bg-opacity: 1;
background-color: rgba(239, 68, 68, var(--tw-bg-opacity));
}
.font-bold {
font-weight: 700;
}
.font-normal {
font-weight: 400;
}
`
)

return runningProcess.stop()
})

test('classes are generated when the tailwind.config.js file changes', async () => {
await writeInputFile('index.html', html`<div class="font-bold md:font-medium"></div>`)

let runningProcess = $('node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css -w')

await waitForOutputFileCreation('main.css')

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
@media (min-width: 768px) {
.md\\:font-medium {
font-weight: 500;
}
}
`
)

await waitForOutputFileChange('main.css', async () => {
await writeInputFile(
'../tailwind.config.js',
javascript`
module.exports = {
purge: ['./src/index.html'],
mode: 'jit',
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
screens: {
md: '800px'
},
fontWeight: {
bold: 'bold'
}
},
},
variants: {
extend: {},
},
corePlugins: {
preflight: false,
},
plugins: [],
}
`
)
})

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.font-bold {
font-weight: bold;
}
@media (min-width: 800px) {
.md\\:font-medium {
font-weight: 500;
}
}
`
)

return runningProcess.stop()
})

test('classes are generated when the index.css file changes', async () => {
await writeInputFile('index.html', html`<div class="font-bold btn"></div>`)

let runningProcess = $('node ../../lib/cli.js -i ./src/index.css -o ./dist/main.css -w')

await waitForOutputFileCreation('main.css')

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.font-bold {
font-weight: 700;
}
`
)

await waitForOutputFileChange('main.css', async () => {
await writeInputFile(
'index.css',
css`
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer components {
.btn {
@apply px-2 py-1 rounded;
}
}
`
)
})

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.btn {
border-radius: 0.25rem;
padding-left: 0.5rem;
padding-right: 0.5rem;
padding-top: 0.25rem;
padding-bottom: 0.25rem;
}
.font-bold {
font-weight: 700;
}
`
)

await waitForOutputFileChange('main.css', async () => {
await writeInputFile(
'index.css',
css`
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer components {
.btn {
@apply px-2 py-1 rounded bg-red-500;
}
}
`
)
})

expect(await readOutputFile('main.css')).toIncludeCss(
css`
.btn {
border-radius: 0.25rem;
--tw-bg-opacity: 1;
background-color: rgba(239, 68, 68, var(--tw-bg-opacity));
padding-left: 0.5rem;
padding-right: 0.5rem;
padding-top: 0.25rem;
padding-bottom: 0.25rem;
}
.font-bold {
font-weight: 700;
}
`
)

return runningProcess.stop()
})
})
Loading