Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create a postAction script to run via node after template installs #448

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,19 @@
}
]
}
}
},
"postActions": [
{
"actionId": "3A7C4B45-1F5D-4A30-959A-51B88E82B5D2",
"description": "Install npm packages, and run linter to resolve linting issues after template instantiation.",
"manualInstructions": [
{ "text": "Run `npm install` then `npm run lint:fix` to resolve linting issues." }
],
"args": {
"executable": "node",
"args": "postAction.js"
},
"continueOnError": true
}
]
}
59 changes: 59 additions & 0 deletions templates/Coalesce.Vue.Template/content/postAction.js
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.');
}
Loading