fix(script): translate log (#549)

* fix: translate log

* Update scripts/connection.mjs

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update scripts/connection.mjs

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update scripts/connection.mjs

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
yaoyun8 2024-08-24 06:46:45 -07:00 committed by GitHub
parent c218724543
commit 76c23b767b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 25 deletions

View File

@ -40,13 +40,13 @@ const validateComponent = (file, component) => {
const requiredList = requiredFields.filter((field) => !fields.includes(field))
if (requiredList.length) {
logger.error(`组件文件 ${file} 缺少必要字段:${requiredList.join('、')}`)
logger.error(`missing required fields: ${requiredList.join(',')} at ${file}.`)
return false
}
if (!component.npm) {
logger.warn(`组件文件 ${file} 缺少 npm 字段出码时将不能通过import语句导入组件。`)
logger.warn(`missing the \`npm\` field, and it cannot be imported when coding at ${file}.`)
return false
}
@ -66,7 +66,7 @@ const validateBlock = (file, block) => {
const requiredList = requiredFields.filter((field) => !fields.includes(field))
if (requiredList.length) {
logger.error(`区块文件 ${file} 缺少必要字段:${requiredList.join('、')}`)
logger.error(`missing required fields: ${requiredList.join(',')} at ${file}.`)
return false
}
@ -84,7 +84,7 @@ const generateComponents = () => {
try {
fg([`${materialsDir}/**/*.json`]).then((files) => {
if (!files.length) {
logger.warn('物料文件夹为空,请先执行`pnpm splitMaterials`命令拆分物料资产包')
logger.warn('please execute `pnpm splitMaterials` first to split the materials.')
}
const bundle = {
@ -108,7 +108,7 @@ const generateComponents = () => {
if (!material) {
const fileFullPath = path.join(process.cwd(), file)
logger.error(`文件格式有误 (${fileFullPath})`)
logger.error(`incorrect file format at ${fileFullPath}.`)
return
}
@ -178,9 +178,9 @@ const generateComponents = () => {
write(bundle)
})
logger.success('物料资产包构建成功')
logger.success('materials built.')
} catch (error) {
logger.error(`物料资产包构建失败:${error}`)
logger.error(`failed to build materials: ${error}.`)
}
}
@ -189,13 +189,13 @@ const watcher = chokidar.watch(`${materialsDir}/**/*.json`, { ignoreInitial: tru
watcher.on('all', (event, file) => {
const eventMap = {
add: '新增',
change: '更新',
unlink: '删除'
add: 'added',
change: 'changed',
unlink: 'deleted'
}
const fileFullPath = path.join(process.cwd(), file)
logger.info(`${eventMap[event]}组件文件 (${fileFullPath})`)
logger.info(`${fileFullPath} ${eventMap[event]}, rebuilding materials...`)
// 监听物料文件变化,更新物料资产包
generateComponents()

View File

@ -38,10 +38,10 @@ class MysqlConnection {
return new Promise((resolve, reject) => {
this.connection.connect((error) => {
if (error) {
logger.warn('未能连接到数据库,请查看数据库配置是否正确')
logger.warn('unable to connect to the database, please check the database configuration is correct.')
reject()
} else {
logger.success('数据库连接成功')
logger.success('database connected.')
this.connected = true
resolve()
}
@ -100,11 +100,11 @@ class MysqlConnection {
* @returns boolean 校验组件字段是否失败false-有字段出错
*/
isValid(component, file) {
const longtextFields = ['name', 'npm', 'snippets', 'schema_fragment', 'configure', 'component_metadata']
const longTextFields = ['name', 'npm', 'snippets', 'schema_fragment', 'configure', 'component_metadata']
return Object.entries(component).every(([key, value]) => {
if (longtextFields.includes(key) && value !== null && typeof value !== 'object') {
logger.error(`"${key}" 的值不是有效的JSON (${file})`)
if (longTextFields.includes(key) && value !== null && typeof value !== 'object') {
logger.error(`the value of "${key}" is not valid JSON at ${file}.`)
return false
}
@ -193,10 +193,10 @@ class MysqlConnection {
this.query(sqlContent, component.component)
.then(() => {
logger.success(`组件 ${component.component} 数据更新成功`)
logger.success(`${component.component} updated.`)
})
.catch((error) => {
logger.error(`组件 ${component.component} 数据更新失败 ${error}`)
logger.error(`failed to update ${component.component}: ${error}.`)
})
}
@ -322,11 +322,11 @@ class MysqlConnection {
.then((result) => {
const id = result.insertId
logger.success(`组件 ${component.component} 数据新增成功`)
logger.success(`${component.component} added.`)
this.relationMaterialHistory(id)
})
.catch((error) => {
logger.success(`组件 ${component.component} 数据新增失败:${error}`)
logger.error(`add ${component.component} failed${error}.`)
})
}
@ -344,7 +344,7 @@ class MysqlConnection {
}
})
.catch((error) => {
logger.success(`查询组件 ${component.component} 失败:${error}`)
logger.error(`query ${component.component} failed${error}.`)
})
}
@ -395,11 +395,11 @@ class MysqlConnection {
return new Promise((resolve, reject) => {
this.query(sqlContent)
.then((result) => {
logger.success(`${componentsTableName} 创建成功`)
logger.success(`table ${componentsTableName} created.`)
resolve(result)
})
.catch((error) => {
logger.success(`${componentsTableName} 创建失败:${error}`)
logger.error(`create table ${componentsTableName} failed${error}.`)
reject(error)
})
})

View File

@ -51,9 +51,9 @@ const splitMaterials = () => {
fs.outputJsonSync(blockPath, block, { spaces: 2 })
})
logger.success('拆分物料资产包完成')
logger.success('materials splitted.')
} catch (error) {
logger.error(`拆分物料资产包失败: ${error}`)
logger.error(`failed to split materials: ${error}.`)
}
}