Repository: Accenture/sfmc-devtools
Pull request #538 (2022-11-09 11:02:59)

4.1.11
release


Patch:
diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml
index 9d6b6042..a6813c6d 100644
--- a/.github/ISSUE_TEMPLATE/bug.yml
+++ b/.github/ISSUE_TEMPLATE/bug.yml
@@ -39,6 +39,7 @@ body:
           label: Version
           description: What version of our software are you running? (mcdev --version)
           options:
+              - 4.1.11
               - 4.1.10
               - 4.1.9
               - 4.1.8
diff --git a/README.md b/README.md
index 6ace4197..da30f3e7 100644
--- a/README.md
+++ b/README.md
@@ -123,7 +123,7 @@ If you experience issues installing Accenture SFMC DevTools, please check out th
 1. Install Accenture SFMC DevTools by running `npm install -g mcdev` (prefix with `sudo` on MacOS)
    - If you get an error, please see the below troubleshooting section.
 
-When completed run `mcdev --version` and it will show you which version you installed (e.g. `4.1.10`).
+When completed run `mcdev --version` and it will show you which version you installed (e.g. `4.1.11`).
 
 > **_Side note for proud nerds_:**
 >
@@ -277,10 +277,10 @@ _Note: Regardless of which tag or branch you install_
 **Install specific version (using a version tag on npm):**
 
 ```bash
-npm install -g mcdev@4.1.10
+npm install -g mcdev@4.1.11
 ```
 
