From a5d54d8f1b0ff37cdccf3204667e93aebfe83472 Mon Sep 17 00:00:00 2001 From: Jonas Damtoft Date: Mon, 1 Oct 2018 11:40:27 +0200 Subject: [PATCH] support other file names Gradle also allows for a build file called "build.gradle.kts". Add support for a list of file names to check for. --- lib/gradle.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/gradle.js b/lib/gradle.js index 9a6bffb..4e22a01 100644 --- a/lib/gradle.js +++ b/lib/gradle.js @@ -1,7 +1,7 @@ 'use babel'; 'use strict'; -import { existsSync, stat, watch } from 'fs'; +import { readdirSync, stat, watch } from 'fs'; import os from 'os'; import path from 'path'; import Promise from 'bluebird'; @@ -9,6 +9,7 @@ import { exec } from 'child_process'; import EventEmitter from 'events'; export function provideBuilder() { + const supportedFiles = ["build.gradle", "build.gradle.kts"]; const statAsync = Promise.promisify(stat); const execAsync = Promise.promisify(exec); const errorMatch = [ @@ -61,13 +62,14 @@ export function provideBuilder() { } isEligible() { - this.file = path.join(this.cwd, 'build.gradle'); - return existsSync(this.file); + const files = readdirSync(this.cwd); + this.file = files.find((f) => supportedFiles.includes(f)); + return this.file !== undefined } settings() { const refresh = new Date(); - this.fileWatcher = watch(this.file, () => { + this.fileWatcher = watch(path.join(this.cwd, this.file), () => { // Gradle touches the file when it's done, which will trigger this watch to // go off again. Require at least 3 second to pass before refreshing. if (new Date() - refresh > 3000) {