Example #1
0
    it('is called for each included file', function() {
      var processFileArguments = [];

      var inputPath = fixturePath + '/dir1';
      var node = new Funnel(inputPath, {
        include: [ /.png$/, /.js$/ ],
        destDir: 'foo',

        processFile: function(sourcePath, destPath, relativePath) {
          var relSourcePath = sourcePath.replace(this.inputPaths[0], '__input_path__');
          var relDestPath = destPath.replace(this.outputPath, '__output_path__');

          processFileArguments.push([
            relSourcePath,
            relDestPath,
            relativePath
          ]);
        }
      });

      builder = new broccoli.Builder(node);
      return builder.build()
      .then(function(results) {

        var expected = [
          [ '__input_path__/subdir1/subsubdir1/foo.png',
            '__output_path__/foo/subdir1/subsubdir1/foo.png',
            'subdir1/subsubdir1/foo.png'
          ],
          [ '__input_path__/subdir1/subsubdir2/some.js',
            '__output_path__/foo/subdir1/subsubdir2/some.js',
            'subdir1/subsubdir2/some.js'
          ]
        ];

        expect(processFileArguments).to.eql(expected);
      });
    });
Example #2
0
    it('correctly rebuilds', function() {
      var inputPath = fixturePath + '/dir1';
      var node = new Funnel(inputPath, {
        include: ['**/*.js']
      });

      builder = new broccoli.Builder(node);
      return builder.build()
        .then(function(results) {
          var outputPath = results.directory;

          expect(walkSync(outputPath, ['**/*.js'])).to.eql(walkSync(inputPath, ['**/*.js']));

          var mutatedFile = inputPath + '/' + 'subdir1/subsubdir2/some.js';
          fs.writeFileSync(mutatedFile, fs.readFileSync(mutatedFile));
          return builder.build();
        })
        .then(function(results) {
          var outputPath = results.directory;

          expect(walkSync(outputPath, ['**/*.js'])).to.eql(walkSync(inputPath, ['**/*.js']));
        });
    });
    it('footerFiles + inputFiles (glob) + headerFiles', co.wrap(function *() {
      let node = concat(inputDir, {
        outputFile: '/rebuild.js',
        headerFiles: ['b.js'],
        footerFiles: ['a.js'],
        inputFiles: [ '**/*.js'],
        sourceMapConfig: { enabled: false }
      });

      write('z.js', 'z');
      write('a.js', 'a');
      write('b.js', 'b');

      builder = new broccoli.Builder(node);

      let result = yield builder.build();
      expect(read(result.directory + '/rebuild.js')).to.eql('b\nz\na');

      write('a.js', 'a-updated');
      result = yield builder.build();
      expect(read(result.directory + '/rebuild.js')).to.eql('b\nz\na-updated');

      write('a.js', 'a');
      result = yield builder.build();
      expect(read(result.directory + '/rebuild.js')).to.eql('b\nz\na');

      write('z.js', 'z-updated');
      result = yield builder.build();
      expect(read(result.directory + '/rebuild.js')).to.eql('b\nz-updated\na');

      unlink('z.js');
      result = yield builder.build();
      expect(read(result.directory + '/rebuild.js')).to.eql('b\na');

      write('z.js', 'z');
      result = yield builder.build();
      expect(read(result.directory + '/rebuild.js')).to.eql('b\nz\na');

      yield builder.build();
    }));
    it('calls updateCache again if existing file is changed', function(){
      var updateCacheCount = 0;
      var tree = cachingWriter(sourcePath, {
        updateCache: function() {
          updateCacheCount++;
        }
      });

      builder = new broccoli.Builder(tree);

      return builder.build()
        .finally(function() {
          expect(updateCacheCount).to.eql(1);
        })
        .then(function() {
          fs.writeFileSync(existingJSFile, '"YIPPIE"\n"KI-YAY"\n');

          return buildInSeries(3);
        })
        .finally(function() {
          expect(updateCacheCount).to.eql(2);
        });
    });
