Skip to content

Commit 9e26fd8

Browse files
committed
CLI. Added --no-comments option to init commend
1 parent 4fc519f commit 9e26fd8

File tree

3 files changed

+64
-34
lines changed

3 files changed

+64
-34
lines changed

__tests__/cli.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ describe('cli', () => {
2828
expect(utils.writeFile.mock.calls[0][1]).toContain('defaultConfig')
2929
})
3030
})
31+
32+
it('creates a Tailwind config file without comments', () => {
33+
cli(['init', '--no-comments']).then(() => {
34+
expect(utils.writeFile.mock.calls[0][1]).not.toContain('/**')
35+
expect(utils.writeFile.mock.calls[0][1]).toContain('//')
36+
})
37+
})
3138
})
3239

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

defaultConfig.stub.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/**
22
33
Tailwind - The Utility-First CSS Framework
44
@@ -27,7 +27,7 @@ View the full documentation at https://tailwindcss.com.
2727
// let defaultConfig = require('tailwindcss/defaultConfig')()
2828

2929

30-
/*
30+
/**
3131
|-------------------------------------------------------------------------------
3232
| Colors https://tailwindcss.com/docs/colors
3333
|-------------------------------------------------------------------------------
@@ -131,7 +131,7 @@ let colors = {
131131

132132
module.exports = {
133133

134-
/*
134+
/**
135135
|-----------------------------------------------------------------------------
136136
| Colors https://tailwindcss.com/docs/colors
137137
|-----------------------------------------------------------------------------
@@ -147,7 +147,7 @@ module.exports = {
147147
colors: colors,
148148

149149

150-
/*
150+
/**
151151
|-----------------------------------------------------------------------------
152152
| Screens https://tailwindcss.com/docs/responsive-design
153153
|-----------------------------------------------------------------------------
@@ -174,7 +174,7 @@ module.exports = {
174174
},
175175

176176

177-
/*
177+
/**
178178
|-----------------------------------------------------------------------------
179179
| Fonts https://tailwindcss.com/docs/fonts
180180
|-----------------------------------------------------------------------------
@@ -230,7 +230,7 @@ module.exports = {
230230
},
231231

232232

233-
/*
233+
/**
234234
|-----------------------------------------------------------------------------
235235
| Text sizes https://tailwindcss.com/docs/text-sizing
236236
|-----------------------------------------------------------------------------
@@ -262,7 +262,7 @@ module.exports = {
262262
},
263263

264264

265-
/*
265+
/**
266266
|-----------------------------------------------------------------------------
267267
| Font weights https://tailwindcss.com/docs/font-weight
268268
|-----------------------------------------------------------------------------
@@ -289,7 +289,7 @@ module.exports = {
289289
},
290290

291291

292-
/*
292+
/**
293293
|-----------------------------------------------------------------------------
294294
| Leading (line height) https://tailwindcss.com/docs/line-height
295295
|-----------------------------------------------------------------------------
@@ -309,7 +309,7 @@ module.exports = {
309309
},
310310

311311

312-
/*
312+
/**
313313
|-----------------------------------------------------------------------------
314314
| Tracking (letter spacing) https://tailwindcss.com/docs/letter-spacing
315315
|-----------------------------------------------------------------------------
@@ -328,7 +328,7 @@ module.exports = {
328328
},
329329

330330

331-
/*
331+
/**
332332
|-----------------------------------------------------------------------------
333333
| Text colors https://tailwindcss.com/docs/text-color
334334
|-----------------------------------------------------------------------------
@@ -344,7 +344,7 @@ module.exports = {
344344
textColors: colors,
345345

346346

347-
/*
347+
/**
348348
|-----------------------------------------------------------------------------
349349
| Background colors https://tailwindcss.com/docs/background-color
350350
|-----------------------------------------------------------------------------
@@ -360,7 +360,7 @@ module.exports = {
360360
backgroundColors: colors,
361361

362362

363-
/*
363+
/**
364364
|-----------------------------------------------------------------------------
365365
| Background sizes https://tailwindcss.com/docs/background-size
366366
|-----------------------------------------------------------------------------
@@ -380,7 +380,7 @@ module.exports = {
380380
},
381381

382382

383-
/*
383+
/**
384384
|-----------------------------------------------------------------------------
385385
| Border widths https://tailwindcss.com/docs/border-width
386386
|-----------------------------------------------------------------------------
@@ -402,7 +402,7 @@ module.exports = {
402402
},
403403

404404

405-
/*
405+
/**
406406
|-----------------------------------------------------------------------------
407407
| Border colors https://tailwindcss.com/docs/border-color
408408
|-----------------------------------------------------------------------------
@@ -422,7 +422,7 @@ module.exports = {
422422
borderColors: global.Object.assign({ default: colors['grey-light'] }, colors),
423423

424424

425-
/*
425+
/**
426426
|-----------------------------------------------------------------------------
427427
| Border radius https://tailwindcss.com/docs/border-radius
428428
|-----------------------------------------------------------------------------
@@ -447,7 +447,7 @@ module.exports = {
447447
},
448448

449449

450-
/*
450+
/**
451451
|-----------------------------------------------------------------------------
452452
| Width https://tailwindcss.com/docs/width
453453
|-----------------------------------------------------------------------------
@@ -500,7 +500,7 @@ module.exports = {
500500
},
501501

502502

503-
/*
503+
/**
504504
|-----------------------------------------------------------------------------
505505
| Height https://tailwindcss.com/docs/height
506506
|-----------------------------------------------------------------------------
@@ -537,7 +537,7 @@ module.exports = {
537537
},
538538

539539

540-
/*
540+
/**
541541
|-----------------------------------------------------------------------------
542542
| Minimum width https://tailwindcss.com/docs/min-width
543543
|-----------------------------------------------------------------------------
@@ -557,7 +557,7 @@ module.exports = {
557557
},
558558

559559

560-
/*
560+
/**
561561
|-----------------------------------------------------------------------------
562562
| Minimum height https://tailwindcss.com/docs/min-height
563563
|-----------------------------------------------------------------------------
@@ -578,7 +578,7 @@ module.exports = {
578578
},
579579

580580

581-
/*
581+
/**
582582
|-----------------------------------------------------------------------------
583583
| Maximum width https://tailwindcss.com/docs/max-width
584584
|-----------------------------------------------------------------------------
@@ -607,7 +607,7 @@ module.exports = {
607607
},
608608

609609

610-
/*
610+
/**
611611
|-----------------------------------------------------------------------------
612612
| Maximum height https://tailwindcss.com/docs/max-height
613613
|-----------------------------------------------------------------------------
@@ -627,7 +627,7 @@ module.exports = {
627627
},
628628

629629

630-
/*
630+
/**
631631
|-----------------------------------------------------------------------------
632632
| Padding https://tailwindcss.com/docs/padding
633633
|-----------------------------------------------------------------------------
@@ -661,7 +661,7 @@ module.exports = {
661661
},
662662

663663

664-
/*
664+
/**
665665
|-----------------------------------------------------------------------------
666666
| Margin https://tailwindcss.com/docs/margin
667667
|-----------------------------------------------------------------------------
@@ -696,7 +696,7 @@ module.exports = {
696696
},
697697

698698

699-
/*
699+
/**
700700
|-----------------------------------------------------------------------------
701701
| Negative margin https://tailwindcss.com/docs/negative-margin
702702
|-----------------------------------------------------------------------------
@@ -730,7 +730,7 @@ module.exports = {
730730
},
731731

732732

733-
/*
733+
/**
734734
|-----------------------------------------------------------------------------
735735
| Shadows https://tailwindcss.com/docs/shadows
736736
|-----------------------------------------------------------------------------
@@ -756,7 +756,7 @@ module.exports = {
756756
},
757757

758758

759-
/*
759+
/**
760760
|-----------------------------------------------------------------------------
761761
| Z-index https://tailwindcss.com/docs/z-index
762762
|-----------------------------------------------------------------------------
@@ -780,7 +780,7 @@ module.exports = {
780780
},
781781

782782

783-
/*
783+
/**
784784
|-----------------------------------------------------------------------------
785785
| Opacity https://tailwindcss.com/docs/opacity
786786
|-----------------------------------------------------------------------------
@@ -802,7 +802,7 @@ module.exports = {
802802
},
803803

804804

805-
/*
805+
/**
806806
|-----------------------------------------------------------------------------
807807
| SVG fill https://tailwindcss.com/docs/svg
808808
|-----------------------------------------------------------------------------
@@ -821,7 +821,7 @@ module.exports = {
821821
},
822822

823823

824-
/*
824+
/**
825825
|-----------------------------------------------------------------------------
826826
| SVG stroke https://tailwindcss.com/docs/svg
827827
|-----------------------------------------------------------------------------
@@ -840,7 +840,7 @@ module.exports = {
840840
},
841841

842842

843-
/*
843+
/**
844844
|-----------------------------------------------------------------------------
845845
| Modules https://tailwindcss.com/docs/configuration#modules
846846
|-----------------------------------------------------------------------------
@@ -912,7 +912,7 @@ module.exports = {
912912
},
913913

914914

915-
/*
915+
/**
916916
|-----------------------------------------------------------------------------
917917
| Plugins https://tailwindcss.com/docs/plugins
918918
|-----------------------------------------------------------------------------
@@ -934,7 +934,7 @@ module.exports = {
934934
],
935935

936936

937-
/*
937+
/**
938938
|-----------------------------------------------------------------------------
939939
| Advanced Options https://tailwindcss.com/docs/configuration#options
940940
|-----------------------------------------------------------------------------

src/cli/commands/init.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import chalk from 'chalk'
2+
import { transform } from 'babel-core'
23

34
import * as constants from '../constants'
45
import * as emoji from '../emoji'
@@ -8,25 +9,47 @@ export const usage = 'init [file]'
89
export const description =
910
'Creates Tailwind config file. Default: ' + chalk.bold.magenta(constants.defaultConfigFile)
1011

12+
export const options = [
13+
{
14+
usage: '--no-comments',
15+
description: 'Omit comments from the config file.',
16+
},
17+
]
18+
19+
export const optionMap = {
20+
noComments: ['no-comments'],
21+
}
22+
23+
const transformSettings = {
24+
ast: false,
25+
babelrc: false,
26+
compact: false,
27+
shouldPrintComment: comment => !comment.startsWith('*'),
28+
}
29+
1130
/**
1231
* Runs the command.
1332
*
1433
* @param {string[]} cliParams
34+
* @param {object} cliOptions
1535
* @return {Promise}
1636
*/
17-
export function run(cliParams) {
37+
export function run(cliParams, cliOptions) {
1838
return new Promise(resolve => {
1939
utils.header()
2040

41+
const noComments = cliOptions.noComments
2142
const file = cliParams[0] || constants.defaultConfigFile
2243

2344
utils.exists(file) && utils.die(chalk.bold.magenta(file), 'already exists.')
2445

25-
const stub = utils
46+
let stub = utils
2647
.readFile(constants.configStubFile)
2748
.replace('// let defaultConfig', 'let defaultConfig')
2849
.replace("require('./plugins/container')", "require('tailwindcss/plugins/container')")
2950

51+
noComments && (stub = transform(stub, transformSettings).code.trim())
52+
3053
utils.writeFile(file, stub)
3154

3255
utils.log()

0 commit comments

Comments
 (0)