-
Notifications
You must be signed in to change notification settings - Fork 0
/
component-cli.ts
executable file
·71 lines (62 loc) · 1.61 KB
/
component-cli.ts
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
#!/usr/bin/env node
import { version } from './package.json';
import addComponent from './methods/add';
import renameComponent from './methods/rename';
import removeComponent from './methods/remove';
const shouldPrintVersion = (
( process.argv.indexOf( '--version' ) !== -1 )
|| ( process.argv.indexOf( '-v' ) !== -1 )
);
if ( shouldPrintVersion ) {
console.log( `v${version}` );
process.exit( 0 );
}
const verboseMode = ( process.argv.indexOf( '--verbose' ) !== -1 );
const action = process.argv.slice( 2 )[0];
const componentName = process.argv.slice( 3 )[0];
switch ( action ) {
case 'add':
case 'create':
case 'new':
addComponent( { componentName, verboseMode } )
.then( ( successMessage ) => {
console.log( successMessage );
process.exit( 0 );
} )
.catch( ( error: string ) => {
console.error( error );
process.exit( 1 );
} );
break;
case 'rename':
case 'rn':
case 'mv':
case 'move':
renameComponent( verboseMode )
.then( ( successMessage ) => {
console.log( successMessage );
process.exit( 0 );
} )
.catch( ( error ) => {
console.error( error );
process.exit( 1 );
} );
break;
case 'delete':
case 'del':
case 'destroy':
case 'remove':
case 'rm':
removeComponent( verboseMode )
.then( ( successMessage ) => {
console.log( successMessage );
process.exit( 0 );
} )
.catch( ( error ) => {
console.error( error );
process.exit( 1 );
} );
break;
default:
console.error( `Unrecognized action: ${action}` );
}