diff --git a/README-CN.md b/README-CN.md index f3602a4..69ce946 100644 --- a/README-CN.md +++ b/README-CN.md @@ -30,15 +30,13 @@ pnpm add cleants ## 使用方法 -> 你可以在执行命令目录下添加 `cleants.config.js` 文件来指定更多配置 - -CLI 使用方法 +### CLI 使用方法 ```shell npx cleants ``` -编程使用方法 +### 编程使用方法 ```javascript import { Cleants } from 'cleants' @@ -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` diff --git a/README.md b/README.md index 53522ae..c525fd2 100644 --- a/README.md +++ b/README.md @@ -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' @@ -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` diff --git a/src/bin.js b/src/bin.js index cc9624e..0ea7042 100755 --- a/src/bin.js +++ b/src/bin.js @@ -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' @@ -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?',