diff --git a/ReplaceVersion.js b/ReplaceVersion.js index 35f00fe..165ad1b 100644 --- a/ReplaceVersion.js +++ b/ReplaceVersion.js @@ -1,77 +1,85 @@ module.exports = { - replace: function replaceVersion (body, dependency) { - const oldVersion = dependency.oldVersion - const newVersion = dependency.version + replace: function replaceVersion(body, dependency) { + const oldVersion = dependency.oldVersion; + const newVersion = dependency.version; - const replaceActions = [] + const replaceActions = []; - const regexVersionVariable = new RegExp(dependency.group + ":" + dependency.name + ":\\${?(\\w+)}?", "ig") + const regexVersionVariable = new RegExp(dependency.group + ":" + dependency.name + ":\\${?(\\w+)}?", "ig"); // 'de.kevcodez:pubg-api-wrapper:$myVar' // 'de.kevcodez:pubg-api-wrapper:${myVar}' - const versionWithVariableMatches = regexVersionVariable.exec(body) + const versionWithVariableMatches = regexVersionVariable.exec(body); if (versionWithVariableMatches && versionWithVariableMatches.length === 2) { - const variableName = versionWithVariableMatches[1] + const variableName = versionWithVariableMatches[1]; - const regexVariableDefinition = new RegExp(`(${variableName}(\\s+)?=(\\s+)?('|")${oldVersion}('|"))`, "ig") - const regexVariableDefinitionMatches = regexVariableDefinition.exec(body) + const regexVariableDefinition = new RegExp(`(${variableName}(\\s+)?=(\\s+)?('|")${oldVersion}('|"))`, "ig"); + const regexVariableDefinitionMatches = regexVariableDefinition.exec(body); if (regexVariableDefinitionMatches && regexVariableDefinitionMatches.length) { - regexVariableDefinitionMatches.filter(it => it.includes(dependency.oldVersion)).forEach(match => { - replaceActions.push({ - searchValue: match, - replaceValue: match.replace(dependency.oldVersion, dependency.version) - }) - }) + regexVariableDefinitionMatches + .filter((it) => it.includes(dependency.oldVersion)) + .forEach((match) => { + replaceActions.push({ + searchValue: match, + replaceValue: match.replace(dependency.oldVersion, dependency.version), + }); + }); } // val PUBG_API_WRAPPER by extra("0.8.1") - const regexKotlinValExtra = new RegExp(`${variableName}.+\(("|')${oldVersion}("|')\)`) - const regexKotlinValMatches = regexKotlinValExtra.exec(body) + const regexKotlinValExtra = new RegExp(`${variableName}.+\(("|')${oldVersion}("|')\)`); + const regexKotlinValMatches = regexKotlinValExtra.exec(body); if (regexKotlinValMatches && regexKotlinValMatches.length) { - regexKotlinValMatches.filter(it => it.includes(dependency.oldVersion)).forEach(match => { - replaceActions.push({ - searchValue: match, - replaceValue: match.replace(dependency.oldVersion, dependency.version) - }) - }) + regexKotlinValMatches + .filter((it) => it.includes(dependency.oldVersion)) + .forEach((match) => { + replaceActions.push({ + searchValue: match, + replaceValue: match.replace(dependency.oldVersion, dependency.version), + }); + }); } } // compile 'de.kevcodez:pubg-api-wrapper:1.0.0' - const regexVersionInline = new RegExp(`${dependency.group}:${dependency.name}:${dependency.oldVersion}`, "g") + const regexVersionInline = new RegExp(`${dependency.group}:${dependency.name}:${dependency.oldVersion}`, "g"); if (regexVersionInline.exec(body)) { replaceActions.push({ searchValue: regexVersionInline, - replaceValue: `${dependency.group}:${dependency.name}:${dependency.version}` - }) + replaceValue: `${dependency.group}:${dependency.name}:${dependency.version}`, + }); } // id 'com.github.ben-manes.versions' version "0.21.0" // id("com.github.ben-manes.versions") version "0.22.0" - const regexPluginVersionWithPrefix = new RegExp(`${dependency.group}("|')\\)?(\\s+)?version(\\s+)?("|')${oldVersion}("|')`) - const regexVersionWithPrefixMatches = regexPluginVersionWithPrefix.exec(body) + const regexPluginVersionWithPrefix = new RegExp(`${dependency.group}("|')\\)?(\\s+)?version(\\s+)?("|')${oldVersion}("|')`); + const regexVersionWithPrefixMatches = regexPluginVersionWithPrefix.exec(body); if (regexVersionWithPrefixMatches && regexVersionWithPrefixMatches.length) { - regexVersionWithPrefixMatches.filter(it => it.includes(oldVersion)).forEach(match => { - replaceActions.push({ - searchValue: match, - replaceValue: match.replace(oldVersion, newVersion) - }) - }) + regexVersionWithPrefixMatches + .filter((it) => it.includes(oldVersion)) + .forEach((match) => { + replaceActions.push({ + searchValue: match, + replaceValue: match.replace(oldVersion, newVersion), + }); + }); } // compile group: 'de.kevcodez.pubg', name: 'pubg-api-wrapper', version: '0.8.1' - const regexDependencyWithVersionPrefix = new RegExp(`${dependency.name}('|"),(\\s+)?version:(\\s+)('|")${dependency.oldVersion}('|")`) - const regexDependencyWithVersionPrefixMatches = regexDependencyWithVersionPrefix.exec(body) + const regexDependencyWithVersionPrefix = new RegExp(`${dependency.name}('|"),(\\s+)?version:(\\s+)('|")${dependency.oldVersion}('|")`); + const regexDependencyWithVersionPrefixMatches = regexDependencyWithVersionPrefix.exec(body); if (regexDependencyWithVersionPrefixMatches && regexDependencyWithVersionPrefixMatches.length) { - regexDependencyWithVersionPrefixMatches.filter(it => it.includes(oldVersion)).forEach(match => { - replaceActions.push({ - searchValue: match, - replaceValue: match.replace(oldVersion, newVersion) - }) - }) + regexDependencyWithVersionPrefixMatches + .filter((it) => it.includes(oldVersion)) + .forEach((match) => { + replaceActions.push({ + searchValue: match, + replaceValue: match.replace(oldVersion, newVersion), + }); + }); } - return replaceActions - } -} + return replaceActions; + }, +}; diff --git a/args.js b/args.js index 2300b9e..c588977 100644 --- a/args.js +++ b/args.js @@ -1,39 +1,41 @@ -const argv = require('yargs') - .option('resolution', { - alias: 'r', - describe: 'Controls the dependency resolution strategy.\nSupported options:\n* release: selects the latest release\n* milestone: select the latest version being either a milestone or a release (default)\n* integration: selects the latest revision of the dependency module (such as SNAPSHOT)', - type: 'string', - nargs: 1, - demand: false - }) - .option('semver', { - alias: 's', - describe: 'Which semantic version diffs to include (https://semver.org). Flag can be used multiple times.\nSupported options:\n* major: Include upgrades with a major version change\n* minor: Include upgrades with a minor version change\n* patch: Include upgrades with a patch version change', - type: 'string', - array: true, - nargs: 1, - demand: false - }) - .option('external-file', { - alias: 'e', - describe: 'Points to a file where dependencies have been declared, e.g. gradle/dependencies.gradle. Option can be used multiple times.', - type: 'array', - nargs: 1, - demand: false - }) - .option('debug', { - alias: 'd', - describe: 'Prints debugging information, such as commands executed and current status.', - type: 'boolean', - demand: false, - default: false - }) - .option('no-color', { - describe: 'Disables color output', - nargs: 1, - demand: false - }).argv +const argv = require("yargs") + .option("resolution", { + alias: "r", + describe: + "Controls the dependency resolution strategy.\nSupported options:\n* release: selects the latest release\n* milestone: select the latest version being either a milestone or a release (default)\n* integration: selects the latest revision of the dependency module (such as SNAPSHOT)", + type: "string", + nargs: 1, + demand: false, + }) + .option("semver", { + alias: "s", + describe: + "Which semantic version diffs to include (https://semver.org). Flag can be used multiple times.\nSupported options:\n* major: Include upgrades with a major version change\n* minor: Include upgrades with a minor version change\n* patch: Include upgrades with a patch version change", + type: "string", + array: true, + nargs: 1, + demand: false, + }) + .option("external-file", { + alias: "e", + describe: "Points to a file where dependencies have been declared, e.g. gradle/dependencies.gradle. Option can be used multiple times.", + type: "array", + nargs: 1, + demand: false, + }) + .option("debug", { + alias: "d", + describe: "Prints debugging information, such as commands executed and current status.", + type: "boolean", + demand: false, + default: false, + }) + .option("no-color", { + describe: "Disables color output", + nargs: 1, + demand: false, + }).argv; module.exports = { - argv -} \ No newline at end of file + argv, +}; diff --git a/buildFiles.js b/buildFiles.js index 091cabd..4e29032 100644 --- a/buildFiles.js +++ b/buildFiles.js @@ -1,58 +1,55 @@ -const { - existsSync -} = require('fs'); -const { - resolve -} = require('path') -const fs = require('fs') +const { existsSync } = require("fs"); +const { resolve } = require("path"); +const fs = require("fs"); function getBuildFiles(externalFiles, debugLog) { - let buildFiles = []; - exports.buildFiles = buildFiles; - if (externalFiles && externalFiles.length) { - externalFiles.forEach(externalFile => { - if (!existsSync(externalFile)) { - console.log(`Unable to find ${externalFile} file.`.bgRed); - return; - } else { - buildFiles.push(externalFile); - } - }); - } + let buildFiles = []; + exports.buildFiles = buildFiles; + if (externalFiles && externalFiles.length) { + externalFiles.forEach((externalFile) => { + if (!existsSync(externalFile)) { + console.log(`Unable to find ${externalFile} file.`.bgRed); + return; + } else { + buildFiles.push(externalFile); + } + }); + } - const directoryToSearchIn = process.cwd() + const directoryToSearchIn = process.cwd(); - debugLog(`Recursively looking for build files in directory ${directoryToSearchIn}`) + debugLog(`Recursively looking for build files in directory ${directoryToSearchIn}`); - const allRecursiveFiles = getAllBuildFiles(directoryToSearchIn) + const allRecursiveFiles = getAllBuildFiles(directoryToSearchIn); - const recursiveBuildFiles = allRecursiveFiles.filter(it => it.endsWith('build.gradle') || it.endsWith('build.gradle.kts')) + const recursiveBuildFiles = allRecursiveFiles.filter((it) => it.endsWith("build.gradle") || it.endsWith("build.gradle.kts")); - buildFiles.push(...recursiveBuildFiles) + buildFiles.push(...recursiveBuildFiles); - return buildFiles + return buildFiles; } const getAllBuildFiles = function (dirPath, arrayOfFiles) { - const files = fs.readdirSync(dirPath, { - withFileTypes: true + const files = fs + .readdirSync(dirPath, { + withFileTypes: true, }) - .filter(it => !it.name.startsWith('.') && !it.name.startsWith('node_modules')) + .filter((it) => !it.name.startsWith(".") && !it.name.startsWith("node_modules")); - arrayOfFiles = arrayOfFiles || [] + arrayOfFiles = arrayOfFiles || []; - files.forEach((dirent) => { - const resolvedFile = resolve(dirPath, dirent.name); - if (dirent.isDirectory()) { - arrayOfFiles = getAllBuildFiles(resolvedFile, arrayOfFiles) - } else { - arrayOfFiles.push(resolvedFile) - } - }) + files.forEach((dirent) => { + const resolvedFile = resolve(dirPath, dirent.name); + if (dirent.isDirectory()) { + arrayOfFiles = getAllBuildFiles(resolvedFile, arrayOfFiles); + } else { + arrayOfFiles.push(resolvedFile); + } + }); - return arrayOfFiles -} + return arrayOfFiles; +}; module.exports = { - getBuildFiles -} \ No newline at end of file + getBuildFiles, +}; diff --git a/gradleCommand.js b/gradleCommand.js index a6d6b35..a5d79e9 100644 --- a/gradleCommand.js +++ b/gradleCommand.js @@ -1,49 +1,45 @@ -const { - spawnSync -} = require('child_process'); -const { - existsSync -} = require('fs') +const { spawnSync } = require("child_process"); +const { existsSync } = require("fs"); function determineGradleCommand(debugLog) { - let gradleCommand = null - let gradleWrapper = false - - debugLog('Determining gradle command') - - try { - const isWindows = process.platform === 'win32' - debugLog('isWindows: ' + isWindows) - const gradleWrapperFile = isWindows ? 'gradlew.bat' : 'gradlew' - - debugLog(`Checking if wrapper file ${gradleWrapperFile} exists`) - if (existsSync(gradleWrapperFile)) { - debugLog('Wrapper file exists') - gradleCommand = (isWindows ? '' : './') + gradleWrapperFile - gradleWrapper = true - } else { - debugLog('Wrapper file not found') - } - } catch (err) { - debugLog('Error trying to determine gradle command.') - debugLog(err) + let gradleCommand = null; + let gradleWrapper = false; + + debugLog("Determining gradle command"); + + try { + const isWindows = process.platform === "win32"; + debugLog("isWindows: " + isWindows); + const gradleWrapperFile = isWindows ? "gradlew.bat" : "gradlew"; + + debugLog(`Checking if wrapper file ${gradleWrapperFile} exists`); + if (existsSync(gradleWrapperFile)) { + debugLog("Wrapper file exists"); + gradleCommand = (isWindows ? "" : "./") + gradleWrapperFile; + gradleWrapper = true; + } else { + debugLog("Wrapper file not found"); } - - if (!gradleCommand) { - const gradleVersion = spawnSync('gradle', ['--version']) - if (gradleVersion.status === 0) { - gradleCommand = 'gradle' - } + } catch (err) { + debugLog("Error trying to determine gradle command."); + debugLog(err); + } + + if (!gradleCommand) { + const gradleVersion = spawnSync("gradle", ["--version"]); + if (gradleVersion.status === 0) { + gradleCommand = "gradle"; } + } - debugLog(`Determined gradle command: ${gradleCommand}, wrapper: ${gradleWrapper}`) + debugLog(`Determined gradle command: ${gradleCommand}, wrapper: ${gradleWrapper}`); - return { - gradleCommand, - gradleWrapper - } + return { + gradleCommand, + gradleWrapper, + }; } module.exports = { - determineGradleCommand -} \ No newline at end of file + determineGradleCommand, +}; diff --git a/io.js b/io.js index 73e160d..eeb7858 100644 --- a/io.js +++ b/io.js @@ -1,12 +1,9 @@ -const { - readdirSync, - lstatSync -} = require('fs'); +const { readdirSync, lstatSync } = require("fs"); -const isDirectory = source => lstatSync(source).isDirectory(); +const isDirectory = (source) => lstatSync(source).isDirectory(); -const subDirectories = path => readdirSync(path).filter(isDirectory); +const subDirectories = (path) => readdirSync(path).filter(isDirectory); module.exports = { - subDirectories -} \ No newline at end of file + subDirectories, +};