2020-01-06 12:03:18 +01:00
|
|
|
import * as util from 'util'
|
|
|
|
import * as path from 'path'
|
|
|
|
import * as fs from 'fs'
|
2020-01-05 12:55:59 +01:00
|
|
|
|
2020-01-06 12:03:18 +01:00
|
|
|
const readdir = util.promisify(fs.readdir)
|
2020-01-05 12:55:59 +01:00
|
|
|
|
2020-01-06 12:03:18 +01:00
|
|
|
export async function findWrapperJars(baseDir: string): Promise<string[]> {
|
|
|
|
const files = await recursivelyListFiles(baseDir)
|
|
|
|
return files
|
|
|
|
.filter(file => file.endsWith('gradle-wrapper.jar'))
|
|
|
|
.map(wrapperJar => path.relative(baseDir, wrapperJar))
|
|
|
|
}
|
2020-01-05 12:55:59 +01:00
|
|
|
|
2020-01-06 12:03:18 +01:00
|
|
|
async function recursivelyListFiles(baseDir: string): Promise<string[]> {
|
|
|
|
const childrenNames = await readdir(baseDir)
|
|
|
|
const childrenPaths = await Promise.all(
|
|
|
|
childrenNames.map(async childName => {
|
|
|
|
const childPath = path.resolve(baseDir, childName)
|
|
|
|
return fs.lstatSync(childPath).isDirectory()
|
|
|
|
? recursivelyListFiles(childPath)
|
|
|
|
: new Promise(resolve => resolve([childPath]))
|
2020-01-06 11:37:12 +01:00
|
|
|
})
|
2020-01-06 12:03:18 +01:00
|
|
|
)
|
|
|
|
return Array.prototype.concat(...childrenPaths)
|
2020-01-05 12:55:59 +01:00
|
|
|
}
|