Skip to content

Commit 4363989

Browse files
authored
non interactive runTask function (#441)
* refactor runTask * rebase main and fix runTask
1 parent 015eeb0 commit 4363989

25 files changed

Lines changed: 110 additions & 103 deletions

File tree

packages/cli/src/cli/commands/agents/pull.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { dirname, join } from "node:path";
22
import type { Command } from "commander";
33
import type { CLIContext, RunCommandResult } from "@/cli/types.js";
4-
import { Base44Command, runTask } from "@/cli/utils/index.js";
4+
import { Base44Command } from "@/cli/utils/index.js";
55
import { readProjectConfig } from "@/core/index.js";
66
import { fetchAgents, writeAgents } from "@/core/resources/agent/index.js";
77

88
async function pullAgentsAction({
99
log,
10+
runTask,
1011
}: CLIContext): Promise<RunCommandResult> {
1112
const { project } = await readProjectConfig();
1213

packages/cli/src/cli/commands/agents/push.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { Command } from "commander";
22
import type { CLIContext, RunCommandResult } from "@/cli/types.js";
3-
import { Base44Command, runTask } from "@/cli/utils/index.js";
3+
import { Base44Command } from "@/cli/utils/index.js";
44
import { readProjectConfig } from "@/core/index.js";
55
import { pushAgents } from "@/core/resources/agent/index.js";
66

77
async function pushAgentsAction({
88
log,
9+
runTask,
910
}: CLIContext): Promise<RunCommandResult> {
1011
const { agents } = await readProjectConfig();
1112

packages/cli/src/cli/commands/auth/login-flow.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Logger } from "@base44-cli/logger";
22
import pWaitFor from "p-wait-for";
33
import type { CLIContext, RunCommandResult } from "@/cli/types.js";
4-
import { runTask } from "@/cli/utils/index.js";
4+
import type { RunTaskFn } from "@/cli/utils/runTask.js";
55
import { theme } from "@/cli/utils/theme.js";
66
import type {
77
DeviceCodeResponse,
@@ -18,6 +18,7 @@ import { AuthExpiredError, InternalError } from "@/core/errors.js";
1818

1919
async function generateAndDisplayDeviceCode(
2020
log: Logger,
21+
runTask: RunTaskFn,
2122
): Promise<DeviceCodeResponse> {
2223
const deviceCodeResponse = await runTask(
2324
"Generating device code...",
@@ -42,6 +43,7 @@ async function waitForAuthentication(
4243
deviceCode: string,
4344
expiresIn: number,
4445
interval: number,
46+
runTask: RunTaskFn,
4547
): Promise<TokenResponse> {
4648
let tokenResponse: TokenResponse | undefined;
4749

@@ -102,13 +104,17 @@ async function saveAuthData(
102104
* Execute the login flow (device code authentication).
103105
* This function is separate from the command to avoid circular dependencies.
104106
*/
105-
export async function login({ log }: CLIContext): Promise<RunCommandResult> {
106-
const deviceCodeResponse = await generateAndDisplayDeviceCode(log);
107+
export async function login({
108+
log,
109+
runTask,
110+
}: CLIContext): Promise<RunCommandResult> {
111+
const deviceCodeResponse = await generateAndDisplayDeviceCode(log, runTask);
107112

108113
const token = await waitForAuthentication(
109114
deviceCodeResponse.deviceCode,
110115
deviceCodeResponse.expiresIn,
111116
deviceCodeResponse.interval,
117+
runTask,
112118
);
113119

114120
const userInfo = await getUserInfo(token.accessToken);

packages/cli/src/cli/commands/auth/password-login.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { dirname, join } from "node:path";
22
import type { Command } from "commander";
33
import type { CLIContext, RunCommandResult } from "@/cli/types.js";
4-
import { Base44Command, runTask } from "@/cli/utils/index.js";
4+
import { Base44Command } from "@/cli/utils/index.js";
55
import { InvalidInputError } from "@/core/errors.js";
66
import { readProjectConfig } from "@/core/project/index.js";
77
import {
@@ -35,7 +35,7 @@ function validateAction(
3535
}
3636

3737
async function passwordLoginAction(
38-
{ log }: CLIContext,
38+
{ log, runTask }: CLIContext,
3939
action: string,
4040
): Promise<RunCommandResult> {
4141
validateAction(action);

packages/cli/src/cli/commands/auth/pull.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { dirname, join } from "node:path";
22
import type { Command } from "commander";
33
import type { CLIContext, RunCommandResult } from "@/cli/types.js";
4-
import { Base44Command, runTask } from "@/cli/utils/index.js";
4+
import { Base44Command } from "@/cli/utils/index.js";
55
import { readProjectConfig } from "@/core/project/index.js";
66
import {
77
pullAuthConfig,
88
writeAuthConfig,
99
} from "@/core/resources/auth-config/index.js";
1010

11-
async function pullAuthAction({ log }: CLIContext): Promise<RunCommandResult> {
11+
async function pullAuthAction({
12+
log,
13+
runTask,
14+
}: CLIContext): Promise<RunCommandResult> {
1215
const { project } = await readProjectConfig();
1316

1417
const configDir = dirname(project.configPath);

packages/cli/src/cli/commands/auth/push.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { confirm, isCancel } from "@clack/prompts";
22
import type { Command } from "commander";
33
import type { CLIContext, RunCommandResult } from "@/cli/types.js";
4-
import { Base44Command, runTask } from "@/cli/utils/index.js";
4+
import { Base44Command } from "@/cli/utils/index.js";
55
import { InvalidInputError } from "@/core/errors.js";
66
import { readProjectConfig } from "@/core/project/index.js";
77
import {
@@ -14,7 +14,7 @@ interface PushAuthOptions {
1414
}
1515

1616
async function pushAuthAction(
17-
{ isNonInteractive, log }: CLIContext,
17+
{ isNonInteractive, log, runTask }: CLIContext,
1818
options: PushAuthOptions,
1919
): Promise<RunCommandResult> {
2020
const { authConfig } = await readProjectConfig();

packages/cli/src/cli/commands/connectors/list-available.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import type { Command } from "commander";
22
import type { CLIContext, RunCommandResult } from "@/cli/types.js";
3-
import {
4-
Base44Command,
5-
formatYaml,
6-
runTask,
7-
YAML_INDENT,
8-
} from "@/cli/utils/index.js";
3+
import { Base44Command, formatYaml, YAML_INDENT } from "@/cli/utils/index.js";
94
import { listAvailableIntegrations } from "@/core/resources/connector/index.js";
105

116
async function listAvailableAction({
127
log,
8+
runTask,
139
}: CLIContext): Promise<RunCommandResult> {
1410
const { integrations } = await runTask(
1511
"Fetching available integrations from Base44",

packages/cli/src/cli/commands/connectors/pull.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { dirname, join } from "node:path";
22
import type { Command } from "commander";
33
import type { CLIContext, RunCommandResult } from "@/cli/types.js";
4-
import { Base44Command, runTask } from "@/cli/utils/index.js";
4+
import { Base44Command } from "@/cli/utils/index.js";
55
import { readProjectConfig } from "@/core/index.js";
66
import {
77
pullAllConnectors,
@@ -10,6 +10,7 @@ import {
1010

1111
async function pullConnectorsAction({
1212
log,
13+
runTask,
1314
}: CLIContext): Promise<RunCommandResult> {
1415
const { project } = await readProjectConfig();
1516

packages/cli/src/cli/commands/connectors/push.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Logger } from "@base44-cli/logger";
22
import type { Command } from "commander";
33
import type { CLIContext, RunCommandResult } from "@/cli/types.js";
4-
import { Base44Command, runTask, theme } from "@/cli/utils/index.js";
4+
import { Base44Command, theme } from "@/cli/utils/index.js";
55
import { getConnectorsUrl } from "@/cli/utils/urls.js";
66
import { readProjectConfig } from "@/core/index.js";
77
import {
@@ -93,6 +93,7 @@ function printSummary(
9393
async function pushConnectorsAction({
9494
isNonInteractive,
9595
log,
96+
runTask,
9697
}: CLIContext): Promise<RunCommandResult> {
9798
const { connectors } = await readProjectConfig();
9899

packages/cli/src/cli/commands/entities/push.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Command } from "commander";
22
import type { CLIContext, RunCommandResult } from "@/cli/types.js";
3-
import { Base44Command, runTask } from "@/cli/utils/index.js";
3+
import { Base44Command } from "@/cli/utils/index.js";
44
import { readProjectConfig } from "@/core/index.js";
55
import { pushEntities } from "@/core/resources/entity/index.js";
66

77
async function pushEntitiesAction({
88
log,
9+
runTask,
910
}: CLIContext): Promise<RunCommandResult> {
1011
const { entities } = await readProjectConfig();
1112

0 commit comments

Comments
 (0)