From dad58d83c3d7f9c65302e1a57088c414a33e8011 Mon Sep 17 00:00:00 2001 From: Mohammad Iskandarani Date: Tue, 14 Mar 2023 17:31:17 +0300 Subject: [PATCH] Move files into src, rename classes --- esbuild.config.mjs | 12 ++++++------ assistant.ts => src/assistant.ts | 2 +- main.ts => src/main.ts | 17 +++++++---------- utils.ts => src/utils.ts | 0 4 files changed, 14 insertions(+), 17 deletions(-) rename assistant.ts => src/assistant.ts (98%) rename main.ts => src/main.ts (92%) rename utils.ts => src/utils.ts (100%) diff --git a/esbuild.config.mjs b/esbuild.config.mjs index b13282b..e4197e9 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -2,20 +2,19 @@ import esbuild from "esbuild"; import process from "process"; import builtins from "builtin-modules"; -const banner = -`/* +const banner = `/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ `; -const prod = (process.argv[2] === "production"); +const prod = process.argv[2] === "production"; const context = await esbuild.context({ banner: { js: banner, }, - entryPoints: ["main.ts"], + entryPoints: ["src/main.ts"], bundle: true, external: [ "obsidian", @@ -31,7 +30,8 @@ const context = await esbuild.context({ "@lezer/common", "@lezer/highlight", "@lezer/lr", - ...builtins], + ...builtins, + ], format: "cjs", target: "es2018", logLevel: "info", @@ -45,4 +45,4 @@ if (prod) { process.exit(0); } else { await context.watch(); -} \ No newline at end of file +} diff --git a/assistant.ts b/src/assistant.ts similarity index 98% rename from assistant.ts rename to src/assistant.ts index 34120ca..d09e71e 100644 --- a/assistant.ts +++ b/src/assistant.ts @@ -1,6 +1,6 @@ import { Configuration, OpenAIApi } from "openai"; import GPT3Tokenizer from "gpt3-tokenizer"; -import { cosineSimilarity } from "utils"; +import { cosineSimilarity } from "./utils"; export interface chunkData { text: string; diff --git a/main.ts b/src/main.ts similarity index 92% rename from main.ts rename to src/main.ts index 50b3224..0e3b056 100644 --- a/main.ts +++ b/src/main.ts @@ -1,8 +1,6 @@ -import { Answer, Assistant } from "assistant"; +import { Answer, Assistant } from "./assistant"; import { App, - Component, - MarkdownPreviewRenderer, MarkdownRenderer, Modal, Notice, @@ -11,18 +9,17 @@ import { Setting, TextAreaComponent, } from "obsidian"; -// TODO: Remember to rename these classes and interfaces! -interface MyPluginSettings { +interface PluginSettings { apiKey: string; } -const DEFAULT_SETTINGS: MyPluginSettings = { +const DEFAULT_SETTINGS: PluginSettings = { apiKey: "", }; -export default class MyPlugin extends Plugin { - settings: MyPluginSettings; +export default class GPTAssistantPlugin extends Plugin { + settings: PluginSettings; assistant: Assistant; async onload() { this.addSettingTab(new AssistantSettings(this.app, this)); @@ -152,9 +149,9 @@ class AskAssistantModal extends Modal { } class AssistantSettings extends PluginSettingTab { - plugin: MyPlugin; + plugin: GPTAssistantPlugin; - constructor(app: App, plugin: MyPlugin) { + constructor(app: App, plugin: GPTAssistantPlugin) { super(app, plugin); this.plugin = plugin; } diff --git a/utils.ts b/src/utils.ts similarity index 100% rename from utils.ts rename to src/utils.ts