const fs = require('fs'); const path = require('path'); // 定义基础路径:src/app const basePath = path.join('src', 'app'); // 要创建的文件夹结构 const folderStructure = { assets: [], environments: [], modules: [], shared: { components: [], models: [], pipes: [], services: [] } }; /** * 递归创建目录 * @param {string} currentPath 当前路径 * @param {Object|Array} structure 文件夹结构 */ function createFolders(currentPath, structure) { if (Array.isArray(structure)) { // 如果是数组,表示当前层级只需创建自己 if (!fs.existsSync(currentPath)) { fs.mkdirSync(currentPath, {recursive: true}); console.log(`✅ Created directory: ${currentPath}`); } } else if (typeof structure === 'object') { // 如果是对象,遍历子项并继续递归 for (const key in structure) { const newPath = path.join(currentPath, key); if (!fs.existsSync(newPath)) { fs.mkdirSync(newPath, {recursive: true}); console.log(`✅ Created directory: ${newPath}`); } createFolders(newPath, structure[key]); } } } // 开始创建 try { createFolders(basePath, folderStructure); console.log('\n🎉 文件夹结构已成功创建!'); } catch (error) { console.error('\n❌ 创建文件夹结构失败:', error.message); }