Example #5
0
  it('assimilates existing sourcemap', function() {
    var inner = concat(firstFixture, {
      outputFile: '/all-inner.js',
      inputFiles: ['inner/*.js'],
      header: "/* This is my header. */"
    });
    var other = concat(firstFixture, {
      outputFile: '/all-other.js',
      inputFiles: ['other/*.js'],
      header: "/* Other header. */"
    });

    var final = concat(merge([inner, other]), {
      outputFile: '/staged.js',
      inputFiles: ['all-inner.js', 'all-other.js'],
    });

    builder = new broccoli.Builder(final);
    return builder.build().then(function(result) {
      expectFile('staged.js').in(result);
      expectFile('staged.map').in(result);
    });
  });
Example #6
0
  it('does not clobber the directory', function(){
    var sourcePath = 'tests/fixtures/sample-ember-style-package';
    var priorFilePath = path.join(root, exportLocation, 'random-stuff.txt');
    var contents   = 'random stuff';

    var tree = exportTree(sourcePath, {
      destDir: exportLocation,
      clobber: false
    });

    mkdirp.sync(exportLocation);
    fs.writeFileSync(priorFilePath, contents, {encoding: 'utf8'});

    builder = new broccoli.Builder(tree);
    return builder.build().then(function(dir) {
      var filePath = '/lib/main.js';
      var expected = fs.readFileSync(sourcePath + filePath);
      var actual   = fs.readFileSync(exportLocation + filePath);

      expect(actual).to.eql(expected);
      expect(fs.readFileSync(priorFilePath, {encoding: 'utf8'})).to.eql(contents);
    });
  })
	it('does not output preprocessors results', function() {
		var jsTech = {
			Tree: FakeTechTree,
			suffixes: 'js',
			preprocessor: true
		}

		var options = {
			blockName: 'index',
			techs: ['js'],
			techModules: [{
				js: jsTech
			}]
		}

		var bem = Builder(options)

		builder = new broccoli.Builder(bem)
		return builder.build().then(function(result) {
			var result = fs.readdirSync(result.directory)
			assert.equal(result.length, 0)
		})
	})
Example #8
0
    it('add/remove inputFile', function() {
      var node = concat(inputDir, {
        outputFile: '/rebuild.js',
        inputFiles: ['**/*.js'],
        allowNone: true,
      });

      builder = new broccoli.Builder(node);
      return builder.build().then(function(result) {
        expect(fs.readFileSync(result.directory + '/rebuild.js', 'UTF8')).to.eql('//# sourceMappingURL=rebuild.map');

        write('omg.js', 'hi');

        return builder.build();
      }).then(function(result) {
        expect(read(result.directory + '/rebuild.js')).to.eql('hi//# sourceMappingURL=rebuild.map');
        unlink('omg.js')
        return builder.build();
      }).then(function(result) {
        expect(read(result.directory + '/rebuild.js')).to.eql('//# sourceMappingURL=rebuild.map');
        return builder.build();
      });
    });
Example #9
0
	it('uses dest options as relative', function() {
		var DEST = 'dest'
		var CSS_DEST = 'cssdest/css.css'
		var HTML_DEST = 'htmldest/html.html'

		var tree = webfont(DIR, {
			dest: DEST,
			cssDest: CSS_DEST,
			htmlDest: HTML_DEST,
			html: true
		})

		builder = new broccoli.Builder(tree)
		return builder.build().then(function(result) {
			var dir = result.directory
			var font = path.join(dir, DEST, 'iconfont.woff')
			var css = path.join(dir, CSS_DEST)
			var html = path.join(dir, HTML_DEST)
			assert(fs.existsSync(font))
			assert(fs.existsSync(css))
			assert(fs.existsSync(html))
		})
	})
Example #10
0
    it('does not delete eagerly (allowing the same file to be used repeatedly)', function(){
      var sourcePath = 'tests/fixtures/sample-ember-style-package';
      var tree = moveFile(sourcePath, {
        files: [
          {srcFile: '/lib/main.js', destFile: '/sample-ember-style-package.js'},
          {srcFile: '/lib/main.js', destFile: '/some-other-file.js'},
          {srcFile: '/lib/core.js', destFile: '/wat.js'}
        ]
      });

      builder = new broccoli.Builder(tree);
      return builder.build().then(function(dir) {
        var expected = fs.readFileSync(sourcePath + '/lib/main.js');
        var core = fs.readFileSync(sourcePath + '/lib/core.js');

        expect(fs.readFileSync(dir + '/sample-ember-style-package.js')).to.eql(expected);
        expect(fs.readFileSync(dir + '/some-other-file.js')).to.eql(expected);
        expect(fs.readFileSync(dir + '/wat.js')).to.eql(core);

        expect(fs.existsSync(dir + '/lib/main.js')).to.not.be.ok();
        expect(fs.existsSync(dir + '/lib/core.js')).to.not.be.ok();
      });
    })
