setUp: function(done) {
   grunt.file.copy(fixture, tmp);
   done();
 },
Example #2
0
 src = files.map(function(filepath) {
   // Read file source.
   return grunt.file.read(filepath);
 }).join("");
Example #3
0
  cases: function(test) {
    var expect, result;

    test.expect(10);

    expect = grunt.file.read("test/expected/simple.html");
    result = grunt.file.read("tmp/cases/simple.html");
    test.equal(expect, result, "should satisfy a simple case");

    expect = grunt.file.read("test/expected/complex.html");
    result = grunt.file.read("tmp/cases/complex.html");
    test.equal(expect, result, "should satisfy a complex case");

    expect = grunt.file.read("test/expected/simple.html");
    result = grunt.file.read("tmp/expected/simple.html");
    test.equal(expect, result, "should not touch file with no includes");

    expect = grunt.file.read("test/expected/simple.html");
    result = grunt.file.read("tmp/flatten/simple.html");
    test.equal(expect, result, "should flatten files");

    expect = grunt.file.read("test/expected/simple_windows.html");
    result = grunt.file.read("tmp/cases/simple_windows.html");
    test.equal(expect, result, "should satisfy simple windows case");

    expect = grunt.file.read("test/expected/banner.html");
    result = grunt.file.read("tmp/banner/banner.html");
    test.equal(expect, result, "should prepend the supplied banner");

    expect = grunt.file.read("test/expected/include_path.html");
    result = grunt.file.read("tmp/include_path/simple.html");
    test.equal(expect, result, "should use header and footer from includes directory");

    expect = grunt.file.read("test/expected/template.html");
    result = grunt.file.read("tmp/template/template.html");
    test.equal(expect, result, "should have header and body wrapped with template");

    expect = grunt.file.read("test/expected/simple.html");
    result = grunt.file.read("tmp/full_path/simple.html");
    test.equal(expect, result, "should use the full filename given in include path");

    expect = grunt.file.read("test/expected/multiple_paths.html");
    result = grunt.file.read("tmp/multiple_paths/simple.html");
    test.equal(expect, result, "should use array of include paths to find proper path");

    test.done();
  }
 tearDown: function(done) {
     grunt.file.setBase(__dirname);
     done();
 }
 inline_test: function(test) {
     test.expect(1);
     test.equal(grunt.file.read('tmp/basic.txt'), 'some basic text');
     test.done();
 }
