standardize: read user input with [key] instead of <key>; pm2 --name=* -e * -o *
This commit is contained in:
		
							parent
							
								
									61d16bb929
								
							
						
					
					
						commit
						8b32a12003
					
				
							
								
								
									
										47
									
								
								coco.js
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								coco.js
									
									
									
									
									
								
							@ -1,5 +1,6 @@
 | 
				
			|||||||
// colors only works in nodejs cli
 | 
					// colors only works in nodejs cli
 | 
				
			||||||
// consola works in nodejs and browser
 | 
					// consola works in nodejs and browser
 | 
				
			||||||
 | 
					// chalk 和 colors 用法类似。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const colors = require('colors')
 | 
					const colors = require('colors')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -14,35 +15,35 @@ module.exports =
 | 
				
			|||||||
        // 客户端 uniapp
 | 
					        // 客户端 uniapp
 | 
				
			||||||
        cclog (...args) {
 | 
					        cclog (...args) {
 | 
				
			||||||
          console.log(
 | 
					          console.log(
 | 
				
			||||||
            `%c ${new Date().toJSON()} ${routeNow()}`,
 | 
					            `%c ${new Date().toJSON()} [LG] ${routeNow()}`,
 | 
				
			||||||
            'background: #808080; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
 | 
					            'background: #808080; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
 | 
				
			||||||
            ...args
 | 
					            ...args
 | 
				
			||||||
          )
 | 
					          )
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccinfo (...args) {
 | 
					        ccinfo (...args) {
 | 
				
			||||||
          console.info(
 | 
					          console.info(
 | 
				
			||||||
            `%cℹ️ ${new Date().toJSON()} ${routeNow()}`,
 | 
					            `%c ${new Date().toJSON()} [IF] ${routeNow()}`,
 | 
				
			||||||
            'background: #0000ff; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
 | 
					            'background: #0000ff; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
 | 
				
			||||||
            ...args
 | 
					            ...args
 | 
				
			||||||
          )
 | 
					          )
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccgood (...args) {
 | 
					        ccgood (...args) {
 | 
				
			||||||
          console.info(
 | 
					          console.info(
 | 
				
			||||||
            `%c✅ ${new Date().toJSON()} ${routeNow()}`,
 | 
					            `%c ${new Date().toJSON()} [OK] ${routeNow()}`,
 | 
				
			||||||
            'background: #2ecc71; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
 | 
					            'background: #2ecc71; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
 | 
				
			||||||
            ...args
 | 
					            ...args
 | 
				
			||||||
          )
 | 
					          )
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccwarn (...args) {
 | 
					        ccwarn (...args) {
 | 
				
			||||||
          console.warn(
 | 
					          console.warn(
 | 
				
			||||||
            `%c❗️ ${new Date().toJSON()} ${routeNow()}`,
 | 
					            `%c ${new Date().toJSON()} [WA] ${routeNow()}`,
 | 
				
			||||||
            'background: #f39c12; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
 | 
					            'background: #f39c12; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
 | 
				
			||||||
            ...args
 | 
					            ...args
 | 
				
			||||||
          )
 | 
					          )
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccerror (...args) {
 | 
					        ccerror (...args) {
 | 
				
			||||||
          console.error(
 | 
					          console.error(
 | 
				
			||||||
            `%c❌ ${new Date().toJSON()} ${routeNow()}`,
 | 
					            `%c ${new Date().toJSON()} [ER] ${routeNow()}`,
 | 
				
			||||||
            'background: #c0392b; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
 | 
					            'background: #c0392b; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
 | 
				
			||||||
            ...args
 | 
					            ...args
 | 
				
			||||||
          )
 | 
					          )
 | 
				
			||||||
@ -50,64 +51,66 @@ module.exports =
 | 
				
			|||||||
        ccdebug (...args) {
 | 
					        ccdebug (...args) {
 | 
				
			||||||
          if (process.env.NODE_ENV !== 'production') {
 | 
					          if (process.env.NODE_ENV !== 'production') {
 | 
				
			||||||
            console.debug(
 | 
					            console.debug(
 | 
				
			||||||
              `%c ${new Date().toJSON()} ${routeNow()}`,
 | 
					              `%c ${new Date().toJSON()} [DB] ${routeNow()}`,
 | 
				
			||||||
              'background: #ff0000; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
 | 
					              'background: #ff0000; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
 | 
				
			||||||
              ...args
 | 
					              ...args
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    : typeof uniCloud === 'undefined'
 | 
					    : typeof uniCloud !== 'undefined'
 | 
				
			||||||
    ? {
 | 
					    ? {
 | 
				
			||||||
        // 后台服务器命令行
 | 
					        // uniCloud 云空间
 | 
				
			||||||
 | 
					        // HBuilder 内置环境的 console 不支持颜色。为了检查是否支持颜色,测试 uniCloud 是否存在(不存在说明在自己的server环境里),
 | 
				
			||||||
 | 
					        // 或 require('supports-color'),相应的返回不同的函数。
 | 
				
			||||||
        cclog (...args) {
 | 
					        cclog (...args) {
 | 
				
			||||||
          console.log(colors.blue(new Date().toJSON()), ...args)
 | 
					          console.log(new Date().toJSON(), '[LG]', ...args)
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccinfo (...args) {
 | 
					        ccinfo (...args) {
 | 
				
			||||||
          console.info('ℹ️', colors.blue(new Date().toJSON()), ...args)
 | 
					          console.info(new Date().toJSON(), '[IF]', ...args)
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccgood (...args) {
 | 
					        ccgood (...args) {
 | 
				
			||||||
          console.info('✅', colors.green(new Date().toJSON()), ...args)
 | 
					          console.info(new Date().toJSON(), '[OK]', ...args)
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccwarn (...args) {
 | 
					        ccwarn (...args) {
 | 
				
			||||||
          // console.warn will appear in pm2's error log
 | 
					          // console.warn will appear in pm2's error log
 | 
				
			||||||
          console.warn('❗️', colors.yellow(new Date().toJSON()), ...args)
 | 
					          console.warn(new Date().toJSON(), '[WA]', ...args)
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccerror (...args) {
 | 
					        ccerror (...args) {
 | 
				
			||||||
          // console.error will appear in pm2's error log
 | 
					          // console.error will appear in pm2's error log
 | 
				
			||||||
          console.error('❌', colors.red(new Date().toJSON()), ...args)
 | 
					          console.error(new Date().toJSON(), '[ER]', ...args)
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccdebug (...args) {
 | 
					        ccdebug (...args) {
 | 
				
			||||||
          if ('production' !== process.env.NODE_ENV) {
 | 
					          if ('production' !== process.env.NODE_ENV) {
 | 
				
			||||||
            // 在server的测试环境下. 注意在 uniCloud 环境下,`process.env.NODE_ENV` 不存在. 如要应用本方法,需要手动设置 `process.env.NODE_ENV`
 | 
					            // 在server的测试环境下. 注意在 uniCloud 环境下,`process.env.NODE_ENV` 不存在. 如要应用本方法,需要手动设置 `process.env.NODE_ENV`
 | 
				
			||||||
            console.log(colors.rainbow(new Date().toJSON()), ...args)
 | 
					            console.log(new Date().toJSON(), '[DB]', ...args)
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    : {
 | 
					    : {
 | 
				
			||||||
        // HBuilder 内置环境的 console 不支持颜色。为了检查是否支持颜色,测试 uniCloud 是否存在(不存在说明在自己的server环境里),或 require('supports-color'),相应的返回不同的 ccXXX 函数。
 | 
					        // 后台服务器命令行。注意如果输出重定向到文件里,会有 ESC[34m2023-10-07T12:32:00.915ZESC[39m 这样的特殊标识。
 | 
				
			||||||
        // uniCloud 云空间
 | 
					        // 在 pm2 里,为了防止特殊标志,可用 --no-color
 | 
				
			||||||
        cclog (...args) {
 | 
					        cclog (...args) {
 | 
				
			||||||
          console.log(new Date().toJSON(), ...args)
 | 
					          console.log(colors.blue(new Date().toJSON()), '[LG]', ...args)
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccinfo (...args) {
 | 
					        ccinfo (...args) {
 | 
				
			||||||
          console.info('ℹ️', new Date().toJSON(), ...args)
 | 
					          console.info(colors.blue(new Date().toJSON()), '[IF]', ...args)
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccgood (...args) {
 | 
					        ccgood (...args) {
 | 
				
			||||||
          console.info('✅', new Date().toJSON(), ...args)
 | 
					          console.info(colors.green(new Date().toJSON()), '[OK]', ...args)
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccwarn (...args) {
 | 
					        ccwarn (...args) {
 | 
				
			||||||
          // console.warn will appear in pm2's error log
 | 
					          // console.warn will appear in pm2's error log
 | 
				
			||||||
          console.warn('❗️', new Date().toJSON(), ...args)
 | 
					          console.warn(colors.yellow(new Date().toJSON()), '[WA]', ...args)
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccerror (...args) {
 | 
					        ccerror (...args) {
 | 
				
			||||||
          // console.error will appear in pm2's error log
 | 
					          // console.error will appear in pm2's error log
 | 
				
			||||||
          console.error('❌', new Date().toJSON(), ...args)
 | 
					          console.error(colors.red(new Date().toJSON()), '[ER]', ...args)
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        ccdebug (...args) {
 | 
					        ccdebug (...args) {
 | 
				
			||||||
          if ('production' !== process.env.NODE_ENV) {
 | 
					          if ('production' !== process.env.NODE_ENV) {
 | 
				
			||||||
            // 在server的测试环境下. 注意在 uniCloud 环境下,`process.env.NODE_ENV` 不存在. 如要应用本方法,需要手动设置 `process.env.NODE_ENV`
 | 
					            // 在server的测试环境下. 注意在 uniCloud 环境下,`process.env.NODE_ENV` 不存在. 如要应用本方法,需要手动设置 `process.env.NODE_ENV`
 | 
				
			||||||
            console.log(new Date().toJSON(), ...args)
 | 
					            console.log(colors.rainbow(new Date().toJSON()), '[DB]', ...args)
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user