-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create a postAction script to run via node after template installs
Dotnet template prompts user if they want to run.
- Loading branch information
1 parent
42b168c
commit 06ecc57
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const { exec } = require('child_process'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const rootDir = process.cwd(); | ||
|
||
function findWebDirectory(dir) { | ||
const files = fs.readdirSync(dir); | ||
for (const file of files) { | ||
const fullPath = path.join(dir, file); | ||
if (fs.statSync(fullPath).isDirectory()) { | ||
if (file.endsWith('.Web')) { | ||
return fullPath; | ||
} else { | ||
const result = findWebDirectory(fullPath); | ||
if (result) return result; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
const webDir = findWebDirectory(rootDir); | ||
|
||
if (webDir) { | ||
console.log(`Found .Web directory: ${webDir}`); | ||
exec('npm install', { cwd: webDir }, (error, stdout, stderr) => { | ||
if (error) { | ||
console.error(`Error executing npm install: ${error.message}`); | ||
console.error(stderr); | ||
console.log(stdout); | ||
return; | ||
} | ||
console.log(stdout); | ||
console.error(stderr); | ||
|
||
exec('npm run lint:fix', { cwd: webDir }, (error, stdout, stderr) => { | ||
if (error) { | ||
console.error(`Error executing npm run lint:fix: ${error.message}`); | ||
console.error(stderr); | ||
console.log(stdout); | ||
return; | ||
} | ||
console.log(stdout); | ||
console.error(stderr); | ||
|
||
// Delete the script after execution | ||
fs.unlink(__filename, (err) => { | ||
if (err) { | ||
console.error(`Error deleting script: ${err.message}`); | ||
} else { | ||
console.log('Script deleted successfully.'); | ||
} | ||
}); | ||
}); | ||
}); | ||
} else { | ||
console.error('No .Web directory found.'); | ||
} |