2020-07-12 09:43:07 +08:00

36 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @copyright chuzhixin 1204505056@qq.com
* @description 导入所有 controller 模块npm run serve时在node环境中自动输出controller文件夹下Mock接口请勿修改。
*/
import { handleMockArray } from "./utils";
import chalk from "chalk";
import fs from "fs";
import { baseURL, devPort, httpRequestFile } from "../src/config/settings";
const mocks = [];
const mockArray = handleMockArray();
if (httpRequestFile) {
fs.writeFile("./http/mock.http", "", {}, function (err) {
if (err) throw err;
});
}
mockArray.forEach(async (item) => {
const obj = require(item).default;
await mocks.push(...obj);
if (httpRequestFile) {
obj.forEach((item) => {
fs.appendFile(
"./http/mock.http",
`\r\n###${item.url}###\r\POST http://localhost:${devPort}/${baseURL}${item.url}\r\nContent-Type: application/x-www-form-urlencoded\r\n###\r\n`,
(error) => {
if (error)
return chalk.red(`\n > 追加HTTP Request失败${error.message}`);
}
);
});
}
});
export default mocks;