Allow optional destination for init command, prevent overriding existing files
This commit is contained in:
parent
ba612c8953
commit
7601b5564a
3 changed files with 33 additions and 7 deletions
|
|
@ -35,6 +35,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"commander": "^2.11.0",
|
||||
"fs-extra": "^4.0.2",
|
||||
"lodash": "^4.17.4",
|
||||
"nodemon": "^1.11.0",
|
||||
"normalize.css": "^7.0.0",
|
||||
|
|
|
|||
19
src/cli.js
19
src/cli.js
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
import fs from 'fs'
|
||||
import fs from 'fs-extra'
|
||||
import _ from 'lodash'
|
||||
import path from 'path'
|
||||
import postcss from 'postcss'
|
||||
|
|
@ -28,7 +28,7 @@ function writeStrategy(program) {
|
|||
}
|
||||
}
|
||||
return (output) => {
|
||||
fs.writeFileSync(program.output, output)
|
||||
fs.outputFileSync(program.output, output)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,11 +48,18 @@ function buildTailwind(inputFile, config, write) {
|
|||
|
||||
program.version('0.1.0').usage('<command> [<args>]')
|
||||
|
||||
program.command('init')
|
||||
.usage('[options]')
|
||||
.action(function () {
|
||||
program.command('init [filename]')
|
||||
.usage('[options] [filename]')
|
||||
.action(function (filename = 'tailwind.js') {
|
||||
const destination = path.resolve(filename)
|
||||
|
||||
if (fs.existsSync(destination)) {
|
||||
console.log(`Destination ${destination} already exists, aborting.`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const output = fs.readFileSync(path.resolve(__dirname + '/../defaultConfig.js'), 'utf8')
|
||||
fs.writeFileSync(path.resolve('./tailwind.js'), output)
|
||||
fs.outputFileSync(destination, output)
|
||||
process.exit()
|
||||
})
|
||||
|
||||
|
|
|
|||
20
yarn.lock
20
yarn.lock
|
|
@ -1618,6 +1618,14 @@ from@~0:
|
|||
version "0.1.7"
|
||||
resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe"
|
||||
|
||||
fs-extra@^4.0.2:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.2.tgz#f91704c53d1b461f893452b0c307d9997647ab6b"
|
||||
dependencies:
|
||||
graceful-fs "^4.1.2"
|
||||
jsonfile "^4.0.0"
|
||||
universalify "^0.1.0"
|
||||
|
||||
fs-readdir-recursive@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-1.0.0.tgz#8cd1745c8b4f8a29c8caec392476921ba195f560"
|
||||
|
|
@ -1762,7 +1770,7 @@ got@^6.7.1:
|
|||
unzip-response "^2.0.1"
|
||||
url-parse-lax "^1.0.0"
|
||||
|
||||
graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4:
|
||||
graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.6:
|
||||
version "4.1.11"
|
||||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
|
||||
|
||||
|
|
@ -2445,6 +2453,12 @@ json5@^0.5.1:
|
|||
version "0.5.1"
|
||||
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"
|
||||
|
||||
jsonfile@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
|
||||
optionalDependencies:
|
||||
graceful-fs "^4.1.6"
|
||||
|
||||
jsonfilter@^1.1.2:
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/jsonfilter/-/jsonfilter-1.1.2.tgz#21ef7cedc75193813c75932e96a98be205ba5a11"
|
||||
|
|
@ -3981,6 +3995,10 @@ unique-string@^1.0.0:
|
|||
dependencies:
|
||||
crypto-random-string "^1.0.0"
|
||||
|
||||
universalify@^0.1.0:
|
||||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"
|
||||
|
||||
unzip-response@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue