Skip to content

Commit

Permalink
Add bundle.ts to overcome missing node: import support of `deno com…
Browse files Browse the repository at this point in the history
…pile`
  • Loading branch information
synaptiko committed Apr 8, 2023
1 parent 376088d commit e93c012
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 22 deletions.
24 changes: 6 additions & 18 deletions .github/workflows/deno-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,16 @@ jobs:

- name: Compile
run: |
mkdir -p bin/
deno compile --output bin/cli-gpt.x86_64-unknown-linux-gnu --target x86_64-unknown-linux-gnu --allow-net --allow-read --allow-env --allow-write --allow-run --unstable src/index.ts
deno compile --output bin/cli-gpt.x86_64-apple-darwin --target x86_64-apple-darwin --allow-net --allow-read --allow-env --allow-write --allow-run --unstable src/index.ts
deno compile --output bin/cli-gpt.aarch64-apple-darwin --target aarch64-apple-darwin --allow-net --allow-read --allow-env --allow-write --allow-run --unstable src/index.ts
cd bin
zip cli-gpt.x86_64-unknown-linux-gnu.zip cli-gpt.x86_64-unknown-linux-gnu
zip cli-gpt.x86_64-apple-darwin.zip cli-gpt.x86_64-apple-darwin
zip cli-gpt.aarch64-apple-darwin.zip cli-gpt.aarch64-apple-darwin
rm cli-gpt.x86_64-unknown-linux-gnu
rm cli-gpt.x86_64-apple-darwin
rm cli-gpt.aarch64-apple-darwin
deno run -A bundle.ts
cd out
chmod u+x cli-gpt
zip cli-gpt.zip cli-gpt
rm cli-gpt
- name: Release and upload artifacts
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
files: |
bin/cli-gpt.x86_64-unknown-linux-gnu.zip
bin/cli-gpt.x86_64-apple-darwin.zip
bin/cli-gpt.aarch64-apple-darwin.zip
out/cli-gpt.zip
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out/
18 changes: 18 additions & 0 deletions bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { build, stop } from 'https://deno.land/x/[email protected]/mod.js';
import denoJson from './deno.json' assert { type: 'json' };

await build({
bundle: true,
format: 'esm',
platform: 'node',
entryPoints: ['src/index.ts'],
outfile: 'out/cli-gpt',
banner: {
js: '#!/usr/bin/env -S deno run --allow-net --allow-read --allow-env --allow-write --allow-run --unstable',
},
alias: Object.fromEntries(
Object.entries(denoJson.imports).map(([key, value]) => [key.slice(0, -1), value.slice(0, -1)]),
),
});

stop();
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"fmt": {
"files": {
"include": ["src/", "deno.json"]
"include": ["src/", "deno.json", "bundle.ts"]
},
"options": {
"useTabs": false,
Expand Down
46 changes: 45 additions & 1 deletion deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { ChatCompletion } from './ChatCompletion.ts';
import { printHelp } from './printHelp.ts';
import { ConversationPersistance, Role } from './ConversationPersistance.ts';

// TODO: reimplement how app is distributed until is resolved https://github.com/denoland/deno/issues/16632 (note: we can't use deno compile, instead we need to use some bundler and add shebang to that script)
// TODO: add ability to set the other model params with env vars
// TODO: finish the README
// TODO: add ability to set the other model params with env vars

const env = await load({
envPath: join(Deno.env.get('HOME')!, '.cli-gpt'),
Expand Down

0 comments on commit e93c012

Please sign in to comment.