2023-09-28 13:50:15 +08:00
|
|
|
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 }) {
|
|
|
|
// 格式化内容
|
2023-11-29 17:41:09 +08:00
|
|
|
const content = await prettier.format(options.code, {
|
2023-09-28 13:50:15 +08:00
|
|
|
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);
|
|
|
|
}
|