Skip to content

Commit

Permalink
♻️ Update how we generate YUIDoc to be compatible with Embroider builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Djamel BENDAOUD authored and dbendaou committed Dec 23, 2022
1 parent 9e998d1 commit 5e69c43
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
15 changes: 7 additions & 8 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ module.exports = function(defaults) {
// Add options here
});

/*
This build file specifies the options for the dummy test app of this
addon, located in `/tests/dummy`
This build file does *not* influence how the addon or the app using it
behave. You most likely want to be modifying `./index.js` or app's build file
*/

const { maybeEmbroider } = require('@embroider/test-setup');
return maybeEmbroider(app);
const appTree = maybeEmbroider(app);

if ('@embroider/core' in app.dependencies()) {
return require('./index').prerender(app, appTree);
} else {
return appTree;
}
};
55 changes: 43 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const fs = require('fs');
const path = require('path');
const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');
const { parse, generatePreviewHead, overrideEnvironment, findEnvironment } = require('./lib/util');

let YUIDocsGenerator;
Expand All @@ -27,22 +26,47 @@ module.exports = {
}

this.app = app;
},
},

postprocessTree(type, tree) {
if (type !== 'all') {
return tree;
}

return this._prerenderTree(tree);
},

/**
* This function is *not* called by ember-cli directly, but supposed to be imported by an app to wrap the app's
* tree, to add the prerendered HTML files. This workaround is currently needed for Embroider-based builds that
* don't support the `postprocessTree('all', tree)` hook used here.
*/
prerender(app, tree) {
let storybookAddon = app.project.addons.find(
({ name }) => name === '@storybook/ember-cli-storybook'
);

if (!storybookAddon) {
throw new Error(
"Could not find initialized ember-cli-storybook addon. It must be part of your app's dependencies!"
);
}

postprocessTree(type, appTree) {
this._super.postprocessTree.apply(this, arguments);
return storybookAddon._prerenderTree(tree);
},

_prerenderTree(tree) {
let options = this._getOptions();
if (!options.enableAddonDocsIntegration) {
return tree;
}

let componentFilePathPatterns = options.componentFilePathPatterns || [
'app/components/*.js',
'lib/**/addon/components/*.js',
'addon/components/*.js',
];

if (type !== 'all' || !options.enableAddonDocsIntegration) {
return appTree;
}

let componentJS = new Funnel('.', {
include: componentFilePathPatterns,
});
Expand All @@ -57,10 +81,17 @@ module.exports = {
packages: [ this.project.name() ]
});

return mergeTrees([
appTree,
componentDocsTree,
]);
let Merge = require('broccoli-merge-trees');

return new Merge(
[
tree,
componentDocsTree,
],
{
overwrite: true,
}
);
},

outputReady: function(result) {
Expand Down

0 comments on commit 5e69c43

Please sign in to comment.