source: frontend/node_modules/detect-port-alt/bin/detect-port

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#!/usr/bin/env node
2
3'use strict';
4
5const pkg = require('../package');
6
7const args = process.argv.slice(2);
8const arg_0 = args[0];
9
10if (!!~['-v', '--version'].indexOf(arg_0)) {
11 console.log(pkg.version);
12 process.exit(0);
13}
14
15const port = parseInt(arg_0, 10);
16
17const main = require('..');
18
19if (!arg_0) {
20 const random = Math.floor(9000 + Math.random() * (65535 - 9000));
21
22 main(random, (err, port) => {
23 if (err) {
24 console.log(`get available port failed with ${err}`);
25 }
26 console.log(`get available port ${port} randomly`);
27 });
28} else if (isNaN(port)) {
29 console.log();
30 console.log(` \u001b[37m${pkg.description}\u001b[0m`);
31 console.log();
32 console.log(' Usage:');
33 console.log();
34 console.log(` ${pkg.name} [port]`);
35 console.log();
36 console.log(' Options:');
37 console.log();
38 console.log(' -v, --version show version and exit');
39 console.log(' -h, --help output usage information');
40 console.log();
41 console.log(' Further help:');
42 console.log();
43 console.log(` ${pkg.homepage}`);
44 console.log();
45} else {
46 main(port, (err, _port) => {
47 if (err) {
48 console.log(`get available port failed with ${err}`);
49 }
50
51 if (port !== _port) {
52 console.log(`port ${port} was occupied`);
53 }
54 console.log(`get available port ${_port}`);
55 });
56}
Note: See TracBrowser for help on using the repository browser.