From 224b7a15c3a4f2934c079861677c12c6564e0565 Mon Sep 17 00:00:00 2001 From: Andreas Rohner Date: Fri, 26 Feb 2016 15:29:36 +0100 Subject: [PATCH] Add after-property to allow ordering of plugins Some plugins do not depend on each other and can be used independently, but if they are used at the same time, they have to be executed in a specific order. The "after"-property in components.js, allows the download page to concatenate the plugins in the right order, without enforcing a hard dependency. --- components.js | 2 ++ download.js | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/components.js b/components.js index d8335438e5..f87b04f20f 100644 --- a/components.js +++ b/components.js @@ -606,6 +606,7 @@ var components = { "keep-markup": { "title": "Keep Markup", "owner": "Golmote", + "after": "normalize-whitespace", "noCSS": true }, "command-line": { @@ -616,6 +617,7 @@ var components = { "normalize-whitespace": { "title": "Normalize Whitespace", "owner": "zeitgeist87", + "after": "unescaped-markup", "noCSS": true } } diff --git a/download.js b/download.js index a8c9e97c71..4e828e486c 100644 --- a/download.js +++ b/download.js @@ -117,6 +117,7 @@ for (var category in components) { noJS: all[id].noJS || all.meta.noJS, enabled: checked, require: $u.type(all[id].require) === 'string' ? [all[id].require] : all[id].require, + after: $u.type(all[id].after) === 'string' ? [all[id].after] : all[id].after, owner: all[id].owner, files: { minified: { @@ -374,18 +375,21 @@ function delayedGenerateCode(){ timerId = setTimeout(generateCode, 500); } -function getSortedComponentsByRequirements(components){ - var sorted = []; - for (var component in components) { - sorted.push(component); +function getSortedComponents(components, requireName, sorted) { + if (!sorted) { + sorted = []; + for (var component in components) { + sorted.push(component); + } } + var i = 0; while (i < sorted.length) { var id = sorted[i]; var indexOfRequirement = i; var notNow = false; - for (var requirement in components[id].require) { - indexOfRequirement = sorted.indexOf(components[id].require[requirement]); + for (var requirement in components[id][requireName]) { + indexOfRequirement = sorted.indexOf(components[id][requireName][requirement]); if (indexOfRequirement > i) { notNow = true; break; @@ -403,6 +407,11 @@ function getSortedComponentsByRequirements(components){ return sorted; } +function getSortedComponentsByRequirements(components){ + var sorted = getSortedComponents(components, "after"); + return getSortedComponents(components, "require", sorted); +} + function generateCode(){ var promises = []; var redownload = {};