https://github.com/alexandre-chapelle/unimod
Automate conversion between CommonJS, ES Modules, and TypeScript. Syntax transformations, type conversions, file renaming, automated backups.
https://github.com/alexandre-chapelle/unimod
cjs cjs-modules converter es5 es6 mjs typescript
Last synced: 10 months ago
JSON representation
Automate conversion between CommonJS, ES Modules, and TypeScript. Syntax transformations, type conversions, file renaming, automated backups.
- Host: GitHub
- URL: https://github.com/alexandre-chapelle/unimod
- Owner: Alexandre-Chapelle
- License: mit
- Created: 2024-12-14T18:38:40.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-26T11:21:13.000Z (over 1 year ago)
- Last Synced: 2025-04-06T07:23:22.107Z (about 1 year ago)
- Topics: cjs, cjs-modules, converter, es5, es6, mjs, typescript
- Language: TypeScript
- Homepage:
- Size: 44.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Unimod
## Automate Conversion Between CommonJS, ES Modules, and TypeScript
Unimod is a versatile tool designed to automate the conversion between CommonJS (CJS), ES Modules (ESM), and TypeScript (TS). It supports all possible combinations of these formats and includes additional functionalities such as logging, backups, dependency type installations, and automatic interface creation for classes.
### Features
- **Module Conversion:** Convert between CJS, ESM, and TS effortlessly.
- **Syntax Transformations:** Automatically handle syntax changes during conversion.
- **Type Conversions:** Convert JavaScript to TypeScript with type annotations.
- **File Renaming:** Rename files appropriately based on the target module system.
- **Automated Backups:** Create backups of original files before modification.
- **Logging:** Enable detailed logging of the conversion process.
- **Dependency Type Installation:** Automatically locate `package.json` and install types for all dependencies when converting to TypeScript.
- **Interface Creation:** Generate interfaces for classes when converting to TypeScript.
### Installation
You can run Unimod using one of the following methods:
#### Using NPM
```
npm run dev
```
#### or
```
npm run start
```
#### Executable
For Windows users, an executable file is available in the releases section. Download the `.exe` file and run it directly.
#### Building from Source
If the executable does not work for you, or if you wish to compile Unimod for another platform, follow the instructions below:
Visit the [Bun Bundler Executables Documentation](https://bun.sh/docs/bundler/executables) for detailed steps on compiling the tool for your desired environment.
### Usage
When you run Unimod, it will prompt you with a series of questions to guide the conversion process:
1. **Target Files Location** ```Are target files in this directory? (Y/n)```
- If `No`, it will ask: ```Please provide the directory path:```
2. **Select Files to Convert**: ```Which files do you want to convert?```
```
◯ JS
◯ MJS
◯ TS
```
3. **TypeScript Specific Prompt** *(Only if TS is selected)*: ```Do you want me to automatically install types for your project (from package.json)? (y/N)```
4. **Choose Transformation Format**: ```Which format do you want to transform to? (Use arrow keys)```
```
JS
MJS
TS
```
5. **Backup Option**: ```Do you want to create backups for each modified file? (y/N)```
6. **Enable Logging**: ```Do you want to enable logging? (Y/n)```
### Examples
- Simple CJS to TS transformation
#### Before

#### After

### Roadmap
- **✅ Current Features:**
- [x] Conversion between CJS, ESM, and TS
- [x] Syntax and type transformations
- [x] File renaming
- [x] Automated backups and logging
- **🚧 Upcoming Features:**
- [ ] Feature to automatically create interfaces for classes when converted to TS
- [ ] Feature to add automatic typing for the whole project when converted to TS
- [ ] Publish as an NPM package
- [ ] Suggest changes to file/class/function/var... naming conventions based on the selected option
- [ ] Feature to automatically add public / private modifiers to class properties / methods based on their name.
### Contributing
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.
Contributing guidelines