Skip to content

Commit

Permalink
#361: upgrade to es6 modules + mcdev 6
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Sep 28, 2023
1 parent d68cb3d commit facc448
Show file tree
Hide file tree
Showing 22 changed files with 3,120 additions and 6,503 deletions.
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
"files": "*.{cmp,page,component}",
"options": { "parser": "html" }
},
{
"files": "package.json",
"options": {
"printWidth": 40
}
},
{
"files": "package-lock.json",
"options": {
"printWidth": 40
}
},
{
"files": "*.json",
"options": {
Expand Down
13 changes: 8 additions & 5 deletions copado-function/app/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
{
"env": {
"es6": true,
"node": true,
"mocha": true
"node": true
},
"extends": [
"eslint:recommended",
"plugin:jsdoc/recommended",
"plugin:prettier/recommended",
"plugin:unicorn/recommended"
],
"plugins": [],
"plugins": ["prettier"],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2020,
"ecmaVersion": 2022,
"sourceType": "module"
},
"root": true,
Expand All @@ -41,6 +40,7 @@
}
},
"rules": {
"logical-assignment-operators": ["error", "always"],
"unicorn/better-regex": "off",
"unicorn/catch-error-name": [
"error",
Expand Down Expand Up @@ -81,6 +81,8 @@
}
}
],
"jsdoc/require-param-type": "error",
"jsdoc/tag-lines": ["warn", "any", { "startLines": 1 }],
"spaced-comment": ["warn", "always", { "block": { "exceptions": ["*"], "balanced": true } }]
},
"overrides": [
Expand All @@ -99,7 +101,8 @@
"extends": ["plugin:mocha/recommended"],
"plugins": ["mocha"],
"rules": {
"mocha/no-mocha-arrows": "off"
"mocha/no-mocha-arrows": "off",
"mocha/no-pending-tests": "off"
}
}
]
Expand Down
1 change: 1 addition & 0 deletions copado-function/app/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"tabWidth": 4,
"printWidth": 100,
"singleQuote": true,
"trailingComma": "es5",
"overrides": [
{
"files": "*.json",
Expand Down
14 changes: 7 additions & 7 deletions copado-function/app/Commit.fn.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env node
'use strict';

const resolve = require('node:path').resolve;
const TYPE = require('./types/mcdev-copado.d');
const CONFIG = require('./common/Config');
const Log = require('./common/Log');
const Util = require('./common/Util');
const Copado = require('./common/Copado');
const Commit = require('./common/Commit');
import { resolve } from 'node:path';
import TYPE from './types/mcdev-copado.d.js';
import CONFIG from './common/Config.js';
import Log from './common/Log.js';
import Util from './common/Util.js';
import Copado from './common/Copado.js';
import Commit from './common/Commit.js';

// ++++ CONFIG ++++
CONFIG.mcdevCopadoVersion = '[VI]{{inject}}[/VI]';
Expand Down
22 changes: 10 additions & 12 deletions copado-function/app/Deploy.fn.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/env node
'use strict';

const fs = require('node:fs');
const execSync = require('node:child_process').execSync;
const resolve = require('node:path').resolve;
const TYPE = require('./types/mcdev-copado.d');
const CONFIG = require('./common/Config');
const Log = require('./common/Log');
const Util = require('./common/Util');
const Copado = require('./common/Copado');
const Commit = require('./common/Commit');
import fs from 'node:fs';
import { execSync } from 'node:child_process';
import { resolve } from 'node:path';
import TYPE from './types/mcdev-copado.d.js';
import CONFIG from './common/Config.js';
import Log from './common/Log.js';
import Util from './common/Util.js';
import Copado from './common/Copado.js';
import Commit from './common/Commit.js';
import mcdev from 'mcdev';

// ++++ CONFIG ++++
CONFIG.mcdevCopadoVersion = '[VI]{{inject}}[/VI]';
Expand Down Expand Up @@ -549,7 +550,6 @@ class Deploy {
* @returns {Promise.<boolean>} true: files found, false: not
*/
static async createDeltaPackage(deployFolder, commitSelectionArr, sourceBU) {
const mcdev = require('../tmp/node_modules/mcdev/lib');
// ensure wizard is not started
mcdev.setSkipInteraction(true);

Expand Down Expand Up @@ -627,8 +627,6 @@ class Deploy {
* @returns {object} deployResult
*/
static async deployBU(bu) {
// * dont use CONFIG.tempDir here to allow proper resolution of required package in VSCode
const mcdev = require('../tmp/node_modules/mcdev/lib');
// ensure wizard is not started
mcdev.setSkipInteraction(true);
const deployResult = await mcdev.deploy(bu);
Expand Down
10 changes: 5 additions & 5 deletions copado-function/app/Init.fn.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env node
'use strict';

const resolve = require('node:path').resolve;
const CONFIG = require('./common/Config');
const Log = require('./common/Log');
const Util = require('./common/Util');
const Copado = require('./common/Copado');
import { resolve } from 'node:path';
import CONFIG from './common/Config.js';
import Log from './common/Log.js';
import Util from './common/Util.js';
import Copado from './common/Copado.js';

// credentials
CONFIG.credentialNameSource = process.env.credentialNameSource;
Expand Down
25 changes: 13 additions & 12 deletions copado-function/app/Retrieve.fn.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/usr/bin/env node
'use strict';

const fs = require('node:fs');
const resolve = require('node:path').resolve;
const TYPE = require('./types/mcdev-copado.d');
const CONFIG = require('./common/Config');
const Log = require('./common/Log');
const Util = require('./common/Util');
const Copado = require('./common/Copado');
import fs from 'node:fs';
import { resolve } from 'node:path';
import TYPE from './types/mcdev-copado.d.js';
import CONFIG from './common/Config.js';
import Log from './common/Log.js';
import Util from './common/Util.js';
import Copado from './common/Copado.js';

import mcdev from 'mcdev';
import Definition from 'mcdev/lib/MetadataTypeDefinitions.js';
import MetadataType from 'mcdev/lib/MetadataTypeInfo.js';

// ++++ CONFIG ++++
CONFIG.mcdevCopadoVersion = '[VI]{{inject}}[/VI]';
Expand Down Expand Up @@ -217,9 +221,6 @@ class Retrieve {
*/
static async retrieveChangelog(sourceBU) {
// * dont use CONFIG.tempDir here to allow proper resolution of required package in VSCode
const mcdev = require('../tmp/node_modules/mcdev/lib');
const Definition = require('../tmp/node_modules/mcdev/lib/MetadataTypeDefinitions');
const MetadataType = require('../tmp/node_modules/mcdev/lib/MetadataTypeInfo');
if (!CONFIG.debug) {
// disable any non-errors originating in mcdev from being printed into the main copado logfile
mcdev.setLoggingLevel({ silent: true });
Expand All @@ -238,11 +239,11 @@ class Retrieve {
},
};
// get userid>name mapping
const retrieve = await mcdev.retrieve(sourceBU, ['accountUser'], null, true);
const retrieve = await mcdev.retrieve(sourceBU, ['user'], null, true);
if (!retrieve) {
throw new Error('Could not retrieve User List');
}
const userList = retrieve.accountUser;
const userList = retrieve.user;
// reduce userList to simple id-name map
for (const key of Object.keys(userList)) {
userList[userList[key].ID] = userList[key].Name;
Expand Down
17 changes: 8 additions & 9 deletions copado-function/app/common/Commit.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';
const fs = require('node:fs');
const execSync = require('node:child_process').execSync;
import fs from 'node:fs';
import { execSync } from 'node:child_process';

const TYPE = require('../types/mcdev-copado.d');
const CONFIG = require('./Config');
const Log = require('./Log');
const Util = require('./Util');
import TYPE from '../types/mcdev-copado.d.js';
import CONFIG from './Config.js';
import Log from './Log.js';
import Util from './Util.js';
import mcdev from 'mcdev';

/**
* methods to handle interaction with the copado platform
Expand All @@ -21,8 +22,6 @@ class Commit {
* @returns {Promise.<string[]>} list of files to git add & commit
*/
static async retrieveCommitSelection(sourceBU, commitSelectionArr) {
// * dont use CONFIG.tempDir here to allow proper resolution of required package in VSCode
const mcdev = require('../tmp/node_modules/mcdev/lib/');
// ensure wizard is not started
mcdev.setSkipInteraction(true);

Expand Down Expand Up @@ -131,4 +130,4 @@ class Commit {
}
}
}
module.exports = Commit;
export default Commit;
2 changes: 1 addition & 1 deletion copado-function/app/common/Config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// empty object returned which is extended in the main classes
module.exports = {};
export default {};
12 changes: 6 additions & 6 deletions copado-function/app/common/Copado.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
const fs = require('node:fs');
const exec = require('node:child_process').exec;
import fs from 'node:fs';
import { exec } from 'node:child_process';

const TYPE = require('../types/mcdev-copado.d');
const Log = require('./Log');
const Util = require('./Util');
import TYPE from '../types/mcdev-copado.d.js';
import Log from './Log.js';
import Util from './Util.js';

/**
* methods to handle interaction with the copado platform
Expand Down Expand Up @@ -177,4 +177,4 @@ class Copado {
}
}

module.exports = Copado;
export default Copado;
6 changes: 3 additions & 3 deletions copado-function/app/common/Log.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const execSync = require('node:child_process').execSync;
const CONFIG = require('./Config');
import { execSync } from 'node:child_process';
import CONFIG from './Config.js';

/**
* logger class
Expand Down Expand Up @@ -74,4 +74,4 @@ class Log {
}
}

module.exports = Log;
export default Log;
78 changes: 40 additions & 38 deletions copado-function/app/common/Util.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict';
const fs = require('node:fs');
const execSync = require('node:child_process').execSync;
import fs from 'node:fs';
import { execSync } from 'node:child_process';

import TYPE from '../types/mcdev-copado.d.js';
import CONFIG from './Config.js';
import Log from './Log.js';
import mcdev from 'mcdev';

const TYPE = require('../types/mcdev-copado.d');
const CONFIG = require('./Config');
const Log = require('./Log');
/**
* helper class
*/
Expand Down Expand Up @@ -111,38 +113,38 @@ class Util {
* @returns {void}
*/
static provideMCDevTools() {
if (fs.existsSync('package.json')) {
Log.debug('package.json found, assuming npm was already initialized');
} else {
Util.execCommand('Initializing npm', ['npm init -y'], 'Completed initializing NPM');
}
let installer;
if (!CONFIG.installMcdevLocally) {
Util.execCommand(
`Initializing Accenture SFMC DevTools (packaged version)`,
[
`npm link mcdev --no-audit --no-fund --ignore-scripts --omit=dev --omit=peer --omit=optional`,
'mcdev --version',
],
'Completed installing Accenture SFMC DevTools'
);
return; // we're done here
} else if (CONFIG.mcdevVersion.charAt(0) === '#') {
// assume branch of mcdev's git repo shall be loaded

installer = `accenture/sfmc-devtools${CONFIG.mcdevVersion}`;
} else if (!CONFIG.mcdevVersion) {
Log.error('Please specify mcdev_version in pipeline & environment settings');
throw new Error('Please specify mcdev_version in pipeline & environment settings');
} else {
// default, install via npm at specified version
installer = `mcdev@${CONFIG.mcdevVersion}`;
}
Util.execCommand(
`Initializing Accenture SFMC DevTools (${installer})`,
[`npm install ${installer}`, 'node ./node_modules/mcdev/lib/cli.js --version'],
'Completed installing Accenture SFMC DevTools'
);
mcdev.version();
// if (fs.existsSync('package.json')) {
// Log.debug('package.json found, assuming npm was already initialized');
// } else {
// Util.execCommand('Initializing npm', ['npm init -y'], 'Completed initializing NPM');
// }
// let installer;
// if (!CONFIG.installMcdevLocally) {
// Util.execCommand(
// `Initializing Accenture SFMC DevTools (packaged version)`,
// [
// `npm link mcdev --no-audit --no-fund --ignore-scripts --omit=dev --omit=peer --omit=optional`,
// 'mcdev --version',
// ],
// 'Completed installing Accenture SFMC DevTools'
// );
// return; // we're done here
// } else if (CONFIG.mcdevVersion.charAt(0) === '#') {
// // assume branch of mcdev's git repo shall be loaded
// installer = `accenture/sfmc-devtools${CONFIG.mcdevVersion}`;
// } else if (!CONFIG.mcdevVersion) {
// Log.error('Please specify mcdev_version in pipeline & environment settings');
// throw new Error('Please specify mcdev_version in pipeline & environment settings');
// } else {
// // default, install via npm at specified version
// installer = `mcdev@${CONFIG.mcdevVersion}`;
// }
// Util.execCommand(
// `Initializing Accenture SFMC DevTools (${installer})`,
// [`npm install ${installer}`, 'node ./node_modules/mcdev/lib/cli.js --version'],
// 'Completed installing Accenture SFMC DevTools'
// );
}
/**
* creates credentials file .mcdev-auth.json based on provided credentials
Expand Down Expand Up @@ -261,4 +263,4 @@ class Util {
}
}

module.exports = Util;
export default Util;
Loading

0 comments on commit facc448

Please sign in to comment.