File

libs/sdk/src/node/journey/generate/lib/create-journey/create-journey.ts

Index

Properties

Properties

aquilaTheme
Type string | undefined
configDirectory
Type string
destinationDirectory
Type string
envPath
Type string | undefined
journeyConfig
Type Journey
journeyName
Type string
import { cpSync, existsSync, rmSync } from 'node:fs';
import { basename, join } from 'node:path';
import { Journey } from '../../../../../lib/model';
import { writeJourneyToFolder } from '../../../write/write';
import { appsFolder, configFolder, isLocalPath } from '../../utils/constants';
import { execAsync } from '../../utils/exec-async';

interface CreateJourneyOptions {
  destinationDirectory: string;
  configDirectory: string;
  journeyConfig: Journey;
  envPath: string | undefined;
  aquilaTheme: string | undefined;
  journeyName: string;
}

export async function createJourney(options: CreateJourneyOptions) {
  // TODO: figure out if app already exists in workspace using nx tooling
  // maybe use `nx graph --file output.json` to get details about
  // generated project to figure out the actual root path of the new project
  // and then use `nx g remove <app-name>` to remove it
  const appsDirectory = join(options.destinationDirectory, appsFolder);
  const journeyDirectory = join(appsDirectory, options.journeyName);

  if (existsSync(appsDirectory)) {
    // TODO: maybe ask the user if they really want to overwrite an existing journey
    rmSync(appsDirectory, { recursive: true, force: true });
  }

  //adds projects.json file and installs necessary dependencies
  await execAsync(`npx nx generate journey --name ${options.journeyName}`, {
    cwd: options.destinationDirectory,
    env: {
      ...process.env,
      TALY_SKIP_CONFIG_VALIDATION: 'true'
    }
  });

  const journeyConfigDirectory = join(journeyDirectory, configFolder);
  // We are not interested in the journey config files, but other content like assets and translations
  cpSync(options.configDirectory, journeyConfigDirectory, {
    recursive: true
  });
  // Write the validated in-memory journey config to the new journey
  writeJourneyToFolder(options.journeyConfig, journeyConfigDirectory);

  if (options.envPath) {
    const fileName = basename(options.envPath);
    const envPathDestination = join(journeyDirectory, configFolder, fileName);
    cpSync(options.envPath, envPathDestination);
  }

  if (options.aquilaTheme && isLocalPath(options.aquilaTheme)) {
    const fileName = basename(options.aquilaTheme);
    const aquilaThemePathDestination = join(journeyDirectory, configFolder, fileName);
    cpSync(options.aquilaTheme, aquilaThemePathDestination);
  }
}

results matching ""

    No results matching ""