@tmsfe/tmskit 0.0.15 → 0.0.18

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/src/utils/io.js CHANGED
@@ -97,6 +97,25 @@ const fileInDir = (dir, file) => {
97
97
  };
98
98
 
99
99
 
100
+ function findAllFilesOfDir(dir) {
101
+ const list = [];
102
+ function listFile(dir) {
103
+ const arr = fs.readdirSync(dir);
104
+ arr.forEach((item) => {
105
+ const fullPath = path.join(dir, item);
106
+ const stats = fs.statSync(fullPath);
107
+ if (stats.isDirectory()) {
108
+ listFile(fullPath);
109
+ } else {
110
+ list.push(fullPath);
111
+ }
112
+ });
113
+ return list;
114
+ }
115
+ listFile(dir);
116
+ return list;
117
+ }
118
+
100
119
  module.exports = {
101
120
  isDirEmpty,
102
121
  copyFile,
@@ -105,4 +124,5 @@ module.exports = {
105
124
  ext,
106
125
  fileInDir,
107
126
  isFile,
127
+ findAllFilesOfDir,
108
128
  };
package/src/utils/log.js CHANGED
@@ -14,7 +14,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
14
14
  const fail = (message = '') => {
15
15
  const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
16
16
  const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
17
- console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
17
+ console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
18
18
  };
19
19
 
20
20
  /**
@@ -25,7 +25,7 @@ const fail = (message = '') => {
25
25
  const succeed = (message = '') => {
26
26
  const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
27
27
  const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
28
- console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
28
+ console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
29
29
  };
30
30
 
31
31
 
@@ -35,10 +35,10 @@ const succeed = (message = '') => {
35
35
  * @returns {undefined} 无
36
36
  */
37
37
  const warn = (message) => {
38
- console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk.yellow(message));
38
+ console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk.yellow(message));
39
39
  };
40
40
 
41
- const info = (...args) => console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
41
+ const info = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
42
42
 
43
43
  module.exports = {
44
44
  fail,
@@ -144,13 +144,13 @@ function createTask(task, startText, endText) {
144
144
  return async (...args) => {
145
145
  const start = Date.now();
146
146
 
147
- const spinner = ora(startText);
148
-
147
+ const spinner = ora();
148
+ info(startText);
149
149
  spinner.start();
150
150
 
151
151
  const result = await task(...args);
152
152
 
153
- endText && spinner.succeed(`${endText}, ${cost(start)}ms`);
153
+ endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
154
154
  spinner.stop();
155
155
 
156
156
  return result;
@@ -180,6 +180,22 @@ const relativeCwdPath = function (file) {
180
180
  return path.relative(process.cwd(), file);
181
181
  };
182
182
 
183
+ /**
184
+ * 从一个对象中,检索出去几个字段
185
+ * @param {*} obj
186
+ * @param {*} name
187
+ * @returns
188
+ */
189
+ const filterField = (obj, filterNames = []) => {
190
+ const newObj = { ...obj };
191
+ filterNames.forEach((name) => {
192
+ if (newObj[name]) {
193
+ delete newObj[name];
194
+ }
195
+ });
196
+ return newObj;
197
+ };
198
+
183
199
  module.exports = {
184
200
  resolve,
185
201
  isObject,
@@ -192,4 +208,5 @@ module.exports = {
192
208
  npmInstall,
193
209
  mergeMap,
194
210
  relativeCwdPath,
211
+ filterField,
195
212
  };