cleants
v0.0.3
Published
🧹 Convert TypeScript to a cleaner JavaScript project
Downloads
95
Maintainers
Readme
Cleants
🧹 Convert TypeScript to a cleaner JavaScript project 中文文档
Features
- 🖖 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
Install
npm install cleants
# or
yarn add cleants
# or
pnpm add cleants
Usage
CLI Usage
npx cleants
Programmatic Usage
import { Cleants } from 'cleants'
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
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: []
}
API
Cleants
The main class used to convert a TypeScript project into a cleaner JavaScript project.
Constructor
constructor(inputDir: string, outputDir: string, options?: CleantsOptions)
Parameters
inputDir: string
- The input directory pathoutputDir: string
- The output directory pathoptions?: CleantsOptions
- Optional configuration options
CleantsOptions
progressCallback?: Function
Progress callback function.
Default: undefined
compilerOptions?: Object
TypeScript compiler options.
Default: {}
ignoredCopyPatterns?: Array<string | RegExp | Function>
Patterns to ignore during the copy phase. Default:
[
'.git',
'dist',
/\.d\.ts$/,
file => file.includes('node_modules'),
file => file.endsWith('.log')
]
ignoredConversionPatterns?: Array<string | RegExp | Function>
Patterns to ignore during the conversion phase. Default:
[
'vendor',
/\.min\.js$/,
file => file.includes('legacy')
]
getOutputDir?: Function
Function to get the output directory.
Default: inputDir => `${path.basename(inputDir)}.cleants`
removeDependencies?: Array<string>
Dependencies to remove.
Default: ['typescript', 'vue-tsc', '@types/node']
replaceInternalImports?: boolean
Whether to replace internal imports.
Default: true
plugins?: Array<Plugin>
List of plugins to use.
Default: [basePlugin, vuePlugin]
Notice
actualOutputDir
is set topath.join(outputDir, options.getOutputDir(inputDir))
- If no
options.plugins
are provided, the default is[basePlugin, vuePlugin]
Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
Support
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:
Contributors
Thanks for all their contributions!
📚 Keywords
typescript
javascript
converter
vue
cli
License
This project is licensed under the MIT License.