diff --git a/.github/workflows/jan-electron-build.yml b/.github/workflows/jan-electron-build.yml index df2b245047..f1c0f5c1e7 100644 --- a/.github/workflows/jan-electron-build.yml +++ b/.github/workflows/jan-electron-build.yml @@ -122,7 +122,7 @@ jobs: yarn build:core yarn install $env:NITRO_VERSION = Get-Content .\plugins\inference-plugin\nitro\version.txt; echo $env:NITRO_VERSION - yarn build:plugins-windows + yarn build:plugins-win32 - name: Build and publish app run: | diff --git a/.github/workflows/jan-electron-linter-and-test.yml b/.github/workflows/jan-electron-linter-and-test.yml index 2c781f6026..1938a40f53 100644 --- a/.github/workflows/jan-electron-linter-and-test.yml +++ b/.github/workflows/jan-electron-linter-and-test.yml @@ -95,7 +95,7 @@ jobs: yarn build:core yarn install $env:NITRO_VERSION = Get-Content .\plugins\inference-plugin\nitro\version.txt; echo $env:NITRO_VERSION - yarn build:plugins-windows + yarn build:plugins-win32 yarn build:test-win32 $env:CI="e2e" yarn test diff --git a/.github/workflows/jan-plugin-core.yml b/.github/workflows/jan-plugin-core.yml deleted file mode 100644 index 39cc2f349a..0000000000 --- a/.github/workflows/jan-plugin-core.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: Plugin Core -on: - push: - branches: - - main - paths: - - "core/**" - - "!core/package.json" - pull_request: - branches: - - main - paths: - - "core/**" - - ".github/workflows/jan-plugin-core.yml" - - "!core/package.json" -jobs: - build-and-publish-plugins: - runs-on: ubuntu-latest - environment: production - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: "0" - token: ${{ secrets.PAT_SERVICE_ACCOUNT }} - - - name: Install jq - uses: dcarbone/install-jq-action@v2.0.1 - - - name: "Auto Increase package Version" - run: | - # Extract current version - current_version=$(jq -r '.version' core/package.json) - - # Break the version into its components - major_version=$(echo $current_version | cut -d "." -f 1) - minor_version=$(echo $current_version | cut -d "." -f 2) - patch_version=$(echo $current_version | cut -d "." -f 3) - - # Increment the patch version by one - new_patch_version=$((patch_version+1)) - - # Construct the new version - 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' 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" - - # Setup .npmrc file to publish to npm - - uses: actions/setup-node@v3 - with: - node-version: "20.x" - registry-url: "https://registry.npmjs.org" - - run: npm install && npm run build - working-directory: ./core - - run: npm publish --access public - if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - working-directory: ./core - - - name: "Commit new version to main and create tag" - if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository - run: | - version=$(jq -r '.version' core/package.json) - git config --global user.email "service@jan.ai" - git config --global user.name "Service Account" - 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 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/.github/workflows/jan-plugins.yml b/.github/workflows/jan-plugins.yml deleted file mode 100644 index fee3b977d7..0000000000 --- a/.github/workflows/jan-plugins.yml +++ /dev/null @@ -1,163 +0,0 @@ -name: Jan Default Plugins -on: - push: - branches: - - main - paths: - - "plugins/**" - - "!plugins/*/package.json" - pull_request: - branches: - - main - paths: - - "plugins/**" - - ".github/workflows/jan-plugins.yml" - - "!plugins/*/package.json" -jobs: - build: - runs-on: macos-latest - environment: production - outputs: - branch_name: ${{ steps.commit_and_tag.outputs.branch_name }} - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: "0" - token: ${{ secrets.PAT_SERVICE_ACCOUNT }} - - - name: Install jq - uses: dcarbone/install-jq-action@v2.0.1 - - - name: Get Cer for code signing - run: base64 -d <<< "$CODE_SIGN_P12_BASE64" > /tmp/codesign.p12 - shell: bash - env: - CODE_SIGN_P12_BASE64: ${{ secrets.CODE_SIGN_P12_BASE64 }} - - - uses: apple-actions/import-codesign-certs@v2 - continue-on-error: true - with: - p12-file-base64: ${{ secrets.CODE_SIGN_P12_BASE64 }} - p12-password: ${{ secrets.CODE_SIGN_P12_PASSWORD }} - - - name: Check Path Change - run: | - git config --global user.email "service@jan.ai" - git config --global user.name "Service Account" - echo "Changes in these directories trigger the build:" - changed_dirs=$(git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.GITHUB_TOKEN }}" diff --name-only HEAD HEAD~1 | grep '^plugins/' | awk -F/ '{print $2}' | uniq) - echo $changed_dirs > /tmp/change_dir.txt - - - name: "Auto Increase package Version" - run: | - cd plugins - for dir in $(cat /tmp/change_dir.txt) - do - echo "$dir" - if [ ! -d "$dir" ]; then - echo "Directory $dir does not exist, plugin might be removed, skipping..." - continue - fi - - # Extract current version - current_version=$(jq -r '.version' $dir/package.json) - - # Break the version into its components - major_version=$(echo $current_version | cut -d "." -f 1) - minor_version=$(echo $current_version | cut -d "." -f 2) - patch_version=$(echo $current_version | cut -d "." -f 3) - - # Increment the patch version by one - new_patch_version=$((patch_version+1)) - - # Construct the new version - 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' $dir/package.json > /tmp/package.json && mv /tmp/package.json $dir/package.json - - # Print the new version - echo "Updated $dir package.json version to: $new_version" - done - - # Setup .npmrc file to publish to npm - - uses: actions/setup-node@v3 - with: - node-version: "20.x" - registry-url: "https://registry.npmjs.org" - - name: Build core module - run: | - cd core - npm install - npm run build - - - name: Publish npm packages - run: | - cd plugins - for dir in $(cat /tmp/change_dir.txt) - do - echo $dir - if [ ! -d "$dir" ]; then - echo "Directory $dir does not exist, plugin might be removed, skipping..." - continue - fi - cd $dir - npm install - if [[ $dir == 'data-plugin' ]]; then - npm run build:deps - fi - npm run postinstall && ../../.github/scripts/auto-sign.sh - if [[ $GITHUB_EVENT_NAME == 'push' && $GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FULL_NAME != $GITHUB_REPOSITORY ]]; then - npm publish --access public - fi - cd .. - done - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - DEVELOPER_ID: ${{ secrets.DEVELOPER_ID }} - APP_PATH: "." - - - name: "Commit new version to main and create tag" - id: commit_and_tag - if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository - run: | - rm -rf /tmp/plugin-catalog - git clone https://${{ secrets.SERVICE_ACCOUNT_USERNAME }}:${{ secrets.PAT_SERVICE_ACCOUNT }}@github.com/janhq/plugin-catalog.git /tmp/plugin-catalog - for dir in $(cat /tmp/change_dir.txt) - do - echo "$dir" - if [ ! -d "$dir" ]; then - echo "Directory $dir does not exist, plugin might be removed, skipping..." - continue - fi - version=$(jq -r '.version' plugins/$dir/package.json) - git config --global user.email "service@jan.ai" - git config --global user.name "Service Account" - git add plugins/$dir/package.json - git commit -m "${GITHUB_REPOSITORY}: Update tag build $version for $dir" - git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.PAT_SERVICE_ACCOUNT }}" push origin HEAD:main - git tag -a $dir-$version -m "${GITHUB_REPOSITORY}: Update tag build $version for $dir" - git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.PAT_SERVICE_ACCOUNT }}" push origin $dir-$version - plugin_name=$(jq -r '.name | sub("@janhq/"; "")' plugins/$dir/package.json) - cp plugins/$dir/package.json /tmp/plugin-catalog/${plugin_name}.json - done - cd /tmp/plugin-catalog - BRANCH_NAME="update-package-$(date +'%Y%m%d%H%M%S')" - git checkout -b $BRANCH_NAME - git add . - git commit -m "Update plugin catalog" - git push origin $BRANCH_NAME - cd /tmp && rm -rf /tmp/plugin-catalog - echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV - echo "::set-output name=branch_name::$BRANCH_NAME" - - pull_request: - runs-on: ubuntu-latest - environment: production - if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository - needs: build - steps: - - run: | - gh pr create --title "Update plugin catalog" --body "Update plugin catalog" --base main --head ${{ needs.build.outputs.branch_name }} --repo janhq/plugin-catalog --reviewer louis-jan,hiento09 - env: - GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }} diff --git a/package.json b/package.json index a8a7397b42..32506ea80c 100644 --- a/package.json +++ b/package.json @@ -35,27 +35,22 @@ "build:web": "yarn workspace jan-web build && cpx \"web/out/**\" \"electron/renderer/\"", "build:electron": "yarn workspace jan build", "build:electron:test": "yarn workspace jan build:test", - "build:pull-plugins": "rimraf ./electron/core/pre-install/*.tgz && cd ./electron/core/pre-install && npm pack @janhq/inference-plugin @janhq/monitoring-plugin", - "build:plugins": "rimraf ./electron/core/pre-install/*.tgz && concurrently --kill-others-on-fail \"cd ./plugins/conversational-json && npm install && npm run postinstall && npm run build:publish\" \"cd ./plugins/inference-plugin && npm install --ignore-scripts && npm run postinstall:dev && npm run build:publish\" \"cd ./plugins/model-plugin && npm install && npm run postinstall && npm run build:publish\" \"cd ./plugins/monitoring-plugin && npm install && npm run postinstall && npm run build:publish\"", - "build:plugins-windows": "rimraf ./electron/core/pre-install/*.tgz && concurrently --kill-others-on-fail \"cd ./plugins/conversational-json && npm install && npm run postinstall && npm run build:publish\" \"cd ./plugins/inference-plugin && npm install --ignore-scripts && npm run postinstall:windows && npm run build:publish\" \"cd ./plugins/model-plugin && npm install && npm run postinstall && npm run build:publish\" \"cd ./plugins/monitoring-plugin && npm install && npm run postinstall && npm run build:publish\"", - "build:plugins-linux": "rimraf ./electron/core/pre-install/*.tgz && concurrently --kill-others-on-fail \"cd ./plugins/conversational-json && npm install && npm run postinstall && npm run build:publish\" \"cd ./plugins/inference-plugin && npm install && npm run postinstall && npm run build:publish\" \"cd ./plugins/model-plugin && npm install && npm run postinstall && npm run build:publish\" \"cd ./plugins/monitoring-plugin && npm install && npm run postinstall && npm run build:publish\"", - "build:plugins-darwin": "rimraf ./electron/core/pre-install/*.tgz && concurrently --kill-others-on-fail \"cd ./plugins/conversational-json && npm install && npm run postinstall && npm run build:publish\" \"cd ./plugins/inference-plugin && npm install && npm run postinstall && ../../.github/scripts/auto-sign.sh && npm run build:publish\" \"cd ./plugins/model-plugin && npm install && npm run postinstall && npm run build:publish\" \"cd ./plugins/monitoring-plugin && npm install && npm run postinstall && npm run build:publish\"", - "build:plugins-web": "rimraf ./electron/core/pre-install/*.tgz && concurrently --kill-others-on-fail \"cd ./plugins/conversational-json && npm install && npm run build:deps && npm run postinstall\" \"cd ./plugins/inference-plugin && npm install && npm run postinstall\" \"cd ./plugins/model-plugin && npm install && npm run postinstall\" \"cd ./plugins/monitoring-plugin && npm install && npm run postinstall\" && concurrently --kill-others-on-fail \"cd ./plugins/conversational-json && npm run build:publish\" \"cd ./plugins/inference-plugin && npm run build:publish\" \"cd ./plugins/model-plugin && npm run build:publish\" \"cd ./plugins/monitoring-plugin && npm run build:publish\"", - "build": "yarn build:web && yarn build:electron", + "build:plugins": "rimraf ./electron/core/pre-install/*.tgz && concurrently --kill-others-on-fail \"cd ./plugins/conversational-json && npm install && npm run build:publish\" \"cd ./plugins/inference-plugin && npm install && npm run build:publish\" \"cd ./plugins/model-plugin && npm install && npm run build:publish\" \"cd ./plugins/monitoring-plugin && npm install && npm run build:publish\"", + "build:plugins-win32": "rimraf ./electron/core/pre-install/*.tgz && concurrently --kill-others-on-fail \"cd ./plugins/conversational-json && npm install && npm run build:publish\" \"cd ./plugins/inference-plugin && npm install && npm run build:publish-win32\" \"cd ./plugins/model-plugin && npm install && npm run build:publish\" \"cd ./plugins/monitoring-plugin && npm install && npm run build:publish\"", + "build:plugins-linux": "rimraf ./electron/core/pre-install/*.tgz && concurrently --kill-others-on-fail \"cd ./plugins/conversational-json && npm install && npm run build:publish\" \"cd ./plugins/inference-plugin && npm install && npm run build:publish-linux\" \"cd ./plugins/model-plugin && npm install && npm run build:publish\" \"cd ./plugins/monitoring-plugin && npm install && npm run build:publish\"", + "build:plugins-darwin": "rimraf ./electron/core/pre-install/*.tgz && concurrently --kill-others-on-fail \"cd ./plugins/conversational-json && npm install && npm run build:publish\" \"cd ./plugins/inference-plugin && npm install && npm run build:publish-darwin\" \"cd ./plugins/model-plugin && npm install && npm run build:publish\" \"cd ./plugins/monitoring-plugin && npm install && npm run build:publish\"", "build:test": "yarn build:web && yarn build:electron:test", "build:test-darwin": "yarn build:web && yarn workspace jan build:test-darwin", "build:test-win32": "yarn build:web && yarn workspace jan build:test-win32", "build:test-linux": "yarn build:web && yarn workspace jan build:test-linux", + "build": "yarn build:web && yarn build:electron", "build:darwin": "yarn build:web && yarn workspace jan build:darwin", "build:win32": "yarn build:web && yarn workspace jan build:win32", "build:linux": "yarn build:web && yarn workspace jan build:linux", "build:publish": "yarn build:web && yarn workspace jan build:publish", "build:publish-darwin": "yarn build:web && yarn workspace jan build:publish-darwin", "build:publish-win32": "yarn build:web && yarn workspace jan build:publish-win32", - "build:publish-linux": "yarn build:web && yarn workspace jan build:publish-linux", - "build:web-plugins": "yarn build:web && yarn build:plugins-web && mkdir -p \"./web/out/plugins/conversational-json\" && cp \"./plugins/conversational-json/dist/index.js\" \"./web/out/plugins/conversational-json\" && mkdir -p \"./web/out/plugins/inference-plugin\" && cp \"./plugins/inference-plugin/dist/index.js\" \"./web/out/plugins/inference-plugin\" && mkdir -p \"./web/out/plugins/model-plugin\" && cp \"./plugins/model-plugin/dist/index.js\" \"./web/out/plugins/model-plugin\" && mkdir -p \"./web/out/plugins/monitoring-plugin\" && cp \"./plugins/monitoring-plugin/dist/index.js\" \"./web/out/plugins/monitoring-plugin\"", - "server:prod": "yarn workspace server build && yarn build:web-plugins && cpx \"web/out/**\" \"server/build/renderer/\" && mkdir -p ./server/build/@janhq && cp -r ./plugins/* ./server/build/@janhq", - "start:server": "yarn server:prod && node server/build/main.js" + "build:publish-linux": "yarn build:web && yarn workspace jan build:publish-linux" }, "devDependencies": { "concurrently": "^8.2.1", diff --git a/plugins/conversational-json/package.json b/plugins/conversational-json/package.json index db2978aab5..198756f82e 100644 --- a/plugins/conversational-json/package.json +++ b/plugins/conversational-json/package.json @@ -10,9 +10,7 @@ ], "scripts": { "build": "tsc -b . && webpack --config webpack.config.js", - "postinstall": "rimraf *.tgz --glob && npm run build", - "build:publish": "npm pack && cpx *.tgz ../../electron/core/pre-install", - "build:debug": "rimraf *.tgz --glob && npm run build && npm pack" + "build:publish": "rimraf *.tgz --glob && npm run build && npm pack && cpx *.tgz ../../electron/core/pre-install" }, "exports": { ".": "./dist/index.js", diff --git a/plugins/conversational-plugin/package.json b/plugins/conversational-plugin/package.json index 3566ef04bc..e7a29f9e77 100644 --- a/plugins/conversational-plugin/package.json +++ b/plugins/conversational-plugin/package.json @@ -11,8 +11,7 @@ ], "scripts": { "build": "tsc -b . && webpack --config webpack.config.js", - "postinstall": "rimraf *.tgz --glob && npm run build", - "build:publish": "npm pack && cpx *.tgz ../../electron/core/pre-install" + "build:publish": "rimraf *.tgz --glob npm run build && && npm pack && cpx *.tgz ../../electron/core/pre-install" }, "exports": { ".": "./dist/index.js", diff --git a/plugins/inference-plugin/package.json b/plugins/inference-plugin/package.json index 8a2e84ad7d..daa60f8e07 100644 --- a/plugins/inference-plugin/package.json +++ b/plugins/inference-plugin/package.json @@ -15,15 +15,16 @@ "build": "tsc -b . && webpack --config webpack.config.js", "downloadnitro:linux-cpu": "NITRO_VERSION=$(cat ./nitro/version.txt) && download https://github.com/janhq/nitro/releases/download/v${NITRO_VERSION}/nitro-${NITRO_VERSION}-linux-amd64.zip -e --strip 1 -o ./nitro/linux-cpu && chmod +x ./nitro/linux-cpu/nitro && chmod +x ./nitro/linux-start.sh ", "downloadnitro:linux-cuda": "NITRO_VERSION=$(cat ./nitro/version.txt) && download https://github.com/janhq/nitro/releases/download/v${NITRO_VERSION}/nitro-${NITRO_VERSION}-linux-amd64-cuda.zip -e --strip 1 -o ./nitro/linux-cuda && chmod +x ./nitro/linux-cuda/nitro && chmod +x ./nitro/linux-start.sh", - "downloadnitro:mac-arm64": "NITRO_VERSION=$(cat ./nitro/version.txt) && download https://github.com/janhq/nitro/releases/download/v${NITRO_VERSION}/nitro-${NITRO_VERSION}-mac-arm64.zip -e --strip 1 -o ./nitro/mac-arm64 && chmod +x ./nitro/mac-arm64/nitro", - "downloadnitro:mac-x64": "NITRO_VERSION=$(cat ./nitro/version.txt) && download https://github.com/janhq/nitro/releases/download/v${NITRO_VERSION}/nitro-${NITRO_VERSION}-mac-amd64.zip -e --strip 1 -o ./nitro/mac-x64 && chmod +x ./nitro/mac-x64/nitro", - "downloadnitro:win-cpu": "download https://github.com/janhq/nitro/releases/download/v%NITRO_VERSION%/nitro-%NITRO_VERSION%-win-amd64.zip -e --strip 1 -o ./nitro/win-cpu", - "downloadnitro:win-cuda": "download https://github.com/janhq/nitro/releases/download/v%NITRO_VERSION%/nitro-%NITRO_VERSION%-win-amd64-cuda.zip -e --strip 1 -o ./nitro/win-cuda", - "postinstall": "rimraf *.tgz --glob && npm run build && npm run downloadnitro:linux-cpu && npm run downloadnitro:linux-cuda && npm run downloadnitro:mac-arm64 && npm run downloadnitro:mac-x64 && rimraf dist/nitro/* && cpx \"nitro/**\" \"dist/nitro\"", - "postinstall:dev": "rimraf *.tgz --glob && npm run build && npm run downloadnitro:mac-arm64 && npm run downloadnitro:mac-x64 && rimraf dist/nitro/* && cpx \"nitro/**\" \"dist/nitro\"", - "postinstall:windows": "rimraf *.tgz --glob && npm run build && npm run downloadnitro:win-cpu && npm run downloadnitro:win-cuda && rimraf dist/nitro/* && cpx \"nitro/**\" \"dist/nitro\"", - "build:publish": "npm pack && cpx *.tgz ../../electron/core/pre-install", - "build:debug": "rimraf *.tgz --glob && npm run build && npm pack && cpx *.tgz ../../electron/core/pre-install" + "downloadnitro:darwin-arm64": "NITRO_VERSION=$(cat ./nitro/version.txt) && download https://github.com/janhq/nitro/releases/download/v${NITRO_VERSION}/nitro-${NITRO_VERSION}-mac-arm64.zip -e --strip 1 -o ./nitro/mac-arm64 && chmod +x ./nitro/mac-arm64/nitro", + "downloadnitro:darwin-x64": "NITRO_VERSION=$(cat ./nitro/version.txt) && download https://github.com/janhq/nitro/releases/download/v${NITRO_VERSION}/nitro-${NITRO_VERSION}-mac-amd64.zip -e --strip 1 -o ./nitro/mac-x64 && chmod +x ./nitro/mac-x64/nitro", + "downloadnitro:win32-cpu": "download https://github.com/janhq/nitro/releases/download/v%NITRO_VERSION%/nitro-%NITRO_VERSION%-win-amd64.zip -e --strip 1 -o ./nitro/win-cpu", + "downloadnitro:win32-cuda": "download https://github.com/janhq/nitro/releases/download/v%NITRO_VERSION%/nitro-%NITRO_VERSION%-win-amd64-cuda.zip -e --strip 1 -o ./nitro/win-cuda", + "downloadnitro:all": "npm run downloadnitro:darwin-arm64 && npm run downloadnitro:darwin-x64 && downloadnitro:win32-cpu && npm run downloadnitro:win32-cuda && npm run downloadnitro:linux-cpu && npm run downloadnitro:linux-cuda", + "build:publish": "rimraf *.tgz --glob && npm run build && npm run downloadnitro:darwin-arm64 && npm run downloadnitro:darwin-x64 && npm pack && cpx *.tgz ../../electron/core/pre-install", + "build:publish-darwin": "rimraf *.tgz --glob && npm run build && npm run downloadnitro:darwin-arm64 && npm run downloadnitro:darwin-x64 && ../../.github/scripts/auto-sign.sh && npm pack && cpx *.tgz ../../electron/core/pre-install", + "build:publish-win32": "rimraf *.tgz --glob && npm run build && npm run downloadnitro:win32-cpu && npm run downloadnitro:win32-cuda && npm pack && cpx *.tgz ../../electron/core/pre-install", + "build:publish-linux": "rimraf *.tgz --glob && npm run build && npm run downloadnitro:linux-cpu && npm run downloadnitro:linux-cuda && npm pack && cpx *.tgz ../../electron/core/pre-install", + "build:publish-all": "rimraf *.tgz --glob && npm run build && npm run downloadnitro:all && npm pack && cpx *.tgz ../../electron/core/pre-install" }, "exports": { ".": "./dist/index.js", diff --git a/plugins/model-plugin/package.json b/plugins/model-plugin/package.json index 67b50016e8..171f0a4e90 100644 --- a/plugins/model-plugin/package.json +++ b/plugins/model-plugin/package.json @@ -14,9 +14,7 @@ ], "scripts": { "build": "tsc -b . && webpack --config webpack.config.js", - "postinstall": "rimraf *.tgz --glob && npm run build", - "build:publish": "npm pack && cpx *.tgz ../../electron/core/pre-install", - "build:debug": "rimraf *.tgz --glob && npm run build && npm pack && cpx *.tgz ../../electron/core/pre-install" + "build:publish": "rimraf *.tgz --glob && npm run build && npm pack && cpx *.tgz ../../electron/core/pre-install" }, "devDependencies": { "cpx": "^1.5.0", diff --git a/plugins/monitoring-plugin/package.json b/plugins/monitoring-plugin/package.json index a60c910c66..4054b8b4d6 100644 --- a/plugins/monitoring-plugin/package.json +++ b/plugins/monitoring-plugin/package.json @@ -14,8 +14,7 @@ ], "scripts": { "build": "tsc -b . && webpack --config webpack.config.js", - "postinstall": "rimraf *.tgz --glob && npm run build", - "build:publish": "npm pack && cpx *.tgz ../../electron/core/pre-install" + "build:publish": "rimraf *.tgz --glob && npm run build && npm pack && cpx *.tgz ../../electron/core/pre-install" }, "devDependencies": { "rimraf": "^3.0.2", diff --git a/server/main.ts b/server/main.ts deleted file mode 100644 index b98b4097ce..0000000000 --- a/server/main.ts +++ /dev/null @@ -1,179 +0,0 @@ -import express, { Express, Request, Response, NextFunction } from 'express' -import cors from "cors"; -import { resolve } from "path"; -const fs = require("fs"); -const progress = require("request-progress"); -const path = require("path"); -const request = require("request"); - -// Create app dir -const userDataPath = appPath(); -if (!fs.existsSync(userDataPath)) fs.mkdirSync(userDataPath); - -interface ProgressState { - percent?: number; - speed?: number; - size?: { - total: number; - transferred: number; - }; - time?: { - elapsed: number; - remaining: number; - }; - success?: boolean | undefined; - fileName: string; -} - -const options: cors.CorsOptions = { origin: "*" }; -const requiredModules: Record = {}; -const port = process.env.PORT || 4000; -const dataDir = __dirname; -type DownloadProgress = Record; -const downloadProgress: DownloadProgress = {}; -const app: Express = express() -app.use(express.static(dataDir + '/renderer')) -app.use(cors(options)) -app.use(express.json()); - -/** - * Execute a plugin module function via API call - * - * @param modulePath path to module name to import - * @param method function name to execute. The methods "deleteFile" and "downloadFile" will call the server function {@link deleteFile}, {@link downloadFile} instead of the plugin function. - * @param args arguments to pass to the function - * @returns Promise - * - */ -app.post('/api/v1/invokeFunction', (req: Request, res: Response, next: NextFunction): void => { - const method = req.body["method"]; - const args = req.body["args"]; - switch (method) { - case "deleteFile": - deleteFile(args).then(() => res.json(Object())).catch((err: any) => next(err)); - break; - case "downloadFile": - downloadFile(args.downloadUrl, args.fileName).then(() => res.json(Object())).catch((err: any) => next(err)); - break; - default: - const result = invokeFunction(req.body["modulePath"], method, args) - if (typeof result === "undefined") { - res.json(Object()) - } else { - result?.then((result: any) => { - res.json(result) - }).catch((err: any) => next(err)); - } - } -}); - -app.post('/api/v1/downloadProgress', (req: Request, res: Response): void => { - const fileName = req.body["fileName"]; - if (fileName && downloadProgress[fileName]) { - res.json(downloadProgress[fileName]) - return; - } else { - const obj = downloadingFile(); - if (obj) { - res.json(obj) - return; - } - } - res.json(Object()); -}); - -app.use((err: Error, req: Request, res: Response, next: NextFunction): void => { - console.error("ErrorHandler", req.url, req.body, err); - res.status(500); - res.json({ error: err?.message ?? "Internal Server Error" }) -}); - -app.listen(port, () => console.log(`Application is running on port ${port}`)); - - -async function invokeFunction(modulePath: string, method: string, args: any): Promise { - console.log(modulePath, method, args); - const module = require(/* webpackIgnore: true */ path.join( - dataDir, - "", - modulePath - )); - requiredModules[modulePath] = module; - if (typeof module[method] === "function") { - return module[method](...args); - } else { - return Promise.resolve(); - } -} - -function downloadModel(downloadUrl: string, fileName: string): void { - const userDataPath = appPath(); - const destination = resolve(userDataPath, fileName); - console.log("Download file", fileName, "to", destination); - progress(request(downloadUrl), {}) - .on("progress", function (state: any) { - downloadProgress[fileName] = { - ...state, - fileName, - success: undefined - }; - console.log("downloading file", fileName, (state.percent * 100).toFixed(2) + '%'); - }) - .on("error", function (err: Error) { - downloadProgress[fileName] = { - ...downloadProgress[fileName], - success: false, - fileName: fileName, - }; - }) - .on("end", function () { - downloadProgress[fileName] = { - success: true, - fileName: fileName, - }; - }) - .pipe(fs.createWriteStream(destination)); -} - -function deleteFile(filePath: string): Promise { - const userDataPath = appPath(); - const fullPath = resolve(userDataPath, filePath); - return new Promise((resolve, reject) => { - fs.unlink(fullPath, function (err: any) { - if (err && err.code === "ENOENT") { - reject(Error(`File does not exist: ${err}`)); - } else if (err) { - reject(Error(`File delete error: ${err}`)); - } else { - console.log(`Delete file ${filePath} from ${fullPath}`) - resolve(); - } - }); - }) -} - -function downloadingFile(): ProgressState | undefined { - const obj = Object.values(downloadProgress).find(obj => obj && typeof obj.success === "undefined") - return obj -} - - -async function downloadFile(downloadUrl: string, fileName: string): Promise { - return new Promise((resolve, reject) => { - const obj = downloadingFile(); - if (obj) { - reject(Error(obj.fileName + " is being downloaded!")) - return; - }; - (async () => { - downloadModel(downloadUrl, fileName); - })().catch(e => { - console.error("downloadModel", fileName, e); - }); - resolve(); - }); -} - -function appPath(): string { - return process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Preferences' : process.env.HOME + "/.local/share") -} \ No newline at end of file diff --git a/server/nodemon.json b/server/nodemon.json deleted file mode 100644 index fa415fa52b..0000000000 --- a/server/nodemon.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "watch": [ - "main.ts" - ] -} \ No newline at end of file diff --git a/server/package.json b/server/package.json deleted file mode 100644 index 895cae2b99..0000000000 --- a/server/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "server", - "version": "1.0.0", - "main": "index.js", - "license": "MIT", - "dependencies": { - "cors": "^2.8.5", - "electron": "^26.2.1", - "express": "^4.18.2", - "request": "^2.88.2", - "request-progress": "^3.0.0" - }, - "devDependencies": { - "@types/cors": "^2.8.14", - "@types/express": "^4.17.18", - "@types/node": "^20.8.2", - "nodemon": "^3.0.1", - "ts-node": "^10.9.1", - "typescript": "^5.2.2" - }, - "scripts": { - "build": "tsc --project ./", - "dev": "nodemon main.ts", - "prod": "node build/main.js" - } -} diff --git a/server/tsconfig.json b/server/tsconfig.json deleted file mode 100644 index a79afcdfe6..0000000000 --- a/server/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "target": "es5", - "module": "commonjs", - "noImplicitAny": true, - "sourceMap": true, - "strict": true, - "outDir": "./build", - "rootDir": "./", - "noEmitOnError": true, - "baseUrl": ".", - "allowJs": true, - "paths": { "*": ["node_modules/*"] }, - "typeRoots": ["node_modules/@types"], - "esModuleInterop": true - }, - "include": ["./**/*.ts"], - "exclude": ["core", "build", "dist", "tests"] - } \ No newline at end of file