@holic512/slothtool 1.0.1 → 1.0.3
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/README.md +330 -31
- package/bin/slothtool.js +60 -31
- package/lib/commands/config.js +35 -0
- package/lib/commands/index.js +14 -4
- package/lib/commands/install.js +9 -9
- package/lib/commands/interactive.js +498 -0
- package/lib/commands/list.js +16 -14
- package/lib/commands/run.js +38 -35
- package/lib/commands/uninstall-all.js +78 -0
- package/lib/commands/uninstall.js +9 -9
- package/lib/commands/update-all.js +10 -0
- package/lib/commands/update.js +20 -0
- package/lib/i18n.js +329 -0
- package/lib/official-plugins.json +24 -0
- package/lib/plugin-manager.js +276 -78
- package/lib/registry.js +43 -43
- package/lib/settings.js +85 -0
- package/lib/utils.js +46 -18
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,81 +1,380 @@
|
|
|
1
1
|
# SlothTool
|
|
2
2
|
|
|
3
|
-
🐌 A plugin manager and dispatcher for CLI tools.
|
|
3
|
+
🐌 A lightweight plugin manager and dispatcher for CLI tools.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@holic512/slothtool)
|
|
6
|
+
[](https://opensource.org/licenses/ISC)
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
SlothTool is a plugin management system that allows you to install, manage, and run CLI tools as plugins without
|
|
11
|
+
polluting your global npm environment. All plugins are installed in an isolated directory (`~/.slothtool/plugins/`) with
|
|
12
|
+
their own dependencies.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- 🔒 **Zero Global Pollution**: Plugins install to `~/.slothtool/plugins/` instead of global npm
|
|
17
|
+
- 📦 **Plugin Isolation**: Each plugin has its own dependencies in isolated directories
|
|
18
|
+
- 🌍 **Bilingual Support**: Full Chinese and English interface (configurable)
|
|
19
|
+
- 🎯 **Simple CLI**: Easy-to-use commands with shorthand syntax
|
|
20
|
+
- 🎨 **Interactive Mode**: Menu-driven interface for easier operation
|
|
21
|
+
- ⚡ **Lightweight**: Only one runtime dependency (`prompts`)
|
|
4
22
|
|
|
5
23
|
## Installation
|
|
6
24
|
|
|
7
25
|
```bash
|
|
8
|
-
npm install -g slothtool
|
|
26
|
+
npm install -g @holic512/slothtool
|
|
9
27
|
```
|
|
10
28
|
|
|
11
|
-
##
|
|
29
|
+
## Quick Start
|
|
12
30
|
|
|
13
31
|
```bash
|
|
14
32
|
# Install a plugin
|
|
15
|
-
slothtool install @
|
|
33
|
+
slothtool install @holic512/plugin-loc
|
|
34
|
+
|
|
35
|
+
# Run the plugin (shorthand)
|
|
36
|
+
slothtool loc ./src
|
|
37
|
+
|
|
38
|
+
# Or use explicit run command
|
|
39
|
+
slothtool run loc ./src
|
|
16
40
|
|
|
17
41
|
# List installed plugins
|
|
18
42
|
slothtool list
|
|
19
43
|
|
|
20
|
-
#
|
|
21
|
-
slothtool
|
|
22
|
-
|
|
23
|
-
# Uninstall a plugin
|
|
24
|
-
slothtool uninstall loc
|
|
44
|
+
# Configure language (default: Chinese)
|
|
45
|
+
slothtool config language en
|
|
25
46
|
|
|
26
|
-
#
|
|
27
|
-
slothtool
|
|
47
|
+
# Interactive mode
|
|
48
|
+
slothtool -i
|
|
28
49
|
```
|
|
29
50
|
|
|
30
51
|
## Commands
|
|
31
52
|
|
|
32
|
-
|
|
33
|
-
- `slothtool uninstall <plugin>` - Uninstall a plugin
|
|
34
|
-
- `slothtool list` - List all installed plugins
|
|
35
|
-
- `slothtool run <plugin> [args]` - Run a plugin with arguments
|
|
36
|
-
- `slothtool <plugin> [args]` - Shorthand for running a plugin
|
|
53
|
+
### Core Commands
|
|
37
54
|
|
|
38
|
-
|
|
55
|
+
| Command | Description |
|
|
56
|
+
|--------------------------------------|--------------------------------|
|
|
57
|
+
| `slothtool install <plugin>` | Install a plugin from npm |
|
|
58
|
+
| `slothtool uninstall <plugin>` | Uninstall a plugin |
|
|
59
|
+
| `slothtool list` | List all installed plugins |
|
|
60
|
+
| `slothtool run <plugin> [args]` | Run a plugin with arguments |
|
|
61
|
+
| `slothtool <plugin> [args]` | Shorthand for running a plugin |
|
|
62
|
+
| `slothtool config language <zh\|en>` | Configure interface language |
|
|
63
|
+
| `slothtool -i, --interactive` | Launch interactive mode |
|
|
64
|
+
| `slothtool --help` | Show help information |
|
|
65
|
+
|
|
66
|
+
### Examples
|
|
39
67
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
68
|
+
```bash
|
|
69
|
+
# Install official plugin
|
|
70
|
+
slothtool install @holic512/plugin-loc
|
|
71
|
+
|
|
72
|
+
# Install any npm package with bin field
|
|
73
|
+
slothtool install some-cli-tool
|
|
74
|
+
|
|
75
|
+
# Run plugin with arguments
|
|
76
|
+
slothtool loc ./src --verbose
|
|
77
|
+
|
|
78
|
+
# Uninstall plugin
|
|
79
|
+
slothtool uninstall loc
|
|
80
|
+
|
|
81
|
+
# Switch to English interface
|
|
82
|
+
slothtool config language en
|
|
83
|
+
|
|
84
|
+
# Use interactive mode
|
|
85
|
+
slothtool -i
|
|
86
|
+
```
|
|
44
87
|
|
|
45
88
|
## How It Works
|
|
46
89
|
|
|
47
|
-
SlothTool manages CLI tools as plugins:
|
|
90
|
+
SlothTool manages CLI tools as isolated plugins:
|
|
91
|
+
|
|
92
|
+
1. **Installation**: Plugins are npm packages with a `bin` field
|
|
93
|
+
2. **Storage**: Downloaded to `~/.slothtool/plugins/<alias>/` with isolated dependencies
|
|
94
|
+
3. **Registry**: Maintains a registry at `~/.slothtool/registry.json` tracking installed plugins
|
|
95
|
+
4. **Execution**: Spawns the plugin's executable when you run it
|
|
96
|
+
5. **Configuration**: User settings stored in `~/.slothtool/settings.json`
|
|
97
|
+
|
|
98
|
+
### Directory Structure
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
~/.slothtool/
|
|
102
|
+
├── plugins/ # Plugin installation directory
|
|
103
|
+
│ ├── loc/ # Example: loc plugin
|
|
104
|
+
│ │ └── node_modules/
|
|
105
|
+
│ └── another-plugin/
|
|
106
|
+
├── plugin-configs/ # Plugin-specific configurations
|
|
107
|
+
│ └── loc.json
|
|
108
|
+
├── registry.json # Plugin registry
|
|
109
|
+
└── settings.json # User settings (language, etc.)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Configuration
|
|
113
|
+
|
|
114
|
+
### Language Settings
|
|
48
115
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
116
|
+
SlothTool supports Chinese (zh) and English (en):
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Switch to English
|
|
120
|
+
slothtool config language en
|
|
121
|
+
|
|
122
|
+
# Switch to Chinese (default)
|
|
123
|
+
slothtool config language zh
|
|
124
|
+
|
|
125
|
+
# View current language
|
|
126
|
+
slothtool config
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Plugin Alias Extraction
|
|
130
|
+
|
|
131
|
+
Package names are automatically converted to simple aliases:
|
|
132
|
+
|
|
133
|
+
- `@holic512/plugin-loc` → `loc`
|
|
134
|
+
- `plugin-mytool` → `mytool`
|
|
135
|
+
- `some-tool` → `some-tool`
|
|
53
136
|
|
|
54
137
|
## Official Plugins
|
|
55
138
|
|
|
56
|
-
- [@holic512/plugin-loc](../plugin-loc) -
|
|
139
|
+
- [@holic512/plugin-loc](../plugin-loc) - Lines of code counter with interactive features
|
|
57
140
|
|
|
58
141
|
## Creating Plugins
|
|
59
142
|
|
|
60
|
-
Any npm package with a `bin` field can be a SlothTool plugin
|
|
143
|
+
Any npm package with a `bin` field can be a SlothTool plugin.
|
|
144
|
+
|
|
145
|
+
### Basic Plugin Structure
|
|
61
146
|
|
|
62
147
|
```json
|
|
63
148
|
{
|
|
64
149
|
"name": "@yourscope/plugin-mytool",
|
|
65
150
|
"version": "1.0.0",
|
|
151
|
+
"description": "My awesome CLI tool",
|
|
66
152
|
"bin": {
|
|
67
|
-
"mytool": "bin/
|
|
68
|
-
}
|
|
153
|
+
"mytool": "bin/mytool.js"
|
|
154
|
+
},
|
|
155
|
+
"keywords": [
|
|
156
|
+
"slothtool-plugin",
|
|
157
|
+
"cli"
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Plugin Best Practices
|
|
163
|
+
|
|
164
|
+
1. **Naming Convention**: Use `plugin-` prefix or include in package scope
|
|
165
|
+
2. **Keywords**: Add `slothtool-plugin` keyword for discoverability
|
|
166
|
+
3. **Internationalization**: Read language from `~/.slothtool/settings.json` for i18n support
|
|
167
|
+
4. **Configuration**: Store plugin-specific config in `~/.slothtool/plugin-configs/<alias>.json`
|
|
168
|
+
5. **Interactive Features**: Use `prompts` library for better UX
|
|
169
|
+
|
|
170
|
+
### Example Plugin with i18n
|
|
171
|
+
|
|
172
|
+
```javascript
|
|
173
|
+
#!/usr/bin/env node
|
|
174
|
+
const fs = require('fs');
|
|
175
|
+
const path = require('path');
|
|
176
|
+
const os = require('os');
|
|
177
|
+
|
|
178
|
+
// Read language setting from slothtool
|
|
179
|
+
function getLanguage() {
|
|
180
|
+
const settingsPath = path.join(os.homedir(), '.slothtool', 'settings.json');
|
|
181
|
+
if (fs.existsSync(settingsPath)) {
|
|
182
|
+
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
|
183
|
+
return settings.language || 'zh';
|
|
184
|
+
}
|
|
185
|
+
return 'zh';
|
|
69
186
|
}
|
|
187
|
+
|
|
188
|
+
const messages = {
|
|
189
|
+
zh: {greeting: '你好,世界!'},
|
|
190
|
+
en: {greeting: 'Hello, World!'}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const lang = getLanguage();
|
|
194
|
+
console.log(messages[lang].greeting);
|
|
70
195
|
```
|
|
71
196
|
|
|
72
|
-
|
|
197
|
+
### Publishing Your Plugin
|
|
73
198
|
|
|
74
199
|
```bash
|
|
200
|
+
# Publish to npm
|
|
201
|
+
npm publish --access public
|
|
202
|
+
|
|
203
|
+
# Users can then install it
|
|
75
204
|
slothtool install @yourscope/plugin-mytool
|
|
76
205
|
slothtool mytool
|
|
77
206
|
```
|
|
78
207
|
|
|
208
|
+
## Interactive Mode
|
|
209
|
+
|
|
210
|
+
Launch interactive mode for a menu-driven experience:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
slothtool -i
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Features:
|
|
217
|
+
|
|
218
|
+
- Install official or custom plugins
|
|
219
|
+
- Uninstall plugins
|
|
220
|
+
- List installed plugins
|
|
221
|
+
- Run plugins
|
|
222
|
+
- Configure language settings
|
|
223
|
+
|
|
224
|
+
## Uninstalling
|
|
225
|
+
|
|
226
|
+
### Uninstall a Plugin
|
|
227
|
+
|
|
228
|
+
When you uninstall a plugin, SlothTool will automatically remove:
|
|
229
|
+
|
|
230
|
+
- Plugin directory and all its dependencies (`~/.slothtool/plugins/<alias>/`)
|
|
231
|
+
- Plugin-specific configuration file (`~/.slothtool/plugin-configs/<alias>.json`)
|
|
232
|
+
- Registry entry from `~/.slothtool/registry.json`
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
# Uninstall a specific plugin
|
|
236
|
+
slothtool uninstall <plugin-alias>
|
|
237
|
+
|
|
238
|
+
# Example
|
|
239
|
+
slothtool uninstall loc
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
The uninstall command will show you exactly what will be removed before proceeding.
|
|
243
|
+
|
|
244
|
+
### Complete Uninstallation
|
|
245
|
+
|
|
246
|
+
To completely remove SlothTool and all its data from your system:
|
|
247
|
+
|
|
248
|
+
#### Option 1: Using the built-in command (recommended)
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
# Remove all plugins, configurations, and SlothTool data
|
|
252
|
+
slothtool --uninstall-all
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
This will remove:
|
|
256
|
+
- All installed plugins (`~/.slothtool/plugins/`)
|
|
257
|
+
- All plugin configurations (`~/.slothtool/plugin-configs/`)
|
|
258
|
+
- Registry file (`~/.slothtool/registry.json`)
|
|
259
|
+
- Settings file (`~/.slothtool/settings.json`)
|
|
260
|
+
- The entire `~/.slothtool/` directory
|
|
261
|
+
|
|
262
|
+
Then uninstall the global SlothTool package:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
npm uninstall -g @holic512/slothtool
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
#### Option 2: Manual removal
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# 1. Remove all SlothTool data
|
|
272
|
+
rm -rf ~/.slothtool/
|
|
273
|
+
|
|
274
|
+
# 2. Uninstall the global package
|
|
275
|
+
npm uninstall -g @holic512/slothtool
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### What Gets Removed
|
|
279
|
+
|
|
280
|
+
Here's a complete breakdown of what SlothTool stores on your system:
|
|
281
|
+
|
|
282
|
+
```
|
|
283
|
+
~/.slothtool/
|
|
284
|
+
├── plugins/ # All installed plugins and their dependencies
|
|
285
|
+
│ ├── loc/ # Example: loc plugin
|
|
286
|
+
│ │ ├── node_modules/
|
|
287
|
+
│ │ └── package.json
|
|
288
|
+
│ └── [other-plugins]/
|
|
289
|
+
├── plugin-configs/ # Plugin-specific configurations
|
|
290
|
+
│ ├── loc.json # Example: loc plugin config
|
|
291
|
+
│ └── [other-configs].json
|
|
292
|
+
├── registry.json # Plugin registry (tracks installed plugins)
|
|
293
|
+
└── settings.json # User settings (language preference, etc.)
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
**Note**: SlothTool only stores data in `~/.slothtool/`. No other system files or directories are modified.
|
|
297
|
+
|
|
298
|
+
## Troubleshooting
|
|
299
|
+
|
|
300
|
+
### Plugin Not Found
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
# Check installed plugins
|
|
304
|
+
slothtool list
|
|
305
|
+
|
|
306
|
+
# Reinstall if needed
|
|
307
|
+
slothtool uninstall <plugin>
|
|
308
|
+
slothtool install <plugin>
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Permission Issues
|
|
312
|
+
|
|
313
|
+
SlothTool installs to user directory (`~/.slothtool/`), so no sudo is required. If you encounter permission issues:
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
# Check directory permissions
|
|
317
|
+
ls -la ~/.slothtool/
|
|
318
|
+
|
|
319
|
+
# Fix permissions if needed
|
|
320
|
+
chmod -R u+w ~/.slothtool/
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
## Development
|
|
324
|
+
|
|
325
|
+
### Local Development
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
# Clone repository
|
|
329
|
+
git clone https://github.com/holic512/SlothTool.git
|
|
330
|
+
cd SlothTool
|
|
331
|
+
|
|
332
|
+
# Install dependencies
|
|
333
|
+
npm install
|
|
334
|
+
|
|
335
|
+
# Link for local testing
|
|
336
|
+
cd packages/slothtool
|
|
337
|
+
npm link
|
|
338
|
+
|
|
339
|
+
# Test the CLI
|
|
340
|
+
slothtool --help
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Project Structure
|
|
344
|
+
|
|
345
|
+
```
|
|
346
|
+
packages/slothtool/
|
|
347
|
+
├── bin/
|
|
348
|
+
│ └── slothtool.js # CLI entry point
|
|
349
|
+
├── lib/
|
|
350
|
+
│ ├── commands/ # Command implementations
|
|
351
|
+
│ │ ├── install.js
|
|
352
|
+
│ │ ├── uninstall.js
|
|
353
|
+
│ │ ├── list.js
|
|
354
|
+
│ │ ├── run.js
|
|
355
|
+
│ │ ├── config.js
|
|
356
|
+
│ │ └── interactive.js
|
|
357
|
+
│ ├── i18n.js # Internationalization
|
|
358
|
+
│ ├── plugin-manager.js # Plugin installation/uninstallation
|
|
359
|
+
│ ├── registry.js # Registry management
|
|
360
|
+
│ ├── settings.js # Settings management
|
|
361
|
+
│ └── utils.js # Utility functions
|
|
362
|
+
└── package.json
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## Contributing
|
|
366
|
+
|
|
367
|
+
Contributions are welcome! Please feel free to submit issues and pull requests.
|
|
368
|
+
|
|
369
|
+
## Related Documentation
|
|
370
|
+
|
|
371
|
+
- [Configuration Analysis](../../docs/slothtool-configuration-analysis.md) - Detailed analysis of the codebase
|
|
372
|
+
- [npm link vs SlothTool](../../docs/npm-link-vs-slothtool.md) - Comparison with npm link
|
|
373
|
+
|
|
79
374
|
## License
|
|
80
375
|
|
|
81
376
|
ISC
|
|
377
|
+
|
|
378
|
+
## Author
|
|
379
|
+
|
|
380
|
+
holic512
|
package/bin/slothtool.js
CHANGED
|
@@ -1,50 +1,79 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const commands = require('../lib/commands');
|
|
4
|
+
const {t} = require('../lib/i18n');
|
|
4
5
|
|
|
5
6
|
const args = process.argv.slice(2);
|
|
6
7
|
const command = args[0];
|
|
7
8
|
|
|
8
9
|
// 如果没有参数,显示帮助信息
|
|
9
10
|
if (!command) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
console.log(t('pluginManager') + '\n');
|
|
12
|
+
console.log(t('usage'));
|
|
13
|
+
console.log(' slothtool install <plugin> ' + t('commands.install'));
|
|
14
|
+
console.log(' slothtool uninstall <plugin> ' + t('commands.uninstall'));
|
|
15
|
+
console.log(' slothtool update <plugin> ' + t('commands.update'));
|
|
16
|
+
console.log(' slothtool --update-all ' + t('commands.updateAll'));
|
|
17
|
+
console.log(' slothtool list ' + t('commands.list'));
|
|
18
|
+
console.log(' slothtool run <plugin> [args] ' + t('commands.run'));
|
|
19
|
+
console.log(' slothtool <plugin> [args] ' + t('commands.runShorthand'));
|
|
20
|
+
console.log(' slothtool config language <lang> ' + t('commands.config'));
|
|
21
|
+
console.log(' slothtool -i, --interactive ' + t('commands.interactive'));
|
|
22
|
+
console.log(' slothtool --uninstall-all ' + t('commands.uninstallAll') + '\n');
|
|
23
|
+
console.log(t('examples'));
|
|
24
|
+
console.log(' slothtool install @holic512/plugin-loc');
|
|
25
|
+
console.log(' slothtool loc ./src');
|
|
26
|
+
console.log(' slothtool update loc');
|
|
27
|
+
console.log(' slothtool --update-all');
|
|
28
|
+
console.log(' slothtool list');
|
|
29
|
+
console.log(' slothtool config language en');
|
|
30
|
+
console.log(' slothtool -i');
|
|
31
|
+
process.exit(0);
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
// 内置命令
|
|
25
35
|
if (command === 'install') {
|
|
26
|
-
|
|
36
|
+
commands.install(args.slice(1));
|
|
27
37
|
} else if (command === 'uninstall') {
|
|
28
|
-
|
|
38
|
+
commands.uninstall(args.slice(1));
|
|
39
|
+
} else if (command === 'update') {
|
|
40
|
+
commands.update(args.slice(1));
|
|
41
|
+
} else if (command === '--update-all') {
|
|
42
|
+
commands.updateAll();
|
|
29
43
|
} else if (command === 'list') {
|
|
30
|
-
|
|
44
|
+
commands.list();
|
|
31
45
|
} else if (command === 'run') {
|
|
32
|
-
|
|
46
|
+
commands.run(args.slice(1));
|
|
47
|
+
} else if (command === 'config') {
|
|
48
|
+
commands.config(args.slice(1));
|
|
49
|
+
} else if (command === '-i' || command === '--interactive') {
|
|
50
|
+
commands.interactive();
|
|
51
|
+
} else if (command === '--uninstall-all') {
|
|
52
|
+
commands.uninstallAll();
|
|
33
53
|
} else if (command === '--help' || command === '-h') {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
console.log(t('pluginManager') + '\n');
|
|
55
|
+
console.log(t('usage'));
|
|
56
|
+
console.log(' slothtool install <plugin> ' + t('commands.install'));
|
|
57
|
+
console.log(' slothtool uninstall <plugin> ' + t('commands.uninstall'));
|
|
58
|
+
console.log(' slothtool update <plugin> ' + t('commands.update'));
|
|
59
|
+
console.log(' slothtool --update-all ' + t('commands.updateAll'));
|
|
60
|
+
console.log(' slothtool list ' + t('commands.list'));
|
|
61
|
+
console.log(' slothtool run <plugin> [args] ' + t('commands.run'));
|
|
62
|
+
console.log(' slothtool <plugin> [args] ' + t('commands.runShorthand'));
|
|
63
|
+
console.log(' slothtool config language <lang> ' + t('commands.config'));
|
|
64
|
+
console.log(' slothtool -i, --interactive ' + t('commands.interactive'));
|
|
65
|
+
console.log(' slothtool --uninstall-all ' + t('commands.uninstallAll') + '\n');
|
|
66
|
+
console.log(t('examples'));
|
|
67
|
+
console.log(' slothtool install @holic512/plugin-loc');
|
|
68
|
+
console.log(' slothtool loc ./src');
|
|
69
|
+
console.log(' slothtool update loc');
|
|
70
|
+
console.log(' slothtool --update-all');
|
|
71
|
+
console.log(' slothtool list');
|
|
72
|
+
console.log(' slothtool config language en');
|
|
73
|
+
console.log(' slothtool -i');
|
|
74
|
+
process.exit(0);
|
|
46
75
|
} else {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
76
|
+
// 简写形式:slothtool <plugin> [...args]
|
|
77
|
+
// 直接将所有参数传递给 run 命令
|
|
78
|
+
commands.run(args);
|
|
50
79
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const settings = require('../settings');
|
|
2
|
+
const {t} = require('../i18n');
|
|
3
|
+
|
|
4
|
+
function config(args) {
|
|
5
|
+
if (args.length === 0) {
|
|
6
|
+
// 显示当前配置
|
|
7
|
+
const language = settings.getLanguage();
|
|
8
|
+
console.log(t('currentLanguage'), language);
|
|
9
|
+
console.log('\n' + t('configUsage'));
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const subCommand = args[0];
|
|
14
|
+
|
|
15
|
+
if (subCommand === 'language') {
|
|
16
|
+
if (args.length < 2) {
|
|
17
|
+
console.log(t('configUsage'));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const language = args[1];
|
|
22
|
+
|
|
23
|
+
if (language !== 'zh' && language !== 'en') {
|
|
24
|
+
console.error(t('invalidLanguage'));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
settings.setLanguage(language);
|
|
29
|
+
console.log(t('languageSet'), language);
|
|
30
|
+
} else {
|
|
31
|
+
console.log(t('configUsage'));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = config;
|
package/lib/commands/index.js
CHANGED
|
@@ -2,10 +2,20 @@ const install = require('./install');
|
|
|
2
2
|
const uninstall = require('./uninstall');
|
|
3
3
|
const list = require('./list');
|
|
4
4
|
const run = require('./run');
|
|
5
|
+
const config = require('./config');
|
|
6
|
+
const interactive = require('./interactive');
|
|
7
|
+
const uninstallAll = require('./uninstall-all');
|
|
8
|
+
const update = require('./update');
|
|
9
|
+
const updateAll = require('./update-all');
|
|
5
10
|
|
|
6
11
|
module.exports = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
install,
|
|
13
|
+
uninstall,
|
|
14
|
+
list,
|
|
15
|
+
run,
|
|
16
|
+
config,
|
|
17
|
+
interactive,
|
|
18
|
+
uninstallAll,
|
|
19
|
+
update,
|
|
20
|
+
updateAll
|
|
11
21
|
};
|
package/lib/commands/install.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {installPlugin} = require('../plugin-manager');
|
|
2
2
|
|
|
3
3
|
function install(args) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
if (args.length === 0) {
|
|
5
|
+
console.error('Error: Please specify a plugin to install.');
|
|
6
|
+
console.log('Usage: slothtool install <plugin-name>');
|
|
7
|
+
console.log('Example: slothtool install @slothtool/plugin-loc');
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const packageName = args[0];
|
|
12
|
+
installPlugin(packageName);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
module.exports = install;
|