Skip to content

Commit 7c85d4e

Browse files
committed
fix: modify uploadMaterials.mjs
1 parent 7254412 commit 7c85d4e

5 files changed

Lines changed: 160 additions & 68 deletions

File tree

bash.exe.stackdump

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Stack trace:
2+
Frame Function Args
3+
000005FF320 00210062B0E (00210298702, 00210275E3E, 0000000005A, 000005FAE80)
4+
000005FF320 0021004846A (00000000000, 00000000000, 7FFD00000000, 00000001000)
5+
000005FF320 002100484A2 (00000000000, 000000005AF, 0000000005A, 00000000000)
6+
000005FF320 002100DA818 (00000000000, 00200000000, 002102759F2, 000005FBFCC)
7+
000005FF320 002101334F7 (00000000000, 0021022B1A0, 0021022B190, 000005FDDE0)
8+
000005FF320 002100488B4 (00210317960, 000005FDDE0, 002100DB7A0, 00000000000)
9+
000005FF320 0021004A01F (0007FFE0384, 00000000000, 00000000000, 00000000000)
10+
000005FF320 002100DB858 (00000000000, 00000000000, 00000000000, 00000000000)
11+
000005FF5C0 7FFD03635D37 (00210040000, 00000000001, 00000000000, 000005FF508)
12+
000005FF5C0 7FFD036385E9 (7FFD03638900, 000006E4201, 7FFD00000001, 00000000001)
13+
000005FF5C0 7FFD03638854 (000006E4250, 000005FF5C0, 000006E4A80, 0000023F000)
14+
000005FF5C0 7FFD0363887E (00000000010, 00000000000, 7FFD03730E50, 000005FF654)
15+
00000000000 7FFD036E6116 (00000000000, 00000000000, 00000000001, 00000000000)
16+
00000000000 7FFD036883FB (7FFD03610000, 00000000000, 00000240000, 00000000000)
17+
00000000000 7FFD03688283 (00000000000, 00000000000, 00000000000, 00000000000)
18+
00000000000 7FFD0368822E (00000000000, 00000000000, 00000000000, 00000000000)
19+
End of stack trace

