0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

feat(cli): add download-url option for install

This commit is contained in:
Gao Sun 2022-10-14 17:37:53 +08:00
parent 7d257c45bf
commit 5dda0a6dd0
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
3 changed files with 29 additions and 7 deletions

View file

@ -6,7 +6,7 @@ import list from './list';
import remove from './remove';
const connector: CommandModule = {
command: ['connector', 'c'],
command: ['connector', 'c', 'connectors'],
describe: 'Command for Logto connectors',
builder: (yargs) =>
yargs

View file

@ -14,15 +14,17 @@ import {
logFinale,
decompress,
inquireOfficialConnectors,
isUrl,
} from './utils';
export type InstallArgs = {
path?: string;
skipSeed: boolean;
officialConnectors?: boolean;
downloadUrl?: string;
};
const installLogto = async ({ path, skipSeed, officialConnectors }: InstallArgs) => {
const installLogto = async ({ path, skipSeed, officialConnectors, downloadUrl }: InstallArgs) => {
validateNodeVersion();
// Get instance path
@ -32,7 +34,8 @@ const installLogto = async ({ path, skipSeed, officialConnectors }: InstallArgs)
await validateDatabase();
// Download and decompress
const tarPath = await downloadRelease();
const tarPath =
!downloadUrl || isUrl(downloadUrl) ? await downloadRelease(downloadUrl) : downloadUrl;
await decompress(instancePath, tarPath);
// Seed database
@ -69,6 +72,7 @@ const install: CommandModule<
p?: string;
ss: boolean;
oc?: boolean;
du?: string;
}
> = {
command: ['init', 'i', 'install'],
@ -91,9 +95,15 @@ const install: CommandModule<
describe: 'Add official connectors after downloading Logto',
type: 'boolean',
},
du: {
alias: 'download-url',
describe: 'URL for downloading Logto, can be a local path to tar',
type: 'string',
hidden: true,
},
}),
handler: async ({ p, ss, oc }) => {
await installLogto({ path: p, skipSeed: ss, officialConnectors: oc });
handler: async ({ p, ss, oc, du }) => {
await installLogto({ path: p, skipSeed: ss, officialConnectors: oc, downloadUrl: du });
},
};

View file

@ -84,12 +84,12 @@ export const validateDatabase = async () => {
}
};
export const downloadRelease = async () => {
export const downloadRelease = async (url?: string) => {
const tarFilePath = path.resolve(os.tmpdir(), './logto.tar.gz');
log.info(`Download Logto to ${tarFilePath}`);
await downloadFile(
'https://github.com/logto-io/logto/releases/latest/download/logto.tar.gz',
url ?? 'https://github.com/logto-io/logto/releases/latest/download/logto.tar.gz',
tarFilePath
);
@ -166,3 +166,15 @@ export const inquireOfficialConnectors = async (initialAnswer?: boolean) => {
return value;
};
export const isUrl = (string: string) => {
try {
// On purpose to test
// eslint-disable-next-line no-new
new URL(string);
return true;
} catch {
return false;
}
};