@holic512/slothtool 1.0.2 → 1.0.4

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/lib/utils.js CHANGED
@@ -7,7 +7,7 @@ const fs = require('fs');
7
7
  * @returns {string} ~/.slothtool
8
8
  */
9
9
  function getSlothToolHome() {
10
- return path.join(os.homedir(), '.slothtool');
10
+ return path.join(os.homedir(), '.slothtool');
11
11
  }
12
12
 
13
13
  /**
@@ -15,7 +15,7 @@ function getSlothToolHome() {
15
15
  * @returns {string} ~/.slothtool/plugins
16
16
  */
17
17
  function getPluginsDir() {
18
- return path.join(getSlothToolHome(), 'plugins');
18
+ return path.join(getSlothToolHome(), 'plugins');
19
19
  }
20
20
 
21
21
  /**
@@ -23,7 +23,15 @@ function getPluginsDir() {
23
23
  * @returns {string} ~/.slothtool/registry.json
24
24
  */
25
25
  function getRegistryPath() {
26
- return path.join(getSlothToolHome(), 'registry.json');
26
+ return path.join(getSlothToolHome(), 'registry.json');
27
+ }
28
+
29
+ /**
30
+ * 获取设置文件路径
31
+ * @returns {string} ~/.slothtool/settings.json
32
+ */
33
+ function getSettingsPath() {
34
+ return path.join(getSlothToolHome(), 'settings.json');
27
35
  }
28
36
 
29
37
  /**
@@ -31,9 +39,9 @@ function getRegistryPath() {
31
39
  * @param {string} dir - 目录路径
32
40
  */
33
41
  function ensureDir(dir) {
34
- if (!fs.existsSync(dir)) {
35
- fs.mkdirSync(dir, { recursive: true });
36
- }
42
+ if (!fs.existsSync(dir)) {
43
+ fs.mkdirSync(dir, {recursive: true});
44
+ }
37
45
  }
38
46
 
39
47
  /**
@@ -44,13 +52,21 @@ function ensureDir(dir) {
44
52
  * @returns {string} 插件别名
45
53
  */
46
54
  function extractPluginAlias(packageName) {
47
- // 移除 scope (如果有)
48
- const withoutScope = packageName.replace(/^@[^/]+\//, '');
55
+ // 移除 scope (如果有)
56
+ const withoutScope = packageName.replace(/^@[^/]+\//, '');
49
57
 
50
- // 移除 plugin- 前缀 (如果有)
51
- const alias = withoutScope.replace(/^plugin-/, '');
58
+ // 移除 plugin- 前缀 (如果有)
59
+ const alias = withoutScope.replace(/^plugin-/, '');
52
60
 
53
- return alias;
61
+ return alias;
62
+ }
63
+
64
+ /**
65
+ * 获取插件配置目录
66
+ * @returns {string} ~/.slothtool/plugin-configs
67
+ */
68
+ function getPluginConfigsDir() {
69
+ return path.join(getSlothToolHome(), 'plugin-configs');
54
70
  }
55
71
 
56
72
  /**
@@ -59,14 +75,26 @@ function extractPluginAlias(packageName) {
59
75
  * @returns {string} 插件安装目录路径
60
76
  */
61
77
  function getPluginDir(pluginAlias) {
62
- return path.join(getPluginsDir(), pluginAlias);
78
+ return path.join(getPluginsDir(), pluginAlias);
79
+ }
80
+
81
+ /**
82
+ * 获取指定插件的配置文件路径
83
+ * @param {string} pluginAlias - 插件别名
84
+ * @returns {string} 插件配置文件路径
85
+ */
86
+ function getPluginConfigPath(pluginAlias) {
87
+ return path.join(getPluginConfigsDir(), `${pluginAlias}.json`);
63
88
  }
64
89
 
65
90
  module.exports = {
66
- getSlothToolHome,
67
- getPluginsDir,
68
- getRegistryPath,
69
- ensureDir,
70
- extractPluginAlias,
71
- getPluginDir
91
+ getSlothToolHome,
92
+ getPluginsDir,
93
+ getRegistryPath,
94
+ getSettingsPath,
95
+ getPluginConfigsDir,
96
+ ensureDir,
97
+ extractPluginAlias,
98
+ getPluginDir,
99
+ getPluginConfigPath
72
100
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holic512/slothtool",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A plugin manager and dispatcher for CLI tools",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -20,5 +20,8 @@
20
20
  "files": [
21
21
  "bin",
22
22
  "lib"
23
- ]
23
+ ],
24
+ "dependencies": {
25
+ "prompts": "^2.4.2"
26
+ }
24
27
  }