#! /usr/bin/env node import colors from 'colors' import Build from './Build' import CreateFunction from './CreateFunction' import DeleteFunction from './DeleteFunction' import { HelpLog } from './HelpLog' import Init from './Init' import Lint from './Lint' import Run from './Run' import TestPath from './TestPath' import Update from './Update' import Version from './Version' import Watch from './Watch' import { checkIfInitShouldRun, checkPackagesExist } from './helpers' import checkVersion from './Version/checkVersion' import CreateEnvFile from './CreateEnvFile' import { IndexState } from './types' const call = () => { const args = process.argv.slice(2) if (args.length < 1) { console.info(`${colors.red('No command entered')}`) HelpLog() process.exit(1) } else if (args[0] !== 'updateVersionComplete') { checkVersion(args[0]) } const flags: string[] = [ 'ciPipeline', 'noSudo', 'devMode', ] const state: IndexState = { ciPipeline: false, noSudo: false, devMode: false, args, } if (args.length >= 1) { args.forEach((arg) => { switch (arg) { case 'ciPipeline': state.ciPipeline = true break case 'noSudo': state.noSudo = true break case 'dev': state.devMode = true break default: break } }) // remove the flags from the args if (state.ciPipeline) { state.args = state.args.filter((arg: string) => !flags.includes(arg)) } } (async () => { if (state.ciPipeline) { console.info(`${colors.green('RUNNING IN A CICD PIPELINE ENVIRONMENT')}`) } switch (args[0]) { case 'i': case 'init': break default: await checkPackagesExist(state) break } switch (args[0]) { case 'build': case 'b': if (checkIfInitShouldRun()) return Build(state) return false case 'create': case 'c': if (checkIfInitShouldRun()) return CreateFunction() return false case 'delete': case 'd': if (checkIfInitShouldRun()) return DeleteFunction() return false case 'envfile': case 'e': return CreateEnvFile(state) case 'help': case 'h': return HelpLog() case 'init': case 'i': return Init() case 'lint': case 'l': return Lint() case 'run': case 'r': return Run(state) case 'test': case 't': return TestPath(state) case 'update': case 'u': return Update() case 'watch': case 'w': return Watch(state) // Internal functionality case 'updateVersionComplete': console.info(`${colors.green(' wappi has been updated')}`) return process.exit(1) case 'updateCoreVersion': return Version() default: console.info(`${colors.red('No command entered')}`) HelpLog() return process.exit(1) } })() } call()