All files / src ObfuscatorCompositor.ts

100% Statements 14/14
100% Branches 0/0
100% Functions 2/2
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 611x             1x   1x 1x 1x   1x                                         66x 66x   66x       66x   66x       66x 66x                 66x      
import { interfaces, Kernel, KernelModule } from 'inversify';
 
import { IJavaScriptObfuscator } from "./interfaces/IJavaScriptObfuscator";
import { IObfuscator } from "./interfaces/IObfuscator";
import { IObfuscatorOptions } from "./interfaces/IObfuscatorOptions";
import { IOptions } from "./interfaces/IOptions";
 
import { KernelTypes } from "./enums/KernelTypes";
 
import { JavaScriptObfuscatorInternal } from "./JavaScriptObfuscatorInternal";
import { Obfuscator } from "./Obfuscator";
import { Options } from "./options/Options";
 
export class ObfuscatorCompositor {
    /**
     * @type {interfaces.Kernel}
     */
    private kernel: interfaces.Kernel;
 
    /**
     * @type {IObfuscatorOptions}
     */
    private obfuscatorOptions: IObfuscatorOptions;
 
    /**
     * @type {string}
     */
    private sourceCode: string;
 
    /**
     * @param sourceCode
     * @param obfuscatorOptions
     */
    constructor (sourceCode: string, obfuscatorOptions: IObfuscatorOptions) {
        this.sourceCode = sourceCode;
        this.obfuscatorOptions = obfuscatorOptions;
 
        this.kernel = new Kernel();
    }
 
    public composite (): void {
        this.kernel.load(
            new KernelModule((bind: interfaces.Bind) => {
                bind<IJavaScriptObfuscator>(KernelTypes.IJavaScriptObfuscator)
                    .toConstantValue(
                        new JavaScriptObfuscatorInternal(this.sourceCode, this.obfuscatorOptions)
                    );
                bind<IObfuscator>(KernelTypes.IObfuscator).to(Obfuscator);
                bind<IOptions>(KernelTypes.IOptions).to(Options);
            })
        );
    }
 
    /**
     * @returns {interfaces.Kernel}
     */
    public getKernel (): interfaces.Kernel {
        return this.kernel;
    }
}