Example #11
0
    it('should output the correct concat files', function() {
      packager = new Packager({
        entries: ['dummy']
      });

      var dist = packager.package();

      builder = new broccoli.Builder(dist);

      return builder.build().then(function(results) {

        expect(listFiles(results.directory)).to.deep.eql([
          'default-build/assets/dummy.css',
          'default-build/assets/dummy.js',
          'default-build/assets/dummy.map',
          'default-build/assets/vendor.css',
          'default-build/assets/vendor.js',
          'default-build/assets/vendor.map',
          'default-build/dummy-tests/testem.js',
          'default-build/index.html'
        ]);
      });
    });
Example #12
0
    it('should output only app files in production', function() {
      process.env.EMBER_ENV = 'production';
      packager = new Packager({
        entries: ['dummy'],
        strategies: ['http2']
      });

      var dist = packager.package();

      builder = new broccoli.Builder(dist);

      return builder.build().then(function(results) {
        process.env.EMBER_ENV = 'development';
        expect(listFiles(results.directory)).to.deep.eql([
          'http2-build/dummy/app.js',
          'http2-build/dummy/components/baz-bar.js',
          'http2-build/dummy/components/foo-bar.js',
          'http2-build/dummy/config/environment.js',
          'http2-build/dummy/crossdomain.xml',
          'http2-build/dummy/index.html',
          'http2-build/dummy/index.js',
          'http2-build/dummy/index.map',
          'http2-build/dummy/pods/bizz-buzz/component.js',
          'http2-build/dummy/pods/bizz-buzz/template.js',
          'http2-build/dummy/pods/foo-baz/component.js',
          'http2-build/dummy/pods/foo-baz/template.js',
          'http2-build/dummy/robots.txt',
          'http2-build/dummy/router.js',
          'http2-build/dummy/styles/app.css',
          'http2-build/dummy/templates/components/foo-bar.js',
          'http2-build/dummy/templates/profile.js',
          'http2-build/ember/ember.js',
          'http2-build/ember/ember/get.js'
        ]);
        
      });
    });
Example #13
0
function buildAndLint(sourcePath) {
  linter.included({
    isTestingSassLintAddon: true,
    options: {
      sassLint: {
        configPath: 'sass-lint-test-config.yml',
        logError: function(fileLint) {
          errors.push(fileLint);
        },
      }
    },
    trees: {
      styles: sourcePath, // Directory to lint
    },
  });

  var node = linter.lintTree('app', {
    tree: sourcePath
  });

  builder = new broccoli.Builder(node);

  return builder.build();
}
Example #14
0
    it('simply returns a copy of the input node at a nested source', function() {
      var inputPath = fixturePath + '/dir1';
      var node = new Funnel(inputPath, {
        srcDir: 'subdir1'
      });

      builder = new broccoli.Builder(node);
      return builder.build()
        .then(function(results) {
          var restrictedInputPath = inputPath + '/subdir1';
          var outputPath = results.directory;

          expect(walkSync(outputPath)).to.eql(walkSync(restrictedInputPath));
        })
        .then(function() {
          return builder.build();
        })
        .then(function(results) {
          var restrictedInputPath = inputPath + '/subdir1';
          var outputPath = results.directory;

          expect(walkSync(outputPath)).to.eql(walkSync(restrictedInputPath));
        });
    });
	it('calls techs "changeDecl" methods', function() {
		var fakeTech = {
			suffixes: ['js'],
			Tree: FakeTechTree,
			changeDecls: sinon.spy(function() {})
		}

		var options = {
			isOptions: true,
			blockName: 'index',
			techs: ['tech'],
			techModules: [{tech: fakeTech}]
		}
		
		var bem = Builder(options)
		
		builder = new broccoli.Builder(bem)
		return builder.build().then(function() {
			// ChangeDecls is called with reader and options
			var args = fakeTech.changeDecls.lastCall.args
			assert(args[0] instanceof FakeDeclReader)
			assert(args[1].isOptions)
		})
	})
