Blame view

bower_components/polymer-element-catalog/build/catalog/elements.js 2.96 KB
07d13c9c   isisadmin   polymer catalog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  var path = require('path');
  var fs = require('fs-extra');
  
  var _ = require('lodash');
  var async = require('async');
  
  var stream = require('./utils/stream').obj;
  var packageDetails = require('./utils/package-details');
  var packageElements = require('./utils/package-elements');
  var analyze = require('./utils/analyze');
  var cleanTags = require('./utils/clean-tags');
  
  module.exports = function (imports) {
  
    var root = imports.root;
    var destDir = imports.destDir;
    var bowerFile = require(root + '/bower.json');
    var deps = bowerFile.dependencies;
  
    var data = [];
    var out = {};
  
    return stream.compose(
      stream.parse('packages.*'),
      stream.filter(function(package) {
  
        return deps[package.name];
      }),
      stream.asyncMap(function (package, done) {
  
        var packageBower = packageDetails({
          root: root,
          name: package.name
        });
  
        var elements = packageElements({
          name: package.name,
          deps: packageBower.dependencies
        });
  
        var output = async.map(elements, function (elementName, cb) {
  
          var details = packageDetails({
            root: root,
            name: elementName
          });
  
          fs.mkdirsSync(path.join(root, destDir, 'data', 'docs'));
          if (typeof details.main === 'string') details.main = [details.main];
          analyze(root, destDir, elementName, details.main || [elementName + '.html'], function(err, data) {
            // Set up object schema
            console.log("-",elementName,"(" + details._release + ")");
  
            var combined = data.elements.concat(data.behaviors);
            var hero;
            combined.forEach(function(el) {
              if (el.hero) hero = '/bower_components/' + elementName + '/' + el.hero;
            });
  
            var active = null;
            var demo = null;
            for (var i in combined) {
              if (combined[i].demos.length) {
                active = combined[i].is;
                demo = (combined[i].demos || [])[0] || null;
              }
            }
  
            cb(err, {
              name: elementName,
              version: details._release,
              source: details._originalSource,
              target: details._target,
              package: package.name,
              description: details.description,
              tags: (details.keywords || []).filter(cleanTags),
              hero: hero,
              demo: demo,
              active: active,
              elements: (data.elements || []).map(function(el){ return el.is; }),
              behaviors: (data.behaviors || []).map(function(be){ return be.is; }),
            });
          });
        }, function(err, output) {
          done(err, output);
        });
      }),
  
      // Convert to objects from arrays (and flatten),
      // and sort
      stream.create(
        function (chunk, enc, done) {
  
          data.push(chunk);
          done();
        },
        function (done) {
  
          var sortedData = _(data)
            .flatten()
            .sortBy('name')
            .value();
  
          this.push(sortedData);
          done();
        }
      )
    );
  }