cli icon indicating copy to clipboard operation
cli copied to clipboard

Add ability to add a baseUrl per environment to aurelia.json

Open DavidColemanUK opened this issue 7 years ago • 4 comments

I'm submitting a feature request

  • Operating System: Windows 10

  • Node Version: 6.10.0

  • NPM Version: 3.10.10

  • Aurelia CLI Version CLI 0.27.0

  • Language: TypeScript 2.3.2

Current behavior: Currently, there is no way to change the baseUrl per deployment environment.

Our current work around is to bruteforce the line using powershell to modify, during the release process to each server.

Expected/desired behavior: Ability to provide baseUrl per environment in aurelia.json file, or in environment.js file. Failing that, then ability to pass in a value via CLI parameter, so that the value can more easily be substituted on deployment

  • What is the motivation / use case for changing the behavior? Make it easier and more versatile to be able to deploy the same build definition to different environments such as in a CI/CD pipeline.

Example: See below for the workaround we are currently having to do in our store multiple value in aurelia.json and then use Powershell to change the value.

baseissue

DavidColemanUK avatar Jul 13 '17 14:07 DavidColemanUK

I have created a pullrequest that can solve this issue if you are using require. https://github.com/aurelia/cli/pull/686

Add the following to the build task (aurelia_project/tasks/build.ts) in your project in the readProjectConfiguration method. Note the you only want one (1) back apostrophe before aurelia_project and one (1) back apostrophe after .ts, but this text editor does not allow me to do that.

const env = CLIOptions.getEnvironment(); const envContent = fs.readFileSync(``aurelia_project/environments/${env}.ts``, 'utf8'); const providerHostUrl = /providerHostUrl: '(.*)'/ig.exec(envContent)[1]; project.paths.customBaseUrl = providerHostUrl;

You also need below import in the build task import * as fs from 'fs';

Then just add below to you environment file providerHostUrl: 'https://your.environemnt.specific.url/',

To be clear. The pull request makes i easy to use absolut url that is different from the hosting page. The change of the build task above makes it possible to override the url for different environements.

To be super clear. You need to build with the environment flag to make it work. au build --env dev

If the pull request 686 is accepted I will add a pull request for above as well.

I am using version 0.30.1 of aurelia-cli

magnusdanielson avatar Aug 02 '17 19:08 magnusdanielson

So one of my environment files looks like below. The providerHostUrl is the interesting configuration.

image

magnusdanielson avatar Aug 02 '17 19:08 magnusdanielson

And yes, before anyone asks. We use another task to move the output files to a ASP.Net MVC project with below task.

import * as gulp from 'gulp'; import * as changed from 'gulp-changed'; import * as project from '../aurelia.json'; export default function sp() { return gulp.src('scripts/**/*', {base:"."}) .pipe(gulp.dest('../../YOUR.PROJECTNAME'));}

It is our last build step in build.ts

magnusdanielson avatar Aug 02 '17 20:08 magnusdanielson

@DavidColemanUK any thoughts on this?

magnusdanielson avatar Aug 14 '17 07:08 magnusdanielson