|
| 1 | +/* Copy/anspired from https://github.com/nodemailer/nodemailer */ |
| 2 | +/* eslint no-control-regex:0 */ |
| 3 | +'use strict'; |
| 4 | + |
| 5 | +const packageData = require('./package.json'); |
| 6 | +const isEnabled = value => !!value && value !== '0' && value !== 'false'; |
| 7 | +const canUseColor = isEnabled(process.env.npm_config_color); |
| 8 | + |
| 9 | +const title = `=== OpenFlow ${packageData.version} ===`; |
| 10 | +const text = ` |
| 11 | +Thank you for using OpenFlow! |
| 12 | +> OpenFlow source ( https://github.com/open-rpa/openflow/ ) |
| 13 | +> Community chat ( https://rocket.openiap.io/ ) |
| 14 | +> Documentation ( https://docs.openiap.io/ ) |
| 15 | +> commercial support ( https://openrpa.dk/ ) enterprise version also avaible |
| 16 | +`; |
| 17 | + |
| 18 | +const secs = 4; |
| 19 | + |
| 20 | +const formatCentered = (row, columns) => { |
| 21 | + if (columns <= row.length) { |
| 22 | + return row; |
| 23 | + } |
| 24 | + |
| 25 | + return ' '.repeat(Math.round(columns / 2 - row.length / 2)) + row; |
| 26 | +}; |
| 27 | + |
| 28 | +const formatRow = (row, columns) => { |
| 29 | + if (row.length <= columns) { |
| 30 | + return [row]; |
| 31 | + } |
| 32 | + // wrap! |
| 33 | + let lines = []; |
| 34 | + while (row.length) { |
| 35 | + if (row.length <= columns) { |
| 36 | + lines.push(row); |
| 37 | + break; |
| 38 | + } |
| 39 | + let slice = row.substr(0, columns); |
| 40 | + |
| 41 | + let prefix = slice.charAt(0) === '>' ? ' ' : ''; |
| 42 | + |
| 43 | + let match = slice.match(/(\s+)[^\s]*$/); |
| 44 | + if (match && match.index) { |
| 45 | + let line = row.substr(0, match.index); |
| 46 | + row = prefix + row.substr(line.length + match[1].length); |
| 47 | + lines.push(line); |
| 48 | + } else { |
| 49 | + lines.push(row); |
| 50 | + break; |
| 51 | + } |
| 52 | + } |
| 53 | + return lines; |
| 54 | +}; |
| 55 | + |
| 56 | + |
| 57 | +const concat = (x, y) => x.concat(y) |
| 58 | + |
| 59 | +const flatMap = (f, xs) => xs.map(f).reduce(concat, []) |
| 60 | + |
| 61 | +if (Array.prototype.flatMap === undefined) { |
| 62 | + Array.prototype.flatMap = function (f) { |
| 63 | + return flatMap(f, this) |
| 64 | + } |
| 65 | +} |
| 66 | +const wrapText = text => { |
| 67 | + let columns = Number(process.stdout.columns) || 80; |
| 68 | + columns = Math.min(columns, 80) - 1; |
| 69 | + |
| 70 | + return (formatCentered(title, columns) + '\n' + text) |
| 71 | + .split('\n') |
| 72 | + .flatMap(row => formatRow(row, columns)) |
| 73 | + .join('\n'); |
| 74 | + try { |
| 75 | + } catch (error) { |
| 76 | + } |
| 77 | +}; |
| 78 | + |
| 79 | +const banner = wrapText(text) |
| 80 | + .replace(/^/gm, '\u001B[96m') |
| 81 | + .replace(/$/gm, '\u001B[0m') |
| 82 | + .replace(/(https:[^\s)]+)/g, '\u001B[94m $1 \u001B[96m'); |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +console.log(canUseColor ? banner : banner.replace(/\u001B\[\d+m/g, '')); |
| 87 | +if (canUseColor) { |
| 88 | + process.stdout.write('\u001B[96m'); |
| 89 | +} |
| 90 | + |
| 91 | +setInterval(() => { |
| 92 | + process.stdout.write('.'); |
| 93 | +}, 500); |
| 94 | + |
| 95 | +setTimeout(() => { |
| 96 | + if (canUseColor) { |
| 97 | + process.stdout.write('\u001B[0m\n'); |
| 98 | + } |
| 99 | + process.exit(0); |
| 100 | +}, secs * 1000 + 100); |
0 commit comments