11import { Command } from '@/application/cli/command/command' ;
22import { Output } from '@/application/cli/io/output' ;
33import { Input } from '@/application/cli/io/input' ;
4- import { ConfigurationManager } from '@/application/project/configuration/manager/configurationManager' ;
4+ import {
5+ ConfigurationManager ,
6+ InitializationState ,
7+ } from '@/application/project/configuration/manager/configurationManager' ;
58import { Installation , Sdk } from '@/application/project/sdk/sdk' ;
9+ import {
10+ ProjectConfiguration ,
11+ ProjectConfigurationError ,
12+ } from '@/application/project/configuration/projectConfiguration' ;
13+ import { ErrorReason } from '@/application/error' ;
614
715export type InstallInput = {
816 clean ?: boolean ,
17+ partialConfiguration ?: boolean ,
918} ;
1019
1120export type InstallConfig = {
@@ -25,14 +34,67 @@ export class InstallCommand implements Command<InstallInput> {
2534 }
2635
2736 public async execute ( input : InstallInput ) : Promise < void > {
28- const { sdk, configurationManager , io} = this . configuration ;
37+ const { sdk, io} = this . configuration ;
2938
3039 const installation : Installation = {
3140 input : io . input ,
3241 output : io . output ,
33- configuration : await configurationManager . load ( ) ,
42+ configuration : await this . getConfiguration ( input . partialConfiguration ?? false ) ,
3443 } ;
3544
3645 await sdk . update ( installation , { clean : input . clean } ) ;
3746 }
47+
48+ private async getConfiguration ( partial : boolean ) : Promise < ProjectConfiguration > {
49+ const { configurationManager} = this . configuration ;
50+
51+ if ( ! partial || await configurationManager . isInitialized ( InitializationState . FULL ) ) {
52+ return configurationManager . load ( ) ;
53+ }
54+
55+ // Partial configuration allows the install command to run when the project is only
56+ // partially initialized.
57+ // This is useful for template projects that have some slots or parts configured,
58+ // but where values like organization, workspace, and applications must be defined when
59+ // connecting to the actual workspace.
60+ const { applications, ...partialConfiguration } = await configurationManager . loadPartial ( ) ;
61+
62+ return {
63+ paths : { } ,
64+ slots : { } ,
65+ components : { } ,
66+ get organization ( ) : string {
67+ return InstallCommand . reportConfigurationError ( 'organization' ) ;
68+ } ,
69+ get workspace ( ) : string {
70+ return InstallCommand . reportConfigurationError ( 'workspace' ) ;
71+ } ,
72+ applications : {
73+ get development ( ) : string {
74+ return InstallCommand . reportConfigurationError ( 'applications.development' ) ;
75+ } ,
76+ get production ( ) : string {
77+ return InstallCommand . reportConfigurationError ( 'applications.production' ) ;
78+ } ,
79+ ...applications ,
80+ } ,
81+ get defaultLocale ( ) : string {
82+ return InstallCommand . reportConfigurationError ( 'defaultLocale' ) ;
83+ } ,
84+ get locales ( ) : string [ ] {
85+ return InstallCommand . reportConfigurationError ( 'locales' ) ;
86+ } ,
87+ ...partialConfiguration ,
88+ } ;
89+ }
90+
91+ private static reportConfigurationError ( property : string ) : never {
92+ throw new ProjectConfigurationError (
93+ `The \`${ property } \` property is not defined in the project configuration.` ,
94+ {
95+ reason : ErrorReason . INVALID_CONFIGURATION ,
96+ suggestions : [ 'Run `init` command to initialize the project configuration.' ] ,
97+ } ,
98+ ) ;
99+ }
38100}
0 commit comments