Skip to content

Commit e4bf7da

Browse files
committed
refactor(commands): migrate every command to defineCommand
Platform validation, dynamic delegation, native-add and widget, test, create/install/post-install-cli/help, enforced-parameter, device, self-contained, platform, plugin and hooks, open|*, and the rest. Class-based surfaces the migration left without callers are deprecated rather than removed, since extensions may import them.
1 parent ae2f54e commit e4bf7da

86 files changed

Lines changed: 7199 additions & 5825 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/bootstrap.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ injector.require(
207207
"vitestExecutionService",
208208
"./services/vitest-execution-service",
209209
);
210-
injector.requireCommand("dev-test|android", "./commands/test");
211-
injector.requireCommand("dev-test|ios", "./commands/test");
212210
injector.requireCommand("test|android", "./commands/test");
213211
injector.requireCommand("test|ios", "./commands/test");
214212
injector.requireCommand("test|vision", "./commands/test");

lib/commands/add-platform.ts

Lines changed: 86 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,102 @@
1-
import { ValidatePlatformCommandBase } from "./command-base";
2-
import { IProjectData } from "../definitions/project";
31
import {
4-
IOptions,
5-
IPlatformCommandHelper,
6-
IPlatformValidationService,
7-
} from "../declarations";
8-
import { IPlatformsDataService } from "../definitions/platform";
9-
import { ICommandParameter, ICommand } from "../common/definitions/commands";
2+
canExecuteCommandBase,
3+
injectPlatformCommandServices,
4+
IPlatformCommandServices,
5+
} from "./command-base";
6+
import { IPlatformCommandHelper } from "../declarations";
107
import { IErrors } from "../common/declarations";
11-
import { injector } from "../common/yok";
8+
import {
9+
CommandContext,
10+
CommandOptionsSchema,
11+
defineCommand,
12+
stringOption,
13+
} from "../common/define-command";
14+
import { inject } from "../common/di";
15+
import { registerCommand } from "../common/services/command-definition-adapter";
16+
17+
const addPlatformCommandOptions = {
18+
frameworkPath: stringOption(),
19+
} satisfies CommandOptionsSchema;
1220