-**Warning**: When you used the above method to install Accenture SFMC DevTools for a specific version or tag, trying to [update Accenture SFMC DevTools](#updating-mcdev) might not download the most recently published official version but instead stay on the version or branch you previously selected (in the above examples: develop, 4.1.10)!
+**Warning**: When you used the above method to install Accenture SFMC DevTools for a specific version or tag, trying to [update Accenture SFMC DevTools](#updating-mcdev) might not download the most recently published official version but instead stay on the version or branch you previously selected (in the above examples: develop, 4.1.11)!
 
 > **Note**: The version is currently _not_ updated on the developer branch until a new release is published. Hence, you will not see a change if you run `mcdev --version`.
 
@@ -1505,7 +1505,7 @@ Assuming you cloned Accenture SFMC DevTools into `C:\repos\sfmc-devtools\` (or `
 
 This should tell npm to create a symlink to your cloned local directory, allowing you to see updates you make in your mcdev repo instantly.
 
-To test your new **global** developer setup, run `mcdev --version` in CLI which should return the current version (e.g. `4.1.10`). Then, go into your mcdev repo and update the version with the suffix `-dev`, e.g. to `4.1.10-dev` and then run `mcdev --version` again to verify that your change propagates instantly.
+To test your new **global** developer setup, run `mcdev --version` in CLI which should return the current version (e.g. `4.1.11`). Then, go into your mcdev repo and update the version with the suffix `-dev`, e.g. to `4.1.11-dev` and then run `mcdev --version` again to verify that your change propagates instantly.
 
 > **Not recommended:** Alternatively, you can install it locally only by opening a terminal in your project directory and executing `npm install --save-dev "C:\repos\sfmc-devtools"`
 > To run the local version you need to prepend "npx" before your commands, e.g. `npx mcdev --version`
@@ -1543,7 +1543,7 @@ The following explains how you _could_ install it locally for certain edge cases
 4. Afterwards, install Accenture SFMC DevTools by running `npm install --save-dev mcdev`
    - If you get an error, please see the below troubleshooting section.
 
-When completed run `mcdev --version` and it will show you which version you installed (e.g. `4.1.10`).
+When completed run `mcdev --version` and it will show you which version you installed (e.g. `4.1.11`).
 
 ### 9.3. NPM Scripts
 
diff --git a/docs/dist/documentation.md b/docs/dist/documentation.md
index c160e156..b3a83618 100644
--- a/docs/dist/documentation.md
+++ b/docs/dist/documentation.md
@@ -4105,6 +4105,7 @@ Script MetadataType
     * [.buildTemplateForNested(templateDir, targetDir, metadata, templateVariables, templateName)](#Script.buildTemplateForNested) ⇒ <code>Promise.&lt;Array.&lt;Array.&lt;string&gt;&gt;&gt;</code>
     * [._buildForNested(templateDir, targetDir, metadata, templateVariables, templateName, mode)](#Script._buildForNested) ⇒ <code>Promise.&lt;Array.&lt;Array.&lt;string&gt;&gt;&gt;</code>
     * [.parseMetadata(metadata)](#Script.parseMetadata) ⇒ <code>TYPE.CodeExtractItem</code>
+    * [.prepExtractedCode(metadataScript, metadataName)](#Script.prepExtractedCode) ⇒ <code>Object</code>
     * [.getFilesToCommit(keyArr)](#Script.getFilesToCommit) ⇒ <code>Array.&lt;string&gt;</code>
 
 <a name="Script.retrieve"></a>
@@ -4276,6 +4277,19 @@ Splits the script metadata into two parts and parses in a standard manner
 | --- | --- | --- |
 | metadata | <code>TYPE.ScriptItem</code> | a single script activity definition |
 
+<a name="Script.prepExtractedCode"></a>
+
+### Script.prepExtractedCode(metadataScript, metadataName) ⇒ <code>Object</code>
+helper for [parseMetadata](parseMetadata) and [_buildForNested](_buildForNested)
+
+**Kind**: static method of [<code>Script</code>](#Script)  
+**Returns**: <code>Object</code> - returns found extension and file content  
+
+| Param | Type | Description |
+| --- | --- | --- |
+| metadataScript | <code>string</code> | the code of the file |
+| metadataName | <code>string</code> | the name of the metadata |
+
 <a name="Script.getFilesToCommit"></a>
 
 ### Script.getFilesToCommit(keyArr) ⇒ <code>Array.&lt;string&gt;</code>
diff --git a/lib/metadataTypes/Script.js b/lib/metadataTypes/Script.js
index 867bfd39..809f72b7 100644
--- a/lib/metadataTypes/Script.js
+++ b/lib/metadataTypes/Script.js
@@ -214,6 +214,11 @@ class Script extends MetadataType {
     ) {
         // get SSJS from filesystem
         let code = await this._mergeCode(metadata, templateDir, templateName);
+        // try to remove script tags and decide on file extension (html/ssjs)
+        const file = Script.prepExtractedCode(code, metadata.name);
+        const fileExt = file.fileExt;
+        code = fileExt === 'ssjs' ? file.code.replace(/^\n/, '') : file.code;
+        // apply templating
         try {
             if (mode === 'definition') {
                 // replace template variables with their values
@@ -241,13 +246,13 @@ class Script extends MetadataType {
             File.writeToFile(
                 [targetDir, this.definition.type],
                 fileName + '.' + this.definition.type + '-meta',
-                'ssjs',
+                fileExt,
                 code
             );
             nestedFilePaths.push([
                 targetDir,
                 this.definition.type,
-                fileName + '.' + this.definition.type + '-meta.ssjs',
+                fileName + '.' + this.definition.type + '-meta.' + fileExt,
             ]);
         }
         return nestedFilePaths;
@@ -266,30 +271,42 @@ class Script extends MetadataType {
         // extract SSJS
         const codeArr = [];
         // keep between tags
+        const { fileExt, code } = Script.prepExtractedCode(metadata.script, metadata.name);
+        delete metadata.script;
+        codeArr.push({
+            subFolder: null,
+            fileName: metadata.key,
+            fileExt: fileExt,
+            content: code,
+        });
+
+        return { json: metadata, codeArr: codeArr, subFolder: null };
+    }
+    /**
+     * helper for {@link parseMetadata} and {@link _buildForNested}
+     *
+     * @param {string} metadataScript the code of the file
+     * @param {string} metadataName the name of the metadata
+     * @returns {{fileExt:string,code:string}} returns found extension and file content
+     */
+    static prepExtractedCode(metadataScript, metadataName) {
         const regex = /<\s*script .*?>(.+?)<\s*\/script>/gms;
-        let ssjs;
+        let code;
         let fileExt;
-        const regexMatches = regex.exec(metadata.script);
+        const regexMatches = regex.exec(metadataScript);
         if (regexMatches?.length > 1) {
-            ssjs = regexMatches[1];
+            code = regexMatches[1];
             fileExt = 'ssjs';
         } else {
-            ssjs = metadata.script;
+            code = metadataScript;
             fileExt = 'html';
             Util.logger.warn(
-                ` - Could not find script tags, saving code in ${metadata.name}.script-meta.html instead of as SSJS file.`
+                ` - Could not find script tags, saving code in ${metadataName}.script-meta.html instead of as SSJS file.`
             );
         }
-        delete metadata.script;
-        codeArr.push({
-            subFolder: null,
-            fileName: metadata.key,
-            fileExt: fileExt,
-            content: ssjs,
-        });
-
-        return { json: metadata, codeArr: codeArr, subFolder: null };
+        return { fileExt, code };
     }
+
     /**
      * 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
diff --git a/package-lock.json b/package-lock.json
index 28eea2e4..e3e00d61 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
 {
     "name": "mcdev",
-    "version": "4.1.10",
+    "version": "4.1.11",
     "lockfileVersion": 2,
     "requires": true,
     "packages": {
         "": {
             "name": "mcdev",
-            "version": "4.1.10",
+            "version": "4.1.11",
             "license": "MIT",
             "dependencies": {
                 "cli-progress": "3.11.2",
@@ -36,10 +36,10 @@
                 "assert": "2.0.0",
                 "axios-mock-adapter": "1.21.2",
                 "chai": "4.3.6",
-                "eslint": "8.26.0",
+                "eslint": "8.27.0",
                 "eslint-config-prettier": "8.5.0",
                 "eslint-config-ssjs": "1.1.11",
-                "eslint-plugin-jsdoc": "39.4.0",
+                "eslint-plugin-jsdoc": "39.6.2",
                 "eslint-plugin-mocha": "10.1.0",
                 "eslint-plugin-prettier": "4.2.1",
                 "eslint-plugin-unicorn": "44.0.2",
@@ -326,9 +326,9 @@
             }
         },
         "node_modules/@es-joy/jsdoccomment": {
-            "version": "0.33.4",
-            "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.33.4.tgz",
-            "integrity": "sha512-02XyYuvR/Gn+3BT6idHVNQ4SSQlA1X1FeEfeKm2ypv8ANB6Lt9KRFZ2S7y5xjwR+EPQ/Rzb0XFaD+xKyqe4ALw==",
+            "version": "0.36.0",
+            "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.36.0.tgz",
+            "integrity": "sha512-u0XZyvUF6Urb2cSivSXA8qXIpT/CxkHcdtZKoWusAzgzmsTWpg0F2FpWXsolHmMUyVY3dLWaoy+0ccJ5uf2QjA==",
             "dev": true,
             "dependencies": {
                 "comment-parser": "1.3.1",
@@ -2642,9 +2642,9 @@
             }
         },
         "node_modules/eslint": {
-            "version": "8.26.0",
-            "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.26.0.tgz",
-            "integrity": "sha512-kzJkpaw1Bfwheq4VXUezFriD1GxszX6dUekM7Z3aC2o4hju+tsR/XyTC3RcoSD7jmy9VkPU3+N6YjVU2e96Oyg==",
+            "version": "8.27.0",
+            "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.27.0.tgz",
+            "integrity": "sha512-0y1bfG2ho7mty+SiILVf9PfuRA49ek4Nc60Wmmu62QlobNR+CeXa4xXIJgcuwSQgZiWaPH+5BDsctpIW0PR/wQ==",
             "dev": true,
             "dependencies": {
                 "@eslint/eslintrc": "^1.3.3",
@@ -2725,12 +2725,12 @@
             }
         },
         "node_modules/eslint-plugin-jsdoc": {
-            "version": "39.4.0",
-            "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-39.4.0.tgz",
-            "integrity": "sha512-2FXAmh8lpO22aqZgu6NLB6berVnYgwbZx95BmjIIQjbRNwLIAwY0dtvSJDUZVW5nflv58c1gSWQjIJ8yLZ/+fw==",
+            "version": "39.6.2",
+            "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-39.6.2.tgz",
+            "integrity": "sha512-dvgY/W7eUFoAIIiaWHERIMI61ZWqcz9YFjEeyTzdPlrZc3TY/3aZm5aB91NUoTLWYZmO/vFlYSuQi15tF7uE5A==",
             "dev": true,
             "dependencies": {
-                "@es-joy/jsdoccomment": "~0.33.4",
+                "@es-joy/jsdoccomment": "~0.36.0",
                 "comment-parser": "1.3.1",
                 "debug": "^4.3.4",
                 "escape-string-regexp": "^4.0.0",
@@ -8938,9 +8938,9 @@
             }
         },
         "@es-joy/jsdoccomment": {
-            "version": "0.33.4",
-            "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.33.4.tgz",
-            "integrity": "sha512-02XyYuvR/Gn+3BT6idHVNQ4SSQlA1X1FeEfeKm2ypv8ANB6Lt9KRFZ2S7y5xjwR+EPQ/Rzb0XFaD+xKyqe4ALw==",
+            "version": "0.36.0",
+            "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.36.0.tgz",
+            "integrity": "sha512-u0XZyvUF6Urb2cSivSXA8qXIpT/CxkHcdtZKoWusAzgzmsTWpg0F2FpWXsolHmMUyVY3dLWaoy+0ccJ5uf2QjA==",
             "dev": true,
             "requires": {
                 "comment-parser": "1.3.1",
@@ -10710,9 +10710,9 @@
             "dev": true
         },
         "eslint": {
-            "version": "8.26.0",
-            "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.26.0.tgz",
-            "integrity": "sha512-kzJkpaw1Bfwheq4VXUezFriD1GxszX6dUekM7Z3aC2o4hju+tsR/XyTC3RcoSD7jmy9VkPU3+N6YjVU2e96Oyg==",
+            "version": "8.27.0",
+            "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.27.0.tgz",
+            "integrity": "sha512-0y1bfG2ho7mty+SiILVf9PfuRA49ek4Nc60Wmmu62QlobNR+CeXa4xXIJgcuwSQgZiWaPH+5BDsctpIW0PR/wQ==",
             "dev": true,
             "requires": {
                 "@eslint/eslintrc": "^1.3.3",
@@ -10791,12 +10791,12 @@
             "requires": {}
         },
         "eslint-plugin-jsdoc": {
-            "version": "39.4.0",
-            "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-39.4.0.tgz",
-            "integrity": "sha512-2FXAmh8lpO22aqZgu6NLB6berVnYgwbZx95BmjIIQjbRNwLIAwY0dtvSJDUZVW5nflv58c1gSWQjIJ8yLZ/+fw==",
+            "version": "39.6.2",
+            "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-39.6.2.tgz",
+            "integrity": "sha512-dvgY/W7eUFoAIIiaWHERIMI61ZWqcz9YFjEeyTzdPlrZc3TY/3aZm5aB91NUoTLWYZmO/vFlYSuQi15tF7uE5A==",
             "dev": true,
             "requires": {
-                "@es-joy/jsdoccomment": "~0.33.4",
+                "@es-joy/jsdoccomment": "~0.36.0",
                 "comment-parser": "1.3.1",
                 "debug": "^4.3.4",
                 "escape-string-regexp": "^4.0.0",
diff --git a/package.json b/package.json
index 8a0ea83a..abb1beef 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
     "name": "mcdev",
-    "version": "4.1.10",
+    "version": "4.1.11",
     "description": "Accenture Salesforce Marketing Cloud DevTools",
     "author": "Accenture: joern.berkefeld, douglas.midgley, robert.zimmermann, maciej.barnas",
     "license": "MIT",
@@ -64,10 +64,10 @@
         "assert": "2.0.0",
         "axios-mock-adapter": "1.21.2",
         "chai": "4.3.6",
-        "eslint": "8.26.0",
+        "eslint": "8.27.0",
         "eslint-config-prettier": "8.5.0",
         "eslint-config-ssjs": "1.1.11",
-        "eslint-plugin-jsdoc": "39.4.0",
+        "eslint-plugin-jsdoc": "39.6.2",
         "eslint-plugin-mocha": "10.1.0",
         "eslint-plugin-prettier": "4.2.1",
         "eslint-plugin-unicorn": "44.0.2",


Test patch:
diff --git a/test/mockRoot/.mcdevrc.json b/test/mockRoot/.mcdevrc.json
index 127fb32b..e1859329 100644
--- a/test/mockRoot/.mcdevrc.json
+++ b/test/mockRoot/.mcdevrc.json
@@ -63,5 +63,5 @@
             "triggeredSendDefinition"
         ]
     },
-    "version": "4.1.10"
+    "version": "4.1.11"
 }