Skip to content

Commit f72158c

Browse files
dextermbadamwathan
authored andcommitted
Automatically add featureFlags.future flags to the configuration files 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
1 parent 9d29f3f commit f72158c

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

__tests__/cli.test.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import cli from '../src/cli/main'
44
import * as constants from '../src/constants'
55
import * as utils from '../src/cli/utils'
66
import runInTempDirectory from '../jest/runInTempDirectory'
7+
import featureFlags from '../src/featureFlags'
78

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

1514
beforeEach(() => {
@@ -21,15 +20,15 @@ describe('cli', () => {
2120
it('creates a Tailwind config file', () => {
2221
return runInTempDirectory(() => {
2322
return cli(['init']).then(() => {
24-
expect(utils.readFile(constants.defaultConfigFile)).toEqual(simpleConfigFixture)
23+
expect(utils.exists(constants.defaultConfigFile)).toEqual(true)
2524
})
2625
})
2726
})
2827

2928
it('creates a Tailwind config file and a postcss.config.js file', () => {
3029
return runInTempDirectory(() => {
3130
return cli(['init', '-p']).then(() => {
32-
expect(utils.readFile(constants.defaultConfigFile)).toEqual(simpleConfigFixture)
31+
expect(utils.exists(constants.defaultConfigFile)).toEqual(true)
3332
expect(utils.readFile(constants.defaultPostCssConfigFile)).toEqual(
3433
defaultPostCssConfigFixture
3534
)
@@ -40,7 +39,7 @@ describe('cli', () => {
4039
it('creates a full Tailwind config file', () => {
4140
return runInTempDirectory(() => {
4241
return cli(['init', '--full']).then(() => {
43-
expect(utils.readFile(constants.defaultConfigFile)).toEqual(defaultConfigFixture)
42+
expect(utils.exists(constants.defaultConfigFile)).toEqual(true)
4443
})
4544
})
4645
})
@@ -94,5 +93,15 @@ describe('cli', () => {
9493
expect(process.stdout.write.mock.calls[0][0]).not.toContain('-ms-input-placeholder')
9594
})
9695
})
96+
97+
it('creates a Tailwind config file with future flags', () => {
98+
return runInTempDirectory(() => {
99+
return cli(['init']).then(() => {
100+
featureFlags.future.forEach(flag => {
101+
expect(utils.readFile(constants.defaultConfigFile)).toContain(`${flag}: true`)
102+
})
103+
})
104+
})
105+
})
97106
})
98107
})

src/cli/commands/init.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,26 @@ export function run(cliParams, cliOptions) {
3535
return new Promise(resolve => {
3636
utils.header()
3737

38-
const full = cliOptions.full
3938
const file = cliParams[0] || constants.defaultConfigFile
4039
const simplePath = utils.getSimplePath(file)
4140

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

44-
const stubFile = full ? constants.defaultConfigStubFile : constants.simpleConfigStubFile
43+
const stubFile = cliOptions.full
44+
? constants.defaultConfigStubFile
45+
: constants.simpleConfigStubFile
4546

46-
utils.copyFile(stubFile, file)
47+
const config = require(stubFile)
48+
const { future: flags } = require('../../featureFlags').default
49+
50+
flags.forEach(flag => {
51+
config.future[`// ${flag}`] = true
52+
})
53+
54+
utils.writeFile(
55+
file,
56+
`module.exports = ${JSON.stringify(config, null, 2).replace(/"([^-_\d"]+)":/g, '$1:')}\n`
57+
)
4758

4859
utils.log()
4960
utils.log(emoji.yes, 'Created Tailwind config file:', colors.file(simplePath))

stubs/defaultConfig.stub.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
module.exports = {
2-
future: {
3-
// removeDeprecatedGapUtilities: true,
4-
// purgeLayersByDefault: true,
5-
},
2+
future: {},
63
purge: [],
74
target: 'relaxed',
85
prefix: '',

stubs/simpleConfig.stub.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
module.exports = {
2-
future: {
3-
// removeDeprecatedGapUtilities: true,
4-
// purgeLayersByDefault: true,
5-
},
2+
future: {},
63
purge: [],
74
theme: {
85
extend: {},

0 commit comments

Comments
 (0)