Skip to content

Commit 6fddfa0

Browse files
authored
Merge pull request #766 from MattStypa/next-cli
Updated CLI init command
2 parents 377c925 + 6d65dfb commit 6fddfa0

24 files changed

+524
-624
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/lib
22
/docs
33
/__tests__/fixtures/cli-utils.js
4-
defaultConfig.stub.js
4+
/stubs/*

__tests__/applyAtRule.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import substituteClassApplyAtRules from '../src/lib/substituteClassApplyAtRules'
33
import processPlugins from '../src/util/processPlugins'
44
import resolveConfig from '../src/util/resolveConfig'
55
import corePlugins from '../src/corePlugins'
6-
import defaultConfig from '../defaultConfig.stub.js'
6+
import defaultConfig from '../stubs/defaultConfig.stub.js'
77

88
const resolvedDefaultConfig = resolveConfig([defaultConfig])
99

__tests__/cli.test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import path from 'path'
22

33
import cli from '../src/cli/main'
4-
import * as constants from '../src/cli/constants'
4+
import * as constants from '../src/constants'
55
import * as utils from '../src/cli/utils'
66

77
describe('cli', () => {
88
const inputCssPath = path.resolve(__dirname, 'fixtures/tailwind-input.css')
99
const customConfigPath = path.resolve(__dirname, 'fixtures/custom-config.js')
10+
const defaultConfigFixture = utils.readFile(constants.defaultConfigStubFile)
11+
const simpleConfigFixture = utils.readFile(constants.simpleConfigStubFile)
1012

1113
beforeEach(() => {
1214
console.log = jest.fn()
@@ -32,6 +34,18 @@ describe('cli', () => {
3234
expect(utils.writeFile.mock.calls[0][1]).not.toContain('/**')
3335
})
3436
})
37+
38+
it('creates a simple Tailwind config file', () => {
39+
return cli(['init']).then(() => {
40+
expect(utils.writeFile.mock.calls[0][1]).toEqual(simpleConfigFixture)
41+
})
42+
})
43+
44+
it('creates a full Tailwind config file', () => {
45+
return cli(['init', '--full']).then(() => {
46+
expect(utils.writeFile.mock.calls[0][1]).toEqual(defaultConfigFixture)
47+
})
48+
})
3549
})
3650

3751
describe('build', () => {

__tests__/cli.utils.test.js

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import path from 'path'
2-
31
import * as utils from '../src/cli/utils'
42

53
describe('cli utils', () => {
6-
const fixture = utils.readFile(path.resolve(__dirname, 'fixtures/cli-utils.js'))
7-
84
describe('parseCliParams', () => {
95
it('parses CLI parameters', () => {
106
const result = utils.parseCliParams(['a', 'b', '-c', 'd'])
@@ -60,53 +56,4 @@ describe('cli utils', () => {
6056
expect(result).toEqual({ test: ['c', 'd', 'h'] })
6157
})
6258
})
63-
64-
describe('stripBlockComments', () => {
65-
it('does not strip code', () => {
66-
const result = utils.stripBlockComments(fixture)
67-
68-
expect(result).toEqual(expect.stringContaining('__code_no_comment__'))
69-
expect(result).toEqual(expect.stringContaining('__code_comment_line__'))
70-
expect(result).toEqual(expect.stringContaining('__code_comment_block__'))
71-
expect(result).toEqual(expect.stringContaining('__code_comment_line_important__'))
72-
expect(result).toEqual(expect.stringContaining('__code_comment_block_important__'))
73-
})
74-
75-
it('strips block comments', () => {
76-
const result = utils.stripBlockComments(fixture)
77-
78-
expect(result).not.toEqual(expect.stringContaining('__comment_block__'))
79-
expect(result).not.toEqual(expect.stringContaining('__comment_block_multiline__'))
80-
expect(result).not.toEqual(expect.stringContaining('__comment_block_code__'))
81-
})
82-
83-
it('strips docblock comments', () => {
84-
const result = utils.stripBlockComments(fixture)
85-
86-
expect(result).not.toEqual(expect.stringContaining('__comment_docblock__'))
87-
})
88-
89-
it('does not strip line comments', () => {
90-
const result = utils.stripBlockComments(fixture)
91-
92-
expect(result).toEqual(expect.stringContaining('__comment_line__'))
93-
expect(result).toEqual(expect.stringContaining('__comment_line_important__'))
94-
expect(result).toEqual(expect.stringContaining('__comment_line_code__'))
95-
expect(result).toEqual(expect.stringContaining('__comment_line_important_code__'))
96-
})
97-
98-
it('does not strip important block comments', () => {
99-
const result = utils.stripBlockComments(fixture)
100-
101-
expect(result).toEqual(expect.stringContaining('__comment_block_important__'))
102-
expect(result).toEqual(expect.stringContaining('__comment_block_multiline_important__'))
103-
expect(result).toEqual(expect.stringContaining('__comment_block_important_code__'))
104-
})
105-
106-
it('does not strip important docblock comments', () => {
107-
const result = utils.stripBlockComments(fixture)
108-
109-
expect(result).toEqual(expect.stringContaining('__comment_docblock_important__'))
110-
})
111-
})
11259
})

__tests__/customConfig.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'path'
33
import rimraf from 'rimraf'
44
import postcss from 'postcss'
55
import tailwind from '../src/index'
6+
import { defaultConfigFile } from '../src/constants'
67

78
function inTempDirectory(callback) {
89
return new Promise(resolve => {
@@ -82,7 +83,7 @@ test('custom config can be passed as an object', () => {
8283
test('tailwind.config.js is picked up by default', () => {
8384
return inTempDirectory(() => {
8485
fs.writeFileSync(
85-
path.resolve('./tailwind.config.js'),
86+
path.resolve(defaultConfigFile),
8687
`module.exports = {
8788
theme: {
8889
screens: {

__tests__/defaultConfig.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import config from '../defaultConfig.js'
2+
import configStub from '../stubs/defaultConfig.stub.js'
23

34
test('the default config matches the stub', () => {
4-
expect(config()).toEqual(require('../defaultConfig.stub.js'))
5+
expect(config).toEqual(configStub)
6+
})
7+
8+
test('modifying the default config does not affect the stub', () => {
9+
config.theme = {}
10+
expect(config).not.toEqual(configStub)
511
})

__tests__/defaultTheme.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import theme from '../defaultTheme.js'
2+
import configStub from '../stubs/defaultConfig.stub.js'
3+
4+
test('the default theme matches the stub', () => {
5+
expect(theme).toEqual(configStub.theme)
6+
})
7+
8+
test('modifying the default theme does not affect the stub', () => {
9+
theme.colors = {}
10+
expect(theme).not.toEqual(configStub.theme)
11+
})

__tests__/fixtures/cli-utils.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

__tests__/responsiveAtRule.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import postcss from 'postcss'
22
import plugin from '../src/lib/substituteResponsiveAtRules'
3-
import config from '../defaultConfig.stub.js'
3+
import config from '../stubs/defaultConfig.stub.js'
44

55
function run(input, opts = config) {
66
return postcss([plugin(opts)]).process(input, { from: undefined })

__tests__/sanity.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs'
22
import path from 'path'
33
import postcss from 'postcss'
44
import tailwind from '../src/index'
5-
import config from '../defaultConfig.js'
5+
import config from '../stubs/defaultConfig.stub.js'
66

77
it('generates the right CSS', () => {
88
const inputPath = path.resolve(`${__dirname}/fixtures/tailwind-input.css`)

__tests__/variantsAtRule.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import postcss from 'postcss'
22
import plugin from '../src/lib/substituteVariantsAtRules'
3-
import config from '../defaultConfig.stub.js'
43
import processPlugins from '../src/util/processPlugins'
4+
import config from '../stubs/defaultConfig.stub.js'
55

66
function run(input, opts = config) {
77
return postcss([plugin(opts, processPlugins(opts.plugins, opts))]).process(input, {

defaultConfig.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
module.exports = function() {
2-
return require('lodash').cloneDeep(require('./defaultConfig.stub.js'))
3-
}
1+
const cloneDeep = require('lodash/cloneDeep')
2+
const defaultConfig = require('./stubs/defaultConfig.stub.js')
3+
4+
module.exports = cloneDeep(defaultConfig)

defaultConfig.stub.js

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)