send-mail/node_modules/nodemailer/postinstall.js

102 lines
3.0 KiB
JavaScript
Raw Permalink Normal View History

2020-03-24 19:34:13 +07:00
/* eslint no-control-regex:0 */
'use strict';
const packageData = require('./package.json');
const isEnabled = value => !!value && value !== '0' && value !== 'false';
const canUseColor = isEnabled(process.env.npm_config_color);
2020-07-09 20:48:05 +07:00
const title = `=== Nodemailer ${packageData.version} ===`;
const text = `
2020-03-24 19:34:13 +07:00
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.
> IMAP API ( https://imapapi.com ) is a server application to easily access IMAP accounts via REST API
2020-07-09 20:48:05 +07:00
> ImapFlow ( https://imapflow.com/ ) is an async IMAP client library for Node.js
2020-03-24 19:34:13 +07:00
> NodemailerApp ( https://nodemailer.com/app/ ) is a cross platform GUI app to debug emails
2020-07-09 20:48:05 +07:00
> Project Pending ( https://projectpending.com/ ) allows you to host DNS of your project domains
> Pending DNS ( https://pendingdns.com/ ) is the DNS server used that powers Project Pending
> Ethereal Email ( https://ethereal.email/ ) is an email testing service that accepts all your test emails
2020-03-24 19:34:13 +07:00
`;
2020-08-30 17:08:22 +07:00
const footer = `Don't like this message?
There's a Github Sponsors goal to remove it
https://github.com/sponsors/andris9
`;
2020-07-09 20:48:05 +07:00
const secs = 4;
const formatCentered = (row, columns) => {
2020-08-30 17:08:22 +07:00
return row
.split(/\r?\n/)
.map(row => {
if (columns <= row.length) {
return row;
}
2020-07-09 20:48:05 +07:00
2020-08-30 17:08:22 +07:00
return ' '.repeat(Math.round(columns / 2 - row.length / 2)) + row;
})
.join('\n');
2020-07-09 20:48:05 +07:00
};
2020-03-24 19:34:13 +07:00
const formatRow = (row, columns) => {
if (row.length <= columns) {
return [row];
}
// wrap!
let lines = [];
while (row.length) {
if (row.length <= columns) {
lines.push(row);
break;
}
let slice = row.substr(0, columns);
2020-07-09 20:48:05 +07:00
let prefix = slice.charAt(0) === '>' ? ' ' : '';
2020-03-24 19:34:13 +07:00
let match = slice.match(/(\s+)[^\s]*$/);
if (match && match.index) {
let line = row.substr(0, match.index);
2020-07-09 20:48:05 +07:00
row = prefix + row.substr(line.length + match[1].length);
2020-03-24 19:34:13 +07:00
lines.push(line);
} else {
lines.push(row);
break;
}
}
return lines;
};
const wrapText = text => {
let columns = Number(process.stdout.columns) || 80;
columns = Math.min(columns, 80) - 1;
2020-08-30 17:08:22 +07:00
return (
(formatCentered(title, columns) + '\n' + text)
.split('\n')
.flatMap(row => formatRow(row, columns))
.join('\n') +
'\n' +
formatCentered(footer, columns)
);
2020-03-24 19:34:13 +07:00
};
const banner = wrapText(text)
.replace(/^/gm, '\u001B[96m')
.replace(/$/gm, '\u001B[0m')
.replace(/(https:[^\s)]+)/g, '\u001B[94m $1 \u001B[96m');
console.log(canUseColor ? banner : banner.replace(/\u001B\[\d+m/g, ''));
2020-07-09 20:48:05 +07:00
if (canUseColor) {
process.stdout.write('\u001B[96m');
}
setInterval(() => {
process.stdout.write('.');
}, 500);
setTimeout(() => {
if (canUseColor) {
process.stdout.write('\u001B[0m\n');
}
process.exit(0);
}, secs * 1000 + 100);