Skip to content

Instantly share code, notes, and snippets.

@vysinsky
Created March 9, 2022 12:47
Show Gist options
  • Save vysinsky/14e5986def21f89cb307e0e874dea48a to your computer and use it in GitHub Desktop.
Save vysinsky/14e5986def21f89cb307e0e874dea48a to your computer and use it in GitHub Desktop.
SFCC toolkit opener for JetBrains IDEs
/**
* If you are SFCC developer and want to use JetBrains IDEs (or any other than VSCode) you can use this script to listen on port 60606 which is the VSCode prophet extensions port.
* It will open files in your favourite IDE.
* Ensure you have VSCode closed first as it listens on same port. If not, you will encounter the `EADDRINUSE` error.
* No need to use this if you want to open file in VSCode ;)
*
* Args:
* * basePath - defaults to cwd + '/storefront-reference-architecture/cartridges'
* * launcher - defaults to 'pstorm'
*
*
* Usage:
* * node opener.js
*
* @licence MIT
* @author Michal Vysinsky (michal.vysinsky@currys.co.uk)
*/
const http = require('http');
const { exec } = require('child_process');
const args = {};
process.argv.slice(2).forEach(arg => {
const [argName, argValue] = arg.split('=');
args[argName.substring(2).trim()] = argValue.trim();
});
const basePath = args.basePath || process.cwd() + '/storefront-reference-architecture/cartridges';
const launcher = args.launcher || 'pstorm';
const server = http.createServer((req, res) => {
if (!req.url.startsWith('/target=')) {
return res.end();
}
const filePath = basePath + req.url.substring(8);
console.debug(`Opening file ${filePath} with launcher ${launcher}`);
exec(`${launcher} ${filePath}`);
res.end();
});
server.listen(60606);
console.log('Listening for open file requests');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment