feat:初始化 -融骅

This commit is contained in:
2023-10-17 09:15:30 +08:00
parent c9ff84e6a2
commit 405e152b38
1190 changed files with 138344 additions and 455 deletions

12
serve/tools/data.js Normal file
View File

@@ -0,0 +1,12 @@
module.exports = [
`
ExamQuestions 考试试题结果存储
historyId number 考试记录Id
questionId number 试题ID
questionScore number 该题分值
score number 我的得分
userAnswer string 我的答案
comment string 老师的评语
`,
];

View File

@@ -0,0 +1,58 @@
const data = require('./data');
for (const item of data) {
const tpls = [
"import { IncrementIdEntity } from 'src/common/entity/increment-id.entity';",
"import { Column, Entity } from 'typeorm';",
'',
];
const [tableAttrs, ...column] = item.trim().replace(/\n+/, '\n').split('\n');
const [table, annotate] = handleAttrs(tableAttrs);
if (annotate) tpls.push('/**', ' * ' + annotate, ' */');
tpls.push('@Entity()', `export class ${table} extends IncrementIdEntity {`);
for (let i = 0, attrs; (attrs = column[i]); i++) {
const [key, type, comment] = handleAttrs(attrs);
const options = [];
if (/[A-Z]/g.test(key)) options.push(`name: '${handleName(key)}'`);
if (comment) options.push(`comment: '${comment}'`);
if (i) tpls.push('');
tpls.push(
` @Column(${options.length ? `{ ${options.join(', ')} }` : ''})`,
` ${key}: ${type};`,
);
}
output(table, tpls.concat('}\n').join('\n'));
}
function handleAttrs(str) {
return str.trim().split(/\s+/);
}
function output(table, tpl) {
const fs = require('fs');
const path = __dirname + '/entity';
if (!fs.existsSync(path)) fs.mkdirSync(path);
fs.writeFile(path + `/${handleName(table, '-')}.entity.ts`, tpl, (err) => {
if (err) {
console.log(err);
throw err;
}
console.log('【', table, '】转换成功');
});
}
function handleName(name, sep = '_') {
if (!name) return;
return (
name[0].toLowerCase() +
name.substr(1).replace(/([A-Z])/g, (m, p) => sep + p.toLowerCase())
);
}