Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update repo info, package-lock, add husky, add install/reinstall scripts #6

Merged
merged 3 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/funding.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github: [waylaidwanderer]
github: [danny-avila]
35 changes: 35 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Node.js Package

# The workflow is triggered when a tag is pushed
on:
push:
tags:
- "*"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: NODE_ENV=production npm ci
- run: npm run build --if-present
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- run: NODE_ENV=production npm ci
- run: npm run build --if-present
- run: npm test
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
3 changes: 3 additions & 0 deletions .husky/lint-staged.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'*.{js,ts}': ['eslint --fix', 'eslint'],
};
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
set -e
. "$(dirname -- "$0")/_/husky.sh"
[ -n "$CI" ] && exit 0
npx lint-staged --config ./.husky/lint-staged.config.cjs
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

## Updates
<details open>
<summary><strong>2023-10-14</strong></summary>
This repo has been forked from [waylaidwanderer/node-chatgpt-api](https://github.com/waylaidwanderer/node-chatgpt-api) for active maintenance.

</details>

<details>
<summary><strong>2023-03-01</strong></summary>

**Support for the official ChatGPT model has been added!** You can now use the `gpt-3.5-turbo` model with the official OpenAI API, using `ChatGPTClient`. This is the same model that ChatGPT uses, and it's the most powerful model available right now. Usage of this model is **not free**, however it is **10x cheaper** (priced at $0.002 per 1k tokens) than `text-davinci-003`.
Expand Down
61 changes: 61 additions & 0 deletions config/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Helper functions
* This allows us to give the console some colour when running in a terminal
*
*/
import fs from 'fs';
import path from 'path';
import readline from 'readline';
import { fileURLToPath } from 'url';
import { execSync } from 'child_process';

export const getRootDir = (trajectory = '..') => {
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
return path.resolve(dirname, trajectory);
};

export const askQuestion = (query) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

return new Promise(resolve => rl.question(`\x1b[36m${query}\n> \x1b[0m`, (ans) => {
rl.close();
resolve(ans);
}));
};

export function isDockerRunning() {
try {
execSync('docker info');
return true;
} catch (e) {
return false;
}
}

export function deleteNodeModules(dir) {
const nodeModulesPath = path.join(dir, 'node_modules');
if (fs.existsSync(nodeModulesPath)) {
console.purple(`Deleting node_modules in ${dir}`);
fs.rmSync(nodeModulesPath, { recursive: true });
}
}

export const silentExit = (code = 0) => {
console.log = () => {};
process.exit(code);
};

// Set the console colours
console.orange = msg => console.log('\x1b[33m%s\x1b[0m', msg);
console.green = msg => console.log('\x1b[32m%s\x1b[0m', msg);
console.red = msg => console.log('\x1b[31m%s\x1b[0m', msg);
console.blue = msg => console.log('\x1b[34m%s\x1b[0m', msg);
console.purple = msg => console.log('\x1b[35m%s\x1b[0m', msg);
console.cyan = msg => console.log('\x1b[36m%s\x1b[0m', msg);
console.yellow = msg => console.log('\x1b[33m%s\x1b[0m', msg);
console.white = msg => console.log('\x1b[37m%s\x1b[0m', msg);
console.gray = msg => console.log('\x1b[90m%s\x1b[0m', msg);
28 changes: 28 additions & 0 deletions config/packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { execSync } from 'child_process';
import path from 'path';
import fs from 'fs';
import { deleteNodeModules, getRootDir } from './helpers.js';

// Set the directories
const rootDir = getRootDir();
const directories = [rootDir];

// Delete package-lock if it exists
const packageLockPath = path.resolve(rootDir, 'package-lock.json');
if (fs.existsSync(packageLockPath)) {
console.purple('Deleting package-lock.json...');
fs.unlinkSync(packageLockPath);
}

(async () => {
// Delete all node_modules
directories.forEach(deleteNodeModules);

// Run npm cache clean --force
console.purple('Cleaning npm cache...');
execSync('npm cache clean --force', { stdio: 'inherit' });

// Install dependencies
console.purple('Installing dependencies...');
execSync('npm install', { stdio: 'inherit' });
})();
44 changes: 44 additions & 0 deletions config/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { execSync } from 'child_process';
import { deleteNodeModules, getRootDir } from './helpers.js';

const config = {
skipGit: process.argv.includes('-g'),
};

// Set the directories
const rootDir = getRootDir();
const directories = [rootDir];

(async () => {
console.green(
'Starting update script, this may take a minute or two depending on your system and network.',
);

const { skipGit } = config;
if (!skipGit) {
// Fetch latest repo
console.purple('Fetching the latest repo...');
execSync('git fetch origin', { stdio: 'inherit' });

// Switch to main branch
console.purple('Switching to main branch...');
execSync('git checkout main', { stdio: 'inherit' });

// Git pull origin main
console.purple('Pulling the latest code from main...');
execSync('git pull origin main', { stdio: 'inherit' });
}

// Delete all node_modules
directories.forEach(deleteNodeModules);

// Run npm cache clean --force
console.purple('Cleaning npm cache...');
execSync('npm cache clean --force', { stdio: 'inherit' });

// Install dependencies
console.purple('Installing dependencies...');
execSync('npm ci', { stdio: 'inherit' });

console.green('node-gpt-api is now up to date!');
})();
Loading