Skip to content

Commit

Permalink
use sectionsWithResources array per export stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Ala Hawash committed Mar 22, 2024
1 parent 4543cd0 commit 4a4e467
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
3 changes: 0 additions & 3 deletions packages/mdctl-cli/lib/env/export.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable max-len */
const { ExportSection } = require('@medable/mdctl-core/streams/section')
const { Transform } = require('stream')

const fs = require('fs'),
Expand Down Expand Up @@ -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({
Expand Down
3 changes: 2 additions & 1 deletion packages/mdctl-core/streams/export_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ExportStream extends Transform {
}, options))
this.runtimes = []
this.completed = false
this.sectionsWithResources = []
}

complete() {
Expand All @@ -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)
Expand Down
13 changes: 5 additions & 8 deletions packages/mdctl-core/streams/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand All @@ -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
}
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit 4a4e467

Please sign in to comment.