cool-admin-vue/build/cool/menu/index.ts
神仙都没用 1735d6258e 发布7.x
2023-09-28 13:50:15 +08:00

35 lines
761 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);
}