88import { IPlatformEnvironmentRequirements } from "../definitions/platform" ;
99import { IErrors } from "../common/declarations" ;
1010import {
11- CommandContext ,
11+ Command ,
1212 CommandOptionsSchema ,
13- defineCommand ,
1413 stringOption ,
1514} from "../common/define-command" ;
1615import { inject } from "../common/di" ;
@@ -19,93 +18,71 @@ const platformCleanCommandOptions = {
1918 frameworkPath : stringOption ( ) ,
2019} satisfies CommandOptionsSchema ;
2120
22- export type PlatformCleanCommandContext = CommandContext <
23- typeof platformCleanCommandOptions
24- > ;
25-
26- export function setupPlatformCleanCommand ( ) {
27- const services = {
28- $errors : inject < IErrors > ( "errors" ) ,
29- $options : inject < IOptions > ( "options" ) ,
30- $platformCommandHelper : inject < IPlatformCommandHelper > (
31- "platformCommandHelper" ,
32- ) ,
33- $platformValidationService : inject < IPlatformValidationService > (
34- "platformValidationService" ,
35- ) ,
36- $platformEnvironmentRequirements : inject < IPlatformEnvironmentRequirements > (
37- "platformEnvironmentRequirements" ,
38- ) ,
39- $projectData : inject < IProjectData > ( "projectData" ) ,
40- } ;
41- services . $projectData . initializeProjectData ( ) ;
42-
43- return services ;
44- }
45-
46- export type IPlatformCleanCommandServices = ReturnType <
47- typeof setupPlatformCleanCommand
48- > ;
21+ export class PlatformCleanCommand extends Command ( {
22+ name : "platform|clean" ,
23+ description : "Removes and adds again the selected platform." ,
24+ options : platformCleanCommandOptions ,
25+ arguments : "any" ,
26+ } ) {
27+ private $errors = inject < IErrors > ( "errors" ) ;
28+ private $options = inject < IOptions > ( "options" ) ;
29+ private $platformCommandHelper = inject < IPlatformCommandHelper > (
30+ "platformCommandHelper" ,
31+ ) ;
32+ private $platformValidationService = inject < IPlatformValidationService > (
33+ "platformValidationService" ,
34+ ) ;
35+ private $platformEnvironmentRequirements =
36+ inject < IPlatformEnvironmentRequirements > ( "platformEnvironmentRequirements" ) ;
37+ private $projectData = inject < IProjectData > ( "projectData" ) ;
4938
50- export async function canExecutePlatformCleanCommand (
51- context : PlatformCleanCommandContext ,
52- services : IPlatformCleanCommandServices ,
53- ) : Promise < boolean > {
54- const args = context . args ;
55- if ( ! args || args . length === 0 ) {
56- services . $errors . failWithHelp (
57- "No platform specified. Please specify a platform to clean." ,
58- ) ;
39+ constructor ( ) {
40+ super ( ) ;
41+ this . $projectData . initializeProjectData ( ) ;
5942 }
6043
61- _ . each ( args , ( platform ) => {
62- services . $platformValidationService . validatePlatform (
63- platform ,
64- services . $projectData ,
65- ) ;
66- } ) ;
44+ public async canExecute ( ) : Promise < boolean > {
45+ const args = this . args ;
46+ if ( ! args || args . length === 0 ) {
47+ this . $errors . failWithHelp (
48+ "No platform specified. Please specify a platform to clean." ,
49+ ) ;
50+ }
6751
68- for ( const platform of args ) {
69- services . $platformValidationService . validatePlatformInstalled (
70- platform ,
71- services . $projectData ,
72- ) ;
52+ _ . each ( args , ( platform ) => {
53+ this . $platformValidationService . validatePlatform (
54+ platform ,
55+ this . $projectData ,
56+ ) ;
57+ } ) ;
7358
74- const currentRuntimeVersion =
75- services . $platformCommandHelper . getCurrentPlatformVersion (
59+ for ( const platform of args ) {
60+ this . $platformValidationService . validatePlatformInstalled (
7661 platform ,
77- services . $projectData ,
62+ this . $projectData ,
7863 ) ;
79- await services . $platformEnvironmentRequirements . checkEnvironmentRequirements (
80- {
64+
65+ const currentRuntimeVersion =
66+ this . $platformCommandHelper . getCurrentPlatformVersion (
67+ platform ,
68+ this . $projectData ,
69+ ) ;
70+ await this . $platformEnvironmentRequirements . checkEnvironmentRequirements ( {
8171 platform,
82- projectDir : services . $projectData . projectDir ,
72+ projectDir : this . $projectData . projectDir ,
8373 runtimeVersion : currentRuntimeVersion ,
84- options : services . $options ,
85- } ,
86- ) ;
87- }
74+ options : this . $options ,
75+ } ) ;
76+ }
8877
89- return true ;
90- }
78+ return true ;
79+ }
9180
92- export async function runPlatformCleanCommand (
93- context : PlatformCleanCommandContext ,
94- services : IPlatformCleanCommandServices ,
95- ) : Promise < void > {
96- await services . $platformCommandHelper . cleanPlatforms (
97- context . args ,
98- services . $projectData ,
99- context . options . frameworkPath ,
100- ) ;
81+ public async run ( ) : Promise < void > {
82+ await this . $platformCommandHelper . cleanPlatforms (
83+ this . args ,
84+ this . $projectData ,
85+ this . options . frameworkPath ,
86+ ) ;
87+ }
10188}
102-
103- export const platformCleanCommandDefinition = defineCommand ( {
104- name : "platform|clean" ,
105- description : "Removes and adds again the selected platform." ,
106- options : platformCleanCommandOptions ,
107- arguments : "any" ,
108- setup : setupPlatformCleanCommand ,
109- canExecute : canExecutePlatformCleanCommand ,
110- run : runPlatformCleanCommand ,
111- } ) ;
0 commit comments