weareinreach / InReach

Suggest correct usage of shebang JS-0271
Bug risk
Major
20 days agoa month old
This file needs no shebang
 1#! /usr/bin/env tsx
 2/* eslint-disable node/no-process-env */
 3import { v2 as compose } from 'docker-compose' 4import { config as loadEnv } from 'dotenv' 5import { expand as dotenvExpand } from 'dotenv-expand' 6import yargs from 'yargs' 7import { hideBin } from 'yargs/helpers' 8 9import fs from 'fs'10import path from 'path'1112dotenvExpand(loadEnv({ path: path.resolve(__dirname, '../.env') }))13const dockerComposeFile = path.resolve(__dirname, './docker-compose.yml')1415if (!fs.existsSync(dockerComposeFile)) {16	throw new Error(`Could not find a docker compose file at: ${dockerComposeFile}`)17}1819const postgresLocalUrlRegex = /^postgres:\/\/(?:([^:]+):([^@]+)@)?(?:localhost|127\.0\.0\.1)(:\d+)?\/([^?]+)/2021yargs(hideBin(process.argv))22	.demandCommand(1)23	.command(24		'up',25		'Start docker containers',26		() => {},27		async () => {28			if (process.env.DATABASE_URL && postgresLocalUrlRegex.test(process.env.DATABASE_URL)) {29				console.log("Starting docker...")30				await compose.upAll({31					config: dockerComposeFile,32					callback: (chunk) => console.log(chunk.toString()),33				})34			} else {35				console.log("Skipping docker start, DATABASE_URL is not set to a local address")36			}37		}38	)39	.command(40		'down',41		'Stop docker containers',42		() => {},43		async () => {44			try {45				await compose.ps({ config: dockerComposeFile })4647				await compose.downAll({48					config: dockerComposeFile,49					callback: (chunk) => console.log(chunk.toString()),50				})51			} catch (err) {52				if (err instanceof Error) {53					console.error(err.message)54				}55			}56		}57	).argv