https://github.com/devonfw/ts-merger
https://github.com/devonfw/ts-merger
typescript
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/devonfw/ts-merger
- Owner: devonfw
- License: apache-2.0
- Created: 2017-05-11T09:53:24.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-02-28T22:36:43.000Z (about 3 years ago)
- Last Synced: 2025-03-28T02:04:39.549Z (about 1 year ago)
- Topics: typescript
- Language: TypeScript
- Size: 852 KB
- Stars: 7
- Watchers: 18
- Forks: 14
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# TS-Merger
Generic TypeScript Merger
[](https://travis-ci.com/github/devonfw/ts-merger)
## Usage
```javascript
let tsm = require('@devonfw/ts-merger');
let mergedCode: string = tsm.merge(baseContents, patchContents, patchOverrides);
```
Being:
- baseContents: contents of the base in a string
- patchContents: contents of the patch in a string
- patchOverrides(**true**/**false**): Being false, base will have priority in case of conflicts. With true, patch will have priority.
### Example
```javascript
let tsm = require('@devonfw/ts-merger');
let mergedCode: string = tsm.merge(baseContents, pathContents, patchOverrides);
```
## Features
The merger allows merging of this node kinds:
- ImportDeclaration
- ExportDeclaration
- ClassDeclaration
- InterfaceDeclaration
- Decorator
- FunctionDeclaration
- MethodDeclaration
- Parameter
- BodyMethod
- PropertyAssignment
- PropertyDeclaration
- Constructor
- ArrayLiteralExpression
- ObjectLiteralExpression
- CallExpression
- VariableAssignment
This version allows merging of TypeScript files that follow this structure:
- Array of imports
- Array of functions
- Array of variables
- Array of classes
##Examples
**Base file**
```javascript
import a from 'b';
import f from 'g';
class Example1 {
private propertyFromBase: string;
oneMethod() {
let variable = 'base';
}
}
```
**Patch file**
```javascript
import c from 'd';
import h from 'g';
class Example1 {
private propertyFromPatch: number;
oneMethod() {
let variable = 'patch';
}
anotherMethod(){}
}
class AnotherClass {}
```
**Resultant merged code (patchOverrides=false)**
```javascript
import a from 'b';
import c from 'd';
import { f, h } from 'g';
class Example1 {
private propertyFromBase: string;
private propertyFromPatch: number;
oneMethod() {
let variable = 'base';
}
anotherMethod(){}
}
class AnotherClass {}
```
**Resulting merged code (patchOverrides=true)**
```javascript
import a from 'b';
import c from 'd';
import { f, h } from 'g';
class Example1 {
private propertyFromBase: string;
private propertyFromPatch: number;
oneMethod() {
let variable = 'patch';
}
anotherMethod(){}
}
class AnotherClass {}
```
## Future version
Next releases will include merge support for:
- Comments support