import { exec } from 'child_process' import { writeFile, existsSync, mkdirSync, rmdirSync, unlinkSync, statSync, } from 'fs' import { dirname } from 'path' import { fileContent } from '../files/fileContent' import { npmCommands } from './npmCommands' import { toDelete } from '../delete/toDelete' import { packageContent } from '../files/packageContent' export const runNpmCommands = (name: string, deleteBootstrap: boolean) => { exec(`dotnet new blazor -o ${name}`, (error, stdout, stderr) => { if (error) { console.error(`Error executing command: dotnet new blazor -o ${name}`) console.error(stderr) } else { process.chdir(`./${name}`) exec('npm init -y', (error, stdout, stderr) => { if (error) { console.error(`Error executing command: npm init -y`) console.error(stderr) } else { writeFile('./package.json', packageContent(name), (err) => { if (err) { console.error(`Error writing to package.json: ${err}`) } }) } }) npmCommands(name).forEach((command, index) => { exec(command, (error, stdout, stderr) => { if (error) { console.error(`Error executing command: ${command}`) console.error(stderr) } }) }) toDelete(deleteBootstrap).forEach((path) => { if (existsSync(path)) { const stats = statSync(path) if (stats.isFile()) { unlinkSync(path) } else if (stats.isDirectory()) { rmdirSync(path, { recursive: true }) } } }) fileContent(name).forEach((file) => { const dir = dirname(file.path) if (!existsSync(dir)) { mkdirSync(dir, { recursive: true }) } writeFile(file.path, file.content, (err) => { if (err) { console.error(`Error writing to ${file.path}: ${err}`) } }) }) } }) }