@@ -2,15 +2,16 @@ import {
22 ANDROID_RELEASE_BUILD_ERROR_MESSAGE ,
33 AndroidAppBundleMessages ,
44} from "../constants" ;
5- import {
6- canExecuteCommandBase ,
7- injectPlatformCommandServices ,
8- validatePlatformOptions ,
9- } from "./command-base" ;
5+ import { canExecuteCommandBase , validatePlatformOptions } from "./command-base" ;
106import { hasValidAndroidSigning } from "../common/helpers" ;
11- import { IAndroidBundleValidatorHelper } from "../declarations" ;
7+ import {
8+ IAndroidBundleValidatorHelper ,
9+ IOptions ,
10+ IPlatformValidationService ,
11+ } from "../declarations" ;
1212import { IBuildController , IBuildDataService } from "../definitions/build" ;
1313import { IMigrateController } from "../definitions/migrate" ;
14+ import { IProjectData } from "../definitions/project" ;
1415import { IErrors } from "../common/declarations" ;
1516import {
1617 booleanOption ,
@@ -48,87 +49,82 @@ const defineBuildCommand = <const TName extends CommandName>(
4849 description : "Builds the project for the selected target platform." ,
4950 options : buildCommandOptions ,
5051 arguments : "none" ,
51- setup ( ) {
52- const devicePlatformsConstants = inject < Mobile . IDevicePlatformsConstants > (
53- "devicePlatformsConstants" ,
52+ async canExecute ( context ) : Promise < boolean > {
53+ const $devicePlatformsConstants =
54+ inject < Mobile . IDevicePlatformsConstants > ( "devicePlatformsConstants" ) ;
55+ const $errors = inject < IErrors > ( "errors" ) ;
56+ const $migrateController =
57+ inject < IMigrateController > ( "migrateController" ) ;
58+ const $platformValidationService = inject < IPlatformValidationService > (
59+ "platformValidationService" ,
5460 ) ;
55- const platform = devicePlatformsConstants [ buildPlatform ] ;
56- const isAndroid = devicePlatformsConstants . isAndroid ( platform ) ;
57- const services = {
58- ...injectPlatformCommandServices ( ) ,
59- platform,
60- isAndroid,
61- $errors : inject < IErrors > ( "errors" ) ,
62- $logger : inject < ILogger > ( "logger" ) ,
63- $buildController : inject < IBuildController > ( "buildController" ) ,
64- $buildDataService : inject < IBuildDataService > ( "buildDataService" ) ,
65- $migrateController : inject < IMigrateController > ( "migrateController" ) ,
66- // Only the android build checks the runtime version.
67- $androidBundleValidatorHelper : isAndroid
68- ? inject < IAndroidBundleValidatorHelper > (
69- "androidBundleValidatorHelper" ,
70- )
71- : null ,
72- } ;
73- services . $projectData . initializeProjectData ( ) ;
74-
75- return services ;
76- } ,
77- async canExecute ( context , services ) : Promise < boolean > {
78- const { platform } = services ;
61+ const $projectData = inject < IProjectData > ( "projectData" ) ;
62+ const platform = $devicePlatformsConstants [ buildPlatform ] ;
63+ const isAndroid = $devicePlatformsConstants . isAndroid ( platform ) ;
64+ // Only the android build checks the runtime version.
65+ const $androidBundleValidatorHelper = isAndroid
66+ ? inject < IAndroidBundleValidatorHelper > ( "androidBundleValidatorHelper" )
67+ : null ;
68+ $projectData . initializeProjectData ( ) ;
7969
8070 if ( ! context . options . force ) {
81- await services . $migrateController . validate ( {
82- projectDir : services . $projectData . projectDir ,
71+ await $migrateController . validate ( {
72+ projectDir : $projectData . projectDir ,
8373 platforms : [ platform ] ,
8474 } ) ;
8575 }
8676
87- if ( services . isAndroid ) {
88- services . $androidBundleValidatorHelper . validateRuntimeVersion (
89- services . $projectData ,
90- ) ;
77+ if ( isAndroid ) {
78+ $androidBundleValidatorHelper . validateRuntimeVersion ( $projectData ) ;
9179 } else if (
92- ! services . $platformValidationService . isPlatformSupportedForOS (
80+ ! $platformValidationService . isPlatformSupportedForOS (
9381 platform ,
94- services . $projectData ,
82+ $projectData ,
9583 )
9684 ) {
97- services . $errors . fail (
85+ $errors . fail (
9886 `Applications for platform ${ platform } can not be built on this OS` ,
9987 ) ;
10088 }
10189
102- if ( ! ( await canExecuteCommandBase ( services , platform ) ) ) {
90+ if ( ! ( await canExecuteCommandBase ( context , platform ) ) ) {
10391 return false ;
10492 }
10593
10694 if (
107- services . isAndroid &&
95+ isAndroid &&
10896 context . options . release &&
10997 ! hasValidAndroidSigning ( context . options )
11098 ) {
111- services . $errors . failWithHelp ( ANDROID_RELEASE_BUILD_ERROR_MESSAGE ) ;
99+ $errors . failWithHelp ( ANDROID_RELEASE_BUILD_ERROR_MESSAGE ) ;
112100 }
113101
114- return validatePlatformOptions ( services , platform ) ;
102+ return validatePlatformOptions ( context , platform ) ;
115103 } ,
116- async run ( context , services ) : Promise < string > {
117- const buildData = services . $buildDataService . getBuildData (
118- services . $projectData . projectDir ,
119- services . platform . toLowerCase ( ) ,
120- services . $options ,
104+ async run ( context ) : Promise < string > {
105+ const $buildController = inject < IBuildController > ( "buildController" ) ;
106+ const $buildDataService = inject < IBuildDataService > ( "buildDataService" ) ;
107+ const $devicePlatformsConstants =
108+ inject < Mobile . IDevicePlatformsConstants > ( "devicePlatformsConstants" ) ;
109+ const $logger = inject < ILogger > ( "logger" ) ;
110+ const $options = inject < IOptions > ( "options" ) ;
111+ const $projectData = inject < IProjectData > ( "projectData" ) ;
112+ const platform = $devicePlatformsConstants [ buildPlatform ] ;
113+ const isAndroid = $devicePlatformsConstants . isAndroid ( platform ) ;
114+ $projectData . initializeProjectData ( ) ;
115+
116+ const buildData = $buildDataService . getBuildData (
117+ $projectData . projectDir ,
118+ platform . toLowerCase ( ) ,
119+ $options ,
121120 ) ;
122- const outputPath =
123- await services . $buildController . prepareAndBuild ( buildData ) ;
121+ const outputPath = await $buildController . prepareAndBuild ( buildData ) ;
124122
125- if ( services . isAndroid && context . options . aab ) {
126- services . $logger . info (
127- AndroidAppBundleMessages . ANDROID_APP_BUNDLE_DOCS_MESSAGE ,
128- ) ;
123+ if ( isAndroid && context . options . aab ) {
124+ $logger . info ( AndroidAppBundleMessages . ANDROID_APP_BUNDLE_DOCS_MESSAGE ) ;
129125
130126 if ( context . options . release ) {
131- services . $logger . info (
127+ $logger . info (
132128 AndroidAppBundleMessages . ANDROID_APP_BUNDLE_PUBLISH_DOCS_MESSAGE ,
133129 ) ;
134130 }
0 commit comments