Compare commits

...

10 Commits

Author SHA1 Message Date
Luk
420f7f1701 ignore *nogit* and *nosf* 2024-09-22 15:51:53 +08:00
Luk
fbaf230f48 u 2024-06-24 09:49:28 +08:00
Luk
011853758f improve gitignore and seafile-ignore 2024-04-24 14:18:36 +08:00
Luk
69257f2aa4 u 2024-02-23 13:25:53 +08:00
Luk
849bc8997b u 2024-02-05 11:41:10 +08:00
Luk
25a01e9bb0 u 2024-02-05 10:07:49 +08:00
Luk
7c0b1bce15 console.log({_at, ...}) 2024-02-05 09:50:07 +08:00
Luk
98ac10723f updated .gitignore and seafile-ignore.txt using npm/sysconfig/*-ignore-find2merge.sh 2024-01-28 12:18:38 +08:00
Luk Lu
02792a8c6b u 2023-12-30 13:22:10 +08:00
Luk Lu
bc76140224 u 2023-12-14 11:26:26 +08:00
10 changed files with 375 additions and 189 deletions

33
.gitignore vendored
View File

@@ -1,16 +1,42 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# how to include another gitignore?
# https://stackoverflow.com/questions/7005142/can-i-include-other-gitignore-file-in-a-gitignore-file-like-include-in-c-li
# https://github.com/github/gitignore
# https://github.com/SlideWave/gitignore-include?tab=readme-ov-file#examples
# https://gitignore.io
### 目录 ################################################################# ### .gitignore.global.txt ###
# Self defined pattern to ignore
?*.gitignore
?*.gitignore/
?*.gitignore.*
?*.gitignore.*/
*.gitomit
*.gitomit.*
*.gitomit/
*.gitomit.*/
*.nogit
*.nogit.*
*.nogit/
*.nogit.*/
# 保留
!.gitignore
!.gitignore.*
!.gitkeep
# 通用 # 通用
.svn/ .svn/
.deploy_git/ .deploy_git/
.idea/ .idea/
.sass-cache/ .sass-cache/
.wrangler
/test/unit/coverage/ /test/unit/coverage/
/test/e2e/reports/ /test/e2e/reports/
node_modules/ node_modules/
*.aab
*.apk *.apk
*.ipa
*.min.js *.min.js
*.min.css *.min.css
*.min.html *.min.html
@@ -70,7 +96,6 @@ _desktop.ini
/db.json /db.json
# wo # wo
*.gitignore.*
# 服务端 # 服务端
/_archive/* /_archive/*
/_datastore/* /_datastore/*
@@ -84,5 +109,5 @@ _desktop.ini
package-lock.json package-lock.json
pages4loader.json5 pages4loader.json5
# 保留 ### .gitignore.local.txt ###
!.gitkeep

99
cc.js Normal file
View File

@@ -0,0 +1,99 @@
const util = require('util')
function deepStringify (args = []) {
if (globalThis.process?.release?.name === 'node') {
// in nodejs console, object only shows children of depth <= 3 by default. 如果要完整数据,就要进行扩展。
return globalThis.wo?.envar?.logDeep
? util.inspect(args, {
showHidden: false,
depth: null,
colors: typeof globalThis.wo?.envar?.logColor === 'undefined' ? true : globalThis.wo?.envar?.logColor
})
: args // JSON.stringify(args, null, 2)
} else if (globalThis.uni && globalThis.UniApp) {
// 可再分为 web 和 app通过 #ifdef 或 globalThis.window/location 判断
// in browser console, object is expandable by default.
return globalThis.wo?.envar?.logDeep
? util.inspect(args, {
showHidden: false,
depth: null,
colors: typeof globalThis.wo?.envar?.logColor === 'undefined' ? true : globalThis.wo?.envar?.logColor
})
: args
} else if (globalThis.uniCloud) {
return args
} else {
return args
}
}
function fromPath () {
if (globalThis.process?.release?.name === 'node') {
return { _from: new Error().stack?.match?.(/\bat (.*?) /g)?.[2] } // { _from: fromPath.caller.name } // new Error().stack?.split('\n') , .match(/at (.*?) /g)[2]
} else if (globalThis.uni && globalThis.UniApp) {
return { _from: globalThis.getCurrentPages?.()?.pop?.()?.route?.substring?.(6) || 'VueApp' }
} else {
return {}
}
}
function expandArgs (args) {
if (args.length > 1) {
return { _args: args }
} else if (typeof args[0] === 'object') {
return args[0]
} else {
return { _arg: args[0] }
}
}
module.exports =
{
cclog (...args) {
console.log(deepStringify({
_at: new Date().toJSON(),
_type: 'CLOG', // arguments.callee.name, // TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
...fromPath(),
...expandArgs(args)
}))
globalThis.UniApp || console.log(',')
},
ccinfo (...args) {
console.info(deepStringify({
_at: new Date().toJSON(),
_type: 'CINFO',
...fromPath(),
...expandArgs(args)
}))
globalThis.UniApp || console.log(',')
},
ccwarn (...args) {
console.warn(deepStringify({
_at: new Date().toJSON(),
_type: 'CWARN',
...fromPath(),
...expandArgs(args)
}))
globalThis.UniApp || console.log(',')
},
ccerror (...args) {
console.error(deepStringify({
_at: new Date().toJSON(),
_type: 'CERROR',
...fromPath(),
...expandArgs(args)
}))
globalThis.UniApp || console.log(',')
},
ccdebug (...args) {
if (process.env.NODE_ENV !== 'production') {
console.debug(deepStringify({
_at: new Date().toJSON(),
_type: 'CDEBUG',
...fromPath(),
...expandArgs(args)
}))
globalThis.UniApp || console.log(',')
}
}
}

8
coco-app.js Normal file
View File

@@ -0,0 +1,8 @@
module.exports = {
cclog () { },
ccinfo () { },
ccgood () { },
ccwarn () { },
ccerror () { },
ccdebug () { }
}

65
coco-browser.js Normal file
View File

@@ -0,0 +1,65 @@
function routeNow () {
const pageNow = globalThis.getCurrentPages()[globalThis.getCurrentPages().length - 1]
return pageNow?.route || 'VueApp'
}
function deepStringify (args = []) {
return JSON.stringify(args, null, 2) // used in web browser console, to avoid clicking to expand by hand.
}
// function prettyPrint (title, text, color) {
// console.log(
// `%c ${title} %c ${text} %c`,
// `background:${color};border:1px solid ${color}; padding: 1px; border-radius: 2px 0 0 2px; color: #fff;`,
// `border:1px solid ${color}; padding: 1px; border-radius: 0 2px 2px 0; color: ${color};`,
// 'background:transparent'
// )
// }
module.exports =
{
cclog (...args) {
console.log(
`%c ${new Date().toJSON()} [LOG] ${routeNow()}`,
'background: #808080; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
deepStringify(args)
)
},
ccinfo (...args) {
console.info(
`%c ${new Date().toJSON()} [INFO] ${routeNow()}`,
'background: #0000ff; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
deepStringify(args)
)
},
ccgood (...args) {
console.info(
`%c ${new Date().toJSON()} [GOOD] ${routeNow()}`,
'background: #2ecc71; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
deepStringify(args)
)
},
ccwarn (...args) {
console.warn(
`%c ${new Date().toJSON()} [WARN] ${routeNow()}`,
'background: #f39c12; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
deepStringify(args)
)
},
ccerror (...args) {
console.error(
`%c ${new Date().toJSON()} [ERROR] ${routeNow()}`,
'background: #c0392b; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
deepStringify(args)
)
},
ccdebug (...args) {
if (process.env.NODE_ENV !== 'production') {
console.debug(
`%c ${new Date().toJSON()} [DEBUG] ${routeNow()}`,
'background: purple; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
deepStringify(args)
)
}
},
}

53
coco-nodejs.js Normal file
View File

@@ -0,0 +1,53 @@
// colors only works in nodejs cli
// consola works in nodejs and browser
// chalk 和 colors 用法类似。
const util = require('util')
const colors = require('colors')
function deepInspect (args = [], colors = false) {
return args.map((arg) => util.inspect(arg, { showHidden: false, depth: null, colors })) // 如果用这个方案,在下面的方法里就要用 ...deepInspect(args) 否则会显示成一整字符串
}
module.exports =
{
// 后台服务器命令行。注意如果输出重定向到文件里,会有 ESC[34m2023-10-07T12:32:00.915ZESC[39m 这样的特殊标识。
// 在 pm2 里,为了防止特殊标志,可用 --no-color
cclog (...args) {
console.log(colors.bgWhite(new Date().toJSON()), colors.bgBlue('[LOG]'), ...deepInspect(args, true))
},
ccinfo (...args) {
console.info(colors.bgWhite(new Date().toJSON()), colors.bgBlue('[INFO]'), ...deepInspect(args, true))
},
ccgood (...args) {
console.info(colors.bgWhite(new Date().toJSON()), colors.bgGreen('[GOOD]'), ...deepInspect(args, true))
},
ccwarn (...args) {
// console.warn will appear in pm2's error log
console.warn(colors.bgWhite(new Date().toJSON()), colors.bgYellow('[WARN]'), ...deepInspect(args, true))
},
ccerror (...args) {
// console.error will appear in pm2's error log
console.error(colors.bgWhite(new Date().toJSON()), colors.bgRed('[ERROR]'), ...deepInspect(args, true))
},
ccdebug (...args) {
if ('production' !== process.env.NODE_ENV) {
// 在server的测试环境下. 注意在 uniCloud 环境下,`process.env.NODE_ENV` 不存在. 如要应用本方法,需要手动设置 `process.env.NODE_ENV`
console.log(colors.rainbow(new Date().toJSON()), colors.rainbow('[DEBUG]'), ...deepInspect(args, true))
}
},
ccinput (headers, path, indata) {
console.log(colors.bgWhite(new Date().toJSON()), colors.bgCyan('[Headers]'), colors.cyan(headers))
console.info(colors.bgWhite(new Date().toJSON()), colors.bgBrightBlue(`[INDATA] ${path}`), colors.brightBlue(util.inspect(indata, { showHidden: false, depth: null, colors: false }))) // 已经被 colors.xxx 进行上色了
},
ccoutput (path, outdata) {
console.log(colors.bgWhite(new Date().toJSON()), colors.bgGreen(`[OUTDATA] ${path}`), colors.green(util.inspect(outdata, { showHidden: false, depth: null, colors: false }))) // 已经被 colors.xxx 进行上色了
},
ccexcept (path, error) {
outdata = { _state: 'WOBASE_EXCEPTION', error }
console.error(colors.bgWhite(new Date().toJSON()), colors.bgRed(`[EXCEPTION] ${path}`), colors.red(util.inspect(outdata, { showHidden: false, depth: null, colors: true })))
},
ccunknown (path) {
console.warn(colors.bgWhite(new Date().toJSON()), colors.bgYellow(`[UNKNOWN] ${path}`), colors.yellow({ _state: 'WOBASE_API_UNKNOWN', response: 401 }))
}
}

8
coco-none.js Normal file
View File

@@ -0,0 +1,8 @@
module.exports = {
cclog () { },
ccinfo () { },
ccgood () { },
ccwarn () { },
ccerror () { },
ccdebug () { }
}

31
coco-unicloud.js Normal file
View File

@@ -0,0 +1,31 @@
function deepStringify (args = []) {
return JSON.stringify(args, null, 2) // used in web browser console, to avoid clicking to expand by hand.
}
module.exports = {
// HBuilder 内置环境的 云空间 console 不支持颜色。为了检查是否支持颜色,测试 uniCloud 是否存在不存在说明在自己的server环境里
// 或 require('supports-color'),相应的返回不同的函数。
cclog (...args) {
console.log(new Date().toJSON(), '[LOG]', deepStringify(args))
},
ccinfo (...args) {
console.info(new Date().toJSON(), '[INFO]', deepStringify(args))
},
ccgood (...args) {
console.info(new Date().toJSON(), '[GOOD]', deepStringify(args))
},
ccwarn (...args) {
// console.warn will appear in pm2's error log
console.warn(new Date().toJSON(), '[WARN]', deepStringify(args))
},
ccerror (...args) {
// console.error will appear in pm2's error log
console.error(new Date().toJSON(), '[ERROR]', deepStringify(args))
},
ccdebug (...args) {
if ('production' !== process.env.NODE_ENV) {
// 在server的测试环境下. 注意在 uniCloud 环境下,`process.env.NODE_ENV` 不存在. 如要应用本方法,需要手动设置 `process.env.NODE_ENV`
console.log(new Date().toJSON(), '[DEBUG]', deepStringify(args))
}
},
}

139
coco.js
View File

@@ -2,135 +2,14 @@
// consola works in nodejs and browser // consola works in nodejs and browser
// chalk 和 colors 用法类似。 // chalk 和 colors 用法类似。
const util = require('util') // globalThis.uni // 在 web/app 里都为对象
const colors = require('colors') // globalThis.UniApp // 在 web 里返回一个函数,在 app 里返回 undefined
// globalThis.getApp?.()?.constructor?.name === 'Vue' // 在 web 里 true, 在 app 里 false
function routeNow () { // typeof(globalThis.getApp)==='function' // 在 web/app 里都为 true
const pageNow = globalThis.getCurrentPages()[globalThis.getCurrentPages().length - 1]
return pageNow?.route || 'VueApp'
}
function deepInspect (args = [], colors = false) {
return args.map((arg) => util.inspect(arg, { showHidden: false, depth: null, colors }))
}
module.exports = module.exports =
globalThis.uni && globalThis.UniApp // && globalThis.getApp?.()?.constructor?.name === 'Vue' globalThis.process?.release?.name === 'node' ? require('./coco-nodejs.js')
? { : globalThis.uniCloud ? require('./coco-unicloud.js')
// 客户端 uniapp : globalThis.window && globalThis.location ? require('./coco-browser.js')
cclog (...args) { : globalThis.uni && globalThis.getApp ? require('./coco-app.js')
console.log( : require('./coco-none.js')
`%c ${new Date().toJSON()} [LOG] ${routeNow()}`,
'background: #808080; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
...deepInspect(args)
)
},
ccinfo (...args) {
console.info(
`%c ${new Date().toJSON()} [INFO] ${routeNow()}`,
'background: #0000ff; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
...deepInspect(args)
)
},
ccgood (...args) {
console.info(
`%c ${new Date().toJSON()} [GOOD] ${routeNow()}`,
'background: #2ecc71; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
...deepInspect(args)
)
},
ccwarn (...args) {
console.warn(
`%c ${new Date().toJSON()} [WARN] ${routeNow()}`,
'background: #f39c12; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
...deepInspect(args)
)
},
ccerror (...args) {
console.error(
`%c ${new Date().toJSON()} [ERROR] ${routeNow()}`,
'background: #c0392b; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
...deepInspect(args)
)
},
ccdebug (...args) {
if (process.env.NODE_ENV !== 'production') {
console.debug(
`%c ${new Date().toJSON()} [DEBUG] ${routeNow()}`,
'background: #ff0000; border-radius: 0.5em;color: white; font-weight: bold; padding: 2px 0.5em;',
...deepInspect(args)
)
}
},
}
: typeof uniCloud !== 'undefined'
? {
// uniCloud 云空间
// HBuilder 内置环境的 console 不支持颜色。为了检查是否支持颜色,测试 uniCloud 是否存在不存在说明在自己的server环境里
// 或 require('supports-color'),相应的返回不同的函数。
cclog (...args) {
console.log(new Date().toJSON(), '[LOG]', ...deepInspect(args))
},
ccinfo (...args) {
console.info(new Date().toJSON(), '[INFO]', ...deepInspect(args))
},
ccgood (...args) {
console.info(new Date().toJSON(), '[GOOD]', ...deepInspect(args))
},
ccwarn (...args) {
// console.warn will appear in pm2's error log
console.warn(new Date().toJSON(), '[WARN]', ...deepInspect(args))
},
ccerror (...args) {
// console.error will appear in pm2's error log
console.error(new Date().toJSON(), '[ERROR]', ...deepInspect(args))
},
ccdebug (...args) {
if ('production' !== process.env.NODE_ENV) {
// 在server的测试环境下. 注意在 uniCloud 环境下,`process.env.NODE_ENV` 不存在. 如要应用本方法,需要手动设置 `process.env.NODE_ENV`
console.log(new Date().toJSON(), '[DEBUG]', ...deepInspect(args))
}
},
}
: {
// 后台服务器命令行。注意如果输出重定向到文件里,会有 ESC[34m2023-10-07T12:32:00.915ZESC[39m 这样的特殊标识。
// 在 pm2 里,为了防止特殊标志,可用 --no-color
cclog (...args) {
console.log(colors.bgWhite(new Date().toJSON()), colors.bgBlue('[LOG]'), ...deepInspect(args, true))
},
ccinfo (...args) {
console.info(colors.bgWhite(new Date().toJSON()), colors.bgBlue('[INFO]'), ...deepInspect(args, true))
},
ccgood (...args) {
console.info(colors.bgWhite(new Date().toJSON()), colors.bgGreen('[GOOD]'), ...deepInspect(args, true))
},
ccwarn (...args) {
// console.warn will appear in pm2's error log
console.warn(colors.bgWhite(new Date().toJSON()), colors.bgYellow('[WARN]'), ...deepInspect(args, true))
},
ccerror (...args) {
// console.error will appear in pm2's error log
console.error(colors.bgWhite(new Date().toJSON()), colors.bgRed('[ERROR]'), ...deepInspect(args, true))
},
ccdebug (...args) {
if ('production' !== process.env.NODE_ENV) {
// 在server的测试环境下. 注意在 uniCloud 环境下,`process.env.NODE_ENV` 不存在. 如要应用本方法,需要手动设置 `process.env.NODE_ENV`
console.log(colors.rainbow(new Date().toJSON()), colors.rainbow('[DEBUG]'), ...deepInspect(args, true))
}
},
ccinput (headers, path, indata) {
console.log(colors.bgWhite(new Date().toJSON()), colors.bgCyan('[LOG] (Request-Headers)'), colors.cyan(headers))
console.info(colors.bgWhite(new Date().toJSON()), colors.bgBlue(`[INFO] (INDATA) ${path}`), colors.blue(util.inspect(indata, { showHidden: false, depth: null, colors: false }))) // 已经被 colors.xxx 进行上色了
},
ccoutput (path, outdata) {
console.log(colors.bgWhite(new Date().toJSON()), colors.bgGreen(`[GOOD] (OUTDATA) ${path}`), colors.green(util.inspect(outdata, { showHidden: false, depth: null, colors: false }))) // 已经被 colors.xxx 进行上色了
},
ccexcept (path, error) {
outdata = { _state: 'WOBASE_EXCEPTION', error }
console.error(colors.bgWhite(new Date().toJSON()), colors.bgRed(`[ERROR] (OUT) ${path}`), colors.red(util.inspect(outdata, { showHidden: false, depth: null, colors: true })))
},
ccunknown (path) {
console.warn(colors.bgWhite(new Date().toJSON()), colors.bgYellow(`[WARN] (OUT) ${path}`), colors.yellow({ _state: 'WOBASE_API_UNKNOWN', response: 401 }))
}
}

View File

@@ -2,7 +2,7 @@
"name": "wo-core-coco", "name": "wo-core-coco",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "coco.js", "main": "cc.js",
"scripts": {}, "scripts": {},
"author": "", "author": "",
"license": "ISC", "license": "ISC",

View File

@@ -6,11 +6,21 @@
# 文件在服务器端的后续更改会被同步到客户端,如果客户端也同时修改了这些文件,系统会生成冲突文件。 # 文件在服务器端的后续更改会被同步到客户端,如果客户端也同时修改了这些文件,系统会生成冲突文件。
# seafile-ignore.txt 只能忽略还没有被同步的文件。对于已经被同步的文件,如果后来把它添加到 seafile-ignore.txt 中,系统只会忽略后续更改,已经上传的版本不会受影响。 # seafile-ignore.txt 只能忽略还没有被同步的文件。对于已经被同步的文件,如果后来把它添加到 seafile-ignore.txt 中,系统只会忽略后续更改,已经上传的版本不会受影响。
### seafile-ignore.global.txt ###
# 自定义的后缀名,凡有 sfignore 后缀的都不进行同步 # 自定义的后缀名,凡有 sfignore 后缀的都不进行同步
*.sfignore *.sfignore
*.sfignore.*
*.sfignore/ *.sfignore/
*.sfignore.*
*.sfignore.*/ *.sfignore.*/
*.sfomit
*.sfomit.*
*.sfomit/
*.sfomit.*/
*.nosf
*.nosf.*
*.nosf/
*.nosf.*/
.DS_Store .DS_Store
*/.DS_Store */.DS_Store
@@ -41,14 +51,22 @@ package-lock.json
pages4loader.json5 pages4loader.json5
.svn/
*/.svn/
.deploy_git/ .deploy_git/
*/.deploy_git/ */.deploy_git/
# HBuilder 目录
unpackage/ unpackage/
*/unpackage/ */unpackage/
Icon Icon
OneDrive/Icon OneDrive/Icon
# wrangler project
.dev.vars*
*/.dev.vars*
.wrangler/
*/.wrangler/
### seafile-ignore.local.txt ###