UNPKG

1.76 kBJavaScriptView Raw
1/* util
2 * @Author: Kvkens(yueming@yonyou.com)
3 * @Date: 2017-5-15 00:00:00
4 * @Last Modified by: Kvkens
5 * @Last Modified time: 2018-01-27 23:29:56
6 */
7
8var chalk = require("chalk");
9var resolve = require("resolve");
10var path = require("path");
11
12/**
13 * 获得uba的帮助信息
14 */
15exports.getHelp = function() {
16 console.log();
17 console.log(chalk.green(" Usage: uba <plugin-name>"));
18 console.log();
19 console.log(chalk.green(" Options:"));
20 console.log();
21 console.log(chalk.green(" -h, --help output usage information"));
22 console.log(chalk.green(" -v, --version output the version number"));
23 console.log();
24}
25
26/**
27 * 检测node.js的指定运行版本
28 * @param {*} number 版本号A
29 */
30exports.checkNodeVersion = function(number) {
31 var currentNodeVersion = process.versions.node;
32 if (currentNodeVersion.split(".")[0] < number) {
33 console.error(chalk.red(`You are running Node ${currentNodeVersion}\nCreate Uba App requires Node 6 or higher. \nPlease update your version of Node.`));
34 process.exit(1);
35 }
36}
37
38/**
39 * 根据插件名称来获得插件真实路径
40 * @param {*} command 插件名
41 */
42exports.findPluginPath = function(command) {
43 if (command && /^\w+$/.test(command)) {
44 try {
45 return resolve.sync("uba-" + command, {
46 paths: [path.join(__dirname, "..", "node_modules")]
47 });
48 } catch (e) {
49 console.log(e);
50 console.log(" " + chalk.green(command) + " command is not installed.");
51 console.log(" You can try to install it by " + chalk.blue.bold("npm install uba-" + command) + ".");
52 console.log("");
53 }
54 }
55}
56
57
58/**
59 * 获得uba版本
60 */
61exports.getVersion = function() {
62 console.log(chalk.green(require("../package.json").version));
63 process.exit(0);
64}
\No newline at end of file