1 |
|
2 | 'use strict';
|
3 |
|
4 | const packageData = require('./package.json');
|
5 | const isEnabled = value => !!value && value !== '0' && value !== 'false';
|
6 | const canUseColor = isEnabled(process.env.npm_config_color);
|
7 |
|
8 | const title = `=== Nodemailer ${packageData.version} ===`;
|
9 | const text = `
|
10 | Thank you for using Nodemailer for your email sending needs! While Nodemailer itself is mostly meant to be a SMTP client there are other related projects in the Nodemailer project as well.
|
11 |
|
12 | > IMAP API ( https://imapapi.com ) is a server application to easily access IMAP accounts via REST API
|
13 | > ImapFlow ( https://imapflow.com/ ) is an async IMAP client library for Node.js
|
14 | > NodemailerApp ( https://nodemailer.com/app/ ) is a cross platform GUI app to debug emails
|
15 | > Project Pending ( https://projectpending.com/ ) allows you to host DNS of your project domains
|
16 | > Pending DNS ( https://pendingdns.com/ ) is the DNS server used that powers Project Pending
|
17 | > Ethereal Email ( https://ethereal.email/ ) is an email testing service that accepts all your test emails
|
18 | `;
|
19 |
|
20 | const footer = `Don't like this message?
|
21 | There's a Github Sponsors goal to remove it
|
22 | https://github.com/sponsors/andris9
|
23 | `;
|
24 |
|
25 | const secs = 4;
|
26 |
|
27 | const formatCentered = (row, columns) => {
|
28 | return row
|
29 | .split(/\r?\n/)
|
30 | .map(row => {
|
31 | if (columns <= row.length) {
|
32 | return row;
|
33 | }
|
34 |
|
35 | return ' '.repeat(Math.round(columns / 2 - row.length / 2)) + row;
|
36 | })
|
37 | .join('\n');
|
38 | };
|
39 |
|
40 | const formatRow = (row, columns) => {
|
41 | if (row.length <= columns) {
|
42 | return [row];
|
43 | }
|
44 |
|
45 | let lines = [];
|
46 | while (row.length) {
|
47 | if (row.length <= columns) {
|
48 | lines.push(row);
|
49 | break;
|
50 | }
|
51 | let slice = row.substr(0, columns);
|
52 |
|
53 | let prefix = slice.charAt(0) === '>' ? ' ' : '';
|
54 |
|
55 | let match = slice.match(/(\s+)[^\s]*$/);
|
56 | if (match && match.index) {
|
57 | let line = row.substr(0, match.index);
|
58 | row = prefix + row.substr(line.length + match[1].length);
|
59 | lines.push(line);
|
60 | } else {
|
61 | lines.push(row);
|
62 | break;
|
63 | }
|
64 | }
|
65 | return lines;
|
66 | };
|
67 |
|
68 | const wrapText = text => {
|
69 | let columns = Number(process.stdout.columns) || 80;
|
70 | columns = Math.min(columns, 80) - 1;
|
71 |
|
72 | return (
|
73 | (formatCentered(title, columns) + '\n' + text)
|
74 | .split('\n')
|
75 | .flatMap(row => formatRow(row, columns))
|
76 | .join('\n') +
|
77 | '\n' +
|
78 | formatCentered(footer, columns)
|
79 | );
|
80 | };
|
81 |
|
82 | const banner = wrapText(text)
|
83 | .replace(/^/gm, '\u001B[96m')
|
84 | .replace(/$/gm, '\u001B[0m')
|
85 | .replace(/(https:[^\s)]+)/g, '\u001B[94m $1 \u001B[96m');
|
86 |
|
87 | console.log(canUseColor ? banner : banner.replace(/\u001B\[\d+m/g, ''));
|
88 | if (canUseColor) {
|
89 | process.stdout.write('\u001B[96m');
|
90 | }
|
91 |
|
92 | setInterval(() => {
|
93 | process.stdout.write('.');
|
94 | }, 500);
|
95 |
|
96 | setTimeout(() => {
|
97 | if (canUseColor) {
|
98 | process.stdout.write('\u001B[0m\n');
|
99 | }
|
100 | process.exit(0);
|
101 | }, secs * 1000 + 100);
|