/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/ProjectTemplates/Web.ProjectTemplates/copyDependency.mjs
44 строки
1 KB
Javier Calvarro Nelson
[Templates] Updates libraries dependencies content (#57863)
17 сен 2024, 02:02
Не верифицирован
17 сен 2024, 02:02
88bf5a3
Код
Авторство
О чём код?
import { existsSync, mkdirSync, readdirSync, lstatSync, copyFileSync, rm } from 'fs'; import { join } from 'path'; function copyFolderSync(source, destination) { if (!existsSync(destination)) { mkdirSync(destination, { recursive: true }); } const items = readdirSync(source); items.forEach(item => { const sourcePath = join(source, item); const destinationPath = join(destination, item); if (lstatSync(sourcePath).isDirectory()) { copyFolderSync(sourcePath, destinationPath); } else { copyFileSync(sourcePath, destinationPath); } }); } const [,, sourceFolder, destinationFolder] = process.argv; if (!sourceFolder || !destinationFolder) { console.error('Please provide both source and destination paths.'); process.exit(1); } // If the destination folder exists, delete the folder and its contents if (existsSync(destinationFolder)) { console.log(`Destination folder '${destinationFolder}' already exists. Deleting it...`); rm(destinationFolder, { recursive: true }, (err) => { if (err) { console.error('Error deleting destination folder:', err); process.exit(1); } copyFolderSync(sourceFolder, destinationFolder); console.log('Folder copied successfully!'); }); }else{ copyFolderSync(sourceFolder, destinationFolder); console.log('Folder copied successfully!'); }