From 0a57e3e5fb173d92b1b5c550e09930764d87923a Mon Sep 17 00:00:00 2001 From: hardope Date: Fri, 18 Oct 2024 00:50:41 +0100 Subject: [PATCH] nodemon --- bin/turbo.js | 26 +++++++++++++++++++++++++- package.json | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/bin/turbo.js b/bin/turbo.js index d73d62a..61fdce4 100755 --- a/bin/turbo.js +++ b/bin/turbo.js @@ -60,6 +60,9 @@ app.listen(PORT, () => { await initNpm(); await installExpress(); + // Modify package.json to add custom start scripts + await updatePackageJson(); + console.log(colors.green('Project setup complete!')); } catch (error) { console.error(colors.red('Error setting up project:', error.message)); @@ -81,7 +84,7 @@ function initNpm() { function installExpress() { return new Promise((resolve, reject) => { - exec('npm install express', (error, stdout, stderr) => { + exec('npm install express nodemon', (error, stdout, stderr) => { if (error) { console.error(colors.red(`Error installing Express: ${stderr}`)); reject(error); @@ -92,6 +95,27 @@ function installExpress() { }); } +// Function to update package.json with custom scripts +async function updatePackageJson() { + try { + const packageJsonPath = path.join(process.cwd(), 'package.json'); + const packageJson = await fs.readJson(packageJsonPath); + + // Add custom start scripts + packageJson.scripts = { + ...packageJson.scripts, // Merge existing scripts if any + "start": "node index.js", + "start:dev": "nodemon index.js" + }; + + // Write the modified package.json back + await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 }); + console.log(colors.green('Custom scripts added to package.json!')); + } catch (error) { + console.error(colors.red('Error updating package.json:', error.message)); + } +} + const [,, command, projectName, currentFolderFlag] = process.argv; const currentDir = process.cwd(); diff --git a/package.json b/package.json index 1a49097..ddfd503 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "turboxpress", - "version": "0.0.0-development", + "version": "1.0.0", "description": "A package to initialize a basic Express.js project with turbo speed", "main": "dist/index.js", "bin": "./bin/turbo.js",