Skip to content

Instantly share code, notes, and snippets.

@mmun
Created March 16, 2021 20:34
Show Gist options
  • Save mmun/89a88c9b84caf73dadb9a79c2d32cf6c to your computer and use it in GitHub Desktop.
Save mmun/89a88c9b84caf73dadb9a79c2d32cf6c to your computer and use it in GitHub Desktop.
crappy component template colocation polyfill
'use strict';
let path = require('path');
let Funnel = require('broccoli-funnel');
module.exports = {
name: require('./package').name,
preprocessTree(type, tree) {
if (type === 'template') {
let addon = this;
let funnel = new Funnel(tree, {
getDestinationPath(relativePath) {
if (path.extname(relativePath) === '.hbs') {
// It is safe to assume the path will always have at least two segments:
// [ <appName>, ..., <fileName> ]
let pathParts = relativePath.split(path.sep);
if (pathParts[1] === 'components') {
pathParts.splice(1, 0, 'templates');
let classicPath = pathParts.join(path.sep);
if (funnel.input.existsSync(classicPath)) {
addon.ui.writeError(
`[${addon.name}] A colocated component template (${relativePath}) conflicts with a classic component template (${classicPath}).`
);
} else {
return classicPath;
}
}
}
return relativePath;
}
});
return funnel;
} else {
return tree;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment