Skip to content

Plugin fixes #1077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions packages/core/src/lib/plugin_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const plugin_manager = function() {
const path = require('path');
const findModules = require('./findModules');
const logger = require('./log');

const pluginMatcher = /^plugin-(.*)$/;
Expand Down Expand Up @@ -38,25 +37,25 @@ const plugin_manager = function() {
* @param {object} patternlab
*/
function initializePlugins(patternlab) {
const nodeModulesPath = path.join(process.cwd(), 'node_modules');
const foundPlugins = findModules(nodeModulesPath, isPlugin);
const foundPlugins = Object.keys(patternlab.config.plugins || {});
foundPlugins.forEach(plugin => {
logger.info(`Found plugin: plugin-${plugin.name}`);
logger.info(`Found plugin: ${plugin}`);
logger.info(`Attempting to load and initialize plugin.`);
const pluginModule = loadPlugin(plugin.modulePath);
const pluginModule = loadPlugin(
path.join(process.cwd(), 'node_modules', plugin)
);
pluginModule(patternlab);
});
}

async function raiseEvent(patternlab, eventName, ...args) {
async function raiseEvent(patternlab, eventName, args) {
patternlab.events.emit(eventName, args);

await (async function() {
const hookHandlers = (patternlab.hooks[eventName] || []).map(h =>
h(args)
);

const results = await Promise.all(hookHandlers);
await Promise.all(hookHandlers);
})();
}

Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-tab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function writeConfigToOutput(patternlab, pluginConfig) {
}
}

async function onPatternIterate(patternlab, pattern) {
async function onPatternIterate(params) {
const [patternlab, pattern] = params;
await tab_loader(patternlab, pattern);
}

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions packages/uikit-workshop/src/scripts/components/panels-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,27 @@ export const panelsViewer = {
const e = new XMLHttpRequest();
// @todo: look deeper into how we can refactor this particular code block
/* eslint-disable */
e.onload = (function(i, panels, patternData, iframeRequest) {
return function() {
e.onload = (function (i, panels, patternData, iframeRequest) {
return function () {

// since non-existant files (such as .scss from plugin-tab) still return a 200, we need to instead inspect the contents
// we look for responseText that starts with the doctype
let rText = this.responseText
if (rText.startsWith('<!DOCTYPE html>')) {
rText = ''
}

// use pretty to format HTML
if (panels[i].name === 'HTML') {
templateFormatted = pretty(this.responseText, { ocd: true });
templateFormatted = pretty(rText, { ocd: true });
} else {
templateFormatted = this.responseText;
templateFormatted = rText;
}

const templateHighlighted = Prism.highlight(
templateFormatted,
Prism.languages[panels[i].name.toLowerCase()] ||
Prism.languages['markup']
Prism.languages['markup']
// Prism.languages[panels[i].name.toLowerCase()],
);

Expand Down