-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-url.js
41 lines (35 loc) · 1 KB
/
start-url.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
if (!process.env.npm_config_nocopy)
{
const { write: copy } = require('clipboardy');
const chalk = require('chalk');
const boxen = require('boxen');
const port = process.env.npm_config_port || 1234;
const params = process.env.npm_config_params;
let url = `http://localhost:${port}`;
if (params)
{
url += `/profile/${encodeURIComponent(params)}`;
}
(async () =>
{
let message = chalk.yellow.inverse('Your URL');
message += `\n\n${chalk.bold(`${url}`)}`;
try
{
await copy(url);
message += `\n\n${chalk.grey('Copied local address to clipboard!')}`;
}
catch (err)
{
message = chalk.red.bold(`Cannot copy ${url} to clipboard 🥺\n\n${err.message}`);
}
console.log(
boxen(message, {
borderStyle: 'round',
padding: 1,
borderColor: 'yellow',
margin: 1
})
);
})();
}