import { execSync } from 'child_process' import fs from 'fs' import colors from 'colors' import { IndexState } from '../types' import { execConfig, log } from '../helpers' const nodeVersion = 'node18' export const installNodeModules = async () => { // Check If Node Modules Exist // If they don't, install them if (!fs.existsSync('./node_modules')) { const output = execSync('npm install', execConfig) console.info(output) } } export const buildAPIFolder = async (state: IndexState) => { const apiFolderCount: number = parseInt(execSync('ls -l ./API/ | grep -c ^d', execConfig), 10) if (apiFolderCount > 2) { const build = execSync( `esbuild ./API/*/*/*/index.ts --bundle --outdir=./dist/API/ --platform=node --target=${nodeVersion} --minify-whitespace;`, execConfig, ) log(build, null, state) // console.info(build) } else { console.info(colors.red("\nYou haven't added any endpoints yet")) const build = execSync( `esbuild ./API/Core/*/*/index.ts --bundle --outdir=./dist/API/Core --platform=node --target=${nodeVersion} --minify-whitespace;`, execConfig, ) log(build, null, state) // console.info(build) } } export const buildIndexFile = async (state: IndexState) => { const build = execSync( 'esbuild ./API/index.ts --outfile=./dist/API/index.js;', execConfig, ) log(build, null, state) // console.info(build) } export const buildServer = async () => { const runJs = execSync( `esbuild ${__dirname}/Templates/Server/run.js --bundle --outdir=./dist/server --platform=node --target=${nodeVersion} --minify-whitespace`, execConfig, ) console.info(runJs) const config = execSync( `esbuild ${__dirname}/Templates/Server/Config/* --bundle --outdir=./dist/server/Config --platform=node --target=${nodeVersion} --minify-whitespace`, execConfig, ) console.info(config) const utils = execSync( `esbuild ${__dirname}/Templates/Server/ServerUtils/*/index.ts --bundle --outdir=./dist/server/ServerUtils --platform=node --target=${nodeVersion} --minify-whitespace`, execConfig, ) console.info(utils) } export const copyDotEnvFile = async () => { const copy = execSync( 'cp -R ./.env ./dist/server/.env', execConfig, ) console.info(copy) } // export const copyDotEnvFile = async () => { // const copy = execSync( // 'cp -R ./.env ./dist/server/.env', // execConfig, // ) // console.info(copy) // }