Skip to content

Commit

Permalink
fix: adjusts in the print warning and error msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaz committed Aug 8, 2024
1 parent 158cf6e commit d17e583
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ yargs(hideBin(process.argv))
.fail((msg, err, yargs) => {
if (msg) {
if (msg.includes("Unknown argument")) {
// Get the command name
const command = process.argv[2];

if (command === "run") {
Expand Down
1 change: 1 addition & 0 deletions src/help/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const helpForm = async (): Promise<void> => {
["new project", "new", "Generate a new project"],
["info", "i", "Provides project information"],
["resources", "r", "Displays cli commands and resources"],
["scripts", "scripts", "Run scripts list or specific scripts"],
["help", "h", "Show command help"],
[
"service",
Expand Down
22 changes: 9 additions & 13 deletions src/scripts/form.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import chalk from "chalk";
import { printError } from "../utils/cli-ui";
import path from "path";
import { ExecSyncOptions, execSync } from "child_process";
import fs from "fs";
import inquirer from "inquirer";
import { execSync, ExecSyncOptions } from "child_process";
import path from "path";
import { printError, printWarning } from "../utils/cli-ui";

const cwd = process.cwd();
const packageJsonPath = path.join(cwd, "package.json");
Expand All @@ -16,18 +15,15 @@ function readPackageJson(): PackageJson {
try {
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
} catch (e) {
printError(
`Error reading package.json: ${chalk.bold(chalk.white(packageJsonPath))}\n${e}`,
"scripts-command",
);
printError(`Error reading package.json`, "scripts-command");
process.exit(1);
}
}

function listScripts(packageJson: PackageJson): Record<string, string> {
const scripts = packageJson.scripts || {};
if (Object.keys(scripts).length === 0) {
console.log(chalk.bold.yellow("No scripts found in package.json."));
printWarning("No scripts found in package.json", "scripts-command");
process.exit(0);
}
return scripts;
Expand Down Expand Up @@ -76,8 +72,8 @@ function executeScripts(

execSync(command, options);
} catch (e) {
printError(
`Failed to run: ${chalk.bold(chalk.white(script))}\n${e}`,
printWarning(
`Command ${script} cancelled or failed - ${e}`,
"scripts-command",
);
}
Expand Down Expand Up @@ -105,8 +101,8 @@ export const scriptsForm = async (scriptArgs: string[] = []): Promise<void> => {

if (!runner) {
printError(
"No package manager found!",
"Please ensure you have npm, yarn, or pnpm installed.",
"No package manager found! Please ensure you have npm, yarn, or pnpm installed.",
"scripts-command",
);
process.exit(1);
}
Expand Down

0 comments on commit d17e583

Please sign in to comment.