13-
export class AddPlatformCommand
14-
extends ValidatePlatformCommandBase
15-
implements ICommand
16-
{
17-
public allowedParameters: ICommandParameter[] = [];
21+
export type AddPlatformCommandContext = CommandContext<
22+
typeof addPlatformCommandOptions
23+
>;
24+
25+
export interface IAddPlatformCommandServices extends IPlatformCommandServices {
26+
$errors: IErrors;
27+
$platformCommandHelper: IPlatformCommandHelper;
28+
}
29+
30+
export function setupAddPlatformCommand(): IAddPlatformCommandServices {
31+
const services = {
32+
...injectPlatformCommandServices(),
33+
$errors: inject<IErrors>("errors"),
34+
$platformCommandHelper: inject<IPlatformCommandHelper>(
35+
"platformCommandHelper",
36+
),
37+
};
38+
services.$projectData.initializeProjectData();
39+
40+
return services;
41+
}
1842

19-
constructor(
20-
$options: IOptions,
21-
private $platformCommandHelper: IPlatformCommandHelper,
22-
$platformValidationService: IPlatformValidationService,
23-
$projectData: IProjectData,
24-
$platformsDataService: IPlatformsDataService,
25-
private $errors: IErrors
26-
) {
27-
super(
28-
$options,
29-
$platformsDataService,
30-
$platformValidationService,
31-
$projectData
43+
export async function canExecuteAddPlatformCommand(
44+
context: AddPlatformCommandContext,
45+
services: IAddPlatformCommandServices,
46+
): Promise<boolean> {
47+
const args = context.args;
48+
if (!args || args.length === 0) {
49+
services.$errors.failWithHelp(
50+
"No platform specified. Please specify a platform to add.",
3251
);
33-
this.$projectData.initializeProjectData();
3452
}
3553

36-
public async execute(args: string[]): Promise<void> {
37-
await this.$platformCommandHelper.addPlatforms(
38-
args,
39-
this.$projectData,
40-
this.$options.frameworkPath
54+
let canExecute = true;
55+
for (const arg of args) {
56+
services.$platformValidationService.validatePlatform(
57+
arg,
58+
services.$projectData,
4159
);
42-
}
4360

44-
public async canExecute(args: string[]): Promise<boolean> {
45-
if (!args || args.length === 0) {
46-
this.$errors.failWithHelp(
47-
"No platform specified. Please specify a platform to add."
61+
if (
62+
!services.$platformValidationService.isPlatformSupportedForOS(
63+
arg,
64+
services.$projectData,
65+
)
66+
) {
67+
services.$errors.fail(
68+
`Applications for platform ${arg} cannot be built on this OS`,
4869
);
4970
}
5071

51-
let canExecute = true;
52-
for (const arg of args) {
53-
this.$platformValidationService.validatePlatform(arg, this.$projectData);
54-
55-
if (
56-
!this.$platformValidationService.isPlatformSupportedForOS(
57-
arg,
58-
this.$projectData
59-
)
60-
) {
61-
this.$errors.fail(
62-
`Applications for platform ${arg} cannot be built on this OS`
63-
);
64-
}
72+
// The assignment overwrites the previous platform's verdict, so only the
73+
// last one decides. Kept as it was.
74+
canExecute = await canExecuteCommandBase(services, arg);
75+
}
6576

66-
canExecute = await super.canExecuteCommandBase(arg);
67-
}
77+
return canExecute;
78+
}
6879

69-
return canExecute;
70-
}
80+
export async function runAddPlatformCommand(
81+
context: AddPlatformCommandContext,
82+
services: IAddPlatformCommandServices,
83+
): Promise<void> {
84+
await services.$platformCommandHelper.addPlatforms(
85+
context.args,
86+
services.$projectData,
87+
context.options.frameworkPath,
88+
);
7189
}
7290

73-
injector.registerCommand("platform|add", AddPlatformCommand);
91+
export const addPlatformCommandDefinition = defineCommand({
92+
name: "platform|add",
93+
description:
94+
"Configures the current project to target the selected platform.",
95+
options: addPlatformCommandOptions,
96+
arguments: "any",
97+
setup: setupAddPlatformCommand,
98+
canExecute: canExecuteAddPlatformCommand,
99+
run: runAddPlatformCommand,
100+
});
101+
102+
registerCommand(addPlatformCommandDefinition);

lib/commands/apple-login.ts

Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,65 @@
1-
import { StringCommandParameter } from "../common/command-params";
2-
import { ICommand, ICommandParameter } from "../common/definitions/commands";
31
import { IErrors } from "../common/declarations";
4-
import { IInjector } from "../common/definitions/yok";
5-
import { injector } from "../common/yok";
2+
import { CommandContext, defineCommand } from "../common/define-command";
3+
import { inject } from "../common/di";
4+
import { registerCommand } from "../common/services/command-definition-adapter";
65
import { IApplePortalSessionService } from "../services/apple-portal/definitions";
76

8-
export class AppleLogin implements ICommand {
9-
public allowedParameters: ICommandParameter[] = [
10-
new StringCommandParameter(this.$injector),
11-
new StringCommandParameter(this.$injector),
12-
];
13-
14-
constructor(
15-
private $applePortalSessionService: IApplePortalSessionService,
16-
private $errors: IErrors,
17-
private $injector: IInjector,
18-
private $logger: ILogger,
19-
private $prompter: IPrompter
20-
) {}
21-
22-
public async execute(args: string[]): Promise<void> {
23-
let username = args[0];
24-
if (!username) {
25-
username = await this.$prompter.getString("Apple ID", {
26-
allowEmpty: false,
27-
});
28-
}
29-
30-
let password = args[1];
31-
if (!password) {
32-
password = await this.$prompter.getPassword("Apple ID password");
33-
}
34-
35-
const user = await this.$applePortalSessionService.createUserSession({
36-
username,
37-
password,
7+
export type AppleLoginCommandContext = CommandContext;
8+
9+
export interface IAppleLoginCommandServices {
10+
$applePortalSessionService: IApplePortalSessionService;
11+
$errors: IErrors;
12+
$logger: ILogger;
13+
$prompter: IPrompter;
14+
}
15+
16+
export function setupAppleLoginCommand(): IAppleLoginCommandServices {
17+
return {
18+
$applePortalSessionService: inject<IApplePortalSessionService>(
19+
"applePortalSessionService",
20+
),
21+
$errors: inject<IErrors>("errors"),
22+
$logger: inject<ILogger>("logger"),
23+
$prompter: inject<IPrompter>("prompter"),
24+
};
25+
}
26+
27+
export async function runAppleLoginCommand(
28+
context: AppleLoginCommandContext,
29+
services: IAppleLoginCommandServices,
30+
): Promise<void> {
31+
let username = context.args[0];
32+
if (!username) {
33+
username = await services.$prompter.getString("Apple ID", {
34+
allowEmpty: false,
3835
});
39-
if (!user.areCredentialsValid) {
40-
this.$errors.fail(
41-
`Invalid username and password combination. Used '${username}' as the username.`
42-
);
43-
}
44-
45-
const output = Buffer.from(user.userSessionCookie).toString("base64");
46-
this.$logger.info(output);
4736
}
37+
38+
let password = context.args[1];
39+
if (!password) {
40+
password = await services.$prompter.getPassword("Apple ID password");
41+
}
42+
43+
const user = await services.$applePortalSessionService.createUserSession({
44+
username,
45+
password,
46+
});
47+
if (!user.areCredentialsValid) {
48+
services.$errors.fail(
49+
`Invalid username and password combination. Used '${username}' as the username.`,
50+
);
51+
}
52+
53+
const output = Buffer.from(user.userSessionCookie).toString("base64");
54+
services.$logger.info(output);
4855
}
49-
injector.registerCommand("apple-login", AppleLogin);
56+
57+
export const appleLoginCommandDefinition = defineCommand({
58+
name: "apple-login",
59+
description: "Logs in to an Apple account and prints the session cookie.",
60+
arguments: [{ name: "appleId" }, { name: "password" }],
61+
setup: setupAppleLoginCommand,
62+
run: runAppleLoginCommand,
63+
});
64+
65+
registerCommand(appleLoginCommandDefinition);

0 commit comments

Comments
 (0)