blob: 1205aa48f935ceeb9b923f628562f5fe6d63864a [file] [log] [blame]
Avi Zivb8e2faf2017-07-18 19:45:38 +03001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
15 */
16
17var exec = require('child_process');
18var prompt = require('prompt');
19var fs = require('fs');
20
21
22function runNpm(target, dir) {
23 console.log('\n---> npm ' + target);
24 let options = {stdio:[0,1,2]};
25 if (dir) options.cwd = dir;
26 exec.execSync("npm " + target,options);
27}
28
29function npmInstallAll() {
30 setNpmconfig();
31 if (!fs.existsSync('../dox-sequence-diagram-ui/node_modules')) {
32 console.log('--> first time installing dox-sequence-diagram-ui');
33 runNpm('install', '../dox-sequence-diagram-ui');
34 };
35 runNpm('install');
36 // just to make sure restful js is installed properly
37 runNpm('install jquery', 'node_modules/restful-js');
38}
39
40function getDevConfig() {
41 var content=fs.readFileSync('./devConfig.json');
42 var data=JSON.parse(content);
43 console.log('Current ATT server is set to: ' + data.proxyATTTarget);
44 if (!data.proxyTarget) {
45 console.log('Current onboarding server defaults to the ATT server');
46 } else {
47 console.log('Current onboarding server set to: ' + data.proxyTarget);
48 }
49 return data;
50}
51
52function setNpmconfig() {
53 exec.execSync("npm config set proxy http://genproxy.amdocs.com:8080");
54 exec.execSync("npm config set https_proxy http://genproxy.amdocs.com:8080");
55}
56
57// getting the run details before starting to work
58prompt.start();
59prompt.get([{
60 name:'runType',
61 type:'number',
62 default:1,
63 description: 'Choose run: 1-test and build, 2- run frontend server '
64 }], function (err, result) {
65 if (result.runType === 2) {
66 console.log('--> Reading the configuration for the local server');
67 if (!fs.existsSync('./devConfig.json')) {
68 console.log('First time - setting up the devConfig.json file');
69 fs.writeFileSync('./devConfig.json', fs.readFileSync('./devConfig.defaults.json'));
70 }
71 let data = getDevConfig();
72 let attProxyField = {
73 name:'attProxyTarget',
74 description:'ATT server'
75 };
76 let proxyField = {
77 name:'proxyTarget',
78 description:'onboarding server, \'null\' to reset'
79 };
80 if (data.proxyATTTarget) attProxyField.default = data.proxyATTTarget;
81 if (data.proxyTarget) proxyField.default = data.proxyTarget;
82 prompt.get([ attProxyField, proxyField], function (err,result) {
83 data.proxyATTTarget = result.attProxyTarget;
84 if(result.proxyTarget) {
85 if (result.proxyTarget === 'null') {
86 if (data.proxyTarget) delete data.proxyTarget;
87 } else {
88 data.proxyTarget = result.proxyTarget;
89 }
90 }
91 fs.writeFileSync('./devConfig.json', JSON.stringify(data, null, 2));
92 getDevConfig();
93 console.log('FE server will be answering on: http://localhost:9000/sdc1/proxy-designer1#/onboardVendor');
94 npmInstallAll();
95 runNpm("start");
96 }
97 );
98 } else {
99 npmInstallAll();
100 runNpm("run build");
101 runNpm("run test");
102 }
103});
104