mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-06 07:06:11 +00:00
Added CI workflow and local pre-commit hook for formatting and linting the newly added JS, iOS and Android code.
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
/*
|
|
* This script is a wrapper for gradle & spotlessApply to make
|
|
* it work properly with lint-staged.
|
|
*/
|
|
const { exit } = require('process');
|
|
const { execSync } = require('child_process');
|
|
|
|
const writeToConsoleOnError = (error, stdout) => {
|
|
if (error) {
|
|
console.log(error);
|
|
console.log(stdout);
|
|
return exit(1);
|
|
}
|
|
};
|
|
|
|
// spotless 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;
|
|
|
|
// reformat code
|
|
execSync(command, writeToConsoleOnError);
|
|
|
|
// file passed by lint-staged is now reformatted
|
|
if (fileName !== undefined) {
|
|
// so stage this file again after formatting
|
|
execSync(`git add ${fileName}`, writeToConsoleOnError);
|
|
} |