Azure / ng-deploy-azure

Deploy Angular apps to Azure using the Angular CLI
MIT License
79 stars 37 forks source link

Allow multiple deploys from same project #84

Open jakobgn opened 4 years ago

jakobgn commented 4 years ago

Description

The hosting property in azure.json is already designed as an enumerable data structure, however only a single configuration can currently be deployed at a time. I.e if I have multiple configs defined in azure.json, only the first has any impact.

Value: Deploy same project with various build-configurations

Solution: Change getAzureHostingConfig to return an array of hosting configs rather than finding the first match. Then run deploy on each configuration.

Type of change

Please delete options that are not relevant.

jakobgn commented 4 years ago

Simple solution (works in my machine™):

const azureProjects = getAzureHostingConfig(workspaceRoot, context.target.project, builderConfig.config); if (!azureProjects || azureProjects.length === 0) { throw new Error(Configuration for project ${context.target.project} was not found in azure.json.); } return (await Promise.all( azureProjects.map(async azureProject => { try { await deploy(context, join(workspaceRoot, project.root), azureProject); return { success: true }; } catch (e) { context.logger.error('Error when trying to deploy: ' + azureProject.azureHosting.account); context.logger.error(e.message); return { success: false }; } }) )).every(x => x.success) ? { success: true } : { success: false }; } );

export function getAzureHostingConfig( projectRoot: string, target: string, azureConfigFile: string ): AzureHostingConfig[] | undefined { const azureJson: AzureJSON = JSON.parse(readFileSync(join(projectRoot, azureConfigFile), 'UTF-8')); if (!azureJson) { throw new Error(Cannot read configuration file "${azureConfigFile}"); } const projects = azureJson.hosting; return projects.filter(project => project.app.project === target); }

jakobgn commented 4 years ago

Probably ng add needs to be updated as well, to not overwrite when new configurations are added.

Authentication should be run before deploy as well, to avoid multiple signin links

manekinekko commented 4 years ago

Thanks for reporting this issue. Would you be interested in creating a PR?