From 4a4e467825bfb46c5f1f9d748692866ccc3404bb Mon Sep 17 00:00:00 2001 From: Ala Hawash Date: Fri, 22 Mar 2024 19:08:34 +0200 Subject: [PATCH] use sectionsWithResources array per export stream --- packages/mdctl-cli/lib/env/export.js | 3 --- packages/mdctl-core/streams/export_stream.js | 3 ++- packages/mdctl-core/streams/section.js | 13 +++++-------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/mdctl-cli/lib/env/export.js b/packages/mdctl-cli/lib/env/export.js index 9572bef2..be747f5d 100644 --- a/packages/mdctl-cli/lib/env/export.js +++ b/packages/mdctl-cli/lib/env/export.js @@ -1,5 +1,4 @@ /* eslint-disable max-len */ -const { ExportSection } = require('@medable/mdctl-core/streams/section') const { Transform } = require('stream') const fs = require('fs'), @@ -181,8 +180,6 @@ const fs = require('fs'), return reject(new Error('Export not complete!')) } - ExportSection.clearSectionsWithResources() - if (options.docs) { console.log('Documenting env') return Docs.generateDocumentation({ diff --git a/packages/mdctl-core/streams/export_stream.js b/packages/mdctl-core/streams/export_stream.js index 3b0e56d5..3923f51f 100644 --- a/packages/mdctl-core/streams/export_stream.js +++ b/packages/mdctl-core/streams/export_stream.js @@ -12,6 +12,7 @@ class ExportStream extends Transform { }, options)) this.runtimes = [] this.completed = false + this.sectionsWithResources = [] } complete() { @@ -33,7 +34,7 @@ class ExportStream extends Transform { this.completed = true } if (this.checkKeys(chunk.object)) { - const section = new ExportSection(chunk, chunk.object) + const section = new ExportSection(chunk, chunk.object, this.sectionsWithResources) this.push(section) } else if (chunk.object === 'stream') { const section = new StreamChunk(chunk, chunk.object) diff --git a/packages/mdctl-core/streams/section.js b/packages/mdctl-core/streams/section.js index 68b9b36b..da123e73 100644 --- a/packages/mdctl-core/streams/section.js +++ b/packages/mdctl-core/streams/section.js @@ -37,17 +37,17 @@ const _ = require('lodash'), }, }, NON_WRITABLE_KEYS = ['facet'], - sectionsWithResources = [], { privatesAccessor } = require('@medable/mdctl-core-utils/privates'), crypto = require('crypto') class ExportSection { - constructor(content, key = '') { + constructor(content, key = '', sectionsWithResources) { Object.assign(privatesAccessor(this), { content, key, + sectionsWithResources, scriptFiles: [], extraFiles: [], templateFiles: [], @@ -59,17 +59,13 @@ class ExportSection { } if (this.isWritable) { const nodes = jp.nodes(content, '$..resourceId') - if (nodes.length > 0) { + if (Array.isArray(sectionsWithResources) && nodes.length > 0) { privatesAccessor(this).resourcePaths.push(...nodes) sectionsWithResources.push(this) } } } - static clearSectionsWithResources() { - sectionsWithResources.length = 0 - } - get id() { return privatesAccessor(this).id } @@ -194,7 +190,8 @@ class ExportSection { } extractAssets() { - const facet = privatesAccessor(this).content + const facet = privatesAccessor(this).content, + { sectionsWithResources } = privatesAccessor(this) let itemSource = null for (let i = 0; i < sectionsWithResources.length; i += 1) { const sc = sectionsWithResources[i],