add template file, update readme, remove logs

This commit is contained in:
Art Lowel
2020-03-27 15:51:54 +01:00
parent 1caec64115
commit f61f92e1ad
3 changed files with 43 additions and 27 deletions

View File

@@ -79,39 +79,46 @@ Installing
Default configuration file is located in `src/environments/` folder. Default configuration file is located in `src/environments/` folder.
To change the default configuration values, create local files that override the parameters you need to change: To change the default configuration values, create local files that override the parameters you need to change. You can use `environment.template.ts` as a starting point.
- Create a new `environment.dev.ts` file in `src/environments/` for `development` environment; - Create a new `environment.dev.ts` file in `src/environments/` for a `development` environment;
- Create a new `environment.prod.ts` file in `src/environments/` for `production` environment; - Create a new `environment.prod.ts` file in `src/environments/` for a `production` environment;
To use the configuration parameters in your component: The server settings can also be overwritten using an environment file.
```bash
import { environment } from '../environment.ts';
```
This file is generated by the script located in `scripts/set-env.ts`.
The server settings can be overwritten using an environment file.
This file should be called `.env` and be placed in the project root. This file should be called `.env` and be placed in the project root.
The following settings can be overwritten in this file: The following settings can be overwritten in this file:
``` ```bash
DSPACE_HOST // The host name of the angular application DSPACE_HOST # The host name of the angular application
DSPACE_PORT // The port number of the angular application DSPACE_PORT # The port number of the angular application
DSPACE_NAMESPACE // The namespace of the angular application DSPACE_NAMESPACE # The namespace of the angular application
DSPACE_SSL // Whether the angular application uses SSL [true/false] DSPACE_SSL # Whether the angular application uses SSL [true/false]
DSPACE_REST_HOST // The host name of the REST application DSPACE_REST_HOST # The host name of the REST application
DSPACE_REST_PORT // The port number of the REST application DSPACE_REST_PORT # The port number of the REST application
DSPACE_REST_NAMESPACE // The namespace of the REST application DSPACE_REST_NAMESPACE # The namespace of the REST application
DSPACE_REST_SSL // Whether the angular REST uses SSL [true/false] DSPACE_REST_SSL # Whether the angular REST uses SSL [true/false]
``` ```
The same settings can also be overwritten by setting system environment variables instead, E.g.: The same settings can also be overwritten by setting system environment variables instead, E.g.:
```export DSPACE_HOST=https://dspace7.4science.cloud/server``` ```bash
export DSPACE_HOST=https://dspace7.4science.cloud/server
```
The priority works as follows: **environment variable** overrides **variable in `.env` file** overrides **`environment.(prod, dev or test).ts`** overrides **`environment.common.ts`**
#### Using environment variables in code
To use environment variables in a UI component, use:
```typescript
import { environment } from '../environment.ts';
```
This file is generated by the script located in `scripts/set-env.ts`. This script will run automatically before every build, or can be manually triggered using the appropriate `config` script in `package.json`
Running the app Running the app
--------------- ---------------

View File

@@ -19,12 +19,15 @@ switch (environment) {
case '--prod': case '--prod':
case '--production': case '--production':
production = true; production = true;
console.log(`Building ${colors.red.bold(`production`)} environment`);
environmentFilePath = '../src/environments/environment.prod.ts'; environmentFilePath = '../src/environments/environment.prod.ts';
break; break;
case '--test': case '--test':
console.log(`Building ${colors.blue.bold(`test`)} environment`);
environmentFilePath = '../src/environments/environment.test.ts'; environmentFilePath = '../src/environments/environment.test.ts';
break; break;
default: default:
console.log(`Building ${colors.green.bold(`development`)} environment`);
environmentFilePath = '../src/environments/environment.dev.ts'; environmentFilePath = '../src/environments/environment.dev.ts';
} }
@@ -49,13 +52,11 @@ function generateEnvironmentFile(file: GlobalConfig): void {
file.production = production; file.production = production;
buildBaseUrls(file); buildBaseUrls(file);
const contents = `export const environment = ` + JSON.stringify(file); const contents = `export const environment = ` + JSON.stringify(file);
console.log(colors.magenta('The file `environment.ts` will be written with the following content: \n'));
console.log(colors.grey(contents));
writeFile(targetPath, contents, (err) => { writeFile(targetPath, contents, (err) => {
if (err) { if (err) {
throw console.error(err); throw console.error(err);
} else { } else {
console.log(colors.magenta(`Angular environment.ts file generated correctly at ${targetPath} \n`)); console.log(`Angular ${colors.bold('environment.ts')} file generated correctly at ${colors.bold(targetPath)} \n`);
} }
}); });
} }
@@ -85,8 +86,6 @@ function createServerConfig(host?: string, port?: string, nameSpace?: string, s
function buildBaseUrls(config: GlobalConfig): void { function buildBaseUrls(config: GlobalConfig): void {
for (const key in config) { for (const key in config) {
if (config.hasOwnProperty(key) && config[key].host) { if (config.hasOwnProperty(key) && config[key].host) {
console.log(key);
console.log(config[key]);
config[key].baseUrl = [ config[key].baseUrl = [
getProtocol(config[key].ssl), getProtocol(config[key].ssl),
getHost(config[key].host), getHost(config[key].host),

View File

@@ -0,0 +1,10 @@
export const environment = {
/**
* TODO add the sections from environment.common.ts you want to override here
* e.g.
* rest: {
* host: 'rest.api',
* nameSpace: '/rest/api',
* }
*/
};