forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
59 lines (46 loc) · 1.41 KB
/
init.js
File metadata and controls
59 lines (46 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import chalk from 'chalk'
import * as constants from '../constants'
import * as emoji from '../emoji'
import * as utils from '../utils'
export const usage = 'init [file]'
export const description =
'Creates Tailwind config file. Default: ' + chalk.bold.magenta(constants.defaultConfigFile)
export const options = [
{
usage: '--full',
description: 'Generate complete configuration file.',
},
{
usage: '--no-comments',
description: 'Omit comments from the config file.',
},
]
export const optionMap = {
full: ['full'],
noComments: ['no-comments'],
}
/**
* Runs the command.
*
* @param {string[]} cliParams
* @param {object} cliOptions
* @return {Promise}
*/
export function run(cliParams, cliOptions) {
return new Promise(resolve => {
utils.header()
const full = cliOptions.full
const noComments = cliOptions.noComments
const file = cliParams[0] || constants.defaultConfigFile
utils.exists(file) && utils.die(chalk.bold.magenta(file), 'already exists.')
const stubFile = full ? constants.defaultConfigStubFile : constants.simpleConfigStubFile
let stub = utils.readFile(stubFile)
stub = utils.replaceAll(stub, constants.replacements)
noComments && (stub = utils.stripBlockComments(stub))
utils.writeFile(file, stub)
utils.log()
utils.log(emoji.yes, 'Created Tailwind config file:', chalk.bold.magenta(file))
utils.footer()
resolve()
})
}