diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..f93df75 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,31 @@ +name: Dev Tests + + +on: + push: + branches: [master] + pull_request: + branches: [master] + workflow_dispatch: + +jobs: + bun: + name: Test on Bun v1.1.34 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: 1.1.34 + + - name: Install dependencies + run: bun install + + - name: Start the bot + env: + BOT_MODE: test + run: bun run src/index.test.ts + + diff --git a/bun.lockb b/bun.lockb index 6ce33d9..0e557bf 100644 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/compatibility.json b/compatibility.json index ae34382..01284eb 100644 --- a/compatibility.json +++ b/compatibility.json @@ -13,6 +13,11 @@ "bun": "bun run src/index.test.ts", "deno": "deno -A src/index.test.ts" }, + "watch": { + "default": "echo \"No watch support for this runtime\" && exit 1", + "bun": "bun run --watch src/index.ts", + "deno": "deno -A --watch src/index.ts" + }, "format": "{npx} prettier --write src scripts", "lint": "{npx} eslint src/**/*.ts --fix", "update": "{run-file} scripts/update-framework.js", diff --git a/compose.yml b/docker-compose.yml similarity index 54% rename from compose.yml rename to docker-compose.yml index bcc108b..e3b0b59 100644 --- a/compose.yml +++ b/docker-compose.yml @@ -6,4 +6,11 @@ services: container_name: ${BOT_NAME} restart: always volumes: - - ./data:/data \ No newline at end of file + - ./data:/data + + sqlite: + image: sqlite + container_name: sqlite + volumes: + - ./data:/data + diff --git a/package.json b/package.json index ecc60b4..b63cdad 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "bot": "bunx @ghom/bot.ts-cli", "build": "rimraf dist && bunx rollup -c && bun run scripts/copy-keepers.js", "final": "rimraf node_modules && bun install --production && bun run build", - "watch": "bun run build -w", + "watch": "bun run --watch src/index.ts", "start": "bun run src/index.ts", "start.test": "bun run src/index.test.ts", "format": "bunx prettier --write src scripts", @@ -88,7 +88,7 @@ "@eslint/compat": "^1.2.0", "@eslint/eslintrc": "^3.1.0", "@eslint/js": "^9.12.0", - "@ghom/bot.ts-cli": "9.0.2", + "@ghom/bot.ts-cli": "9.0.3", "@rollup/plugin-alias": "^5.1.1", "@rollup/plugin-node-resolve": "^15.3.0", "@rollup/plugin-typescript": "^12.1.1", @@ -116,5 +116,4 @@ "npm": ">=10.x.x", "yarn": ">=1.22.22" } -} - +} \ No newline at end of file diff --git a/templates/compose.ejs b/templates/compose.ejs new file mode 100644 index 0000000..65192e7 --- /dev/null +++ b/templates/compose.ejs @@ -0,0 +1,57 @@ +services: + bot: + build: + context: . + dockerfile: Dockerfile + container_name: ${BOT_NAME} + restart: always + volumes: + <%- + client === "sqlite3" ? "- ./data:/data" : + client === "pg" ? "- ./data:/var/lib/postgresql/data" : + client === "mysql" ? "- ./data:/var/lib/mysql" : "" + %> + <% + if (client === "sqlite3") { + %> + sqlite: + image: sqlite + container_name: sqlite + volumes: + - ./data:/data + <% + } else if (client === "pg") { + %> + postgres: + image: postgres + container_name: postgres + environment: + - POSTGRES_USER=${DB_USER} + - POSTGRES_PASSWORD=${DB_PASSWORD} + - POSTGRES_DB=${DB_DATABASE} + volumes: + - ./data:/var/lib/postgresql/data + <% if (process.env.DB_PORT) { %> + ports: + - "${DB_PORT}:5432" + <% } %> + <% + } else if (client === "mysql") { + %> + mysql: + image: mysql + container_name: mysql + environment: + - MYSQL_USER=${DB_USER} + - MYSQL_PASSWORD=${DB_PASSWORD} + - MYSQL_DATABASE=${DB_DATABASE} + - MYSQL_ROOT_PASSWORD=${DB_PASSWORD} + volumes: + - ./data:/var/lib/mysql + <% if (process.env.DB_PORT) { %> + ports: + - "${DB_PORT}:3306" + <% } %> + <% + } + %> diff --git a/templates/dockerfile.ejs b/templates/dockerfile.ejs new file mode 100644 index 0000000..deecb29 --- /dev/null +++ b/templates/dockerfile.ejs @@ -0,0 +1,43 @@ +<% if (runtime === 'bun') { + %>FROM oven/bun:latest<% +} else if (runtime === 'node') { + %>FROM node:latest<% +} else if (runtime === 'deno') { + %>FROM denoland/deno:alpine<% +} %> + +WORKDIR /app + +COPY package.json . + +<% if (packageManager === 'bun') { + %>RUN bun install<% +} else if (packageManager === 'npm') { + %>RUN npm install + <% if (client === 'sqlite3' && runtime === 'node') { %> + RUN npm rebuild sqlite3<% + } %><% +} else if (packageManager === 'yarn') { + %>RUN yarn install + <% if (client === 'sqlite3' && runtime === 'node') { %> + RUN yarn rebuild sqlite3<% + } %><% +} else if (packageManager === 'pnpm') { + %>RUN pnpm install + <% if (client === 'sqlite3' && runtime === 'node') { %> + RUN pnpm rebuild sqlite3<% + } %><% +} else if (packageManager === 'deno') { + %>RUN deno install --global --allow-read --allow-write --allow-net --allow-env --allow-run<% +} %> + +COPY . . + +<% if (runtime === 'bun') { + %>CMD ["bun", "run", "start"]<% +} else if (runtime === 'node') { + %>RUN npm build +CMD ["node", "dist/index.js"]<% +} else if (runtime === 'deno') { + %>CMD ["deno", "run", "--allow-read", "--allow-write", "--allow-net", "--allow-env", "--allow-run", "src/index.ts"]<% +} %> \ No newline at end of file