cool-admin-vue/build/cool/lib/menu/index.ts
2023-03-08 15:14:43 +08:00

35 lines
764 B
TypeScript

import { createWriteStream } from "fs";
import prettier from "prettier";
import { join } from "path";
import { mkdirs } from "../../utils";
// 创建文件
export async function createMenu(options: { viewPath: string; code: string }) {
// 格式化内容
const content = prettier.format(options.code, {
parser: "vue",
useTabs: true,
tabWidth: 4,
endOfLine: "lf",
semi: true,
jsxBracketSameLine: true,
singleQuote: false,
printWidth: 100,
trailingComma: "none"
});
// 目录路径
const dir = (options.viewPath || "").split("/");
// 文件名
const fname = dir.pop();
// 创建目录
const path = mkdirs(`./src/${dir.join("/")}`);
// 创建文件
createWriteStream(join(path, fname || "demo"), {
flags: "w"
}).write(content);
}