summaryrefslogtreecommitdiffstats
path: root/openecomp-ui/runLocalFE.js
blob: 1205aa48f935ceeb9b923f628562f5fe6d63864a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*!
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

var exec = require('child_process');
var prompt = require('prompt');
var fs = require('fs');


function runNpm(target, dir) {
	console.log('\n---> npm ' + target);
	let options = {stdio:[0,1,2]};
	if (dir) options.cwd = dir;
	exec.execSync("npm " + target,options);
}

function npmInstallAll() {
	setNpmconfig();
	if (!fs.existsSync('../dox-sequence-diagram-ui/node_modules')) {
		console.log('--> first time installing dox-sequence-diagram-ui');
		runNpm('install', '../dox-sequence-diagram-ui');
	};
	runNpm('install');
	// just to make sure restful js is installed properly
	runNpm('install jquery', 'node_modules/restful-js');
}

function getDevConfig() {
	var content=fs.readFileSync('./devConfig.json');
	var data=JSON.parse(content);
	console.log('Current ATT server is set to: ' + data.proxyATTTarget);
	if (!data.proxyTarget) {
		console.log('Current onboarding server defaults to the ATT server');
	} else {
		console.log('Current onboarding server set to: ' + data.proxyTarget);
	}
	return data;
}

function setNpmconfig() {
	exec.execSync("npm config set proxy http://genproxy.amdocs.com:8080");
	exec.execSync("npm config set https_proxy http://genproxy.amdocs.com:8080");
}

// getting the run details before starting to work
prompt.start();
prompt.get([{
		name:'runType',
		type:'number',
		default:1,
		description: 'Choose run: 1-test and build, 2- run frontend server '
	}], function (err, result) {
	if (result.runType === 2) {
		console.log('--> Reading the configuration for the local server');
		if (!fs.existsSync('./devConfig.json')) {
			console.log('First time - setting up the devConfig.json file');
			fs.writeFileSync('./devConfig.json', fs.readFileSync('./devConfig.defaults.json'));
		}
		let data = getDevConfig();
		let attProxyField = {
			name:'attProxyTarget',
			description:'ATT server'
		};
		let proxyField = {
			name:'proxyTarget',
			description:'onboarding server, \'null\' to reset'
		};
		if (data.proxyATTTarget) attProxyField.default = data.proxyATTTarget;
		if (data.proxyTarget) proxyField.default = data.proxyTarget;
		prompt.get([ attProxyField, proxyField], function (err,result) {
				data.proxyATTTarget = result.attProxyTarget;
				if(result.proxyTarget) {
					if (result.proxyTarget === 'null') {
						if (data.proxyTarget) delete data.proxyTarget;
					} else {
						data.proxyTarget = result.proxyTarget;
					}
				}
				fs.writeFileSync('./devConfig.json', JSON.stringify(data, null, 2));
				getDevConfig();
				console.log('FE server will be answering on: http://localhost:9000/sdc1/proxy-designer1#/onboardVendor');
				npmInstallAll();
				runNpm("start");
			}
		);
	} else {
		npmInstallAll();
		runNpm("run build");
		runNpm("run test");
	}
});