Skip to content

Commit

Permalink
cleanup with docs (#91)
Browse files Browse the repository at this point in the history
Co-authored-by: Joe Becher <[email protected]>
  • Loading branch information
eddiemoore and drazisil-codecov authored May 17, 2021
1 parent 8e332e1 commit 758ff37
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 9 deletions.
61 changes: 52 additions & 9 deletions src/helpers/files.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// @ts-check
const childProcess = require('child_process')
const fs = require('fs')
const path = require('path')
const glob = require('glob')

/**
*
* @param {string} projectRoot
* @returns Promise<string>
*/
async function getFileListing (projectRoot) {
return getAllFiles(projectRoot, projectRoot).join('')
}
Expand Down Expand Up @@ -144,20 +150,29 @@ function coverageFilePatterns () {
]
}

/**
*
* @param {string} projectRoot
* @param {string[]} coverageFilePatterns
* @returns string[]
*/
function getCoverageFiles (projectRoot, coverageFilePatterns) {
let files = []
for (let index = 0; index < coverageFilePatterns.length; index++) {
const pattern = coverageFilePatterns[index]
const newFiles = glob.sync(`**/${pattern}`, {
const files = coverageFilePatterns.flatMap(pattern => {
return glob.sync(`**/${pattern}`, {
cwd: projectRoot,
ignore: globBlacklist()
})

files = files.concat(newFiles)
}
})
return files
}

/**
*
* @param {string} projectRoot
* @param {string} file
* @param {string[]} manualBlacklist
* @returns boolean
*/
function isBlacklisted (projectRoot, file, manualBlacklist) {
const blacklist = manualBlacklist
return blacklist.includes(file)
Expand All @@ -179,6 +194,11 @@ function fetchGitRoot () {
}
}

/**
*
* @param {string} projectRoot
* @returns string[]
*/
function parseGitIgnore (projectRoot) {
const gitIgnorePath = path.join(projectRoot, '.gitignore')
let lines
Expand All @@ -197,9 +217,15 @@ function parseGitIgnore (projectRoot) {
return filteredLines
}

function getAllFiles (projectRoot, dirPath, arrayOfFiles) {
/**
*
* @param {string} projectRoot Root of the project
* @param {string} dirPath Directory to search in
* @param {string[]} arrayOfFiles
* @returns {string[]}
*/
function getAllFiles (projectRoot, dirPath, arrayOfFiles = []) {
const files = fs.readdirSync(dirPath)
arrayOfFiles = arrayOfFiles || []

files.forEach(function (file) {
if (
Expand All @@ -223,13 +249,24 @@ function getAllFiles (projectRoot, dirPath, arrayOfFiles) {
return arrayOfFiles
}

/**
*
* @param {string} filePath
* @returns string[]
*/
function readAllLines (filePath) {
const fileContents = fs.readFileSync(filePath)

const lines = fileContents.toString().split('\n') || []
return lines
}

/**
*
* @param {string} projectRoot
* @param {string} filePath
* @returns string
*/
function readCoverageFile (projectRoot, filePath) {
try {
return fs.readFileSync(getFilePath(projectRoot, filePath))
Expand All @@ -254,6 +291,12 @@ function endEnvironmentMarker () {
return '<<<<<< ENV\n'
}

/**
*
* @param {string} projectRoot
* @param {string} filePath
* @returns string
*/
function getFilePath (projectRoot, filePath) {
if (filePath.startsWith('./') ||
filePath.startsWith('/') ||
Expand Down
17 changes: 17 additions & 0 deletions src/helpers/web.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
const superagent = require('superagent')
const validateHelpers = require('./validate')

/**
*
* @param {Object} inputs
* @param {NodeJS.ProcessEnv} inputs.envs
* @param {Object} serviceParams
* @returns Object
*/
function populateBuildParams (inputs, serviceParams) {
const { args, envs } = inputs
serviceParams.name = args.name || envs.CODECOV_NAME || ''
Expand Down Expand Up @@ -68,12 +75,22 @@ async function uploadToCodecov (uploadURL, token, query, uploadFile, version) {
}
}

/**
*
* @param {string} str
* @returns string
*/
function camelToSnake (str) {
return str && str.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.map(s => s.toLowerCase())
.join('_')
}

/**
*
* @param {Object} queryParams
* @returns string
*/
function generateQuery (queryParams) {
const query = Object
.entries(queryParams)
Expand Down
13 changes: 13 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
// @ts-check
const zlib = require('zlib')
const { version } = require('../package.json')
const fileHelpers = require('./helpers/files')
const validateHelpers = require('./helpers/validate')
const webHelpers = require('./helpers/web')
const providers = require('./ci_providers')

/**
*
* @param {string} uploadHost
* @param {string} token
* @param {string} query
* @param {string} uploadFile
*/
function dryRun (uploadHost, token, query, uploadFile) {
console.log('==> Dumping upload file (no upload)')
console.log(
Expand Down Expand Up @@ -192,6 +200,11 @@ async function main (args) {
}
}

/**
*
* @param {string} version
* @returns string
*/
function generateHeader (version) {
return `
_____ _
Expand Down

0 comments on commit 758ff37

Please sign in to comment.