Skip to content

Commit 776f2f8

Browse files
committed
[Draft] Add function for add dependency
1 parent 3616b5e commit 776f2f8

File tree

2 files changed

+55
-37
lines changed

2 files changed

+55
-37
lines changed

app.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
*/
55

66
declare function require(name: string);
7-
87
const commander = require('commander'),
98
fs = require('fs'),
109
path = require('path'),
1110
chalk = require('chalk'),
1211
walk = require('walk'),
1312
inquirer = require('inquirer'),
1413
xml2js = require('xml2js'),
15-
changeCase = require('change-case');
14+
changeCase = require('change-case'),
15+
gjs = require('gradlejs');
16+
1617

1718
let xmlParser = new xml2js.Parser();
1819
let xmlBuilder = new xml2js.Builder();
@@ -21,7 +22,7 @@ commander.arguments('<name>')
2122
.version('0.0.1')
2223
.option('-g, --generate [name]', 'component (e.g activity, fragment etc..)')
2324
.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')
2526
.option('--adb-reset', 'kill server adb (required environment variable for ADB_PATH)')
2627
.action((name: string) => {
2728

@@ -55,7 +56,6 @@ commander.arguments('<name>')
5556
if (commander.permission) {
5657
console.log(commander.permission);
5758
addPermissionToManifest(commander.permission, xml => {
58-
5959
try {
6060
fs.writeFileSync('./app/src/main/AndroidManifest.xml', xml);
6161
console.log(chalk.green(`Successful adding permission`));
@@ -66,6 +66,22 @@ if (commander.permission) {
6666
});
6767
}
6868

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+
6985
/**
7086
* @desc Add permission to Manfest
7187
*

package.json

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
{
2-
"name": "android-cli",
3-
"version": "1.0.0",
4-
"description": "Inspired to angular cli",
5-
"main": "bin/acli",
6-
"bin": {
7-
"acli": "./bin/acli"
8-
},
9-
"scripts": {
10-
"test": "echo \"Error: no test specified\" && exit 1"
11-
},
12-
"repository": {
13-
"type": "git",
14-
"url": "git+https://github.com/endlessdev/android-cli.git"
15-
},
16-
"files": [
17-
"bin/"
18-
],
19-
"author": "Jade Yeom <ysw0094@gmail.com>",
20-
"license": "MIT",
21-
"bugs": {
22-
"url": "https://github.com/endlessdev/android-cli/issues"
23-
},
24-
"homepage": "https://github.com/endlessdev/android-cli#readme",
25-
"dependencies": {
26-
"chalk": "^1.1.3",
27-
"change-case": "^3.0.1",
28-
"commander": "^2.9.0",
29-
"inquirer": "^3.0.6",
30-
"node": "0.0.0",
31-
"walk": "^2.3.9",
32-
"xml2js": "^0.4.17"
33-
}
34-
}
2+
"name": "android-cli",
3+
"version": "1.0.0",
4+
"description": "Inspired to angular cli",
5+
"main": "bin/acli",
6+
"bin": {
7+
"acli": "./bin/acli"
8+
},
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/endlessdev/android-cli.git"
15+
},
16+
"files": [
17+
"bin/"
18+
],
19+
"author": "Jade Yeom <ysw0094@gmail.com>",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/endlessdev/android-cli/issues"
23+
},
24+
"homepage": "https://github.com/endlessdev/android-cli#readme",
25+
"dependencies": {
26+
"chalk": "^1.1.3",
27+
"change-case": "^3.0.1",
28+
"commander": "^2.9.0",
29+
"gradle-to-js": "^0.2.5",
30+
"gradlejs": "^1.0.0",
31+
"inquirer": "^3.0.6",
32+
"node": "0.0.0",
33+
"walk": "^2.3.9",
34+
"xml2js": "^0.4.17"
35+
}
36+
}

0 commit comments

Comments
 (0)