Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/gradle.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'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';
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 = [
Expand Down Expand Up @@ -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) {
Expand Down