Skip to content

Commit

Permalink
perf: ⚡️ CLI interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Oct 17, 2024
1 parent 9033b14 commit 34a80b8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
17 changes: 13 additions & 4 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ pnpm add cleants

## 使用方法

> 你可以在执行命令目录下添加 `cleants.config.js` 文件来指定更多配置
CLI 使用方法
### CLI 使用方法

```shell
npx cleants
```

编程使用方法
### 编程使用方法

```javascript
import { Cleants } from 'cleants'
Expand All @@ -47,6 +45,17 @@ const cleaner = new Cleants(inputDir, outputDir, options)
await cleaner.run()
```

### 外部配置文件

> 你可以在执行命令目录下添加 `cleants.config.js` 文件来指定更多配置
```javascript
module.exports = {
inputDir: 'D:\\user\\test',
outputDir: 'C:\\Users\\user\\Downloads'
}
```

## API

### `Cleants`
Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ pnpm add cleants

## Usage

> You can add a `cleants.config.js` file in the command execution directory to specify more configurations
CLI Usage
### CLI Usage

```shell
npx cleants
```

Programmatic Usage
### Programmatic Usage

```javascript
import { Cleants } from 'cleants'
Expand All @@ -47,6 +45,17 @@ const cleaner = new Cleants(inputDir, outputDir, options)
await cleaner.run()
```

### External profile

> You can add a `cleants.config.js` file in the command execution directory to specify more configurations
```javascript
module.exports = {
inputDir: 'D:\\user\\test',
outputDir: 'C:\\Users\\user\\Downloads'
}
```

## API

### `Cleants`
Expand Down
31 changes: 15 additions & 16 deletions src/bin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import Cleants from './index.js'
import { capitalizeFirstLetter } from './helpers/index.js'
import { capitalizeFirstLetter, loadConfig } from './helpers/index.js'
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
import * as p from '@clack/prompts'
Expand All @@ -14,23 +14,22 @@ function runCommand() {

const { _: io, $0, ...cleantsOptions } = argv

let inputDir = io[0]
let outputDir = io[1]
const fileOptions = await loadConfig()

if (!inputDir) {
inputDir = await p.text({
message: 'Enter the TypeScript project directory to convert:',
validate: value => value.trim() === '' ? 'This field is required' : undefined,
})
}
let inputDir = io[0] || fileOptions.inputDir
let outputDir = io[1] || fileOptions.outputDir

if (!outputDir) {
outputDir = await p.text({
message: 'Enter the output project directory:',
validate: value => value.trim() === '' ? 'This field is required' : undefined,
initialValue: './',
})
}
inputDir = await p.text({
message: 'Enter the TypeScript project directory to convert:',
validate: value => value.trim() === '' ? 'This field is required' : undefined,
initialValue: inputDir,
})

outputDir = await p.text({
message: 'Enter the output project directory:',
validate: value => value.trim() === '' ? 'This field is required' : undefined,
initialValue: outputDir || './',
})

const replaceInternalImports = await p.confirm({
message: 'Automatically replace the suffix of inline imports?',
Expand Down

0 comments on commit 34a80b8

Please sign in to comment.