/*
 * Atmosphere Demos Gulpfile
 * 
 * Description: Build atmosphere demos for endpoint apps with gulp on node.js 
 * 
 * gulp (runs the default gulp)
 * 
 * 
 */ 

// Vanilla Node Dependencies
var gulp = require('gulp');

// Gulp Specific Dependencies
var jsonConcat = require('gulp-json-concat');


var demoUrl = "https://atmosphere.anaren.com/demos/"
    
var projectTypes = ["bcm20737", "bcm43364", "intelCurie"];

var versions = ["1.5.0", "1.5.1", "2.0.0", "2.0.1", "2.0.2"];

// Get the */offical/*.atmo files and load up sufficient data for a demos.json file to serve the IDE
gulp.task('compile', function() {
    
    return gulp.src('**/official/*.atmo')
        .pipe(jsonConcat('alldemos.json', function(data){
            
            var newData = [];
            
            for (d in data) {
                
                // ignore invalid project types and old our non pub versions
                if ((projectTypes.indexOf(data[d].header.meta.projectType) > -1) && (versions.indexOf(data[d].header.meta.version) > -1)) {
                    
                    newData.push({version: data[d].header.meta.version,
                        description: data[d].header.meta.description,
                        projectType: data[d].header.meta.projectType,
                        name: data[d].header.meta.name,
                        url: demoUrl + d +".atmo"
                    });
                
                }
                
            }
            
            return new Buffer(JSON.stringify(newData));
            
        }))
        .pipe(gulp.dest('./'));
    
});

// The default tasks is scripts, so run scripts clean, which then runs scripts
gulp.task('default', ['compile']);
@@ -482,105 +482,104 @@
 %0A// 
-Get the */offical/*.atmo files and load up sufficient data for a demos.json file to serve the IDE
+Production alldemos.json - cleanses the output based on projectTypes and versions defined above.
 %0Agul
@@ -586,23 +586,20 @@
 p.task('
-compile
+prod
 ', funct
@@ -1596,16 +1596,846 @@
   %0A%7D);%0A%0A
+%0A// Development devdemos.json - useful for viewing out of date versions and projectTypes that need to be updated%0Agulp.task('dev', function() %7B%0A    %0A    return gulp.src('**/official/*.atmo')%0A        .pipe(jsonConcat('devdemos.json', function(data)%7B%0A            %0A            var newData = %5B%5D;%0A            %0A            for (d in data) %7B                           %0A                newData.push(%7Bversion: data%5Bd%5D.header.meta.version,%0A                    description: data%5Bd%5D.header.meta.description,%0A                    projectType: data%5Bd%5D.header.meta.projectType,%0A                    name: data%5Bd%5D.header.meta.name,%0A                    url: demoUrl + d +%22.atmo%22%0A                %7D); %0A            %7D%0A            %0A            return new Buffer(JSON.stringify(newData));%0A            %0A        %7D))%0A        .pipe(gulp.dest('./'));%0A    %0A%7D);%0A%0A
 // The d
@@ -2532,15 +2532,12 @@
 , %5B'
-compile
+prod
 '%5D);

create a dev demos json as well