Giter Club home page Giter Club logo

ts-merger's Introduction

TS-Merger

Generic TypeScript Merger

build status

Usage

let tsm = require('@devonfw/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('@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

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:

  • Comments support

ts-merger's People

Contributors

jdiazgon avatar maybeec avatar mghcapgemini avatar mandybuchhold avatar jan-vcapgemini avatar dependabot[bot] avatar jambulud avatar sjimenez77 avatar themetalone avatar jorge-dacal avatar lillicao avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.