Skip to content

Commit

Permalink
Auto-update misc improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoretsu committed Jan 28, 2024
1 parent aa323aa commit 00f8dea
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 30 deletions.
42 changes: 42 additions & 0 deletions src/@types/github.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace GitHub {
interface Release {
url: string;
assets_url: string;
upload_url: string;
html_url: string;
id: number;
author: {
login: string;
id: number;
node_id: string;
avatar_url: string;
gravatar_id: string;
url: string;
html_url: string;
followers_url: string;
following_url: string;
gists_url: string;
starred_url: string;
subscriptions_url: string;
organizations_url: string;
repos_url: string;
events_url: string;
received_events_url: string;
type: string;
site_admin: boolean
};
node_id: string;
tag_name: string;
target_commitish: string;
name: string;
draft: boolean;
prerelease: boolean;
created_at: string;
published_at: string;
assets: any[];
tarball_url: string;
zipball_url: string;
body: string;
mentions_count: number
}
}
64 changes: 34 additions & 30 deletions src/helpers/updateApp.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
import fs from 'fs/promises';
import fetch from 'node-fetch';
import { exec } from 'child_process';
import os from 'os';
import { exec } from "child_process";
import fetch from "node-fetch";
import os from "os";
import { version as localVersion } from "../../package.json";

async function getAppVersionGithub() {
const githubJson = await fetch('https://api.github.com/repos/aymene69/stremio-jackett/releases/latest');
const githubJsonContent = await githubJson.json();
// @ts-ignore
const appVersion = githubJsonContent.tag_name;
return appVersion.replace('v', '');
/** @type {GitHub.Release} */
// @ts-ignore
const latestRelease = await (
await fetch("https://api.github.com/repos/aymene69/stremio-jackett/releases/latest")
).json();

const appVersion = latestRelease.tag_name;

return appVersion.replace("v", "");
}

export async function updateApp() {
const appVersionLocal = localVersion
const appVersionGithub = await getAppVersionGithub();
if (appVersionLocal !== appVersionGithub) {
console.log('A new update is available!');
console.log('Local version:', appVersionLocal, 'Github version:', appVersionGithub);
console.log('Updating app...');
if (os.platform() === 'win32') {
const updateCmd = "git clone https://github.com/aymene69/stremio-jackett temp & xcopy temp\\* .\\ /E /I /Q & rmdir /S /Q temp & npm install";
await exec(updateCmd);
}
else {
const updateCmd = "git clone https://github.com/aymene69/stremio-jackett temp && sudo rsync -a temp/ ./ && sudo rm -r temp && npm install";
await exec(updateCmd);
}
console.log('App updated.');
}
else {
console.log('App is up to date.');
console.log('Local version:', appVersionLocal, 'Github version:', appVersionGithub)
}
}
const latestVersion = await getAppVersionGithub();

if (localVersion === latestVersion) {
return;
}

console.log("A new update is available!");
console.log("Local version:", localVersion, "GitHub version:", latestVersion);
console.log("Updating app...");

let updateCmd = "git clone https://github.com/aymene69/stremio-jackett temp";
if (os.platform() === "win32") {
updateCmd += " & xcopy temp\\* .\\ /E /I /Q & rmdir /S /Q temp & ";
} else {
updateCmd += " && sudo rsync -a temp/ ./ && sudo rm -r temp && ";
}
updateCmd += "npm install";

exec(updateCmd);

console.log("App updated.");
}

0 comments on commit 00f8dea

Please sign in to comment.