-
Notifications
You must be signed in to change notification settings - Fork 838
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: 分离自定义vite plugins,添加快速构建docker image 脚本
- Loading branch information
Showing
9 changed files
with
105 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,4 +151,4 @@ out | |
.wrangler | ||
package-lock.json | ||
/plugins/interpolate.js | ||
dist/index.d.ts | ||
config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as fs from 'node:fs/promises'; | ||
import path from "node:path"; | ||
|
||
const dockerfile = ` | ||
FROM node:alpine as PROD | ||
WORKDIR /app | ||
COPY index.js package.json /app/ | ||
RUN npm install --only=production --omit=dev | ||
RUN apk add --no-cache sqlite | ||
EXPOSE 8787 | ||
CMD ["npm", "run", "start"] | ||
` | ||
|
||
const packageJson = ` | ||
{ | ||
"name": "chatgpt-telegram-workers", | ||
"type": "module", | ||
"version": "1.8.0", | ||
"author": "TBXark", | ||
"license": "MIT", | ||
"module": "index.js", | ||
"scripts": { | ||
"start": "node index.js" | ||
}, | ||
"dependencies": { | ||
"cloudflare-worker-adapter": "^1.2.3" | ||
}, | ||
"devDependencies": {} | ||
} | ||
` | ||
|
||
export const createDockerPlugin = (targetDir: string) => { | ||
return { | ||
name: 'docker', | ||
async closeBundle() { | ||
await fs.writeFile(path.resolve(targetDir, 'Dockerfile'), dockerfile.trim()); | ||
await fs.writeFile(path.resolve(targetDir, 'package.json'), packageJson.trim()); | ||
}, | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {execSync} from "node:child_process"; | ||
import * as fs from 'node:fs/promises'; | ||
import path from "node:path"; | ||
|
||
|
||
let COMMIT_HASH = 'unknown' | ||
let TIMESTAMP = Math.floor(Date.now() / 1000); | ||
|
||
try { | ||
COMMIT_HASH = execSync('git rev-parse --short HEAD').toString().trim(); | ||
} catch (e) { | ||
console.warn(e) | ||
} | ||
|
||
export const createVersionPlugin = (targetDir: string) => { | ||
return { | ||
name: 'buildInfo', | ||
async closeBundle() { | ||
await fs.writeFile(path.resolve(targetDir, 'timestamp'), TIMESTAMP.toString()); | ||
await fs.writeFile(path.resolve(targetDir, 'buildinfo.json'), JSON.stringify({ | ||
sha: COMMIT_HASH, | ||
timestamp: TIMESTAMP, | ||
})); | ||
}, | ||
}; | ||
} | ||
|
||
export const versionDefine = { | ||
__BUILD_VERSION__: JSON.stringify(COMMIT_HASH), | ||
__BUILD_TIMESTAMP__: TIMESTAMP.toString(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.