@@ -114,6 +114,7 @@ import {
114114 commitEnterpriseFileUpload ,
115115 updateTestingDistributionReleaseNotes ,
116116 getLatestAppVersionId ,
117+ createSubOrganization
117118} from '../services' ;
118119import { commandWriter , configWriter } from './writer' ;
119120import { trustAppcircleCertificate } from '../security/trust-url-certificate' ;
@@ -261,6 +262,16 @@ const handleOrganizationCommand = async (command: ProgramCommand, params: any) =
261262 fullCommandName : command . fullCommandName ,
262263 data : userInfo . roles ,
263264 } ) ;
265+ } else if ( command . fullCommandName === `${ PROGRAM_NAME } -organization-create-sub` ) {
266+ const spinner = createOra ( 'Creating sub-organization...' ) . start ( ) ;
267+ try {
268+ const response = await createSubOrganization ( { name : params . name } ) ;
269+ const successMessage = `${ params . name } sub organization created successfully!` ;
270+ spinner . succeed ( successMessage ) ;
271+ } catch ( error : any ) {
272+ const errorMessage = error . response ?. data ?. message || error . message || 'Failed to create sub-organization' ;
273+ spinner . fail ( `Error: ${ errorMessage } ` ) ;
274+ }
264275 } else {
265276 const beutufiyCommandName = command . fullCommandName . split ( '-' ) . join ( ' ' ) ;
266277 console . error ( `"${ beutufiyCommandName } ..." command not found \nRun "${ beutufiyCommandName } --help" for more information` ) ;
@@ -477,6 +488,59 @@ const handlePublishCommand = async (command: ProgramCommand, params: any) => {
477488 spinner . fail ( 'Failed to upload environment variables' ) ;
478489 throw e ;
479490 }
491+ } else if ( command . fullCommandName === `${ PROGRAM_NAME } -publish-variable-group-download` ) {
492+ const spinner = createOra ( 'Downloading publish environment variables...' ) . start ( ) ;
493+ try {
494+ const variableGroups = await getPublishVariableGroups ( ) ;
495+ const variableGroup = variableGroups . find ( ( group : any ) => group . id === params . publishVariableGroupId ) ;
496+
497+ if ( ! variableGroup ) {
498+ spinner . fail ( `Variable group with ID ${ params . publishVariableGroupId } not found` ) ;
499+ throw new Error ( `Variable group not found` ) ;
500+ }
501+
502+ const variables = await getPublishVariableListByGroupId ( params ) ;
503+
504+ let formattedVariables = variables . variables . map ( ( variable : any ) => ( {
505+ key : variable . key ,
506+ value : variable . value ,
507+ isSecret : variable . isSecret ,
508+ isFile : variable . isFile || false ,
509+ id : variable . key
510+ } ) ) ;
511+
512+ formattedVariables . sort ( ( a : any , b : any ) => {
513+ const aKey = a . key ;
514+ const bKey = b . key ;
515+ return bKey . localeCompare ( aKey ) ;
516+ } ) ;
517+
518+ const timestamp = Date . now ( ) ;
519+ const fileName = `${ variableGroup . name } _${ timestamp } .json` ;
520+
521+ let filePath = params . path || process . cwd ( ) ;
522+
523+ if ( filePath . includes ( '~' ) ) {
524+ filePath = filePath . replace ( / ~ / g, os . homedir ( ) ) ;
525+ }
526+
527+ filePath = path . resolve ( filePath ) ;
528+
529+ if ( ! fs . existsSync ( filePath ) ) {
530+ fs . mkdirSync ( filePath , { recursive : true } ) ;
531+ }
532+
533+ if ( fs . statSync ( filePath ) . isDirectory ( ) ) {
534+ filePath = path . join ( filePath , fileName ) ;
535+ }
536+
537+ fs . writeFileSync ( filePath , JSON . stringify ( formattedVariables ) ) ;
538+
539+ spinner . succeed ( `Publish environment variables downloaded successfully to ${ filePath } ` ) ;
540+ } catch ( e ) {
541+ spinner . fail ( 'Failed to download publish environment variables' ) ;
542+ throw e ;
543+ }
480544 } else if ( command . fullCommandName === `${ PROGRAM_NAME } -publish-profile-version-list` ) {
481545 const spinner = createOra ( 'Fetching...' ) . start ( ) ;
482546 const appVersions = await getAppVersions ( params ) ;
@@ -556,7 +620,7 @@ const handleBuildCommand = async (command: ProgramCommand, params:any) => {
556620 fullCommandName : command . fullCommandName ,
557621 data : responseData ,
558622 } ) ;
559- } else if ( command . fullCommandName === `${ PROGRAM_NAME } -build-profile-branch-list` ) {
623+ } else if ( command . fullCommandName === `${ PROGRAM_NAME } -build-profile-branch-list` ) {
560624 const spinner = createOra ( 'Fetching...' ) . start ( ) ;
561625 const responseData = await getBranches ( params ) ;
562626 spinner . succeed ( ) ;
@@ -683,6 +747,57 @@ const handleBuildCommand = async (command: ProgramCommand, params:any) => {
683747 fullCommandName : command . fullCommandName ,
684748 data : responseData ,
685749 } ) ;
750+ } else if ( command . fullCommandName === `${ PROGRAM_NAME } -build-variable-download` ) {
751+ const spinner = createOra ( 'Downloading environment variables...' ) . start ( ) ;
752+ try {
753+ const variableGroups = await getEnvironmentVariableGroups ( ) ;
754+ const variableGroup = variableGroups . find ( ( group : any ) => group . id === params . variableGroupId ) ;
755+
756+ if ( ! variableGroup ) {
757+ spinner . fail ( `Variable group with ID ${ params . variableGroupId } not found` ) ;
758+ throw new Error ( `Variable group not found` ) ;
759+ }
760+
761+ const responseData = await getEnvironmentVariables ( params ) ;
762+
763+ let formattedVariables = responseData . map ( ( variable : any ) => ( {
764+ key : variable . key ,
765+ value : variable . value ,
766+ isSecret : variable . isSecret ,
767+ isFile : variable . isFile || false ,
768+ id : variable . key
769+ } ) ) ;
770+
771+ formattedVariables . sort ( ( a : any , b : any ) => {
772+ const aKey = a . key ;
773+ const bKey = b . key ;
774+ return bKey . localeCompare ( aKey ) ;
775+ } ) ;
776+
777+ const timestamp = Date . now ( ) ;
778+ const fileName = `${ variableGroup . name } _${ timestamp } .json` ;
779+ let filePath = params . path || process . cwd ( ) ;
780+
781+ if ( filePath . includes ( '~' ) ) {
782+ filePath = filePath . replace ( / ~ / g, os . homedir ( ) ) ;
783+ }
784+
785+ filePath = path . resolve ( filePath ) ;
786+
787+ if ( ! fs . existsSync ( filePath ) ) {
788+ fs . mkdirSync ( filePath , { recursive : true } ) ;
789+ }
790+
791+ if ( fs . statSync ( filePath ) . isDirectory ( ) ) {
792+ filePath = path . join ( filePath , fileName ) ;
793+ }
794+
795+ fs . writeFileSync ( filePath , JSON . stringify ( formattedVariables ) ) ;
796+ spinner . succeed ( `Environment variables downloaded successfully to ${ filePath } ` ) ;
797+ } catch ( e ) {
798+ spinner . fail ( 'Failed to download environment variables' ) ;
799+ throw e ;
800+ }
686801 } else if ( command . fullCommandName === `${ PROGRAM_NAME } -build-variable-create` ) {
687802 const spinner = createOra ( 'Creating environment variable' ) . start ( ) ;
688803 try {
0 commit comments