|
| 1 | +// this script generates JSON file with stats on: |
| 2 | +// - which samples are in the browser (DOC samples) |
| 3 | +// - which samples are excluded from browser (DEV samples) |
| 4 | +// - which samples are imported from xplat repo |
| 5 | + |
| 6 | +const gulp = require("gulp"); |
| 7 | +const chmod = require("gulp-chmod"); |
| 8 | +const flatten = require("gulp-flatten"); |
| 9 | +const fs = require("fs"); |
| 10 | +const path = require("path"); |
| 11 | + |
| 12 | +const path = require("path"); |
| 13 | +const es = require("event-stream"); |
| 14 | +const del = require("del"); |
| 15 | + |
| 16 | +// NOTE you can comment out strings in this array to run these function only on a subset of samples |
| 17 | +var samplesRepoPath = [ |
| 18 | + // including samples for all components |
| 19 | + '../samples/**/package.json', |
| 20 | + |
| 21 | + // including specific samples |
| 22 | + // '../samples/charts/doughnut-chart/overview/package.json', |
| 23 | + // '../samples/charts/category-chart/area-chart-multiple-sources/package.json', |
| 24 | + // '../samples/gauges/**/measures/package.json', |
| 25 | + // '../samples/charts/sparkline/grid/package.json', |
| 26 | + // '../samples/maps/**/display-heat-imagery/package.json', |
| 27 | + // '../samples/excel/**/operations-on-workbooks/package.json', |
| 28 | + // '../samples/charts/zoomslider/overview/package.json', |
| 29 | + |
| 30 | + // including samples for specific components |
| 31 | + // '../samples/charts/**/package.json', |
| 32 | + // '../samples/maps/**/package.json', |
| 33 | + // '../samples/excel/**/package.json', |
| 34 | + // '../samples/gauges//**/package.json', |
| 35 | + // '../samples/grids/**/package.json', |
| 36 | + // '../samples/layouts/**/package.json', |
| 37 | + // '../samples/editors/**/package.json', |
| 38 | + |
| 39 | + // excluding package.json in node_modules sub folders in case they are installed locally |
| 40 | + // '!../samples/**/charts/financial-chart/theming/package.json', |
| 41 | + '!../samples/**/node_modules/**/package.json', |
| 42 | + '!../samples/**/node_modules/**', |
| 43 | + '!../samples/**/node_modules', |
| 44 | +]; |
| 45 | + |
| 46 | +function generate(cb, samplesInBrowser) { |
| 47 | + |
| 48 | + var sampleStats = {}; |
| 49 | + gulp.src(samplesRepoPath, {allowEmpty: true}) |
| 50 | + .pipe(es.map(function(file, fileCallback) { |
| 51 | + //log("getting: " + file.dirname); |
| 52 | + // saving info for each samples in samplesDatabase |
| 53 | + // log("sample: " + file.dirname); |
| 54 | + var samplePath = file.dirname.toString().split('\\samples\\')[1].split('\\').join('/'); |
| 55 | + sampleStats[samplePath] = { browser: false, xplat: false, path: samplePath, } |
| 56 | + |
| 57 | + fileCallback(null, file); |
| 58 | + })) |
| 59 | + .on("end", function() { |
| 60 | + |
| 61 | + for (const samplePath of samplesInBrowser) { |
| 62 | + if (sampleStats[samplePath]) { |
| 63 | + sampleStats[samplePath].browser = true; |
| 64 | + } else { |
| 65 | + console.log(sampleStats); |
| 66 | + throw new Error("Cannot find a sample in all samples: " + samplePath); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + var jsonStats = []; |
| 71 | + var keys = Object.keys(sampleStats); |
| 72 | + for (const samplePath of keys) { |
| 73 | + var info = sampleStats[samplePath]; |
| 74 | + jsonStats.push( ' { "browser": ' + info.browser + ', "xplat": ' + info.xplat + ', "path": "' + info.path + '" }' ); |
| 75 | + // jsonStats.push(sampleStats[samplePath]); |
| 76 | + // if (sampleStats[samplePath]) |
| 77 | + } |
| 78 | + var jsonData = jsonStats.join(',\n').replace(/true,/g, 'true, '); |
| 79 | + jsonData = "[\n" + jsonData + "\n]" |
| 80 | + // var json = JSON.stringify(jsonStats, null, ' ').replace(/\",\n/g, '\",') |
| 81 | + // .replace(/ /g, ' ') |
| 82 | + // // .replace(/true,/g, 'true, ') |
| 83 | + // .replace(/\"\n*.\}/g, '\" \}') |
| 84 | + // .replace(/\{\n*.\"/g, '\{ \"') |
| 85 | + // ; |
| 86 | + |
| 87 | + // console.log(jsonStats); |
| 88 | + // console.log(sampleStats); |
| 89 | + // console.log("generate... done = " + sampleStats.length); |
| 90 | + |
| 91 | + const jsonPath = "./src/assets/stats.json"; |
| 92 | + fs.writeFileSync(jsonPath, jsonData); |
| 93 | + // console.log(jsonData); |
| 94 | + console.log("saved " + jsonStats.length + " samples stats to " + jsonPath); |
| 95 | + |
| 96 | + if (cb) cb(); |
| 97 | + }); |
| 98 | + |
| 99 | +} exports.generate = generate; |
0 commit comments