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'; import remove from './remove';
const connector: CommandModule = { const connector: CommandModule = {
command: ['connector', 'c'], command: ['connector', 'c', 'connectors'],
describe: 'Command for Logto connectors', describe: 'Command for Logto connectors',
builder: (yargs) => builder: (yargs) =>
yargs yargs

View file

@ -14,15 +14,17 @@ import {
logFinale, logFinale,
decompress, decompress,
inquireOfficialConnectors, inquireOfficialConnectors,
isUrl,
} from './utils'; } from './utils';
export type InstallArgs = { export type InstallArgs = {
path?: string; path?: string;
skipSeed: boolean; skipSeed: boolean;
officialConnectors?: boolean; officialConnectors?: boolean;
downloadUrl?: string;
}; };
const installLogto = async ({ path, skipSeed, officialConnectors }: InstallArgs) => { const installLogto = async ({ path, skipSeed, officialConnectors, downloadUrl }: InstallArgs) => {
validateNodeVersion(); validateNodeVersion();
// Get instance path // Get instance path
@ -32,7 +34,8 @@ const installLogto = async ({ path, skipSeed, officialConnectors }: InstallArgs)
await validateDatabase(); await validateDatabase();
// Download and decompress // Download and decompress
const tarPath = await downloadRelease(); const tarPath =
!downloadUrl || isUrl(downloadUrl) ? await downloadRelease(downloadUrl) : downloadUrl;
await decompress(instancePath, tarPath); await decompress(instancePath, tarPath);
// Seed database // Seed database
@ -69,6 +72,7 @@ const install: CommandModule<
p?: string; p?: string;
ss: boolean; ss: boolean;
oc?: boolean; oc?: boolean;
du?: string;
} }
> = { > = {
command: ['init', 'i', 'install'], command: ['init', 'i', 'install'],
@ -91,9 +95,15 @@ const install: CommandModule<
describe: 'Add official connectors after downloading Logto', describe: 'Add official connectors after downloading Logto',
type: 'boolean', 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 }) => { handler: async ({ p, ss, oc, du }) => {
await installLogto({ path: p, skipSeed: ss, officialConnectors: oc }); 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'); const tarFilePath = path.resolve(os.tmpdir(), './logto.tar.gz');
log.info(`Download Logto to ${tarFilePath}`); log.info(`Download Logto to ${tarFilePath}`);
await downloadFile( 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 tarFilePath
); );
@ -166,3 +166,15 @@ export const inquireOfficialConnectors = async (initialAnswer?: boolean) => {
return value; 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;
}
};