Skip to content

Commit

Permalink
add --format flag to run prettier --write after lampone finish
Browse files Browse the repository at this point in the history
  • Loading branch information
Apolofx committed Jul 24, 2021
1 parent 16c86d6 commit cf84596
Show file tree
Hide file tree
Showing 9 changed files with 413 additions and 149 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ build
dist
coverage
test_project
.env
20 changes: 7 additions & 13 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
#!/usr/bin/env node
import minimist, { ParsedArgs } from "minimist";
import figlet from "figlet";
import { clear } from "console";
import { SetPrettier } from "./lib/scripts";
import { initCLI } from "./lib/helpers";
import { Argv } from "types";
import inquirer from "inquirer";
import { debug } from "./lib/config";

clear();
//TODO put questions array on a separate file inquirer.ts

console.log(
figlet.textSync("Lampone", {
font: "Larry 3D",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true,
})
);
initCLI();

const args: Argv = minimist(process.argv.slice(2));
debug(args);
if (Object.keys(args).length < 2) {
inquirer
.prompt([
Expand Down Expand Up @@ -51,5 +44,6 @@ if (Object.keys(args).length < 2) {
}
});
} else {
SetPrettier(args["pre-commit"]);
// If there are non-default arguments present in argv run CLI
SetPrettier({ format: args["format"], precommit: args["precommit"] });
}
116 changes: 0 additions & 116 deletions lib/.env

This file was deleted.

20 changes: 19 additions & 1 deletion lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import fs from "fs";
import figlet from "figlet";
import { clear } from "console";
import { PackageJson } from "type-fest";
import chalk from "chalk";

interface CustomPackageJSON extends PackageJson {
"lint-staged": string;
Expand All @@ -16,4 +19,19 @@ function editPacakgeJson(
fs.writeFileSync("package.json", JSON.stringify(packageJSON));
}

export { editPacakgeJson };
function initCLI() {
clear();
console.log(
chalk.yellow(
figlet.textSync("Lampone", {
font: "Larry 3D",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true,
})
)
);
}

export { editPacakgeJson, initCLI };
7 changes: 3 additions & 4 deletions lib/scripts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { execSync } from "child_process";
import fs from "fs";

//---PRETTIER---//
function SetPrettier(precommit = false): void {
function SetPrettier({ precommit = false, format = false } = {}): void {
//setup precommit
if (precommit) {
execSync("npm install --save-dev husky lint-staged", { stdio: [0, 1, 2] });
Expand All @@ -11,7 +10,7 @@ function SetPrettier(precommit = false): void {
const huskyPrecommit = fs.existsSync(".husky/pre-commit")
? fs.readFileSync(".husky/pre-commit").toString()
: "";
!huskyPrecommit.includes("npx lint-staged") &&
if (!huskyPrecommit.includes("npx lint-staged"))
execSync("npx husky add .husky/pre-commit 'npx lint-staged'", {
stdio: [0, 1, 2],
});
Expand All @@ -35,7 +34,7 @@ function SetPrettier(precommit = false): void {
fs.writeFileSync(".prettierignore", ignored);

//format already written code
execSync("npx prettier --write .", { stdio: [0, 1, 2] });
if (format) execSync("npx prettier --write .", { stdio: [0, 1, 2] });
}

export { SetPrettier };
Loading

0 comments on commit cf84596

Please sign in to comment.