mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
refactor(cli): fallback to latest when current version is unavailable (#3779)
refactor(cli): fallback to latest when current version number is unavailable
This commit is contained in:
parent
4bba658d7b
commit
11db88a77a
1 changed files with 24 additions and 3 deletions
|
@ -6,6 +6,7 @@ import path from 'node:path';
|
||||||
|
|
||||||
import { assert } from '@silverhand/essentials';
|
import { assert } from '@silverhand/essentials';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
|
import { got, RequestError } from 'got';
|
||||||
import inquirer from 'inquirer';
|
import inquirer from 'inquirer';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import tar from 'tar';
|
import tar from 'tar';
|
||||||
|
@ -102,11 +103,31 @@ export const validateDatabase = async () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchDownloadUrl = async (url?: string) => {
|
||||||
|
if (url) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultUrl = `https://github.com/logto-io/logto/releases/download/v${packageJson.version}/logto.tar.gz`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await got.head(defaultUrl);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof RequestError && error.response?.statusCode === 404) {
|
||||||
|
consoleLog.warn(
|
||||||
|
`Current version "v${packageJson.version}" not found in GitHub Releases, fallback to "latest".\n` +
|
||||||
|
'If you want to download the latest version, please wait a few moments and try again.'
|
||||||
|
);
|
||||||
|
return 'https://github.com/logto-io/logto/releases/latest/download/logto.tar.gz';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultUrl;
|
||||||
|
};
|
||||||
|
|
||||||
export const downloadRelease = async (url?: string) => {
|
export const downloadRelease = async (url?: string) => {
|
||||||
const tarFilePath = path.resolve(os.tmpdir(), './logto.tar.gz');
|
const tarFilePath = path.resolve(os.tmpdir(), './logto.tar.gz');
|
||||||
const from =
|
const from = await fetchDownloadUrl(url);
|
||||||
url ??
|
|
||||||
`https://github.com/logto-io/logto/releases/download/v${packageJson.version}/logto.tar.gz`;
|
|
||||||
|
|
||||||
consoleLog.info(`Download Logto from ${from}`);
|
consoleLog.info(`Download Logto from ${from}`);
|
||||||
consoleLog.info(`Target ${tarFilePath}`);
|
consoleLog.info(`Target ${tarFilePath}`);
|
||||||
|
|
Loading…
Reference in a new issue