var gulp = require('gulp'); var gulpDocumentation = require('gulp-documentation'); var jsonTransform = require("gulp-json-transform"); gulp.task('documentation', function () { // Generating README documentation //return gulp.src(desktopBasePath + 'Sandbox/Guy/web-app/**/*.js') return gulp.src('./dotnet/websiteDesktop/app/js/controllers/**/*.js') // return gulp.src('./dist/json-documentation/API.json') .pipe(gulpDocumentation('json', {filename: 'componentLibrary1.json'})) .pipe(jsonTransform(function(data){ //call some function to pivot the data function createTagsJSON(data){ //make a new array of object var pivotedJsonTags= [] ; //loop through each data for (var i = 0; i < data.length ; i++) { var tags = data[i].tags; var obj = {}; //loop through each tag within the data for (var k = 0; k < tags.length ; k++){ //make a new object //make title the key var title = tags[k].title; var description = tags[k].description; //make description the value obj[title] = description; } //append the complete object to the json object pivotedJsonTags.push(obj); } return pivotedJsonTags; // return data[0].tags; } var jsonTags = createTagsJSON(data); //array of the documentation text function createComponentLibraryJSON(jsonTags) { //loop through each array var obj = {}; var arrayOfComponentType = []; var arrayOfComponentGroup = []; for (var i = 0; i < jsonTags.length; i++) { //create array of objects with the same object type //check to see if the array already exist with the component type //if not create a new array var componentType = jsonTags[i].componentType; var componentGroup = jsonTags[i].componentGroup; if (arrayOfComponentType.indexOf(componentType) < 0) { arrayOfComponentType.push(componentType); // obj[componentType] = jsonTags[i]; obj[componentType] = {}; // if group is not created, create a group key if (arrayOfComponentGroup.indexOf(componentGroup) < 0) { arrayOfComponentGroup.push(componentGroup); obj[componentType][componentGroup] = []; obj[componentType][componentGroup].push(jsonTags[i]); } else { //if group is created just push append it to the array obj[componentType][componentGroup].push(jsonTags[i]); } //obj[componentType].push(jsonTags[i]); } else { if (arrayOfComponentGroup.indexOf(componentGroup) < 0) { arrayOfComponentGroup.push(componentGroup); obj[componentType][componentGroup] = []; obj[componentType][componentGroup].push(jsonTags[i]); } else { //if group is created just push append it to the array obj[componentType][componentGroup].push(jsonTags[i]); } } } //if component type doesn't exit create a new array of object with the component type name //push it into the array //return the array return obj; } var componentLibaryJSON = createComponentLibraryJSON(jsonTags); return { components: componentLibaryJSON }; })) // .pipe(gulp.dest('./dist/json-documentation')); .pipe(gulp.dest('./dotnet/websitedesktop/app/handlebars/controllers/static/json')); });