-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
88 lines (72 loc) · 2.08 KB
/
main.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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env node
const lib = require('./src');
const args = require('minimist')( process.argv.slice( 2 ) );
const isInstalledGlobally = require('is-installed-globally');
/**
* get the status of the app and current working directory
*
* @param {boolean} verbose extra verbose logging
* @param {string} directory directory to act upon
*/
async function status( verbose, directory ) {
const { action, exitCode } = await lib.status( verbose, directory );
if( action === 'exit' ) process.exit( exitCode );
}
/**
* install the pre-commit hook
*
* @param {boolean} verbose extra verbose logging
* @param {string} directory directory to act upon
*/
async function install( verbose, directory, auto ) {
if( isInstalledGlobally && auto ) process.exit(0);
const { action, exitCode } = await lib.install( verbose, directory );
if( action === 'exit' ) process.exit( exitCode );
}
/**
* uninstall the pre-commit hook
*
* @param {boolean} verbose extra verbose logging
* @param {string} directory directory to act upon
*/
async function uninstall( verbose, directory, auto ) {
if( isInstalledGlobally && auto ) process.exit(0);
const { action, exitCode } = await lib.uninstall( verbose, directory );
if( action === 'exit' ) process.exit( exitCode );
}
/**
* gets the help documentation
*
* @returns {string}
*/
async function help() {
return require('./manual')();
}
/**
*
*/
if ( require.main === module ) {
( async() => {
const verbose = !!args['verbose'] || false;
const directory = !!args['directory'] ? args['directory'] : process.cwd();
const auto = !!args['auto'] || false;
if( !!args['help'] || ( !args['install'] && !args['uninstall'] && !args['status']) ) {
console.log( await help() );
} else
if( !!args['status'] ) {
await status( verbose, directory );
} else
if( !!args['install'] ) {
await install( verbose, directory, auto );
} else
if( !!args['uninstall'] ) {
await uninstall( verbose, directory, auto );
}
})();
} else {
module.exports = {
install,
uninstall,
help,
}
}