From 3e2d878e12ba1fb201cc17d0a000aa2a6be53034 Mon Sep 17 00:00:00 2001 From: hiento09 <136591877+hiento09@users.noreply.github.com> Date: Tue, 17 Oct 2023 13:56:57 +0700 Subject: [PATCH] Rename plugin-core to core (#370) Co-authored-by: Hien To <> --- .github/workflows/publish-plugin-core.yml | 24 +++++++++--------- {plugin-core => core}/README.md | 30 +++++++++++------------ {plugin-core => core}/core.ts | 0 {plugin-core => core}/events.ts | 0 {plugin-core => core}/index.ts | 0 {plugin-core => core}/package-lock.json | 8 +++--- {plugin-core => core}/package.json | 4 +-- {plugin-core => core}/preferences.ts | 0 {plugin-core => core}/store.ts | 0 {plugin-core => core}/tsconfig.json | 0 {plugin-core => core}/types/index.d.ts | 0 11 files changed, 33 insertions(+), 33 deletions(-) rename {plugin-core => core}/README.md (93%) rename {plugin-core => core}/core.ts (100%) rename {plugin-core => core}/events.ts (100%) rename {plugin-core => core}/index.ts (100%) rename {plugin-core => core}/package-lock.json (88%) rename {plugin-core => core}/package.json (92%) rename {plugin-core => core}/preferences.ts (100%) rename {plugin-core => core}/store.ts (100%) rename {plugin-core => core}/tsconfig.json (100%) rename {plugin-core => core}/types/index.d.ts (100%) diff --git a/.github/workflows/publish-plugin-core.yml b/.github/workflows/publish-plugin-core.yml index 9614a8759..4d8227c62 100644 --- a/.github/workflows/publish-plugin-core.yml +++ b/.github/workflows/publish-plugin-core.yml @@ -1,12 +1,12 @@ -name: Publish Plugin-core Package to npmjs +name: Publish plugin core Package to npmjs on: push: branches: - main paths: - - "plugin-core/**" - - ".github/workflows/publish-plugin-core.yml" - - "!plugin-core/package.json" + - "core/**" + - ".github/workflows/publish-core.yml" + - "!core/package.json" jobs: build: runs-on: ubuntu-latest @@ -23,7 +23,7 @@ jobs: - name: "Auto Increase package Version" run: | # Extract current version - current_version=$(jq -r '.version' plugin-core/package.json) + current_version=$(jq -r '.version' core/package.json) # Break the version into its components major_version=$(echo $current_version | cut -d "." -f 1) @@ -37,7 +37,7 @@ jobs: new_version="$major_version.$minor_version.$new_patch_version" # Replace the old version with the new version in package.json - jq --arg version "$new_version" '.version = $version' plugin-core/package.json > /tmp/package.json && mv /tmp/package.json plugin-core/package.json + jq --arg version "$new_version" '.version = $version' core/package.json > /tmp/package.json && mv /tmp/package.json core/package.json # Print the new version echo "Updated package.json version to: $new_version" @@ -48,19 +48,19 @@ jobs: node-version: "20.x" registry-url: "https://registry.npmjs.org" - run: npm install && npm run build - working-directory: ./plugin-core + working-directory: ./core - run: npm publish --access public env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - working-directory: ./plugin-core + working-directory: ./core - name: "Commit new version to main and create tag" run: | - version=$(jq -r '.version' plugin-core/package.json) + version=$(jq -r '.version' core/package.json) git config --global user.email "service@jan.ai" git config --global user.name "Service Account" - git add plugin-core/package.json + git add core/package.json git commit -m "${GITHUB_REPOSITORY}: Update tag build $version" git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.PAT_SERVICE_ACCOUNT }}" push origin HEAD:main - git tag -a plugin-core-$version -m "${GITHUB_REPOSITORY}: Update tag build $version for plugin-core" - git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.PAT_SERVICE_ACCOUNT }}" push origin plugin-core-$version + git tag -a core-$version -m "${GITHUB_REPOSITORY}: Update tag build $version for core" + git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.PAT_SERVICE_ACCOUNT }}" push origin core-$version diff --git a/plugin-core/README.md b/core/README.md similarity index 93% rename from plugin-core/README.md rename to core/README.md index ee4814ffc..1803a2e7d 100644 --- a/plugin-core/README.md +++ b/core/README.md @@ -1,4 +1,4 @@ -## @janhq/plugin-core +## @janhq/core > The module includes functions for communicating with core APIs, registering plugin extensions, and exporting type definitions. @@ -8,10 +8,10 @@ ```js // javascript -const core = require("@janhq/plugin-core"); +const core = require("@janhq/core"); // typescript -import { core } from "@janhq/plugin-core"; +import { core } from "@janhq/core"; ``` ### Register Plugin Extensions @@ -23,7 +23,7 @@ You can `register` any function as a plugin extension using `CoreServiceAPI` bel Once the extension is registered, it can be used by other plugins or components in the Jan platform. For example, a UI component might use the DataService.GetConversations extension to retrieve a list of conversations to display to the user. ```js -import { RegisterExtensionPoint, DataService } from "@janhq/plugin-core"; +import { RegisterExtensionPoint, DataService } from "@janhq/core"; function getConversations() { // Your logic here @@ -43,7 +43,7 @@ The Core API allows you to interact with local data storage. Here are a couple o You can use the store.insertOne function to insert data into a specific collection in the local data store. ```js -import { store } from "@janhq/plugin-core"; +import { store } from "@janhq/core"; function insertData() { store.insertOne("conversations", { name: "meow" }); @@ -59,7 +59,7 @@ store.getOne(collectionName, key) retrieves a single document that matches the p store.getMany(collectionName, selector, sort) retrieves multiple documents that match the provided selector in the specified collection. ```js -import { store } from "@janhq/plugin-core"; +import { store } from "@janhq/core"; function getData() { const selector = { name: "meow" }; @@ -104,7 +104,7 @@ function deleteData() { You can subscribe to NewMessageRequest events by defining a function to handle the event and registering it with the events object: ```js -import { events } from "@janhq/plugin-core"; +import { events } from "@janhq/core"; function handleMessageRequest(message: NewMessageRequest) { // Your logic here. For example: @@ -122,7 +122,7 @@ export function init({ register }) { In this example, we're defining a function called handleMessageRequest that takes a NewMessageRequest object as its argument. We're also defining a function called registerListener that registers the handleMessageRequest function as a listener for NewMessageRequest events using the on method of the events object. ```js -import { events } from "@janhq/plugin-core"; +import { events } from "@janhq/core"; function handleMessageRequest(data: NewMessageRequest) { // Your logic here. For example: @@ -138,10 +138,10 @@ function handleMessageRequest(data: NewMessageRequest) { ### Preferences -To register plugin preferences, you can use the preferences object from the @janhq/plugin-core package. Here's an example of how to register and retrieve plugin preferences: +To register plugin preferences, you can use the preferences object from the @janhq/core package. Here's an example of how to register and retrieve plugin preferences: ```js -import { PluginService, preferences } from "@janhq/plugin-core"; +import { PluginService, preferences } from "@janhq/core"; const pluginName = "your-first-plugin"; const preferenceKey = ""; @@ -165,7 +165,7 @@ In this example, we're registering preference update handlers and plugin prefere To retrieve the values of the registered preferences, we're using the get method of the preferences object and passing in the name of the plugin and the name of the preference. ```js -import { preferences } from "@janhq/plugin-core"; +import { preferences } from "@janhq/core"; const pluginName = "your-first-plugin"; const preferenceKey = "apiKey"; @@ -182,11 +182,11 @@ To access the Core API in your plugin, you can follow the code examples and expl ##### Import Core API and Store Module -In your main entry code (e.g., `index.ts`), start by importing the necessary modules and functions from the `@janhq/plugin-core` library. +In your main entry code (e.g., `index.ts`), start by importing the necessary modules and functions from the `@janhq/core` library. ```js // index.ts -import { core } from "@janhq/plugin-core"; +import { core } from "@janhq/core"; ``` #### Perform File Operations @@ -219,11 +219,11 @@ To execute a plugin module in the main process of your application, you can foll ##### Import the `core` Object -In your main process code (e.g., `index.ts`), start by importing the `core` object from the `@janhq/plugin-core` library. +In your main process code (e.g., `index.ts`), start by importing the `core` object from the `@janhq/core` library. ```js // index.ts -import { core } from "@janhq/plugin-core"; +import { core } from "@janhq/core"; ``` ##### Define the Module Path diff --git a/plugin-core/core.ts b/core/core.ts similarity index 100% rename from plugin-core/core.ts rename to core/core.ts diff --git a/plugin-core/events.ts b/core/events.ts similarity index 100% rename from plugin-core/events.ts rename to core/events.ts diff --git a/plugin-core/index.ts b/core/index.ts similarity index 100% rename from plugin-core/index.ts rename to core/index.ts diff --git a/plugin-core/package-lock.json b/core/package-lock.json similarity index 88% rename from plugin-core/package-lock.json rename to core/package-lock.json index d7c80a77f..3a2846eaa 100644 --- a/plugin-core/package-lock.json +++ b/core/package-lock.json @@ -1,12 +1,12 @@ { - "name": "@janhq/plugin-core", - "version": "0.1.6", + "name": "@janhq/core", + "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@janhq/plugin-core", - "version": "0.1.6", + "name": "@janhq/core", + "version": "0.1.0", "license": "MIT", "devDependencies": { "@types/node": "^12.0.2", diff --git a/plugin-core/package.json b/core/package.json similarity index 92% rename from plugin-core/package.json rename to core/package.json index 26dcb548a..db747ed06 100644 --- a/plugin-core/package.json +++ b/core/package.json @@ -1,6 +1,6 @@ { - "name": "@janhq/plugin-core", - "version": "0.1.8", + "name": "@janhq/core", + "version": "0.1.0", "description": "Plugin core lib", "keywords": [ "jan", diff --git a/plugin-core/preferences.ts b/core/preferences.ts similarity index 100% rename from plugin-core/preferences.ts rename to core/preferences.ts diff --git a/plugin-core/store.ts b/core/store.ts similarity index 100% rename from plugin-core/store.ts rename to core/store.ts diff --git a/plugin-core/tsconfig.json b/core/tsconfig.json similarity index 100% rename from plugin-core/tsconfig.json rename to core/tsconfig.json diff --git a/plugin-core/types/index.d.ts b/core/types/index.d.ts similarity index 100% rename from plugin-core/types/index.d.ts rename to core/types/index.d.ts