Skip to content

Commit

Permalink
feat: added prettier
Browse files Browse the repository at this point in the history
- Added prettier
- Added prettier config
- Formated all the files
- Added prettier ignore
  • Loading branch information
pranshuchittora committed Nov 28, 2019
1 parent f38c5f0 commit 36bfe04
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
/dist
/build
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"trailingComma": "all"
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "autarky",
"version": "1.2.0",
"version": "1.2.1",
"description": "Liberating disk space from node_modules",
"author": "Pranshu Chittora <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -29,6 +29,7 @@
"scripts": {
"watch": "tsc -p tsconfig.dev.json --watch",
"build": "tsc -p tsconfig.prod.json",
"format": "prettier --write 'src/**/*.*'",
"test": "jest",
"test-watch": "jest --watchAll",
"prepublish": "yarn run build"
Expand All @@ -45,6 +46,7 @@
"@types/redux": "^3.6.0",
"@types/rimraf": "^2.0.3",
"jest": "^24.9.0",
"prettier": "^1.19.1",
"ts-jest": "^24.2.0",
"typescript": "^3.7.2"
},
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { showFiles } from "./lib/getLocation";
import {
promptMultiSelectDir,
promptAgeSelect,
promptDeleteConfirm
promptDeleteConfirm,
} from "./lib/prompter";
import { sortQueriesRefinedPath } from "./lib/utils";
import store from "./redux/index";
Expand All @@ -15,19 +15,19 @@ import store from "./redux/index";
await promptAgeSelect();
const QueriedPathList = showFiles(process.cwd(), {
filelist: [],
RefinedFileList: []
RefinedFileList: [],
});

if (QueriedPathList.RefinedFileList.length > 0) {
QueriedPathList.RefinedFileList = sortQueriesRefinedPath(
QueriedPathList.RefinedFileList
QueriedPathList.RefinedFileList,
);
await promptMultiSelectDir(QueriedPathList.RefinedFileList);
if (Array.isArray(store.getState().config.dir_list))
await promptDeleteConfirm();
} else {
await console.log(
chalk.bgCyan("Oops! Your node_modules are too young to be deleted 😉")
chalk.bgCyan("Oops! Your node_modules are too young to be deleted 😉"),
);
}
return;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/removeDir.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("Removes files given an array of path", () => {
const currentDirArr = fs.readdirSync("./");
expect(
currentDirArr.includes("single1.temp") &&
currentDirArr.includes("single2.temp")
currentDirArr.includes("single2.temp"),
).toBe(false);
});
});
12 changes: 6 additions & 6 deletions src/lib/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ describe("Tests for utils - sortQueriesRefinedPath", () => {
const UnsortedList = [
{
age: 200,
path: "file1"
path: "file1",
},
{
age: 100,
path: "file2"
}
path: "file2",
},
];
expect(sortQueriesRefinedPath(UnsortedList)).toStrictEqual([
{
age: 100,
path: "file2"
path: "file2",
},
{
age: 200,
path: "file1"
}
path: "file1",
},
]);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/getLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const showFiles = (dir, { filelist, RefinedFileList }) => {
if (validDiff(timeDiff)) {
let fileDetailsObj: IRefinedListItem = {
path: absPath,
age: fileMTime
age: fileMTime,
};
// console.log(fileDetailsObj);
RefinedFileList.push(fileDetailsObj);
Expand Down
22 changes: 11 additions & 11 deletions src/lib/prompter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export async function promptAgeSelect() {
{
type: "number",
name: "age",
message: "How old node_modules you wanna delete? (months)"
}
message: "How old node_modules you wanna delete? (months)",
},
]);

store.dispatch({ type: CHANGE_AGE_CAP, payload: { file_age: response.age } });
Expand All @@ -42,8 +42,8 @@ export async function promptMultiSelectDir(ListDir: Object[]) {
}

return true;
}
}
},
},
]);
let ListWithSize = [];
response.selectedDirs.forEach(elm => {
Expand All @@ -58,8 +58,8 @@ export async function promptMultiSelectDir(ListDir: Object[]) {
store.dispatch({
type: UPDATE_DIRS_LIST,
payload: {
dir_list: ListWithSize
}
dir_list: ListWithSize,
},
});
}

Expand All @@ -73,8 +73,8 @@ export async function promptDeleteConfirm() {
{
type: "confirm",
message: `Confirm deleteing ${count} directories ?`,
name: "confirmation"
}
name: "confirmation",
},
]);

if (response.confirmation === true) {
Expand All @@ -83,9 +83,9 @@ export async function promptDeleteConfirm() {
chalk.green(
`\nDeleted ${count} directories successfully 🎉\n
${chalk.black(
chalk.magentaBright(convertBytes(TOTAL_SIZE))
)} now free on your 💻\n\n`
)
chalk.magentaBright(convertBytes(TOTAL_SIZE)),
)} now free on your 💻\n\n`,
),
);
} else {
process.stdout.write(chalk.red(`\nBetter luck next time. 😔\n\n`));
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function promptListParser(List: Object[]): Object[] {
" " +
chalk.bgBlack(chalk.greenBright(TimeRelative(item.age) + " old")),
value: item.path,
size: FileSize.SIZE_Number
size: FileSize.SIZE_Number,
};
ParsedList.push(ItemObj);
});
Expand Down
6 changes: 3 additions & 3 deletions src/redux/__tests__/ConfigReducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("Tests the Config Reducer - CHANGE_AGE_CAP", () => {
const PREV_VALUE = store.getState().config.file_age;
store.dispatch({
type: CHANGE_AGE_CAP,
payload: { file_age: "SomeString" }
payload: { file_age: "SomeString" },
});
expect(store.getState().config.file_age).toBe(PREV_VALUE);
});
Expand All @@ -22,8 +22,8 @@ describe("Tests the Config Reducer - UPDATE_DIRS_LIST", () => {
store.dispatch({
type: UPDATE_DIRS_LIST,
payload: {
dir_list: FILE_ARR
}
dir_list: FILE_ARR,
},
});
expect(store.getState().config.dir_list).toBe(FILE_ARR);
});
Expand Down
2 changes: 1 addition & 1 deletion src/redux/reducers/ConfigReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const InitialState = { file_age: 0, dir_list: [] };

export const R_Config = (
state = InitialState,
action: { payload: Object | any; type: String }
action: { payload: Object | any; type: String },
) => {
let newState = { ...state };
const payload = action.payload;
Expand Down
2 changes: 1 addition & 1 deletion src/redux/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { combineReducers } from "redux";

import { R_Config } from "./ConfigReducer";
const RootReducer = combineReducers({
config: R_Config
config: R_Config,
});

export default RootReducer;
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2885,6 +2885,11 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=

prettier@^1.19.1:
version "1.19.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==

pretty-format@^24.9.0:
version "24.9.0"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-24.9.0.tgz#12fac31b37019a4eea3c11aa9a959eb7628aa7c9"
Expand Down

0 comments on commit 36bfe04

Please sign in to comment.