public mergeJsonInFolders()

in GatewayPluginExample/Ux/gulps/gulp-merge-json-in-folders/json-merge.ts [35:65]


    public mergeJsonInFolders(targetFolderPathRoot: string, sourceFoldersPathRoot: string[]): any[] {
        const outputFiles: any[] = []; 
        const targetFilesContentMap = {};
        let targetFiles = this.getFilePaths(targetFolderPathRoot);
        targetFiles.forEach((targetFile) => {
            let relativePath = targetFile.substring(targetFolderPathRoot.length + 1, targetFile.length);
            targetFilesContentMap[relativePath] = this.readJSON(targetFile);

        });

        sourceFoldersPathRoot.forEach((sourceFolderPathRoot) => {
            let sourceFiles = this.getFilePaths(sourceFolderPathRoot);
            sourceFiles.forEach((sourceFile) => {
                let relativePath = sourceFile.substring(sourceFolderPathRoot.length + 1, sourceFile.length);
                let sourceJson = this.readJSON(sourceFile);

                this.mergeJsons(relativePath, sourceJson, targetFilesContentMap);
            });
        });

        Object.keys(targetFilesContentMap).forEach(path => {
            let jsonFile = new Vinyl({
                    cwd: './',
                    path: path,
                    contents: new Buffer(JSON.stringify(targetFilesContentMap[path]))
            });
            outputFiles.push(jsonFile);
        });

        return outputFiles;
    }