mirror of
https://github.com/logto-io/logto.git
synced 2025-02-03 21:48:55 -05:00
refactor(core): add --no-inquiry
option
This commit is contained in:
parent
19640ec849
commit
4481c2b351
4 changed files with 18 additions and 0 deletions
|
@ -4,6 +4,7 @@ import { createPool } from 'slonik';
|
|||
import { createInterceptors } from 'slonik-interceptor-preset';
|
||||
|
||||
import appendDotEnv from './append-dot-env';
|
||||
import { noInquiry } from './parameters';
|
||||
|
||||
const createPoolByEnv = async (isTest: boolean) => {
|
||||
// Database connection is disabled in unit test environment
|
||||
|
@ -19,6 +20,10 @@ const createPoolByEnv = async (isTest: boolean) => {
|
|||
|
||||
return createPool(databaseDsn, { interceptors });
|
||||
} catch (error: unknown) {
|
||||
if (noInquiry) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const answer = await inquirer.prompt({
|
||||
name: 'dsn',
|
||||
message: `No Postgres DSN (${key}) found in env variables. Please input the DSN which points to Logto database:`,
|
||||
|
|
|
@ -4,12 +4,18 @@ import { readFileSync, writeFileSync } from 'fs';
|
|||
import { getEnv } from '@silverhand/essentials';
|
||||
import inquirer from 'inquirer';
|
||||
|
||||
import { noInquiry } from './parameters';
|
||||
|
||||
const readPrivateKey = async (path: string): Promise<string> => {
|
||||
const privateKeyPath = getEnv('OIDC_PRIVATE_KEY_PATH', 'oidc-private-key.pem');
|
||||
|
||||
try {
|
||||
return readFileSync(path, 'utf-8');
|
||||
} catch (error: unknown) {
|
||||
if (noInquiry) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const answer = await inquirer.prompt({
|
||||
type: 'confirm',
|
||||
name: 'confirm',
|
||||
|
|
2
packages/core/src/env-set/parameters.ts
Normal file
2
packages/core/src/env-set/parameters.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
const parameters = process.argv.slice(2);
|
||||
export const noInquiry = parameters.includes('--no-inquiry');
|
|
@ -4,6 +4,7 @@ import { nanoid } from 'nanoid';
|
|||
import { number, string } from 'zod';
|
||||
|
||||
import appendDotEnv from './append-dot-env';
|
||||
import { noInquiry } from './parameters';
|
||||
|
||||
const loadPeppers = async (isTest: boolean): Promise<string[]> => {
|
||||
if (isTest) {
|
||||
|
@ -17,6 +18,10 @@ const loadPeppers = async (isTest: boolean): Promise<string[]> => {
|
|||
.array()
|
||||
.parse(JSON.parse(assertEnv(key)));
|
||||
} catch (error: unknown) {
|
||||
if (noInquiry) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (!(error instanceof Error && error.message === `env variable ${key} not found`)) {
|
||||
throw error;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue