1- #!/usr/bin/env node
21const { spawn, exec } = require ( 'child_process' )
32const { address } = require ( 'ip' )
43const cc = require ( 'camelcase' )
5- const argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) )
4+ const { exitOnError } = require ( './common' )
65
7- const main = argv . _ [ 0 ]
8-
9- switch ( main ) {
10- case 'start' :
11- start ( )
12- break
13- case 'stop' :
14- stop ( )
15- break
16- default :
17- help ( )
18- break
6+ function parseDockerPs ( table ) {
7+ const rows = table
8+ . split ( '\n' )
9+ . map ( ( line ) =>
10+ line . split ( ' ' ) . map ( w => w . trim ( ) ) . filter ( w => w ) )
11+ . filter ( ( row ) => row && row . length )
12+ . map ( ( row ) =>
13+ row . map ( word => word . trim ( ) )
14+ )
15+ const names = rows . shift ( ) . map ( ( word ) => cc ( word ) )
16+ return rows . map ( ( values ) =>
17+ values . reduce ( ( res , val , ix ) => ( {
18+ ...res ,
19+ [ names [ ix ] ] : val
20+ } ) , { } ) )
1921}
2022
21- function start ( ) {
23+ const rxCliContainer = / c l i _ /
24+ function start ( { attach } ) {
2225 const command = `docker-compose`
2326 const args = [ 'up' ]
2427
25- if ( ! argv . attach ) { args . push ( '-d' ) }
28+ if ( ! attach ) { args . push ( '-d' ) }
2629
2730 const HOST_IP = address ( )
2831 const options = {
@@ -40,8 +43,6 @@ function start () {
4043 pcs . on ( 'error' , exitOnError )
4144}
4245
43- const rxCliContainer = / c l i _ /
44-
4546function stop ( ) {
4647 exec ( 'docker ps' , ( error , stdout , stderr ) => {
4748 exitOnError ( error )
@@ -55,7 +56,7 @@ function stop () {
5556 process . exit ( 0 )
5657 }
5758
58-
59+
5960 console . log ( cliContainers . map ( c => 'Stopping ' + c . names ) . join ( '\n' ) )
6061 const args = [ 'stop' ] . concat ( cliContainers . map ( c => c . containerId ) )
6162 const options = {
@@ -73,30 +74,7 @@ function stop () {
7374 } )
7475}
7576
76- function help ( ) {
77- console . log ( 'help' )
78- }
79-
80- function parseDockerPs ( table ) {
81- const rows = table
82- . split ( '\n' )
83- . map ( ( line ) =>
84- line . split ( ' ' ) . map ( w => w . trim ( ) ) . filter ( w => w ) )
85- . filter ( ( row ) => row && row . length )
86- . map ( ( row ) =>
87- row . map ( word => word . trim ( ) )
88- )
89- const names = rows . shift ( ) . map ( ( word ) => cc ( word ) )
90- return rows . map ( ( values ) =>
91- values . reduce ( ( res , val , ix ) => ( {
92- ...res ,
93- [ names [ ix ] ] : val
94- } ) , { } ) )
95- }
96-
97- function exitOnError ( error ) {
98- if ( error ) {
99- console . error ( error )
100- process . exit ( 1 )
101- }
77+ module . exports = {
78+ start,
79+ stop
10280}
0 commit comments