Exemplo n.º 1
0
    return through.obj( function( file, enc, cb ) {

        var moduleName = './scripts/' + path.basename( file.path, '.js' );
        var dest = args.d ?
            path.join( opts.dest, path.basename( file.path ) ) :
            './tmp/build.js';

        // Punting out to a temporary file is very un-gulp but builder wont write to a buffer so its the only option
        builder.reset();
        builder.build( moduleName, dest, {
            config: {
                baseURL: './public'
            },
            // minify: true,
            sourceMaps: !!args.d
        })
            .then( function() {
                file.contents = args.d ?
                    fs.readFileSync( dest ) :
                    fs.readFileSync( './tmp/build.js' );
                rimraf( './tmp', function( err ) {
                    cb( null, file );
                });
            })
            .catch( function( err ) {
                console.error( 'error::', err );
            });

    });
Exemplo n.º 2
0
gulp.task('buildjs', function (cb) {
  var Builder = require('systemjs-builder');
  var builder = new Builder("./","systemjs.config.js");

  builder.reset();

  builder.buildStatic("app", "dist/app.min.js", {minify: true})
    .then(console.log("finished"))
  .catch(function(err) {
    console.log(err);
    cb(err);
  });
});
Exemplo n.º 3
0
exports.bundle = function(moduleExpression, fileName, opts) {
  var args = moduleExpression.split(' ');

  var firstModule = args[0];

  var operations = extractOperations(args);

  systemBuilder.reset();

  return config.load()
  .then(function() {
    fileName = fileName || path.resolve(config.pjson.baseURL, 'build.js');

    if (!opts.sourceMaps)
      return removeExistingSourceMap(fileName);
  })
  .then(function() {
    ui.log('info', 'Building the bundle tree for `' + moduleExpression + '`...');

    // trace the starting module
    var cfg = config.loader.getConfig();
    cfg.baseURL = path.relative(process.cwd(), config.pjson.baseURL);

    return systemBuilder.trace(firstModule, cfg);
  })
  .then(function(trace) {

    // if there are no other operations, then we have the final tree
    if (!operations.length)
      return trace.tree;

    // chain the operations, applying them with the trace of the next module
    var operationPromise = Promise.resolve(trace.tree);
    operations.forEach(function(op) {
      operationPromise = operationPromise
      .then(function(curTree) {
        return systemBuilder.trace(op.moduleName)
        .then(function(nextTrace) {

          var operatorFunction;

          if (op.operator == '+')
            operatorFunction = systemBuilder.addTrees;
          else if (op.operator == '-')
            operatorFunction = systemBuilder.subtractTrees;
          else
            throw 'Unknown operator ' + op.operator;

          return operatorFunction(curTree, nextTrace.tree);
        });
      });
    });

    return operationPromise;
  })
  .then(function(buildTree) {
    if (opts.inject) {
      // Add the bundle to config if the inject flag was given.
      var bundleName = extractBundleName(fileName);
      if (!config.loader.bundles) {
        config.loader.bundles = {};
      }
      config.loader.bundles[bundleName] = Object.keys(buildTree).filter(function(moduleName) {
        return buildTree[moduleName].metadata.build !== false;
      });
      ui.log('ok', '`' + bundleName + '` added to config bundles.');
    }
    return systemBuilder.buildTree(buildTree, fileName, opts);
  })
  .then(function() {
    delete config.loader.depCache;
  })
  .then(config.save)
  .then(function() {
    ui.log('ok', 'Built into `' + path.relative(process.cwd(), fileName) + '`' + (opts.sourceMaps ? ' with source maps' : '') + ', ' + (opts.minify ? '' : 'un') + 'minified.');
  })
  .catch(function(e) {
    ui.log('err', e.stack || e);
    throw e;
  });
}