-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve utils by splitting them & adding UT (#373)
- Loading branch information
Showing
16 changed files
with
260 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Import Node.js Dependencies | ||
import path from "node:path"; | ||
|
||
// Import Third-party Dependencies | ||
import filenamify from "filenamify"; | ||
|
||
/** | ||
* @function cleanReportName | ||
* @description clean the report name | ||
* @param {!string} name | ||
* @param {string} [extension=null] | ||
* @returns {string} | ||
*/ | ||
export function cleanReportName( | ||
name, | ||
extension = null | ||
) { | ||
const cleanName = filenamify(name); | ||
if (extension === null) { | ||
return cleanName; | ||
} | ||
|
||
return path.extname(cleanName) === extension ? | ||
cleanName : | ||
`${cleanName}${extension}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Import Node.js Dependencies | ||
import fs from "node:fs"; | ||
|
||
// Import Third-party Dependencies | ||
import git from "isomorphic-git"; | ||
import http from "isomorphic-git/http/node/index.js"; | ||
|
||
/** | ||
* @async | ||
* @function cloneGITRepository | ||
* @description clone a given repository from github | ||
* @param {!string} dir | ||
* @param {!string} url | ||
* | ||
* @returns {Promise<string>} | ||
*/ | ||
export async function cloneGITRepository( | ||
dir, | ||
url | ||
) { | ||
await git.clone({ | ||
fs, | ||
http, | ||
dir, | ||
url, | ||
token: process.env.GIT_TOKEN, | ||
singleBranch: true, | ||
oauth2format: "github" | ||
}); | ||
|
||
return dir; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @param {!string} organizationPrefix | ||
* @param {string[]} packages | ||
* | ||
* @returns {string[]} | ||
*/ | ||
export function formatNpmPackages( | ||
organizationPrefix, | ||
packages | ||
) { | ||
if (organizationPrefix === "") { | ||
return packages; | ||
} | ||
|
||
return packages.map((pkg) => { | ||
// in case the user has already added the organization prefix | ||
return pkg.startsWith(organizationPrefix) ? | ||
pkg : | ||
`${organizationPrefix}/${pkg}`; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./cleanReportName.js"; | ||
export * from "./cloneGITRepository.js"; | ||
export * from "./runInSpinner.js"; | ||
export * from "./formatNpmPackages.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Import Third-party Dependencies | ||
import { Spinner } from "@topcli/spinner"; | ||
import kleur from "kleur"; | ||
|
||
export async function runInSpinner( | ||
options, | ||
asyncHandler | ||
) { | ||
const { title, start = void 0 } = options; | ||
|
||
const spinner = new Spinner() | ||
.start(start, { withPrefix: `${kleur.gray().bold(title)} - ` }); | ||
|
||
try { | ||
const response = await asyncHandler(spinner); | ||
|
||
const elapsed = `${spinner.elapsedTime.toFixed(2)}ms`; | ||
spinner.succeed(kleur.white().bold(`successfully executed in ${kleur.green().bold(elapsed)}`)); | ||
|
||
return response; | ||
} | ||
catch (err) { | ||
spinner.failed(err.message); | ||
|
||
throw err; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.