-
Notifications
You must be signed in to change notification settings - Fork 1
/
start.js
62 lines (51 loc) · 1.59 KB
/
start.js
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
const settings = require('./settings');
const Backend = require('./processes/backend');
const Frontend = require('./processes/frontend');
const Database = require('./database');
const Cypress = require('./processes/cypress');
const { info } = require('@vue/cli-shared-utils');
async function start(api, options = {}) {
const config = Object.assign(options, await settings, process.env);
const { BACKEND_PORT } = config;
options.devServer.proxy = {
'/api': {
target: `http://localhost:${BACKEND_PORT}`,
},
'/accounts/*': {
target: `http://localhost:${BACKEND_PORT}`,
},
'/media/*': {
target: `http://localhost:${BACKEND_PORT}`,
},
};
process.env.NODE_ENV = 'production';
// Setup backend, frontend and database
const database = new Database(config);
await database.create();
const runserver = config['runserver']
let backend
if (runserver === true) {
backend = new Backend(config);
await backend.start();
} else {
info('Not starting backend server (assuming it is already running)...')
}
const frontend = new Frontend(config);
await frontend.start(api);
// Setup cypress e2e test runner
const cypress = new Cypress(config);
const runner = cypress.start();
async function teardown(code) {
if (runserver === true) {
await backend.kill();
}
await database.drop();
process.exit(code);
}
// Make sure to clean up running process when tests are done or failing
runner.on('exit', teardown);
runner.on('error', teardown);
// Handle SIGINT signal
process.on('SIGINT', teardown);
}
module.exports = start;