Created
June 18, 2020 06:09
-
-
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
This file contains hidden or 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
// 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}`); |
This file contains hidden or 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
// .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