mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
use standard environments
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import { environment } from '../src/environments/environment';
|
||||
|
||||
import * as child from 'child_process';
|
||||
|
||||
import { environment } from '../src/environments/environment';
|
||||
|
||||
// import { AppConfig } from '../src/config/app-config.interface';
|
||||
// import { buildAppConfig } from '../src/config/config.server';
|
||||
|
||||
// const appConfig: AppConfig = buildAppConfig();
|
||||
|
||||
/**
|
||||
* Calls `ng serve` with the following arguments configured for the UI in the environment file: host, port, nameSpace, ssl
|
||||
* Calls `ng serve` with the following arguments configured for the UI in the environment: host, port, nameSpace, ssl
|
||||
*/
|
||||
child.spawn(
|
||||
`ng serve --host ${environment.ui.host} --port ${environment.ui.port} --servePath ${environment.ui.nameSpace} --ssl ${environment.ui.ssl}`,
|
||||
`ng serve --host ${environment.ui.host} --port ${environment.ui.port} --serve-path ${environment.ui.nameSpace} --ssl ${environment.ui.ssl}`,
|
||||
{ stdio:'inherit', shell: true }
|
||||
);
|
||||
|
@@ -1,116 +0,0 @@
|
||||
import { writeFile } from 'fs';
|
||||
import { environment as commonEnv } from '../src/environments/environment.common';
|
||||
import { AppConfig } from '../src/config/app-config.interface';
|
||||
import { ServerConfig } from '../src/config/server-config.interface';
|
||||
import { hasValue } from '../src/app/shared/empty.util';
|
||||
|
||||
// Configure Angular `environment.ts` file path
|
||||
const targetPath = './src/environments/environment.ts';
|
||||
// Load node modules
|
||||
const colors = require('colors');
|
||||
require('dotenv').config();
|
||||
const merge = require('deepmerge');
|
||||
const mergeOptions = { arrayMerge: (destinationArray, sourceArray, options) => sourceArray };
|
||||
const environment = process.argv[2];
|
||||
let environmentFilePath;
|
||||
let production = false;
|
||||
|
||||
switch (environment) {
|
||||
case '--prod':
|
||||
case '--production':
|
||||
production = true;
|
||||
console.log(`Building ${colors.red.bold(`production`)} environment`);
|
||||
environmentFilePath = '../src/environments/environment.prod.ts';
|
||||
break;
|
||||
case '--test':
|
||||
console.log(`Building ${colors.blue.bold(`test`)} environment`);
|
||||
environmentFilePath = '../src/environments/environment.test.ts';
|
||||
break;
|
||||
default:
|
||||
console.log(`Building ${colors.green.bold(`development`)} environment`);
|
||||
environmentFilePath = '../src/environments/environment.dev.ts';
|
||||
}
|
||||
|
||||
const processEnv = {
|
||||
ui: createServerConfig(
|
||||
process.env.DSPACE_HOST,
|
||||
process.env.DSPACE_PORT,
|
||||
process.env.DSPACE_NAMESPACE,
|
||||
process.env.DSPACE_SSL),
|
||||
rest: createServerConfig(
|
||||
process.env.DSPACE_REST_HOST,
|
||||
process.env.DSPACE_REST_PORT,
|
||||
process.env.DSPACE_REST_NAMESPACE,
|
||||
process.env.DSPACE_REST_SSL)
|
||||
} as AppConfig;
|
||||
|
||||
import(environmentFilePath)
|
||||
.then((file) => generateEnvironmentFile(merge.all([commonEnv, file.environment, processEnv], mergeOptions)))
|
||||
.catch(() => {
|
||||
console.log(colors.yellow.bold(`No specific environment file found for ` + environment));
|
||||
generateEnvironmentFile(merge(commonEnv, processEnv, mergeOptions))
|
||||
});
|
||||
|
||||
function generateEnvironmentFile(file: AppConfig): void {
|
||||
file.production = production;
|
||||
buildBaseUrls(file);
|
||||
const contents = `export const environment = ` + JSON.stringify(file);
|
||||
writeFile(targetPath, contents, (err) => {
|
||||
if (err) {
|
||||
throw console.error(err);
|
||||
} else {
|
||||
console.log(`Angular ${colors.bold('environment.ts')} file generated correctly at ${colors.bold(targetPath)} \n`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// allow to override a few important options by environment variables
|
||||
function createServerConfig(host?: string, port?: string, nameSpace?: string, ssl?: string): ServerConfig {
|
||||
const result = {} as any;
|
||||
if (hasValue(host)) {
|
||||
result.host = host;
|
||||
}
|
||||
|
||||
if (hasValue(nameSpace)) {
|
||||
result.nameSpace = nameSpace;
|
||||
}
|
||||
|
||||
if (hasValue(port)) {
|
||||
result.port = Number(port);
|
||||
}
|
||||
|
||||
if (hasValue(ssl)) {
|
||||
result.ssl = ssl.trim().match(/^(true|1|yes)$/i) ? true : false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function buildBaseUrls(config: AppConfig): void {
|
||||
for (const key in config) {
|
||||
if (config.hasOwnProperty(key) && config[key].host) {
|
||||
config[key].baseUrl = [
|
||||
getProtocol(config[key].ssl),
|
||||
getHost(config[key].host),
|
||||
getPort(config[key].port),
|
||||
getNameSpace(config[key].nameSpace)
|
||||
].join('');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getProtocol(ssl: boolean): string {
|
||||
return ssl ? 'https://' : 'http://';
|
||||
}
|
||||
|
||||
function getHost(host: string): string {
|
||||
return host;
|
||||
}
|
||||
|
||||
function getPort(port: number): string {
|
||||
return port ? (port !== 80 && port !== 443) ? ':' + port : '' : '';
|
||||
}
|
||||
|
||||
function getNameSpace(nameSpace: string): string {
|
||||
return nameSpace ? nameSpace.charAt(0) === '/' ? nameSpace : '/' + nameSpace : '';
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
import { copyFile } from 'fs';
|
||||
|
||||
// Configure Angular `environment.ts` file path
|
||||
const sourcePath = './src/environments/mock-environment.ts';
|
||||
const targetPath = './src/environments/environment.ts';
|
||||
|
||||
// destination.txt will be created or overwritten by default.
|
||||
copyFile(sourcePath, targetPath, (err) => {
|
||||
if (err) throw err;
|
||||
console.log(sourcePath + ' was copied to ' + targetPath);
|
||||
});
|
@@ -1,13 +1,19 @@
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
|
||||
import { environment } from '../src/environments/environment';
|
||||
|
||||
// import { AppConfig } from '../src/config/app-config.interface';
|
||||
// import { buildAppConfig } from '../src/config/config.server';
|
||||
|
||||
// const appConfig: AppConfig = buildAppConfig();
|
||||
|
||||
/**
|
||||
* Script to test the connection with the configured REST API (in the 'rest' settings of your environment.*.ts)
|
||||
*
|
||||
* This script is useful to test for any Node.js connection issues with your REST API.
|
||||
*
|
||||
* Usage (see package.json): yarn test:rest-api
|
||||
* Usage (see package.json): yarn test:rest
|
||||
*/
|
||||
|
||||
// Get root URL of configured REST API
|
||||
|
Reference in New Issue
Block a user