-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- related to #3 #2 give up on making code completion work, at least project level module got proper hint - enable color by default
- Loading branch information
Showing
5 changed files
with
73 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,23 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
const meow = require('meow'); | ||
const chalk = require('chalk'); | ||
const error = chalk.bold.red; | ||
console.log(error('Error!')); | ||
const configLocator = require('../lib/config/locator'); | ||
|
||
const cli = meow(` | ||
Usage | ||
$ foo <input> | ||
$ about <input> | ||
Options | ||
--rainbow, -r Include a rainbow | ||
--config, -c Specify config file | ||
Examples | ||
$ foo unicorns --rainbow | ||
🌈 unicorns 🌈 | ||
$ about --config ./example/config.yaml | ||
$ about -c ./example/config.yaml | ||
`, { | ||
alias: { | ||
r: 'rainbow' | ||
c: 'config' | ||
} | ||
}); | ||
/* | ||
{ | ||
input: ['unicorns'], | ||
flags: {rainbow: true}, | ||
... | ||
} | ||
*/ | ||
// node about.js unicorns --rainbow | ||
// unicorns { rainbow: true, r: true } | ||
console.log(cli.input[0], cli.flags); | ||
console.log(cli.input[0], cli.flags); | ||
configLocator.detectConfigFile(cli.flags); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Created by at15 on 2016/9/6. | ||
*/ | ||
const logger = require('../logger'); | ||
const fsUtil = require('../util/fs'); | ||
|
||
function detectConfigFile(flags) { | ||
if (typeof flags.config === 'string') { | ||
let configFile = flags.config; | ||
logger.debug(`config file set as ${configFile}`); | ||
// it must exist, if not we fallback to the default one and throw a warning | ||
if (!fsUtil.fileExists(configFile)) { | ||
logger.warn(`config file can't be found ${configFile}`); | ||
} | ||
} | ||
logger.debug('using default config file'); | ||
} | ||
|
||
module.exports = { | ||
detectConfigFile | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Created by at15 on 2016/9/6. | ||
* | ||
*/ | ||
|
||
const winston = require('winston'); | ||
|
||
let logger = new (winston.Logger)({ | ||
transports: [ | ||
new (winston.transports.Console)({ level: 'debug', colorize: true }) | ||
] | ||
}); | ||
|
||
module.exports = { | ||
// FIXME: got no type hint for the function parameters | ||
// TODO: add color using chalk, don't know if winston has color by default | ||
// winston is using colors instead of chalk (colors seems to have problems which are solved by chalk) | ||
debug: logger.debug, | ||
info: logger.info, | ||
warn: logger.warn, | ||
error: logger.error | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Created by at15 on 2016/9/6. | ||
*/ | ||
var fs = require('fs'); | ||
|
||
/** @param path {string} */ | ||
function fileExists(path) { | ||
try { | ||
fs.accessSync(path, fs.constants.F_OK) | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
module.exports = { | ||
fileExists | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters