UNPKG

1.82 kBJavaScriptView Raw
1var R = require('ramda');
2var minimist = require('minimist');
3var chalk = require('chalk');
4var fsPath = require('path');
5
6var codeDir = process.env.QUICK_BUILD ? 'src' : 'lib';
7var loadScript = path => require(fsPath.join(__dirname, codeDir, path));
8
9var server = loadScript('server').default;
10var yamlConfig = loadScript('server/yaml-config');
11var log = loadScript('shared/log').default;
12
13
14// Read-in command-line arguments.
15var args = process.argv.slice(2);
16args = args.length > 0 ? args = minimist(args) : {};
17
18
19// Look for an entry string.
20const config = yamlConfig.load() || {};
21var entry = args.entry || (config && config.entry);
22
23
24/**
25 * Look for arguments passed in at the command-line,
26 * and starts the server if required.
27 *
28 * If arguments are no explicitly passed at the command-line, then the values are
29 * retrieved from the [.uiharness.yml] file if present.
30 *
31 * Command-line arguments:
32 *
33 * --entry: Required. Path to the specs files (comma separated if more than one).
34 * If not present the server is not started.
35 * Example: --entry ./src/specs
36 *
37 * --port: Optional. The port to start the server on.
38 * Default: 3030
39 *
40 */
41if (entry) {
42 entry = R.is(String, entry) ? entry.split(',') : entry;
43 server.start({
44 entry,
45 port: args.port || config.port,
46 })
47 .catch(err => {
48 log.error(chalk.red('Failed to start.'));
49 log.error(chalk.red(err.message));
50 log.error()
51 });
52} else {
53 log.error();
54 log.error(chalk.red('No entry path was specified for the UIHarness.'));
55 log.error(chalk.grey(' Make sure you have a [.uiharness.yml] file in the root of the project,'));
56 log.error(chalk.grey(' or pass a --entry command line argument, for example: `--entry ./src/specs`'));
57 log.error();
58}