🧹 Convert TypeScript to a cleaner JavaScript project 中文文档
- 🖖 Vue-First: Priority support for Vue project conversion
- 🔌 Extensible: Plugin system for supporting various file types
- ⚡ Lightning Fast: Utilizes ts.transpileModule for rapid transpilation
- 🖥️ User-Friendly CLI: Quick conversion with a single command
- 🧩 Seamless Integration: Import as an npm package for easy project integration
- 🛠️ Customizable: Fine-tune the conversion process with flexible options
- 📊 Progress Tracking: Real-time feedback on conversion status
- 🎯 Selective Conversion: Ignore specific patterns during copy and conversion
- 📦 Dependency Management: Option to remove specified dependencies
- 🔄 Import Optimization: Capability to replace internal imports
npm install cleants
# or
yarn add cleants
# or
pnpm add cleants
npx cleants
import { Cleants } from 'cleants'
const cleaner = new Cleants(inputDir, outputDir, options)
await cleaner.run()
You can add a
cleants.config.js
file in the command execution directory to specify more configurations
module.exports = {
inputDir: 'D:\\Projects\\demo',
outputDir: 'C:\\Users\\viarotel\\Downloads',
compilerOptions: {},
ignoredCopyPatterns: [
'.git',
'dist',
/\.d\.ts$/,
file => file.includes('node_modules'),
file => file.endsWith('.log')
],
ignoredConversionPatterns: [
'vendor',
/\.min\.js$/,
file => file.includes('legacy')
],
getOutputDir: inputDir => `${path.basename(inputDir)}.cleants`,
removeDependencies: ['typescript', 'vue-tsc', '@types/node'],
replaceInternalImports: true,
plugins: []
}
The main class used to convert a TypeScript project into a cleaner JavaScript project.
constructor(inputDir: string, outputDir: string, options?: CleantsOptions)
inputDir: string
- The input directory pathoutputDir: string
- The output directory pathoptions?: CleantsOptions
- Optional configuration options
Progress callback function.
Default: undefined
TypeScript compiler options.
Default: {}
Patterns to ignore during the copy phase. Default:
[
'.git',
'dist',
/\.d\.ts$/,
file => file.includes('node_modules'),
file => file.endsWith('.log')
]
Patterns to ignore during the conversion phase. Default:
[
'vendor',
/\.min\.js$/,
file => file.includes('legacy')
]
Function to get the output directory.
Default: inputDir => `${path.basename(inputDir)}.cleants`
Dependencies to remove.
Default: ['typescript', 'vue-tsc', '@types/node']
Whether to replace internal imports.
Default: true
List of plugins to use.
Default: [basePlugin, vuePlugin]
actualOutputDir
is set topath.join(outputDir, options.getOutputDir(inputDir))
- If no
options.plugins
are provided, the default is[basePlugin, vuePlugin]
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
If you find this project helpful for your work or study, please consider starring the project or buying me a cup of coffee through the links below:
Thanks for all their contributions!
typescript
javascript
converter
vue
cli
This project is licensed under the MIT License.