A comprehensive set of build tools and configurations for LoopBack 4 and TypeScript projects providing CLI commands for compilation, linting, testing, and coverage
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Prettier integration with automatic configuration discovery and file-first configuration precedence for consistent code formatting.
Runs Prettier with automatic configuration discovery and sensible defaults.
/**
* Prettier formatter function with configuration discovery
* @param argv - Command line arguments including files and options
* @param options - Execution options for dry run and process control
* @returns ChildProcess when executed, string when dry run
*/
function prettier(argv: string[], options?: RunOptions): ChildProcess | string;CLI Usage:
# Format files
lb-prettier "**/*.ts" "**/*.js"
# Check formatting without changes
lb-prettier --check "**/*.ts"
# List files that would be formatted
lb-prettier --list-different "**/*.ts"
# Write formatted files
lb-prettier --write "**/*.ts" "**/*.js"
# Format specific files
lb-prettier src/index.ts src/utils.tsProgrammatic Usage:
import { prettier } from "@loopback/build";
// Format TypeScript files
const child = prettier(["--write", "**/*.ts"]);
// Dry run to see command
const command = prettier(["--check", "src/"], { dryRun: true });
console.log(command); // Shows the Prettier command that would be executed
// Format with custom working directory
prettier(["--write", "src/"], { cwd: "/path/to/project" });Automatically discovers Prettier configuration files with file-first precedence.
Configuration Search Order:
--config, --no-config, or --find-config-path not provided).prettierrc in project root@loopback/build/config/.prettierrcConfiguration Precedence:
Uses --config-precedence prefer-file to prioritize project configuration files over CLI options.
Provides sensible defaults for LoopBack and TypeScript projects.
// @loopback/build/config/.prettierrc contents:
interface PrettierConfig {
bracketSpacing: false; // {foo} instead of { foo }
singleQuote: true; // 'string' instead of "string"
printWidth: 80; // Line wrap at 80 characters
trailingComma: "all"; // Trailing commas everywhere
arrowParens: "avoid"; // x => x instead of (x) => x
}Supports glob patterns and specific file targeting.
// Glob patterns for multiple files
// Specific file paths
// Supports all file types that Prettier handlesCommon File Patterns:
# TypeScript and JavaScript
lb-prettier "**/*.{ts,js}"
# All supported formats
lb-prettier "**/*.{ts,js,json,md,yml,yaml}"
# Specific directories
lb-prettier "src/**/*.ts" "test/**/*.ts"All Prettier command line options are supported and passed through.
interface PrettierOptions {
"--write": boolean; // Write formatted files to disk
"--check": boolean; // Check if files are formatted
"--list-different": boolean; // List files that differ from Prettier formatting
"--config": string; // Path to configuration file
"--no-config": boolean; // Do not look for configuration file
"--find-config-path": string; // Find and return path to configuration file
"--ignore-path": string; // Path to ignore file
"--no-ignore": boolean; // Do not look for ignore files
"--with-node-modules": boolean; // Process files in node_modules
"--parser": string; // Parser to use (auto-detected by default)
"--print-width": number; // Line wrap width
"--tab-width": number; // Tab width
"--use-tabs": boolean; // Use tabs instead of spaces
"--semi": boolean; // Print semicolons
"--single-quote": boolean; // Use single quotes
"--quote-props": string; // Quote object properties
"--jsx-single-quote": boolean; // Use single quotes in JSX
"--trailing-comma": string; // Trailing comma policy
"--bracket-spacing": boolean; // Print spaces inside object brackets
"--bracket-same-line": boolean; // Put closing bracket on same line
"--arrow-parens": string; // Arrow function parentheses policy
"--range-start": number; // Format from this character
"--range-end": number; // Format to this character
"--stdin-filepath": string; // File path for stdin input
"--end-of-line": string; // Line ending style
}Basic Formatting:
import { prettier } from "@loopback/build";
// Format all TypeScript files
prettier(["--write", "**/*.ts"], { dryRun: false });
// Check formatting without changes
prettier(["--check", "src/"], { dryRun: false });Package.json Integration:
{
"scripts": {
"prettier:cli": "lb-prettier \"**/*.ts\" \"**/*.js\"",
"prettier:check": "npm run prettier:cli -- --list-different",
"prettier:fix": "npm run prettier:cli -- --write",
"format": "npm run prettier:fix"
}
}Custom Configuration:
# Use custom config file
lb-prettier --config .prettierrc.custom.json --write "**/*.ts"
# Ignore configuration files
lb-prettier --no-config --write --single-quote "**/*.ts"
# Custom ignore file
lb-prettier --ignore-path .prettierignore.custom --write "**/*.ts"Works seamlessly with ESLint and other development tools.
ESLint Integration:
Editor Integration:
Prettier errors are properly handled and reported.
// Syntax errors in files are reported with file location
// Configuration errors show helpful error messages
// Process exits with non-zero code on formatting errors (when using --check)
// Invalid file patterns are reported clearly