Example #6
0
 assertWatch([function() {
   grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var test = true;');
   grunt.file.write(path.join(cwd, 'lib', 'two.js'), 'var test = true;');
 }], function(result) {
Example #7
0
 setTimeout(function() {
   grunt.file.write(path.join(cwd, 'lib', 'wait.js'), 'var wait = true;');
 }, 500);
Example #8
0
 grunt.file.expand(JS_GLOB).forEach(function(file) {
   grunt.file.copy(
     file,
     STARTER_BUILD_PATH + file
   );
 });
Example #9
0
 files.forEach(function(file) {
   grunt.file.delete(file, {force: true});
 });
Example #10
0
var cheerio= require('cheerio'), grunt= require('grunt');
var html= grunt.file.read('/Users/andrea/Progetti/grunt/plurimedia/www/grunt/src/html/block/projects.html');
$= cheerio.load('<div></div>');
$html= $.load('<div id="mio">'+html+'</div>').root();

console.log($html.find('[data-template]').length);
$.root().append($html.contents());

console.log($('[data-template]').length);
console.log($.html());
Example #11
0
 grunt.file.expand(STARTER_GLOB).forEach(function(file) {
   grunt.file.copy(
     file,
     'build/' + file
   );
 });
 testbump('bump:prerelease', function(result) {
   test.ok(result.indexOf('from 0.1.0 to 0.1.1-0') !== -1, 'Should have bumped prerelease and patch version.');
   test.equal(grunt.file.readJSON(tmp).version, '0.1.1-0', 'Should have written the version to the file.');
   test.done();
 });
 testbump('bump:minor', function(result) {
   test.ok(result.indexOf('from 0.1.0 to 0.2.0') !== -1, 'Should have bumped minor version.');
   test.equal(grunt.file.readJSON(tmp).version, '0.2.0', 'Should have written the version to the file.');
   test.done();
 });
 tearDown: function(done) {
   grunt.file.delete(tmp);
   done();
 },
Example #15
0
 assertWatch(function() {
   grunt.file.write(path.join(cwd, 'lib', 'fail.js'), 'var fail = false;');
 }, function(result) {
Example #16
0
 BOWER_FILES.forEach(function(file) {
   grunt.file.copy('build/' + file, BOWER_PATH + file);
 });
Example #17
0
 assertWatch(function() {
   var write = 'var test = true;';
   grunt.file.write(path.join(cwd, 'lib', 'one.js'), write);
 }, function(result) {
Example #18
0
function docs() {
  grunt.file.copy('build/react-' + VERSION + '.zip', 'docs/downloads/react-' + VERSION + '.zip');
  grunt.file.copy('build/react.js', 'docs/js/react.js');
  grunt.file.copy('build/react-dom.js', 'docs/js/react-dom.js');
}
Example #19
0
 assertWatch(function() {
   grunt.file.write(path.join(cwd, 'lib', 'wait.js'), 'var wait = false;');
   setTimeout(function() {
     grunt.file.write(path.join(cwd, 'lib', 'wait.js'), 'var wait = true;');
   }, 500);
 }, function(result) {
Example #20
0
 assertWatch([function() {
   grunt.file.write(path.join(cwd, 'lib/one.js'), 'var one = true;');
 }, function() {
Example #21
0
var shimSharedModules = aliasify.configure({
  'aliases': {
    'react/lib/React': 'react/lib/ReactUMDShim',
    'react/lib/ReactCurrentOwner': 'react/lib/ReactCurrentOwnerUMDShim',
    'react/lib/ReactComponentTreeHook': 'react/lib/ReactComponentTreeHookUMDShim',
  },
});

var shimDOMModules = aliasify.configure({
  'aliases': {
    './ReactAddonsDOMDependencies': {relative: './ReactAddonsDOMDependenciesUMDShim'},
  },
});

var SIMPLE_TEMPLATE =
  grunt.file.read('./grunt/data/header-template-short.txt');

var LICENSE_TEMPLATE =
  grunt.file.read('./grunt/data/header-template-extended.txt');

function minify(src) {
  return UglifyJS.minify(src, {fromString: true}).code;
}

// TODO: move this out to another build step maybe.
function bannerify(src) {
  var version = grunt.config.data.pkg.version;
  var packageName = this.data.packageName || this.data.standalone;
  return (
    grunt.template.process(
      LICENSE_TEMPLATE,
Example #22
0
 }, function() {
   grunt.file.write(path.join(cwd, 'lib/one.js'), 'var one = true;');
 }], function(result) {
var assertFileEqual = function(test, fileName, message) {
  var actual = grunt.file.read('tmp/' + fileName);
  var expected = grunt.file.read('test/expected/' + fileName);
  test.equal(actual, expected, message);
};
Example #24
0
function assertFileDoesNotExist(test, path) {
    var exists = grunt.file.exists(path);
    test.equal(false, exists, 'Expected this file to not exist: ' + path);
}
 files.forEach(function(file) {
   var actual = grunt.file.read(file[0]);
   var expected = grunt.file.read(file[1]);
   test.equal(actual, expected, file[0] + ' differs from ' + file[1]);
 });
Example #26
0
 assertWatch(function() {
   grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), 'var interrupt = false;');
   setTimeout(function() {
     grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), 'var interrupt = true;');
   }, 1000);
 }, function(result) {
Example #27
0
 before(function() {
   usemin.call(grunt,grunt);
   grunt.log.muted = true;
   grunt.file.mkdir('images');
   grunt.file.mkdir('css');
 });
Example #28
0
 setTimeout(function() {
   grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), 'var interrupt = true;');
 }, 1000);
Example #29
0
Job.prototype._replace = function (resource) {
  var options = this.options,
      self = this,
      ignorePath = this.options.ignorePath,
      relativeTo = this.options.cdn;

  // absolute urls will not be passed into this function
  // skip those absolute urls
  // if (resource.match(/^https?:\/\//i) || resource.match(/^\/\//) || resource.match(/^data:/i)) {
  //   self.emit("ignore", {
  //     resource: resource,
  //     reason: "ignored on purpose"
  //   });
  //   return resource;
  // }

  if(ignorePath && resource.match(ignorePath)) {
    self.emit("ignore", {
      resource: resource,
      reason: "ignore on purpose"
    });
    return resource;
  }

  var resourceUrl = url.parse(resource);
  
  if(resourceUrl.protocol === "about:") {
    return resource;
  }

  // if flatten is true then we will convert all paths to absolute here!
  if (options.flatten) {
    resourceUrl.pathname = '/' + resourceUrl.pathname.replace(/^(\.\.?\/)+/, '');
  }

  if (options.match) {
    if (typeof options.match === 'function') {
      if (!options.match(resourceUrl, resource)) {
        self.emit("ignore", {
          resource: resource,
          reason: "not matched"
        });
        return resource;
      }
    } else {
      if (!resourceUrl.pathname.match(options.match)) {
        self.emit("ignore", {
          resource: resource,
          reason: "not matched"
        });
        return resource;
      }
    }
  }

  // if path is relative let it be
  if (!options.flatten && !grunt.file.isPathAbsolute(resourceUrl.pathname)) {
    self.emit("ignore", {
      resource: resource,
      reason: "it's a relative URL"
    });
    return resource;
  }

  // if stripDirs then loop through and strip
  if (options.stripDirs) {
    if (typeof options.stripDirs === 'string') {
      options.stripDirs = [options.stripDirs];
    }
    options.stripDirs.forEach(function(dirname) {
      var re = new RegExp('\/('+dirname+'\/)', 'g');
      resourceUrl.pathname = resourceUrl.pathname.replace(re, '');
    });
  }

  var src = path.join(relativeTo, resourceUrl.pathname).replace(/\\/g, '/').replace(/:\/(\w)/, '://$1');

  // if using protocol-relative CDN URL re-add the leading double-slash removed by path.join
  if (relativeTo.match(/^\/\/\w/)) {
    src = src.replace(/^\/(\w)/, '\/\/$1');
  }
  
  self.emit('entry', {
    before: resourceUrl.pathname,
    after: src
  });
  return grunt.template.process('<%= url %><%= search %><%= hash %>', {
    data: {
    url: src,
    hash: (resourceUrl.hash || ''), // keep the original hash too
    search: (resourceUrl.search || '') // keep the original querystring
    }
  });
};
Example #30
0
 'Test replace tasks in grunt file produced the correct result': function (test) {
     var modifiedFile = grunt.file.read('test/modified/example.txt');
     var expectedResult = grunt.file.read('test/text_files/expected-result.txt');
     test.equal(modifiedFile, expectedResult);
     test.done();
 },