-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathformat-android.js
More file actions
27 lines (21 loc) · 823 Bytes
/
format-android.js
File metadata and controls
27 lines (21 loc) · 823 Bytes
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
/*
* This script is a wrapper for gradle & spotlessApply to make
* it work properly with lint-staged.
*/
const { exit } = require("process");
const { exec } = require("child_process");
// spotless ktlint formatting task in android/build.gradle
const spotlessApply = "./android/gradlew -p android spotlessApply";
// takes file as parameter passed by lint-staged (optional)
const fileName = process.argv[2];
// https://github.com/diffplug/spotless/blob/main/plugin-gradle/IDE_HOOK.md
// creates file argument without space between arguments
const fileArgument = `-PspotlessIdeHook=${fileName}`;
const command = fileName !== undefined ? `${spotlessApply} ${fileArgument}` : spotlessApply;
exec(command, (error, stdout) => {
if (error) {
console.log(error);
console.log(stdout);
return exit(1);
}
});