Skip to content

Commit

Permalink
#354: Tested Migration to es6
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Midgley committed May 20, 2023
1 parent 1110982 commit 0cb5af7
Show file tree
Hide file tree
Showing 11 changed files with 1,959 additions and 624 deletions.
13 changes: 9 additions & 4 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6151,7 +6151,8 @@ Saves json content to a file in the local file system. Will create the parent di
<a name="File.writePrettyToFile"></a>

### File.writePrettyToFile(directory, filename, filetype, content, [templateVariables]) ⇒ <code>Promise.&lt;boolean&gt;</code>
Saves beautified files in the local file system. Will create the parent directory if it does not exist! Important: run 'await File.initPrettier()' in your MetadataType.retrieve() once before hitting this
Saves beautified files in the local file system. Will create the parent directory if it does not exist
! Important: run 'await File.initPrettier()' in your MetadataType.retrieve() once before hitting this

**Kind**: static method of [<code>File</code>](#File)
**Returns**: <code>Promise.&lt;boolean&gt;</code> - Promise
Expand Down Expand Up @@ -6179,7 +6180,8 @@ helper for [writePrettyToFile](#File.writePrettyToFile), applying beautyAmp onto
<a name="File._beautify_prettier"></a>

### File.\_beautify\_prettier(directory, filename, filetype, content) ⇒ <code>string</code>
helper for [writePrettyToFile](#File.writePrettyToFile), applying prettier onto given stringified content! Important: run 'await File.initPrettier()' in your MetadataType.retrieve() once before hitting this
helper for [writePrettyToFile](#File.writePrettyToFile), applying prettier onto given stringified content
! Important: run 'await File.initPrettier()' in your MetadataType.retrieve() once before hitting this

**Kind**: static method of [<code>File</code>](#File)
**Returns**: <code>string</code> - original string on error; formatted string on success
Expand Down Expand Up @@ -6240,7 +6242,8 @@ reads file from local file system.
<a name="File.readDirectories"></a>

### File.readDirectories(directory, depth, [includeStem], [_stemLength]) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
reads directories to a specific depth returning an arrayof file paths to be iterated over
reads directories to a specific depth returning an array
of file paths to be iterated over

**Kind**: static method of [<code>File</code>](#File)
**Returns**: <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> - array of fully defined file paths
Expand All @@ -6259,7 +6262,9 @@ reads directories to a specific depth returning an array of file paths to be ite
<a name="File.readDirectoriesSync"></a>

### File.readDirectoriesSync(directory, [depth], [includeStem], [_stemLength]) ⇒ <code>Array.&lt;string&gt;</code> \| <code>void</code>
reads directories to a specific depth returning an arrayof file paths to be iterated over using sync api (required in constructors)TODO - merge with readDirectories. so far the logic is really different
reads directories to a specific depth returning an array
of file paths to be iterated over using sync api (required in constructors)
TODO - merge with readDirectories. so far the logic is really different

**Kind**: static method of [<code>File</code>](#File)
**Returns**: <code>Array.&lt;string&gt;</code> \| <code>void</code> - array of fully defined file paths; void on error
Expand Down
35 changes: 2 additions & 33 deletions lib/metadataTypes/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import File from '../util/file.js';
import pLimit from 'p-limit';
import cliProgress from 'cli-progress';
import cache from '../util/cache.js';
import TriggeredSend from './TriggeredSend.js';

/**
* FileTransfer MetadataType
*
* @augments MetadataType
*/
class Asset extends MetadataType {
/**
* Retrieves Metadata of Asset
*
* @param {string} retrieveDir Directory where retrieved metadata directory will be saved
* @param {void} _ -
* @param {TYPE.AssetSubType[]} [subTypeArr] optionally limit to a single subtype
Expand Down Expand Up @@ -45,7 +44,6 @@ class Asset extends MetadataType {

/**
* Retrieves asset metadata for caching
*
* @param {void} _ unused
* @param {string[]} [subTypeArr] optionally limit to a single subtype
* @returns {Promise.<{metadata: TYPE.AssetMap, type: string}>} Promise
Expand All @@ -56,7 +54,6 @@ class Asset extends MetadataType {

/**
* Retrieves asset metadata for templating
*
* @param {string} templateDir Directory where retrieved metadata directory will be saved
* @param {string} name name of the metadata file
* @param {TYPE.TemplateMap} templateVariables variables to be replaced in the metadata
Expand Down Expand Up @@ -85,7 +82,6 @@ class Asset extends MetadataType {
}
/**
* helper for {@link retrieve} + {@link retrieveAsTemplate}
*
* @private
* @returns {TYPE.AssetSubType[]} subtype array
*/
Expand All @@ -108,7 +104,6 @@ class Asset extends MetadataType {

/**
* Creates a single asset
*
* @param {TYPE.AssetItem} metadata a single asset
* @returns {Promise} Promise
*/
Expand All @@ -120,7 +115,6 @@ class Asset extends MetadataType {

/**
* Updates a single asset
*
* @param {TYPE.AssetItem} metadata a single asset
* @returns {Promise} Promise
*/
Expand All @@ -130,7 +124,6 @@ class Asset extends MetadataType {
}
/**
* Retrieves Metadata of a specific asset type
*
* @param {TYPE.AssetSubType} subType group of similar assets to put in a folder (ie. images)
* @param {string} [retrieveDir] target directory for saving assets
* @param {string} [templateName] name of the metadata file
Expand Down Expand Up @@ -235,7 +228,7 @@ class Asset extends MetadataType {
rightOperand: {
property: 'id',
simpleOperator: 'greaterThan',
value: items[items.length - 1].id,
value: items.at(-1).id,
},
};
lastPage = 0;
Expand Down Expand Up @@ -273,7 +266,6 @@ class Asset extends MetadataType {
}
/**
* Retrieves extended metadata (files or extended content) of asset
*
* @param {Array} items array of items to retrieve
* @param {TYPE.AssetSubType} subType group of similar assets to put in a folder (ie. images)
* @param {string} retrieveDir target directory for saving assets
Expand Down Expand Up @@ -365,7 +357,6 @@ class Asset extends MetadataType {

/**
* helper that reset the log level and prints errors
*
* @private
* @param {'info'|'verbose'|'debug'|'error'} loggerLevelBak original logger level
* @param {object[]} failed array of failed items
Expand Down Expand Up @@ -424,7 +415,6 @@ class Asset extends MetadataType {
/**
* Some metadata types store their actual content as a separate file, e.g. images
* This method retrieves these and saves them alongside the metadata json
*
* @param {TYPE.AssetItem} metadata a single asset
* @param {TYPE.AssetSubType} subType group of similar assets to put in a folder (ie. images)
* @param {string} retrieveDir target directory for saving assets
Expand All @@ -449,7 +439,6 @@ class Asset extends MetadataType {
* helper for {@link preDeployTasks}
* Some metadata types store their actual content as a separate file, e.g. images
* This method reads these from the local FS stores them in the metadata object allowing to deploy it
*
* @param {TYPE.AssetItem} metadata a single asset
* @param {TYPE.AssetSubType} subType group of similar assets to put in a folder (ie. images)
* @param {string} deployDir directory of deploy files
Expand Down Expand Up @@ -484,7 +473,6 @@ class Asset extends MetadataType {
}
/**
* manages post retrieve steps
*
* @param {TYPE.AssetItem} metadata a single asset
* @returns {TYPE.CodeExtractItem} metadata
*/
Expand All @@ -498,7 +486,6 @@ class Asset extends MetadataType {

/**
* Gets executed after deployment of metadata type
*
* @param {TYPE.MetadataTypeMap} metadata metadata mapped by their keyField
* @param {TYPE.MetadataTypeMap} _ originalMetadata to be updated (contains additioanl fields)
* @param {{created: number, updated: number}} createdUpdated counter representing successful creates/updates
Expand All @@ -520,7 +507,6 @@ class Asset extends MetadataType {

/**
* helper for {@link postDeployTasks}. triggers a refresh of active triggerredSendDefinitions associated with the updated asset-message items. Gets executed if isRefresh is true.
*
* @private
* @param {TYPE.MetadataTypeMap} metadata metadata mapped by their keyField
* @returns {Promise.<void>} -
Expand All @@ -538,7 +524,6 @@ class Asset extends MetadataType {
return;
}
// prep triggeredSendDefinition class
const TriggeredSend = require('./TriggeredSend');
TriggeredSend.properties = this.properties;
TriggeredSend.buObject = this.buObject;
TriggeredSend.client = this.client;
Expand Down Expand Up @@ -570,7 +555,6 @@ class Asset extends MetadataType {

/**
* prepares an asset definition for deployment
*
* @param {TYPE.AssetItem} metadata a single asset
* @param {string} deployDir directory of deploy files
* @returns {Promise.<TYPE.AssetItem>} Promise
Expand Down Expand Up @@ -632,7 +616,6 @@ class Asset extends MetadataType {
}
/**
* find the subType matching the extendedSubType
*
* @param {string} extendedSubType webpage, htmlblock, etc
* @returns {string} subType: block, message, other, etc
*/
Expand All @@ -643,7 +626,6 @@ class Asset extends MetadataType {
}
/**
* helper to find a new unique name during asset creation
*
* @private
* @param {string} key key of the asset
* @param {string} name name of the asset
Expand All @@ -669,7 +651,6 @@ class Asset extends MetadataType {
}
/**
* determines the subtype of the current asset
*
* @private
* @param {TYPE.AssetItem} metadata a single asset
* @returns {TYPE.AssetSubType | void} subtype
Expand All @@ -684,7 +665,6 @@ class Asset extends MetadataType {
/**
* helper for {@link MetadataType.buildDefinition}
* handles extracted code if any are found for complex types
*
* @param {string} templateDir Directory where metadata templates are stored
* @param {string} targetDir Directory where built definitions will be saved
* @param {TYPE.AssetItem} metadata main JSON file that was read from file system
Expand All @@ -711,7 +691,6 @@ class Asset extends MetadataType {
/**
* helper for {@link MetadataType.buildTemplate}
* handles extracted code if any are found for complex types
*
* @example assets of type codesnippetblock will result in 1 json and 1 amp/html file. both files need to be run through templating
* @param {string} templateDir Directory where metadata templates are stored
* @param {string|string[]} targetDir (List of) Directory where built definitions will be saved
Expand Down Expand Up @@ -740,7 +719,6 @@ class Asset extends MetadataType {
/**
* helper for {@link MetadataType.buildDefinition}
* handles extracted code if any are found for complex types
*
* @param {string} templateDir Directory where metadata templates are stored
* @param {string} targetDir Directory where built definitions will be saved
* @param {TYPE.AssetItem} metadata main JSON file that was read from file system
Expand Down Expand Up @@ -832,7 +810,6 @@ class Asset extends MetadataType {
}
/**
* generic script that retrieves the folder path from cache and updates the given metadata with it after retrieve
*
* @param {TYPE.MetadataTypeItem} metadata a single script activity definition
*/
static setFolderPath(metadata) {
Expand All @@ -854,7 +831,6 @@ class Asset extends MetadataType {
}
/**
* Asset-specific script that retrieves the folder ID from cache and updates the given metadata with it before deploy
*
* @param {TYPE.MetadataTypeItem} metadata a single item
*/
static setFolderId(metadata) {
Expand All @@ -866,7 +842,6 @@ class Asset extends MetadataType {

/**
* helper for {@link preDeployTasks} that loads extracted code content back into JSON
*
* @param {TYPE.AssetItem} metadata a single asset definition
* @param {string} deployDir directory of deploy files
* @param {TYPE.AssetSubType} subType asset-subtype name
Expand Down Expand Up @@ -1150,7 +1125,6 @@ class Asset extends MetadataType {
}
/**
* helper for {@link preDeployTasks} that loads extracted code content back into JSON
*
* @param {string} prefix usually the customerkey
* @param {object} metadataSlots metadata.views.html.slots or deeper slots.<>.blocks.<>.slots
* @param {string[]} readDirArr directory of deploy files
Expand Down Expand Up @@ -1231,7 +1205,6 @@ class Asset extends MetadataType {
/**
* helper for {@link postRetrieveTasks} that finds code content in JSON and extracts it
* to allow saving that separately and formatted
*
* @param {TYPE.AssetItem} metadata a single asset definition
* @returns {TYPE.CodeExtractItem} { json: metadata, codeArr: object[], subFolder: string[] }
*/
Expand Down Expand Up @@ -1426,7 +1399,6 @@ class Asset extends MetadataType {
}
/**
* Returns file contents mapped to their fileName without '.json' ending
*
* @param {string} dir directory that contains '.json' files to be read
* @param {void} [_] unused parameter
* @param {string[]} selectedSubType asset, message, ...
Expand Down Expand Up @@ -1495,7 +1467,6 @@ class Asset extends MetadataType {
}
/**
* check template directory for complex types that open subfolders for their subtypes
*
* @param {string} templateDir Directory where metadata templates are stored
* @param {string} templateName name of the metadata file
* @returns {Promise.<TYPE.AssetSubType>} subtype name
Expand Down Expand Up @@ -1529,7 +1500,6 @@ class Asset extends MetadataType {
}
/**
* optional method used for some types to try a different folder structure
*
* @param {string} templateDir Directory where metadata templates are stored
* @param {string[]} typeDirArr current subdir for this type
* @param {string} templateName name of the metadata template
Expand All @@ -1544,7 +1514,6 @@ class Asset extends MetadataType {
/**
* should return only the json for all but asset, query and script that are saved as multiple files
* additionally, the documentation for dataExtension and automation should be returned
*
* @param {string[]} keyArr customerkey of the metadata
* @returns {string[]} list of all files that need to be committed in a flat array ['path/file1.ext', 'path/file2.ext']
*/
Expand Down
Loading

0 comments on commit 0cb5af7

Please sign in to comment.