Skip to content

Commit

Permalink
chore: consistently use process.env.NODE_ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
sQVe committed Feb 18, 2020
1 parent 80ab124 commit a36d181
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 1 addition & 3 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const { NODE_ENV } = process.env;

module.exports = {
presets: [
[
"@babel/env",
{
corejs: 3,
loose: true,
modules: NODE_ENV === "test" ? "auto" : false,
modules: process.env.NODE_ENV === "test" ? "auto" : false,
targets: { node: 10 },
useBuiltIns: "usage",
},
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { formatFileStructure } from "./index/formatFileStructure";
import { version } from "../package.json";
import logger from "./shared/logger";

const { argv, env } = process;
const { argv } = process;
const defaults = {
options: {
help: false,
Expand Down Expand Up @@ -102,6 +102,7 @@ const getFilePaths = (paths: string[], detectRoots: boolean) => {
)
);
detectRoots = false;
console.log(paths);
} else {
paths.push(path.join(filePath, "/**/*.*"));
}
Expand Down Expand Up @@ -136,6 +137,6 @@ export const run = async (args: any[]) => {
await formatFileStructure(filesToRestructure, filesToEdit);
};

if (env.NODE_ENV !== "test") {
if (process.env.NODE_ENV !== "test") {
run(argv.slice(2, argv.length));
}
8 changes: 3 additions & 5 deletions src/shared/logger.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import chalk from "chalk";

const { NODE_ENV } = process.env;

export const error = (err: Error | string, code = 0) => {
if (NODE_ENV === "test") return;
if (process.env.NODE_ENV === "test") return;
if (err instanceof Error) {
console.error(err);
} else {
Expand All @@ -17,12 +15,12 @@ export const error = (err: Error | string, code = 0) => {
};

export const warn = (msg: string) => {
if (NODE_ENV === "test") return;
if (process.env.NODE_ENV === "test") return;
console.log(chalk`{yellow.bold WARN:} ${msg}`);
};

export const info = (msg: string) => {
if (NODE_ENV === "test") return;
if (process.env.NODE_ENV === "test") return;
console.log(chalk`{green.bold INFO:} ${msg}`);
};

Expand Down

0 comments on commit a36d181

Please sign in to comment.