designer-demo/scripts/logger.mjs

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,88 @@
1+
const log = (() => {
2+
return (...args) => {
3+
process.stdout.write(args.map(arg =>
4+
typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg)
5+
).join(' ') + '\n');
6+
};
7+
})();
8+
9+
const warn = (() => {
10+
return (...args) => {
11+
process.stderr.write(args.map(arg =>
12+
typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg)
13+
).join(' ') + '\n');
14+
};
15+
})();
16+
117
class Logger {
218
constructor(command = 'default') {
3-
this.command = command
4-
this.hasColors = this.checkColorSupport()
19+
this.command = command;
20+
this.colors = null;
21+
this.hasColors = false;
22+
this.initColors();
523
}
624

7-
checkColorSupport() {
25+
async initColors() {
826
try {
9-
require('colors')
10-
return true
11-
} catch (e) {
12-
console.warn('colors package not found, using basic logging')
13-
return false
27+
const colorsModule = await import('colors');
28+
this.colors = colorsModule.default || colorsModule;
29+
this.hasColors = true;
30+
} catch (err) {
31+
warn('colors package not found, using basic logging');
32+
this.hasColors = false;
1433
}
1534
}
1635

17-
output(type, ...args) { // 支持多个参数
18-
const time = new Date().toLocaleTimeString()
19-
const prefix = `[${this.command}] [${time}]`
20-
21-
// 将所有参数合并为一个字符串
22-
const message = args.map(arg => {
36+
output(type, ...args) {
37+
const time = new Date().toLocaleTimeString();
38+
const prefix = `[${this.command}] [${time}]`;
39+
const message = args.map((arg) => {
2340
if (typeof arg === 'object') {
24-
return JSON.stringify(arg, null, 2)
41+
return JSON.stringify(arg, null, 2);
2542
}
26-
return String(arg)
27-
}).join(' ')
43+
return String(arg);
44+
}).join(' ');
45+
46+
const outputFn = type === 'error' || type === 'warn' ? warn : log;
2847

29-
if (this.hasColors) {
30-
const colors = require('colors')
48+
if (this.hasColors && this.colors) {
3149
const colorMap = {
32-
info: colors.cyan,
33-
warn: colors.yellow,
34-
error: colors.red,
35-
success: colors.green
36-
}
50+
info: this.colors.cyan,
51+
warn: this.colors.yellow,
52+
error: this.colors.red,
53+
success: this.colors.green,
54+
};
55+
const coloredType = colorMap[type]
56+
? colorMap[type](type.toUpperCase())
57+
: type.toUpperCase();
3758

38-
const coloredType = colorMap[type] ? colorMap[type](type.toUpperCase()) : type.toUpperCase()
39-
console.log(`${prefix} ${coloredType} ${message}`)
59+
outputFn(`${prefix} ${coloredType} ${message}`);
4060
} else {
4161
const emojiMap = {
4262
info: 'ℹ️',
4363
warn: '⚠️',
4464
error: '❌',
45-
success: '✅'
46-
}
47-
console.log(`${prefix} ${emojiMap[type] || ''} ${message}`)
65+
success: '✅',
66+
};
67+
outputFn(`${prefix} ${emojiMap[type] || ''} ${message}`);
4868
}
4969
}
5070

5171
success(...args) {
52-
this.output('success', ...args)
72+
this.output('success', ...args);
5373
}
5474

5575
info(...args) {
56-
this.output('info', ...args)
76+
this.output('info', ...args);
5777
}
5878

5979
warn(...args) {
60-
this.output('warn', ...args)
80+
this.output('warn', ...args);
6181
}
6282

6383
error(...args) {
64-
this.output('error', ...args)
84+
this.output('error', ...args);
6585
}
6686
}
67-
export default Logger
87+
88+
export default Logger;

designer-demo/scripts/uploadMaterials.mjs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Buffer } from 'node:buffer'
2-
import path from 'node:path'
31
import dotenv from 'dotenv'
42
import fs from 'fs-extra'
3+
import { Buffer } from 'node:buffer'
4+
import path from 'node:path'
55
import Logger from './logger.mjs'
66

77

@@ -54,13 +54,10 @@ async function main() {
5454
}
5555
const data = await response.json()
5656
if (data && data.success) {
57-
logger.success('File uploaded successfully!')
58-
logger.success('Inserted records:', data.data?.insertNum || 0)
59-
logger.success('Updated records:', data.data?.updateNum || 0)
60-
logger.success('Message:', data.message)
57+
logger.success(`File uploaded successfully:${JSON.stringify(data)}`)
6158
} else {
62-
logger.warn('Upload completed but success flag is false:', data)
63-
logger.warn('Upload completed with warnings:', data.message)
59+
logger.warn(`Upload completed but success flag is false: ${JSON.stringify(data)}`)
60+
logger.warn(`Upload completed with warnings: ${JSON.stringify(data.message)}`)
6461
}
6562
} catch (error) {
6663
logger.error('Error uploading file:', error instanceof Error ? error.message : String(error))

packages/engine-cli/template/designer/scripts/logger.mjs

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,87 @@
1-
import colors from 'picocolors'
1+
const log = (() => {
2+
return (...args) => {
3+
process.stdout.write(
4+
args.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg))).join(' ') + '\n'
5+
)
6+
}
7+
})()
8+
9+
const warn = (() => {
10+
return (...args) => {
11+
process.stderr.write(
12+
args.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg))).join(' ') + '\n'
13+
)
14+
}
15+
})()
216

