feat:Optimize console log
This commit is contained in:
parent
8f0486329e
commit
a415365159
@ -29,9 +29,12 @@ async function doMerge(jsFile: string) {
|
|||||||
|
|
||||||
|
|
||||||
export async function mergeMap(mapFile: string) {
|
export async function mergeMap(mapFile: string) {
|
||||||
|
const buildMap = mapFile.replace(/bundle\//, 'build/')
|
||||||
|
if (fs.existsSync(buildMap)) {
|
||||||
const mergedMap = createMergedSourceMapFromFiles([
|
const mergedMap = createMergedSourceMapFromFiles([
|
||||||
mapFile.replace(/bundle\//, 'build/'),
|
buildMap,
|
||||||
mapFile,
|
mapFile,
|
||||||
], true);
|
], true);
|
||||||
await fs.promises.writeFile(mapFile, mergedMap);
|
await fs.promises.writeFile(mapFile, mergedMap);
|
||||||
}
|
}
|
||||||
|
}
|
@ -83,7 +83,10 @@ export default async function dev() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const sourceMap = mergeMap(`${jsFile}.map`);
|
const sourceMap = `${jsFile}.map`
|
||||||
|
if (fs.existsSync(sourceMap)) {
|
||||||
|
mergeMap(sourceMap);
|
||||||
|
}
|
||||||
server.connections.forEach((e: any) => {
|
server.connections.forEach((e: any) => {
|
||||||
e.sendText(
|
e.sendText(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
@ -8,19 +8,20 @@ export async function createServer() {
|
|||||||
let contextId: string = "0"
|
let contextId: string = "0"
|
||||||
let clientConnection: any = null
|
let clientConnection: any = null
|
||||||
let debuggerConnection: any = null
|
let debuggerConnection: any = null
|
||||||
|
let deviceId = 0
|
||||||
const server = (ws as any).createServer((connection: any) => {
|
const server = (ws as any).createServer((connection: any) => {
|
||||||
|
let thisDeviceId = deviceId++
|
||||||
console.log('Connected', connection.headers.host)
|
console.log('Connected', connection.headers.host)
|
||||||
if (connection.headers.host.startsWith("localhost")) {
|
if (connection.headers.host.startsWith("localhost")) {
|
||||||
console.log(`Debugger ${connection.key} attached to dev kit`.green)
|
console.log(`Debugger ${thisDeviceId} attached to dev kit`.green)
|
||||||
debuggerConnection = connection
|
debuggerConnection = connection
|
||||||
clientConnection.sendText(JSON.stringify({
|
clientConnection.sendText(JSON.stringify({
|
||||||
cmd: 'SWITCH_TO_DEBUG',
|
cmd: 'SWITCH_TO_DEBUG',
|
||||||
contextId: contextId
|
contextId: contextId
|
||||||
}), () => { })
|
}), () => { })
|
||||||
} else {
|
} else {
|
||||||
console.log(`Client ${connection.key} attached to dev kit`.green)
|
console.log(`Client ${thisDeviceId} attached to dev kit`.green)
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.on('text', function (result: string) {
|
connection.on('text', function (result: string) {
|
||||||
let resultObject = JSON.parse(result)
|
let resultObject = JSON.parse(result)
|
||||||
switch (resultObject.cmd) {
|
switch (resultObject.cmd) {
|
||||||
@ -49,12 +50,19 @@ export async function createServer() {
|
|||||||
console.log(resultObject.data.exception.red);
|
console.log(resultObject.data.exception.red);
|
||||||
break;
|
break;
|
||||||
case 'LOG':
|
case 'LOG':
|
||||||
|
const date = new Date
|
||||||
|
const format = function (num: number) {
|
||||||
|
return (Array(2).join("0") + num).slice(-2);
|
||||||
|
};
|
||||||
|
const timeStr = `${format(date.getHours())}:${format(date.getMinutes())}:${format(date.getSeconds())}.${(Array(3).join("0") + date.getMilliseconds()).slice(-3)}`
|
||||||
|
let logContent = resultObject.data.message as string
|
||||||
|
|
||||||
if (resultObject.data.type == 'DEFAULT') {
|
if (resultObject.data.type == 'DEFAULT') {
|
||||||
console.log(`>>>>>>${(resultObject.data.message as string).green}>>>>>>`);
|
console.log(`${timeStr} Device ${thisDeviceId} ${"[I]".green} ${logContent.green}`.bgBlue);
|
||||||
} else if (resultObject.data.type == 'ERROR') {
|
} else if (resultObject.data.type == 'ERROR') {
|
||||||
console.log(`>>>>>>${(resultObject.data.message as string).red}>>>>>>`);
|
console.log(`${timeStr} Device ${thisDeviceId} ${"[E]".green} ${logContent.green}`.bgRed);
|
||||||
} else if (resultObject.data.type == 'WARN') {
|
} else if (resultObject.data.type == 'WARN') {
|
||||||
console.log(`>>>>>>${(resultObject.data.message as string).yellow}>>>>>>`);
|
console.log(`${timeStr.black} ${("Device " + thisDeviceId).black} ${"[W]".green} ${logContent.green}`.bgYellow);
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,9 @@ class CounterVM extends ViewModel<CountModel, CounterView> {
|
|||||||
}
|
}
|
||||||
onBind(s: CountModel, vh: CounterView) {
|
onBind(s: CountModel, vh: CounterView) {
|
||||||
vh.number.text = `${s.count}`
|
vh.number.text = `${s.count}`
|
||||||
|
log("onBind\nseee")
|
||||||
|
logw("onBind")
|
||||||
|
loge("onBind")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user