Skip to content

Commit

Permalink
nodemon
Browse files Browse the repository at this point in the history
  • Loading branch information
hardope committed Oct 17, 2024
1 parent fd97341 commit 0a57e3e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion bin/turbo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 0a57e3e

Please sign in to comment.