@tmsfe/tmskit 0.0.10 → 0.0.13

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/log.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const chalk = require('chalk');
2
+ const moment = require('moment');
2
3
 
3
4
  /**
4
5
  * 本文件提供无依赖的在终端打印彩色文字的方法。
@@ -13,7 +14,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
13
14
  const fail = (message = '') => {
14
15
  const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
15
16
  const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
16
- console.log(`${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
17
+ console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
17
18
  };
18
19
 
19
20
  /**
@@ -24,7 +25,7 @@ const fail = (message = '') => {
24
25
  const succeed = (message = '') => {
25
26
  const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
26
27
  const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
27
- console.log(`${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
28
+ console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
28
29
  };
29
30
 
30
31
 
@@ -34,10 +35,10 @@ const succeed = (message = '') => {
34
35
  * @returns {undefined} 无
35
36
  */
36
37
  const warn = (message) => {
37
- console.log(chalk.yellow(message));
38
+ console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk.yellow(message));
38
39
  };
39
40
 
40
- const info = (...args) => console.log(...args);
41
+ const info = (...args) => console.log(`\n${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
41
42
 
42
43
  module.exports = {
43
44
  fail,
@@ -114,7 +114,7 @@ function pullRepoForGit(dest, branch) {
114
114
  function npmInstall(dir) {
115
115
  return new Promise((resolve, reject) => {
116
116
  shelljs.exec(
117
- 'npx yarn --production --registry http://mirrors.tencent.com/npm/',
117
+ 'npm install --production --registry http://mirrors.tencent.com/npm/',
118
118
  { cwd: dir, silent: true },
119
119
  (code, stdout, stderr) => {
120
120
  if (code !== 0) {
@@ -147,7 +147,6 @@ function createTask(task, startText, endText) {
147
147
  const spinner = ora(startText);
148
148
 
149
149
  spinner.start();
150
- info('\n');
151
150
 
152
151
  const result = await task(...args);
153
152
 
@@ -165,6 +164,22 @@ function createTask(task, startText, endText) {
165
164
  */
166
165
  const camelize = str => str.replace(/-(\w)/g, (a, c) => (c ? c.toUpperCase() : ''));
167
166
 
167
+ const mergeMap = function (obj, src) {
168
+ for (const [k, v] of src) {
169
+ if (obj.has(k)) {
170
+ obj.set(k, obj.get(k) + v);
171
+ } else {
172
+ obj.set(k, v);
173
+ }
174
+ }
175
+
176
+ return obj;
177
+ };
178
+
179
+ const relativeCwdPath = function (file) {
180
+ return path.relative(process.cwd(), file);
181
+ };
182
+
168
183
  module.exports = {
169
184
  resolve,
170
185
  isObject,
@@ -175,4 +190,6 @@ module.exports = {
175
190
  suggestCommands,
176
191
  camelize,
177
192
  npmInstall,
193
+ mergeMap,
194
+ relativeCwdPath,
178
195
  };