/* eslint-disable no-process-exit */ /* eslint-disable no-console */ /* * Copyright (C) Sapphirecode - All Rights Reserved * This file is part of console-app which is released under MIT. * See file 'LICENSE' for full license details. * Created by Timo Hocker , May 2020 */ /* eslint-disable max-lines-per-function */ /* eslint-disable complexity */ /* eslint-disable max-statements */ /* eslint-disable no-process-env */ import { Persistent } from '@sapphirecode/modelling'; import fs from 'fs-extra'; import yargs, { Options } from 'yargs'; import { Confirm, Input } from 'enquirer'; type OptionType = 'string' | 'number' | 'boolean' | 'file' | 'folder' | 'path'; interface Option { name: string; type: OptionType; required?: boolean; default?: unknown; alias?: string; env?: string; description?: string; message?: string; } interface OptionProcess extends Option { filled: boolean; value?: unknown; } function get_string_type (type: OptionType): 'string'|'number'|'boolean' { if ([ 'string', 'number', 'boolean' ].includes (type)) return type as ('string'|'number'|'boolean'); if ([ 'file', 'folder', 'path' ].includes (type)) return 'string'; throw new Error (`unknown option type ${type}`); } export class InteractiveOptions extends Persistent { protected options: Array; protected quiet = false; public constructor (options: Array