Пример #1
0
 it('should export default', co(function* () {
   tree = yield* resolve(fixture('export-default'), options)
   js = yield build(tree)
   var ctx = vm.createContext()
   vm.runInContext(js, ctx)
   ctx.require('export-default').should.containEql('prop')
 }))
Пример #2
0
 it('should export', co(function* () {
   tree = yield* resolve(fixture('export'), options)
   js = yield build(tree)
   var ctx = vm.createContext()
   vm.runInContext(js, ctx)
   ctx.require('export').fn().should.be.eql(13)
 }))
Пример #3
0
 it('should import a subset', co(function* () {
   tree = yield* resolve(fixture('import-from-cjs'), options)
   js = yield build(tree)
   var ctx = vm.createContext()
   vm.runInContext(js, ctx)
   var array = ctx.require('import-from-cjs')
   should(array).be.a.Function
 }))
Пример #4
0
 it('should import all', co(function* () {
   tree = yield* resolve(fixture('import-default-from-cjs'), options)
   js = yield build(tree)
   var ctx = vm.createContext()
   vm.runInContext(js, ctx)
   var Emitter = ctx.require('import-default-from-cjs')
   should(Emitter).be.a.Function
 }))
Пример #5
0
 it('should install', co(function* () {
   tree = yield* resolve({
     dependencies: {
       "fortawesome/font-awesome": "4.0.3"
     }
   }, options)
   nodes = resolve.flatten(tree)
 }))
Пример #6
0
 it('should work', function (done) {
   resolve(fixture('simple'), {}, function (err, tree) {
     if (err) throw err;
     buildScripts(tree, {}, function (string) {
       var fn = vm.runInNewContext(req(string, tree));
       fn().trim().should.eql('Merhaba, dünya!');
       done();
     });
   });
 });
Пример #7
0
function* resolve(path) {
  var tree = yield resolver(path, {
    install: true
  });
  var meta = {
    locals: Object.keys(tree.locals)
  };

  return bundler.pages(meta)(tree);
}
Пример #8
0
    it('should resolve', function (done) {
        resolve(fixture, {
            install: true,
        }, function (err, tree) {
            if (err) return done(err);

            build = Build(tree);
            done();
        });
    });
Пример #9
0
Builder.prototype.resolve = function (done) {
  var root = this.root
  var out = join(root, 'components')
  var start = Date.now()

  if (!dev && this.tree) return done(null, this.tree)

  resolve(root, {install:true, out:out}, function (err, tree) {
    debug('resolved deps in %dms', Date.now() - start)
    done(err, tree)
  })
}
Пример #10
0
/**
 * build files with component-resolver and component-build.
 *
 * @param {Object} file gulp provided file.
 * @param {Object} option for component-build option.
 * @param {Function} configure build configuration function.
 * @param {Function} done
 */
function files(file, option, configure, done) {
  resolver(path.dirname(file.path), option, function(err, tree) {
    if (err) return done(err);

    var files = Build(tree, option);
    var plugins = files.filePlugins;
    files.filePlugins = function(build, option) {
      plugins.call(files, build, option);
      configure(build, option);
    };
    files.files(done);
  });
}
Пример #11
0
/**
 * build styles with component-resolver and component-build.
 *
 * @param {Object} file gulp provided file.
 * @param {Object} option for component-build option.
 * @param {Function} configure build configuration function.
 * @param {Function} done
 */
function styles(file, option, configure, done) {
  resolver(path.dirname(file.path), option, function(err, tree) {
    if (err) return done(err);

    var styles = Build(tree, option);
    var plugins = styles.stylePlugins;
    styles.stylePlugins = function(build, option) {
      plugins.call(styles, build, option);
      configure(build, option);
    };
    styles.styles(function(err, string) {
      if (err) return done(err);

      done(null, string);
    });
  });
}
  /**
   * Build the component
   * @param   {object} component The parsed component.json object
   */
  function build(component) {

    var validateOptions = {
      filename:     componentDirectory,
      verbose:      options.verbose === true
    };

    var resolveOptions = {
      root:         componentDirectory,
      out:          installDirectory,
      install:      options.install !== false,
      development:  options.development === true,
      verbose:      options.verbose === true
    };

    var builderOptions = {
      development:  options.development === true,
    };

    //validate the component
    try {
      validator(component, validateOptions);
    } catch(err) {
      callback([err]);
      return;
    }

    //build the component
    resolver(component, resolveOptions, function (err, tree) {
      if (err) return callback([err]);

      if (options.scripts !== false) {
        buildScripts(tree, builderOptions);
      }

      if (options.styles !== false) {
        buildStyles(tree, builderOptions);
      }

      if (options.files !== false) {
        buildFiles(tree, builderOptions);
      }

    });
  }
Пример #13
0
/**
 * build scripts with component-resolver and component-build.
 *
 * @param {Object} file gulp provided file.
 * @param {Object} option for component-build option.
 * @param {Function} configure build configuration function.
 * @param {Function} done
 */
function scripts(file, option, configure, done) {
  resolver(path.dirname(file.path), option, function(err, tree) {
    if (err) return done(err);

    var scripts = Build(tree, option);
    var plugins = scripts.scriptPlugins;
    scripts.scriptPlugins = function(build, option) {
      plugins.call(scripts, build, option);
      configure(build, option);
    };
    configure(scripts); // apply user customize.
    scripts.scripts(function(err, string) {
      if (err) return done(err);

      done(null, string);
    });
  });
}
Пример #14
0
function build(next) {
  resolve(process.cwd(), {
    // install the remote components locally
    install: false,
    root: 'public'
  }, function (err, tree) {
    if (err) console.log(err), process.exit(1);

    mkdir('public');

    builder.scripts(tree)
      .use('scripts', builder.plugins.js())
      .use('json', builder.plugins.json())
      .use('templates', jade({
        string: false,
        runtime: true
      }))
      .use('templates', builder.plugins.string())
      .end(function (err, js) {
        if (err) throw err;
        write('public/app.js', builder.scripts.require + jade.runtime + js);
      });

    builder.styles(tree)
      .use('styles', builder.plugins.css())
      .use('styles', stylus())
      .use('styles', builder.plugins.urlRewriter(''))
      .end(function (err, string) {
        if (err) throw err;
        fs.writeFileSync('public/app.css', string);
      });

    builder.files(tree, {destination: 'public'})
      .use('images', builder.plugins.copy())
      .use('files', builder.plugins.copy())
      .end();

    if (next) return next();
  })
}
Пример #15
0
  function end () {
    if (branches === undefined) {
        resolve(process.cwd(), { development: true }, function (err, tree) {
          branches = flatten(tree); 
          next();
        });
    } else {
      next();
    }

    function next() {
      var output;
      try { output = parse(); }
      catch (err) {
        tr.emit('error', new Error(
          err.toString().replace('Error: ', '') + ' (' + file + ')')
        );
      }

      finish(output);
    }
  }
gulp.task('scripts-component', [ 'scripts-gulp' ], function (cb) {
    var fs = require('fs');
    var resolve = require('component-resolver');
    var builder = require('component-builder');
    var typescript = require('./');
  
    // resolve the dependency tree
    resolve(process.cwd(), {
      // install the remote components locally
      install: true
    }, function (err, tree) {
      if (err) throw err;

      // only include `.js` files from components' `.scripts` field
      builder.scripts(tree)
        .use('scripts', typescript({ gulp: false }), builder.plugins.js())
        .use('json', builder.plugins.json())
        .use('templates', builder.plugins.string())
        .end(function (err, string) {
          if (err) throw err;
          fs.writeFile('build/build_1.js', string, cb);
        });
    })
});
Пример #17
0
function build (done) {
  log('Start assets compilation');

  var options = {
    install: false,
    root: 'public'
  };

  resolve(process.cwd(), options, onresolve);

  function onresolve (err, tree) {
    if (err) {
      log('Found error resolving dependencies tree %s', err);
      return done(err);
    }

    var batch = new Batch();
    batch.push(buildScripts);
    batch.push(buildStyles);
    batch.push(buildFiles);

    batch.end(function (err, results) {
      if (err) {
        log('Found error compiling assets: %s', err);
        return done(err);
      }

      log('Done compiling assets');
      var res = {};
      res.js = results[0];
      res.css = results[1];
      done(null, res);
    });

    function buildScripts (done) {
      builder.scripts(tree)
        .use('scripts', builder.plugins.js())
        .use('json', builder.plugins.json())
        .use('templates', jade({
          string: false,
          runtime: true
        }))
        .use('templates', builder.plugins.string())
        .end(function (err, js) {
          if (err) {
            log('Found error building scripts');
            return done(err);
          }

          log('Scripts built successfully');
          return done(null, builder.scripts.require + jade.runtime + js);
        });
    }

    function buildStyles (done) {
      builder.styles(tree)
        .use('styles', builder.plugins.css())
        .use('styles', stylus())
        .use('styles', builder.plugins.urlRewriter(''))
        .end(function (err, css) {
          if (err) {
            log('Found error building styles: %s', err);
            return done(err);
          }

          log('Styles built successfully');
          return done(null, css);
        });
    }

    function buildFiles (done) {
      builder.files(tree, {destination: 'public'})
        .use('images', builder.plugins.copy())
        .use('files', builder.plugins.copy())
        .end(function () {
          log('Files copied successfully');
          return done();
        });
    }
  }
}
Пример #18
0
 it('should install', co(function* () {
   tree = yield* resolve(fixture('js-nested-locals'), options)
 }))
Пример #19
0
 it('should install', co(function* () {
   tree = yield* resolve(fixture('js-matching-prefixes'), options)
 }))
Пример #20
0
 it('should install', co(function* () {
   tree = yield* resolve(fixture('js-require-single-quotes'), options);
 }))
Пример #21
0
 it('should install', co(function* () {
   tree = yield* resolve(fixture('js-asset-path'), options);
 }))
Пример #22
0
 it('should install', co(function* () {
   tree = yield* resolve(fixture('js-require-uppercase'), options);
 }))
Пример #23
0
 it('should install', co(function* () {
   tree = yield* resolve(fixture('js-page.js'), options);
 }))
Пример #24
0
 it('should install', co(function* () {
   tree = yield* resolve(fixture('js-relative-camelcase'), options)
 }))
Пример #25
0
 it('should install', co(function* () {
   tree = yield* resolve(fixture('js-multiple-names'), options);
 }))
Пример #26
0
 it('should install', co(function* () {
   tree = yield* resolve(fixture('js-scripts'), options)
 }))
Пример #27
0
 it('should install', co(function* () {
   tree = yield* resolve(fixture('js-infer-main'), options)
 }))
Пример #28
0
 it('should install', co(function* () {
   tree = yield* resolve(fixture('js-extension'), options)
 }))
Пример #29
0
	stream._read = function () {
		if (done) return stream.push(null);
		resolve('.', { development: !argv.production }, build);
	};
Пример #30
0
  resolve: function (basePath, options, cb) {
    resolve(basePath, options, function (err, tree) {
      if (err) throw err;
      var build = Build(tree, options);
      var defaultScriptPlugins = build.scriptPlugins;
      var defaultStylePlugins = build.stylePlugins;
      var defaultFilePlugins  = build.filePlugins;
      var func = {
        scripts: function () {
          var stream = through();
          build.scriptPlugins = function (build, options) {
            defaultScriptPlugins(build, options);

            var plugin = function (file, done) {
              gutil.log('scripts', file.filename);
              done();
            };

            build
              .use('scripts', plugin);
          };

          build.scripts(function (err, string) {

            if (err) {console.error(err);}

            stream.end(new File({
              cwd:  basePath,
              base: options.base || basePath,
              path: 'build.js',
              contents: new Buffer(string)
            }));
          });

          return stream;
        },

        styles: function () {
          var stream = through();
          build.stylePlugins = function (build, options) {
            defaultStylePlugins(build, options);
            var plugin = function (file, done) {
              stream.write(new File({
                cwd:  basePath,
                base: options.base || basePath,
                path: file.filename,
                contents: new Buffer(file.string)
              }));
              gutil.log('styles', file.filename);
              done();
            };

            build
              .use('styles', plugin);
          };

          build.styles(function (err, string) {
            if (err) throw err;
            stream.end();
          });

          return stream;
        },
        files: function () {
          var stream = through();
          build.filePlugins = function (build, options) {
            var plugin = function (file, done) {
              stream.write(new File({
                cwd:  basePath,
                base: options.base || basePath,
                path: file.filename
              }));
              gutil.log('files', file.filename);
              done();
            };

            build
              .use('images', plugin)
              .use('fonts', plugin)
              .use('files', plugin);
          };

          build.files(function (err) {
            if (err) throw err;
            stream.end();
          });

          return stream;
        }
      };
      cb(func);
    });
  }