Example #16
0
  it('defaults work', function() {
    fixturify.writeSync(INPUT_PATH, {
      'index.js': "__invoke(require('./a')); require('chai')",
      'a.js' : "module.exports = 1;"
    });

    const node = new Watchify(INPUT_PATH);

    pipeline = new Builder(node);

    return pipeline.build().then(function() {
      const outputFile = pipeline.outputPath + '/browserify.js';

      expect(file(outputFile)).to.exist; // jshint ignore:line

      const returnResult = evalAndInvoke(outputFile);

      expect(returnResult.value).to.eql(1);
      expect(returnResult.wasCalled).to.eql(1);

      fixturify.writeSync(INPUT_PATH, {
        'a.js' : "module.exports = 222",
      });

      return pipeline.build();
    }).then(function(results) {
      const outputFile = pipeline.outputPath + '/browserify.js';

      expect(file(outputFile)).to.exist; // jshint ignore:line

      const returnResult = evalAndInvoke(outputFile);

      expect(returnResult.value).to.eql(222);
      expect(returnResult.wasCalled).to.eql(1);
    });
  });
Example #17
0
    it('receives relative inputPath as argument and can escape destDir with ..', function() {
      var inputPath = fixturePath + '/lib';
      var node = new Funnel(inputPath, {
        destDir: 'utility',
        getDestinationPath: function(relativePath) {
          if (relativePath === 'main.js') {
            return '../utility.js';
          }
          return relativePath;
        }
      });

      builder = new broccoli.Builder(node);
      return builder.build().then(function(results) {
        var outputPath = results.directory;
        expect(walkSync(outputPath)).to.eql([
          'utility.js',
          'utility/',
          'utility/utils.js',
          'utility/utils/',
          'utility/utils/foo.js',
        ]);
      });
    });
Example #18
0
    it('can properly handle the output path being a broken symlink', function() {
      var inputPath = fixturePath + '/dir1';
      var node = new Funnel(inputPath, {
        srcDir: 'subdir1'
      });

      builder = new broccoli.Builder(node);
      return builder.build()
        .then(function() {
          return rimraf(node.outputPath);
        })
        .then(function() {
          fs.symlinkSync('foo/bar/baz.js', node.outputPath);
        })
        .then(function() {
          return builder.build();
        })
        .then(function(results) {
          var restrictedInputPath = inputPath + '/subdir1';
          var outputPath = results.directory;

          expect(walkSync(outputPath)).to.eql(walkSync(restrictedInputPath));
        });
    });
Example #19
0
 }).then(function(result){
   expect(read(result.directory + '/rebuild.js')).to.eql('b\nz\na//# sourceMappingURL=rebuild.map');
   return builder.build();
 });
