11#!/usr/bin/env node
22
3- const figlet = require ( 'figlet' )
4- const { program } = require ( "commander" ) ;
5- console . log ( figlet . textSync ( 'Microservices-Suite' ) )
6- const {
7- addDepsAtWorkspace,
8- installDepsAtWorkspace,
9- changeDirectory,
10- isMatch,
11- logSuccess,
12- logError,
13- logInfoMessage,
14- pathExists,
15- generateDirectoryPath,
16- checkDocker,
17- getPlatform,
18- startDocker
19- } = require ( "./scripts" ) ;
3+ const actionHandlers = require ( './scripts' )
4+ const { Command } = require ( 'commander' ) ;
5+ const program = new Command ( )
206
21- const [ , , command , ...args ] = process . argv ;
22- console . log ( { command, args } )
23- switch ( command ) {
24- case add :
25- addDepsAtWorkspace ( args )
26- case add :
27- installDepsAtWorkspace ( args )
28- case add :
29- logInfoMessage ( args )
30- case add :
31- logError ( args )
32- case add :
33- logSuccess ( args )
34- case add :
35- changeDirectory ( args )
36- case add :
37- isMatch ( args )
38- case add :
39- generateDirectoryPath ( args )
40- case add :
41- checkDocker ( args )
42- case add :
43- getPlatform ( args )
44- case add :
45- pathExists ( args )
46- case add :
47- startDocker ( args )
48- }
7+ program
8+ . command ( 'err' )
9+ . description ( 'Prints Error message to screen' )
10+ . argument ( '<error>' , 'Error to display to console' )
11+ . action ( ( error ) => {
12+ actionHandlers . logErrorMessage ( { error } ) ;
13+ } )
14+
15+ program . command ( 'info' )
16+ . description ( 'Prints informational message to screen' )
17+ . argument ( '<message>' , 'Info to display to console' )
18+ . action ( ( message ) => {
19+ actionHandlers . logInfoMessage ( { message } )
20+ } )
21+
22+ program . command ( 'succ' )
23+ . description ( 'Prints success message to screen' )
24+ . argument ( '<message>' , 'Message to display to console' )
25+ . action ( ( message ) => {
26+ actionHandlers . logSuccessMessage ( { message } ) ;
27+ } ) ;
28+
29+ program
30+ . command ( 'docker:check' )
31+ . alias ( 'do' )
32+ . description ( 'Checks if docker is running' )
33+ . action ( async ( ) => await actionHandlers . checkDocker ( ) ) ;
34+ program
35+ . command ( 'chdir' )
36+ . description ( 'The function cds into given directory_path' )
37+ . argument ( '<directory_path>' , 'The path to the file' )
38+ . action ( ( directory_path ) => actionHandlers . changeDirectory ( { directory_path } ) ) ;
39+ program
40+ . command ( 'host' )
41+ . description ( 'Gets the host platorm Os the app is running on' )
42+ . action ( ( ) => actionHandlers . getPlatform ) ;
43+ program
44+ . command ( 'add' )
45+ . description ( 'Adds dependencies at given workspace and updates package.json' )
46+ . requiredOption ( '-n, --workspace-name <name>' , 'Name of the workspace where to add dependencies' )
47+ . option ( '-d, --workspace-directory <directory>' , 'Directory where to look for the workspace. Defaults to "microservices"' , 'microservices' )
48+ . argument ( '<packages...>' , 'Space-separated list of packages to add' )
49+ . action ( async ( packages , options ) => await actionHandlers . addDepsAtWorkspace ( { packages, options } ) ) ;
50+ program
51+ . command ( 'install' )
52+ . description ( 'Installs dependencies at given workspace. If not specified workspace defaults to "microservices"' )
53+ . requiredOption ( '-n, --workspace-name <name>' , 'Name of the workspace where to install dependencies' )
54+ . option ( '-d, --workspace-directory <directory>' , 'Name of the workspace where to install dependencies' , 'microservices' )
55+ . argument ( '<packages...>' , 'Space-separated list of packages to install' )
56+ . action ( async ( packages , options ) => await actionHandlers . installDepsAtWorkspace ( { packages, options } ) ) ;
57+ program
58+ . command ( 'equal' )
59+ . description ( 'Compares if 2 values match' )
60+ . argument ( '<a>' , 'first value' )
61+ . argument ( '<b>' , 'second value' )
62+ . action ( ( a , b ) => actionHandlers . isMatch ( { a, b } ) ) ;
63+ program
64+ . command ( 'path:exist' )
65+ . description ( 'Checks if the file exists at the given path' )
66+ . argument ( '<file_path>' , 'The path to the file to check' )
67+ . action ( ( file_path ) => actionHandlers . pathExists ( { file_path } ) ) ;
68+
69+ program
70+ . command ( 'docker:start' )
71+ . description ( 'Starts the docker daemon' )
72+ . action ( async ( ) => await actionHandlers . startDocker ( ) ) ;
73+ program
74+ . command ( 'path:gen' )
75+ . description ( 'Dynamically generate directory path given workspace_name' )
76+ . argument ( '<workspace-name>' , 'Name of the workspace to cd into' )
77+ . option ( '-d, --workspace-directory <directory>' , 'Directory where to look for the workspace. Defaults to "microservices"' , 'microservices' )
78+ . action ( ( workspace_name , options ) => actionHandlers . generateDirectoryPath ( { workspace_name, options } ) ) ;
79+ program . parse ( process . argv ) ;
80+ module . exports = program
0 commit comments