Skip to content

Instantly share code, notes, and snippets.

@lukemelia
Created June 18, 2020 06:09
Show Gist options
  • Save lukemelia/79a3505bee6d9ef748114210d7c57879 to your computer and use it in GitHub Desktop.
Save lukemelia/79a3505bee6d9ef748114210d7c57879 to your computer and use it in GitHub Desktop.
vscode task for re-exporting an ember addon file that is open in the addon dir to the app dir
// bin/generate-reexport-in-app.js
const fs = require('fs');
const path = require('path');
let args = process.argv.slice(2);
let sourcePath = args[0];
let targetPath = sourcePath.replace(/^addon/,'app').replace(/^\.hbs/, '.js');
let pkg = require('../package.json');
let addonName = pkg.name;
let sourceModule = sourcePath.replace(/^addon/,addonName).replace(/\.(js|hbs)$/,'');
let fileContents = `export { default } from '${sourceModule}';\n`;
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
fs.writeFileSync(targetPath, fileContents);
console.log(`Generated a re-export at ${targetPath}`);
// .vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "re-export",
"type": "shell",
"command": "node ./bin/generate-reexport-in-app.js ${relativeFile}",
"problemMatcher": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment