Skip to content

Commit

Permalink
feat: check stable only
Browse files Browse the repository at this point in the history
  • Loading branch information
CKylinMC committed Jul 17, 2023
1 parent d809eab commit 9c58dd2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
22 changes: 15 additions & 7 deletions src/actions/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ export async function update(download = false) {
return;
}
console.log(`Current version: v${Info.version}`);
let updateUrl = await Settings.get('update_url');
if (updateUrl != CONSTS.UPDATE_URL) {
console.log(chalk.yellow(`Using custom update url: ${updateUrl}`));
const stable_only = await Settings.get('stable_only', false);
let targetUrl;
if (stable_only) {
targetUrl = await Settings.get('release_url', CONSTS.RELEASE_URL);
} else {
targetUrl = await Settings.get('update_url', CONSTS.UPDATE_URL);
}
let cfproxy = await Settings.get('cfproxy', '');
updateUrl = proxyedUrl(cfproxy, updateUrl);
targetUrl = proxyedUrl(cfproxy, targetUrl);
let spinner1 = new Spinner("Checking for update...").start();
got(updateUrl).json().then(
async (releases: any[]):Promise<any> => {
const latest = releases[0];
got(targetUrl).json().then(
async (releases: any[]): Promise<any> => {
let latest;
if (stable_only) {
latest = releases;
} else {
latest = releases[0];
}
const latestVersion = latest.tag_name;
const isBeta = latest.prerelease;
const url = latest.html_url;
Expand Down
4 changes: 2 additions & 2 deletions src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ export default async function App() {
.action((path, options) => importPackage(path, options.yes));

p.command('update')
.aliases(['upgrade'])
.option('-y, --yes', 'download update and install')
.aliases(['upgrade','up'])
.option('-y, --yes', 'download update and install without confirmation')
.description('check for cmand updates')
.action((options) => update(options.yes));

Expand Down
4 changes: 3 additions & 1 deletion src/lib/Db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Db{

export const CONSTS = {
UPDATE_URL: 'https://api.github.com/repos/CKylinMC/cmand/releases',
RELEASE_URL: 'https://api.github.com/repos/CKylinMC/cmand/releases',
REPO_LIST: [
{
tag: 'cmdpkg',
Expand Down Expand Up @@ -118,12 +119,13 @@ export class Settings{
await Settings.set('ver', 3);
await Settings.set('repos', CONSTS.REPO_LIST, true);
await Settings.set('update_url', CONSTS.UPDATE_URL, true);
await Settings.set('release_url', CONSTS.RELEASE_URL, true);
await Settings.set('cfproxy', '', true);
await Settings.set('proxy', '', true);
await Settings.set('update_url', CONSTS.UPDATE_URL, true);
await Settings.set('auto_select_source', true, true);
await Settings.set('disable_banner', false, true);
await Settings.set('allow_remote_install', true, true);
await Settings.set('stable_only', false, true);
}
}

Expand Down

0 comments on commit 9c58dd2

Please sign in to comment.