const fs = require("fs");
const path = require("path");

const targetDir = `${process.cwd()}/${process.argv[3]}`;

// 初始化内容
const files = [
  {
    name: "index.vue",
    content: `<template>\n  <view>\n    <!-- 页面内容 -->\n  </view>\n</template>\n\n<script setup lang="ts">\nimport method from "./method";\nimport useModel from "./model";\n</script>\n\n<style setup>\n@import './style.scss';\n</style>\n`,
  },
  {
    name: "model.ts",
    content: `import { ref } from "vue";\n\nexport default {\n //model \n}\n`,
  },
  {
    name: "method.ts",
    content: `\nexport default {\n //method \n}`,
  },
  {
    name: "style.scss",
    content: `/* 页面样式 */`,
  },
  { name: "components", content: null }, // 文件夹
];

files.forEach((file) => {
  const filePath = path.join(targetDir, file.name);
  if (file.content !== null) {
    // 创建文件
    fs.writeFile(filePath, file.content, (err) => {
      if (err) {
        console.error(`创建文件 ${file.name} 失败:`, err);
      } else {
        console.log(`文件 ${file.name} 创建成功`);
      }
    });
  } else {
    // 创建文件夹
    fs.mkdir(filePath, { recursive: true }, (err) => {
      if (err) {
        console.error(`创建文件夹 ${file.name} 失败:`, err);
      } else {
        console.log(`文件夹 ${file.name} 创建成功`);
      }
    });
  }
});
