src/shared/parser/folderConverters.js
// Returns both a list of ProjectObjectExport objects, and a ProjectCommon
Returns both a list of ProjectObjectExport objects, and a ProjectCommon
Returns both a list of ProjectObjectExport objects and a ProjectCommon
function convertCommonFolder(folder){
    var exports = [];
    var projectCommon = new ProjectCommon();
    var commentsCommon = new ProjectCommon();
    for(var i = 0; i < folder.folders.length; i++){
        var subFolder = folder.folders[i];
        var prop = subFolder.name;
        if(commonMappings[prop]){
            prop = commonMappings[prop];
        }
        var flat = !!commonFlatFileMappings[prop];
        var objects = [];
        var comments = [];
        for(var j = 0; j < subFolder.files.length; j++){
            var file = subFolder.files[j];
            var fileName = file.name;
            var fileData = file.data;
            var fileComments = file.comments;
            if(flat){
                var id = guid();
                var projObj = new ProjectObjectFlat();
                projObj.data = fileData;
                projObj.id = id;
                projObj.name = fileName;
                projObj.fileName = fileName;
                comments.push({id, data: fileComments});
                var projObjExport = new ProjectObjectExport();
                projObjExport.id = id;
                projObjExport.relativePath = "common/" + prop + "/" + fileName;
                exports.push(projObjExport);
                objects.push(projObj);
            } else{
                var fileDataKeys = Object.keys(fileData);
                for(var k = 0; k < fileDataKeys.length; k++){
                    var key = fileDataKeys[k];
                    var obj = fileData[key];
                    var id = guid();
                    var comment = fileComments[key];
                    comments.push({id, data: comment});
                    var projObj = new ProjectObject();
                    projObj.name = key;
                    projObj.data = obj;
                    projObj.id = id;
                    var projObjExport = new ProjectObjectExport();
                    projObjExport.id = id;
                    projObjExport.relativePath = "common/" + prop + "/" + fileName;
                    exports.push(projObjExport);
                    objects.push(projObj);
                }
            }
        }
        var objectsObj = objects.reduce((prev, cur) => Object.assign(prev, {[cur.id]: cur}),{});
        projectCommon[prop] = objectsObj;
        var commentsObj = comments.reduce((prev, cur) => Object.assign(prev, {[cur.id]: cur}),{});
        commentsCommon[prop] = commentsObj;
    }
    return [projectCommon, exports, commentsCommon]
}
function convertCommonFolder ( folder ) { var exports = [ ] ; var projectCommon = new ProjectCommon ( ) ; var commentsCommon = new ProjectCommon ( ) ; for ( var i = 0 ; i < folder . folders . length ; i ++ ) { var subFolder = folder . folders [ i ] ; var prop = subFolder . name ; if ( commonMappings [ prop ] ) { prop = commonMappings [ prop ] ; } var flat = ! ! commonFlatFileMappings [ prop ] ; var objects = [ ] ; var comments = [ ] ; for ( var j = 0 ; j < subFolder . files . length ; j ++ ) { var file = subFolder . files [ j ] ; var fileName = file . name ; var fileData = file . data ; var fileComments = file . comments ; if ( flat ) { var id = guid ( ) ; var projObj = new ProjectObjectFlat ( ) ; projObj . data = fileData ; projObj . id = id ; projObj . name = fileName ; projObj . fileName = fileName ; comments . push ( { id , data : fileComments } ) ; var projObjExport = new ProjectObjectExport ( ) ; projObjExport . id = id ; projObjExport . relativePath = "common/" + prop + "/" + fileName ; exports . push ( projObjExport ) ; objects . push ( projObj ) ; } else { var fileDataKeys = Object . keys ( fileData ) ; for ( var k = 0 ; k < fileDataKeys . length ; k ++ ) { var key = fileDataKeys [ k ] ; var obj = fileData [ key ] ; var id = guid ( ) ; var comment = fileComments [ key ] ; comments . push ( { id , data : comment } ) ; var projObj = new ProjectObject ( ) ; projObj . name = key ; projObj . data = obj ; projObj . id = id ; var projObjExport = new ProjectObjectExport ( ) ; projObjExport . id = id ; projObjExport . relativePath = "common/" + prop + "/" + fileName ; exports . push ( projObjExport ) ; objects . push ( projObj ) ; } } } var objectsObj = objects . reduce ( ( prev , cur ) => Object . assign ( prev , { [ cur . id ] : cur } ) , { } ) ; projectCommon [ prop ] = objectsObj ; var commentsObj = comments . reduce ( ( prev , cur ) => Object . assign ( prev , { [ cur . id ] : cur } ) , { } ) ; commentsCommon [ prop ] = commentsObj ; } return [ projectCommon , exports , commentsCommon ] }
Returns both a list of ProjectObjectExport objects, and a ProjectCommon
Returns both a list of ProjectObjectExport objects and a ProjectCommon
// For each file in the folder, read all the properties as objects by default