From b0365cf173d5df5cb7d2bc4517c3b2581c2889ed Mon Sep 17 00:00:00 2001 From: Hassan El Mghari Date: Mon, 13 Feb 2023 17:18:29 -0500 Subject: [PATCH] migrated to ts --- .example.env.json | 1 - .gitignore | 1 - index.js => index.ts | 4 ++-- package.json | 11 +++++++---- tsconfig.json | 12 ++++++++++++ 5 files changed, 21 insertions(+), 8 deletions(-) delete mode 100644 .example.env.json rename index.js => index.ts (96%) create mode 100644 tsconfig.json diff --git a/.example.env.json b/.example.env.json deleted file mode 100644 index ee8ab04..0000000 --- a/.example.env.json +++ /dev/null @@ -1 +0,0 @@ -{ "OPENAI_API_KEY": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx" } diff --git a/.gitignore b/.gitignore index 25c4eb0..5e52727 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -.env.json /node_modules package-lock.json diff --git a/index.js b/index.ts similarity index 96% rename from index.js rename to index.ts index 3a240e5..686e6fe 100644 --- a/index.js +++ b/index.ts @@ -76,7 +76,7 @@ async function main() { }); } -async function generateCommitMessage(prompt) { +async function generateCommitMessage(prompt: string) { const payload = { model: "text-davinci-003", prompt, @@ -97,7 +97,7 @@ async function generateCommitMessage(prompt) { body: JSON.stringify(payload), }); - const json = await response.json(); + const json: any = await response.json(); const aiCommit = json.choices[0].text; return aiCommit.replace(/(\r\n|\n|\r)/gm, ""); diff --git a/package.json b/package.json index 4644a84..d10825f 100644 --- a/package.json +++ b/package.json @@ -2,17 +2,20 @@ "name": "aicommits", "version": "0.1.4", "description": "Writes your git commit messages for you with AI", - "main": "index.js", + "main": "bin/index.js", "bin": { - "aicommits": "./index.js" + "aicommits": "bin/index.js" }, - "type": "module", "repository": "https://github.com/Nutlope/aicommits", "author": "Hassan El Mghari (@nutlope)", "license": "MIT", + "scripts": { + "build": "tsc" + }, "dependencies": { "chalk": "^5.2.0", "inquirer": "^9.1.4", - "node-fetch": "^3.3.0" + "node-fetch": "^3.3.0", + "typescript": "^4.9.5" } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..9c8605e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + "module": "commonjs" /* Specify what module code is generated. */, + "outDir": "./bin" /* Specify an output folder for all emitted files. */, + "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, + "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, + "strict": true /* Enable all strict type-checking options. */, + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + }, + "exclude": ["node_modules"] +}