-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev-smtp-cli.js
More file actions
66 lines (52 loc) · 1.09 KB
/
dev-smtp-cli.js
File metadata and controls
66 lines (52 loc) · 1.09 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
// tslint:disable:no-console
const argv = require( 'minimist' )(
process.argv.slice( 2 ),
{
boolean: 'version',
alias: {
port: 'p',
version: 'v',
},
default: {
port: 2525,
},
}
);
const packageData = require( './package.json' );
if ( argv.version )
{
console.log( packageData.version );
process.exit();
}
if ( argv._.length !== 1 )
{
console.log( `
${packageData.name} ${packageData.version}
Usage: dev-smtp [options] <path>
<path> - Path to directory to store emails (should exist).
Options:
-p, --port PORT Port to listen for (default is 2525).
-v, --version Current version.
` );
process.exit();
}
const path = argv._[0];
const Fs = require( 'fs' );
try
{
const stats = Fs.statSync( path );
if ( !stats.isDirectory() )
{
throw new Error( 'Path should be a directory.' );
}
}
catch ( exception )
{
console.error( exception.message );
process.exit( 1 );
}
const devSmtp = require( './index' );
devSmtp( path, argv.port );
console.log( 'Starting development SMTP server on port %s', argv.port );
console.log( 'Mail directory is "%s"', path );