317
class Logger {
4-
constructor(command) {
18+
constructor(command = 'default') {
519
this.command = command
20+
this.colors = null
21+
this.hasColors = false
22+
this.initColors()
23+
}
24+
25+
async initColors() {
26+
try {
27+
const colorsModule = await import('colors')
28+
this.colors = colorsModule.default || colorsModule
29+
this.hasColors = true
30+
} catch (err) {
31+
warn('colors package not found, using basic logging')
32+
this.hasColors = false
33+
}
634
}
735

8-
output(type, msg) {
9-
const format = () => {
36+
output(type, ...args) {
37+
const time = new Date().toLocaleTimeString()
38+
const prefix = `[${this.command}] [${time}]`
39+
const message = args
40+
.map((arg) => {
41+
if (typeof arg === 'object') {
42+
return JSON.stringify(arg, null, 2)
43+
}
44+
return String(arg)
45+
})
46+
.join(' ')
47+
48+
const outputFn = type === 'error' || type === 'warn' ? warn : log
49+
50+
if (this.hasColors && this.colors) {
1051
const colorMap = {
11-
info: 'cyan',
12-
warn: 'yellow',
13-
error: 'red',
14-
success: 'green'
52+
info: this.colors.cyan,
53+
warn: this.colors.yellow,
54+
error: this.colors.red,
55+
success: this.colors.green
1556
}
16-
const time = new Date().toLocaleTimeString()
17-
const colorMsg = colors[colorMap[type]](type)
57+
const coloredType = colorMap[type] ? colorMap[type](type.toUpperCase()) : type.toUpperCase()
1858

19-
return `[${this.command}] [${colors.dim(time)}] ${colorMsg} ${msg}`
59+
outputFn(`${prefix} ${coloredType} ${message}`)
60+
} else {
61+
const emojiMap = {
62+
info: 'ℹ️',
63+
warn: '⚠️',
64+
error: '❌',
65+
success: '✅'
66+
}
67+
outputFn(`${prefix} ${emojiMap[type] || ''} ${message}`)
2068
}
21-
const _logger = console
22-
23-
return _logger.log(format())
2469
}
2570

26-
info(msg) {
27-
this.output('info', msg)
71+
success(...args) {
72+
this.output('success', ...args)
2873
}
2974

30-
warn(msg) {
31-
this.output('warn', msg)
75+
info(...args) {
76+
this.output('info', ...args)
3277
}
3378

34-
error(msg) {
35-
this.output('error', msg)
79+
warn(...args) {
80+
this.output('warn', ...args)
3681
}
3782

38-
success(msg) {
39-
this.output('success', msg)
83+
error(...args) {
84+
this.output('error', ...args)
4085
}
4186
}
4287

packages/engine-cli/template/designer/scripts/uploadMaterials.mjs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Buffer } from 'node:buffer'
2-
import path from 'node:path'
31
import dotenv from 'dotenv'
42
import fs from 'fs-extra'
3+
import { Buffer } from 'node:buffer'
4+
import path from 'node:path'
55
import Logger from './logger.mjs'
66

77
/**
@@ -29,7 +29,7 @@ async function main() {
2929

3030
if (!backend_url) {
3131
logger.error('backend_url is not set in .env.local file')
32-
return
32+
process.exit(1)
3333
}
3434

3535
const bundlePath = path.join(process.cwd(), './public/mock/bundle.json')
@@ -48,8 +48,18 @@ async function main() {
4848
method: 'POST',
4949
body: formData
5050
})
51+
52+
if (!response.ok) {
53+
const errorText = await response.text()
54+
throw new Error(`Upload failed with status ${response.status}: ${errorText}`)
55+
}
5156
const data = await response.json()
52-
logger.success('File uploaded successfully:', data)
57+
if (data && data.success) {
58+
logger.success(`File uploaded successfully:${JSON.stringify(data)}`)
59+
} else {
60+
logger.warn(`Upload completed but success flag is false: ${JSON.stringify(data)}`)
61+
logger.warn(`Upload completed with warnings: ${JSON.stringify(data.message)}`)
62+
}
5363
} catch (error) {
5464
logger.error('Error uploading file:', error instanceof Error ? error.message : String(error))
5565
}

0 commit comments

Comments
 (0)