diff --git a/.gitignore b/.gitignore index ad08e406..8729fca1 100644 --- a/.gitignore +++ b/.gitignore @@ -152,3 +152,4 @@ out /wrangler-test.toml /dist/index.cjs /dist/index.d.ts +/dist/src diff --git a/Dockerfile b/Dockerfile index 64d1009e..637e0efd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,15 @@ -FROM node:alpine - +FROM node:alpine AS build WORKDIR /app -COPY package.json tsconfig.json ./ -COPY src src +COPY package.json tsconfig.json vite.config.ts ./ RUN npm install +COPY src src +RUN npm run build:local + + +FROM node:alpine AS production +WORKDIR /app +COPY package.json ./ +RUN npm install --omit=dev +COPY --from=build /app/dist ./dist EXPOSE 8787 -CMD ["npm", "run", "start:local"] +CMD ["npm", "run", "start:dist"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 226b4443..932f99f6 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,3 +7,5 @@ services: volumes: - ./config.json:/app/config.json:ro # change `./config.json` to your local path - ./wrangler.toml:/app/wrangler.toml:ro # change `./wrangler.toml` to your local path + network_mode: "host" # If you access the proxy port based on the host + entrypoint: ["npm", "run", "start:dist"] \ No newline at end of file diff --git a/package.json b/package.json index b10c5d60..65af9e31 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "chatgpt-telegram-workers", "type": "module", - "version": "1.9.4", + "version": "1.10.0", "description": "The easiest and quickest way to deploy your own ChatGPT Telegram bot is to use a single file and simply copy and paste it. There is no need for any dependencies, local development environment configuration, domain names, or servers.", "author": "tbxark ", "license": "MIT", @@ -21,20 +21,21 @@ ], "scripts": { "lint": "eslint --fix *.js *.ts src plugins scripts", - "version": "tsx ./scripts/plugins/version/main.ts", + "version": "tsx src/vite/version/main.ts", "build": "vite build", - "build:local": "vite build", + "build:local": "ENTRY=src/entry/local/index.ts vite build", "build:docker": "docker build -t chatgpt-telegram-workers:latest .", "build:dockerx": "docker build --platform linux/amd64,linux/arm64 -t tbxark/chatgpt-telegram-workers:latest --push .", "build:vercel": "ENTRY=src/entry/vercel/index.ts vite build", + "build:pack": "TYPES=true FORMATS=es,cjs vite build", "deploy:dist": "wrangler deploy", "deploy:build": "npm run build && wrangler deploy", "deploy:vercel": "vercel deploy --prod", "deploy:plugin": "vite build -c plugins/vite.config.ts && wrangler pages deploy plugins --project-name=interpolate-test --branch=main", - "start:dist": "node dist/index.js", + "start:dist": "CONFIG_PATH=./config.json TOML_PATH=./wrangler.toml node dist/index.js", "start:local": "CONFIG_PATH=./config.json TOML_PATH=./wrangler.toml tsx src/entry/local/index.ts", "start:debug": "wrangler dev --local", - "prepare:vercel": "tsx ./scripts/plugins/vercel/setenv.ts", + "prepare:vercel": "tsx src/vite/vercel/setenv.ts", "wrangler": "wrangler", "test": "tsx ./src/agent/index.test.ts" }, diff --git a/src/config/version.ts b/src/config/version.ts index b2cc9ccc..969fe7cf 100644 --- a/src/config/version.ts +++ b/src/config/version.ts @@ -1,2 +1,2 @@ -export const BUILD_TIMESTAMP = 1731464647; -export const BUILD_VERSION = 'fe9ef45'; +export const BUILD_TIMESTAMP = 1731468421; +export const BUILD_VERSION = '9e1cda2'; diff --git a/scripts/plugins/vercel/index.ts b/src/vite/vercel/index.ts similarity index 96% rename from scripts/plugins/vercel/index.ts rename to src/vite/vercel/index.ts index 7a3f02f4..7d1421ed 100644 --- a/scripts/plugins/vercel/index.ts +++ b/src/vite/vercel/index.ts @@ -1,7 +1,7 @@ import { execSync } from 'node:child_process'; import fs from 'node:fs/promises'; import { parse } from 'toml'; -import { ENV } from '../../../src/config/env'; +import { ENV } from '../../config/env'; export function createVercelPlugin(vercelPath: string, tomlPath: string, removeUnused = true) { return { diff --git a/scripts/plugins/vercel/setenv.ts b/src/vite/vercel/setenv.ts similarity index 100% rename from scripts/plugins/vercel/setenv.ts rename to src/vite/vercel/setenv.ts diff --git a/scripts/plugins/version/index.ts b/src/vite/version/index.ts similarity index 100% rename from scripts/plugins/version/index.ts rename to src/vite/version/index.ts diff --git a/scripts/plugins/version/main.ts b/src/vite/version/main.ts similarity index 100% rename from scripts/plugins/version/main.ts rename to src/vite/version/main.ts diff --git a/vite.config.ts b/vite.config.ts index a041ae85..3d149b4b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,38 +1,49 @@ +import type { LibraryFormats, Plugin } from 'vite'; import * as path from 'node:path'; import { nodeResolve } from '@rollup/plugin-node-resolve'; import cleanup from 'rollup-plugin-cleanup'; +import { nodeExternals } from 'rollup-plugin-node-externals'; import { defineConfig } from 'vite'; import checker from 'vite-plugin-checker'; import dts from 'vite-plugin-dts'; -import { createVersionPlugin } from './scripts/plugins/version'; +import { createVersionPlugin } from './src/vite/version'; const { + TYPES = 'false', + FORMATS = 'es', ENTRY = 'src/entry/core/index.ts', } = process.env; +const plugins: Plugin[] = [ + nodeResolve({ + browser: false, + preferBuiltins: true, + }), + cleanup({ + comments: 'none', + extensions: ['js', 'ts'], + }), + checker({ + typescript: true, + }), + nodeExternals(), + createVersionPlugin(path.resolve(__dirname)), +]; + +if (TYPES === 'true') { + plugins.push( + dts(), + ); +} + export default defineConfig({ - plugins: [ - nodeResolve({ - preferBuiltins: true, - }), - cleanup({ - comments: 'none', - extensions: ['js', 'ts'], - }), - checker({ - typescript: true, - }), - dts({ - rollupTypes: true, - }), - createVersionPlugin(path.resolve(__dirname)), - ], + plugins, build: { target: 'esnext', lib: { entry: path.resolve(__dirname, ENTRY), fileName: 'index', - formats: ['es', 'cjs'], + formats: FORMATS.split(',') as LibraryFormats[], }, minify: false, outDir: path.resolve(__dirname, 'dist'),