From 06ecc5752254b622736cba884f62799fcae29c66 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Fri, 20 Sep 2024 09:52:51 -0700 Subject: [PATCH 1/2] feat: Create a postAction script to run via node after template installs Dotnet template prompts user if they want to run. --- .../content/.template.config/template.json | 16 ++++- .../content/postAction.js | 59 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 templates/Coalesce.Vue.Template/content/postAction.js diff --git a/templates/Coalesce.Vue.Template/content/.template.config/template.json b/templates/Coalesce.Vue.Template/content/.template.config/template.json index f33f6888c..b87b2d222 100644 --- a/templates/Coalesce.Vue.Template/content/.template.config/template.json +++ b/templates/Coalesce.Vue.Template/content/.template.config/template.json @@ -226,5 +226,19 @@ } ] } - } + }, + "postActions": [ + { + "actionId": "3A7C4B45-1F5D-4A30-959A-51B88E82B5D2", + "description": "Run npm lint:fix in the .Web directory after template instantiation", + "manualInstructions": [ + { "text": "Install npm packages, and run linter to resolve linting issues." } + ], + "args": { + "executable": "node", + "args": "postAction.js" + }, + "continueOnError": true + } + ] } diff --git a/templates/Coalesce.Vue.Template/content/postAction.js b/templates/Coalesce.Vue.Template/content/postAction.js new file mode 100644 index 000000000..13fc4fcf4 --- /dev/null +++ b/templates/Coalesce.Vue.Template/content/postAction.js @@ -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.'); +} From 80ed242fb21082a18b40a510c14e69b939d077b2 Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Fri, 20 Sep 2024 09:59:09 -0700 Subject: [PATCH 2/2] Update template.json --- .../content/.template.config/template.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/Coalesce.Vue.Template/content/.template.config/template.json b/templates/Coalesce.Vue.Template/content/.template.config/template.json index b87b2d222..0ca778489 100644 --- a/templates/Coalesce.Vue.Template/content/.template.config/template.json +++ b/templates/Coalesce.Vue.Template/content/.template.config/template.json @@ -230,9 +230,9 @@ "postActions": [ { "actionId": "3A7C4B45-1F5D-4A30-959A-51B88E82B5D2", - "description": "Run npm lint:fix in the .Web directory after template instantiation", + "description": "Install npm packages, and run linter to resolve linting issues after template instantiation.", "manualInstructions": [ - { "text": "Install npm packages, and run linter to resolve linting issues." } + { "text": "Run `npm install` then `npm run lint:fix` to resolve linting issues." } ], "args": { "executable": "node",