clear_node_modules 1.3.1 → 1.4.0

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.
Files changed (3) hide show
  1. package/bin.js +24 -17
  2. package/package.json +5 -7
  3. package/config.json +0 -5
package/bin.js CHANGED
@@ -1,39 +1,46 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const path = require("path");
4
- const config = require("./config.json");
5
4
  const clearDir = require("./src/lib");
6
5
 
7
6
  const { version } = require("./package.json");
8
7
 
9
8
  const args = process.argv.slice(2);
10
9
 
10
+ // 版本信息
11
11
  if (args.includes("-v") || args.includes("--version")) {
12
12
  console.log(`cnm v${version}`);
13
13
  process.exit(0);
14
14
  }
15
15
 
16
- const log = console.log;
16
+ // 帮助信息
17
+ const isHelp = args.some((arg) => /^(-+|\/)(h(elp)?|\?)$/.test(arg));
17
18
 
18
- const DIST_DIR = path.resolve(process.cwd(), args[0] || config.dist_dir_path);
19
- const LIMIT_SIZE = args[1] || config.dist_dir_size;
20
- const NODE_MODULES = args[2] || config.dist_dir_name;
19
+ if (isHelp) {
20
+ console.log(`
21
+ cnm v${version} - Clear Node Modules
21
22
 
22
- let isHelp = false;
23
+ Usage: npx cnms [path] [limit] [folder]
23
24
 
24
- args.forEach((arg) => {
25
- if (arg.match(/^(-+|\/)(h(elp)?|\?)$/)) isHelp = true;
26
- });
25
+ Arguments:
26
+ path Target directory (default: current directory)
27
+ limit Minimum size in MB to delete (default: 0)
28
+ folder Folder name to delete (default: node_modules)
27
29
 
28
- if (args.length < 1) isHelp = true;
30
+ Examples:
31
+ npx cnms # Clear all node_modules in current dir
32
+ npx cnms ./projects # Clear in specific directory
33
+ npx cnms ./ 100 # Only delete if > 100MB
29
34
 
30
- if (isHelp) {
31
- log("");
32
- log("useage: cnm <path> <limit(mb)> <distDir>");
33
- log("");
34
- log(" delete the specified folder!");
35
- log("");
36
- process.exit(1);
35
+ After global install (npm i -g cnms):
36
+ cnm # Same as above, shorter command
37
+ `);
38
+ process.exit(0);
37
39
  }
38
40
 
41
+ // 默认配置
42
+ const DIST_DIR = path.resolve(process.cwd(), args[0] || "./");
43
+ const LIMIT_SIZE = args[1] || 0;
44
+ const NODE_MODULES = args[2] || "node_modules";
45
+
39
46
  clearDir(DIST_DIR, LIMIT_SIZE, NODE_MODULES);
package/package.json CHANGED
@@ -1,11 +1,8 @@
1
1
  {
2
2
  "name": "clear_node_modules",
3
- "version": "1.3.1",
4
- "description": "help you remove all large file of node_modules in dist dir!",
3
+ "version": "1.4.0",
4
+ "description": "Recursively remove node_modules folders from current directory and subdirectories",
5
5
  "main": "index.js",
6
- "directories": {
7
- "test": "test"
8
- },
9
6
  "bin": {
10
7
  "cnm": "./bin.js"
11
8
  },
@@ -18,7 +15,9 @@
18
15
  },
19
16
  "keywords": [
20
17
  "clear",
21
- "node_modules"
18
+ "node_modules",
19
+ "cleanup",
20
+ "npx"
22
21
  ],
23
22
  "author": "taobeer",
24
23
  "license": "ISC",
@@ -27,7 +26,6 @@
27
26
  },
28
27
  "homepage": "https://github.com/mooniitt/clear_node_modules#readme",
29
28
  "dependencies": {
30
- "clear_node_modules": "^1.2.0",
31
29
  "ora": "^3.0.0",
32
30
  "rimraf": "^2.6.2"
33
31
  }
package/config.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "dist_dir_size": 0,
3
- "dist_dir_path": "./test",
4
- "dist_dir_name": "node_modules"
5
- }