2.0.0 • Published 7 years ago

@oasp/ts-merger v2.0.0

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
7 years ago

TS-Merger

Generic TypeScript Merger

build status build status

Usage

let tsm = require('@oasp/ts-merger');
let mergedCode: string = tsm.merge(baseContents, pathContents, 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

let tsm = require('@oasp/ts-merger');
let mergedCode: string = tsm.merge(baseContents, pathContents, patchOverrides);

Features

The merger allows merging of this node kinds:

  • ImportDeclaration
  • ClassDeclaration
  • 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

import a from 'b';
import f from 'g';

class Example1 {
    private propertyFromBase: string;

    oneMethod() {
        let variable = 'base';
    }
}

Patch file

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)

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)

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:

  • InterfaceDeclaration
2.0.0

7 years ago

2.0.0-rc.3

7 years ago

2.0.0-rc.2

7 years ago

2.0.0-rc.1

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago