foam.CLASS({
  package: 'foam.tools',
  name: 'Build',

  requires: [
    'foam.json2.Serializer',
    //'foam.json.Outputter',
    //'foam.TestRefines',
  ],

  imports: [
    'modelDAO',
  ],

  properties: [
    {
      name: 'modelId',
      value: 'foam.tools.Build',
    },
    {
      class: 'String',
      name: 'output',
      view: { class: 'foam.u2.tag.TextArea', rows: 16 },
    },
    {
      class: 'StringArray',
      name: 'flags',
      value: ['web'],
    },
    {
      hidden: true,
      name: 'outputter',
      expression: function(flags) {
        return this.Serializer.create();
        return this.Outputter.create({
          indentStr: '  ',
          formatFunctionsAsStrings: false,
          outputDefaultValues: false,
          passPropertiesByReference: false,
          //pretty: false,
          strict: false,
          propertyPredicate: function(o, p) {
            if ( p.flags ) {
              for ( var i = 0; i < flags.length; i++ ) {
                if ( p.flags[flags[i]] ) return true;
              }
              return false;
            }
            return !p.transient;
          },
          objectKeyValuePredicate: function(k, v) {
            if ( v.prototype && v.prototype.cls_ ) {
              return v !== v.prototype.cls_;
            }
            return true;
          },
        });
      },
    },
  ],

  actions: [
    function execute() {
      var self = this;
      return new Promise(function(ret) {

        var getDeps = function(model) {
          var deps = model.requires ?
              model.requires.map(function(r) { return r.path }) :
              [];

          deps = deps.concat(model.implements ?
                             model.implements.map((function(i) { return i.path })) :
                             []);

          if ( model.extends ) deps.push(model.extends);

          return deps;
        };

        var loaded = {};
        var queue = [self.modelId];
        var next = function() {
          if ( !queue.length ) {
            var output = [];
            Object.values(loaded).forEach(function(model) {
              output.push(self.outputter.stringify(foam.__context__, model));
            });
            self.output = output.join('\n');
            ret(self.output);
            return;
          }
          var modelId = queue.shift();
          if (loaded[modelId] ||
              modelId == 'FObject') {
            next();
            return;
          }
          var enqueueDeps = function(model) {
            loaded[modelId] = model;
            queue = queue.concat(getDeps(model));
            next();
          }
          self.modelDAO.find(modelId).then(function(model) {
            if ( ! model ) {
              console.error('Unable to load', modelId);
              next();
            } else {
              enqueueDeps(model);
            }
          });
        }
        next();
      });
    }
  ]
});

@@ -96,63 +96,8 @@
 r',%0A
-    //'foam.json.Outputter',%0A    //'foam.TestRefines',%0A
   %5D,
@@ -478,18 +478,15 @@
     
-expression
+factory
 : fu
@@ -492,21 +492,16 @@
 unction(
-flags
 ) %7B%0A    
@@ -508,283 +508,71 @@
     
-return this.Serializer.create();%0A        return this.Outputter.create(%7B%0A          indentStr: '  ',%0A          formatFunctionsAsStrings: false,%0A          outputDefaultValues: false,%0A          passPropertiesByReference: false,%0A          //pretty: false,%0A          strict: false,
+var flags = this.flags;%0A        return this.Serializer.create(%7B
 %0A   
@@ -582,16 +582,13 @@
     
-property
+axiom
 Pred
@@ -607,12 +607,9 @@
 ion(
-o, p
+a
 ) %7B%0A
@@ -621,25 +621,25 @@
        if ( 
-p
+a
 .flags ) %7B%0A 
@@ -810,218 +810,8 @@
   %7D%0A
-            return !p.transient;%0A          %7D,%0A          objectKeyValuePredicate: function(k, v) %7B%0A            if ( v.prototype && v.prototype.cls_ ) %7B%0A              return v !== v.prototype.cls_;%0A            %7D%0A
     
@@ -838,25 +838,24 @@
 %0A          %7D
-,
 %0A        %7D);
@@ -948,664 +948,45 @@
     
-return new Promise(function(ret) %7B%0A%0A        var getDeps = function(model) %7B%0A          var deps = model.requires ?%0A              model.requires.map(function(r) %7B return r.path %7D) :%0A              %5B%5D;%0A%0A          deps = deps.concat(model.implements ?%0A                             model.implements.map((function(i) %7B return i.path %7D)) :%0A                             %5B%5D);%0A%0A          if ( model.extends ) deps.push(model.extends);%0A%0A          return deps;%0A        %7D;%0A%0A        var loaded = %7B%7D;%0A        var queue = %5Bself.modelId%5D;%0A        var next = function() %7B%0A          if ( !queue.length ) %7B%0A            var output = %5B%5D;%0A            Object.values(loaded).forEach
+self.modelDAO.find(self.modelId).then
 (fun
@@ -984,36 +984,32 @@
 .then(function(m
-odel
 ) %7B%0A            
@@ -1008,802 +1008,69 @@
     
-      output.push(self.outputter.stringify(foam.__context__, model));%0A            %7D);%0A            self.output = output.join('%5Cn');%0A            ret(self.output);%0A            return;%0A          %7D%0A          var modelId = queue.shift();%0A          if (loaded%5BmodelId%5D %7C%7C%0A              modelId == 'FObject') %7B%0A            next();%0A            return;%0A          %7D%0A          var enqueueDeps = function(model) %7B%0A            loaded%5BmodelId%5D = model;%0A            queue = queue.concat(getDeps(model));%0A            next();%0A          %7D%0A          self.modelDAO.find(modelId).then(function(model) %7B%0A            if ( ! model ) %7B%0A              console.error('Unable to load', modelId);%0A              next();%0A            %7D else %7B%0A              enqueueDeps(model);%0A            %7D%0A          %7D);%0A        %7D%0A        next(
+self.output = self.outputter.stringify(self.__subContext__, m
 );%0A 

Fix up build tool to use the new Serializer and provide an axiomPredicate that gets rid of anything with flags that don't match the flags given to the tool.