2022-03-12 07:07:08 +00:00
|
|
|
|
const util = require("util");
|
|
|
|
|
const glob = util.promisify(require('glob'));
|
|
|
|
|
const fs = require("fs").promises;
|
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
|
var errors = [];
|
|
|
|
|
var directories = await glob(__dirname + '../../dishes/**/*.md');
|
|
|
|
|
|
|
|
|
|
for (var filePath of directories) {
|
|
|
|
|
var data = await fs.readFile(filePath, 'utf8');
|
|
|
|
|
var filename = path.parse(filePath).base.replace(".md","");
|
|
|
|
|
|
2022-03-13 06:09:46 +00:00
|
|
|
|
dataLines = data.split('\n').map(t => t.trim());
|
2022-03-12 07:07:08 +00:00
|
|
|
|
titles = dataLines.filter(t => t.startsWith('#'));
|
2022-03-13 06:09:46 +00:00
|
|
|
|
secondTitles = titles.filter(t => t.startsWith('## '));
|
2022-03-12 07:07:08 +00:00
|
|
|
|
|
2022-03-20 18:49:02 +00:00
|
|
|
|
if (dataLines.filter(line => line.includes('勺')).length >
|
|
|
|
|
dataLines.filter(line => line.includes('勺子')).length +
|
|
|
|
|
dataLines.filter(line => line.includes('炒勺')).length +
|
|
|
|
|
dataLines.filter(line => line.includes('漏勺')).length +
|
|
|
|
|
dataLines.filter(line => line.includes('吧勺')).length) {
|
2022-03-20 18:28:18 +00:00
|
|
|
|
errors.push(`文件 ${filePath} 不符合仓库的规范!勺 不是一个精准的单位!`);
|
2022-03-15 05:44:53 +00:00
|
|
|
|
}
|
2022-03-20 18:14:45 +00:00
|
|
|
|
if (dataLines.filter(line => line.includes('适量')).length > 0) {
|
2022-03-20 18:28:18 +00:00
|
|
|
|
errors.push(`文件 ${filePath} 不符合仓库的规范!适量 不是一个精准的描述!请给出克 g 或毫升 ml。`);
|
2022-03-20 18:14:45 +00:00
|
|
|
|
}
|
2022-03-20 19:26:23 +00:00
|
|
|
|
if (dataLines.filter(line => line.includes('min')).length > 0) {
|
|
|
|
|
errors.push(`文件 ${filePath} 不符合仓库的规范!min 这个词汇有多重含义。建议改成中文"分钟"。`);
|
|
|
|
|
}
|
2022-03-20 18:14:45 +00:00
|
|
|
|
if (dataLines.filter(line => line.includes('左右')).length > 0) {
|
2022-03-20 18:28:18 +00:00
|
|
|
|
errors.push(`文件 ${filePath} 不符合仓库的规范!左右 不是一个能够明确定量的标准! 如果是在描述一个模糊物体的特征,请使用 '大约'。例如:鸡(大约1kg)`);
|
|
|
|
|
}
|
2022-03-23 10:53:00 +00:00
|
|
|
|
if (dataLines.filter(line => line.includes('少许')).length > 0) {
|
|
|
|
|
errors.push(`文件 ${filePath} 不符合仓库的规范!少许 不是一个精准的描述!请给出克 g 或毫升 ml。`);
|
|
|
|
|
}
|
2022-03-20 18:28:18 +00:00
|
|
|
|
if (dataLines.filter(line => line.includes('你')).length > 0) {
|
|
|
|
|
errors.push(`文件 ${filePath} 不符合仓库的规范!请不要出现人称代词。`);
|
2022-03-20 18:14:45 +00:00
|
|
|
|
}
|
2022-03-12 07:07:08 +00:00
|
|
|
|
if (titles[0].trim() != "# " + filename + "的做法") {
|
2022-03-20 19:26:23 +00:00
|
|
|
|
errors.push(`文件 ${filePath} 不符合仓库的规范!它的大标题应该是: ${"# " + filename + "的做法"}! 而它现在是 ${titles[0].trim()}!`);
|
2022-03-12 07:07:08 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (secondTitles.length != 4) {
|
2022-03-27 09:18:31 +00:00
|
|
|
|
errors.push(`文件 ${filePath} 不符合仓库的规范!它并不是四个标题的格式。请从示例菜模板中创建菜谱!请不要破坏模板的格式!`);
|
2022-03-12 07:07:08 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (secondTitles[0].trim() != "## 必备原料和工具") {
|
2022-03-20 19:26:23 +00:00
|
|
|
|
errors.push(`文件 ${filePath} 不符合仓库的规范!第一个标题不是 必备原料和工具!`);
|
2022-03-12 07:07:08 +00:00
|
|
|
|
}
|
|
|
|
|
if (secondTitles[1].trim() != "## 计算") {
|
2022-03-20 19:26:23 +00:00
|
|
|
|
errors.push(`文件 ${filePath} 不符合仓库的规范!第二个标题不是 计算!`);
|
2022-03-12 07:07:08 +00:00
|
|
|
|
}
|
|
|
|
|
if (secondTitles[2].trim() != "## 操作") {
|
2022-03-20 19:26:23 +00:00
|
|
|
|
errors.push(`文件 ${filePath} 不符合仓库的规范!第三个标题不是 操作`);
|
2022-03-12 07:07:08 +00:00
|
|
|
|
}
|
|
|
|
|
if (secondTitles[3].trim() != "## 附加内容") {
|
2022-03-20 19:26:23 +00:00
|
|
|
|
errors.push(`文件 ${filePath} 不符合仓库的规范!第四个标题不是 附加内容`);
|
2022-03-12 07:07:08 +00:00
|
|
|
|
}
|
2022-03-13 06:09:46 +00:00
|
|
|
|
|
|
|
|
|
var mustHave = '如果您遵循本指南的制作流程而发现有问题或可以改进的流程,请提出 Issue 或 Pull request 。';
|
|
|
|
|
var mustHaveIndex = dataLines.indexOf(mustHave);
|
|
|
|
|
if (mustHaveIndex < 0) {
|
2022-03-20 18:35:53 +00:00
|
|
|
|
errors.push(`文件 ${filePath} 不符合仓库的规范! 它没有包含必需的附加内容!`);
|
2022-03-13 06:09:46 +00:00
|
|
|
|
}
|
2022-03-12 07:07:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (errors.length > 0) {
|
|
|
|
|
for (var error of errors) {
|
|
|
|
|
console.error(error + "\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var message = `Found ${errors.length} errors! Please fix!`;
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main();
|