Skip to content

Commit

Permalink
fix(script): translate log (#549)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
yaoyun8 and coderabbitai[bot] authored Aug 24, 2024
1 parent c218724 commit 76c23b7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
22 changes: 11 additions & 11 deletions scripts/buildMaterials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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 = {
Expand All @@ -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
}
Expand Down Expand Up @@ -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}.`)
}
}

Expand All @@ -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()
Expand Down
24 changes: 12 additions & 12 deletions scripts/connection.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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}.`)
})
}

Expand Down Expand Up @@ -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}.`)
})
}

Expand All @@ -344,7 +344,7 @@ class MysqlConnection {
}
})
.catch((error) => {
logger.success(`查询组件 ${component.component} 失败${error}`)
logger.error(`query ${component.component} failed${error}.`)
})
}

Expand Down Expand Up @@ -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)
})
})
Expand Down
4 changes: 2 additions & 2 deletions scripts/splitMaterials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`)
}
}

Expand Down

0 comments on commit 76c23b7

Please sign in to comment.