Example #20
0
 }).then(function(result) {
   expect(read(result.directory + '/rebuild.js')).to.eql('a\nb\nz//# sourceMappingURL=rebuild.map');
   unlink('a.js')
   return builder.build();
 }).then(function(result) {
Example #21
0
 }).then(function(result) {
   expect(read(result.directory + '/rebuild.js')).to.eql('b\na-updated//# sourceMappingURL=rebuild.map');
   write('a.js', 'a');
   return builder.build();
 }).then(function(result) {
Example #22
0
 .then(() => this.builder.build(this.broccoliBuilderFallback ? addWatchDirCallback : null))
'use strict';
var process = require('process');
var fs = require('fs');
var broccoli = require('broccoli');
var Typify = require('../');

var path = process.argv[2];

if (!path || !fs.existsSync(path)) {
  console.error("Need a directory to process");
  process.exit(2);
}


var builder = new broccoli.Builder(Typify.Compiler(path));
builder.build().then(function (results) {
    console.log('success');
    process.exit(0);
}, function (fail) {
    console.log(fail.message);
    process.exit(1);
});
Example #24
0
 return builder.build().then(function(result) {
   expectFile('browserify_stubs.js').toMatch('first.js').in(result);
   fs.writeFileSync(path.join(src.inputTree, 'new.js'), "import SomethingNew from \"npm:something-new\"\n");
   return builder.build();
 }).then(function(result){
Example #25
0
 return builder.build().then(function(result) {
   expectFile('browserify_stubs.js').toMatch('first.js').in(result);
   fs.unlinkSync(path.join(src.inputTree, 'sample.js'));
   return builder.build();
 }).then(function(result){
Example #26
0
 return builder.build().then(function(result){
   expectFile('browserify/browserify.js').toMatch('bundle4.js').in(result);
   expect(spy).to.have.callCount(1);
   return builder.build();
 }).then(function(){
Example #27
0
 return builder.build().then(function(result){
   expectFile('special-browserify/browserify.js').toMatch('bundle1.js').in(result);
   return builder.build();
 });
Example #28
0
 function build() {
   var tree = broccoli.loadBrocfile();
   var builder = new broccoli.Builder(tree);
   return builder.build();
 }
        it('Insert content according to "includeInOutput" & "includeInIndexHtml"', function() {
            appTree = new EmberAddon({
                'ember-index': {
                    output: 'index.jsp',
                    content: [{
                        key: '1',
                        file: '_emberIndexContent/file1.txt',
                        includeInOutput: false,
                        includeInIndexHtml: false
                    }, {
                        key: '2',
                        file: '_emberIndexContent/file2.txt',
                        includeInOutput: true,
                        includeInIndexHtml: false
                    }, {
                        key: '3',
                        file: '_emberIndexContent/file3.txt',
                        includeInOutput: false,
                        includeInIndexHtml: true
                    },{
                        key: '4',
                        file: '_emberIndexContent/file4.txt',
                        includeInOutput: true,
                        includeInIndexHtml: true
                    }]
                }
            }).toTree();

            builder = new broccoli.Builder(appTree);
            return builder.build()
                .then(function(results) {
                    var indexHtml, indexJsp,
                        outputPath = results.directory,
                        indexJspPath = path.join(outputPath, 'index.jsp'),
                        indexHtmlPath = path.join(outputPath, 'index.html'),
                        file1RegExp = /<!-- content from file1 -->/,
                        file2RegExp = /<!-- content from file2 -->/,
                        file3RegExp = /<!-- content from file3 -->/,
                        file4RegExp = /<!-- content from file4 -->/;

                        expect(fs.existsSync(indexJspPath)).to.be.equal(true);

                    indexJsp = fs.readFileSync(indexJspPath).toString();
                    indexHtml = fs.readFileSync(indexHtmlPath).toString();

                    expect(file1RegExp.test(indexJsp)).to.be.equal(false);

                    expect(file1RegExp.test(indexHtml)).to.be.equal(false);

                    expect(file2RegExp.test(indexJsp)).to.be.equal(true);

                    expect(file2RegExp.test(indexHtml)).to.be.equal(false);

                    expect(file3RegExp.test(indexJsp)).to.be.equal(false);

                    expect(file3RegExp.test(indexHtml)).to.be.equal(true);

                    expect(file4RegExp.test(indexJsp)).to.be.equal(true);

                    expect(file4RegExp.test(indexHtml)).to.be.equal(true);


                });
        });
Example #30
0
var broccoli = require('broccoli');
var RSVP     = require('rsvp');
var rimraf   = RSVP.denodeify(require('rimraf'));
var ncp      = RSVP.denodeify(require('ncp'));
var mkdir    = RSVP.denodeify(require('fs').mkdir);
var chalk    = require('chalk');


process.env.BROCCOLI_ENV = process.env.BROCCOLI_ENV || 'production';
var tree    = broccoli.loadBrocfile();
var builder = new broccoli.Builder(tree);

var buildPath = process.argv[2] || 'dist';

builder.build()
  .then(function(results) {
    return rimraf(buildPath)
      .then(function() {
        return mkdir(buildPath);
      })
      .then(function() {
        return ncp(results.directory, buildPath, {
          clobber: true,
          stopOnErr: true
        });
      });
  })
  .then(function() {
    console.log(chalk.green('Built project successfully. Stored in "' + buildPath + '/".\n'));
  })