Skip to content

Commit

Permalink
Automatically add featureFlags.future flags to the configuration fi…
Browse files Browse the repository at this point in the history
…les whenever the `init` command is ran (#2379)

* Add --future flag to CLI

* Remove early exit

* Always add future flags but commented out

- Update replace regex

- Remove future CLI flag

- Update tests
  • Loading branch information
dextermb authored and adamwathan committed Sep 28, 2020
1 parent ea76539 commit 038a0b6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
19 changes: 14 additions & 5 deletions __tests__/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import cli from '../src/cli/main'
import * as constants from '../src/constants'
import * as utils from '../src/cli/utils'
import runInTempDirectory from '../jest/runInTempDirectory'
import featureFlags from '../src/featureFlags'

describe('cli', () => {
const inputCssPath = path.resolve(__dirname, 'fixtures/tailwind-input.css')
const customConfigPath = path.resolve(__dirname, 'fixtures/custom-config.js')
const defaultConfigFixture = utils.readFile(constants.defaultConfigStubFile)
const simpleConfigFixture = utils.readFile(constants.simpleConfigStubFile)
const defaultPostCssConfigFixture = utils.readFile(constants.defaultPostCssConfigStubFile)

beforeEach(() => {
Expand All @@ -21,15 +20,15 @@ describe('cli', () => {
it('creates a Tailwind config file', () => {
return runInTempDirectory(() => {
return cli(['init']).then(() => {
expect(utils.readFile(constants.defaultConfigFile)).toEqual(simpleConfigFixture)
expect(utils.exists(constants.defaultConfigFile)).toEqual(true)
})
})
})

it('creates a Tailwind config file and a postcss.config.js file', () => {
return runInTempDirectory(() => {
return cli(['init', '-p']).then(() => {
expect(utils.readFile(constants.defaultConfigFile)).toEqual(simpleConfigFixture)
expect(utils.exists(constants.defaultConfigFile)).toEqual(true)
expect(utils.readFile(constants.defaultPostCssConfigFile)).toEqual(
defaultPostCssConfigFixture
)
Expand All @@ -40,7 +39,7 @@ describe('cli', () => {
it('creates a full Tailwind config file', () => {
return runInTempDirectory(() => {
return cli(['init', '--full']).then(() => {
expect(utils.readFile(constants.defaultConfigFile)).toEqual(defaultConfigFixture)
expect(utils.exists(constants.defaultConfigFile)).toEqual(true)
})
})
})
Expand Down Expand Up @@ -94,5 +93,15 @@ describe('cli', () => {
expect(process.stdout.write.mock.calls[0][0]).not.toContain('-ms-input-placeholder')
})
})

it('creates a Tailwind config file with future flags', () => {
return runInTempDirectory(() => {
return cli(['init']).then(() => {
featureFlags.future.forEach(flag => {
expect(utils.readFile(constants.defaultConfigFile)).toContain(`${flag}: true`)
})
})
})
})
})
})
17 changes: 14 additions & 3 deletions src/cli/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,26 @@ export function run(cliParams, cliOptions) {
return new Promise(resolve => {
utils.header()

const full = cliOptions.full
const file = cliParams[0] || constants.defaultConfigFile
const simplePath = utils.getSimplePath(file)

utils.exists(file) && utils.die(colors.file(simplePath), 'already exists.')

const stubFile = full ? constants.defaultConfigStubFile : constants.simpleConfigStubFile
const stubFile = cliOptions.full
? constants.defaultConfigStubFile
: constants.simpleConfigStubFile

utils.copyFile(stubFile, file)
const config = require(stubFile)
const { future: flags } = require('../../featureFlags').default

flags.forEach(flag => {
config.future[`// ${flag}`] = true
})

utils.writeFile(
file,
`module.exports = ${JSON.stringify(config, null, 2).replace(/"([^-_\d"]+)":/g, '$1:')}\n`
)

utils.log()
utils.log(emoji.yes, 'Created Tailwind config file:', colors.file(simplePath))
Expand Down
5 changes: 1 addition & 4 deletions stubs/defaultConfig.stub.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module.exports = {
future: {
// removeDeprecatedGapUtilities: true,
// purgeLayersByDefault: true,
},
future: {},
purge: [],
target: 'relaxed',
prefix: '',
Expand Down
5 changes: 1 addition & 4 deletions stubs/simpleConfig.stub.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module.exports = {
future: {
// removeDeprecatedGapUtilities: true,
// purgeLayersByDefault: true,
},
future: {},
purge: [],
theme: {
extend: {},
Expand Down

0 comments on commit 038a0b6

Please sign in to comment.