Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
refactor: add individual log function
Browse files Browse the repository at this point in the history
  • Loading branch information
Lotus authored and Lotus committed Jul 14, 2021
1 parent 3b7bbea commit 2737e89
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/utils/interfaces/package-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface PackageJson {
name: string;
version: string;
}
14 changes: 14 additions & 0 deletions src/utils/log.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import chalk from "chalk";
import log from "./log";

test("Log function", () => {
const results: any = [];
jest
.spyOn(process.stdout, "write")
.mockImplementation(val => results.push(String(val).trim()));

log("Hello");
log(chalk.red("Red"));

expect(results).toEqual(["Hello", chalk.red("Red")]);
});
7 changes: 7 additions & 0 deletions src/utils/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { format } from "util";

const log = (text: string): void => {
process.stdout.write(`${format(text)}\n`);
};

export default log;
16 changes: 5 additions & 11 deletions src/utils/path-to-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import chalk from "chalk";
import jsonfile from "jsonfile";
import path from "path";
import { format } from "util";

interface PackageJson {
name: string;
version: string;
}
import log from "./log";

import { PackageJson } from "./interfaces/package-json";

const pathToPackage = (dirArray: string[]): PackageJson[] => {
const packageJsons = dirArray
Expand All @@ -20,12 +18,8 @@ const pathToPackage = (dirArray: string[]): PackageJson[] => {
);
return data;
} catch {
process.stdout.write(
`${format(
chalk.red(
`${packageJsonPath} may have been removed. Not publishing.`
)
)}\n`
log(
chalk.red(`${packageJsonPath} may have been removed. Not publishing.`)
);
}
})
Expand Down

0 comments on commit 2737e89

Please sign in to comment.