DEV: Support colocation of component templates in plugins ()

This allows plugins to colocate component JS and HBS under `/plugins/{name}/assets/javascripts/discourse/components`.

`discourse-presence` is updated to use this new pattern, which also serves as an integration test for this part of the build pipeline.
This commit is contained in:
David Taylor 2022-10-17 09:38:20 +01:00 committed by GitHub
parent 7e372b3a15
commit f5419521f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 0 deletions
app/assets/javascripts/discourse-plugins
plugins/discourse-presence/assets/javascripts/discourse
components
connectors
before-composer-controls
topic-above-footer-buttons

@ -0,0 +1,19 @@
const ColocatedTemplateProcessor = require("ember-cli-htmlbars/lib/colocated-broccoli-plugin");
module.exports = class DiscoursePluginColocatedTemplateProcessor extends (
ColocatedTemplateProcessor
) {
detectRootName() {
const entries = this.currentEntries().filter((e) => !e.isDirectory());
const path = entries[0]?.relativePath;
const match = path?.match(
/^discourse\/plugins\/(?<name>[^/]+)\/discourse\//
);
if (match) {
return `discourse/plugins/${match.groups.name}/discourse`;
}
}
};

@ -7,6 +7,7 @@ const mergeTrees = require("broccoli-merge-trees");
const fs = require("fs");
const concat = require("broccoli-concat");
const RawHandlebarsCompiler = require("discourse-hbr/raw-handlebars-compiler");
const DiscoursePluginColocatedTemplateProcessor = require("./colocated-template-compiler");
function fixLegacyExtensions(tree) {
return new Funnel(tree, {
@ -169,6 +170,8 @@ module.exports = {
tree = namespaceModules(tree, pluginName);
tree = RawHandlebarsCompiler(tree);
tree = new DiscoursePluginColocatedTemplateProcessor(tree);
tree = this.compileTemplates(tree);
tree = this.processedAddonJsFiles(tree);