4
4
*/
5
5
6
6
declare function require ( name : string ) ;
7
-
8
7
const commander = require ( 'commander' ) ,
9
8
fs = require ( 'fs' ) ,
10
9
path = require ( 'path' ) ,
11
10
chalk = require ( 'chalk' ) ,
12
11
walk = require ( 'walk' ) ,
13
12
inquirer = require ( 'inquirer' ) ,
14
13
xml2js = require ( 'xml2js' ) ,
15
- changeCase = require ( 'change-case' ) ;
14
+ changeCase = require ( 'change-case' ) ,
15
+ gjs = require ( 'gradlejs' ) ;
16
+
16
17
17
18
let xmlParser = new xml2js . Parser ( ) ;
18
19
let xmlBuilder = new xml2js . Builder ( ) ;
@@ -21,7 +22,7 @@ commander.arguments('<name>')
21
22
. version ( '0.0.1' )
22
23
. option ( '-g, --generate [name]' , 'component (e.g activity, fragment etc..)' )
23
24
. option ( '-p, --permission <permission>' , 'add uses-permission to manifest file(e.g INTERNET)' )
24
- . option ( '-d, --dependency' , 'add ' )
25
+ . option ( '-d, --dependency <dependency> ' , 'add dependency to build.gradle and sync gradle ' )
25
26
. option ( '--adb-reset' , 'kill server adb (required environment variable for ADB_PATH)' )
26
27
. action ( ( name : string ) => {
27
28
@@ -55,7 +56,6 @@ commander.arguments('<name>')
55
56
if ( commander . permission ) {
56
57
console . log ( commander . permission ) ;
57
58
addPermissionToManifest ( commander . permission , xml => {
58
-
59
59
try {
60
60
fs . writeFileSync ( './app/src/main/AndroidManifest.xml' , xml ) ;
61
61
console . log ( chalk . green ( `Successful adding permission` ) ) ;
@@ -66,6 +66,22 @@ if (commander.permission) {
66
66
} ) ;
67
67
}
68
68
69
+ if ( commander . dependency ) {
70
+ console . log ( commander . dependency ) ;
71
+
72
+ let gradlePath : string = "./app/build.gradle" ;
73
+
74
+ gjs . parseFile ( gradlePath ) . then ( ( representation ) => {
75
+ representation . dependencies . compile . push ( `\'${ commander . dependency } \'` )
76
+ console . log ( representation . dependencies . compile ) ;
77
+ fs . writeFile ( gradlePath , gjs . makeGradleText ( representation ) , function ( e , r ) {
78
+ console . log ( e , r ) ;
79
+ } ) ;
80
+ } ) ;
81
+
82
+
83
+ }
84
+
69
85
/**
70
86
* @desc Add permission to Manfest
71
87
*
0 commit comments