cc-codeline 1.0.3 → 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.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/bin.js +42 -20
  3. package/package.json +6 -3
package/README.md CHANGED
@@ -3,4 +3,8 @@
3
3
  npm i -g cc-codeline
4
4
 
5
5
  codeline /path/
6
+
7
+ -h Show help
8
+ -l Print log
9
+ -e Exclude directory
6
10
  ```
package/bin.js CHANGED
@@ -46,28 +46,44 @@ const languages = {
46
46
  comment: /'''[\s\S]+?'''|#.*/g
47
47
  }
48
48
  };
49
- let total = 0;
50
- let empty = 0;
51
- let source = 0;
52
- let comment = 0;
53
- let fileCount = 0;
54
49
 
55
50
  const param = process.argv.slice(2);
56
- const isLog = param.includes('-l');
57
-
58
- const base = process.cwd();
59
- const path = resolve(base, param[0] || '');
60
-
61
- (() => {
62
- if (param.includes('-h')) {
63
- console.log(`
64
- codeline /path/ -l
51
+ if (param.includes('-h')) {
52
+ console.log(`
53
+ codeline /path/ -l -e node_modules dist
65
54
  ------------------
66
55
  -h Show help
67
56
  -l Print log
57
+ -e Exclude directory
68
58
  `);
69
- return;
59
+ process.exit(0);
60
+ }
61
+ const base = process.cwd();
62
+ const isLog = (() => {
63
+ const index = param.indexOf('-l');
64
+ if (index >= 0) {
65
+ param.splice(index, 1);
66
+ return true;
67
+ }
68
+ return false;
69
+ })();
70
+
71
+ const excludePath = (() => {
72
+ const index = param.findIndex(it => it == '-e');
73
+ if (index >= 0) {
74
+ return param.splice(index).map(it => resolve(base, it));
70
75
  }
76
+ })();
77
+
78
+ const path = resolve(base, param[0] || '');
79
+
80
+ let total = 0;
81
+ let empty = 0;
82
+ let source = 0;
83
+ let comment = 0;
84
+ let fileCount = 0;
85
+
86
+ (() => {
71
87
  try {
72
88
  const stat = fs.statSync(path);
73
89
  if (stat.isDirectory()) {
@@ -79,8 +95,8 @@ codeline /path/ -l
79
95
  print()
80
96
  });
81
97
  }
82
- } catch (_) {
83
- console.log('Error, the path may not exist');
98
+ } catch (err) {
99
+ console.log(err.message || 'Error, the path may not exist');
84
100
  }
85
101
  })();
86
102
 
@@ -95,10 +111,14 @@ function print() {
95
111
  }
96
112
 
97
113
  function readDirectory(dirPath, callback) {
114
+ if (excludePath && excludePath.includes(dirPath)) {
115
+ callback();
116
+ return;
117
+ }
98
118
  let progress = 0;
99
119
  fs.readdir(dirPath, (err, filenames) => {
100
120
  if (err) {
101
- console.log('Error reading directory');
121
+ console.log(err.message);
102
122
  callback();
103
123
  return;
104
124
  }
@@ -136,12 +156,14 @@ function readFile(filepath, callback) {
136
156
  }
137
157
  fs.readFile(filepath, (err, data) => {
138
158
  if (err) {
139
- console.log('Error reading file');
159
+ console.log(err.message);
140
160
  callback();
141
161
  return;
142
162
  }
143
163
 
144
- isLog && console.log(filepath);
164
+ if (isLog) {
165
+ console.log(filepath);
166
+ }
145
167
 
146
168
  const content = data.toString();
147
169
  fileCount += 1;
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "cc-codeline",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "main": "bin.js",
5
5
  "description": "Quickly count your lines of code",
6
6
  "bin": {
7
7
  "codeline": "./bin.js"
8
8
  },
9
- "keywords": ["codeline"],
9
+ "keywords": [
10
+ "codeline",
11
+ "cli"
12
+ ],
10
13
  "author": "",
11
14
  "license": "MIT",
12
15
  "type": "commonjs"
13
- }
16
+ }