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

Automatically add featureFlags.future flags to the configuration files whenever the init command is ran #2379

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
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