diff --git a/packages/mdctl-core/streams/section.js b/packages/mdctl-core/streams/section.js index 3c611a15..68b9b36b 100644 --- a/packages/mdctl-core/streams/section.js +++ b/packages/mdctl-core/streams/section.js @@ -37,7 +37,7 @@ const _ = require('lodash'), }, }, NON_WRITABLE_KEYS = ['facet'], - SectionsCreated = [], + sectionsWithResources = [], { privatesAccessor } = require('@medable/mdctl-core-utils/privates'), crypto = require('crypto') @@ -51,16 +51,25 @@ class ExportSection { scriptFiles: [], extraFiles: [], templateFiles: [], + resourcePaths: [], id: uuid.v4() }) if (new.target === ExportSection) { Object.seal(this) } if (this.isWritable) { - SectionsCreated.push(this) + const nodes = jp.nodes(content, '$..resourceId') + if (nodes.length > 0) { + privatesAccessor(this).resourcePaths.push(...nodes) + sectionsWithResources.push(this) + } } } + static clearSectionsWithResources() { + sectionsWithResources.length = 0 + } + get id() { return privatesAccessor(this).id } @@ -85,6 +94,10 @@ class ExportSection { return privatesAccessor(this).templateFiles } + get resourcePaths() { + return privatesAccessor(this).resourcePaths + } + get name() { const { content, key } = privatesAccessor(this), { @@ -183,10 +196,9 @@ class ExportSection { extractAssets() { const facet = privatesAccessor(this).content let itemSource = null - for (let i = 0; i < SectionsCreated.length; i += 1) { - const sc = SectionsCreated[i], - nodes = jp.nodes(sc.content, '$..resourceId'), - item = _.find(nodes, n => n.value === facet.resourceId) + for (let i = 0; i < sectionsWithResources.length; i += 1) { + const sc = sectionsWithResources[i], + item = _.find(sc.resourcePaths, n => n.value === facet.resourceId) if (item) { // replace last path const ETagPathItem = _.clone(item.path)