Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ export default function setup() {
)
)
.addOption(new Option('-d, --pull-dependencies', 'Pull dependencies.'))
// TO DO: implementing for 'clean'
// .addOption(
// new Option('-c, --clean', 'Clear existing configuration before pull.')
// )
.addOption(
new Option('-c, --clean', 'Clear existing configuration before pull.')
)
.action(async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
Expand All @@ -58,7 +57,8 @@ export default function setup() {
const outcome = await configManagerExportJourneys(
options.name,
realm,
options.pullDependencies
options.pullDependencies,
options.clean
);
if (!outcome) process.exitCode = 1;
}
Expand Down
45 changes: 35 additions & 10 deletions src/configManagerOps/FrConfigJourneysOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
MultiTreeExportInterface,
TreeExportOptions,
} from '@rockcarver/frodo-lib/types/ops/JourneyOps';
import fs from 'fs';

import { extractFrConfigDataToFile } from '../utils/Config';
import { printError, verboseMessage } from '../utils/Console';
Expand All @@ -11,11 +12,19 @@ import { existScript, realmList, safeFileName } from '../utils/FrConfig';
const { saveJsonToFile, getFilePath } = frodo.utils;
const { exportJourneys } = frodo.authn.journey;

/**
* Export journeys in fr-config-manager format
* @param {string} name exports only the specifically named journey
* @param {string} realm exports journeys only in specified realm
* @param {boolean} pullDependency include journey dependencies
* @param {boolean} clean if true clear existing configuration, otherwise false
* @returns {Promise<boolean>} A promise that resolves to true if successful, false otherwise
*/
export async function configManagerExportJourneys(
Comment thread
brycentrivir marked this conversation as resolved.
name?,
realm?,
pullDependency?
// TO DO: clean?
name?: string,
realm?: string,
pullDependency?: boolean,
clean?: boolean
): Promise<boolean> {
const options: TreeExportOptions = {
deps: pullDependency,
Expand All @@ -28,7 +37,14 @@ export async function configManagerExportJourneys(
const exportData = (await exportJourneys(
options
)) as MultiTreeExportInterface;
processJourneys(exportData.trees, realm, name, pullDependency, 'realms');
await processJourneys(
exportData.trees,
realm,
name,
pullDependency,
'realms',
clean
);
} else {
for (const realm of await realmList()) {
if (
Expand All @@ -47,7 +63,8 @@ export async function configManagerExportJourneys(
realm,
name,
pullDependency,
'realms'
'realms',
clean
);
}
}
Expand All @@ -71,7 +88,8 @@ async function processJourneys(
realm,
name,
pullDependencies,
exportDir
exportDir,
clean
) {
const fileDir = `${exportDir}/${realm}/journeys`;
try {
Expand All @@ -83,6 +101,14 @@ async function processJourneys(
const nodeDir = `${journeyDir}/nodes`;
const scriptJsonDir = `realms/${realm}/scripts/scripts-config`;

if (clean) {
fs.rmSync(nodeDir, { recursive: true, force: true });
}

if (!fs.existsSync(nodeDir)) {
fs.mkdirSync(nodeDir, { recursive: true });
}

for (const [nodeId, node] of Object.entries(journey.nodes) as [
string,
any,
Expand Down Expand Up @@ -168,10 +194,10 @@ async function processJourneys(
realm,
node.tree,
pullDependencies,
exportDir
exportDir,
clean
);
}

saveJsonToFile(
node,
getFilePath(`${nodeFileNameRoot}.json`, true),
Expand All @@ -180,7 +206,6 @@ async function processJourneys(
true
);
}

const fileName = `${journeyDir}/${journey.tree._id}.json`;
saveJsonToFile(
journey.tree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Arguments:
password Password.

Options:
-c, --clean Clear existing configuration before pull.
-d, --pull-dependencies Pull dependencies.
-n, --name <name> Journey name, It only export the journey with the
name.
Expand Down
546 changes: 291 additions & 255 deletions test/e2e/__snapshots__/config-manager-export-journeys.e2e.test.js.snap

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions test/e2e/config-manager-export-journeys.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager pull journeys -D testDir11
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager pull journeys -r alpha -D testDir12
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager pull journeys -r alpha -n FrodoTest -D testDir13
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager pull journeys -D testDir14 --pull-dependencies
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager pull journeys -cD testDir14 --pull-dependencies

*/

Expand Down Expand Up @@ -79,9 +79,9 @@ describe('frodo config-manager pulls', () => {
const CMD = `frodo config-manager pull journeys -r alpha -n FrodoTest -D ${dirName}`;
await testExport(CMD, env, undefined, undefined, dirName, false);
});
test('"frodo config-manager pull journeys -D testDir14 --pull-dependencies": should export the journeys in fr-config-manager style"', async () => {
test('"frodo config-manager pull journeys -cD testDir14 --pull-dependencies": should export the journeys in fr-config-manager style"', async () => {
const dirName = 'testDir14';
const CMD = `frodo config-manager pull journeys -D ${dirName} --pull-dependencies`;
const CMD = `frodo config-manager pull journeys -cD ${dirName} --pull-dependencies`;
await testExport(CMD, env, undefined, undefined, dirName, false);
});
});
Loading