@yuw-cli-dev/core 1.0.32 → 1.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/index.js CHANGED
@@ -1,3 +1,8 @@
1
- #!/user/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
- console.log("This is the core package of yuw-cli-dev");
3
+ const importLocal = require("import-local");
4
+ if (importLocal(__filename)) {
5
+ require("npmlog").info("cli", "正在使用 yuw-cli-dev 本地版本");
6
+ } else {
7
+ require("../lib/index.js")(process.argv.slice(2));
8
+ }
package/lib/const.js ADDED
@@ -0,0 +1,7 @@
1
+ const LOWEST_NODE_VERSION = "16.0.0";
2
+ const DEFAULT_CLI_HOME = ".yuw-cli";
3
+
4
+ module.exports = {
5
+ LOWEST_NODE_VERSION,
6
+ DEFAULT_CLI_HOME,
7
+ };
package/lib/index.js ADDED
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ module.exports = core;
4
+
5
+ const path = require("path");
6
+ const colors = require("colors/safe");
7
+ const semver = require("semver");
8
+ const userHome = require("user-home");
9
+ const pathExists = require("path-exists").sync;
10
+ const pkg = require("../package.json");
11
+ const log = require("@yuw-cli-dev/log");
12
+ const constants = require("./const");
13
+
14
+ function core() {
15
+ try {
16
+ checkPkgVersion();
17
+ checkNodeVersion();
18
+ checkRoot();
19
+ checkUserHome();
20
+ checkInputArgs();
21
+ checkEnv();
22
+ } catch (error) {
23
+ log.error(error.message);
24
+ }
25
+ }
26
+ function checkPkgVersion() {
27
+ log.info("cli", pkg.version);
28
+ }
29
+
30
+ function checkNodeVersion() {
31
+ const currentVersion = process.version;
32
+ const lowestVersion = constants.LOWEST_NODE_VERSION;
33
+ if (!semver.gte(currentVersion, lowestVersion)) {
34
+ throw new Error(
35
+ colors.red(
36
+ `yuw-cli 需要安装 v${lowestVersion} 以上版本的 Node.js,当前版本为 ${currentVersion},请升级您的 Node.js 版本。`,
37
+ ),
38
+ );
39
+ }
40
+ }
41
+
42
+ function checkRoot() {
43
+ const rootCheck = require("root-check");
44
+ rootCheck();
45
+ }
46
+
47
+ function checkUserHome() {
48
+ console.log(userHome);
49
+ if (!userHome || !pathExists(userHome)) {
50
+ throw new Error(colors.red("当前登录用户主目录不存在!"));
51
+ }
52
+ }
53
+
54
+ function checkInputArgs() {
55
+ const minimist = require("minimist");
56
+ const args = minimist(process.argv.slice(2));
57
+ checkArgs(args);
58
+ }
59
+
60
+ function checkArgs(args) {
61
+ if (args.debug) {
62
+ process.env.LOG_LEVEL = "verbose";
63
+ } else {
64
+ process.env.LOG_LEVEL = "info";
65
+ }
66
+ log.level = process.env.LOG_LEVEL;
67
+ }
68
+
69
+ function checkEnv() {
70
+ const dotenv = require("dotenv");
71
+ const dotenvPath = path.resolve(userHome, ".env");
72
+ if (pathExists(dotenvPath)) {
73
+ dotenv.config({
74
+ path: dotenvPath,
75
+ });
76
+ }
77
+ createDefaultConfig();
78
+ log.verbose("环境变量", process.env.CLI_HOME_PATH);
79
+ }
80
+
81
+ function createDefaultConfig() {
82
+ const cliConfig = {
83
+ home: userHome,
84
+ };
85
+ if (process.env.CLI_HOME_PATH) {
86
+ cliConfig.cliHome = path.join(userHome, process.env.CLI_HOME_PATH);
87
+ } else {
88
+ cliConfig.cliHome = path.join(userHome, constants.DEFAULT_CLI_HOME);
89
+ }
90
+ process.env.CLI_HOME_PATH = cliConfig.cliHome;
91
+ }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@yuw-cli-dev/core",
3
- "version": "1.0.32",
3
+ "version": "1.0.36",
4
4
  "description": "> TODO: description",
5
5
  "author": "yuwei <yuwei@huya.com>",
6
6
  "homepage": "",
7
7
  "license": "ISC",
8
8
  "main": "lib/core.js",
9
9
  "bin": {
10
- "yuw-cli": "bin/index.js"
10
+ "yuw-cli-dev": "bin/index.js"
11
11
  },
12
12
  "directories": {
13
13
  "lib": "lib",
@@ -20,9 +20,18 @@
20
20
  "test": "echo \"Error: run tests from root\" && exit 1"
21
21
  },
22
22
  "dependencies": {
23
- "@yuw-cli-dev/utils": "^1.0.32"
23
+ "@yuw-cli-dev/log": "^1.0.36",
24
+ "@yuw-cli-dev/utils": "^1.0.36",
25
+ "colors": "^1.4.0",
26
+ "dotenv": "^17.2.3",
27
+ "import-local": "^3.2.0",
28
+ "minimist": "^1.2.8",
29
+ "npmlog": "^7.0.1",
30
+ "path-exists": "^4.0.0",
31
+ "root-check": "^1.0.0",
32
+ "user-home": "^3.0.0"
24
33
  },
25
- "gitHead": "f0cd1a284537c1d9da4d9d7c9b0d2647f603a14a",
34
+ "gitHead": "3158601705698cd7fd8a308d939a6ccce3d77035",
26
35
  "publishConfig": {
27
36
  "access": "public"
28
37
  }
package/lib/core.js DELETED
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = core;
4
-
5
- function core() {
6
- // TODO
7
- }