From a167b5c61cdeb2baca0c642820ff01f16519ae5d Mon Sep 17 00:00:00 2001 From: Christopher Powroznik Date: Wed, 23 Oct 2024 18:51:10 -0700 Subject: [PATCH] fix: remove concurrency option, and add readme --- README.md | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- src/cli.ts | 6 ---- src/index.ts | 1 - 4 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b28ceb9 --- /dev/null +++ b/README.md @@ -0,0 +1,82 @@ +# Relative to Alias Resolver + +## Overview + +The **Relative to Alias Resolver** is a tool designed to convert a TypeScript project from using relative imports to alias imports. This can help improve the readability and maintainability of your codebase by using more descriptive import paths. + +## Features + +- Converts relative imports to alias imports based on your `tsconfig.json` configuration. +- Supports both CommonJS and ES Module formats. +- Provides a CLI for easy integration into your build process. +- Includes options for dry runs and concurrency control. + +## Installation + +To install the package cli, use npm: + +```bash +npm install -g relative-to-alias-resolver +``` + +if you intend to use the library in your project, you can install it locally: + +```bash +npm install relative-to-alias-resolver +``` + +## Usage + +### CLI + +The package provides a command-line interface to perform the conversion. You can use it as follows: + +```bash +relative-to-alias-resolver --project --tsconfig +``` + +#### Options + +- `-p, --project `: The path to the project to generate alias imports for. Defaults to the current directory. +- `-t, --tsconfig `: The path to the `tsconfig.json` file to use for the project. Defaults to `./tsconfig.json`. +- `-d, --dry-run`: Run the command in dry run mode. Defaults to `true`. +- `-i, --ignore `: A comma-separated list of regex patterns for paths to ignore. Defaults to `["node_modules"]`. +- `-c, --concurrency `: The number of promises to allow at once when editing the project. Defaults to `5`. + +#### Example + +```bash +relative-to-alias-resolver --project ./src --tsconfig ./tsconfig.json +``` + +### Library + +The library can be used to convert relative imports to alias imports in a TypeScript project. + +```typescript +import { resolveRelativeToAlias } from "relative-to-alias-resolver"; + +resolveRelativeToAlias({ + projectPath: "./src", + tsconfigPath: "./tsconfig.json", + dryRun: true, + ignore: ["node_modules"], +}); +``` + +## Configuration + +The tool relies on the `tsconfig.json` file to determine the base URL and paths for aliasing. Ensure your `tsconfig.json` is correctly configured with the `baseUrl` and `paths` properties. + +Example `tsconfig.json`: + +```json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@/*": ["src/*"] + } + } +} +``` \ No newline at end of file diff --git a/package.json b/package.json index c6f4629..7b3149f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "relative-to-alias-resolver", "version": "1.0.1", - "description": "converts a typescript from from relative imports to alias imports", + "description": "Converts a typescript project from relative imports to alias imports.", "main": "dist/cjs/index.cjs", "module": "dist/esm/index.js", "type": "module", diff --git a/src/cli.ts b/src/cli.ts index b776afe..d56a1a8 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -22,12 +22,6 @@ program (value) => value.split(","), ["node_modules"] ) - .option( - "-c, --concurrency ", - "The number of promises to allow at once when editing the project.", - (value) => parseInt(value), - 5 - ) .action(main); program.parse(process.argv); diff --git a/src/index.ts b/src/index.ts index 6c68e18..117af62 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,6 @@ export interface Options { tsconfig: string; dryRun: boolean; ignoreDirectories: string[]; - concurrency: number; } export default async function main(options: Options) {