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,QAAQ,GAAqB,GAAK,0BAA0B,QAAA,QAAM,UAAU,SAAA,KAAK,EAAmB,UAC5L,KAAM,SACG,IAAI,SAAS,IAGlB,YAAW,KACT,GAAS,GA3CF,IA4CK,QAIjB,EACH,CACE,MAAO,uBAAuB,aAC9B,KAAM,SACG,IAAI,SAAA,MAAM,EAAK,OAAA,OAAA,OAAA,OAAA,GACjB,GACA,QAIN,GACJ,OAAA,OAAA,OAAA,OAAA,GACI,GAAkB,CACrB,YAAY,IAGG,EAON,QAAA,kBAAoB,KAC/B,uBAAA,QAAY,aAAa,QAAA,SAEzB,QAAA,QAAM,OAAO,UAAW,CACtB,SAAU,qCACV,KAAM,SACN,QAAS,OACR,MAAM,IAAK,WAEd,QAAQ,GAAG,sBAAuB,IAChC,QAAQ,MAAM,4DACd,QAAQ,MAAM,GACd,QAAQ,KAAK,EAAE,IAGjB,QAAQ,GAAG,qBAAsB,IAC/B,QAAQ,MAAM,2DACd,QAAQ,MAAM,GACd,QAAQ,KAAK,EAAE,IAGjB,QAAQ,GAAG,UAAU,KACnB,QAAQ,KAAK,kDACb,QAAQ,MAAM,GACd","file":"/npm/@bmd-studio/genstack-cli@3.0.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@bmd-studio/genstack-cli@3.0.0/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import Docker from 'dockerode';\r\nimport { Listr, ListrTask, ListrOptions } from 'listr2';\r\nimport chalk from 'chalk';\r\nimport yargs from 'yargs';\r\nimport { isEmpty, join } from 'lodash';\r\nimport path from 'upath';\r\nimport fs from 'fs-extra';\r\n\r\nimport logger from '@bmd-studio/genstack-logger';\r\nimport environment, { EnvVars, VersionedConfig } from '@bmd-studio/genstack-environment';\r\n\r\nimport { getCurrentServices, getRequestedServices } from './services';\r\n\r\nexport * from './docker';\r\nexport * from './services';\r\n\r\nexport interface ServiceRepository {\r\n  url: string;\r\n  ref?: string;\r\n}\r\n\r\n/**\r\n * Definition of a (micro) service.\r\n */\r\nexport interface Service {\r\n  /** True when this service is active and should be deployed. */\r\n  active?: boolean;\r\n  /** Name of the service to identity it throughout the application. */\r\n  name: string;\r\n  /** Reference to the container to be used as a base for this service. */\r\n  repository?: ServiceRepository;\r\n  /** The relative path to the project-specific files for this service. */\r\n  path?: string;\r\n  /** Additional environment variables passed to this service. */\r\n  env?: EnvVars;\r\n}\r\n\r\n/**\r\n * Versioned configuration of all the services for the application\r\n */\r\nexport interface VersionedServicesConfig extends Omit<VersionedConfig, 'config'> {\r\n  /** Required config properties to define services */\r\n  config: ServicesConfig;\r\n}\r\n\r\n/**\r\n * Definition of what properties are allowed in the `config` namespace of the service configuration. \r\n */\r\nexport interface ServicesConfig {\r\n  /** List of all the services */\r\n  services: Service[];\r\n}\r\n\r\n/**\r\n * Definition of the possible environment variables for interfacing with the Docker deamon.\r\n */\r\nexport interface DockerEnv {\r\n  /** App name prefix to be used by Docker Compose to identity this application. */\r\n  COMPOSE_APP_NAME?: string;\r\n  /** Project name prefix to be used by Docker Compose to identity this application. */\r\n  COMPOSE_PROJECT_NAME?: string;\r\n  /** The host name and port number concatenated with `:` in between\r\n   of the Docker instance to deploy to. E.g. `docker.bmd:2376` */\r\n  DOCKER_HOST?: string;\r\n  /** Path to the SSL certificate for the Docker instance. */\r\n  DOCKER_CERT_PATH?: string;\r\n}\r\n\r\n/**\r\n * Definition to match a container to a project service.\r\n */\r\nexport interface MatchedContainer {\r\n  /** The container instance */\r\n  container: Docker.ContainerInspectInfo;\r\n  /** The project service definition */\r\n  service: Service|undefined;\r\n}\r\n\r\nexport interface LaunchConfig {\r\n  configurations?: LaunchConfiguration[];\r\n  compounds?: LaunchCompound[];\r\n}\r\n\r\nexport interface LaunchConfiguration {\r\n  type: string;\r\n  request: string;\r\n  name: string;\r\n  protocol: string;\r\n  port: number;\r\n  restart: boolean;\r\n  sourceMaps: boolean;\r\n  localRoot: string;\r\n  remoteRoot: string;\r\n  outFiles: string[];\r\n  skipFiles: string[];\r\n}\r\n\r\nexport interface LaunchCompound {\r\n  name: string;\r\n  configurations: string[];\r\n}\r\n\r\nexport interface TaskRunnerOptions {\r\n  tasks: ListrTask[];\r\n  preTasks?: ListrTask[];\r\n  postTasks?: ListrTask[];\r\n  taskOptions?: ListrOptions;\r\n}\r\n\r\nexport type ServiceCommandHandler = (service: Service) => Promise<void>;\r\n\r\nconst ONE_SECOND = 1000;\r\n\r\nexport const createTaskRunner = ({ tasks, preTasks = [], postTasks = [], taskOptions = {} }: TaskRunnerOptions): Listr => {\r\n  const envName = environment.getEnvName();\r\n  const envType = environment.getEnvType();\r\n  const genstackConfig = environment.getGenstackConfig();\r\n  const projectRoot = environment.getProjectRoot();\r\n  const envNameFilePath = path.join(projectRoot, genstackConfig?.environment?.envPath ?? '', envName); \r\n  const envNameFileExists = fs.existsSync(envNameFilePath);\r\n  const services = getCurrentServices();\r\n  const requestedServices = getRequestedServices();\r\n  const serviceAmount = services.length;\r\n  const taskRenderer = logger.isEnabled() ? 'verbose' : 'default';\r\n  const defaultTaskOptions: ListrOptions = {\r\n    // @ts-ignore\r\n    renderer: taskRenderer,\r\n    exitOnError: false,\r\n    concurrent: true,\r\n    rendererOptions: {\r\n      collapse: false,\r\n      collapseSkips: false,\r\n      clearOutput: false,\r\n      showSubtasks: true,\r\n      showSkipMessage: true,\r\n      collapseErrors: false,\r\n      showErrorMessage: true,\r\n      showTimer: true,\r\n    },\r\n  };\r\n\r\n  // guard: make sure the environment name file exists\r\n  if (!envNameFileExists) {\r\n    throw new Error(`Could not find environment file ${chalk.underline(envName)} at ${chalk.underline(envNameFilePath)}. Make sure your environment exists.`);\r\n  }\r\n\r\n  const taskRunner = new Listr([\r\n    {\r\n      title: `Select environment ${chalk.underline(envName)} in ${chalk.underline(envType)} ${isEmpty(requestedServices) ? '' : `for service selection: ${chalk.underline(join(requestedServices, ','))}`}`,\r\n      task: async (): Promise<void> => {\r\n        return new Promise((resolve) => {\r\n\r\n          // give some time to cancel\r\n          setTimeout(() => {\r\n            resolve();\r\n          }, ONE_SECOND);\r\n        })\r\n      },\r\n    },\r\n    ...preTasks,\r\n    {\r\n      title: `Execute command for ${serviceAmount} services`,\r\n      task: async() => {\r\n        return new Listr(tasks, {\r\n          ...defaultTaskOptions,\r\n          ...taskOptions,\r\n        });\r\n      },\r\n    },\r\n    ...postTasks,\r\n  ], {\r\n    ...defaultTaskOptions,\r\n    concurrent: false,\r\n  });\r\n\r\n  return taskRunner;\r\n};\r\n\r\n/**\r\n * The default yargs command builder.\r\n * @param argv \r\n */\r\nexport const initializeCommand = (): void =>  {\r\n  environment.buildEnvArgs(yargs);\r\n\r\n  yargs.option('service', {\r\n    describe: `Execute only for specific services`,\r\n    type: 'string',\r\n    default: null,\r\n  }).alias('s', 'service');\r\n\r\n  process.on('unhandledRejection', (error: any) => {\r\n    console.error('Could not execute command due to an unhandled rejection:');\r\n    console.error(error);\r\n    process.exit(1);\r\n  });\r\n\r\n  process.on('uncaughtException', (error: Error) => {\r\n    console.error('Could not execute command due to an uncaught exception:');\r\n    console.error(error);\r\n    process.exit(1);\r\n  });\r\n\r\n  process.on('SIGINT', () => {\r\n    console.info('Caught interrupt signal. Exiting gracefully...');\r\n    process.exit();\r\n  });\r\n};"]}