Compile and package Angular libraries in Angular Package Format (APF)
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
The command system provides a unified interface for executing build operations with standardized error handling and promise-based execution.
Common interface for all commands with generic type support.
/**
* Common call signature for a command
*/
interface Command<Arguments, Result> {
(args?: Arguments): Result | Promise<Result>;
}Executes any command and ensures the result is properly promisified.
/**
* Executes a Command and returns its promisified result
* @param command - The command to execute
* @param args - Arguments to pass to the command
* @returns Promise resolving to command result
*/
function execute<A, R>(command: Command<A, R>, args?: A): Promise<R>;Usage Example:
import { execute, build } from "ng-packagr";
const args = {
project: './ng-package.json',
watch: false
};
await execute(build, args);Command for performing one-off builds of Angular libraries.
/**
* Command running an "one-off" build
*/
const build: Command<CliArguments, void>;Usage Examples:
import { build } from "ng-packagr";
// Direct command usage
await build({
project: './ng-package.json',
watch: false
});
// With custom TypeScript config
await build({
project: './ng-package.json',
config: './tsconfig.lib.json'
});
// With watch mode
await build({
project: './ng-package.json',
watch: true,
poll: 1000
});Command for printing version information for ng-packagr and its dependencies.
/**
* Prints version information
*/
const version: Command<any, Promise<void>>;Usage Example:
import { version } from "ng-packagr";
// Print version information
await version();
// Outputs:
// ng-packagr: 20.2.0
// @angular/compiler: 20.2.0
// typescript: 5.9.2Defines the structure of arguments passed to CLI commands.
/**
* CLI arguments passed to `ng-packagr` executable and `build()` command
*/
interface CliArguments {
/** Path to the project file 'package.json', 'ng-package.json', or 'ng-package.js' */
project: string;
/** Whether or not ng-packagr will watch for file changes and perform an incremental build */
watch?: boolean;
/** Path to a tsconfig file */
config?: string;
/** Enable and define the file watching poll time period in milliseconds */
poll?: number;
}Commands automatically handle both synchronous and asynchronous errors:
import { execute, build } from "ng-packagr";
try {
await execute(build, { project: './ng-package.json' });
console.log('Build completed successfully');
} catch (error) {
console.error('Build failed:', error.message);
}You can create custom commands that follow the Command interface:
import { Command, execute } from "ng-packagr";
const customBuild: Command<{ projectPath: string }, void> = async (args) => {
console.log(`Building project at ${args.projectPath}`);
// Custom build logic here
};
// Execute custom command
await execute(customBuild, { projectPath: './my-project' });